javax.xml.transform.URIResolver Java Examples
The following examples show how to use
javax.xml.transform.URIResolver.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XsltUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
public static void saxonTransform(String xsltDir, String source, String xslt, String dest, URIResolver alt, Map<String, String> params) throws FileNotFoundException, TransformerException { TransformerFactoryImpl f = new net.sf.saxon.TransformerFactoryImpl(); f.setAttribute("http://saxon.sf.net/feature/version-warning", Boolean.FALSE); StreamSource xsrc = new StreamSource(new FileInputStream(xslt)); f.setURIResolver(new MyURIResolver(xsltDir, alt)); Transformer t = f.newTransformer(xsrc); if (params != null) { for (Map.Entry<String, String> entry : params.entrySet()) { t.setParameter(entry.getKey(), entry.getValue()); } } t.setURIResolver(new MyURIResolver(xsltDir, alt)); StreamSource src = new StreamSource(new FileInputStream(source)); StreamResult res = new StreamResult(new FileOutputStream(dest)); t.transform(src, res); }
Example #2
Source File: TemplatesImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Overrides the default readObject implementation since we decided * it would be cleaner not to serialize the entire tranformer * factory. [ ref bugzilla 12317 ] * We need to check if the user defined class for URIResolver also * implemented Serializable * if yes then we need to deserialize the URIResolver * Fix for bugzilla bug 22438 */ @SuppressWarnings("unchecked") private void readObject(ObjectInputStream is) throws IOException, ClassNotFoundException { SecurityManager security = System.getSecurityManager(); if (security != null){ String temp = SecuritySupport.getSystemProperty(DESERIALIZE_TRANSLET); if (temp == null || !(temp.length()==0 || temp.equalsIgnoreCase("true"))) { ErrorMsg err = new ErrorMsg(ErrorMsg.DESERIALIZE_TRANSLET_ERR); throw new UnsupportedOperationException(err.toString()); } } // We have to read serialized fields first. ObjectInputStream.GetField gf = is.readFields(); _name = (String)gf.get("_name", null); _bytecodes = (byte[][])gf.get("_bytecodes", null); _class = (Class[])gf.get("_class", null); _transletIndex = gf.get("_transletIndex", -1); _outputProperties = (Properties)gf.get("_outputProperties", null); _indentNumber = gf.get("_indentNumber", 0); if (is.readBoolean()) { _uriResolver = (URIResolver) is.readObject(); } _tfactory = new TransformerFactoryImpl(); }
Example #3
Source File: TemplatesHandlerImpl.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * Store URIResolver needed for Transformers. */ public void setURIResolver(URIResolver resolver) { _uriResolver = resolver; }
Example #4
Source File: TemplatesImpl.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** * Overrides the default readObject implementation since we decided * it would be cleaner not to serialize the entire tranformer * factory. [ ref bugzilla 12317 ] * We need to check if the user defined class for URIResolver also * implemented Serializable * if yes then we need to deserialize the URIResolver * Fix for bugzilla bug 22438 */ @SuppressWarnings("unchecked") private void readObject(ObjectInputStream is) throws IOException, ClassNotFoundException { SecurityManager security = System.getSecurityManager(); if (security != null){ String temp = SecuritySupport.getSystemProperty(DESERIALIZE_TRANSLET); if (temp == null || !(temp.length()==0 || temp.equalsIgnoreCase("true"))) { ErrorMsg err = new ErrorMsg(ErrorMsg.DESERIALIZE_TRANSLET_ERR); throw new UnsupportedOperationException(err.toString()); } } // We have to read serialized fields first. ObjectInputStream.GetField gf = is.readFields(); _name = (String)gf.get("_name", null); _bytecodes = (byte[][])gf.get("_bytecodes", null); _class = (Class[])gf.get("_class", null); _transletIndex = gf.get("_transletIndex", -1); _outputProperties = (Properties)gf.get("_outputProperties", null); _indentNumber = gf.get("_indentNumber", 0); if (is.readBoolean()) { _uriResolver = (URIResolver) is.readObject(); } _tfactory = new TransformerFactoryImpl(); }
Example #5
Source File: TemplatesImpl.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Overrides the default readObject implementation since we decided * it would be cleaner not to serialize the entire tranformer * factory. [ ref bugzilla 12317 ] * We need to check if the user defined class for URIResolver also * implemented Serializable * if yes then we need to deserialize the URIResolver * Fix for bugzilla bug 22438 */ @SuppressWarnings("unchecked") private void readObject(ObjectInputStream is) throws IOException, ClassNotFoundException { SecurityManager security = System.getSecurityManager(); if (security != null){ String temp = SecuritySupport.getSystemProperty(DESERIALIZE_TRANSLET); if (temp == null || !(temp.length()==0 || temp.equalsIgnoreCase("true"))) { ErrorMsg err = new ErrorMsg(ErrorMsg.DESERIALIZE_TRANSLET_ERR); throw new UnsupportedOperationException(err.toString()); } } // We have to read serialized fields first. ObjectInputStream.GetField gf = is.readFields(); _name = (String)gf.get("_name", null); _bytecodes = (byte[][])gf.get("_bytecodes", null); _class = (Class[])gf.get("_class", null); _transletIndex = gf.get("_transletIndex", -1); _outputProperties = (Properties)gf.get("_outputProperties", null); _indentNumber = gf.get("_indentNumber", 0); if (is.readBoolean()) { _uriResolver = (URIResolver) is.readObject(); } _tfactory = new TransformerFactoryImpl(); }
Example #6
Source File: XsltUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
public static void transform(String xsltDir, String source, String xslt, String dest, URIResolver alt) throws FileNotFoundException, TransformerException { TransformerFactory f = TransformerFactory.newInstance(); StreamSource xsrc = new StreamSource(new FileInputStream(xslt)); f.setURIResolver(new MyURIResolver(xsltDir, alt)); Transformer t = f.newTransformer(xsrc); t.setURIResolver(new MyURIResolver(xsltDir, alt)); StreamSource src = new StreamSource(new FileInputStream(source)); StreamResult res = new StreamResult(new FileOutputStream(dest)); t.transform(src, res); }
Example #7
Source File: TemplatesImpl.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * Overrides the default readObject implementation since we decided * it would be cleaner not to serialize the entire tranformer * factory. [ ref bugzilla 12317 ] * We need to check if the user defined class for URIResolver also * implemented Serializable * if yes then we need to deserialize the URIResolver * Fix for bugzilla bug 22438 */ @SuppressWarnings("unchecked") private void readObject(ObjectInputStream is) throws IOException, ClassNotFoundException { SecurityManager security = System.getSecurityManager(); if (security != null){ String temp = SecuritySupport.getSystemProperty(DESERIALIZE_TRANSLET); if (temp == null || !(temp.length()==0 || temp.equalsIgnoreCase("true"))) { ErrorMsg err = new ErrorMsg(ErrorMsg.DESERIALIZE_TRANSLET_ERR); throw new UnsupportedOperationException(err.toString()); } } // We have to read serialized fields first. ObjectInputStream.GetField gf = is.readFields(); _name = (String)gf.get("_name", null); _bytecodes = (byte[][])gf.get("_bytecodes", null); _class = (Class[])gf.get("_class", null); _transletIndex = gf.get("_transletIndex", -1); _outputProperties = (Properties)gf.get("_outputProperties", null); _indentNumber = gf.get("_indentNumber", 0); if (is.readBoolean()) { _uriResolver = (URIResolver) is.readObject(); } _tfactory = new TransformerFactoryImpl(); }
Example #8
Source File: MyURIResolver.java From org.hl7.fhir.core with Apache License 2.0 | 4 votes |
public MyURIResolver(String path, URIResolver alt) { super(); this.path = path; this.alt = alt; }
Example #9
Source File: SmartTransformerFactoryImpl.java From JDKSourceCode1.8 with MIT License | 4 votes |
public URIResolver getURIResolver() { return _uriresolver; }
Example #10
Source File: SmartTransformerFactoryImpl.java From JDKSourceCode1.8 with MIT License | 4 votes |
public void setURIResolver(URIResolver resolver) { _uriresolver = resolver; }
Example #11
Source File: TemplatesHandlerImpl.java From JDKSourceCode1.8 with MIT License | 4 votes |
/** * Store URIResolver needed for Transformers. */ public void setURIResolver(URIResolver resolver) { _uriResolver = resolver; }
Example #12
Source File: XalanTransformerFactory.java From camel-quarkus with Apache License 2.0 | 4 votes |
@Override public URIResolver getURIResolver() { return delegate.getURIResolver(); }
Example #13
Source File: XalanTransformerFactory.java From camel-quarkus with Apache License 2.0 | 4 votes |
@Override public void setURIResolver(URIResolver resolver) { delegate.setURIResolver(resolver); }
Example #14
Source File: XsltUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 4 votes |
public static void saxonTransform(String xsltDir, String source, String xslt, String dest, URIResolver alt) throws FileNotFoundException, TransformerException { saxonTransform(xsltDir, source, xslt, dest, alt, null); }
Example #15
Source File: XSLTFunctionsTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * bug 8062518 * Verifies that a reference to the DTM created by XSLT document function is * actually read from the DTM by an extension function. * @param xml Content of xml file to process * @param xsl stylesheet content that loads external document {@code externalDoc} * with XSLT 'document' function and then reads it with * DocumentExtFunc.test() function * @param externalDoc Content of the external xml document * @param expectedResult Expected transformation result **/ @Test(dataProvider = "document") public void testDocument(final String xml, final String xsl, final String externalDoc, final String expectedResult) throws Exception { // Prepare sources for transormation Source src = new StreamSource(new StringReader(xml)); Source xslsrc = new StreamSource(new StringReader(xsl)); // Create factory and transformer TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf.newTransformer( xslsrc ); t.setErrorListener(tf.getErrorListener()); // Set URI Resolver to return the newly constructed xml // stream source object from xml test string t.setURIResolver(new URIResolver() { @Override public Source resolve(String href, String base) throws TransformerException { if (href.contains("externalDoc")) { return new StreamSource(new StringReader(externalDoc)); } else { return new StreamSource(new StringReader(xml)); } } }); // Prepare output stream StringWriter xmlResultString = new StringWriter(); StreamResult xmlResultStream = new StreamResult(xmlResultString); //Transform the xml t.transform(src, xmlResultStream); // If the document can't be accessed and the bug is in place then // reported exception will be thrown during transformation System.out.println("Transformation result:"+xmlResultString.toString().trim()); // Check the result - it should contain two (node name, node values) entries - // one for original document, another for a document created with // call to 'document' function assertEquals(xmlResultString.toString().trim(), expectedResult); }
Example #16
Source File: SmartTransformerFactoryImpl.java From jdk1.8-source-analysis with Apache License 2.0 | 4 votes |
public URIResolver getURIResolver() { return _uriresolver; }
Example #17
Source File: SmartTransformerFactoryImpl.java From jdk1.8-source-analysis with Apache License 2.0 | 4 votes |
public void setURIResolver(URIResolver resolver) { _uriresolver = resolver; }
Example #18
Source File: TransformerUtilsTests.java From spring-analysis-note with MIT License | 4 votes |
@Override public URIResolver getURIResolver() { throw new UnsupportedOperationException(); }
Example #19
Source File: XSLTFunctionsTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
/** * bug 8062518 * Verifies that a reference to the DTM created by XSLT document function is * actually read from the DTM by an extension function. * @param xml Content of xml file to process * @param xsl stylesheet content that loads external document {@code externalDoc} * with XSLT 'document' function and then reads it with * DocumentExtFunc.test() function * @param externalDoc Content of the external xml document * @param expectedResult Expected transformation result **/ @Test(dataProvider = "document") public void testDocument(final String xml, final String xsl, final String externalDoc, final String expectedResult) throws Exception { // Prepare sources for transormation Source src = new StreamSource(new StringReader(xml)); Source xslsrc = new StreamSource(new StringReader(xsl)); // Create factory and transformer TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf.newTransformer( xslsrc ); t.setErrorListener(tf.getErrorListener()); // Set URI Resolver to return the newly constructed xml // stream source object from xml test string t.setURIResolver(new URIResolver() { @Override public Source resolve(String href, String base) throws TransformerException { if (href.contains("externalDoc")) { return new StreamSource(new StringReader(externalDoc)); } else { return new StreamSource(new StringReader(xml)); } } }); // Prepare output stream StringWriter xmlResultString = new StringWriter(); StreamResult xmlResultStream = new StreamResult(xmlResultString); //Transform the xml t.transform(src, xmlResultStream); // If the document can't be accessed and the bug is in place then // reported exception will be thrown during transformation System.out.println("Transformation result:"+xmlResultString.toString().trim()); // Check the result - it should contain two (node name, node values) entries - // one for original document, another for a document created with // call to 'document' function assertEquals(xmlResultString.toString().trim(), expectedResult); }
Example #20
Source File: XSLTFunctionsTest.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * bug 8062518 * Verifies that a reference to the DTM created by XSLT document function is * actually read from the DTM by an extension function. * @param xml Content of xml file to process * @param xsl stylesheet content that loads external document {@code externalDoc} * with XSLT 'document' function and then reads it with * DocumentExtFunc.test() function * @param externalDoc Content of the external xml document * @param expectedResult Expected transformation result **/ @Test(dataProvider = "document") public void testDocument(final String xml, final String xsl, final String externalDoc, final String expectedResult) throws Exception { // Prepare sources for transormation Source src = new StreamSource(new StringReader(xml)); Source xslsrc = new StreamSource(new StringReader(xsl)); // Create factory and transformer TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf.newTransformer( xslsrc ); t.setErrorListener(tf.getErrorListener()); // Set URI Resolver to return the newly constructed xml // stream source object from xml test string t.setURIResolver(new URIResolver() { @Override public Source resolve(String href, String base) throws TransformerException { if (href.contains("externalDoc")) { return new StreamSource(new StringReader(externalDoc)); } else { return new StreamSource(new StringReader(xml)); } } }); // Prepare output stream StringWriter xmlResultString = new StringWriter(); StreamResult xmlResultStream = new StreamResult(xmlResultString); //Transform the xml t.transform(src, xmlResultStream); // If the document can't be accessed and the bug is in place then // reported exception will be thrown during transformation System.out.println("Transformation result:"+xmlResultString.toString().trim()); // Check the result - it should contain two (node name, node values) entries - // one for original document, another for a document created with // call to 'document' function assertEquals(xmlResultString.toString().trim(), expectedResult); }
Example #21
Source File: SmartTransformerFactoryImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
public URIResolver getURIResolver() { return _uriresolver; }
Example #22
Source File: SmartTransformerFactoryImpl.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public URIResolver getURIResolver() { return _uriresolver; }
Example #23
Source File: TemplatesHandlerImpl.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * Store URIResolver needed for Transformers. */ public void setURIResolver(URIResolver resolver) { _uriResolver = resolver; }
Example #24
Source File: TransformerUtilsTests.java From java-technology-stack with MIT License | 4 votes |
@Override public void setURIResolver(URIResolver resolver) { throw new UnsupportedOperationException(); }
Example #25
Source File: TemplatesImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * Store URIResolver needed for Transformers. */ public synchronized void setURIResolver(URIResolver resolver) { _uriResolver = resolver; }
Example #26
Source File: TemplatesHandlerImpl.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Store URIResolver needed for Transformers. */ public void setURIResolver(URIResolver resolver) { _uriResolver = resolver; }
Example #27
Source File: XSLTFunctionsTest.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * bug 8062518 * Verifies that a reference to the DTM created by XSLT document function is * actually read from the DTM by an extension function. * @param xml Content of xml file to process * @param xsl stylesheet content that loads external document {@code externalDoc} * with XSLT 'document' function and then reads it with * DocumentExtFunc.test() function * @param externalDoc Content of the external xml document * @param expectedResult Expected transformation result **/ @Test(dataProvider = "document") public void testDocument(final String xml, final String xsl, final String externalDoc, final String expectedResult) throws Exception { // Prepare sources for transormation Source src = new StreamSource(new StringReader(xml)); Source xslsrc = new StreamSource(new StringReader(xsl)); // Create factory and transformer TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf.newTransformer( xslsrc ); t.setErrorListener(tf.getErrorListener()); // Set URI Resolver to return the newly constructed xml // stream source object from xml test string t.setURIResolver(new URIResolver() { @Override public Source resolve(String href, String base) throws TransformerException { if (href.contains("externalDoc")) { return new StreamSource(new StringReader(externalDoc)); } else { return new StreamSource(new StringReader(xml)); } } }); // Prepare output stream StringWriter xmlResultString = new StringWriter(); StreamResult xmlResultStream = new StreamResult(xmlResultString); //Transform the xml t.transform(src, xmlResultStream); // If the document can't be accessed and the bug is in place then // reported exception will be thrown during transformation System.out.println("Transformation result:"+xmlResultString.toString().trim()); // Check the result - it should contain two (node name, node values) entries - // one for original document, another for a document created with // call to 'document' function assertEquals(xmlResultString.toString().trim(), expectedResult); }
Example #28
Source File: SmartTransformerFactoryImpl.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public void setURIResolver(URIResolver resolver) { _uriresolver = resolver; }
Example #29
Source File: SmartTransformerFactoryImpl.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public URIResolver getURIResolver() { return _uriresolver; }
Example #30
Source File: TemplatesImpl.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Store URIResolver needed for Transformers. */ public synchronized void setURIResolver(URIResolver resolver) { _uriResolver = resolver; }