use of org.apache.xpath.objects.XObject in project j2objc by google.
the class ElemVariable method getValue.
/**
* Get the XObject representation of the variable.
*
* @param transformer non-null reference to the the current transform-time state.
* @param sourceNode non-null reference to the <a href="http://www.w3.org/TR/xslt#dt-current-node">current source node</a>.
*
* @return the XObject representation of the variable.
*
* @throws TransformerException
*/
public XObject getValue(TransformerImpl transformer, int sourceNode) throws TransformerException {
XObject var;
XPathContext xctxt = transformer.getXPathContext();
xctxt.pushCurrentNode(sourceNode);
try {
if (null != m_selectPattern) {
var = m_selectPattern.execute(xctxt, sourceNode, this);
var.allowDetachToRelease(false);
} else if (null == getFirstChildElem()) {
var = XString.EMPTYSTRING;
} else {
// Use result tree fragment.
// Global variables may be deferred (see XUnresolvedVariable) and hence
// need to be assigned to a different set of DTMs than local variables
// so they aren't popped off the stack on return from a template.
int df;
////// problem in parameters. Needs more study.
try {
//////////xctxt.getVarStack().link(0);
if (// Global variable
m_parentNode instanceof Stylesheet)
df = transformer.transformToGlobalRTF(this);
else
df = transformer.transformToRTF(this);
} finally {
//////////////xctxt.getVarStack().unlink();
}
var = new XRTreeFrag(df, xctxt, this);
}
} finally {
xctxt.popCurrentNode();
}
return var;
}
use of org.apache.xpath.objects.XObject in project j2objc by google.
the class ElemWithParam method getValue.
/**
* Get the XObject representation of the variable.
*
* @param transformer non-null reference to the the current transform-time state.
* @param sourceNode non-null reference to the <a href="http://www.w3.org/TR/xslt#dt-current-node">current source node</a>.
*
* @return the XObject representation of the variable.
*
* @throws TransformerException
*/
public XObject getValue(TransformerImpl transformer, int sourceNode) throws TransformerException {
XObject var;
XPathContext xctxt = transformer.getXPathContext();
xctxt.pushCurrentNode(sourceNode);
try {
if (null != m_selectPattern) {
var = m_selectPattern.execute(xctxt, sourceNode, this);
var.allowDetachToRelease(false);
} else if (null == getFirstChildElem()) {
var = XString.EMPTYSTRING;
} else {
// Use result tree fragment
int df = transformer.transformToRTF(this);
var = new XRTreeFrag(df, xctxt, this);
}
} finally {
xctxt.popCurrentNode();
}
return var;
}
use of org.apache.xpath.objects.XObject in project j2objc by google.
the class FuncFormatNumb method execute.
/**
* Execute the function. The function must return
* a valid object.
* @param xctxt The current execution context.
* @return A valid XObject.
*
* @throws javax.xml.transform.TransformerException
*/
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException {
// A bit of an ugly hack to get our context.
ElemTemplateElement templElem = (ElemTemplateElement) xctxt.getNamespaceContext();
StylesheetRoot ss = templElem.getStylesheetRoot();
java.text.DecimalFormat formatter = null;
java.text.DecimalFormatSymbols dfs = null;
double num = getArg0().execute(xctxt).num();
String patternStr = getArg1().execute(xctxt).str();
// TODO: what should be the behavior here??
if (patternStr.indexOf(0x00A4) > 0)
// currency sign not allowed
ss.error(XSLTErrorResources.ER_CURRENCY_SIGN_ILLEGAL);
// decimal-format declared in the stylesheet!(xsl:decimal-format
try {
Expression arg2Expr = getArg2();
if (null != arg2Expr) {
String dfName = arg2Expr.execute(xctxt).str();
QName qname = new QName(dfName, xctxt.getNamespaceContext());
dfs = ss.getDecimalFormatComposed(qname);
if (null == dfs) {
warn(xctxt, XSLTErrorResources.WG_NO_DECIMALFORMAT_DECLARATION, //"not found!!!
new Object[] { dfName });
//formatter = new java.text.DecimalFormat(patternStr);
} else {
//formatter = new java.text.DecimalFormat(patternStr, dfs);
formatter = new java.text.DecimalFormat();
formatter.setDecimalFormatSymbols(dfs);
formatter.applyLocalizedPattern(patternStr);
}
}
//else
if (null == formatter) {
// look for a possible default decimal-format
dfs = ss.getDecimalFormatComposed(new QName(""));
if (dfs != null) {
formatter = new java.text.DecimalFormat();
formatter.setDecimalFormatSymbols(dfs);
formatter.applyLocalizedPattern(patternStr);
} else {
dfs = new java.text.DecimalFormatSymbols(java.util.Locale.US);
dfs.setInfinity(Constants.ATTRVAL_INFINITY);
dfs.setNaN(Constants.ATTRVAL_NAN);
formatter = new java.text.DecimalFormat();
formatter.setDecimalFormatSymbols(dfs);
if (null != patternStr)
formatter.applyLocalizedPattern(patternStr);
}
}
return new XString(formatter.format(num));
} catch (Exception iae) {
templElem.error(XSLTErrorResources.ER_MALFORMED_FORMAT_STRING, new Object[] { patternStr });
return XString.EMPTYSTRING;
//throw new XSLProcessorException(iae);
}
}
use of org.apache.xpath.objects.XObject in project j2objc by google.
the class FuncKey method execute.
/**
* Execute the function. The function must return
* a valid object.
* @param xctxt The current execution context.
* @return A valid XObject.
*
* @throws javax.xml.transform.TransformerException
*/
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException {
// TransformerImpl transformer = (TransformerImpl)xctxt;
TransformerImpl transformer = (TransformerImpl) xctxt.getOwnerObject();
XNodeSet nodes = null;
int context = xctxt.getCurrentNode();
DTM dtm = xctxt.getDTM(context);
int docContext = dtm.getDocumentRoot(context);
if (DTM.NULL == docContext) {
// path.error(context, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC); //"context does not have an owner document!");
}
String xkeyname = getArg0().execute(xctxt).str();
QName keyname = new QName(xkeyname, xctxt.getNamespaceContext());
XObject arg = getArg1().execute(xctxt);
boolean argIsNodeSetDTM = (XObject.CLASS_NODESET == arg.getType());
KeyManager kmgr = transformer.getKeyManager();
// Don't bother with nodeset logic if the thing is only one node.
if (argIsNodeSetDTM) {
XNodeSet ns = (XNodeSet) arg;
ns.setShouldCacheNodes(true);
int len = ns.getLength();
if (len <= 1)
argIsNodeSetDTM = false;
}
if (argIsNodeSetDTM) {
Hashtable usedrefs = null;
DTMIterator ni = arg.iter();
int pos;
UnionPathIterator upi = new UnionPathIterator();
upi.exprSetParent(this);
while (DTM.NULL != (pos = ni.nextNode())) {
dtm = xctxt.getDTM(pos);
XMLString ref = dtm.getStringValue(pos);
if (null == ref)
continue;
if (null == usedrefs)
usedrefs = new Hashtable();
if (usedrefs.get(ref) != null) {
// We already have 'em.
continue;
} else {
// ISTRUE being used as a dummy value.
usedrefs.put(ref, ISTRUE);
}
XNodeSet nl = kmgr.getNodeSetDTMByKey(xctxt, docContext, keyname, ref, xctxt.getNamespaceContext());
nl.setRoot(xctxt.getCurrentNode(), xctxt);
// try
// {
upi.addIterator(nl);
// }
// catch(CloneNotSupportedException cnse)
// {
// // will never happen.
// }
//mnodeset.addNodesInDocOrder(nl, xctxt); needed??
}
int current = xctxt.getCurrentNode();
upi.setRoot(current, xctxt);
nodes = new XNodeSet(upi);
} else {
XMLString ref = arg.xstr();
nodes = kmgr.getNodeSetDTMByKey(xctxt, docContext, keyname, ref, xctxt.getNamespaceContext());
nodes.setRoot(xctxt.getCurrentNode(), xctxt);
}
return nodes;
}
use of org.apache.xpath.objects.XObject in project j2objc by google.
the class XUnresolvedVariable method execute.
/**
* For support of literal objects in xpaths.
*
* @param xctxt The XPath execution context.
*
* @return This object.
*
* @throws javax.xml.transform.TransformerException
*/
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException {
if (!m_doneEval) {
this.m_transformer.getMsgMgr().error(xctxt.getSAXLocator(), XSLTErrorResources.ER_REFERENCING_ITSELF, new Object[] { ((ElemVariable) this.object()).getName().getLocalName() });
}
VariableStack vars = xctxt.getVarStack();
// These three statements need to be combined into one operation.
int currentFrame = vars.getStackFrame();
//// vars.setStackFrame(m_varStackPos);
ElemVariable velem = (ElemVariable) m_obj;
try {
m_doneEval = false;
if (-1 != velem.m_frameSize)
vars.link(velem.m_frameSize);
XObject var = velem.getValue(m_transformer, m_context);
m_doneEval = true;
return var;
} finally {
if (-1 != velem.m_frameSize)
vars.unlink(currentFrame);
}
}
Aggregations