Search in sources :

Example 16 with Item

use of org.eclipse.wst.xml.xpath2.api.Item in project webtools.sourceediting by eclipse.

the class STAxesTest method test_statictypingaxis_2.

// Evaluates static typing on self axis. Context item not a node.
public void test_statictypingaxis_2() throws Exception {
    String inputFile = "/TestSources/emptydoc.xml";
    String xqFile = "/Queries/XQuery/StaticTyping/STPathExpr/STSteps/STAxes/statictypingaxis-2.xq";
    String expectedResult = "XPTY0019";
    URL fileURL = bundle.getEntry(inputFile);
    loadDOMDocument(fileURL);
    // Get XML Schema Information for the Document
    XSModel schema = getGrammar();
    setupDynamicContext(schema);
    String xpath = extractXPathExpression(xqFile, inputFile);
    String actual = null;
    try {
        compileXPath(xpath);
        ResultSequence rs = evaluate(domDoc);
        actual = buildResultString(rs);
    } catch (XPathParserException ex) {
        actual = ex.code();
    } catch (StaticError ex) {
        actual = ex.code();
    } catch (DynamicError ex) {
        actual = ex.code();
    }
    assertEquals("XPath Result Error " + xqFile + ":", expectedResult, actual);
}
Also used : XPathParserException(org.eclipse.wst.xml.xpath2.processor.XPathParserException) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) XSModel(org.apache.xerces.xs.XSModel) StaticError(org.eclipse.wst.xml.xpath2.processor.StaticError) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError) URL(java.net.URL)

Example 17 with Item

use of org.eclipse.wst.xml.xpath2.api.Item in project webtools.sourceediting by eclipse.

the class AbstractURIFunction method escape_uri.

/**
 * Apply the URI escaping rules to the arguments.
 *
 * @param args
 *            have the URI escaping rules applied to them.
 * @param escape_space TODO
 * @throws DynamicError
 *             Dynamic error.
 * @return The result of applying the URI escaping rules to the arguments.
 */
public static ResultSequence escape_uri(Collection args, boolean escape_delimiters, boolean escape_space) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    Iterator argi = cargs.iterator();
    ResultSequence arg1 = (ResultSequence) argi.next();
    if (arg1.empty()) {
        return new XSString("");
    }
    AnyType aat = (AnyType) arg1.item(0);
    String str = aat.getStringValue();
    ByteBuffer buffer = UTF_8.encode(str);
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < buffer.limit(); i++) {
        byte x = buffer.get(i);
        if (needs_escape(x, escape_delimiters, escape_space)) {
            sb.append("%");
            sb.append(Integer.toHexString(x & 0xFF).toUpperCase());
        } else
            sb.append((char) x);
    }
    return new XSString(sb.toString());
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Iterator(java.util.Iterator) Collection(java.util.Collection) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType) ByteBuffer(java.nio.ByteBuffer)

Example 18 with Item

use of org.eclipse.wst.xml.xpath2.api.Item in project webtools.sourceediting by eclipse.

the class FnAdjustDateToTimeZone method adjustDate.

/**
 * Evaluate the function using the arguments passed.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @param sc
 *            Result of static context operation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of the fn:dateTime operation.
 */
public static ResultSequence adjustDate(Collection args, DynamicContext dc) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expectedArgs());
    // get args
    Iterator argiter = cargs.iterator();
    ResultSequence arg1 = (ResultSequence) argiter.next();
    if (arg1.empty()) {
        return ResultBuffer.EMPTY;
    }
    ResultSequence arg2 = ResultBuffer.EMPTY;
    if (argiter.hasNext()) {
        arg2 = (ResultSequence) argiter.next();
    }
    XSDate date = (XSDate) arg1.item(0);
    XSDayTimeDuration timezone = null;
    if (arg2.empty()) {
        if (date.timezoned()) {
            XSDate localized = new XSDate(date.calendar(), null);
            return localized;
        }
        return arg1;
    }
    timezone = (XSDayTimeDuration) arg2.item(0);
    if (timezone.lt(minDuration, dc) || timezone.gt(maxDuration, dc)) {
        throw DynamicError.invalidTimezone();
    }
    if (date.tz() == null) {
        return new XSDate(date.calendar(), timezone);
    }
    XMLGregorianCalendar xmlCalendar = _datatypeFactory.newXMLGregorianCalendar((GregorianCalendar) date.normalizeCalendar(date.calendar(), date.tz()));
    Duration duration = _datatypeFactory.newDuration(timezone.getStringValue());
    xmlCalendar.add(duration);
    return new XSDate(xmlCalendar.toGregorianCalendar(), timezone);
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) XSDate(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDate) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Iterator(java.util.Iterator) XSDayTimeDuration(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration) Collection(java.util.Collection) Duration(javax.xml.datatype.Duration) XSDayTimeDuration(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration)

Example 19 with Item

use of org.eclipse.wst.xml.xpath2.api.Item in project webtools.sourceediting by eclipse.

the class ElementTest method createElementType.

private AnyType createElementType(Item at, StaticContext sc) {
    anyType = new ElementType();
    NodeType nodeType = (NodeType) at;
    Node node = nodeType.node_value();
    Document doc = null;
    if (node.getNodeType() == Node.DOCUMENT_NODE) {
        doc = (Document) node;
    } else {
        doc = nodeType.node_value().getOwnerDocument();
    }
    NodeList nodeList = null;
    if (!wild()) {
        nodeList = doc.getElementsByTagNameNS(name().namespace(), name().local());
    } else {
        nodeList = new SingleItemNodeListImpl(node);
    }
    if (nodeList.getLength() > 0) {
        anyType = createElementForXSDType(nodeList, sc);
    }
    return anyType;
}
Also used : ElementType(org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document)

Example 20 with Item

use of org.eclipse.wst.xml.xpath2.api.Item in project webtools.sourceediting by eclipse.

the class AttributeTest method createAttrType.

private AnyType createAttrType(Item at, StaticContext sc) {
    anyType = new AttrType();
    NodeType nodeType = (NodeType) at;
    Node node = nodeType.node_value();
    if (node == null) {
        return anyType;
    }
    String nodeName = node.getLocalName();
    if (wild()) {
        if (type() != null) {
            anyType = createAttrForXSDType(node, sc);
        }
    } else if (nodeName.equals(name().local())) {
        if (type() != null) {
            anyType = createAttrForXSDType(node, sc);
        } else {
            anyType = new AttrType((Attr) node, sc.getTypeModel());
        }
    }
    return anyType;
}
Also used : AttrType(org.eclipse.wst.xml.xpath2.processor.internal.types.AttrType) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) Node(org.w3c.dom.Node)

Aggregations

DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)71 Item (org.eclipse.wst.xml.xpath2.api.Item)69 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)66 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)65 URL (java.net.URL)64 XSModel (org.apache.xerces.xs.XSModel)64 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)64 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)46 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)34 Iterator (java.util.Iterator)26 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)14 BigInteger (java.math.BigInteger)13 Collection (java.util.Collection)13 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)11 ListIterator (java.util.ListIterator)8 NodeType (org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)8 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)6 NumericType (org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType)5 ArrayList (java.util.ArrayList)4 GregorianCalendar (java.util.GregorianCalendar)4