Search in sources :

Example 11 with NodeType

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

Example 12 with NodeType

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

the class FnNodeName method node_name.

/**
 * Node-Name operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:node-name operation.
 */
public static ResultSequence node_name(Collection args) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
    if (arg1.empty())
        return ResultBuffer.EMPTY;
    NodeType nt = (NodeType) arg1.first();
    QName nodename = nt.node_name();
    if (nodename == null)
        return ResultBuffer.EMPTY;
    return nodename;
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) Collection(java.util.Collection)

Example 13 with NodeType

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

the class FnRoot method fn_root.

/**
 * Root operation.
 *
 * @param arg
 *            Result from the expressions evaluation.
 * @param dc
 *            Result of dynamic context operation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:root operation.
 */
public static ResultSequence fn_root(Collection args, EvaluationContext ec) {
    Collection cargs = Function.convert_arguments(args, expected_args());
    if (cargs.size() > 1)
        throw new DynamicError(TypeError.invalid_type(null));
    ResultSequence arg = null;
    if (cargs.isEmpty()) {
        if (ec.getContextItem() == null) {
            throw DynamicError.contextUndefined();
        }
        arg = ResultBuffer.wrap(ec.getContextItem());
    } else {
        arg = (ResultSequence) cargs.iterator().next();
    }
    if (arg.empty()) {
        return ResultBuffer.EMPTY;
    }
    Item aa = arg.item(0);
    if (!(aa instanceof NodeType))
        throw new DynamicError(TypeError.invalid_type(null));
    NodeType nt = (NodeType) aa;
    // ok we got a sane argument... own it.
    Node root = nt.node_value();
    while (root != null && !(root instanceof Document)) {
        Node newroot = root.getParentNode();
        if (newroot == null && root instanceof Attr) {
            newroot = ((Attr) root).getOwnerElement();
        }
        // found it
        if (newroot == null)
            break;
        root = newroot;
    }
    return NodeType.dom_to_xpath(root, ec.getStaticContext().getTypeModel());
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) Node(org.w3c.dom.Node) Collection(java.util.Collection) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr)

Example 14 with NodeType

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

the class OpExcept method op_except.

/**
 * Op-Except operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of operation.
 */
public static ResultSequence op_except(Collection args) throws DynamicError {
    ResultBuffer rs = new ResultBuffer();
    // convert arguments
    Collection cargs = Function.convert_arguments(args, expected_args());
    // get arguments
    Iterator iter = cargs.iterator();
    ResultSequence one = (ResultSequence) iter.next();
    ResultSequence two = (ResultSequence) iter.next();
    // XXX lame
    for (Iterator i = one.iterator(); i.hasNext(); ) {
        NodeType node = (NodeType) i.next();
        boolean found = false;
        // death
        for (Iterator j = two.iterator(); j.hasNext(); ) {
            NodeType node2 = (NodeType) j.next();
            if (node.node_value() == node2.node_value()) {
                found = true;
                break;
            }
        }
        if (!found)
            rs.add(node);
    }
    rs = NodeType.linarize(rs);
    return rs.getSequence();
}
Also used : 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) Iterator(java.util.Iterator) Collection(java.util.Collection)

Example 15 with NodeType

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

the class DefaultEvaluator method name_test.

// XXX this routine sux
private boolean name_test(NodeType node, QName name, String type) {
    // make sure principal node kind is the same
    if (node == null) {
        return false;
    }
    if (!type.equals(node.string_type())) {
        return false;
    }
    String test_prefix = name.prefix();
    // element namespace
    if (test_prefix == null && type.equals("element")) {
        // XXX make a new copy
        name = new QName(null, name.local());
        name.set_namespace(_sc.getDefaultNamespace());
        // if we actually have a namespace, pretend we do =D
        if (name.namespace() != null && name.namespace().length() > 0)
            test_prefix = "";
    }
    QName node_name = node.node_name();
    assert node_name != null;
    // make sure namespace matches
    String node_namespace = node_name.namespace();
    String test_namespace = null;
    if (name.expanded())
        test_namespace = name.namespace();
    // name test has no prefix
    if (test_prefix == null) {
        // ok no namespace... match
        if (node_namespace == null) {
        } else {
            return false;
        }
    } else // XXX AT THIS POINT ALL PREFIXES NEED TO BE RESOLVED!
    if (!test_namespace.equals("*")) {
        // the node doesn't have a namespace... no match
        if (node_namespace == null) {
            return false;
        } else // check namespaces
        {
            if (node_namespace.equals(test_namespace)) {
            // namespace matches
            } else {
                return false;
            }
        }
    }
    // check for wildcard in localpart
    if (name.local().equals("*"))
        return true;
    // check if local part matches
    if (!name.local().equals(node_name.local())) {
        return false;
    }
    return true;
}
Also used : QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName)

Aggregations

NodeType (org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)39 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)23 Iterator (java.util.Iterator)21 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)15 Collection (java.util.Collection)12 Node (org.w3c.dom.Node)12 QName (org.eclipse.wst.xml.xpath2.processor.internal.types.QName)11 ListIterator (java.util.ListIterator)10 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)9 ElementType (org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType)9 VarExprPair (org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair)7 TypeDefinition (org.eclipse.wst.xml.xpath2.api.typesystem.TypeDefinition)6 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)5 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)5 ArrayList (java.util.ArrayList)4 Attr (org.w3c.dom.Attr)4 ForwardAxis (org.eclipse.wst.xml.xpath2.processor.internal.ForwardAxis)3 ParentAxis (org.eclipse.wst.xml.xpath2.processor.internal.ParentAxis)3 ReverseAxis (org.eclipse.wst.xml.xpath2.processor.internal.ReverseAxis)3 AttrType (org.eclipse.wst.xml.xpath2.processor.internal.types.AttrType)3