/** * Create a new input source with a DOM node, and with the * system ID also passed in as the base URI. * * @param node The DOM node that will contain the Source tree. * @param systemID Specifies the base URI associated with node. */ public DOMSource(Node node, String systemID) { setNode(node); setSystemId(systemID); }
DOMLSInput(Document doc, String systemId) throws TransformerException { this.systemId = systemId; TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); DOMSource source = new DOMSource(doc); source.setSystemId(systemId); StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); transformer.transform(source, result); data = writer.toString(); LOG.fine(systemId + ": " + data); }
public static DOMSource toDOMSource(final InputSource inputSource) throws IOException { try { final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); final DocumentBuilder db = factory.newDocumentBuilder(); final Document document = db.parse(inputSource); final DOMSource res = new DOMSource(document); res.setSystemId(inputSource.getSystemId()); return res; } catch (ParserConfigurationException | SAXException e) { throw new IOException(e); } }
/** * Create a new input source with a DOM node, and with the * system ID also passed in as the base URI. * * @param node The DOM node that will contain the Source tree. * @param systemID Specifies the base URI associated with node. */ public DOMSource(Node node, String systemID) { setNode(node); setSystemId(systemID); }
/** * Create a new input source with a DOM node, and with the * system ID also passed in as the base URI. * * @param node The DOM node that will contain the Source tree. * @param systemID Specifies the base URI associated with node. */ public DOMSource(Node node, String systemID) { setNode(node); setSystemId(systemID); }
/** * Create a new input source with a DOM node, and with the * system ID also passed in as the base URI. * * @param node The DOM node that will contain the Source tree. * @param systemID Specifies the base URI associated with node. */ public DOMSource(Node node, String systemID) { setNode(node); setSystemId(systemID); }
/** * Create a new input source with a DOM node, and with the * system ID also passed in as the base URI. * * @param node The DOM node that will contain the Source tree. * @param systemID Specifies the base URI associated with node. */ public DOMSource(Node node, String systemID) { setNode(node); setSystemId(systemID); }
private Document validate( final Document doc ) throws Exception { final DOMSource source = new DOMSource( doc ); source.setSystemId( this.systemId ); final DOMResult result = VALIDATOR.validate( source ); return (Document) result.getNode(); }
/** * Create a new input source with a DOM node, and with the * system ID also passed in as the base URI. * * @param node The DOM node that will contain the Source tree. * @param systemID Specifies the base URI associated with node. */ public DOMSource(Node node, String systemID) { setNode(node); setSystemId(systemID); }
/** * Create a new input source with a DOM node, and with the * system ID also passed in as the base URI. * * @param node The DOM node that will contain the Source tree. * @param systemID Specifies the base URI associated with node. */ public DOMSource(Node node, String systemID) { setNode(node); setSystemId(systemID); }
/** * Create a new input source with a DOM node, and with the * system ID also passed in as the base URI. * * @param node The DOM node that will contain the Source tree. * @param systemID Specifies the base URI associated with node. */ public DOMSource(Node node, String systemID) { setNode(node); setSystemId(systemID); }
@Override public DOMSource process(DOMSource aDocument) throws XMLException { DOMResult result = new DOMResult(); try { transform(aDocument, result); } catch (IOException e) { throw new XMLException(e.getMessage(), e); } catch (TransformerException e) { throw new XMLException(e.getMessage(), e); } Document docraw = (Document)result.getNode(); DOMSource resultSource = new DOMSource(docraw); resultSource.setSystemId(aDocument.getSystemId() + "/transformed(" + systemId + ")"); return resultSource; }
private Schema createSchema(List<InputSource> xsdsInJar, String[] schemas) throws SAXException, IOException { SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); sf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE); sf.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "file"); SchemaResourceResolver resourceResolver = new SchemaResourceResolver(); sf.setResourceResolver(resourceResolver); List<Source> sources = new ArrayList<>(); for (InputSource is : xsdsInJar) { Message msg = new Message("CREATE_SCHEMA_LOADED_FROM_JAR", LOG, is.getSystemId()); LOG.log(Level.FINE, msg.toString()); Document doc = docBuilder.parse(is.getByteStream()); DOMSource stream = new DOMSource(doc, is.getSystemId()); stream.setSystemId(is.getSystemId()); sources.add(stream); } if (schemas != null) { for (int i = 0; i < schemas.length; i++) { Document doc = docBuilder.parse(schemas[i]); DOMSource stream = new DOMSource(doc, schemas[i]); sources.add(stream); } } Source[] args = new Source[sources.size()]; sources.toArray(args); return sf.newSchema(args); }
/** * 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; }
public XMLValidationSchema loadSchemas(String baseURI, Map<String, EmbeddedSchema> sources) throws XMLStreamException { parserFactory = getSaxFactory(); ResolvingGrammarReaderController ctrl = new ResolvingGrammarReaderController(baseURI, sources); xmlSchemaReader = new RecursiveAllowedXMLSchemaReader(ctrl, parserFactory); multiSchemaReader = new MultiSchemaReader(xmlSchemaReader); for (EmbeddedSchema source : sources.values()) { DOMSource domSource = new DOMSource(source.getSchemaElement()); domSource.setSystemId(source.getSystemId()); multiSchemaReader.parse(domSource); } XMLSchemaGrammar grammar = multiSchemaReader.getResult(); if (grammar == null) { throw new XMLStreamException("Failed to load schemas"); } return new W3CSchema(grammar); }
public XMLValidationSchema loadSchemas(String baseURI, Map<String, EmbeddedSchema> sources) throws XMLStreamException { parserFactory = getSaxFactory(); ResolvingGrammarReaderController ctrl = new ResolvingGrammarReaderController(baseURI, sources); xmlSchemaReader = new RecursiveAllowedXMLSchemaReader(ctrl, parserFactory); multiSchemaReader = new MultiSchemaReader(xmlSchemaReader); for (EmbeddedSchema source : sources.values()) { DOMSource domSource = new DOMSource(source.getSchemaElement()); domSource.setSystemId(source.getSystemId()); multiSchemaReader.parse(domSource); } XMLSchemaGrammar grammar = multiSchemaReader.getResult(); if (grammar == null) { throw new XMLStreamException("Failed to load schemas"); } return new W3CSchema(grammar); }
public XMLValidationSchema loadSchemas(String baseURI, Map<String, EmbeddedSchema> sources) throws XMLStreamException { parserFactory = getSaxFactory(); ResolvingGrammarReaderController ctrl = new ResolvingGrammarReaderController(baseURI, sources); xmlSchemaReader = new RecursiveAllowedXMLSchemaReader(ctrl, parserFactory); multiSchemaReader = new MultiSchemaReader(xmlSchemaReader); for (EmbeddedSchema source : sources.values()) { DOMSource domSource = new DOMSource(source.getSchemaElement()); domSource.setSystemId(source.getSystemId()); multiSchemaReader.parse(domSource); } XMLSchemaGrammar grammar = multiSchemaReader.getResult(); if (grammar == null) { throw new XMLStreamException("Failed to load schemas"); } return new W3CSchema(grammar); }
@Test public void testWsdlMultiSchema() throws Exception { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); URL wsdlUri = getClass().getResource("/test.wsdl"); assertNotNull(wsdlUri); Document wsdl = documentBuilder.parse(wsdlUri.openStream()); String wsdlSystemId = wsdlUri.toExternalForm(); DOMSource source = new DOMSource(wsdl); source.setSystemId(wsdlSystemId); LocalController controller = new LocalController(); SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); XMLSchemaGrammar result = WSDLSchemaReader.read(source, factory, controller); assertNotNull(result); }
@Test public void testWsdlMultiRefSchema() throws Exception { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); URL wsdlUri = getClass().getResource("/multireference.wsdl"); assertNotNull(wsdlUri); Document wsdl = documentBuilder.parse(wsdlUri.openStream()); String wsdlSystemId = wsdlUri.toExternalForm(); DOMSource source = new DOMSource(wsdl); source.setSystemId(wsdlSystemId); LocalController controller = new LocalController(); SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); XMLSchemaGrammar result = WSDLSchemaReader.read(source, factory, controller); assertNotNull(result); } }
private static DOMSource read(LSInput aInput, LSResourceResolver aResolver) throws XMLException { try { DOMImplementationLS impl = DomUtils.getDomImplementationLS(); LSParser builder = impl.createLSParser( DOMImplementationLS.MODE_SYNCHRONOUS, null); if (aResolver != null) { builder.getDomConfig().setParameter("resource-resolver", aResolver); } Document docraw = builder.parse(aInput); DOMSource result = new DOMSource(docraw); result.setSystemId(aInput.getSystemId()); return result; } catch (LSException e) { throw new XMLException(e.getMessage(), e); } }