/** * Returns the XML representation as a DOM document. * * @return The DOM document. */ protected Document getDocument() throws Exception { return getDocumentBuilder().parse(getInputSource()); }
/** * Puts a new mapping between a prefix and a namespace URI. * * @param prefix * The namespace prefix. * @param namespaceURI * The namespace URI. */ public void putNamespace(String prefix, String namespaceURI) { getNamespaces().put(prefix, namespaceURI); }
/** * Returns a SAX source. * * @return A SAX source. * @throws IOException */ public javax.xml.transform.sax.SAXSource getSaxSource() throws IOException { return getSaxSource(this); }
/** * Validates the XML representation against a given schema. * * @param schemaRepresentation * The XML schema representation to use. * @param result * The Result object that receives (possibly augmented) XML. */ public void validate(Representation schemaRepresentation, Result result) throws Exception { validate(getSchema(schemaRepresentation), result); }
/** * Returns a document builder properly configured. * * @return A document builder properly configured. */ protected DocumentBuilder getDocumentBuilder() throws IOException { DocumentBuilder result = null; try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(isNamespaceAware()); dbf.setValidating(isValidatingDtd()); dbf.setCoalescing(isCoalescing()); dbf.setExpandEntityReferences(isExpandingEntityRefs()); dbf.setIgnoringComments(isIgnoringComments()); dbf.setIgnoringElementContentWhitespace(isIgnoringExtraWhitespaces()); try { dbf.setXIncludeAware(isXIncludeAware()); } catch (UnsupportedOperationException uoe) { Context.getCurrentLogger().log(Level.FINE, "The JAXP parser doesn't support XInclude.", uoe); } result = dbf.newDocumentBuilder(); result.setEntityResolver(getEntityResolver()); result.setErrorHandler(getErrorHandler()); } catch (ParserConfigurationException pce) { throw new IOException("Couldn't create the empty document: " + pce.getMessage()); } return result; }
/** * Returns a document builder properly configured. * * @return A document builder properly configured. */ protected DocumentBuilder getDocumentBuilder() throws IOException { DocumentBuilder result = null; try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(isNamespaceAware()); dbf.setValidating(isValidating()); try { dbf.setXIncludeAware(isXIncludeAware()); } catch (UnsupportedOperationException uoe) { Context.getCurrentLogger().log(Level.FINE, "The JAXP parser doesn't support XInclude.", uoe); } Schema xsd = getSchema(); if (xsd != null) { dbf.setSchema(xsd); } result = dbf.newDocumentBuilder(); result.setEntityResolver(getEntityResolver()); result.setErrorHandler(getErrorHandler()); } catch (ParserConfigurationException pce) { throw new IOException("Couldn't create the empty document: " + pce.getMessage()); } return result; }
/** * Returns a DOM source. * * @return A DOM source. * @throws IOException */ public javax.xml.transform.dom.DOMSource getDomSource() throws IOException { javax.xml.transform.dom.DOMSource result = null; Node document = null; try { document = getDocumentBuilder().parse(getInputSource()); } catch (SAXException se) { throw new IOException("Couldn't read the XML representation. " + se.getMessage()); } if (document != null) { result = new javax.xml.transform.dom.DOMSource(document); if (getLocationRef() != null) { result.setSystemId(getLocationRef().getTargetRef().toString()); } } return result; }
/** * Returns a DOM source. * * @return A DOM source. * @throws IOException */ public DOMSource getDomSource() throws IOException { DOMSource result = null; Node document = null; try { document = getDocumentBuilder().parse(getStream()); } catch (SAXException se) { throw new IOException("Couldn't read the XML representation. " + se.getMessage()); } if (document != null) { result = new DOMSource(document); if (getIdentifier() != null) { result.setSystemId(getIdentifier().getTargetRef().toString()); } } return result; }
/** * Releases the namespaces map. */ @Override public void release() { if (this.source != null) { this.source = null; } super.release(); }
/** * Set a schema representation to be compiled and used when parsing and * validating this type of XML representations. * * @param schemaRepresentation * The schema representation to set. */ public void setSchema(Representation schemaRepresentation) { try { this.schema = getSchema(schemaRepresentation); } catch (Exception e) { Context.getCurrentLogger().log(Level.WARNING, "Unable to compile the schema representation", e); } }
dbf.setNamespaceAware(isNamespaceAware()); dbf.setValidating(isValidatingDtd()); dbf.setCoalescing(isCoalescing()); dbf.setExpandEntityReferences(false); dbf.setFeature("http://xml.org/sax/features/external-parameter-entities",isExpandingEntityRefs()); dbf.setFeature("http://xml.org/sax/features/external-general-entities",isExpandingEntityRefs()); dbf.setIgnoringComments(isIgnoringComments()); dbf.setIgnoringElementContentWhitespace(isIgnoringExtraWhitespaces()); dbf.setXIncludeAware(isXIncludeAware()); } catch (UnsupportedOperationException uoe) { Context.getCurrentLogger().log(Level.FINE, javax.xml.validation.Schema xsd = getSchema(); result.setEntityResolver(getEntityResolver()); result.setErrorHandler(getErrorHandler()); } catch (ParserConfigurationException pce) { throw new IOException("Couldn't create the empty document: "
/** * Releases the namespaces map. */ @Override public void release() { if (this.source != null) { this.source = null; } super.release(); }
/** * Validates the XML representation against a given schema. * * @param schemaRepresentation * The XML schema representation to use. * @param result * The Result object that receives (possibly augmented) XML. */ public void validate(Representation schemaRepresentation, javax.xml.transform.Result result) throws Exception { validate(getSchema(schemaRepresentation), result); }
/** * Set a schema representation to be compiled and used when parsing and * validating this type of XML representations. * * @param schemaRepresentation * The schema representation to set. */ public void setSchema(Representation schemaRepresentation) { try { this.schema = getSchema(schemaRepresentation); } catch (Exception e) { Context.getCurrentLogger().log(Level.WARNING, "Unable to compile the schema representation", e); } }
/** * Returns a SAX source. * * @return A SAX source. * @throws IOException */ public SAXSource getSaxSource() throws IOException { return getSaxSource(this); }
/** * {@inheritDoc * javax.xml.namespace.NamespaceContext#getPrefix(java.lang.String} */ public String getPrefix(String namespaceURI) { String result = null; boolean found = false; for (Iterator<String> iterator = getNamespaces().keySet().iterator(); iterator .hasNext() && !found;) { String key = iterator.next(); if (getNamespaces().get(key).equals(namespaceURI)) { found = true; result = key; } } return result; }
/** * Releases the namespaces map. */ @Override public void release() { if (this.source != null) { this.source = null; } if (this.xmlRepresentation != null) { this.xmlRepresentation.release(); } super.release(); }
/** * Returns the XML representation as a DOM document. * * @return The DOM document. */ protected Document getDocument() throws Exception { return getDocumentBuilder().parse(getInputSource()); }
/** * Validates the XML representation against a given schema. * * @param schema * The XML schema to use. * @param result * The Result object that receives (possibly augmented) XML. */ public void validate(javax.xml.validation.Schema schema, javax.xml.transform.Result result) throws Exception { schema.newValidator().validate(getSaxSource(), result); }
/** * {@inheritDoc * javax.xml.namespace.NamespaceContext#getPrefix(java.lang.String} */ public String getPrefix(String namespaceURI) { String result = null; boolean found = false; for (Iterator<String> iterator = getNamespaces().keySet().iterator(); iterator .hasNext() && !found;) { String key = iterator.next(); if (getNamespaces().get(key).equals(namespaceURI)) { found = true; result = key; } } return result; }