use of javax.xml.transform.TransformerException in project robovm by robovm.
the class SourceTreeManager method getXMLReader.
/**
* This method returns the SAX2 parser to use with the InputSource
* obtained from this URI.
* It may return null if any SAX2-conformant XML parser can be used,
* or if getInputSource() will also return null. The parser must
* be free for use (i.e.
* not currently in use for another parse().
*
* @param inputSource The value returned from the URIResolver.
* @return a SAX2 XMLReader to use to resolve the inputSource argument.
* @param locator The location of the original caller, for diagnostic purposes.
*
* @throws TransformerException if the reader can not be created.
*/
public static XMLReader getXMLReader(Source inputSource, SourceLocator locator) throws TransformerException {
try {
XMLReader reader = (inputSource instanceof SAXSource) ? ((SAXSource) inputSource).getXMLReader() : null;
if (null == reader) {
try {
javax.xml.parsers.SAXParserFactory factory = javax.xml.parsers.SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
javax.xml.parsers.SAXParser jaxpParser = factory.newSAXParser();
reader = jaxpParser.getXMLReader();
} catch (javax.xml.parsers.ParserConfigurationException ex) {
throw new org.xml.sax.SAXException(ex);
} catch (javax.xml.parsers.FactoryConfigurationError ex1) {
throw new org.xml.sax.SAXException(ex1.toString());
} catch (NoSuchMethodError ex2) {
} catch (AbstractMethodError ame) {
}
if (null == reader)
reader = XMLReaderFactory.createXMLReader();
}
try {
reader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
} catch (org.xml.sax.SAXException se) {
// What can we do?
// TODO: User diagnostics.
}
return reader;
} catch (org.xml.sax.SAXException se) {
throw new TransformerException(se.getMessage(), locator, se);
}
}
use of javax.xml.transform.TransformerException in project robovm by robovm.
the class VariableStack method getLocalVariable.
/**
* Get a local variable or parameter in the current stack frame.
*
*
* @param xctxt The XPath context, which must be passed in order to
* lazy evaluate variables.
*
* @param index Local variable index relative to the current stack
* frame bottom.
*
* @return The value of the variable.
*
* @throws TransformerException
*/
public XObject getLocalVariable(XPathContext xctxt, int index) throws TransformerException {
index += _currentFrameBottom;
XObject val = _stackFrames[index];
if (null == val)
throw new TransformerException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_VARIABLE_ACCESSED_BEFORE_BIND, null), xctxt.getSAXLocator());
// Lazy execution of variables.
if (val.getType() == XObject.CLASS_UNRESOLVEDVARIABLE)
return (_stackFrames[index] = val.execute(xctxt));
return val;
}
use of javax.xml.transform.TransformerException in project robovm by robovm.
the class XPath method bool.
/**
* Given an expression and a context, evaluate the XPath
* and return the result.
*
* @param xctxt The execution context.
* @param contextNode The node that "." expresses.
* @param namespaceContext The context in which namespaces in the
* XPath are supposed to be expanded.
*
* @throws TransformerException thrown if the active ProblemListener decides
* the error condition is severe enough to halt processing.
*
* @throws javax.xml.transform.TransformerException
* @xsl.usage experimental
*/
public boolean bool(XPathContext xctxt, int contextNode, PrefixResolver namespaceContext) throws javax.xml.transform.TransformerException {
xctxt.pushNamespaceContext(namespaceContext);
xctxt.pushCurrentNodeAndExpression(contextNode, contextNode);
try {
return m_mainExp.bool(xctxt);
} catch (TransformerException te) {
te.setLocator(this.getLocator());
ErrorListener el = xctxt.getErrorListener();
if (// defensive, should never happen.
null != el) {
el.error(te);
} else
throw te;
} catch (Exception e) {
while (e instanceof org.apache.xml.utils.WrappedRuntimeException) {
e = ((org.apache.xml.utils.WrappedRuntimeException) e).getException();
}
// e.printStackTrace();
String msg = e.getMessage();
if (msg == null || msg.length() == 0) {
msg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_XPATH_ERROR, null);
}
TransformerException te = new TransformerException(msg, getLocator(), e);
ErrorListener el = xctxt.getErrorListener();
// te.printStackTrace();
if (// defensive, should never happen.
null != el) {
el.fatalError(te);
} else
throw te;
} finally {
xctxt.popNamespaceContext();
xctxt.popCurrentNodeAndExpression();
}
return false;
}
use of javax.xml.transform.TransformerException in project robovm by robovm.
the class XPath method execute.
/**
* Given an expression and a context, evaluate the XPath
* and return the result.
*
* @param xctxt The execution context.
* @param contextNode The node that "." expresses.
* @param namespaceContext The context in which namespaces in the
* XPath are supposed to be expanded.
*
* @throws TransformerException thrown if the active ProblemListener decides
* the error condition is severe enough to halt processing.
*
* @throws javax.xml.transform.TransformerException
* @xsl.usage experimental
*/
public XObject execute(XPathContext xctxt, int contextNode, PrefixResolver namespaceContext) throws javax.xml.transform.TransformerException {
xctxt.pushNamespaceContext(namespaceContext);
xctxt.pushCurrentNodeAndExpression(contextNode, contextNode);
XObject xobj = null;
try {
xobj = m_mainExp.execute(xctxt);
} catch (TransformerException te) {
te.setLocator(this.getLocator());
ErrorListener el = xctxt.getErrorListener();
if (// defensive, should never happen.
null != el) {
el.error(te);
} else
throw te;
} catch (Exception e) {
while (e instanceof org.apache.xml.utils.WrappedRuntimeException) {
e = ((org.apache.xml.utils.WrappedRuntimeException) e).getException();
}
// e.printStackTrace();
String msg = e.getMessage();
if (msg == null || msg.length() == 0) {
msg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_XPATH_ERROR, null);
}
TransformerException te = new TransformerException(msg, getLocator(), e);
ErrorListener el = xctxt.getErrorListener();
// te.printStackTrace();
if (// defensive, should never happen.
null != el) {
el.fatalError(te);
} else
throw te;
} finally {
xctxt.popNamespaceContext();
xctxt.popCurrentNodeAndExpression();
}
return xobj;
}
use of javax.xml.transform.TransformerException in project robovm by robovm.
the class JAXPVariableStack method getVariableOrParam.
public XObject getVariableOrParam(XPathContext xctxt, QName qname) throws TransformerException, IllegalArgumentException {
if (qname == null) {
//JAXP 1.3 spec says that if variable name is null then
// we need to through IllegalArgumentException
String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_ARG_CANNOT_BE_NULL, new Object[] { "Variable qname" });
throw new IllegalArgumentException(fmsg);
}
javax.xml.namespace.QName name = new javax.xml.namespace.QName(qname.getNamespace(), qname.getLocalPart());
Object varValue = resolver.resolveVariable(name);
if (varValue == null) {
String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_RESOLVE_VARIABLE_RETURNS_NULL, new Object[] { name.toString() });
throw new TransformerException(fmsg);
}
return XObject.create(varValue, xctxt);
}
Aggregations