Search in sources :

Example 1 with IllegalNameException

use of org.apache.jackrabbit.spi.commons.conversion.IllegalNameException in project jackrabbit by apache.

the class EventState method setupCachingPathResolver.

private static void setupCachingPathResolver() {
    if (cachingPathResolver != null) {
        return;
    }
    PathResolver pathResolver = new ParsingPathResolver(PathFactoryImpl.getInstance(), new NameResolver() {

        public Name getQName(String name) throws IllegalNameException, NamespaceException {
            return null;
        }

        public String getJCRName(Name name) throws NamespaceException {
            return name.getLocalName();
        }
    });
    cachingPathResolver = new CachingPathResolver(pathResolver);
}
Also used : NamespaceException(javax.jcr.NamespaceException) CachingPathResolver(org.apache.jackrabbit.spi.commons.conversion.CachingPathResolver) PathResolver(org.apache.jackrabbit.spi.commons.conversion.PathResolver) ParsingPathResolver(org.apache.jackrabbit.spi.commons.conversion.ParsingPathResolver) IllegalNameException(org.apache.jackrabbit.spi.commons.conversion.IllegalNameException) ParsingPathResolver(org.apache.jackrabbit.spi.commons.conversion.ParsingPathResolver) NameResolver(org.apache.jackrabbit.spi.commons.conversion.NameResolver) Name(org.apache.jackrabbit.spi.Name) CachingPathResolver(org.apache.jackrabbit.spi.commons.conversion.CachingPathResolver)

Example 2 with IllegalNameException

use of org.apache.jackrabbit.spi.commons.conversion.IllegalNameException in project jackrabbit by apache.

the class AggregateRuleImpl method getPropertyIncludes.

/**
 * Creates property includes defined in the <code>config</code>.
 *
 * @param config the indexing aggregate configuration.
 * @return the property includes defined in the <code>config</code>.
 * @throws MalformedPathException if a path in the configuration is
 *                                malformed.
 * @throws IllegalNameException   if the node type name contains illegal
 *                                characters.
 * @throws NamespaceException if the node type contains an unknown
 *                                prefix.
 * @throws RepositoryException If the PropertyInclude cannot be builded
 * due to unknown ancestor relationship.
 */
private PropertyInclude[] getPropertyIncludes(Node config) throws MalformedPathException, IllegalNameException, NamespaceException, RepositoryException {
    List<PropertyInclude> includes = new ArrayList<PropertyInclude>();
    NodeList childNodes = config.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node n = childNodes.item(i);
        if (n.getNodeName().equals("include-property")) {
            PathBuilder builder = new PathBuilder();
            for (String element : Text.explode(getTextContent(n), '/')) {
                if (element.equals("*")) {
                    throw new IllegalNameException("* not supported in include-property");
                }
                builder.addLast(resolver.getQName(element));
            }
            includes.add(new PropertyInclude(builder.getPath()));
        }
    }
    return includes.toArray(new PropertyInclude[includes.size()]);
}
Also used : PathBuilder(org.apache.jackrabbit.spi.commons.name.PathBuilder) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) IllegalNameException(org.apache.jackrabbit.spi.commons.conversion.IllegalNameException)

Example 3 with IllegalNameException

use of org.apache.jackrabbit.spi.commons.conversion.IllegalNameException in project jackrabbit by apache.

the class LuceneQueryFactory method getNodeNameQuery.

