List of usage examples for javax.xml.transform TransformerConfigurationException printStackTrace
@Override public void printStackTrace()
From source file:org.jasig.portlet.maps.tools.MapDataTransformer.java
/** * @param args/*from w w w. j a v a2 s. co m*/ */ public static void main(String[] args) { // translate the KML file to the map portlet's native data format File kml = new File("map-data.xml"); File xslt = new File("google-earth.xsl"); try { TransformerFactory transFact = javax.xml.transform.TransformerFactory.newInstance(); Transformer trans = transFact.newTransformer(new StreamSource(xslt)); trans.transform(new StreamSource(kml), new StreamResult(System.out)); } catch (TransformerConfigurationException e) { e.printStackTrace(); } catch (TransformerException e) { e.printStackTrace(); } // deserialize the map data from XML MapData data = null; try { JAXBContext jc = JAXBContext.newInstance(MapData.class); Unmarshaller u = jc.createUnmarshaller(); data = (MapData) u.unmarshal(new FileInputStream(new File("map-data-transformed.xml"))); } catch (JAXBException e1) { e1.printStackTrace(); return; } catch (FileNotFoundException e) { e.printStackTrace(); return; } // ensure each location has a unique, non-null abbreviation setAbbreviations(data); // update each location with an address // setAddresses(data); // sort locations by name Collections.sort(data.getLocations(), new ByNameLocationComparator()); // serialize new map data out to a file into JSON format try { mapper.defaultPrettyPrintingWriter().writeValue(new File("map.json"), data); } catch (JsonGenerationException e) { System.out.println("Error generating JSON data for map"); e.printStackTrace(); } catch (JsonMappingException e) { System.out.println("Error generating JSON data for map"); e.printStackTrace(); } catch (IOException e) { System.out.println("Error writing JSON data to map file"); e.printStackTrace(); } }
From source file:Main.java
public static void setDocument(Document document, String fileName) { try {/* ww w .ja v a 2s . com*/ TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource domSource = new DOMSource(document); StreamResult streamResult = new StreamResult(new File(fileName)); transformer.transform(domSource, streamResult); } catch (TransformerConfigurationException e) { e.printStackTrace(); } catch (TransformerException e) { e.printStackTrace(); } }
From source file:Main.java
public static void transfer(Document doc, String filepath) { try {//from w w w.j a va 2 s . c o m Transformer tf = tff.newTransformer(); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(filepath); tf.transform(source, result); } catch (TransformerConfigurationException e) { e.printStackTrace(); } catch (TransformerException e) { e.printStackTrace(); } }
From source file:Main.java
/** * output result to object/*from www . j a v a 2 s . c om*/ * @param ds input DOM Source * @param sr output stream result */ public static void OutputXmlStream(DOMSource ds, StreamResult sr) { Transformer t; try { t = TransformerFactory.newInstance().newTransformer(); t.transform(ds, sr); } catch (TransformerConfigurationException e) { e.printStackTrace(); } catch (TransformerFactoryConfigurationError e) { e.printStackTrace(); } catch (TransformerException e) { e.printStackTrace(); } }
From source file:Main.java
public static void transfor(Document doc, OutputStream out) { try {/* www . j a v a 2s.c o m*/ Transformer tf = tff.newTransformer(); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(out); tf.transform(source, result); } catch (TransformerConfigurationException e) { e.printStackTrace(); } catch (TransformerException e) { e.printStackTrace(); } }
From source file:Main.java
public static OutputStream writeDocument(Document doc, OutputStream os) { TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer;// w ww.j a va 2 s .c o m try { transformer = tFactory.newTransformer(); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(os); transformer.transform(source, result); } catch (TransformerConfigurationException e) { e.printStackTrace(); } catch (TransformerException e) { e.printStackTrace(); } return os; }
From source file:Main.java
private static void WriteXMLFile(Document doc, OutputStreamWriter w, String encoding) { try {/*from w ww . j a va2s . co m*/ Source source = new DOMSource(doc); Result ret = new StreamResult(w); Transformer xformer = TransformerFactory.newInstance().newTransformer(); xformer.setOutputProperty(OutputKeys.ENCODING, encoding); xformer.transform(source, ret); } catch (TransformerConfigurationException e) { e.printStackTrace(); } catch (TransformerException e) { e.printStackTrace(); } }
From source file:Main.java
public static boolean write(Document doc, String path) { boolean result = false; try {/* w w w. j a v a2 s .c o m*/ DOMSource inputDoc = new DOMSource(doc); StreamResult sr = new StreamResult(path); TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf.newTransformer(); t.setOutputProperty(OutputKeys.INDENT, "yes"); t.transform(inputDoc, sr); result = true; } catch (TransformerConfigurationException e) { e.printStackTrace(); } catch (TransformerException e) { e.printStackTrace(); } return result; }
From source file:Main.java
public static String xmlToString(Document xml) { TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = null; try {/*from w ww.j av a2 s .co m*/ transformer = tFactory.newTransformer(); } catch (TransformerConfigurationException e) { e.printStackTrace(); } DOMSource source = new DOMSource(xml); StringWriter writer = new StringWriter(); try { transformer.transform(source, new StreamResult(writer)); } catch (TransformerException e) { e.printStackTrace(); } return writer.toString(); }
From source file:Main.java
public static String getXmlPage(String xmlString, int page, String xslPath) { String styledResponse = ""; StringReader rd = new StringReader(xmlString); StringWriter wrt = new StringWriter(); TransformerFactory tFac = TransformerFactory.newInstance(); try {//w w w.j a v a 2s . co m File xsl = new File(xslPath); Transformer transformer = tFac.newTransformer(new StreamSource(xsl)); transformer.setParameter("Page", String.format("%s", page)); transformer.transform(new StreamSource(rd), new StreamResult(wrt)); styledResponse = wrt.toString(); } catch (TransformerConfigurationException e) { e.printStackTrace(); } catch (TransformerException e) { e.printStackTrace(); } return styledResponse; }