use of org.apache.xpath.objects.XString 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.XString in project robovm by robovm.
the class FuncDoclocation 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 {
int whereNode = getArg0AsNode(xctxt);
String fileLocation = null;
if (DTM.NULL != whereNode) {
DTM dtm = xctxt.getDTM(whereNode);
// %REVIEW%
if (DTM.DOCUMENT_FRAGMENT_NODE == dtm.getNodeType(whereNode)) {
whereNode = dtm.getFirstChild(whereNode);
}
if (DTM.NULL != whereNode) {
fileLocation = dtm.getDocumentBaseURI();
// int owner = dtm.getDocument();
// fileLocation = xctxt.getSourceTreeManager().findURIFromDoc(owner);
}
}
return new XString((null != fileLocation) ? fileLocation : "");
}
use of org.apache.xpath.objects.XString in project robovm by robovm.
the class FuncLocalPart 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 {
int context = getArg0AsNode(xctxt);
if (DTM.NULL == context)
return XString.EMPTYSTRING;
DTM dtm = xctxt.getDTM(context);
String s = (context != DTM.NULL) ? dtm.getLocalName(context) : "";
if (s.startsWith("#") || s.equals("xmlns"))
return XString.EMPTYSTRING;
return new XString(s);
}
use of org.apache.xpath.objects.XString in project robovm by robovm.
the class FuncNamespace 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 {
int context = getArg0AsNode(xctxt);
String s;
if (context != DTM.NULL) {
DTM dtm = xctxt.getDTM(context);
int t = dtm.getNodeType(context);
if (t == DTM.ELEMENT_NODE) {
s = dtm.getNamespaceURI(context);
} else if (t == DTM.ATTRIBUTE_NODE) {
// This function always returns an empty string for namespace nodes.
// We check for those here. Fix inspired by Davanum Srinivas.
s = dtm.getNodeName(context);
if (s.startsWith("xmlns:") || s.equals("xmlns"))
return XString.EMPTYSTRING;
s = dtm.getNamespaceURI(context);
} else
return XString.EMPTYSTRING;
} else
return XString.EMPTYSTRING;
return ((null == s) ? XString.EMPTYSTRING : new XString(s));
}
use of org.apache.xpath.objects.XString in project robovm by robovm.
the class FuncTranslate 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 {
String theFirstString = m_arg0.execute(xctxt).str();
String theSecondString = m_arg1.execute(xctxt).str();
String theThirdString = m_arg2.execute(xctxt).str();
int theFirstStringLength = theFirstString.length();
int theThirdStringLength = theThirdString.length();
// A vector to contain the new characters. We'll use it to construct
// the result string.
StringBuffer sbuffer = new StringBuffer();
for (int i = 0; i < theFirstStringLength; i++) {
char theCurrentChar = theFirstString.charAt(i);
int theIndex = theSecondString.indexOf(theCurrentChar);
if (theIndex < 0) {
// Didn't find the character in the second string, so it
// is not translated.
sbuffer.append(theCurrentChar);
} else if (theIndex < theThirdStringLength) {
// OK, there's a corresponding character in the
// third string, so do the translation...
sbuffer.append(theThirdString.charAt(theIndex));
} else {
// There's no corresponding character in the
// third string, since it's shorter than the
// second string. In this case, the character
// is removed from the output string, so don't
// do anything.
}
}
return new XString(sbuffer.toString());
}
Aggregations