Search in sources :

Example 11 with MalformedPathException

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

the class LockManagerImpl method consolidateEvents.

/**
 * Consolidate an event iterator obtained from observation, merging
 * add and remove operations on nodes with the same UUID into a move
 * operation.
 */
@SuppressWarnings("unchecked")
private Iterator<HierarchyEvent> consolidateEvents(EventIterator events) {
    LinkedMap eventMap = new LinkedMap();
    while (events.hasNext()) {
        EventImpl event = (EventImpl) events.nextEvent();
        HierarchyEvent he;
        try {
            he = new HierarchyEvent(event.getChildId(), sysSession.getQPath(event.getPath()).getNormalizedPath(), event.getType());
        } catch (MalformedPathException e) {
            log.info("Unable to get event's path: " + e.getMessage());
            continue;
        } catch (RepositoryException e) {
            log.info("Unable to get event's path: " + e.getMessage());
            continue;
        }
        HierarchyEvent heExisting = (HierarchyEvent) eventMap.get(he.id);
        if (heExisting != null) {
            heExisting.merge(he);
        } else {
            eventMap.put(he.id, he);
        }
    }
    return eventMap.values().iterator();
}
Also used : EventImpl(org.apache.jackrabbit.core.observation.EventImpl) MalformedPathException(org.apache.jackrabbit.spi.commons.conversion.MalformedPathException) RepositoryException(javax.jcr.RepositoryException) LinkedMap(org.apache.commons.collections.map.LinkedMap)

Example 12 with MalformedPathException

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

the class ValueFactoryQImpl method createValue.

/**
 * {@inheritDoc}
 */
public Value createValue(String value, int type) throws ValueFormatException {
    try {
        QValue qvalue;
        if (type == PropertyType.NAME) {
            Name name = resolver.getQName(value);
            qvalue = qfactory.create(name);
        } else if (type == PropertyType.PATH) {
            Path path = resolver.getQPath(value, false);
            qvalue = qfactory.create(path);
        } else {
            qvalue = qfactory.create(value, type);
        }
        return new QValueValue(qvalue, resolver);
    } catch (IllegalNameException ex) {
        throw new ValueFormatException(ex);
    } catch (MalformedPathException ex) {
        throw new ValueFormatException(ex);
    } catch (NamespaceException ex) {
        throw new ValueFormatException(ex);
    } catch (ValueFormatException ex) {
        throw ex;
    } catch (RepositoryException ex) {
        throw new ValueFormatException(ex);
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) QValue(org.apache.jackrabbit.spi.QValue) MalformedPathException(org.apache.jackrabbit.spi.commons.conversion.MalformedPathException) ValueFormatException(javax.jcr.ValueFormatException) NamespaceException(javax.jcr.NamespaceException) RepositoryException(javax.jcr.RepositoryException) IllegalNameException(org.apache.jackrabbit.spi.commons.conversion.IllegalNameException) Name(org.apache.jackrabbit.spi.Name)

Example 13 with MalformedPathException

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

the class ValueFormatTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    idResolver = new IdentifierResolver() {

        public Path getPath(String identifier) throws MalformedPathException {
            throw new UnsupportedOperationException();
        }

        public void checkFormat(String identifier) throws MalformedPathException {
        // nop
        }
    };
    NameResolver nResolver = new ParsingNameResolver(NameFactoryImpl.getInstance(), new DummyNamespaceResolver());
    PathResolver pResolver = new ParsingPathResolver(PathFactoryImpl.getInstance(), nResolver, idResolver);
    resolver = new DefaultNamePathResolver(nResolver, pResolver);
    qvFactory = QValueFactoryImpl.getInstance();
    vFactory = new ValueFactoryQImpl(qvFactory, resolver);
}
Also used : IdentifierResolver(org.apache.jackrabbit.spi.commons.conversion.IdentifierResolver) Path(org.apache.jackrabbit.spi.Path) ParsingNameResolver(org.apache.jackrabbit.spi.commons.conversion.ParsingNameResolver) DummyNamespaceResolver(org.apache.jackrabbit.spi.commons.conversion.DummyNamespaceResolver) MalformedPathException(org.apache.jackrabbit.spi.commons.conversion.MalformedPathException) NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) PathResolver(org.apache.jackrabbit.spi.commons.conversion.PathResolver) ParsingPathResolver(org.apache.jackrabbit.spi.commons.conversion.ParsingPathResolver) DefaultNamePathResolver(org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver) DefaultNamePathResolver(org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver) NameResolver(org.apache.jackrabbit.spi.commons.conversion.NameResolver) ParsingNameResolver(org.apache.jackrabbit.spi.commons.conversion.ParsingNameResolver) ParsingPathResolver(org.apache.jackrabbit.spi.commons.conversion.ParsingPathResolver)

Example 14 with MalformedPathException

use of org.apache.jackrabbit.spi.commons.conversion.MalformedPathException 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 15 with MalformedPathException

use of org.apache.jackrabbit.spi.commons.conversion.MalformedPathException 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)

Aggregations

MalformedPathException (org.apache.jackrabbit.spi.commons.conversion.MalformedPathException)16 Path (org.apache.jackrabbit.spi.Path)10 RepositoryException (javax.jcr.RepositoryException)8 PathBuilder (org.apache.jackrabbit.spi.commons.name.PathBuilder)5 ItemNotFoundException (javax.jcr.ItemNotFoundException)3 NodeId (org.apache.jackrabbit.core.id.NodeId)3 NodeState (org.apache.jackrabbit.core.state.NodeState)3 ItemExistsException (javax.jcr.ItemExistsException)2 PathNotFoundException (javax.jcr.PathNotFoundException)2 ValueFormatException (javax.jcr.ValueFormatException)2 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)2 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)2 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)2 Name (org.apache.jackrabbit.spi.Name)2 QValue (org.apache.jackrabbit.spi.QValue)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1