Package org.apache.jackrabbit.name

Examples of org.apache.jackrabbit.name.Path


                    + " already exists!";
            log.debug(msg);
            throw new ItemExistsException(msg);
        } else if (uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING) {
            // make sure conflicting node is not importTarget or an ancestor thereof
            Path p0 = hierMgr.getPath(importTarget.getNodeId());
            Path p1 = hierMgr.getPath(conflicting.getNodeId());
            try {
                if (p1.equals(p0) || p1.isAncestorOf(p0)) {
                    String msg = "cannot remove ancestor node";
                    log.debug(msg);
                    throw new ConstraintViolationException(msg);
                }
            } catch (MalformedPathException mpe) {
View Full Code Here


            RepositoryException {

        checkInitialized();
        try {
            NamespaceResolver resolver = session.getNamespaceResolver();
            Path p = PathFormat.parse(absPath, resolver).getNormalizedPath();
            if (!p.isAbsolute()) {
                throw new RepositoryException(absPath + " is not an absolute path");
            }

            String relPath = PathFormat.format(p, resolver).substring(1);
            Node queryNode = session.getRootNode().addNode(relPath,
View Full Code Here

                    operation.setId(in.readPropertyId());
                    processor.process(operation);
                } else if (c == 'E') {
                    int type = in.readByte();
                    NodeId parentId = in.readNodeId();
                    Path parentPath = in.readPath();
                    NodeId childId = in.readNodeId();
                    Path.PathElement childRelPath = in.readPathElement();
                    QName ntName = in.readQName();

                    Set mixins = new HashSet();
View Full Code Here

    public Object visit(TextsearchQueryNode node, Object data) {
        StringBuffer sb = (StringBuffer) data;
        try {
            NameFormat.format(XPathQueryBuilder.JCR_CONTAINS, resolver, sb);
            sb.append("(");
            Path relPath = node.getRelativePath();
            if (relPath == null) {
                sb.append(".");
            } else {
                Path.PathElement[] elements = relPath.getElements();
                String slash = "";
                for (int i = 0; i < elements.length; i++) {
                    sb.append(slash);
                    slash = "/";
                    if (node.getReferencesProperty() && i == elements.length - 1) {
View Full Code Here

        StringBuffer sb = (StringBuffer) data;
        try {

            StringBuffer propPath = new StringBuffer();
            // only encode if not position function
            Path relPath = node.getRelativePath();
            if (relPath.getNameElement().getName().equals(XPathQueryBuilder.FN_POSITION_FULL)) {
                NameFormat.format(XPathQueryBuilder.FN_POSITION_FULL, resolver, propPath);
            } else {
                Path.PathElement[] elements = relPath.getElements();
                String slash = "";
                for (int i = 0; i < elements.length; i++) {
                    propPath.append(slash);
                    slash = "/";
                    if (i == elements.length - 1) {
View Full Code Here

     * @param doc           The document to which to add the field
     * @param fieldName     The name of the field to add
     * @param internalValue The value for the field to add to the document.
     */
    protected void addPathValue(Document doc, String fieldName, Object internalValue) {
        Path path = (Path) internalValue;
        String pathString = path.toString();
        try {
            pathString = PathFormat.format(path, mappings);
        } catch (NoPrefixDeclaredException e) {
            // will never happen
        }
View Full Code Here

        }
    }

    public Object visit(TextsearchQueryNode node, Object data) {
        try {
            Path relPath = node.getRelativePath();
            String fieldname;
            if (relPath == null || !node.getReferencesProperty()) {
                // fulltext on node
                fieldname = FieldNames.FULLTEXT;
            } else {
                // final path element is a property name
                QName propName = relPath.getNameElement().getName();
                StringBuffer tmp = new StringBuffer();
                tmp.append(nsMappings.getPrefix(propName.getNamespaceURI()));
                tmp.append(":").append(FieldNames.FULLTEXT_PREFIX);
                tmp.append(propName.getLocalName());
                fieldname = tmp.toString();
            }
            QueryParser parser = new QueryParser(fieldname, analyzer);
            parser.setOperator(QueryParser.DEFAULT_OPERATOR_AND);
            // replace unescaped ' with " and escaped ' with just '
            StringBuffer query = new StringBuffer();
            String textsearch = node.getQuery();
            // the default lucene query parser recognizes 'AND' and 'NOT' as
            // keywords.
            textsearch = textsearch.replaceAll("AND", "and");
            textsearch = textsearch.replaceAll("NOT", "not");
            boolean escaped = false;
            for (int i = 0; i < textsearch.length(); i++) {
                if (textsearch.charAt(i) == '\\') {
                    if (escaped) {
                        query.append("\\\\");
                        escaped = false;
                    } else {
                        escaped = true;
                    }
                } else if (textsearch.charAt(i) == '\'') {
                    if (escaped) {
                        query.append('\'');
                        escaped = false;
                    } else {
                        query.append('\"');
                    }
                } else {
                    if (escaped) {
                        query.append('\\');
                        escaped = false;
                    }
                    query.append(textsearch.charAt(i));
                }
            }
            Query context = parser.parse(query.toString());
            if (relPath != null && (!node.getReferencesProperty() || relPath.getLength() > 1)) {
                // text search on some child axis
                Path.PathElement[] elements = relPath.getElements();
                for (int i = elements.length - 1; i >= 0; i--) {
                    String name = null;
                    if (!elements[i].getName().equals(RelationQueryNode.STAR_NAME_TEST)) {
                        name = NameFormat.format(elements[i].getName(), nsMappings);;
                    }
View Full Code Here

                }
                return data;
            }
        }, null);

        Path relPath = node.getRelativePath();
        String field = "";
        try {
            field = NameFormat.format(relPath.getNameElement().getName(), nsMappings);
        } catch (NoPrefixDeclaredException e) {
            // should never happen
            exceptions.add(e);
        }

        switch (node.getOperation()) {
            case QueryConstants.OPERATION_EQ_VALUE:      // =
            case QueryConstants.OPERATION_EQ_GENERAL:
                BooleanQuery or = new BooleanQuery();
                for (int i = 0; i < stringValues.length; i++) {
                    Term t = new Term(FieldNames.PROPERTIES,
                                FieldNames.createNamedValue(field, stringValues[i]));
                    Query q;
                    if (transform[0] == TransformConstants.TRANSFORM_UPPER_CASE) {
                        q = new CaseTermQuery.Upper(t);
                    } else if (transform[0] == TransformConstants.TRANSFORM_LOWER_CASE) {
                        q = new CaseTermQuery.Lower(t);
                    } else {
                        q = new TermQuery(t);
                    }
                    or.add(q, Occur.SHOULD);
                }
                query = or;
                if (node.getOperation() == QueryConstants.OPERATION_EQ_VALUE) {
                    query = createSingleValueConstraint(or, field);
                }
                break;
            case QueryConstants.OPERATION_GE_VALUE:      // >=
            case QueryConstants.OPERATION_GE_GENERAL:
                or = new BooleanQuery();
                for (int i = 0; i < stringValues.length; i++) {
                    Term lower = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(field, stringValues[i]));
                    Term upper = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(field, "\uFFFF"));
                    or.add(new RangeQuery(lower, upper, true, transform[0]), Occur.SHOULD);
                }
                query = or;
                if (node.getOperation() == QueryConstants.OPERATION_GE_VALUE) {
                    query = createSingleValueConstraint(or, field);
                }
                break;
            case QueryConstants.OPERATION_GT_VALUE:      // >
            case QueryConstants.OPERATION_GT_GENERAL:
                or = new BooleanQuery();
                for (int i = 0; i < stringValues.length; i++) {
                    Term lower = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(field, stringValues[i]));
                    Term upper = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(field, "\uFFFF"));
                    or.add(new RangeQuery(lower, upper, false, transform[0]), Occur.SHOULD);
                }
                query = or;
                if (node.getOperation() == QueryConstants.OPERATION_GT_VALUE) {
                    query = createSingleValueConstraint(or, field);
                }
                break;
            case QueryConstants.OPERATION_LE_VALUE:      // <=
            case QueryConstants.OPERATION_LE_GENERAL:      // <=
                or = new BooleanQuery();
                for (int i = 0; i < stringValues.length; i++) {
                    Term lower = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(field, ""));
                    Term upper = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(field, stringValues[i]));
                    or.add(new RangeQuery(lower, upper, true, transform[0]), Occur.SHOULD);
                }
                query = or;
                if (node.getOperation() == QueryConstants.OPERATION_LE_VALUE) {
                    query = createSingleValueConstraint(query, field);
                }
                break;
            case QueryConstants.OPERATION_LIKE:          // LIKE
                // the like operation always has one string value.
                // no coercing, see above
                if (stringValues[0].equals("%")) {
                    query = new MatchAllQuery(field);
                } else {
                    query = new WildcardQuery(FieldNames.PROPERTIES, field, stringValues[0], transform[0]);
                }
                break;
            case QueryConstants.OPERATION_LT_VALUE:      // <
            case QueryConstants.OPERATION_LT_GENERAL:
                or = new BooleanQuery();
                for (int i = 0; i < stringValues.length; i++) {
                    Term lower = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(field, ""));
                    Term upper = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(field, stringValues[i]));
                    or.add(new RangeQuery(lower, upper, false, transform[0]), Occur.SHOULD);
                }
                query = or;
                if (node.getOperation() == QueryConstants.OPERATION_LT_VALUE) {
                    query = createSingleValueConstraint(or, field);
                }
                break;
            case QueryConstants.OPERATION_NE_VALUE:      // !=
                // match nodes with property 'field' that includes svp and mvp
                BooleanQuery notQuery = new BooleanQuery();
                notQuery.add(new MatchAllQuery(field), Occur.SHOULD);
                // exclude all nodes where 'field' has the term in question
                for (int i = 0; i < stringValues.length; i++) {
                    Term t = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(field, stringValues[i]));
                    Query q;
                    if (transform[0] == TransformConstants.TRANSFORM_UPPER_CASE) {
                        q = new CaseTermQuery.Upper(t);
                    } else if (transform[0] == TransformConstants.TRANSFORM_LOWER_CASE) {
                        q = new CaseTermQuery.Lower(t);
                    } else {
                        q = new TermQuery(t);
                    }
                    notQuery.add(q, Occur.MUST_NOT);
                }
                // and exclude all nodes where 'field' is multi valued
                notQuery.add(new TermQuery(new Term(FieldNames.MVP, field)), Occur.MUST_NOT);
                query = notQuery;
                break;
            case QueryConstants.OPERATION_NE_GENERAL:    // !=
                // that's:
                // all nodes with property 'field'
                // minus the nodes that have a single property 'field' that is
                //    not equal to term in question
                // minus the nodes that have a multi-valued property 'field' and
                //    all values are equal to term in question
                notQuery = new BooleanQuery();
                notQuery.add(new MatchAllQuery(field), Occur.SHOULD);
                for (int i = 0; i < stringValues.length; i++) {
                    // exclude the nodes that have the term and are single valued
                    Term t = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(field, stringValues[i]));
                    Query svp = new NotQuery(new TermQuery(new Term(FieldNames.MVP, field)));
                    BooleanQuery and = new BooleanQuery();
                    Query q;
                    if (transform[0] == TransformConstants.TRANSFORM_UPPER_CASE) {
                        q = new CaseTermQuery.Upper(t);
                    } else if (transform[0] == TransformConstants.TRANSFORM_LOWER_CASE) {
                        q = new CaseTermQuery.Lower(t);
                    } else {
                        q = new TermQuery(t);
                    }
                    and.add(q, Occur.MUST);
                    and.add(svp, Occur.MUST);
                    notQuery.add(and, Occur.MUST_NOT);
                }
                // todo above also excludes multi-valued properties that contain
                //      multiple instances of only stringValues. e.g. text={foo, foo}
                query = notQuery;
                break;
            case QueryConstants.OPERATION_NULL:
                query = new NotQuery(new MatchAllQuery(field));
                break;
            case QueryConstants.OPERATION_NOT_NULL:
                query = new MatchAllQuery(field);
                break;
            default:
                throw new IllegalArgumentException("Unknown relation operation: "
                        + node.getOperation());
        }

        if (relPath.getLength() > 1) {
            try {
                // child axis in relation
                Path.PathElement[] elements = relPath.getElements();
                // elements.length - 1 = property name
                // elements.length - 2 = last child axis name test
                for (int i = elements.length - 2; i >= 0; i--) {
                    String name = null;
                    if (!elements[i].getName().equals(RelationQueryNode.STAR_NAME_TEST)) {
View Full Code Here

    }

    public Object visit(ASTContainsExpression node, Object data) {
        NAryQueryNode parent = (NAryQueryNode) data;
        try {
            Path relPath = null;
            if (node.getPropertyName() != null) {
                Path.PathBuilder builder = new Path.PathBuilder();
                builder.addLast(node.getPropertyName());
                relPath = builder.getPath();
            }
View Full Code Here

        RelationQueryNode node = null;

        try {
            Path.PathBuilder builder = new Path.PathBuilder();
            builder.addLast(propertyName);
            Path relPath = builder.getPath();
            if (literal.getType() == QueryConstants.TYPE_DATE) {
                SimpleDateFormat format = new SimpleDateFormat(DATE_PATTERN);
                Date date = format.parse(stringValue);
                node = new RelationQueryNode(parent, relPath, date, operationType);
            } else if (literal.getType() == QueryConstants.TYPE_DOUBLE) {
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.name.Path

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.