List of usage examples for javax.xml.transform TransformerConfigurationException printStackTrace
@Override public void printStackTrace()
From source file:cross.datastructures.workflow.DefaultWorkflow.java
/** * Applies a stylesheet transformation to this DefaultWorkflow to create * text./* w w w. j ava2 s . c om*/ * * @param f */ protected void saveTEXT(final File f) { final TransformerFactory tf = TransformerFactory.newInstance(); try { final InputStream xsstyler = getClass().getClassLoader() .getResourceAsStream("res/xslt/maltcmsTEXTResult.xsl"); final StreamSource sstyles = new StreamSource(xsstyler); final FileInputStream xsr = new FileInputStream(f); final FileOutputStream xsw = new FileOutputStream(new File(f.getParentFile(), "workflow.txt")); final StreamSource sts = new StreamSource(xsr); final StreamResult str = new StreamResult(xsw); final Transformer t = tf.newTransformer(sstyles); t.transform(sts, str); } catch (final TransformerConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (final FileNotFoundException | TransformerException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.marklogic.entityservices.TestEsConversionModuleGenerator.java
@Test public void testInstanceToEnvelope() throws IOException, TestEvalException, SAXException, TransformerException { String entityType = "valid-ref-same-document.xml"; String sourceDocument = "ALFKI.xml"; String ns = getNameSpace(entityType); StringHandle handle = evalOneResult("import module namespace ext = \"" + ns + "\" at \"/conv/" + entityType.replaceAll("\\.(xml|json)", ".xqy") + "\"; " + "ext:instance-to-envelope(ext:extract-instance-Customer( doc('" + sourceDocument + "') ))", new StringHandle()); String actualDoc = handle.get(); //Get the keys file as controlDoc InputStream is = this.getClass().getResourceAsStream("/test-envelope/" + entityType); Document controlDoc = builder.parse(is); // convert DOM Document into a string StringWriter writer = new StringWriter(); DOMSource domSource = new DOMSource(controlDoc); StreamResult result = new StreamResult(writer); TransformerFactory tf = TransformerFactory.newInstance(); javax.xml.transform.Transformer transformer = null; try {/*from www . j a v a 2s. c om*/ transformer = tf.newTransformer(); } catch (TransformerConfigurationException e) { e.printStackTrace(); } transformer.transform(domSource, result); //logger.info("XML IN String format is: \n" + writer.toString()); //logger.info("actualDoc now ::::" + actualDoc); XMLUnit.setIgnoreWhitespace(true); XMLAssert.assertXMLEqual(writer.toString(), actualDoc); }
From source file:com.marklogic.entityservices.TestEsConversionModuleGenerator.java
@Test public void testInstanceXmlFromDocumentRefSame() throws IOException, TestEvalException, SAXException, TransformerException { String sourceDocument = "10248.xml"; StringHandle handle = evalOneResult( "import module namespace gen = 'http://refSameDocument#Northwind-Ref-Same-Document-0.0.1' at '/conv/valid-ref-same-doc-gen.xqy'; " + "es:instance-xml-from-document(gen:instance-to-envelope(gen:extract-instance-Order( doc('" + sourceDocument + "'))))", new StringHandle()); String actualDoc = handle.get(); //Get the keys file as controlDoc InputStream is = this.getClass() .getResourceAsStream("/test-instance-from-document/refSame-xml-from-document.xml"); Document controlDoc = builder.parse(is); // convert DOM Document into a string StringWriter writer = new StringWriter(); DOMSource domSource = new DOMSource(controlDoc); StreamResult result = new StreamResult(writer); TransformerFactory tf = TransformerFactory.newInstance(); javax.xml.transform.Transformer transformer = null; try {/* ww w . j a va2 s .c o m*/ transformer = tf.newTransformer(); } catch (TransformerConfigurationException e) { e.printStackTrace(); } transformer.transform(domSource, result); //logger.info("XML IN String format is: \n" + writer.toString()); //logger.info("actualDoc now ::::" + actualDoc); XMLUnit.setIgnoreWhitespace(true); XMLAssert.assertXMLEqual("Expected: \n" + writer.toString() + "\n but got: \n" + actualDoc, writer.toString(), actualDoc); }
From source file:com.marklogic.entityservices.TestEsConversionModuleGenerator.java
@Test public void testInstanceXmlFromDocumentNoRef() throws IOException, TestEvalException, SAXException, TransformerException { String entityType = "valid-ref-same-document.xml"; String sourceDocument = "VINET.xml"; String ns = getNameSpace(entityType); StringHandle handle = evalOneResult("import module namespace ext = \"" + ns + "\" at \"/conv/" + entityType.replaceAll("\\.(xml|json)", ".xqy") + "\"; " + "es:instance-xml-from-document(ext:instance-to-envelope(ext:extract-instance-Customer( doc('" + sourceDocument + "'))))", new StringHandle()); String actualDoc = handle.get(); //Get the keys file as controlDoc InputStream is = this.getClass() .getResourceAsStream("/test-instance-from-document/noRef-xml-from-document.xml"); Document controlDoc = builder.parse(is); // convert DOM Document into a string StringWriter writer = new StringWriter(); DOMSource domSource = new DOMSource(controlDoc); StreamResult result = new StreamResult(writer); TransformerFactory tf = TransformerFactory.newInstance(); javax.xml.transform.Transformer transformer = null; try {//from www . j a va 2s . c o m transformer = tf.newTransformer(); } catch (TransformerConfigurationException e) { e.printStackTrace(); } transformer.transform(domSource, result); logger.error("Checking entity type " + entityType); logger.error("XML IN String format is: \n" + writer.toString()); logger.error("actualDoc now ::::" + actualDoc); XMLUnit.setIgnoreWhitespace(true); XMLAssert.assertXMLEqual(writer.toString(), actualDoc); }
From source file:com.marklogic.entityservices.TestEsConversionModuleGenerator.java
@Test public void testInstanceToCanonicalXml() throws IOException, TestEvalException, SAXException, TransformerException { String entityType = "valid-ref-combo-sameDocument-subIri.xml"; String sourceDocument = "10248.xml"; String ns = getNameSpace(entityType); StringHandle handle = evalOneResult("import module namespace ext = \"" + ns + "\" at \"/conv/" + entityType.replaceAll("\\.(xml|json)", ".xqy") + "\"; " + "ext:instance-to-canonical-xml(ext:extract-instance-Order( doc('" + sourceDocument + "') ))", new StringHandle()); String actualDoc = handle.get(); //Get the keys file as controlDoc InputStream is = this.getClass().getResourceAsStream("/test-canonical/" + entityType); Document controlDoc = builder.parse(is); // convert DOM Document into a string StringWriter writer = new StringWriter(); DOMSource domSource = new DOMSource(controlDoc); StreamResult result = new StreamResult(writer); TransformerFactory tf = TransformerFactory.newInstance(); javax.xml.transform.Transformer transformer = null; try {//ww w. j av a 2s . co m transformer = tf.newTransformer(); } catch (TransformerConfigurationException e) { e.printStackTrace(); } transformer.transform(domSource, result); //logger.info("XML IN String format is: \n" + writer.toString()); //logger.info("actualDoc now ::::" + actualDoc); XMLUnit.setIgnoreWhitespace(true); XMLAssert.assertXMLEqual(writer.toString(), actualDoc); }
From source file:com.marklogic.entityservices.TestEsConversionModuleGenerator.java
@Test public void testInstanceToEnvelope2() throws IOException, TestEvalException, SAXException, TransformerException { String entityType = "valid-ref-same-document.xml"; String sourceDocument = "10249.xml"; String ns = getNameSpace(entityType); StringHandle handle = evalOneResult( "import module namespace ext = \"" + ns + "\" at \"/conv/" + entityType.replaceAll("\\.(xml|json)", ".xqy") + "\"; " + "ext:instance-to-envelope(ext:extract-instance-Order( doc('" + sourceDocument + "') ))", new StringHandle()); String actualDoc = handle.get(); //Get the keys file as controlDoc InputStream is = this.getClass().getResourceAsStream("/test-envelope/" + "valid-ref-same-document-2.xml"); Document controlDoc = builder.parse(is); // convert DOM Document into a string StringWriter writer = new StringWriter(); DOMSource domSource = new DOMSource(controlDoc); StreamResult result = new StreamResult(writer); TransformerFactory tf = TransformerFactory.newInstance(); javax.xml.transform.Transformer transformer = null; try {//from www .j a va2s . co m transformer = tf.newTransformer(); } catch (TransformerConfigurationException e) { e.printStackTrace(); } transformer.transform(domSource, result); //logger.info("XML IN String format is: \n" + writer.toString()); //logger.info("actualDoc now ::::" + actualDoc); XMLUnit.setIgnoreWhitespace(true); XMLAssert.assertXMLEqual(writer.toString(), actualDoc); }
From source file:com.marklogic.entityservices.TestEsConversionModuleGenerator.java
@Test public void testInstanceGetAttachments() throws IOException, TestEvalException, SAXException, TransformerException { String entityType = "valid-ref-same-document.xml"; String sourceDocument = "ALFKI.xml"; String ns = getNameSpace(entityType); //String envelopeDoc = "valid-ref-combo-sameDocument-subIri-envelope.xml"; StringHandle handle = evalOneResult("import module namespace ext = \"" + ns + "\" at \"/conv/" + entityType.replaceAll("\\.(xml|json)", ".xqy") + "\"; " + //"xdmp:document-insert('valid-ref-combo-sameDocument-subIri-envelope.xml', ext:instance-to-envelope(ext:extract-instance-Customer( doc('"+sourceDocument+"') )))", new StringHandle()); //StringHandle handle2 = evalOneResult("import module namespace ext = \""+ns+"\" at \"/conv/"+entityType.replaceAll("\\.(xml|json)", ".xqy")+"\"; "+ "es:instance-get-attachments(ext:instance-to-envelope(ext:extract-instance-Customer( doc('" + sourceDocument + "'))))", new StringHandle()); String actualDoc = handle.get(); //Get the keys file as controlDoc InputStream is = this.getClass().getResourceAsStream("/test-attachments/" + entityType); Document controlDoc = builder.parse(is); // convert DOM Document into a string StringWriter writer = new StringWriter(); DOMSource domSource = new DOMSource(controlDoc); StreamResult result = new StreamResult(writer); TransformerFactory tf = TransformerFactory.newInstance(); javax.xml.transform.Transformer transformer = null; try {/* w w w . ja va 2 s .com*/ transformer = tf.newTransformer(); } catch (TransformerConfigurationException e) { e.printStackTrace(); } transformer.transform(domSource, result); //logger.info("XML IN String format is: \n" + writer.toString()); //logger.info("actualDoc now ::::" + actualDoc); XMLUnit.setIgnoreWhitespace(true); XMLAssert.assertXMLEqual(writer.toString(), actualDoc); }
From source file:com.marklogic.entityservices.TestEsConversionModuleGenerator.java
@Test public void testInstanceToCanonicalXml2() throws IOException, TestEvalException, SAXException, TransformerException { String entityType = "valid-ref-same-document.xml"; String sourceDocument = "ALFKI.xml"; String ns = getNameSpace(entityType); StringHandle handle = evalOneResult("import module namespace ext = \"" + ns + "\" at \"/conv/" + entityType.replaceAll("\\.(xml|json)", ".xqy") + "\"; " + "ext:instance-to-canonical-xml(ext:extract-instance-Customer( doc('" + sourceDocument + "') ))", new StringHandle()); String actualDoc = handle.get(); //Get the keys file as controlDoc InputStream is = this.getClass().getResourceAsStream("/test-canonical/" + entityType); Document controlDoc = builder.parse(is); // convert DOM Document into a string StringWriter writer = new StringWriter(); DOMSource domSource = new DOMSource(controlDoc); StreamResult result = new StreamResult(writer); TransformerFactory tf = TransformerFactory.newInstance(); javax.xml.transform.Transformer transformer = null; try {// ww w. ja v a 2 s.c o m transformer = tf.newTransformer(); } catch (TransformerConfigurationException e) { e.printStackTrace(); } transformer.transform(domSource, result); //logger.error("Entity type " + entityType); //logger.error("XML IN String format is: \n" + writer.toString()); //logger.error("actualDoc now ::::" + actualDoc); XMLUnit.setIgnoreWhitespace(true); XMLAssert.assertXMLEqual(writer.toString(), actualDoc); }
From source file:at.ac.tuwien.auto.iotsys.gateway.connectors.knx.KNXDeviceLoaderETSImpl.java
public ArrayList<Connector> initDevices(ObjectBroker objectBroker) { log.info("KNX ETS device loader starting. - connectorsConfig: " + connectorsConfig); setConfiguration(connectorsConfig);/* ww w.j a va2 s .c o m*/ ArrayList<Connector> connectors = new ArrayList<Connector>(); log.info("connectors config now: " + connectorsConfig); Object knxConnectors = connectorsConfig.getProperty("knx-ets.connector.name"); int connectorsSize = 0; if (knxConnectors != null) { connectorsSize = 1; } if (knxConnectors instanceof Collection<?>) { connectorsSize = ((Collection<?>) knxConnectors).size(); } // Networks List networks = new List(); networks.setName("networks"); networks.setOf(new Contract(Network.CONTRACT)); networks.setHref(new Uri("/networks")); boolean networkEnabled = false; for (int connector = 0; connector < connectorsSize; connector++) { HierarchicalConfiguration subConfig = connectorsConfig .configurationAt("knx-ets.connector(" + connector + ")"); // String connectorName = subConfig.getString("name"); String routerIP = subConfig.getString("router.ip"); int routerPort = subConfig.getInteger("router.port", 3671); String localIP = subConfig.getString("localIP"); Boolean enabled = subConfig.getBoolean("enabled", false); Boolean forceRefresh = subConfig.getBoolean("forceRefresh", false); String knxProj = subConfig.getString("knx-proj"); Boolean enableGroupComm = subConfig.getBoolean("groupCommEnabled", false); Boolean enableHistories = subConfig.getBoolean("historyEnabled", false); if (enabled) { if (!networkEnabled) { objectBroker.addObj(networks, true); networkEnabled = true; } File file = new File(knxProj); if (!file.exists() || file.isDirectory() || !file.getName().endsWith(".knxproj") || file.getName().length() < 8) { log.warning("KNX project file " + knxProj + " is not a valid KNX project file."); continue; } String projDirName = knxProj.substring(0, knxProj.length() - 8); File projDir = new File(projDirName); if (!projDir.exists() || forceRefresh) { log.info("Expanding " + knxProj + " into directory " + projDirName); unZip(knxProj, projDirName); } String directory = "./" + knxProj.substring(knxProj.indexOf("/") + 1).replaceFirst(".knxproj", ""); // now the unpacked ETS project should be available in the directory String transformFileName = knxProj.replaceFirst(".knxproj", "") + "/" + file.getName().replaceFirst(".knxproj", "") + ".xml"; File transformFile = new File(transformFileName); if (!transformFile.exists() || forceRefresh) { log.info("Transforming ETS configuration."); // System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl"); // Create a transform factory instance. TransformerFactory tfactory = TransformerFactory.newInstance(); // Create a transformer for the stylesheet. Transformer transformer; try { transformer = tfactory.newTransformer(new StreamSource("knx-config/stylesheet_knx.xsl")); Collection<File> listFiles = FileUtils.listFiles(projDir, FileFilterUtils.nameFileFilter("0.xml"), new IOFileFilter() { @Override public boolean accept(File file) { return true; } @Override public boolean accept(File dir, String name) { return true; } }); if (listFiles.size() != 1) { log.severe("Found no or more than one 0.xml file in " + projDirName); continue; } log.info("Transforming with directory parameter set to " + directory); transformer.setParameter("directory", directory); transformer.transform(new StreamSource(listFiles.iterator().next().getAbsoluteFile()), new StreamResult(transformFileName)); log.info("Transformation completed and result written to: " + transformFileName); } catch (TransformerConfigurationException e) { e.printStackTrace(); } catch (TransformerException e) { e.printStackTrace(); } } try { devicesConfig = new XMLConfiguration(transformFileName); } catch (Exception e) { log.log(Level.SEVERE, e.getMessage(), e); } KNXConnector knxConnector = new KNXConnector(routerIP, routerPort, localIP); connect(knxConnector); initNetworks(knxConnector, objectBroker, networks, enableGroupComm, enableHistories); connectors.add(knxConnector); } } return connectors; }
From source file:com.collabnet.tracker.core.PTrackerWebServicesClient.java
private void printDocument(Document doc) { TransformerFactory tf = TransformerFactory.newInstance(); Transformer t;/*from w ww.j a v a 2 s .com*/ try { t = tf.newTransformer(); StringWriter sw = new StringWriter(); t.transform(new DOMSource(doc), new StreamResult(sw)); log.debug(sw.toString()); } catch (TransformerConfigurationException e) { e.printStackTrace(); } catch (TransformerException e) { e.printStackTrace(); } }