Search in sources :

Example 11 with XString

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

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

Example 12 with XString

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

the class FuncUnparsedEntityURI 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 name = m_arg0.execute(xctxt).str();
    int context = xctxt.getCurrentNode();
    DTM dtm = xctxt.getDTM(context);
    int doc = dtm.getDocument();
    String uri = dtm.getUnparsedEntityURI(name);
    return new XString(uri);
}
Also used : XString(org.apache.xpath.objects.XString) XString(org.apache.xpath.objects.XString) DTM(org.apache.xml.dtm.DTM)

Example 13 with XString

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

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

Example 14 with XString

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

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

Example 15 with XString

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

the class FuncSubstring 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 {
    XMLString s1 = m_arg0.execute(xctxt).xstr();
    double start = m_arg1.execute(xctxt).num();
    int lenOfS1 = s1.length();
    XMLString substr;
    if (lenOfS1 <= 0)
        return XString.EMPTYSTRING;
    else {
        int startIndex;
        if (Double.isNaN(start)) {
            // Double.MIN_VALUE doesn't work with math below 
            // so just use a big number and hope I never get caught.
            start = -1000000;
            startIndex = 0;
        } else {
            start = Math.round(start);
            startIndex = (start > 0) ? (int) start - 1 : 0;
        }
        if (null != m_arg2) {
            double len = m_arg2.num(xctxt);
            int end = (int) (Math.round(len) + start) - 1;
            // Normalize end index.
            if (end < 0)
                end = 0;
            else if (end > lenOfS1)
                end = lenOfS1;
            if (startIndex > lenOfS1)
                startIndex = lenOfS1;
            substr = s1.substring(startIndex, end);
        } else {
            if (startIndex > lenOfS1)
                startIndex = lenOfS1;
            substr = s1.substring(startIndex);
        }
    }
    // cast semi-safe
    return (XString) substr;
}
Also used : XString(org.apache.xpath.objects.XString) XMLString(org.apache.xml.utils.XMLString)

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