use of javax.xml.transform.Result in project bnd by bndtools.
the class SpringComponent method analyze.
public static Set<CharSequence> analyze(InputStream in) throws Exception {
if (transformer == null) {
TransformerFactory tf = TransformerFactory.newInstance();
Source source = new StreamSource(SpringComponent.class.getResourceAsStream("extract.xsl"));
transformer = tf.newTransformer(source);
}
Set<CharSequence> refers = new HashSet<CharSequence>();
ByteArrayOutputStream bout = new ByteArrayOutputStream();
Result r = new StreamResult(bout);
Source s = new StreamSource(in);
transformer.transform(s, r);
try (BufferedReader br = IO.reader(bout.toString("UTF-8"))) {
String line = br.readLine();
while (line != null) {
line = line.trim();
if (line.length() > 0) {
String[] parts = line.split("\\s*,\\s*");
for (int i = 0; i < parts.length; i++) {
int n = parts[i].lastIndexOf('.');
if (n > 0) {
refers.add(parts[i].subSequence(0, n));
}
}
}
line = br.readLine();
}
}
return refers;
}
use of javax.xml.transform.Result in project Gargoyle by callakrsos.
the class DesignerFx method saveSettings.
private void saveSettings() {
try {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.newDocument();
Element settingsElement = document.createElement("settings");
document.appendChild(settingsElement);
Element codeElement = document.createElement("code");
settingsElement.appendChild(codeElement);
codeElement.setAttribute("language-version", getLanguageVersion().getTerseName());
codeElement.appendChild(document.createCDATASection(codeEditorPane.getText()));
Element xpathElement = document.createElement("xpath");
settingsElement.appendChild(xpathElement);
Object userData = xpathVersionButtonGroup.getSelectedToggle().getUserData();
xpathElement.setAttribute("version", userData.toString());
// xpathElement.setAttribute("version", xpathVersionButtonGroup.getSelection().getActionCommand());
xpathElement.appendChild(document.createCDATASection(xpathQueryArea.getText()));
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
// This is as close to pretty printing as we'll get using standard Java APIs.
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "3");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
Source source = new DOMSource(document);
Result result = new StreamResult(new FileWriter(new File(SETTINGS_FILE_NAME)));
transformer.transform(source, result);
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (TransformerException e) {
e.printStackTrace();
}
}
use of javax.xml.transform.Result in project linuxtools by eclipse.
the class AbstractDataAdapter method getInputStream.
/**
* @return an InputStream to the newly created XML data.
*/
public InputStream getInputStream() {
InputStream inp = null;
Source source = new DOMSource(getDocument());
StringWriter stw = new StringWriter();
Result result = new StreamResult(stw);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer xformer;
try {
xformer = factory.newTransformer();
// $NON-NLS-1$ //$NON-NLS-2$
xformer.setOutputProperty("indent", "yes");
xformer.transform(source, result);
inp = new ByteArrayInputStream(stw.toString().getBytes(StandardCharsets.UTF_8));
} catch (TransformerException e) {
e.printStackTrace();
}
return inp;
}
use of javax.xml.transform.Result in project linuxtools by eclipse.
the class SessionManager method writeToFile.
/**
* Write the contents of the given Document to a file.
*/
private void writeToFile(String filePath) {
Source source = new DOMSource(doc);
Result result = new StreamResult(new File(filePath));
TransformerFactory factory = TransformerFactory.newInstance();
Transformer xformer;
try {
xformer = factory.newTransformer();
xformer.transform(source, result);
} catch (TransformerException e) {
e.printStackTrace();
}
}
use of javax.xml.transform.Result in project cxf by apache.
the class XSLTJaxbProvider method marshalToOutputStream.
@Override
protected void marshalToOutputStream(Marshaller ms, Object obj, OutputStream os, Annotation[] anns, MediaType mt) throws Exception {
Templates t = createTemplates(getOutTemplates(anns, mt), outParamsMap, outProperties);
if (t == null && supportJaxbOnly) {
super.marshalToOutputStream(ms, obj, os, anns, mt);
return;
}
org.apache.cxf.common.jaxb.JAXBUtils.setMinimumEscapeHandler(ms);
TransformerHandler th = null;
try {
th = factory.newTransformerHandler(t);
} catch (TransformerConfigurationException ex) {
TemplatesImpl ti = (TemplatesImpl) t;
th = factory.newTransformerHandler(ti.getTemplates());
this.trySettingProperties(th, ti);
}
Result result = new StreamResult(os);
if (systemId != null) {
result.setSystemId(systemId);
}
th.setResult(result);
if (getContext() == null) {
th.startDocument();
}
ms.marshal(obj, th);
if (getContext() == null) {
th.endDocument();
}
}
Aggregations