use of org.apache.xpath.XPathContext in project j2objc by google.
the class ElemCopyOf method execute.
/**
* The xsl:copy-of element can be used to insert a result tree
* fragment into the result tree, without first converting it to
* a string as xsl:value-of does (see [7.6.1 Generating Text with
* xsl:value-of]).
*
* @param transformer non-null reference to the the current transform-time state.
*
* @throws TransformerException
*/
public void execute(TransformerImpl transformer) throws TransformerException {
try {
XPathContext xctxt = transformer.getXPathContext();
int sourceNode = xctxt.getCurrentNode();
XObject value = m_selectExpression.execute(xctxt, sourceNode, this);
SerializationHandler handler = transformer.getSerializationHandler();
if (null != value) {
int type = value.getType();
String s;
switch(type) {
case XObject.CLASS_BOOLEAN:
case XObject.CLASS_NUMBER:
case XObject.CLASS_STRING:
s = value.str();
handler.characters(s.toCharArray(), 0, s.length());
break;
case XObject.CLASS_NODESET:
// System.out.println(value);
DTMIterator nl = value.iter();
// Copy the tree.
DTMTreeWalker tw = new TreeWalker2Result(transformer, handler);
int pos;
while (DTM.NULL != (pos = nl.nextNode())) {
DTM dtm = xctxt.getDTMManager().getDTM(pos);
short t = dtm.getNodeType(pos);
// generated, so we need to only walk the child nodes.
if (t == DTM.DOCUMENT_NODE) {
for (int child = dtm.getFirstChild(pos); child != DTM.NULL; child = dtm.getNextSibling(child)) {
tw.traverse(child);
}
} else if (t == DTM.ATTRIBUTE_NODE) {
SerializerUtils.addAttribute(handler, pos);
} else {
tw.traverse(pos);
}
}
// nl.detach();
break;
case XObject.CLASS_RTREEFRAG:
SerializerUtils.outputResultTreeFragment(handler, value, transformer.getXPathContext());
break;
default:
s = value.str();
handler.characters(s.toCharArray(), 0, s.length());
break;
}
}
// I don't think we want this. -sb
// if (transformer.getDebug())
// transformer.getTraceManager().fireSelectedEvent(sourceNode, this,
// "endSelect", m_selectExpression, value);
} catch (org.xml.sax.SAXException se) {
throw new TransformerException(se);
}
}
use of org.apache.xpath.XPathContext in project j2objc by google.
the class ElemElement method execute.
/**
* Create an element in the result tree.
* The xsl:element element allows an element to be created with a
* computed name. The expanded-name of the element to be created
* is specified by a required name attribute and an optional namespace
* attribute. The content of the xsl:element element is a template
* for the attributes and children of the created element.
*
* @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();
XPathContext xctxt = transformer.getXPathContext();
int sourceNode = xctxt.getCurrentNode();
String nodeName = m_name_avt == null ? null : m_name_avt.evaluate(xctxt, sourceNode, this);
String prefix = null;
String nodeNamespace = "";
// Only validate if an AVT was used.
if ((nodeName != null) && (!m_name_avt.isSimple()) && (!XML11Char.isXML11ValidQName(nodeName))) {
transformer.getMsgMgr().warn(this, XSLTErrorResources.WG_ILLEGAL_ATTRIBUTE_VALUE, new Object[] { Constants.ATTRNAME_NAME, nodeName });
nodeName = null;
} else if (nodeName != null) {
prefix = QName.getPrefixPart(nodeName);
if (null != m_namespace_avt) {
nodeNamespace = m_namespace_avt.evaluate(xctxt, sourceNode, this);
if (null == nodeNamespace || (prefix != null && prefix.length() > 0 && nodeNamespace.length() == 0))
transformer.getMsgMgr().error(this, XSLTErrorResources.ER_NULL_URI_NAMESPACE);
else {
// Determine the actual prefix that we will use for this nodeNamespace
prefix = resolvePrefix(rhandler, prefix, nodeNamespace);
if (null == prefix)
prefix = "";
if (prefix.length() > 0)
nodeName = (prefix + ":" + QName.getLocalPart(nodeName));
else
nodeName = QName.getLocalPart(nodeName);
}
} else // No namespace attribute was supplied. Use the namespace declarations
// currently in effect for the xsl:element element.
{
try {
// Maybe temporary, until I get this worked out. test: axes59
nodeNamespace = getNamespaceForPrefix(prefix);
if ((null == nodeNamespace) && (prefix.length() == 0))
nodeNamespace = "";
else if (null == nodeNamespace) {
transformer.getMsgMgr().warn(this, XSLTErrorResources.WG_COULD_NOT_RESOLVE_PREFIX, new Object[] { prefix });
nodeName = null;
}
} catch (Exception ex) {
transformer.getMsgMgr().warn(this, XSLTErrorResources.WG_COULD_NOT_RESOLVE_PREFIX, new Object[] { prefix });
nodeName = null;
}
}
}
constructNode(nodeName, prefix, nodeNamespace, transformer);
}
use of org.apache.xpath.XPathContext in project j2objc by google.
the class ElemExsltFuncResult method execute.
/**
* Generate the EXSLT function return value, and assign it to the variable
* index slot assigned for it in ElemExsltFunction compose().
*
*/
public void execute(TransformerImpl transformer) throws TransformerException {
XPathContext context = transformer.getXPathContext();
// in the owner ElemExsltFunction execute().
if (transformer.currentFuncResultSeen()) {
throw new TransformerException("An EXSLT function cannot set more than one result!");
}
int sourceNode = context.getCurrentNode();
// Set the return value;
XObject var = getValue(transformer, sourceNode);
transformer.popCurrentFuncResult();
transformer.pushCurrentFuncResult(var);
}
use of org.apache.xpath.XPathContext in project j2objc by google.
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 org.apache.xpath.XPathContext in project j2objc by google.
the class ElemPI method execute.
/**
* Create a processing instruction in the result tree.
* The content of the xsl:processing-instruction element is a
* template for the string-value of the processing instruction node.
* @see <a href="http://www.w3.org/TR/xslt#section-Creating-Processing-Instructions">section-Creating-Processing-Instructions 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 {
XPathContext xctxt = transformer.getXPathContext();
int sourceNode = xctxt.getCurrentNode();
String piName = m_name_atv == null ? null : m_name_atv.evaluate(xctxt, sourceNode, this);
// Ignore processing instruction if name is null
if (piName == null)
return;
if (piName.equalsIgnoreCase("xml")) {
transformer.getMsgMgr().warn(this, XSLTErrorResources.WG_PROCESSINGINSTRUCTION_NAME_CANT_BE_XML, new Object[] { Constants.ATTRNAME_NAME, piName });
return;
} else // Ignore processing instruction, if invalid
if ((!m_name_atv.isSimple()) && (!XML11Char.isXML11ValidNCName(piName))) {
transformer.getMsgMgr().warn(this, XSLTErrorResources.WG_PROCESSINGINSTRUCTION_NOTVALID_NCNAME, new Object[] { Constants.ATTRNAME_NAME, piName });
return;
}
// Note the content model is:
// <!ENTITY % instructions "
// %char-instructions;
// | xsl:processing-instruction
// | xsl:comment
// | xsl:element
// | xsl:attribute
// ">
String data = transformer.transformToString(this);
try {
transformer.getResultTreeHandler().processingInstruction(piName, data);
} catch (org.xml.sax.SAXException se) {
throw new TransformerException(se);
}
}
Aggregations