Search in sources :

Example 16 with PathBuilder

use of org.apache.jackrabbit.spi.commons.name.PathBuilder in project jackrabbit by apache.

the class OrderQueryNode method createPath.

//--------------------------------< internal >------------------------------
/**
     * Creates a path with a single element out of the given <code>name</code>.
     *
     * @param name the name to create the path from.
     * @return a path with a single element.
     */
private static Path createPath(Name name) {
    try {
        PathBuilder builder = new PathBuilder();
        builder.addLast(name);
        return builder.getPath();
    } catch (MalformedPathException e) {
        // never happens, we just added an element
        throw new InternalError();
    }
}
Also used : PathBuilder(org.apache.jackrabbit.spi.commons.name.PathBuilder) MalformedPathException(org.apache.jackrabbit.spi.commons.conversion.MalformedPathException)

Example 17 with PathBuilder

use of org.apache.jackrabbit.spi.commons.name.PathBuilder in project jackrabbit by apache.

the class JCRSQLQueryBuilder method createRelationQueryNode.

//------------------------< internal >--------------------------------------
/**
     * Creates a new {@link org.apache.jackrabbit.spi.commons.query.RelationQueryNode}.
     *
     * @param parent        the parent node for the created <code>RelationQueryNode</code>.
     * @param propertyName  the property name for the relation.
     * @param operationType the operation type.
     * @param literal       the literal value for the relation or
     *                      <code>null</code> if the relation does not have a
     *                      literal (e.g. IS NULL).
     * @return a <code>RelationQueryNode</code>.
     * @throws IllegalArgumentException if the literal value does not conform
     *                                  to its type. E.g. a malformed String representation of a date.
     */
private RelationQueryNode createRelationQueryNode(QueryNode parent, Name propertyName, int operationType, ASTLiteral literal) throws IllegalArgumentException {
    RelationQueryNode node = null;
    try {
        Path relPath = null;
        if (propertyName != null) {
            PathBuilder builder = new PathBuilder();
            builder.addLast(propertyName);
            relPath = builder.getPath();
        }
        if (literal == null) {
            node = factory.createRelationQueryNode(parent, operationType);
            node.setRelativePath(relPath);
        } else if (literal.getType() == QueryConstants.TYPE_DATE) {
            SimpleDateFormat format = new SimpleDateFormat(DATE_PATTERN);
            Date date = format.parse(literal.getValue());
            node = factory.createRelationQueryNode(parent, operationType);
            node.setRelativePath(relPath);
            node.setDateValue(date);
        } else if (literal.getType() == QueryConstants.TYPE_DOUBLE) {
            double d = Double.parseDouble(literal.getValue());
            node = factory.createRelationQueryNode(parent, operationType);
            node.setRelativePath(relPath);
            node.setDoubleValue(d);
        } else if (literal.getType() == QueryConstants.TYPE_LONG) {
            long l = Long.parseLong(literal.getValue());
            node = factory.createRelationQueryNode(parent, operationType);
            node.setRelativePath(relPath);
            node.setLongValue(l);
        } else if (literal.getType() == QueryConstants.TYPE_STRING) {
            node = factory.createRelationQueryNode(parent, operationType);
            node.setRelativePath(relPath);
            node.setStringValue(literal.getValue());
        } else if (literal.getType() == QueryConstants.TYPE_TIMESTAMP) {
            Calendar c = ISO8601.parse(literal.getValue());
            node = factory.createRelationQueryNode(parent, operationType);
            node.setRelativePath(relPath);
            node.setDateValue(c.getTime());
        }
    } catch (java.text.ParseException e) {
        throw new IllegalArgumentException(e.toString());
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException(e.toString());
    } catch (MalformedPathException e) {
        // path is always valid, but throw anyway
        throw new IllegalArgumentException(e.getMessage());
    }
    if (node == null) {
        throw new IllegalArgumentException("Unknown type for literal: " + literal.getType());
    }
    return node;
}
Also used : Path(org.apache.jackrabbit.spi.Path) PathBuilder(org.apache.jackrabbit.spi.commons.name.PathBuilder) Calendar(java.util.Calendar) MalformedPathException(org.apache.jackrabbit.spi.commons.conversion.MalformedPathException) SimpleDateFormat(java.text.SimpleDateFormat) RelationQueryNode(org.apache.jackrabbit.spi.commons.query.RelationQueryNode) Date(java.util.Date)

Example 18 with PathBuilder

use of org.apache.jackrabbit.spi.commons.name.PathBuilder in project jackrabbit by apache.

the class TextsearchQueryNode method setPropertyName.

/**
     * Sets a new name as the search scope for this fulltext query.
     *
     * @param property the name of the property.
     * @deprecated Use {@link #setRelativePath(Path)} instead.
     */
public void setPropertyName(Name property) {
    PathBuilder builder = new PathBuilder();
    builder.addLast(property);
    try {
        this.relPath = builder.getPath();
        this.propertyRef = true;
    } catch (MalformedPathException e) {
    // path is always valid
    }
}
Also used : PathBuilder(org.apache.jackrabbit.spi.commons.name.PathBuilder) MalformedPathException(org.apache.jackrabbit.spi.commons.conversion.MalformedPathException)

Aggregations

PathBuilder (org.apache.jackrabbit.spi.commons.name.PathBuilder)18 Path (org.apache.jackrabbit.spi.Path)8 Name (org.apache.jackrabbit.spi.Name)6 MalformedPathException (org.apache.jackrabbit.spi.commons.conversion.MalformedPathException)5 ArrayList (java.util.ArrayList)3 RepositoryException (javax.jcr.RepositoryException)3 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)3 ItemNotFoundException (javax.jcr.ItemNotFoundException)2 NamespaceException (javax.jcr.NamespaceException)2 PathNotFoundException (javax.jcr.PathNotFoundException)2 NodeId (org.apache.jackrabbit.core.id.NodeId)2 NodeState (org.apache.jackrabbit.core.state.NodeState)2 IdFactory (org.apache.jackrabbit.spi.IdFactory)2 NodeId (org.apache.jackrabbit.spi.NodeId)2 IllegalNameException (org.apache.jackrabbit.spi.commons.conversion.IllegalNameException)2 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)2 NAryQueryNode (org.apache.jackrabbit.spi.commons.query.NAryQueryNode)2 RelationQueryNode (org.apache.jackrabbit.spi.commons.query.RelationQueryNode)2 TextsearchQueryNode (org.apache.jackrabbit.spi.commons.query.TextsearchQueryNode)2 Node (org.w3c.dom.Node)2