use of javax.xml.transform.TransformerException in project robovm by robovm.
the class XSLTAttributeDef method processENUM.
/**
* Process an attribute string of type T_ENUM into a int value.
*
* @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
* @param uri The Namespace URI, or an empty string.
* @param name The local name (without prefix), or empty string if not namespace processing.
* @param rawName The qualified name (with prefix).
* @param value non-null string that represents an enumerated value that is
* valid for this element.
* @param owner
*
* @return An Integer representation of the enumerated value if this attribute does not support
* AVT. Otherwise, and AVT is returned.
*/
Object processENUM(StylesheetHandler handler, String uri, String name, String rawName, String value, ElemTemplateElement owner) throws org.xml.sax.SAXException {
AVT avt = null;
if (getSupportsAVT()) {
try {
avt = new AVT(handler, uri, name, rawName, value, owner);
// If this attribute used an avt, then we can't validate at this time.
if (!avt.isSimple())
return avt;
} catch (TransformerException te) {
throw new org.xml.sax.SAXException(te);
}
}
int retVal = this.getEnum(value);
if (retVal == StringToIntTable.INVALID_KEY) {
StringBuffer enumNamesList = getListOfEnums();
handleError(handler, XSLTErrorResources.INVALID_ENUM, new Object[] { name, value, enumNamesList.toString() }, null);
return null;
}
if (getSupportsAVT())
return avt;
else
return new Integer(retVal);
}
use of javax.xml.transform.TransformerException in project robovm by robovm.
the class ElemExsltFunction method execute.
public void execute(TransformerImpl transformer, XObject[] args) throws TransformerException {
XPathContext xctxt = transformer.getXPathContext();
VariableStack vars = xctxt.getVarStack();
// Increment the frame bottom of the variable stack by the
// frame size
int thisFrame = vars.getStackFrame();
int nextFrame = vars.link(m_frameSize);
if (m_inArgsSize < args.length) {
throw new TransformerException("function called with too many args");
}
// have to clear the section of the stack frame that has params.
if (m_inArgsSize > 0) {
vars.clearLocalSlots(0, m_inArgsSize);
if (args.length > 0) {
vars.setStackFrame(thisFrame);
NodeList children = this.getChildNodes();
for (int i = 0; i < args.length; i++) {
Node child = children.item(i);
if (children.item(i) instanceof ElemParam) {
ElemParam param = (ElemParam) children.item(i);
vars.setLocalVariable(param.getIndex(), args[i], nextFrame);
}
}
vars.setStackFrame(nextFrame);
}
}
// Removed ElemTemplate 'push' and 'pop' of RTFContext, in order to avoid losing the RTF context
// before a value can be returned. ElemExsltFunction operates in the scope of the template that called
// the function.
// xctxt.pushRTFContext();
vars.setStackFrame(nextFrame);
transformer.executeChildTemplates(this, true);
// Reset the stack frame after the function call
vars.unlink(thisFrame);
// Following ElemTemplate 'pop' removed -- see above.
// xctxt.popRTFContext();
}
use of javax.xml.transform.TransformerException in project robovm by robovm.
the class ElemExtensionDecl method compose.
public void compose(StylesheetRoot sroot) throws TransformerException {
super.compose(sroot);
String prefix = getPrefix();
String declNamespace = getNamespaceForPrefix(prefix);
String lang = null;
String srcURL = null;
String scriptSrc = null;
if (null == declNamespace)
throw new TransformerException(XSLMessages.createMessage(XSLTErrorResources.ER_NO_NAMESPACE_DECL, new Object[] { prefix }));
//"Prefix " + prefix does not have a corresponding namespace declaration");
for (ElemTemplateElement child = getFirstChildElem(); child != null; child = child.getNextSiblingElem()) {
if (Constants.ELEMNAME_EXTENSIONSCRIPT == child.getXSLToken()) {
ElemExtensionScript sdecl = (ElemExtensionScript) child;
lang = sdecl.getLang();
srcURL = sdecl.getSrc();
ElemTemplateElement childOfSDecl = sdecl.getFirstChildElem();
if (null != childOfSDecl) {
if (Constants.ELEMNAME_TEXTLITERALRESULT == childOfSDecl.getXSLToken()) {
ElemTextLiteral tl = (ElemTextLiteral) childOfSDecl;
char[] chars = tl.getChars();
scriptSrc = new String(chars);
if (scriptSrc.trim().length() == 0)
scriptSrc = null;
}
}
}
}
if (null == lang)
lang = "javaclass";
if (lang.equals("javaclass") && (scriptSrc != null))
throw new TransformerException(XSLMessages.createMessage(XSLTErrorResources.ER_ELEM_CONTENT_NOT_ALLOWED, new Object[] { scriptSrc }));
//"Element content not allowed for lang=javaclass " + scriptSrc);
// Register the extension namespace if it has not already been registered.
ExtensionNamespaceSupport extNsSpt = null;
ExtensionNamespacesManager extNsMgr = sroot.getExtensionNamespacesManager();
if (extNsMgr.namespaceIndex(declNamespace, extNsMgr.getExtensions()) == -1) {
if (lang.equals("javaclass")) {
if (null == srcURL) {
extNsSpt = extNsMgr.defineJavaNamespace(declNamespace);
} else if (extNsMgr.namespaceIndex(srcURL, extNsMgr.getExtensions()) == -1) {
extNsSpt = extNsMgr.defineJavaNamespace(declNamespace, srcURL);
}
} else // not java
{
String handler = "org.apache.xalan.extensions.ExtensionHandlerGeneral";
Object[] args = { declNamespace, this.m_elements, this.m_functions, lang, srcURL, scriptSrc, getSystemId() };
extNsSpt = new ExtensionNamespaceSupport(declNamespace, handler, args);
}
}
if (extNsSpt != null)
extNsMgr.registerExtension(extNsSpt);
}
use of javax.xml.transform.TransformerException in project robovm by robovm.
the class ElemLiteralResult method execute.
/**
* Copy a Literal Result Element into the Result tree, copy the
* non-excluded namespace attributes, copy the attributes not
* of the XSLT namespace, and execute the children of the LRE.
* @see <a href="http://www.w3.org/TR/xslt#literal-result-element">literal-result-element in XSLT Specification</a>
*
* @param transformer non-null reference to the the current transform-time state.
*
* @throws TransformerException
*/
public void execute(TransformerImpl transformer) throws TransformerException {
SerializationHandler rhandler = transformer.getSerializationHandler();
try {
// JJK Bugzilla 3464, test namespace85 -- make sure LRE's
// namespace is asserted even if default, since xsl:element
// may have changed the context.
rhandler.startPrefixMapping(getPrefix(), getNamespace());
// Add namespace declarations.
executeNSDecls(transformer);
rhandler.startElement(getNamespace(), getLocalName(), getRawName());
} catch (SAXException se) {
throw new TransformerException(se);
}
/*
* If we make it to here we have done a successful startElement()
* we will do an endElement() call for balance, no matter what happens
* in the middle.
*/
// tException remembers if we had an exception "in the middle"
TransformerException tException = null;
try {
// Process any possible attributes from xsl:use-attribute-sets first
super.execute(transformer);
// Process the list of avts next
if (null != m_avts) {
int nAttrs = m_avts.size();
for (int i = (nAttrs - 1); i >= 0; i--) {
AVT avt = (AVT) m_avts.get(i);
XPathContext xctxt = transformer.getXPathContext();
int sourceNode = xctxt.getCurrentNode();
String stringedValue = avt.evaluate(xctxt, sourceNode, this);
if (null != stringedValue) {
// Important Note: I'm not going to check for excluded namespace
// prefixes here. It seems like it's too expensive, and I'm not
// even sure this is right. But I could be wrong, so this needs
// to be tested against other implementations.
rhandler.addAttribute(avt.getURI(), avt.getName(), avt.getRawName(), "CDATA", stringedValue, false);
}
}
// end for
}
// Now process all the elements in this subtree
// TODO: Process m_extensionElementPrefixes && m_attributeSetsNames
transformer.executeChildTemplates(this, true);
} catch (TransformerException te) {
// thrown in finally to prevent original exception consumed by subsequent exceptions
tException = te;
} catch (SAXException se) {
tException = new TransformerException(se);
}
try {
/* we need to do this endElement() to balance the
* successful startElement() call even if
* there was an exception in the middle.
* Otherwise an exception in the middle could cause a system to hang.
*/
rhandler.endElement(getNamespace(), getLocalName(), getRawName());
} catch (SAXException se) {
/* we did call endElement(). If thee was an exception
* in the middle throw that one, otherwise if there
* was an exception from endElement() throw that one.
*/
if (tException != null)
throw tException;
else
throw new TransformerException(se);
}
/* If an exception was thrown in the middle but not with startElement() or
* or endElement() then its time to let it percolate.
*/
if (tException != null)
throw tException;
unexecuteNSDecls(transformer);
// JJK Bugzilla 3464, test namespace85 -- balance explicit start.
try {
rhandler.endPrefixMapping(getPrefix());
} catch (SAXException se) {
throw new TransformerException(se);
}
}
use of javax.xml.transform.TransformerException in project robovm by robovm.
the class ProcessorStylesheetElement method startElement.
/**
* Receive notification of the start of an strip-space element.
*
* @param handler The calling StylesheetHandler/TemplatesBuilder.
* @param uri The Namespace URI, or the empty string if the
* element has no Namespace URI or if Namespace
* processing is not being performed.
* @param localName The local name (without prefix), or the
* empty string if Namespace processing is not being
* performed.
* @param rawName The raw XML 1.0 name (with prefix), or the
* empty string if raw names are not available.
* @param attributes The attributes attached to the element. If
* there are no attributes, it shall be an empty
* Attributes object.
*/
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 {
int stylesheetType = handler.getStylesheetType();
Stylesheet stylesheet;
if (stylesheetType == StylesheetHandler.STYPE_ROOT) {
try {
stylesheet = getStylesheetRoot(handler);
} catch (TransformerConfigurationException tfe) {
throw new TransformerException(tfe);
}
} else {
Stylesheet parent = handler.getStylesheet();
if (stylesheetType == StylesheetHandler.STYPE_IMPORT) {
StylesheetComposed sc = new StylesheetComposed(parent);
parent.setImport(sc);
stylesheet = sc;
} else {
stylesheet = new Stylesheet(parent);
parent.setInclude(stylesheet);
}
}
stylesheet.setDOMBackPointer(handler.getOriginatingNode());
stylesheet.setLocaterInfo(handler.getLocator());
stylesheet.setPrefixes(handler.getNamespaceSupport());
handler.pushStylesheet(stylesheet);
setPropertiesFromAttributes(handler, rawName, attributes, handler.getStylesheet());
handler.pushElemTemplateElement(handler.getStylesheet());
} catch (TransformerException te) {
throw new org.xml.sax.SAXException(te);
}
}
Aggregations