use of javax.xml.transform.ErrorListener in project robovm by robovm.
the class MsgMgr method error.
/**
* Tell the user of an error, and probably throw an
* exception.
*
* @param styleNode Stylesheet node
* @param sourceNode Source tree node
* @param msg Message text to issue
* @param args Arguments to use in message
* @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
* the error condition is severe enough to halt processing.
*
* @throws TransformerException
* @xsl.usage internal
*/
public void error(SourceLocator srcLctr, Node styleNode, Node sourceNode, String msg, Object[] args) throws TransformerException {
String formattedMsg = XSLMessages.createMessage(msg, args);
// Locator locator = m_stylesheetLocatorStack.isEmpty()
// ? null :
// ((Locator)m_stylesheetLocatorStack.peek());
// Locator locator = null;
ErrorListener errHandler = m_transformer.getErrorListener();
if (null != errHandler)
errHandler.fatalError(new TransformerException(formattedMsg, srcLctr));
else
throw new TransformerException(formattedMsg, srcLctr);
}
use of javax.xml.transform.ErrorListener in project robovm by robovm.
the class MsgMgr method warn.
/**
* Warn the user of a problem.
*
* @param styleNode Stylesheet node
* @param sourceNode Source tree node
* @param msg Message text to issue
* @param args Arguments to pass to the message
* @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
* the error condition is severe enough to halt processing.
*
* @throws TransformerException
* @xsl.usage internal
*/
public void warn(SourceLocator srcLctr, Node styleNode, Node sourceNode, String msg, Object[] args) throws TransformerException {
String formattedMsg = XSLMessages.createWarning(msg, args);
ErrorListener errHandler = m_transformer.getErrorListener();
if (null != errHandler)
errHandler.warning(new TransformerException(formattedMsg, srcLctr));
else
System.out.println(formattedMsg);
}
use of javax.xml.transform.ErrorListener in project robovm by robovm.
the class ToXMLStream method addAttribute.
/**
* Add an attribute to the current element.
* @param uri the URI associated with the element name
* @param localName local part of the attribute name
* @param rawName prefix:localName
* @param type
* @param value the value of the attribute
* @param xslAttribute true if this attribute is from an xsl:attribute,
* false if declared within the elements opening tag.
* @throws SAXException
*/
public void addAttribute(String uri, String localName, String rawName, String type, String value, boolean xslAttribute) throws SAXException {
if (m_elemContext.m_startTagOpen) {
boolean was_added = addAttributeAlways(uri, localName, rawName, type, value, xslAttribute);
/*
* We don't run this block of code if:
* 1. The attribute value was only replaced (was_added is false).
* 2. The attribute is from an xsl:attribute element (that is handled
* in the addAttributeAlways() call just above.
* 3. The name starts with "xmlns", i.e. it is a namespace declaration.
*/
if (was_added && !xslAttribute && !rawName.startsWith("xmlns")) {
String prefixUsed = ensureAttributesNamespaceIsDeclared(uri, localName, rawName);
if (prefixUsed != null && rawName != null && !rawName.startsWith(prefixUsed)) {
// use a different raw name, with the prefix used in the
// generated namespace declaration
rawName = prefixUsed + ":" + localName;
}
}
addAttributeAlways(uri, localName, rawName, type, value, xslAttribute);
} else {
/*
* The startTag is closed, yet we are adding an attribute?
*
* Section: 7.1.3 Creating Attributes Adding an attribute to an
* element after a PI (for example) has been added to it is an
* error. The attributes can be ignored. The spec doesn't explicitly
* say this is disallowed, as it does for child elements, but it
* makes sense to have the same treatment.
*
* We choose to ignore the attribute which is added too late.
*/
// Generate a warning of the ignored attributes
// Create the warning message
String msg = Utils.messages.createMessage(MsgKey.ER_ILLEGAL_ATTRIBUTE_POSITION, new Object[] { localName });
try {
// Prepare to issue the warning message
Transformer tran = super.getTransformer();
ErrorListener errHandler = tran.getErrorListener();
// Issue the warning message
if (null != errHandler && m_sourceLocator != null)
errHandler.warning(new TransformerException(msg, m_sourceLocator));
else
System.out.println(msg);
} catch (TransformerException e) {
// A user defined error handler, errHandler, may throw
// a TransformerException if it chooses to, and if it does
// we will wrap it with a SAXException and re-throw.
// Of course if the handler throws another type of
// exception, like a RuntimeException, then that is OK too.
SAXException se = new SAXException(e);
throw se;
}
}
}
use of javax.xml.transform.ErrorListener 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.ErrorListener 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;
}
Aggregations