Search in sources :

Example 11 with ElementType

use of org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType in project webtools.sourceediting by eclipse.

the class TestXPath20 method testProcessSimpleXpath.

public void testProcessSimpleXpath() throws Exception {
    // Get XML Schema Information for the Document
    XSModel schema = getGrammar();
    setupDynamicContext(schema);
    String xpath = "/employees/employee[1]/location";
    compileXPath(xpath);
    ResultSequence rs = evaluate(domDoc);
    ElementType result = (ElementType) rs.first();
    String resultValue = result.node_value().getTextContent();
    assertEquals("Unexpected value returned", "Boston", resultValue);
}
Also used : ElementType(org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) XSModel(org.apache.xerces.xs.XSModel)

Example 12 with ElementType

use of org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType in project webtools.sourceediting by eclipse.

the class TestXPath20 method testProcessSimpleXpathVariable.

public void testProcessSimpleXpathVariable() throws Exception {
    // Get XML Schema Information for the Document
    XSModel schema = getGrammar();
    setupDynamicContext(schema);
    String xpath = "$input-context/employees/employee[1]/location";
    compileXPath(xpath);
    ResultSequence rs = evaluate(domDoc);
    ElementType result = (ElementType) rs.first();
    String resultValue = result.node_value().getTextContent();
    assertEquals("Unexpected value returned", "Boston", resultValue);
}
Also used : ElementType(org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) XSModel(org.apache.xerces.xs.XSModel)

Example 13 with ElementType

use of org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType in project webtools.sourceediting by eclipse.

the class FnInScopePrefixes method lookupPrefixes.

private static List lookupPrefixes(ElementType element) {
    Element domElm = (Element) element.node_value();
    List prefixList = new ArrayList();
    Node node = domElm;
    while (node != null && node.getNodeType() != Node.DOCUMENT_NODE) {
        NamedNodeMap attrs = node.getAttributes();
        for (int i = 0; i < attrs.getLength(); i++) {
            Node attr = attrs.item(i);
            String prefix = null;
            if (attr.getNamespaceURI() != null && attr.getNamespaceURI().equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) {
                // Default Namespace
                if (attr.getNodeName().equals(XMLConstants.XMLNS_ATTRIBUTE)) {
                    prefix = "";
                } else {
                    // Should we check the namespace in the Dynamic Context and return that???
                    prefix = attr.getLocalName();
                }
                if (prefix != null) {
                    if (!prefixList.contains(prefix)) {
                        prefixList.add(prefix);
                    }
                }
            }
        }
        node = node.getParentNode();
    }
    return prefixList;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)

Example 14 with ElementType

use of org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType in project webtools.sourceediting by eclipse.

the class FnInScopePrefixes method expected_args.

/**
 * Obtain a list of expected arguments.
 *
 * @return Result of operation.
 */
public static synchronized Collection expected_args() {
    if (_expected_args == null) {
        _expected_args = new ArrayList();
        SeqType arg = new SeqType(new ElementType(), SeqType.OCC_PLUS);
        _expected_args.add(arg);
    }
    return _expected_args;
}
Also used : ElementType(org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType) SeqType(org.eclipse.wst.xml.xpath2.processor.internal.SeqType) ArrayList(java.util.ArrayList)

Example 15 with ElementType

use of org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType in project webtools.sourceediting by eclipse.

the class FnIDREF method idref.

/**
 * Insert-Before operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @param dc
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:insert-before operation.
 */
public static ResultSequence idref(Collection args, EvaluationContext ec) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    ResultBuffer rs = new ResultBuffer();
    Iterator argIt = cargs.iterator();
    ResultSequence idrefRS = (ResultSequence) argIt.next();
    String[] idst = idrefRS.first().getStringValue().split(" ");
    ArrayList ids = createIDs(idst);
    ResultSequence nodeArg = null;
    NodeType nodeType = null;
    if (argIt.hasNext()) {
        nodeArg = (ResultSequence) argIt.next();
        nodeType = (NodeType) nodeArg.first();
    } else {
        if (ec.getContextItem() == null) {
            throw DynamicError.contextUndefined();
        }
        if (!(ec.getContextItem() instanceof NodeType)) {
            throw new DynamicError(TypeError.invalid_type(null));
        }
        nodeType = (NodeType) ec.getContextItem();
        if (nodeType.node_value().getOwnerDocument() == null) {
            throw DynamicError.contextUndefined();
        }
    }
    Node node = nodeType.node_value();
    if (node.getOwnerDocument() == null) {
        // W3C test suite seems to want XPDY0002 here
        throw DynamicError.contextUndefined();
    // throw DynamicError.noContextDoc();
    }
    if (hasID(ids, node)) {
        ElementType element = new ElementType((Element) node, ec.getStaticContext().getTypeModel());
        rs.add(element);
    }
    rs = processAttributes(node, ids, rs, ec);
    rs = processChildNodes(node, ids, rs, ec);
    return rs.getSequence();
}
Also used : ElementType(org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType) ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) Node(org.w3c.dom.Node) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) Collection(java.util.Collection) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError)

Aggregations

ElementType (org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType)19 NodeType (org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)8 Node (org.w3c.dom.Node)8 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)7 ArrayList (java.util.ArrayList)6 Iterator (java.util.Iterator)6 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)5 NodeList (org.w3c.dom.NodeList)5 Collection (java.util.Collection)4 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)4 Element (org.w3c.dom.Element)4 NamedNodeMap (org.w3c.dom.NamedNodeMap)4 ListIterator (java.util.ListIterator)3 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)3 VarExprPair (org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair)3 QName (org.eclipse.wst.xml.xpath2.processor.internal.types.QName)3 Attr (org.w3c.dom.Attr)3 List (java.util.List)2 XSModel (org.apache.xerces.xs.XSModel)2 TypeDefinition (org.eclipse.wst.xml.xpath2.api.typesystem.TypeDefinition)2