Package org.apache.jackrabbit.spi

Examples of org.apache.jackrabbit.spi.Name


            throw new PathNotFoundException(
                    "Failed to resolve path " + relPath + " relative to " + this);
        }

        // Resolve node type name (if any)
        Name typeName = null;
        if (nodeTypeName != null) {
            typeName = session.getQName(nodeTypeName);
        }

        // Check that the given UUID (if any) does not already exist
View Full Code Here


    public boolean canAddMixin(String mixinName)
            throws NoSuchNodeTypeException, RepositoryException {
        // check state of this instance
        sanityCheck();

        Name ntName = session.getQName(mixinName);
        NodeTypeManagerImpl ntMgr = session.getNodeTypeManager();
        NodeTypeImpl mixin = ntMgr.getNodeType(ntName);
        if (!mixin.isMixin()) {
            return false;
        }

        int options = ItemValidator.CHECK_LOCK | ItemValidator.CHECK_CHECKED_OUT
                | ItemValidator.CHECK_CONSTRAINTS | ItemValidator.CHECK_HOLD;
        int permissions = Permission.NODE_TYPE_MNGMT;
        // special handling of mix:(simple)versionable. since adding the mixin alters
        // the version storage jcr:versionManagement privilege is required
        // in addition.
        if (NameConstants.MIX_VERSIONABLE.equals(ntName)
                || NameConstants.MIX_SIMPLE_VERSIONABLE.equals(ntName)) {
            permissions |= Permission.VERSION_MNGMT;
        }
        if (!session.getValidator().canModify(this, options, permissions)) {
            return false;
        }

        final Name primaryTypeName = data.getNodeState().getNodeTypeName();

        NodeTypeImpl primaryType = ntMgr.getNodeType(primaryTypeName);
        if (primaryType.isDerivedFrom(ntName)) {
            // mixin already inherited -> addMixin is allowed but has no effect.
            return true;
View Full Code Here

            if (stateMgr.hasNodeReferences(getNodeId())) {
                NodeReferences refs = stateMgr.getNodeReferences(getNodeId());
                // refs.getReferences() returns a list of PropertyId's
                List<PropertyId> idList = refs.getReferences();
                if (name != null) {
                    Name qName;
                    try {
                        qName = session.getQName(name);
                    } catch (NameException e) {
                        throw new RepositoryException("invalid property name: " + name, e);
                    }
View Full Code Here

            String msg = "changing the primary type of the root node is not supported";
            log.debug(msg);
            throw new RepositoryException(msg);
        }

        Name ntName = session.getQName(nodeTypeName);
        if (ntName.equals(state.getNodeTypeName())) {
            log.debug("Node already has " + nodeTypeName + " as primary node type.");
            return;
        }

        NodeTypeManagerImpl ntMgr = session.getNodeTypeManager();
View Full Code Here

            NodeTypeIterator allTypes = ntMgr.getAllNodeTypes();
            while (allTypes.hasNext()) {
                NodeType nt = allTypes.nextNodeType();
                NodeType[] superTypes = nt.getSupertypes();
                if (Arrays.asList(superTypes).contains(base)) {
                    Name n = session.getQName(nt.getName());
                    String ntName = nsMappings.translateName(n);
                    Term t;
                    if (nt.isMixin()) {
                        // search on jcr:mixinTypes
                        t = new Term(FieldNames.PROPERTIES,
View Full Code Here

            if (relPath == null || !node.getReferencesProperty()) {
                // fulltext on node
                fieldname = FieldNames.FULLTEXT;
            } else {
                // final path element is a property name
                Name propName = relPath.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 JackrabbitQueryParser(
                    fieldname, analyzer, synonymProvider, cache);
            Query context = parser.parse(node.getQuery());
            if (relPath != null && (!node.getReferencesProperty() || relPath.getLength() > 1)) {
                // text search on some child axis
                Path.Element[] elements = relPath.getElements();
                for (int i = elements.length - 1; i >= 0; i--) {
                    Name name = null;
                    if (!elements[i].getName().equals(RelationQueryNode.STAR_NAME_TEST)) {
                        name = elements[i].getName();
                    }
                    // join text search with name test
                    // if path references property that's elements.length - 2
View Full Code Here

        Query context = null;
        LocationStepQueryNode[] steps = node.getPathSteps();
        if (steps.length > 0) {
            if (node.isAbsolute() && !steps[0].getIncludeDescendants()) {
                // eat up first step
                Name nameTest = steps[0].getNameTest();
                if (nameTest == null) {
                    // this is equivalent to the root node
                    context = new JackrabbitTermQuery(new Term(FieldNames.PARENT, ""));
                } else if (nameTest.getLocalName().length() == 0) {
                    // root node
                    context = new JackrabbitTermQuery(new Term(FieldNames.PARENT, ""));
                } else {
                    // then this is a node != the root node
                    // will never match anything!
View Full Code Here

                && node.getOperation() != QueryConstants.OPERATION_SPELLCHECK) {
            exceptions.add(new InvalidQueryException("@* not supported in predicate"));
            return data;
        }
        LocationStepQueryNode[] steps = relPath.getPathSteps();
        Name propertyName;
        if (node.getOperation() == QueryConstants.OPERATION_SIMILAR) {
            // this is a bit ugly:
            // use the name of a dummy property because relPath actually
            // references a property. whereas the relPath of the similar
            // operation references a node
            propertyName = NameConstants.JCR_PRIMARYTYPE;
        } else {
            propertyName = steps[steps.length - 1].getNameTest();
        }

        Query query;
        String[] stringValues = new String[1];
        switch (node.getValueType()) {
            case 0:
                // not set: either IS NULL or IS NOT NULL
                break;
            case QueryConstants.TYPE_DATE:
                stringValues[0] = DateField.dateToString(node.getDateValue());
                break;
            case QueryConstants.TYPE_DOUBLE:
                stringValues[0] = DoubleField.doubleToString(node.getDoubleValue());
                break;
            case QueryConstants.TYPE_LONG:
                stringValues[0] = LongField.longToString(node.getLongValue());
                break;
            case QueryConstants.TYPE_STRING:
                if (node.getOperation() == QueryConstants.OPERATION_EQ_GENERAL
                        || node.getOperation() == QueryConstants.OPERATION_EQ_VALUE
                        || node.getOperation() == QueryConstants.OPERATION_NE_GENERAL
                        || node.getOperation() == QueryConstants.OPERATION_NE_VALUE) {
                    // only use coercing on non-range operations
                    stringValues = getStringValues(propertyName, node.getStringValue());
                } else {
                    stringValues[0] = node.getStringValue();
                }
                break;
            case QueryConstants.TYPE_POSITION:
                // ignore position. is handled in the location step
                return null;
            default:
                throw new IllegalArgumentException("Unknown relation type: "
                        + node.getValueType());
        }

        // get property transformation
        final int[] transform = new int[]{TransformConstants.TRANSFORM_NONE};
        node.acceptOperands(new DefaultQueryNodeVisitor() {
            public Object visit(PropertyFunctionQueryNode node, Object data) {
                if (node.getFunctionName().equals(PropertyFunctionQueryNode.LOWER_CASE)) {
                    transform[0] = TransformConstants.TRANSFORM_LOWER_CASE;
                } else if (node.getFunctionName().equals(PropertyFunctionQueryNode.UPPER_CASE)) {
                    transform[0] = TransformConstants.TRANSFORM_UPPER_CASE;
                }
                return data;
            }
        }, null);

        String field = "";
        try {
            field = resolver.getJCRName(propertyName);
        } catch (NamespaceException e) {
            // should never happen
            exceptions.add(e);
        }

        // support for fn:name()
        if (propertyName.equals(FN_NAME)) {
            if (node.getValueType() != QueryConstants.TYPE_STRING) {
                exceptions.add(new InvalidQueryException("Name function can "
                        + "only be used in conjunction with a string literal"));
                return data;
            }
            if (node.getOperation() == QueryConstants.OPERATION_EQ_VALUE
                    || node.getOperation() == QueryConstants.OPERATION_EQ_GENERAL) {
                // check if string literal is a valid XML Name
                if (XMLChar.isValidName(node.getStringValue())) {
                    // parse string literal as JCR Name
                    try {
                        Name n = session.getQName(ISO9075.decode(node.getStringValue()));
                        query = new NameQuery(n, indexFormatVersion, nsMappings);
                    } catch (NameException e) {
                        exceptions.add(e);
                        return data;
                    } catch (NamespaceException e) {
                        exceptions.add(e);
                        return data;
                    }
                } else {
                    // will never match -> create dummy query
                    query = new BooleanQuery();
                }
            } else if (node.getOperation() == QueryConstants.OPERATION_LIKE) {
                // the like operation always has one string value.
                // no coercing, see above
                if (stringValues[0].equals("%")) {
                    query = new org.apache.lucene.search.MatchAllDocsQuery();
                } else {
                    query = new WildcardNameQuery(stringValues[0],
                            transform[0], session, nsMappings, cache);
                }
            } else {
                exceptions.add(new InvalidQueryException("Name function can "
                        + "only be used in conjunction with the following operators: equals, like"));
                return data;
            }
        } else {
            switch (node.getOperation()) {
                case QueryConstants.OPERATION_EQ_VALUE:      // =
                case QueryConstants.OPERATION_EQ_GENERAL:
                    BooleanQuery or = new BooleanQuery();
                    for (String value : stringValues) {
                        Term t = new Term(FieldNames.PROPERTIES,
                                FieldNames.createNamedValue(field, value));
                        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 JackrabbitTermQuery(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 (String value : stringValues) {
                        Term lower = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(field, value));
                        Term upper = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(field, "\uFFFF"));
                        or.add(new RangeQuery(lower, upper, true, transform[0], cache), 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 (String value : stringValues) {
                        Term lower = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(field, value));
                        Term upper = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(field, "\uFFFF"));
                        or.add(new RangeQuery(lower, upper, false, transform[0], cache), 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 (String value : stringValues) {
                        Term lower = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(field, ""));
                        Term upper = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(field, value));
                        or.add(new RangeQuery(lower, upper, true, transform[0], cache), 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 = Util.createMatchAllQuery(field, indexFormatVersion, cache);
                    } else {
                        query = new WildcardQuery(FieldNames.PROPERTIES, field, stringValues[0], transform[0], cache);
                    }
                    break;
                case QueryConstants.OPERATION_LT_VALUE:      // <
                case QueryConstants.OPERATION_LT_GENERAL:
                    or = new BooleanQuery();
                    for (String value : stringValues) {
                        Term lower = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(field, ""));
                        Term upper = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(field, value));
                        or.add(new RangeQuery(lower, upper, false, transform[0], cache), 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(Util.createMatchAllQuery(field, indexFormatVersion, cache), Occur.SHOULD);
                    // exclude all nodes where 'field' has the term in question
                    for (String value : stringValues) {
                        Term t = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(field, value));
                        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 JackrabbitTermQuery(t);
                        }
                        notQuery.add(q, Occur.MUST_NOT);
                    }
                    // and exclude all nodes where 'field' is multi valued
                    notQuery.add(new JackrabbitTermQuery(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(Util.createMatchAllQuery(field, indexFormatVersion, cache), Occur.SHOULD);
                    for (String value : stringValues) {
                        // exclude the nodes that have the term and are single valued
                        Term t = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(field, value));
                        Query svp = new NotQuery(new JackrabbitTermQuery(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 JackrabbitTermQuery(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(Util.createMatchAllQuery(field, indexFormatVersion, cache));
                    break;
                case QueryConstants.OPERATION_SIMILAR:
                    try {
                        NodeId id = hmgr.resolveNodePath(session.getQPath(node.getStringValue()));
                        if (id != null) {
                            query = new SimilarityQuery(id.toString(), analyzer);
                        } else {
                            query = new BooleanQuery();
                        }
                    } catch (Exception e) {
                        exceptions.add(e);
                        query = new BooleanQuery();
                    }
                    break;
                case QueryConstants.OPERATION_NOT_NULL:
                    query = Util.createMatchAllQuery(field, indexFormatVersion, cache);
                    break;
                case QueryConstants.OPERATION_SPELLCHECK:
                    query = Util.createMatchAllQuery(field, indexFormatVersion, cache);
                    break;
                default:
                    throw new IllegalArgumentException("Unknown relation operation: "
                            + node.getOperation());
            }
        }

        if (steps.length > 1) {
            // child axis in relation
            // elements.length - 1 = property name
            // elements.length - 2 = last child axis name test
            boolean selectParent = true;
            for (int i = steps.length - 2; i >= 0; i--) {
                LocationStepQueryNode step = steps[i];
                Name name = steps[i].getNameTest();
                if (i == steps.length - 2) {
                    if (step instanceof DerefQueryNode) {
                        query = createPredicateDeref(query, (DerefQueryNode) step, data);
                        if (steps.length == 2) {
                            selectParent = false;
                        }
                    } else if (step instanceof LocationStepQueryNode) {
                        // join name test with property query if there is one
                        if (name != null) {
                            if (!name.equals(PARENT_ELEMENT_NAME)) {
                                Query nameTest = new NameQuery(name,
                                        indexFormatVersion, nsMappings);
                                BooleanQuery and = new BooleanQuery();
                                and.add(query, Occur.MUST);
                                and.add(nameTest, Occur.MUST);
   
                                query = and;
                            } else {
                                // If we're searching the parent, we want to return the child axis,
                                // not the parent because this is part of the predicate. For instance,
                                // if the query is //child[../base], this part of the code is operating
                                // on the "../base" portion. So we want to return all the child nodes
                                // of "base", which will then be matched against the non predicate part.
                                query = new ChildAxisQuery(sharedItemMgr,
                                                           query,
                                                           null,
                                                           indexFormatVersion,
                                                           nsMappings);
                                selectParent = false;
                            }
                        } else {
                            // otherwise the query can be used as is
                        }
                    }
                } else if (name != null && name.equals(PARENT_ELEMENT_NAME)) {
                    // We need to select one of the properties if we haven't already.
                    if (selectParent) {
                        query = new ParentAxisQuery(query, null,
                                                    indexFormatVersion, nsMappings);

View Full Code Here

        for (PropertyTypeRegistry.TypeMapping type : types) {
            switch (type.type) {
                case PropertyType.NAME:
                    // try to translate name
                    try {
                        Name n = session.getQName(literal);
                        values.add(nsMappings.translateName(n));
                        log.debug("Coerced " + literal + " into NAME.");
                    } catch (NameException e) {
                        log.debug("Unable to coerce '" + literal + "' into a NAME: " + e.toString());
                    } catch (NamespaceException e) {
                        log.debug("Unable to coerce '" + literal + "' into a NAME: " + e.toString());
                    }
                    break;
                case PropertyType.PATH:
                    // try to translate path
                    try {
                        Path p = session.getQPath(literal);
                        values.add(resolver.getJCRPath(p));
                        log.debug("Coerced " + literal + " into PATH.");
                    } catch (NameException e) {
                        log.debug("Unable to coerce '" + literal + "' into a PATH: " + e.toString());
                    } catch (NamespaceException e) {
                        log.debug("Unable to coerce '" + literal + "' into a PATH: " + e.toString());
                    }
                    break;
                case PropertyType.DATE:
                    // try to parse date
                    Calendar c = ISO8601.parse(literal);
                    if (c != null) {
                        values.add(DateField.timeToString(c.getTimeInMillis()));
                        log.debug("Coerced " + literal + " into DATE.");
                    } else {
                        log.debug("Unable to coerce '" + literal + "' into a DATE.");
                    }
                    break;
                case PropertyType.DOUBLE:
                    // try to parse double
                    try {
                        double d = Double.parseDouble(literal);
                        values.add(DoubleField.doubleToString(d));
                        log.debug("Coerced " + literal + " into DOUBLE.");
                    } catch (NumberFormatException e) {
                        log.debug("Unable to coerce '" + literal + "' into a DOUBLE: " + e.toString());
                    }
                    break;
                case PropertyType.LONG:
                    // try to parse long
                    try {
                        long l = Long.parseLong(literal);
                        values.add(LongField.longToString(l));
                        log.debug("Coerced " + literal + " into LONG.");
                    } catch (NumberFormatException e) {
                        log.debug("Unable to coerce '" + literal + "' into a LONG: " + e.toString());
                    }
                    break;
                case PropertyType.DECIMAL:
                    // try to parse decimal
                    try {
                        BigDecimal d = new BigDecimal(literal);
                        values.add(DecimalField.decimalToString(d));
                        log.debug("Coerced " + literal + " into DECIMAL.");
                    } catch (NumberFormatException e) {
                        log.debug("Unable to coerce '" + literal + "' into a DECIMAL: " + e.toString());
                    }
                    break;
                case PropertyType.URI:
                    // fall through... TODO: correct?
                case PropertyType.STRING:
                    values.add(literal);
                    log.debug("Using literal " + literal + " as is.");
                    break;
            }
        }
        if (values.size() == 0) {
            // use literal as is then try to guess other types
            values.add(literal);

            // try to guess property type
            if (literal.indexOf('/') > -1) {
                // might be a path
                try {
                    values.add(resolver.getJCRPath(session.getQPath(literal)));
                    log.debug("Coerced " + literal + " into PATH.");
                } catch (Exception e) {
                    // not a path
                }
            }
            if (XMLChar.isValidName(literal)) {
                // might be a name
                try {
                    Name n = session.getQName(literal);
                    values.add(nsMappings.translateName(n));
                    log.debug("Coerced " + literal + " into NAME.");
                } catch (Exception e) {
                    // not a name
                }
View Full Code Here

     * @return true if the specified node is <i>shareable</i>, false otherwise.
     * @throws RepositoryException if an error occurs
     */
    private boolean isShareable(NodeState state) throws RepositoryException {
        // shortcut: check some wellknown built-in types first
        Name primary = state.getNodeTypeName();
        Set<Name> mixins = state.getMixinTypeNames();
        if (mixins.contains(NameConstants.MIX_SHAREABLE)) {
            return true;
        }

View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.spi.Name

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.