protected Query getNodeNameQuery(int transform, String operator, StaticOperand right) throws RepositoryException {
    if (transform != TRANSFORM_NONE || !JCR_OPERATOR_EQUAL_TO.equals(operator)) {
        throw new UnsupportedRepositoryOperationException();
    }
    Value value = evaluator.getValue(right);
    int type = value.getType();
    String string = value.getString();
    if (type == PropertyType.URI && string.startsWith("./")) {
        string = string.substring("./".length());
    } else if (type == PropertyType.DOUBLE || type == PropertyType.DECIMAL || type == PropertyType.LONG || type == PropertyType.BOOLEAN || type == PropertyType.REFERENCE || type == PropertyType.WEAKREFERENCE) {
        throw new InvalidQueryException("Invalid name value: " + string);
    }
    try {
        Name name = session.getQName(string);
        Term uri = new Term(NAMESPACE_URI, name.getNamespaceURI());
        Term local = new Term(LOCAL_NAME, name.getLocalName());
        BooleanQuery query = new BooleanQuery();
        query.add(new JackrabbitTermQuery(uri), MUST);
        query.add(new JackrabbitTermQuery(local), MUST);
        return query;
    } catch (IllegalNameException e) {
        throw new InvalidQueryException("Illegal name: " + string, e);
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) BooleanQuery(org.apache.lucene.search.BooleanQuery) Value(javax.jcr.Value) PropertyValue(javax.jcr.query.qom.PropertyValue) Term(org.apache.lucene.index.Term) IllegalNameException(org.apache.jackrabbit.spi.commons.conversion.IllegalNameException) Constraint(javax.jcr.query.qom.Constraint) InvalidQueryException(javax.jcr.query.InvalidQueryException) NodeName(javax.jcr.query.qom.NodeName) NodeLocalName(javax.jcr.query.qom.NodeLocalName) Name(org.apache.jackrabbit.spi.Name)

Example 4 with IllegalNameException

use of org.apache.jackrabbit.spi.commons.conversion.IllegalNameException in project jackrabbit by apache.

the class SharedFieldComparatorSource method newComparator.

/**
 * Create a new <code>FieldComparator</code> for an embedded <code>propertyName</code>
 * and a <code>reader</code>.
 *
 * @param propertyName the relative path to the property to sort on as returned
 *          by {@link org.apache.jackrabbit.spi.Path#getString()}.
 * @return a <code>FieldComparator</code>
 * @throws java.io.IOException if an error occurs
 */
@Override
public FieldComparator newComparator(String propertyName, int numHits, int sortPos, boolean reversed) throws IOException {
    PathFactory factory = PathFactoryImpl.getInstance();
    Path path = factory.create(propertyName);
    try {
        SimpleFieldComparator simple = new SimpleFieldComparator(nsMappings.translatePath(path), field, numHits);
        return path.getLength() == 1 ? simple : new CompoundScoreFieldComparator(new FieldComparator[] { simple, new RelPathFieldComparator(path, numHits) }, numHits);
    } catch (IllegalNameException e) {
        throw Util.createIOException(e);
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) PathFactory(org.apache.jackrabbit.spi.PathFactory) AbstractFieldComparator(org.apache.jackrabbit.core.query.lucene.sort.AbstractFieldComparator) FieldComparator(org.apache.lucene.search.FieldComparator) IllegalNameException(org.apache.jackrabbit.spi.commons.conversion.IllegalNameException)

Example 5 with IllegalNameException

use of org.apache.jackrabbit.spi.commons.conversion.IllegalNameException in project jackrabbit by apache.

the class XPathQueryBuilder method createFunction.

/**
 * Creates a function based on <code>node</code>.
 *
 * @param node      the function node from the xpath tree.
 * @param queryNode the current query node.
 * @return the function node
 */
private QueryNode createFunction(SimpleNode node, QueryNode queryNode) {
    // find out function name
    String tmp = ((SimpleNode) node.jjtGetChild(0)).getValue();
    String fName = tmp.substring(0, tmp.length() - 1);
    try {
        Name funName = resolver.getQName(fName);
        if (FN_NOT.equals(funName) || FN_NOT_10.equals(funName)) {
            if (queryNode instanceof NAryQueryNode) {
                QueryNode not = factory.createNotQueryNode(queryNode);
                ((NAryQueryNode) queryNode).addOperand(not);
                // @todo is this needed?
                queryNode = not;
                // traverse
                if (node.jjtGetNumChildren() == 2) {
                    node.jjtGetChild(1).jjtAccept(this, queryNode);
                } else {
                    exceptions.add(new InvalidQueryException("fn:not only supports one expression argument"));
                }
            } else {
                exceptions.add(new InvalidQueryException("Unsupported location for function fn:not"));
            }
        } else if (XS_DATETIME.equals(funName)) {
            // check arguments
            if (node.jjtGetNumChildren() == 2) {
                if (queryNode instanceof RelationQueryNode) {
                    RelationQueryNode rel = (RelationQueryNode) queryNode;
                    SimpleNode literal = (SimpleNode) node.jjtGetChild(1).jjtGetChild(0);
                    if (literal.getId() == JJTSTRINGLITERAL) {
                        String value = literal.getValue();
                        // strip quotes
                        value = value.substring(1, value.length() - 1);
                        Calendar c = ISO8601.parse(value);
                        if (c == null) {
                            exceptions.add(new InvalidQueryException("Unable to parse string literal for xs:dateTime: " + value));
                        } else {
                            rel.setDateValue(c.getTime());
                        }
                    } else {
                        exceptions.add(new InvalidQueryException("Wrong argument type for xs:dateTime"));
                    }
                } else {
                    exceptions.add(new InvalidQueryException("Unsupported location for function xs:dateTime"));
                }
            } else {
                // wrong number of arguments
                exceptions.add(new InvalidQueryException("Wrong number of arguments for xs:dateTime"));
            }
        } else if (JCR_CONTAINS.equals(funName)) {
            // check number of arguments
            if (node.jjtGetNumChildren() == 3) {
                if (queryNode instanceof NAryQueryNode) {
                    SimpleNode literal = (SimpleNode) node.jjtGetChild(2).jjtGetChild(0);
                    if (literal.getId() == JJTSTRINGLITERAL) {
                        TextsearchQueryNode contains = factory.createTextsearchQueryNode(queryNode, unescapeQuotes(literal.getValue()));
                        // assign property name
                        SimpleNode path = (SimpleNode) node.jjtGetChild(1);
                        path.jjtAccept(this, contains);
                        ((NAryQueryNode) queryNode).addOperand(contains);
                    } else {
                        exceptions.add(new InvalidQueryException("Wrong argument type for jcr:contains"));
                    }
                }
            } else {
                // wrong number of arguments
                exceptions.add(new InvalidQueryException("Wrong number of arguments for jcr:contains"));
            }
        } else if (JCR_LIKE.equals(funName)) {
            // check number of arguments
            if (node.jjtGetNumChildren() == 3) {
                if (queryNode instanceof NAryQueryNode) {
                    RelationQueryNode like = factory.createRelationQueryNode(queryNode, RelationQueryNode.OPERATION_LIKE);
                    ((NAryQueryNode) queryNode).addOperand(like);
                    // assign property name
                    node.jjtGetChild(1).jjtAccept(this, like);
                    // check property name
                    if (like.getRelativePath() == null) {
                        exceptions.add(new InvalidQueryException("Wrong first argument type for jcr:like"));
                    }
                    SimpleNode literal = (SimpleNode) node.jjtGetChild(2).jjtGetChild(0);
                    if (literal.getId() == JJTSTRINGLITERAL) {
                        like.setStringValue(unescapeQuotes(literal.getValue()));
                    } else {
                        exceptions.add(new InvalidQueryException("Wrong second argument type for jcr:like"));
                    }
                } else {
                    exceptions.add(new InvalidQueryException("Unsupported location for function jcr:like"));
                }
            } else {
                // wrong number of arguments
                exceptions.add(new InvalidQueryException("Wrong number of arguments for jcr:like"));
            }
        } else if (FN_TRUE.equals(funName)) {
            if (queryNode.getType() == QueryNode.TYPE_RELATION) {
                RelationQueryNode rel = (RelationQueryNode) queryNode;
                rel.setStringValue("true");
            } else {
                exceptions.add(new InvalidQueryException("Unsupported location for true()"));
            }
        } else if (FN_FALSE.equals(funName)) {
            if (queryNode.getType() == QueryNode.TYPE_RELATION) {
                RelationQueryNode rel = (RelationQueryNode) queryNode;
                rel.setStringValue("false");
            } else {
                exceptions.add(new InvalidQueryException("Unsupported location for false()"));
            }
        } else if (FN_POSITION.equals(funName)) {
            if (queryNode.getType() == QueryNode.TYPE_RELATION) {
                RelationQueryNode rel = (RelationQueryNode) queryNode;
                if (rel.getOperation() == RelationQueryNode.OPERATION_EQ_GENERAL) {
                    // set dummy value to set type of relation query node
                    // will be overwritten when the tree is further parsed.
                    rel.setPositionValue(1);
                    rel.addPathElement(PATH_FACTORY.createElement(FN_POSITION_FULL));
                } else {
                    exceptions.add(new InvalidQueryException("Unsupported expression with position(). Only = is supported."));
                }
            } else {
                exceptions.add(new InvalidQueryException("Unsupported location for position()"));
            }
        } else if (FN_FIRST.equals(funName)) {
            if (queryNode.getType() == QueryNode.TYPE_RELATION) {
                ((RelationQueryNode) queryNode).setPositionValue(1);
            } else if (queryNode.getType() == QueryNode.TYPE_LOCATION) {
                ((LocationStepQueryNode) queryNode).setIndex(1);
            } else {
                exceptions.add(new InvalidQueryException("Unsupported location for first()"));
            }
        } else if (FN_LAST.equals(funName)) {
            if (queryNode.getType() == QueryNode.TYPE_RELATION) {
                ((RelationQueryNode) queryNode).setPositionValue(LocationStepQueryNode.LAST);
            } else if (queryNode.getType() == QueryNode.TYPE_LOCATION) {
                ((LocationStepQueryNode) queryNode).setIndex(LocationStepQueryNode.LAST);
            } else {
                exceptions.add(new InvalidQueryException("Unsupported location for last()"));
            }
        } else if (JCR_DEREF.equals(funName)) {
            // check number of arguments
            if (node.jjtGetNumChildren() == 3) {
                boolean descendant = false;
                if (queryNode.getType() == QueryNode.TYPE_LOCATION) {
                    LocationStepQueryNode loc = (LocationStepQueryNode) queryNode;
                    // remember if descendant axis
                    descendant = loc.getIncludeDescendants();
                    queryNode = loc.getParent();
                    ((NAryQueryNode) queryNode).removeOperand(loc);
                }
                if (queryNode.getType() == QueryNode.TYPE_PATH) {
                    PathQueryNode pathNode = (PathQueryNode) queryNode;
                    pathNode.addPathStep(createDerefQueryNode(node, descendant, pathNode));
                } else if (queryNode.getType() == QueryNode.TYPE_RELATION) {
                    RelationQueryNode relNode = (RelationQueryNode) queryNode;
                    DerefQueryNode deref = createDerefQueryNode(node, descendant, relNode.getRelativePath());
                    relNode.getRelativePath().addPathStep(deref);
                } else {
                    exceptions.add(new InvalidQueryException("Unsupported location for jcr:deref()"));
                }
            }
        } else if (JCR_SCORE.equals(funName)) {
            if (queryNode.getType() == QueryNode.TYPE_ORDER) {
                setOrderSpecPath(node, (OrderQueryNode) queryNode);
            } else {
                exceptions.add(new InvalidQueryException("Unsupported location for jcr:score()"));
            }
        } else if (FN_LOWER_CASE.equals(funName)) {
            if (node.jjtGetNumChildren() == 2) {
                if (queryNode.getType() == QueryNode.TYPE_RELATION) {
                    RelationQueryNode relNode = (RelationQueryNode) queryNode;
                    relNode.addOperand(factory.createPropertyFunctionQueryNode(relNode, PropertyFunctionQueryNode.LOWER_CASE));
                    // get property name
                    node.jjtGetChild(1).jjtAccept(this, relNode);
                } else if (queryNode.getType() == QueryNode.TYPE_ORDER) {
                    ((OrderQueryNode) queryNode).setFunction(FN_LOWER_CASE.getLocalName());
                    node.childrenAccept(this, queryNode);
                } else {
                    exceptions.add(new InvalidQueryException("Unsupported location for fn:lower-case()"));
                }
            } else {
                exceptions.add(new InvalidQueryException("Wrong number of argument for fn:lower-case()"));
            }
        } else if (FN_UPPER_CASE.equals(funName)) {
            if (node.jjtGetNumChildren() == 2) {
                if (queryNode.getType() == QueryNode.TYPE_RELATION) {
                    RelationQueryNode relNode = (RelationQueryNode) queryNode;
                    relNode.addOperand(factory.createPropertyFunctionQueryNode(relNode, PropertyFunctionQueryNode.UPPER_CASE));
                    // get property name
                    node.jjtGetChild(1).jjtAccept(this, relNode);
                } else if (queryNode.getType() == QueryNode.TYPE_ORDER) {
                    ((OrderQueryNode) queryNode).setFunction(FN_UPPER_CASE.getLocalName());
                    node.childrenAccept(this, queryNode);
                } else {
                    exceptions.add(new InvalidQueryException("Unsupported location for fn:upper-case()"));
                }
            } else {
                exceptions.add(new InvalidQueryException("Wrong number of argument for fn:upper-case()"));
            }
        } else if (REP_NORMALIZE.equals(funName)) {
            if (node.jjtGetNumChildren() == 2) {
                if (queryNode.getType() == QueryNode.TYPE_ORDER) {
                    ((OrderQueryNode) queryNode).setFunction(REP_NORMALIZE.getLocalName());
                    node.childrenAccept(this, queryNode);
                } else {
                    exceptions.add(new InvalidQueryException("Unsupported location for rep:normalize()"));
                }
            } else {
                exceptions.add(new InvalidQueryException("Wrong number of argument for rep:normalize()"));
            }
        } else if (REP_SIMILAR.equals(funName)) {
            if (node.jjtGetNumChildren() == 3) {
                if (queryNode instanceof NAryQueryNode) {
                    NAryQueryNode parent = (NAryQueryNode) queryNode;
                    RelationQueryNode rel = factory.createRelationQueryNode(parent, RelationQueryNode.OPERATION_SIMILAR);
                    parent.addOperand(rel);
                    // assign path
                    node.jjtGetChild(1).jjtAccept(this, rel);
                    // get path string
                    node.jjtGetChild(2).jjtAccept(this, rel);
                    // check if string is set
                    if (rel.getStringValue() == null) {
                        exceptions.add(new InvalidQueryException("Second argument for rep:similar() must be of type string"));
                    }
                } else {
                    exceptions.add(new InvalidQueryException("Unsupported location for rep:similar()"));
                }
            } else {
                exceptions.add(new InvalidQueryException("Wrong number of arguments for rep:similar()"));
            }
        } else if (REP_SPELLCHECK.equals(funName) && queryNode.getType() != QueryNode.TYPE_PATH) {
            if (node.jjtGetNumChildren() == 2) {
                if (queryNode instanceof NAryQueryNode) {
                    NAryQueryNode parent = (NAryQueryNode) queryNode;
                    RelationQueryNode rel = factory.createRelationQueryNode(parent, RelationQueryNode.OPERATION_SPELLCHECK);
                    parent.addOperand(rel);
                    // get string to check
                    node.jjtGetChild(1).jjtAccept(this, rel);
                    // check if string is set
                    if (rel.getStringValue() == null) {
                        exceptions.add(new InvalidQueryException("Argument for rep:spellcheck() must be of type string"));
                    }
                    // set a dummy property name
                    rel.addPathElement(PATH_FACTORY.createElement(NameConstants.JCR_PRIMARYTYPE));
                } else {
                    exceptions.add(new InvalidQueryException("Unsupported location for rep:spellcheck()"));
                }
            } else {
                exceptions.add(new InvalidQueryException("Wrong number of arguments for rep:spellcheck()"));
            }
        } else if (queryNode.getType() == QueryNode.TYPE_RELATION) {
            // use function name as name of a pseudo property in a relation
            try {
                Name name = resolver.getQName(fName + "()");
                Path.Element element = PATH_FACTORY.createElement(name);
                RelationQueryNode relNode = (RelationQueryNode) queryNode;
                relNode.addPathElement(element);
            } catch (NameException e) {
                exceptions.add(e);
            }
        } else if (queryNode.getType() == QueryNode.TYPE_PATH) {
            // use function name as name of a pseudo property in select clause
            try {
                Name name = resolver.getQName(fName + "()");
                root.addSelectProperty(name);
            } catch (NameException e) {
                exceptions.add(e);
            }
        } else {
            exceptions.add(new InvalidQueryException("Unsupported function: " + fName));
        }
    } catch (NamespaceException e) {
        exceptions.add(e);
    } catch (IllegalNameException e) {
        exceptions.add(e);
    }
    return queryNode;
}
Also used : Path(org.apache.jackrabbit.spi.Path) NAryQueryNode(org.apache.jackrabbit.spi.commons.query.NAryQueryNode) OrderQueryNode(org.apache.jackrabbit.spi.commons.query.OrderQueryNode) Calendar(java.util.Calendar) LocationStepQueryNode(org.apache.jackrabbit.spi.commons.query.LocationStepQueryNode) DerefQueryNode(org.apache.jackrabbit.spi.commons.query.DerefQueryNode) RelationQueryNode(org.apache.jackrabbit.spi.commons.query.RelationQueryNode) Name(org.apache.jackrabbit.spi.Name) TextsearchQueryNode(org.apache.jackrabbit.spi.commons.query.TextsearchQueryNode) PathQueryNode(org.apache.jackrabbit.spi.commons.query.PathQueryNode) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) IllegalNameException(org.apache.jackrabbit.spi.commons.conversion.IllegalNameException) RelationQueryNode(org.apache.jackrabbit.spi.commons.query.RelationQueryNode) OrderQueryNode(org.apache.jackrabbit.spi.commons.query.OrderQueryNode) QueryNode(org.apache.jackrabbit.spi.commons.query.QueryNode) DerefQueryNode(org.apache.jackrabbit.spi.commons.query.DerefQueryNode) NAryQueryNode(org.apache.jackrabbit.spi.commons.query.NAryQueryNode) NotQueryNode(org.apache.jackrabbit.spi.commons.query.NotQueryNode) NodeTypeQueryNode(org.apache.jackrabbit.spi.commons.query.NodeTypeQueryNode) PathQueryNode(org.apache.jackrabbit.spi.commons.query.PathQueryNode) TextsearchQueryNode(org.apache.jackrabbit.spi.commons.query.TextsearchQueryNode) PropertyFunctionQueryNode(org.apache.jackrabbit.spi.commons.query.PropertyFunctionQueryNode) LocationStepQueryNode(org.apache.jackrabbit.spi.commons.query.LocationStepQueryNode) NamespaceException(javax.jcr.NamespaceException) IllegalNameException(org.apache.jackrabbit.spi.commons.conversion.IllegalNameException) InvalidQueryException(javax.jcr.query.InvalidQueryException)

Aggregations

IllegalNameException (org.apache.jackrabbit.spi.commons.conversion.IllegalNameException)8 Name (org.apache.jackrabbit.spi.Name)5 NamespaceException (javax.jcr.NamespaceException)3 Path (org.apache.jackrabbit.spi.Path)3 InvalidQueryException (javax.jcr.query.InvalidQueryException)2 Term (org.apache.lucene.index.Term)2 BooleanQuery (org.apache.lucene.search.BooleanQuery)2 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 RepositoryException (javax.jcr.RepositoryException)1 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)1 Value (javax.jcr.Value)1 ValueFormatException (javax.jcr.ValueFormatException)1 Constraint (javax.jcr.query.qom.Constraint)1 NodeLocalName (javax.jcr.query.qom.NodeLocalName)1 NodeName (javax.jcr.query.qom.NodeName)1 PropertyValue (javax.jcr.query.qom.PropertyValue)1 AbstractFieldComparator (org.apache.jackrabbit.core.query.lucene.sort.AbstractFieldComparator)1 PathFactory (org.apache.jackrabbit.spi.PathFactory)1 QValue (org.apache.jackrabbit.spi.QValue)1