use of org.apache.xpath.objects.XString 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);
}
}
Aggregations