use of org.apache.xpath.objects.XObject in project robovm by robovm.
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 robovm by robovm.
the class ElemParam method execute.
/**
* Execute a variable declaration and push it onto the variable stack.
* @see <a href="http://www.w3.org/TR/xslt#variables">variables 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 {
VariableStack vars = transformer.getXPathContext().getVarStack();
if (!vars.isLocalSet(m_index)) {
int sourceNode = transformer.getXPathContext().getCurrentNode();
XObject var = getValue(transformer, sourceNode);
// transformer.getXPathContext().getVarStack().pushVariable(m_qname, var);
transformer.getXPathContext().getVarStack().setLocalVariable(m_index, var);
}
}
use of org.apache.xpath.objects.XObject in project robovm by robovm.
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 robovm by robovm.
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 robovm by robovm.
the class TransformerImpl method pushGlobalVars.
/**
* Internal -- push the global variables from the Stylesheet onto
* the context's runtime variable stack.
* <p>If we encounter a variable
* that is already defined in the variable stack, we ignore it. This
* is because the second variable definition will be at a lower import
* precedence. Presumably, global"variables at the same import precedence
* with the same name will have been caught during the recompose process.
* <p>However, if we encounter a parameter that is already defined in the
* variable stack, we need to see if this is a parameter whose value was
* supplied by a setParameter call. If so, we need to "receive" the one
* already in the stack, ignoring this one. If it is just an earlier
* xsl:param or xsl:variable definition, we ignore it using the same
* reasoning as explained above for the variable.
*
* @param contextNode The root of the source tree, can't be null.
*
* @throws TransformerException
*/
protected void pushGlobalVars(int contextNode) throws TransformerException {
XPathContext xctxt = m_xcontext;
VariableStack vs = xctxt.getVarStack();
StylesheetRoot sr = getStylesheet();
Vector vars = sr.getVariablesAndParamsComposed();
int i = vars.size();
vs.link(i);
while (--i >= 0) {
ElemVariable v = (ElemVariable) vars.elementAt(i);
// XObject xobj = v.getValue(this, contextNode);
XObject xobj = new XUnresolvedVariable(v, contextNode, this, vs.getStackFrame(), 0, true);
if (null == vs.elementAt(i))
vs.setGlobalVariable(i, xobj);
}
}
Aggregations