Search in sources :

Example 6 with XString

use of org.apache.xpath.objects.XString in project j2objc by google.

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 : "");
}
Also used : XString(org.apache.xpath.objects.XString) XString(org.apache.xpath.objects.XString) DTM(org.apache.xml.dtm.DTM)

Example 7 with XString

use of org.apache.xpath.objects.XString in project j2objc by google.

the class FuncQname 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);
    XObject val;
    if (DTM.NULL != context) {
        DTM dtm = xctxt.getDTM(context);
        String qname = dtm.getNodeNameX(context);
        val = (null == qname) ? XString.EMPTYSTRING : new XString(qname);
    } else {
        val = XString.EMPTYSTRING;
    }
    return val;
}
Also used : XString(org.apache.xpath.objects.XString) XString(org.apache.xpath.objects.XString) DTM(org.apache.xml.dtm.DTM) XObject(org.apache.xpath.objects.XObject)

Example 8 with XString

use of org.apache.xpath.objects.XString in project j2objc by google.

the class FuncSubstringBefore 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 s1 = m_arg0.execute(xctxt).str();
    String s2 = m_arg1.execute(xctxt).str();
    int index = s1.indexOf(s2);
    return (-1 == index) ? XString.EMPTYSTRING : new XString(s1.substring(0, index));
}
Also used : XString(org.apache.xpath.objects.XString) XString(org.apache.xpath.objects.XString)

Example 9 with XString

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);
    }
}
Also used : Expression(org.apache.xpath.Expression) QName(org.apache.xml.utils.QName) XString(org.apache.xpath.objects.XString) XObject(org.apache.xpath.objects.XObject) XPathContext(org.apache.xpath.XPathContext) XString(org.apache.xpath.objects.XString) TransformerException(javax.xml.transform.TransformerException) WrongNumberArgsException(org.apache.xpath.functions.WrongNumberArgsException)

Example 10 with XString

use of org.apache.xpath.objects.XString in project j2objc by google.

the class FuncSystemProperty 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 fullName = m_arg0.execute(xctxt).str();
    int indexOfNSSep = fullName.indexOf(':');
    String result = null;
    String propName = "";
    // List of properties where the name of the
    // property argument is to be looked for.
    Properties xsltInfo = new Properties();
    loadPropertyFile(XSLT_PROPERTIES, xsltInfo);
    if (indexOfNSSep > 0) {
        String prefix = (indexOfNSSep >= 0) ? fullName.substring(0, indexOfNSSep) : "";
        String namespace;
        namespace = xctxt.getNamespaceContext().getNamespaceForPrefix(prefix);
        propName = (indexOfNSSep < 0) ? fullName : fullName.substring(indexOfNSSep + 1);
        if (namespace.startsWith("http://www.w3.org/XSL/Transform") || namespace.equals("http://www.w3.org/1999/XSL/Transform")) {
            result = xsltInfo.getProperty(propName);
            if (null == result) {
                warn(xctxt, XPATHErrorResources.WG_PROPERTY_NOT_SUPPORTED, //"XSL Property not supported: "+fullName);
                new Object[] { fullName });
                return XString.EMPTYSTRING;
            }
        } else {
            warn(xctxt, XPATHErrorResources.WG_DONT_DO_ANYTHING_WITH_NS, new Object[] { namespace, //"Don't currently do anything with namespace "+namespace+" in property: "+fullName);
            fullName });
            try {
                //if secure procession is enabled only handle required properties do not not map any valid system property
                if (!xctxt.isSecureProcessing()) {
                    result = System.getProperty(propName);
                } else {
                    warn(xctxt, XPATHErrorResources.WG_SECURITY_EXCEPTION, //"SecurityException when trying to access XSL system property: "+fullName);
                    new Object[] { fullName });
                }
                if (null == result) {
                    return XString.EMPTYSTRING;
                }
            } catch (SecurityException se) {
                warn(xctxt, XPATHErrorResources.WG_SECURITY_EXCEPTION, //"SecurityException when trying to access XSL system property: "+fullName);
                new Object[] { fullName });
                return XString.EMPTYSTRING;
            }
        }
    } else {
        try {
            //if secure procession is enabled only handle required properties do not not map any valid system property
            if (!xctxt.isSecureProcessing()) {
                result = System.getProperty(fullName);
            } else {
                warn(xctxt, XPATHErrorResources.WG_SECURITY_EXCEPTION, //"SecurityException when trying to access XSL system property: "+fullName);
                new Object[] { fullName });
            }
            if (null == result) {
                return XString.EMPTYSTRING;
            }
        } catch (SecurityException se) {
            warn(xctxt, XPATHErrorResources.WG_SECURITY_EXCEPTION, //"SecurityException when trying to access XSL system property: "+fullName);
            new Object[] { fullName });
            return XString.EMPTYSTRING;
        }
    }
    if (propName.equals("version") && result.length() > 0) {
        try {
            // Needs to return the version number of the spec we conform to.
            return new XString("1.0");
        } catch (Exception ex) {
            return new XString(result);
        }
    } else
        return new XString(result);
}
Also used : XString(org.apache.xpath.objects.XString) XObject(org.apache.xpath.objects.XObject) XString(org.apache.xpath.objects.XString) Properties(java.util.Properties)

Aggregations

XString (org.apache.xpath.objects.XString)20 DTM (org.apache.xml.dtm.DTM)10 XObject (org.apache.xpath.objects.XObject)6 Properties (java.util.Properties)2 TransformerException (javax.xml.transform.TransformerException)2 QName (org.apache.xml.utils.QName)2 XMLString (org.apache.xml.utils.XMLString)2 Expression (org.apache.xpath.Expression)2 XPathContext (org.apache.xpath.XPathContext)2 WrongNumberArgsException (org.apache.xpath.functions.WrongNumberArgsException)2