use of javax.xml.transform.TransformerException in project spring-framework by spring-projects.
the class JibxMarshaller method transformAndMarshal.
private void transformAndMarshal(Object graph, Result result) throws IOException {
try {
ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
marshalOutputStream(graph, os);
ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
Transformer transformer = this.transformerFactory.newTransformer();
transformer.transform(new StreamSource(is), result);
} catch (TransformerException ex) {
throw new MarshallingFailureException("Could not transform to [" + ClassUtils.getShortName(result.getClass()) + "]", ex);
}
}
use of javax.xml.transform.TransformerException in project robovm by robovm.
the class Compiler method compileFunction.
/**
* Compile a built-in XPath function.
*
* @param opPos The current position in the m_opMap array.
*
* @return reference to {@link org.apache.xpath.functions.Function} instance.
*
* @throws TransformerException if a error occurs creating the Expression.
*/
Expression compileFunction(int opPos) throws TransformerException {
int endFunc = opPos + getOp(opPos + 1) - 1;
opPos = getFirstChildPos(opPos);
int funcID = getOp(opPos);
opPos++;
if (-1 != funcID) {
Function func = m_functionTable.getFunction(funcID);
if (func instanceof FuncExtFunctionAvailable)
((FuncExtFunctionAvailable) func).setFunctionTable(m_functionTable);
func.postCompileStep(this);
try {
int i = 0;
for (int p = opPos; p < endFunc; p = getNextOpPos(p), i++) {
// System.out.println("argPos: "+ p);
// System.out.println("argCode: "+ m_opMap[p]);
func.setArg(compile(p), i);
}
func.checkNumberArgs(i);
} catch (WrongNumberArgsException wnae) {
java.lang.String name = m_functionTable.getFunctionName(funcID);
m_errorHandler.fatalError(new TransformerException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_ONLY_ALLOWS, new Object[] { name, wnae.getMessage() }), m_locator));
//"name + " only allows " + wnae.getMessage() + " arguments", m_locator));
}
return func;
} else {
//"function token not found.");
error(XPATHErrorResources.ER_FUNCTION_TOKEN_NOT_FOUND, null);
return null;
}
}
use of javax.xml.transform.TransformerException in project robovm by robovm.
the class DOM2Helper method parse.
/**
* Parse an XML document.
*
* <p>Right now the Xerces DOMParser class is used. This needs
* fixing, either via jaxp, or via some other, standard method.</p>
*
* <p>The application can use this method to instruct the SAX parser
* to begin parsing an XML document from any valid input
* source (a character stream, a byte stream, or a URI).</p>
*
* <p>Applications may not invoke this method while a parse is in
* progress (they should create a new Parser instead for each
* additional XML document). Once a parse is complete, an
* application may reuse the same Parser object, possibly with a
* different input source.</p>
*
* @param source The input source for the top-level of the
* XML document.
*
* @throws TransformerException if any checked exception is thrown.
* @xsl.usage internal
*/
public void parse(InputSource source) throws TransformerException {
try {
// I guess I should use JAXP factory here... when it's legal.
// org.apache.xerces.parsers.DOMParser parser
// = new org.apache.xerces.parsers.DOMParser();
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
builderFactory.setNamespaceAware(true);
builderFactory.setValidating(true);
DocumentBuilder parser = builderFactory.newDocumentBuilder();
/*
// domParser.setFeature("http://apache.org/xml/features/dom/create-entity-ref-nodes", getShouldExpandEntityRefs()? false : true);
if(m_useDOM2getNamespaceURI)
{
parser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", true);
parser.setFeature("http://xml.org/sax/features/namespaces", true);
}
else
{
parser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false);
}
parser.setFeature("http://apache.org/xml/features/allow-java-encodings", true);
*/
parser.setErrorHandler(new org.apache.xml.utils.DefaultErrorHandler());
// if(null != m_entityResolver)
// {
// System.out.println("Setting the entity resolver.");
// parser.setEntityResolver(m_entityResolver);
// }
setDocument(parser.parse(source));
} catch (org.xml.sax.SAXException se) {
throw new TransformerException(se);
} catch (ParserConfigurationException pce) {
throw new TransformerException(pce);
} catch (IOException ioe) {
throw new TransformerException(ioe);
}
// setDocument(((org.apache.xerces.parsers.DOMParser)parser).getDocument());
}
use of javax.xml.transform.TransformerException in project bazel by bazelbuild.
the class XmlOutputFormatter method createPostFactoStreamCallback.
@Override
public OutputFormatterCallback<Target> createPostFactoStreamCallback(final OutputStream out, final QueryOptions options) {
return new OutputFormatterCallback<Target>() {
private Document doc;
private Element queryElem;
@Override
public void start() {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
doc = factory.newDocumentBuilder().newDocument();
} catch (ParserConfigurationException e) {
// This shouldn't be possible: all the configuration is hard-coded.
throw new IllegalStateException("XML output failed", e);
}
doc.setXmlVersion("1.1");
queryElem = doc.createElement("query");
queryElem.setAttribute("version", "2");
doc.appendChild(queryElem);
}
@Override
public void processOutput(Iterable<Target> partialResult) throws IOException, InterruptedException {
for (Target target : partialResult) {
queryElem.appendChild(createTargetElement(doc, target));
}
}
@Override
public void close(boolean failFast) throws IOException {
if (!failFast) {
try {
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.transform(new DOMSource(doc), new StreamResult(out));
} catch (TransformerFactoryConfigurationError | TransformerException e) {
// This shouldn't be possible: all the configuration is hard-coded.
throw new IllegalStateException("XML output failed", e);
}
}
}
};
}
use of javax.xml.transform.TransformerException in project robovm by robovm.
the class ExtensionNamespaceSupport method launch.
/**
* Launch the ExtensionHandler that this ExtensionNamespaceSupport object defines.
*/
public ExtensionHandler launch() throws TransformerException {
ExtensionHandler handler = null;
try {
Class cl = ExtensionHandler.getClassForName(m_handlerClass);
Constructor con = null;
//System.out.println("class " + cl + " " + m_args + " " + m_args.length + " " + m_sig);
if (m_sig != null)
con = cl.getConstructor(m_sig);
else // Pick the constructor based on number of args.
{
Constructor[] cons = cl.getConstructors();
for (int i = 0; i < cons.length; i++) {
if (cons[i].getParameterTypes().length == m_args.length) {
con = cons[i];
break;
}
}
}
// System.out.println("constructor " + con);
if (con != null)
handler = (ExtensionHandler) con.newInstance(m_args);
else
throw new TransformerException("ExtensionHandler constructor not found");
} catch (Exception e) {
throw new TransformerException(e);
}
return handler;
}
Aggregations