Java Code Examples for javax.xml.transform.TransformerFactory#setURIResolver()
The following examples show how to use
javax.xml.transform.TransformerFactory#setURIResolver() .
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: CatalogSupportBase.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Returns an instance of TransformerFactory with either a custom URIResolver * or Catalog. * * @param setUseCatalog a flag indicates whether USE_CATALOG shall be set * through the factory * @param useCatalog the value of USE_CATALOG * @param catalog a catalog * @param resolver a custom resolver * @return an instance of TransformerFactory * @throws Exception */ TransformerFactory getTransformerFactory(boolean setUseCatalog, boolean useCatalog, String catalog, URIResolver resolver) throws Exception { TransformerFactory factory = TransformerFactory.newInstance(); if (setUseCatalog) { factory.setFeature(XMLConstants.USE_CATALOG, useCatalog); } if (catalog != null) { factory.setAttribute(CatalogFeatures.Feature.FILES.getPropertyName(), catalog); } // use resolver or catalog if resolver = null if (resolver != null) { factory.setURIResolver(resolver); } return factory; }
Example 2
Source File: Util.java From carbon-commons with Apache License 2.0 | 6 votes |
public static void transform(Source xmlIn, Source xslIn, Result result, Map paramMap, URIResolver uriResolver) throws TransformerException { try { TransformerFactory transformerFactory = new TransformerFactoryImpl(); transformerFactory.setURIResolver(uriResolver); Transformer transformer = transformerFactory.newTransformer(xslIn); if (paramMap != null) { Set set = paramMap.keySet(); for (Object aSet : set) { String key = (String) aSet; String value = (String) paramMap.get(key); transformer.setParameter(key, value); } } transformer.transform(xmlIn, result); } catch (TransformerException e) { log.error(e.getMessage(), e); throw e; } }
Example 3
Source File: StyleServiceImpl.java From rice with Educational Community License v2.0 | 5 votes |
@Override public Templates getStyleAsTranslet(String name) throws TransformerConfigurationException { if (name == null) { return null; } Style style = getStyle(name); if (style == null) { return null; } boolean useXSLTC = CoreFrameworkServiceLocator.getParameterService().getParameterValueAsBoolean(KewApiConstants.KEW_NAMESPACE, KRADConstants.DetailTypes.EDOC_LITE_DETAIL_TYPE, KewApiConstants.EDL_USE_XSLTC_IND); if (useXSLTC) { LOG.info("using xsltc to compile stylesheet"); String key = "javax.xml.transform.TransformerFactory"; String value = "org.apache.xalan.xsltc.trax.TransformerFactoryImpl"; Properties props = System.getProperties(); props.put(key, value); System.setProperties(props); } TransformerFactory factory = TransformerFactory.newInstance(); factory.setURIResolver(new StyleUriResolver(this)); if (useXSLTC) { factory.setAttribute("translet-name",name); factory.setAttribute("generate-translet",Boolean.TRUE); String debugTransform = CoreFrameworkServiceLocator.getParameterService().getParameterValueAsString(KewApiConstants.KEW_NAMESPACE, KRADConstants.DetailTypes.EDOC_LITE_DETAIL_TYPE, KewApiConstants.EDL_DEBUG_TRANSFORM_IND); if (debugTransform.trim().equals("Y")) { factory.setAttribute("debug", Boolean.TRUE); } } return factory.newTemplates(new StreamSource(new StringReader(style.getXmlContent()))); }
Example 4
Source File: CuentasContablesv11.java From factura-electronica with Apache License 2.0 | 5 votes |
byte[] getOriginalBytes() throws Exception { JAXBSource in = new JAXBSource(context, document); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Result out = new StreamResult(baos); TransformerFactory factory = tf; if (factory == null) { factory = TransformerFactory.newInstance(); factory.setURIResolver(new URIResolverImpl()); } Transformer transformer = factory.newTransformer(new StreamSource(getClass().getResourceAsStream(XSLT))); transformer.transform(in, out); return baos.toByteArray(); }
Example 5
Source File: BalanzaComprobacionv11.java From factura-electronica with Apache License 2.0 | 5 votes |
byte[] getOriginalBytes() throws Exception { JAXBSource in = new JAXBSource(context, document); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Result out = new StreamResult(baos); TransformerFactory factory = tf; if (factory == null) { factory = TransformerFactory.newInstance(); factory.setURIResolver(new URIResolverImpl()); } Transformer transformer = factory.newTransformer(new StreamSource(getClass().getResourceAsStream(XSLT))); transformer.transform(in, out); return baos.toByteArray(); }
Example 6
Source File: RestContentProvider.java From sakai with Educational Community License v2.0 | 5 votes |
/** * create transformer * @param stylesheet * @return */ private static Transformer createTransformer(Document stylesheet) { if (log.isDebugEnabled()) { log.debug("createTransformer(Document " + stylesheet + ")"); } Transformer transformer = null; TransformerFactory transformerFactory = TransformerFactory.newInstance(); URIResolver resolver = new URIResolver(); transformerFactory.setURIResolver(resolver); try { DOMSource source = new DOMSource(stylesheet); String systemId = "/xsl"; source.setSystemId(systemId); transformer = transformerFactory.newTransformer(source); } catch (TransformerConfigurationException e) { log.error(e.getMessage(), e); } return transformer; }
Example 7
Source File: CFDv22.java From factura-electronica with Apache License 2.0 | 5 votes |
byte[] getOriginalBytes() throws Exception { JAXBSource in = new JAXBSource(context, document); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Result out = new StreamResult(baos); TransformerFactory factory = tf; if (factory == null) { factory = TransformerFactory.newInstance(); factory.setURIResolver(new URIResolverImpl()); } Transformer transformer = factory.newTransformer(new StreamSource(getClass().getResourceAsStream(XSLT))); transformer.transform(in, out); return baos.toByteArray(); }
Example 8
Source File: CFDv32.java From factura-electronica with Apache License 2.0 | 5 votes |
byte[] getOriginalBytes() throws Exception { JAXBSource in = new JAXBSource(context, document); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Result out = new StreamResult(baos); TransformerFactory factory = tf; if (factory == null) { factory = TransformerFactory.newInstance(); factory.setURIResolver(new URIResolverImpl()); } Transformer transformer = factory.newTransformer(new StreamSource(getClass().getResourceAsStream(XSLT))); transformer.transform(in, out); return baos.toByteArray(); }
Example 9
Source File: CFDv3.java From factura-electronica with Apache License 2.0 | 5 votes |
byte[] getOriginalBytes() throws Exception { JAXBSource in = new JAXBSource(context, document); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Result out = new StreamResult(baos); TransformerFactory factory = tf; if (factory == null) { factory = TransformerFactory.newInstance(); factory.setURIResolver(new URIResolverImpl()); } Transformer transformer = factory.newTransformer(new StreamSource(getClass().getResourceAsStream(XSLT))); transformer.transform(in, out); return baos.toByteArray(); }
Example 10
Source File: PolizasPeriodov11.java From factura-electronica with Apache License 2.0 | 5 votes |
byte[] getOriginalBytes() throws Exception { JAXBSource in = new JAXBSource(context, document); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Result out = new StreamResult(baos); TransformerFactory factory = tf; if (factory == null) { factory = TransformerFactory.newInstance(); factory.setURIResolver(new URIResolverImpl()); } Transformer transformer = factory.newTransformer(new StreamSource(getClass().getResourceAsStream(XSLT))); transformer.transform(in, out); return baos.toByteArray(); }
Example 11
Source File: MCRXSLTransformer.java From mycore with GNU General Public License v3.0 | 5 votes |
public synchronized void setTransformerFactory(String factoryClass) throws TransformerFactoryConfigurationError { TransformerFactory transformerFactory = Optional.ofNullable(factoryClass) .map(c -> TransformerFactory.newInstance(c, MCRClassTools.getClassLoader())) .orElseGet(TransformerFactory::newInstance); LOGGER.debug("Transformerfactory: {}", transformerFactory.getClass().getName()); transformerFactory.setURIResolver(URI_RESOLVER); transformerFactory.setErrorListener(MCRErrorListener.getInstance()); if (transformerFactory.getFeature(SAXSource.FEATURE) && transformerFactory.getFeature(SAXResult.FEATURE)) { this.tFactory = (SAXTransformerFactory) transformerFactory; } else { throw new MCRConfigurationException("Transformer Factory " + transformerFactory.getClass().getName() + " does not implement SAXTransformerFactory"); } }
Example 12
Source File: URIResolverTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * This is to test the URIResolver.resolve() method when a transformer is * created using DOMSource. style-sheet file has xsl:include in it. * * @throws Exception If any errors occur. */ @Test public static void resolver02() throws Exception { TransformerFactory tfactory = TransformerFactory.newInstance(); URIResolverTest resolver = new URIResolverTest(XSL_TEMP_FILE, SYSTEM_ID); tfactory.setURIResolver(resolver); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder db = dbf.newDocumentBuilder(); Document document = db.parse(XSL_INCLUDE_FILE); DOMSource domSource = new DOMSource(document, SYSTEM_ID); assertNotNull(tfactory.newTransformer(domSource)); }
Example 13
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 14
Source File: CatalogTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "supportURIResolver") public void supportURIResolver(URI catalogFile, Source xsl, Source xml, String expected) throws Exception { CatalogResolver cr = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalogFile); TransformerFactory factory = TransformerFactory.newInstance(); factory.setURIResolver(cr); Transformer transformer = factory.newTransformer(xsl); StringWriter out = new StringWriter(); transformer.transform(xml, new StreamResult(out)); if (expected != null) { Assert.assertTrue(out.toString().contains(expected), "supportURIResolver"); } }
Example 15
Source File: CFDv32.java From factura-electronica with Apache License 2.0 | 4 votes |
@Override public void setTransformerFactory(TransformerFactory tf) { this.tf = tf; tf.setURIResolver(new URIResolverImpl()); }
Example 16
Source File: CFDv3.java From factura-electronica with Apache License 2.0 | 4 votes |
@Override public void setTransformerFactory(TransformerFactory tf) { this.tf = tf; tf.setURIResolver(new URIResolverImpl()); }
Example 17
Source File: MCRFoFormatterFOP.java From mycore with GNU General Public License v3.0 | 4 votes |
private static TransformerFactory getTransformerFactory() throws TransformerFactoryConfigurationError { TransformerFactory transformerFactory = TransformerFactory.newInstance(); transformerFactory.setURIResolver(MCRURIResolver.instance()); transformerFactory.setErrorListener(MCRErrorListener.getInstance()); return transformerFactory; }
Example 18
Source File: DocExporter.java From TranskribusCore with GNU General Public License v3.0 | 4 votes |
public File transformTei(Mets mets, String workDir, String exportFilename) throws JAXBException, TransformerException, IOException, SAXException, ParserConfigurationException { if(mets == null){ throw new IllegalArgumentException("An argument is null!"); } File teiFile = new File(exportFilename); try ( InputStream metsIs = new ByteArrayInputStream(JaxbUtils.marshalToBytes(mets, TrpDocMetadata.class)); InputStream xslIS = new BufferedInputStream(this.getClass().getClassLoader().getResourceAsStream(PAGE_TO_TEI_XSLT)); OutputStream teiOs = new FileOutputStream(teiFile); ) { StreamSource mySrc = new StreamSource(metsIs); //necessary to use the relative paths of the mets in the xslt mySrc.setSystemId(workDir); DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance(); dFactory.setNamespaceAware(true); DocumentBuilder dBuilder = dFactory.newDocumentBuilder(); InputSource xslInputSource = new InputSource(xslIS); Document xslDoc = dBuilder.parse(xslInputSource); DOMSource xslDomSource = new DOMSource(xslDoc); TransformerFactory transFact = TransformerFactory.newInstance(); //may? this is the only way to dynamically include a xsl in the xsl-source transFact.setURIResolver(new MyURIResolver(dBuilder)); //would be the short way from MyURIResolver: lambda expression -> brought some .NullPointerException, I/O error reported by XML parser // transFact.setURIResolver((href, base) -> { // final InputStream s = DocExporter.class.getClassLoader().getResourceAsStream("xslt/" + href); // return new StreamSource(s); // }); Transformer trans = transFact.newTransformer(xslDomSource); trans.transform(mySrc, new StreamResult(teiOs)); } return teiFile; }
Example 19
Source File: BalanzaComprobacionv11.java From factura-electronica with Apache License 2.0 | 4 votes |
public void setTransformerFactory(TransformerFactory tf) { this.tf = tf; tf.setURIResolver(new URIResolverImpl()); }
Example 20
Source File: CuentasContablesv11.java From factura-electronica with Apache License 2.0 | 4 votes |
public void setTransformerFactory(TransformerFactory tf) { this.tf = tf; tf.setURIResolver(new URIResolverImpl()); }