use of javax.xml.transform.TransformerException in project robovm by robovm.
the class ProcessorTemplateElem method startElement.
/**
* Receive notification of the start of an element.
*
* @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
* @param uri The Namespace URI, or an empty string.
* @param localName The local name (without prefix), or empty string if not namespace processing.
* @param rawName The qualified name (with prefix).
* @param attributes The specified or defaulted attributes.
*/
public void startElement(StylesheetHandler handler, String uri, String localName, String rawName, Attributes attributes) throws org.xml.sax.SAXException {
super.startElement(handler, uri, localName, rawName, attributes);
try {
// ElemTemplateElement parent = handler.getElemTemplateElement();
XSLTElementDef def = getElemDef();
Class classObject = def.getClassObject();
ElemTemplateElement elem = null;
try {
elem = (ElemTemplateElement) classObject.newInstance();
elem.setDOMBackPointer(handler.getOriginatingNode());
elem.setLocaterInfo(handler.getLocator());
elem.setPrefixes(handler.getNamespaceSupport());
} catch (InstantiationException ie) {
//"Failed creating ElemTemplateElement instance!", ie);
handler.error(XSLTErrorResources.ER_FAILED_CREATING_ELEMTMPL, null, ie);
} catch (IllegalAccessException iae) {
//"Failed creating ElemTemplateElement instance!", iae);
handler.error(XSLTErrorResources.ER_FAILED_CREATING_ELEMTMPL, null, iae);
}
setPropertiesFromAttributes(handler, rawName, attributes, elem);
appendAndPush(handler, elem);
} catch (TransformerException te) {
throw new org.xml.sax.SAXException(te);
}
}
use of javax.xml.transform.TransformerException in project robovm by robovm.
the class ElemTemplateElement method unexecuteNSDecls.
/**
* Send endPrefixMapping events to the result tree handler
* for all declared prefix mappings in the stylesheet.
*
* @param transformer non-null reference to the the current transform-time state.
* @param ignorePrefix string prefix to not endPrefixMapping
*
* @throws TransformerException
*/
void unexecuteNSDecls(TransformerImpl transformer, String ignorePrefix) throws TransformerException {
try {
if (null != m_prefixTable) {
SerializationHandler rhandler = transformer.getResultTreeHandler();
int n = m_prefixTable.size();
for (int i = 0; i < n; i++) {
XMLNSDecl decl = (XMLNSDecl) m_prefixTable.get(i);
if (!decl.getIsExcluded() && !(null != ignorePrefix && decl.getPrefix().equals(ignorePrefix))) {
rhandler.endPrefixMapping(decl.getPrefix());
}
}
}
} catch (org.xml.sax.SAXException se) {
throw new TransformerException(se);
}
}
use of javax.xml.transform.TransformerException in project robovm by robovm.
the class ElemTextLiteral method execute.
/**
* Copy the text literal to the result tree.
*
* @param transformer non-null reference to the the current transform-time state.
*
* @throws TransformerException
*/
public void execute(TransformerImpl transformer) throws TransformerException {
try {
SerializationHandler rth = transformer.getResultTreeHandler();
if (m_disableOutputEscaping) {
rth.processingInstruction(javax.xml.transform.Result.PI_DISABLE_OUTPUT_ESCAPING, "");
}
rth.characters(m_ch, 0, m_ch.length);
if (m_disableOutputEscaping) {
rth.processingInstruction(javax.xml.transform.Result.PI_ENABLE_OUTPUT_ESCAPING, "");
}
} catch (SAXException se) {
throw new TransformerException(se);
}
}
use of javax.xml.transform.TransformerException in project robovm by robovm.
the class FuncDocument method error.
/**
* Tell the user of an error, and probably throw an
* exception.
*
* @param xctxt The XPath runtime state.
* @param msg The error message key
* @param args Arguments to be used in the error message
* @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
* the error condition is severe enough to halt processing.
*
* @throws javax.xml.transform.TransformerException
*/
public void error(XPathContext xctxt, String msg, Object[] args) throws javax.xml.transform.TransformerException {
String formattedMsg = XSLMessages.createMessage(msg, args);
ErrorListener errHandler = xctxt.getErrorListener();
TransformerException spe = new TransformerException(formattedMsg, (SourceLocator) xctxt.getSAXLocator());
if (null != errHandler)
errHandler.error(spe);
else
System.out.println(formattedMsg);
}
use of javax.xml.transform.TransformerException in project robovm by robovm.
the class ProcessorInclude method parse.
/**
* Set off a new parse for an included or imported stylesheet. This will
* set the {@link StylesheetHandler} to a new state, and recurse in with
* a new set of parse events. Once this function returns, the state of
* the StylesheetHandler should be restored.
*
* @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
* @param uri The Namespace URI, which should be the XSLT namespace.
* @param localName The local name (without prefix), which should be "include" or "import".
* @param rawName The qualified name (with prefix).
* @param attributes The list of attributes on the xsl:include or xsl:import element.
*
* @throws org.xml.sax.SAXException Any SAX exception, possibly
* wrapping another exception.
*/
protected void parse(StylesheetHandler handler, String uri, String localName, String rawName, Attributes attributes) throws org.xml.sax.SAXException {
TransformerFactoryImpl processor = handler.getStylesheetProcessor();
URIResolver uriresolver = processor.getURIResolver();
try {
Source source = null;
if (null != uriresolver) {
// There is a user provided URI resolver.
// At the startElement() call we would
// have tried to obtain a Source from it
// which we now retrieve
source = handler.peekSourceFromURIResolver();
if (null != source && source instanceof DOMSource) {
Node node = ((DOMSource) source).getNode();
// There is a user provided URI resolver.
// At the startElement() call we would
// have already pushed the system ID, obtained
// from either the source.getSystemId(), if non-null
// or from SystemIDResolver.getAbsoluteURI() as a backup
// which we now retrieve.
String systemId = handler.peekImportURL();
// stylesheet module onto the stack.
if (systemId != null)
handler.pushBaseIndentifier(systemId);
TreeWalker walker = new TreeWalker(handler, new org.apache.xml.utils.DOM2Helper(), systemId);
try {
walker.traverse(node);
} catch (org.xml.sax.SAXException se) {
throw new TransformerException(se);
}
if (systemId != null)
handler.popBaseIndentifier();
return;
}
}
if (null == source) {
String absURL = SystemIDResolver.getAbsoluteURI(getHref(), handler.getBaseIdentifier());
source = new StreamSource(absURL);
}
// possible callback to a class that over-rides this method.
source = processSource(handler, source);
XMLReader reader = null;
if (source instanceof SAXSource) {
SAXSource saxSource = (SAXSource) source;
// may be null
reader = saxSource.getXMLReader();
}
InputSource inputSource = SAXSource.sourceToInputSource(source);
if (null == reader) {
// Use JAXP1.1 ( if possible )
try {
javax.xml.parsers.SAXParserFactory factory = javax.xml.parsers.SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
if (handler.getStylesheetProcessor().isSecureProcessing()) {
try {
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
} catch (org.xml.sax.SAXException se) {
}
}
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();
if (null != reader) {
reader.setContentHandler(handler);
// Push the absolute URI of the included/imported
// stylesheet module onto the stack.
handler.pushBaseIndentifier(inputSource.getSystemId());
try {
reader.parse(inputSource);
} finally {
handler.popBaseIndentifier();
}
}
} catch (IOException ioe) {
handler.error(XSLTErrorResources.ER_IOEXCEPTION, new Object[] { getHref() }, ioe);
} catch (TransformerException te) {
handler.error(te.getMessage(), te);
}
}
Aggregations