Search in sources :

Example 56 with Name

use of org.apache.jackrabbit.spi.Name in project jackrabbit by apache.

the class QueryFormat method visit.

public Object visit(OrderQueryNode node, Object data) {
    StringBuffer sb = (StringBuffer) data;
    sb.append(" order by");
    OrderQueryNode.OrderSpec[] specs = node.getOrderSpecs();
    String comma = "";
    try {
        for (int i = 0; i < specs.length; i++) {
            sb.append(comma);
            Path propPath = specs[i].getPropertyPath();
            Path.Element[] elements = propPath.getElements();
            sb.append(" ");
            String slash = "";
            for (int j = 0; j < elements.length; j++) {
                sb.append(slash);
                slash = "/";
                Path.Element element = elements[j];
                Name name = encode(element.getName());
                if (j == elements.length - 1) {
                    // last
                    sb.append("@");
                }
                sb.append(resolver.getJCRName(name));
            }
            if (!specs[i].isAscending()) {
                sb.append(" descending");
            }
            comma = ",";
        }
    } catch (NamespaceException e) {
        exceptions.add(e);
    }
    return data;
}
Also used : Path(org.apache.jackrabbit.spi.Path) NamespaceException(javax.jcr.NamespaceException) Name(org.apache.jackrabbit.spi.Name)

Example 57 with Name

use of org.apache.jackrabbit.spi.Name in project jackrabbit by apache.

the class QueryFormat method visit.

public Object visit(TextsearchQueryNode node, Object data) {
    StringBuffer sb = (StringBuffer) data;
    try {
        sb.append(resolver.getJCRName(XPathQueryBuilder.JCR_CONTAINS));
        sb.append("(");
        Path relPath = node.getRelativePath();
        if (relPath == null) {
            sb.append(".");
        } else {
            Path.Element[] elements = relPath.getElements();
            String slash = "";
            for (int i = 0; i < elements.length; i++) {
                sb.append(slash);
                slash = "/";
                if (node.getReferencesProperty() && i == elements.length - 1) {
                    sb.append("@");
                }
                if (elements[i].getName().equals(RelationQueryNode.STAR_NAME_TEST)) {
                    sb.append("*");
                } else {
                    Name n = encode(elements[i].getName());
                    sb.append(resolver.getJCRName(n));
                }
                if (elements[i].getIndex() != 0) {
                    sb.append("[").append(elements[i].getIndex()).append("]");
                }
            }
        }
        sb.append(", '");
        sb.append(node.getQuery().replaceAll("'", "''"));
        sb.append("')");
    } catch (NamespaceException e) {
        exceptions.add(e);
    }
    return sb;
}
Also used : Path(org.apache.jackrabbit.spi.Path) NamespaceException(javax.jcr.NamespaceException) Name(org.apache.jackrabbit.spi.Name)

Example 58 with Name

use of org.apache.jackrabbit.spi.Name in project jackrabbit by apache.

the class NameFactoryTest method testCreationFromOtherString.

public void testCreationFromOtherString() throws Exception {
    for (int i = 0; i < tests.length; i++) {
        final JcrName t = tests[i];
        if (t.isValid()) {
            Name n1 = new Name() {

                public String getLocalName() {
                    return t.jcrName;
                }

                public String getNamespaceURI() {
                    return t.prefix;
                }

                public int compareTo(Object o) {
                    throw new UnsupportedOperationException();
                }

                public String toString() {
                    return "{" + t.prefix + "}" + t.jcrName;
                }

                public boolean equals(Object obj) {
                    if (obj instanceof Name) {
                        Name n = (Name) obj;
                        return n.getLocalName().equals(t.jcrName) && n.getNamespaceURI().equals(t.prefix);
                    }
                    return false;
                }
            };
            Name n2 = factory.create(n1.toString());
            assertTrue(n1.getLocalName().equals(n2.getLocalName()));
            assertTrue(n1.getNamespaceURI().equals(n2.getNamespaceURI()));
            assertTrue(n2.equals(n1));
        }
    }
}
Also used : Name(org.apache.jackrabbit.spi.Name)

Example 59 with Name

use of org.apache.jackrabbit.spi.Name in project jackrabbit by apache.

the class NameFactoryTest method testEquality.

public void testEquality() throws Exception {
    for (int i = 0; i < tests.length; i++) {
        final JcrName t = tests[i];
        if (t.isValid()) {
            Name n1 = new Name() {

                public String getLocalName() {
                    return t.jcrName;
                }

                public String getNamespaceURI() {
                    return t.prefix;
                }

                public int compareTo(Object o) {
                    throw new UnsupportedOperationException();
                }
            };
            Name n2 = factory.create(t.prefix, t.jcrName);
            assertTrue(n2.equals(n1));
        }
    }
}
Also used : Name(org.apache.jackrabbit.spi.Name)

Example 60 with Name

use of org.apache.jackrabbit.spi.Name in project jackrabbit by apache.

the class PathBuilderTest method buildReverse.

private Path buildReverse(String path, boolean normalize) throws Exception {
    PathBuilder builder = new PathBuilder();
    String[] elems = explode(path, '/', false);
    for (int i = elems.length - 1; i >= 0; i--) {
        int pos = elems[i].indexOf('[');
        String elem;
        Name name;
        int index;
        if (pos < 0) {
            elem = elems[i];
            index = -1;
        } else {
            index = Integer.parseInt(elems[i].substring(pos + 1, elems[i].length() - 1));
            elem = elems[i].substring(0, pos);
        }
        if (".".equals(elem)) {
            builder.addFirst(factory.getCurrentElement());
        } else if ("..".equals(elems[i])) {
            builder.addFirst(factory.getParentElement());
        } else {
            name = NameParser.parse(elem, nsResolver, NameFactoryImpl.getInstance());
            if (index < 0) {
                builder.addFirst(name);
            } else {
                builder.addFirst(name, index);
            }
        }
    }
    if (path.startsWith("/")) {
        builder.addRoot();
    }
    return normalize ? builder.getPath().getNormalizedPath() : builder.getPath();
}
Also used : Name(org.apache.jackrabbit.spi.Name)

Aggregations

Name (org.apache.jackrabbit.spi.Name)382 RepositoryException (javax.jcr.RepositoryException)101 ArrayList (java.util.ArrayList)57 QValue (org.apache.jackrabbit.spi.QValue)42 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)39 HashSet (java.util.HashSet)38 Path (org.apache.jackrabbit.spi.Path)38 NodeId (org.apache.jackrabbit.core.id.NodeId)37 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)33 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)32 NodeId (org.apache.jackrabbit.spi.NodeId)32 PropertyId (org.apache.jackrabbit.core.id.PropertyId)29 HashMap (java.util.HashMap)28 NamespaceException (javax.jcr.NamespaceException)28 NodeState (org.apache.jackrabbit.core.state.NodeState)28 Value (javax.jcr.Value)25 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)25 InternalValue (org.apache.jackrabbit.core.value.InternalValue)23 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)22 PropertyState (org.apache.jackrabbit.core.state.PropertyState)22