List of usage examples for javax.xml.transform TransformerException printStackTrace
@Override public void printStackTrace()
From source file:org.alfresco.util.XMLUtil.java
/** utility function for serializing a node */ public static void print(final Node n, final Writer output, final boolean indent) { try {//from w ww.java 2 s . com final TransformerFactory tf = TransformerFactory.newInstance(); final Transformer t = tf.newTransformer(); t.setOutputProperty(OutputKeys.INDENT, indent ? "yes" : "no"); t.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); t.setOutputProperty(OutputKeys.METHOD, "xml"); if (LOGGER.isDebugEnabled()) { LOGGER.debug("writing out a document for " + (n instanceof Document ? ((Document) n).getDocumentElement() : n).getNodeName() + " to " + (output instanceof StringWriter ? "string" : output)); } t.transform(new DOMSource(n), new StreamResult(output)); } catch (TransformerException te) { te.printStackTrace(); assert false : te.getMessage(); } }
From source file:org.dbpedia.spotlight.string.XmlParser.java
public static NodeList getNodes(String xpathExpr, Element rootTag) { NodeList nodesFound = null;/*ww w . ja v a2s . com*/ try { nodesFound = XPathAPI.selectNodeList(rootTag, xpathExpr); } catch (TransformerException e) { // TODO Auto-generated catch block e.printStackTrace(); } return nodesFound; }
From source file:org.eclipse.wst.xsl.xalan.debugger.XalanVariable.java
public String getValue() { String value = "???"; try {/*from w w w . j a va 2s. c o m*/ xobject = getXObject(); if (xobject != null) { int xalanType = xobject.getType(); switch (xalanType) { case XObject.CLASS_UNRESOLVEDVARIABLE: value = ""; break; case XObject.CLASS_NODESET: XNodeSet xns = (XNodeSet) xobject; if (xns.nodelist().getLength() > 0) { value = convertNode(xns); } else value = "<EMPTY NODESET>"; break; case XObject.CLASS_BOOLEAN: case XObject.CLASS_NUMBER: case XObject.CLASS_STRING: case XObject.CLASS_UNKNOWN: default: value = xobject.toString(); break; } } } catch (TransformerException e) { e.printStackTrace(); } // value = getScope()+"."+getSlotNumber()+")"+getName(); // log.debug(getScope()+"."+getSlotNumber()+")"+getName() + "=" + // value); return value; }
From source file:org.gnucash.android.export.ExporterTask.java
/** * Writes out the document held in <code>node</code> to <code>outputWriter</code> * @param node {@link Node} containing the OFX document structure. Usually the parent node * @param outputWriter {@link Writer} to use in writing the file to stream * @param omitXmlDeclaration Flag which causes the XML declaration to be omitted *//* w w w . ja v a 2 s. c o m*/ public void write(Node node, Writer outputWriter, boolean omitXmlDeclaration) { try { TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(node); StreamResult result = new StreamResult(outputWriter); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); if (omitXmlDeclaration) { transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); } transformer.transform(source, result); } catch (TransformerConfigurationException txconfigException) { txconfigException.printStackTrace(); } catch (TransformerException tfException) { tfException.printStackTrace(); } }
From source file:org.gnucash.android.ui.accounts.ExportDialogFragment.java
/** * Writes out the file held in <code>document</code> to <code>outputWriter</code> * @param document {@link Document} containing the OFX document structure * @param outputWriter {@link Writer} to use in writing the file to stream */// w ww .ja va 2 s . c om public void write(Document document, Writer outputWriter) { try { TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(document); StreamResult result = new StreamResult(outputWriter); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.transform(source, result); } catch (TransformerConfigurationException txconfigException) { txconfigException.printStackTrace(); } catch (TransformerException tfException) { tfException.printStackTrace(); } }
From source file:org.jboss.windup.decorator.xml.XPathSummaryDecorator.java
protected void createLineNumberMeta(final XmlMetadata meta, Integer lineNumber, String descripiton, Node match) {/* www . ja va 2 s . c o m*/ XmlLine result = new XmlLine(); result.setDescription(descripiton); try { result.setPattern(convertNode(match)); } catch (TransformerException e) { e.printStackTrace(); } result.setMatchedNode(match); result.setLineNumber(lineNumber); result.setEffort(effort); for (ResultProcessor hint : hints) { hint.process(result); } meta.getDecorations().add(result); }
From source file:org.kalypso.model.hydrology.util.optimize.NAOptimizingJob.java
/** * @see org.kalypso.optimize.IOptimizingJob#optimize(org.kalypso.optimizer.Parameter[], double[]) *///from w w w. j a v a 2 s . c om @Override public void optimize(final Parameter[] parameterConf, final double[] values) throws Exception { final ParameterOptimizeContext[] calcContexts = new ParameterOptimizeContext[parameterConf.length]; for (int i = 0; i < parameterConf.length; i++) calcContexts[i] = new ParameterOptimizeContext(parameterConf[i]); try { final GMLWorkspace contextWorkspace = m_data.getModelWorkspace(); final NaOptimizeData optimizeData = m_data.getOptimizeData(); optimizeData.applyCalibration(values, calcContexts, contextWorkspace); } catch (final TransformerException e) { e.printStackTrace(); } }
From source file:org.mule.ibeans.IBeansSupport.java
/** * Returns a formatted XML string representation of an XML Node or Document. This is useful for debugging or for * capturing data that can be used for Mock testing. * @param node the Xml to read//from w ww . j a va 2 s .c o m * @return a formated XML string */ public static String prettyPrintXml(Node node) { try { // Set up the output transformer TransformerFactory transfac = TransformerFactory.newInstance(); javax.xml.transform.Transformer trans = transfac.newTransformer(); trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); trans.setOutputProperty(OutputKeys.INDENT, "yes"); // Print the DOM node StringWriter sw = new StringWriter(); StreamResult result = new StreamResult(sw); DOMSource source = new DOMSource(node); trans.transform(source, result); return sw.toString(); } catch (TransformerException e) { e.printStackTrace(); return null; } }
From source file:org.n52.wps.ags.algorithmpackage.AlgorithmPackage.java
/** * Generates an XML file. Uses a ProcessDescription file and a XSLT file to generate an * AlgorithmDescription./*w w w . java 2s . com*/ * * @param xmlFile - the ProcessDescription in XML * @param xsltFile - the transformation rules in XSLT * @throws Exception - the exceptions */ private static StringReader generateAlgorithmDescription(File xmlFile) { Source xmlSource = new StreamSource(xmlFile); TransformerFactory transFact = TransformerFactory.newInstance(); StringWriter sw = new StringWriter(); StreamResult transformResult = new StreamResult(sw); try { Source xsltSource = transFact.getAssociatedStylesheet(xmlSource, null, null, null); Transformer trans = transFact.newTransformer(xsltSource); trans.transform(xmlSource, transformResult); StringReader sr = new StringReader(sw.toString()); return sr; } catch (TransformerException e) { LOGGER.error("Error evaluating ProcessDescription XML."); e.printStackTrace(); } return null; }
From source file:org.ncbo.stanford.service.xml.impl.XMLSerializationServiceImpl.java
/** * Generates XML response then apply XSL transformation. This is useful to * filter huge XML response such as findAll() Ontologies. * //from w w w. j a va 2 s.co m * If SUCCESS - Entity info is displayed. else - Error info is displayed. * * @param request * @param response * @param data * @param xsltFile */ public void generateXMLResponse(Request request, Response response, Object data, String xsltFile) { if (response.getStatus().isError()) { generateStatusXMLResponse(request, response); } else { MediaType prefMediaType = getPreferredMediaType(request); if (prefMediaType.equals(MediaType.APPLICATION_JSON)) { generateXMLResponse(request, response, data); } else { try { RequestUtils.setHttpServletResponse(response, Status.SUCCESS_OK, prefMediaType, applyXSL(request, data, xsltFile)); } catch (TransformerException e) { // XML parse ERROR response.setStatus(Status.SERVER_ERROR_INTERNAL, e.getMessage()); generateStatusXMLResponse(request, response); e.printStackTrace(); log.error(e); } } } }