use of javax.xml.transform.Transformer in project opennms by OpenNMS.
the class QuickBaseAPITest method XXXtestCreateLead.
public void XXXtestCreateLead() {
PrintWriter out = null;
try {
out = new PrintWriter(System.out);
out.println("Welcome to QuickBase\n");
QuickBaseClient qdb = createClient();
qdb.findDbByName("TPMG Support");
HashMap tables = (HashMap) qdb.grantedDBs(false, false, true);
if (tables == null) {
out.println("No tables belong to this user.");
}
Set tableNames = tables.keySet();
String tableName = "";
String tableDbid = "";
for (Iterator it = tableNames.iterator(); it.hasNext(); ) {
tableName = (String) it.next();
tableDbid = (String) tables.get(tableName);
out.println("Name: " + tableName + " DBID: " + tableDbid);
Document schema = qdb.getSchema(tableDbid);
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.transform(new DOMSource(schema), new StreamResult(out));
NodeList fields = schema.getElementsByTagName("field");
out.println("The QuickBase application " + tableName + " has " + fields.getLength() + " fields.");
out.println("The fields are listed below.");
for (int i = 0; i < fields.getLength(); i++) {
out.println("Field ID: " + fields.item(i).getAttributes().getNamedItem("id").getNodeValue());
out.println("Field Type: " + fields.item(i).getAttributes().getNamedItem("type").getNodeValue());
out.println("Field Label: " + fields.item(i).getChildNodes().item(0).getNodeValue());
}
}
} catch (QuickBaseException qdbe) {
System.err.println("Exception in main " + qdbe.toString() + " error code: " + qdbe.getErrorCode());
qdbe.printStackTrace();
} catch (Throwable e) {
System.err.println("Exception in main " + e.toString());
e.printStackTrace();
} finally {
if (null != out) {
out.flush();
out.close();
}
}
}
use of javax.xml.transform.Transformer in project opennms by OpenNMS.
the class OnmsPdfViewResolver method resolveView.
@Override
public void resolveView(ServletRequest request, ServletResponse response, Preferences preferences, Object viewData) throws Exception {
InputStream is = new ByteArrayInputStream(((String) viewData).getBytes(StandardCharsets.UTF_8));
ByteArrayOutputStream out = new ByteArrayOutputStream();
FopFactory fopFactory = FopFactory.newInstance();
fopFactory.setStrictValidation(false);
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
TransformerFactory tfact = TransformerFactory.newInstance();
Transformer transformer = tfact.newTransformer();
Source src = new StreamSource(is);
Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(src, res);
byte[] contents = out.toByteArray();
response.setContentLength(contents.length);
response.getOutputStream().write(contents);
}
use of javax.xml.transform.Transformer in project tdi-studio-se by Talend.
the class FeaturesModel method internalGetContent.
private InputStream internalGetContent() throws Exception {
Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
Element features = document.createElement("features");
features.setAttribute("xmlns", "http://karaf.apache.org/xmlns/features/v1.0.0");
features.setAttribute("name", getArtifactId());
document.appendChild(features);
Element feature = document.createElement("feature");
feature.setAttribute("name", getArtifactId());
feature.setAttribute("version", getVersion());
features.appendChild(feature);
// add sub features
for (FeatureModel fm : subFeatures) {
Element subFeature = document.createElement("feature");
if (null != fm.getVersion() && !fm.getVersion().isEmpty()) {
subFeature.setAttribute("version", fm.getVersion());
}
subFeature.appendChild(document.createTextNode(fm.getArtifactId()));
feature.appendChild(subFeature);
}
// add sub bundles
for (BundleModel bm : subBundles) {
Element bundle = document.createElement("bundle");
bundle.appendChild(document.createTextNode(toBundleString(bm)));
feature.appendChild(bundle);
}
if (null == contexts || contexts.isEmpty()) {
// add config
Element config = document.createElement("config");
config.setAttribute("name", configName);
StringBuilder sb = new StringBuilder("talendcontext=\"");
for (int i = 0; i < contextList.length; i++) {
if (i != 0) {
sb.append(',');
}
sb.append(contextList[i]);
}
sb.append('"');
config.appendChild(document.createTextNode(sb.toString()));
feature.appendChild(config);
} else {
// add contexts config
for (Map.Entry<String, Map<String, String>> context : contexts.entrySet()) {
Element config = document.createElement("config");
config.setAttribute("name", name + ".talendcontext." + context.getKey());
StringBuilder sb = new StringBuilder("\n");
for (Map.Entry<String, String> property : context.getValue().entrySet()) {
sb.append(property.getKey());
sb.append('=');
sb.append(property.getValue());
sb.append('\n');
}
config.appendChild(document.createTextNode(sb.toString()));
feature.appendChild(config);
}
}
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
ByteArrayOutputStream os = new ByteArrayOutputStream();
transformer.transform(new DOMSource(document), new StreamResult(os));
return new ByteArrayInputStream(os.toByteArray());
}
use of javax.xml.transform.Transformer in project zm-mailbox by Zimbra.
the class QuotedTextUtil method getHtml.
/**
* Convert the DOM document back to HTML string
*
* @param document
* @return String the String representation of the DOM document
*/
private String getHtml(Document document) {
try {
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
transformer.transform(new DOMSource(document), result);
return writer.toString();
} catch (TransformerException e) {
ZimbraLog.soap.warn("Exception in converting DOM to html", e);
}
return null;
}
use of javax.xml.transform.Transformer in project zm-mailbox by Zimbra.
the class XsdCleaner method getTranformer.
public static Transformer getTranformer() {
try {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
return transformer;
} catch (TransformerFactoryConfigurationError | TransformerException e) {
LOG.error("XsdCleaner:Problem getting XML Transformer", e);
}
return null;
}
Aggregations