Search in sources :

Example 1 with ElementType

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

the class FnIDREF method processChildNodes.

private static ResultBuffer processChildNodes(Node node, List ids, ResultBuffer rs, EvaluationContext ec) {
    if (!node.hasChildNodes()) {
        return rs;
    }
    NodeList nodeList = node.getChildNodes();
    for (int nodecnt = 0; nodecnt < nodeList.getLength(); nodecnt++) {
        Node childNode = nodeList.item(nodecnt);
        if (childNode.getNodeType() == Node.ELEMENT_NODE && !isDuplicate(childNode, rs)) {
            ElementType element = new ElementType((Element) childNode, ec.getStaticContext().getTypeModel());
            if (element.isIDREF()) {
                if (hasID(ids, childNode)) {
                    rs.add(element);
                }
            }
            rs = processAttributes(childNode, ids, rs, ec);
            rs = processChildNodes(childNode, ids, rs, ec);
        }
    }
    return rs;
}
Also used : ElementType(org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node)

Example 2 with ElementType

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

the class FnInScopePrefixes method inScopePrefixes.

/**
 * Prefix-from-QName operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:prefix-from-QName operation.
 */
public static ResultSequence inScopePrefixes(Collection args, DynamicContext dc) throws DynamicError {
    // Collection cargs = Function.convert_arguments(args, expected_args());
    Collection cargs = args;
    ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
    if (arg1.empty())
        return ResultBuffer.EMPTY;
    ResultBuffer rs = new ResultBuffer();
    Item anytype = arg1.item(0);
    if (!(anytype instanceof ElementType)) {
        throw new DynamicError(TypeError.invalid_type(null));
    }
    ElementType element = (ElementType) anytype;
    List prefixList = lookupPrefixes(element);
    createPrefixResultSet(rs, prefixList);
    return rs.getSequence();
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) 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) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError)

Example 3 with ElementType

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

the class FnID method processChildNodes.

private static void processChildNodes(Node node, List idrefs, ResultBuffer rs, EvaluationContext context) {
    if (!node.hasChildNodes()) {
        return;
    }
    NodeList nodeList = node.getChildNodes();
    for (int nodecnt = 0; nodecnt < nodeList.getLength(); nodecnt++) {
        Node childNode = nodeList.item(nodecnt);
        if (childNode.getNodeType() == Node.ELEMENT_NODE && !isDuplicate(childNode, rs)) {
            ElementType element = new ElementType((Element) childNode, context.getStaticContext().getTypeModel());
            if (element.isID()) {
                if (hasIDREF(idrefs, childNode)) {
                    rs.add(element);
                }
            }
            processAttributes(childNode, idrefs, rs, context);
            processChildNodes(childNode, idrefs, rs, context);
        }
    }
}
Also used : ElementType(org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node)

Example 4 with ElementType

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

the class FnID method id.

/**
 * Insert-Before operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:insert-before operation.
 */
public static ResultSequence id(Collection args, EvaluationContext context) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    ResultBuffer rs = new ResultBuffer();
    Iterator argIt = cargs.iterator();
    ResultSequence idrefRS = (ResultSequence) argIt.next();
    String[] idrefst = idrefRS.first().getStringValue().split(" ");
    ArrayList idrefs = createIDRefs(idrefst);
    ResultSequence nodeArg = null;
    NodeType nodeType = null;
    if (argIt.hasNext()) {
        nodeArg = (ResultSequence) argIt.next();
        nodeType = (NodeType) nodeArg.first();
    } else {
        if (context.getContextItem() == null) {
            throw DynamicError.contextUndefined();
        }
        if (!(context.getContextItem() instanceof NodeType)) {
            throw new DynamicError(TypeError.invalid_type(null));
        }
        nodeType = (NodeType) context.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
        throw DynamicError.contextUndefined();
    // throw DynamicError.noContextDoc();
    }
    if (hasIDREF(idrefs, node)) {
        ElementType element = new ElementType((Element) node, context.getStaticContext().getTypeModel());
        rs.add(element);
    }
    processAttributes(node, idrefs, rs, context);
    processChildNodes(node, idrefs, rs, context);
    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)

Example 5 with ElementType

use of org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType 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)

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