List of usage examples for javax.xml.transform OutputKeys METHOD
String METHOD
To view the source code for javax.xml.transform OutputKeys METHOD.
Click Source Link
From source file:org.slc.sli.scaffold.DocumentManipulator.java
/** * Serializes a document to html//from w w w .ja va 2 s.c om * * @param document * @param outputFile * @param xslFile * @throws DocumentManipulatorException */ public void serializeDocumentToHtml(Document document, File outputFile, File xslFile) throws DocumentManipulatorException { FileOutputStream fileOutput = null; StreamSource xslSource = null; Properties props = new Properties(); // set the output properties props.put(OutputKeys.METHOD, "html"); try { fileOutput = new FileOutputStream(outputFile); // create the stream source from the xsl stylesheet xslSource = new StreamSource(xslFile); serialize(document, new StreamResult(fileOutput), xslSource, props); } catch (FileNotFoundException e) { throw new DocumentManipulatorException(e); } }
From source file:org.slc.sli.scaffold.DocumentManipulator.java
/** * Serializes a document to string//from ww w. j ava 2 s.co m * * @param document * @return * @throws DocumentManipulatorException */ public String serializeDocumentToString(Document document) throws DocumentManipulatorException { StringWriter outText = new StringWriter(); Properties props = new Properties(); props.put(OutputKeys.METHOD, "xml"); serialize(document, new StreamResult(outText), null, props); return outText.toString(); }
From source file:org.soa4all.dashboard.gwt.module.wsmolite.server.WsmoLiteDataServiceImpl.java
private String getXMLString(Document doc) throws Exception { StringWriter buffer = new StringWriter(); Transformer tr = TransformerFactory.newInstance().newTransformer(); tr.setOutputProperty(OutputKeys.METHOD, "xml"); tr.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); tr.transform(new DOMSource(doc), new StreamResult(buffer)); return buffer.getBuffer().toString(); }
From source file:org.springsource.ide.eclipse.commons.browser.javafx.JavaFxBrowserManager.java
/** * For debugging..//from w w w . j a va 2 s.c o m */ private void printPageHtml() { StringWriter sw = new StringWriter(); try { TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.setOutputProperty(OutputKeys.METHOD, "html"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.transform(new DOMSource(getView().getEngine().getDocument()), new StreamResult(sw)); System.out.println(sw.toString()); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.tizzit.util.XercesHelper.java
public static String doc2String(Document doc) { StringWriter stringOut = new StringWriter(); try {/*from w ww . j a va 2 s . co m*/ Transformer t = TransformerFactory.newInstance().newTransformer(); t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); t.setOutputProperty(OutputKeys.METHOD, "xml"); t.transform(new DOMSource(doc), new StreamResult(stringOut)); /*OutputFormat format = new OutputFormat(doc, "ISO-8859-1", true); format.setOmitXMLDeclaration(true); format.setOmitDocumentType(true); stringOut = new StringWriter(); XMLSerializer serial = new XMLSerializer(stringOut, format); serial.asDOMSerializer(); serial.serialize(doc);*/ } catch (Exception exe) { log.error("unknown error occured", exe); } return stringOut.toString(); }
From source file:org.tizzit.util.XercesHelper.java
public static String node2Html(Node node) { Document doc = getNewDocument(); Node newnde = doc.importNode(node, true); doc.appendChild(newnde);/* w w w .j a v a2 s .c o m*/ StringWriter stringOut = new StringWriter(); try { Transformer t = TransformerFactory.newInstance().newTransformer(); // for "XHTML" serialization, use the output method "xml" and set publicId as shown /*t.setOutputProperty(OutputKeys.METHOD, "xml"); t.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, "-//W3C//DTD XHTML 1.0 Transitional//EN"); t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd");*/ t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); t.setOutputProperty(OutputKeys.METHOD, "xml"); t.transform(new DOMSource(doc), new StreamResult(stringOut)); } catch (Exception exe) { log.error("unknown error occured", exe); } return stringOut.toString(); }
From source file:org.tizzit.util.xml.SAXHelper.java
/** * @param node the string to stream./*from www .j av a2 s .co m*/ * @param handler the content handler. * @since tizzit-common 15.10.2009 */ public static void string2sax(String node, ContentHandler handler) { try { Transformer t = TransformerFactory.newInstance().newTransformer(); t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); t.setOutputProperty(OutputKeys.STANDALONE, "no"); t.setOutputProperty(OutputKeys.METHOD, "xml"); StreamSource source = new StreamSource(new StringReader(node)); SAXResult result = new SAXResult(new OmitXmlDeclarationContentHandler(handler)); t.transform(source, result); } catch (Exception exe) { log.error("unknown error occured", exe); } }
From source file:org.tizzit.util.xml.SAXHelper.java
/** * @param node the string to stream.// ww w.jav a 2s . c om * @param handler the content handler. * @since tizzit-common 15.10.2009 */ public static void string2sax(String node, ContentHandler handler, String encoding) { try { Transformer t = TransformerFactory.newInstance().newTransformer(); t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); t.setOutputProperty(OutputKeys.STANDALONE, "no"); t.setOutputProperty(OutputKeys.METHOD, "xml"); if (!"".equals(encoding) && encoding != null) { t.setOutputProperty(OutputKeys.ENCODING, encoding); } StreamSource source = new StreamSource(new StringReader(node)); SAXResult result = new SAXResult(new OmitXmlDeclarationContentHandler(handler)); t.transform(source, result); } catch (Exception exe) { log.error("unknown error occured", exe); } }
From source file:org.wandora.application.gui.topicpanels.webview.WebViewPanel.java
private void initFX(final JFXPanel fxPanel) { Group group = new Group(); Scene scene = new Scene(group); fxPanel.setScene(scene);//from w w w . j a v a 2 s. c o m webView = new WebView(); if (javaFXVersionInt >= 8) { webView.setScaleX(1.0); webView.setScaleY(1.0); //webView.setFitToHeight(false); //webView.setFitToWidth(false); //webView.setZoom(javafx.stage.Screen.getPrimary().getDpi() / 96); } group.getChildren().add(webView); int w = this.getWidth(); int h = this.getHeight() - 34; webView.setMinSize(w, h); webView.setMaxSize(w, h); webView.setPrefSize(w, h); // Obtain the webEngine to navigate webEngine = webView.getEngine(); webEngine.locationProperty().addListener(new ChangeListener<String>() { @Override public void changed(ObservableValue<? extends String> observable, String oldValue, final String newValue) { if (newValue.endsWith(".pdf")) { try { int a = WandoraOptionPane.showConfirmDialog(Wandora.getWandora(), "Open PDF document in external application?", "Open PDF document in external application?", WandoraOptionPane.YES_NO_OPTION); if (a == WandoraOptionPane.YES_OPTION) { Desktop dt = Desktop.getDesktop(); dt.browse(new URI(newValue)); } } catch (Exception e) { } } else { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { urlTextField.setText(newValue); } }); } } }); webEngine.titleProperty().addListener(new ChangeListener<String>() { @Override public void changed(ObservableValue<? extends String> observable, String oldValue, final String newValue) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { title = newValue; } }); } }); webEngine.setOnAlert(new EventHandler<WebEvent<java.lang.String>>() { @Override public void handle(WebEvent<String> t) { if (t != null) { String str = t.getData(); if (str != null && str.length() > 0) { WandoraOptionPane.showMessageDialog(Wandora.getWandora(), str, "Javascript Alert", WandoraOptionPane.PLAIN_MESSAGE); } } } }); webEngine.setConfirmHandler(new Callback<String, Boolean>() { @Override public Boolean call(String msg) { int a = WandoraOptionPane.showConfirmDialog(Wandora.getWandora(), msg, "Javascript Alert", WandoraOptionPane.YES_NO_OPTION); return (a == WandoraOptionPane.YES_OPTION); } }); webEngine.setPromptHandler(new Callback<PromptData, String>() { @Override public String call(PromptData data) { String a = WandoraOptionPane.showInputDialog(Wandora.getWandora(), data.getMessage(), data.getDefaultValue(), "Javascript Alert", WandoraOptionPane.QUESTION_MESSAGE); return a; } }); webEngine.setCreatePopupHandler(new Callback<PopupFeatures, WebEngine>() { @Override public WebEngine call(PopupFeatures features) { if (informPopupBlocking) { WandoraOptionPane.showMessageDialog(Wandora.getWandora(), "A javascript popup has been blocked. Wandora doesn't allow javascript popups in Webview topic panel.", "Javascript popup blocked", WandoraOptionPane.PLAIN_MESSAGE); } informPopupBlocking = false; return null; } }); webEngine.setOnVisibilityChanged(new EventHandler<WebEvent<Boolean>>() { @Override public void handle(WebEvent<Boolean> t) { if (t != null) { Boolean b = t.getData(); if (informVisibilityChanges) { WandoraOptionPane.showMessageDialog(Wandora.getWandora(), "A browser window visibility change has been blocked. Wandora doesn't allow visibility changes of windows in Webview topic panel.", "Javascript visibility chnage blocked", WandoraOptionPane.PLAIN_MESSAGE); informVisibilityChanges = false; } } } }); webEngine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() { @Override public void changed(ObservableValue ov, State oldState, State newState) { if (newState == Worker.State.SCHEDULED) { //System.out.println("Scheduled!"); startLoadingAnimation(); } if (newState == Worker.State.SUCCEEDED) { Document doc = webEngine.getDocument(); try { Transformer transformer = TransformerFactory.newInstance().newTransformer(); //transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); // transformer.transform(new DOMSource(doc), new StreamResult(new OutputStreamWriter(System.out, "UTF-8"))); StringWriter stringWriter = new StringWriter(); transformer.transform(new DOMSource(doc), new StreamResult(stringWriter)); webSource = stringWriter.toString(); } catch (Exception ex) { ex.printStackTrace(); } stopLoadingAnimation(); } else if (newState == Worker.State.CANCELLED) { //System.out.println("Cancelled!"); stopLoadingAnimation(); } else if (newState == Worker.State.FAILED) { webEngine.loadContent(failedToOpenMessage); stopLoadingAnimation(); } } }); }
From source file:org.wisdom.content.jackson.JacksonSingleton.java
/** * Retrieves the string form of the given XML document. * * @param document the XML document, must not be {@literal null} * @return the String form of the object *///from w w w . j a v a2 s . co m @Override public String stringify(Document document) { try { StringWriter sw = new StringWriter(); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.transform(new DOMSource(document), new StreamResult(sw)); return sw.toString(); } catch (TransformerException e) { throw new RuntimeException(e); } }