Search in sources :

Example 1 with PathBuilder

use of org.apache.jackrabbit.spi.commons.name.PathBuilder 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 2 with PathBuilder

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

the class NodeEntryImpl method buildPath.

/**
     * @see HierarchyEntryImpl#buildPath(boolean)
     */
@Override
Path buildPath(boolean wspPath) throws RepositoryException {
    PathFactory pf = getPathFactory();
    // shortcut for root state
    if (parent == null) {
        return pf.getRootPath();
    }
    // build path otherwise
    PathBuilder builder = new PathBuilder(pf);
    buildPath(builder, this, wspPath);
    return builder.getPath();
}
Also used : PathBuilder(org.apache.jackrabbit.spi.commons.name.PathBuilder) PathFactory(org.apache.jackrabbit.spi.PathFactory)

Example 3 with PathBuilder

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

the class NodeEntryImpl method getDeepPropertyEntry.

/**
     * @see NodeEntry#getDeepPropertyEntry(Path)
     */
public PropertyEntry getDeepPropertyEntry(Path path) throws PathNotFoundException, RepositoryException {
    NodeEntryImpl entry = this;
    Path.Element[] elems = path.getElements();
    int i = 0;
    for (; i < elems.length - 1; i++) {
        Path.Element elem = elems[i];
        if (elems[i].denotesRoot()) {
            if (entry.getParent() != null) {
                throw new RepositoryException("NodeEntry out of 'hierarchy' " + path.toString());
            }
            continue;
        }
        int index = elem.getNormalizedIndex();
        Name name = elem.getName();
        // first try to resolve to known node or property entry
        NodeEntry cne = entry.getNodeEntry(name, index, false);
        if (cne != null) {
            entry = (NodeEntryImpl) cne;
        } else {
            //    on the persistent layer.
            if (entry.childNodeEntries.isComplete()) {
                throw new PathNotFoundException(factory.saveGetJCRPath(path));
            }
            // -> check for moved child entry in node-attic
            // -> check if child points to a removed/moved sns
            List<NodeEntry> siblings = entry.childNodeEntries.get(name);
            if (entry.containsAtticChild(siblings, name, index)) {
                throw new PathNotFoundException(factory.saveGetJCRPath(path));
            }
            // break out of the loop and start deep loading the property
            break;
        }
    }
    int st = entry.getStatus();
    PropertyEntry pe;
    if (i == elems.length - 1 && Status.INVALIDATED != st && Status._UNDEFINED_ != st) {
        // all node entries present in the hierarchy and the direct ancestor
        // has already been resolved and isn't invalidated -> no need to
        // retrieve property entry from SPI
        pe = entry.properties.get(path.getName());
    } else {
        /*
            * Unknown parent entry (not-existing or not yet loaded) or a parent
            * entry that has been invalidated:
            * Skip all intermediate entries and directly try to load the
            * PropertyState (including building the intermediate entries. If that
            * fails ItemNotFoundException is thrown.
            */
        PathBuilder pb = new PathBuilder(getPathFactory());
        for (int j = i; j < elems.length; j++) {
            pb.addLast(elems[j]);
        }
        Path remainingPath = pb.getPath();
        IdFactory idFactory = getIdFactory();
        NodeId parentId = entry.getWorkspaceId();
        if (remainingPath.getLength() != 1) {
            parentId = idFactory.createNodeId(parentId, remainingPath.getAncestor(1));
        }
        PropertyId propId = idFactory.createPropertyId(parentId, remainingPath.getName());
        pe = entry.loadPropertyEntry(propId);
    }
    if (pe == null) {
        throw new PathNotFoundException(factory.saveGetJCRPath(path));
    }
    return pe;
}
Also used : Path(org.apache.jackrabbit.spi.Path) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.spi.PropertyId) PathBuilder(org.apache.jackrabbit.spi.commons.name.PathBuilder) IdFactory(org.apache.jackrabbit.spi.IdFactory) NodeId(org.apache.jackrabbit.spi.NodeId) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 4 with PathBuilder

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

the class NodeEntryImpl method buildNodeId.

private static NodeId buildNodeId(NodeEntryImpl entry, PathFactory pathFactory, IdFactory idFactory, boolean wspId) throws RepositoryException {
    PathBuilder pathBuilder = new PathBuilder(pathFactory);
    while (entry.getParent() != null && entry.getUniqueID() == null) {
        pathBuilder.addFirst(entry.getName(wspId), entry.getIndex(wspId));
        entry = (wspId && entry.revertInfo != null) ? entry.revertInfo.oldParent : entry.parent;
    }
    // a NodeId from an uuid and a relative path.
    if (entry.getParent() == null) {
        pathBuilder.addRoot();
        return idFactory.createNodeId((String) null, pathBuilder.getPath());
    } else {
        return idFactory.createNodeId(entry.getUniqueID(), pathBuilder.getPath());
    }
}
Also used : PathBuilder(org.apache.jackrabbit.spi.commons.name.PathBuilder)

Example 5 with PathBuilder

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

the class HierarchyManagerImpl method resolvePath.

//-------------------------------------------------------< implementation >
/**
     * Internal implementation that iteratively resolves a path into an item.
     *
     * @param elements path elements
     * @param next index of next item in <code>elements</code> to inspect
     * @param id id of item at path <code>elements[0]</code>..<code>elements[next - 1]</code>
     * @param typesAllowed one of <code>RETURN_ANY</code>, <code>RETURN_NODE</code>
     *                     or <code>RETURN_PROPERTY</code>
     * @return id or <code>null</code>
     * @throws ItemStateException if an intermediate item state is not found
     * @throws MalformedPathException if building an intermediate path fails
     */
protected ItemId resolvePath(Path.Element[] elements, int next, ItemId id, int typesAllowed) throws ItemStateException, MalformedPathException {
    PathBuilder builder = new PathBuilder();
    for (int i = 0; i < next; i++) {
        builder.addLast(elements[i]);
    }
    for (int i = next; i < elements.length; i++) {
        Path.Element elem = elements[i];
        NodeId parentId = (NodeId) id;
        id = null;
        Name name = elem.getName();
        int index = elem.getIndex();
        if (index == 0) {
            index = 1;
        }
        int typeExpected = typesAllowed;
        if (i < elements.length - 1) {
            // intermediate items must always be nodes
            typeExpected = RETURN_NODE;
        }
        NodeState parentState = (NodeState) getItemState(parentId);
        if ((typeExpected & RETURN_NODE) != 0) {
            ChildNodeEntry nodeEntry = getChildNodeEntry(parentState, name, index);
            if (nodeEntry != null) {
                id = nodeEntry.getId();
            }
        }
        if (id == null && (typeExpected & RETURN_PROPERTY) != 0) {
            if (parentState.hasPropertyName(name) && (index <= 1)) {
                // property
                id = new PropertyId(parentState.getNodeId(), name);
            }
        }
        if (id == null) {
            break;
        }
        builder.addLast(elements[i]);
        pathResolved(id, builder);
    }
    return id;
}
Also used : Path(org.apache.jackrabbit.spi.Path) PathBuilder(org.apache.jackrabbit.spi.commons.name.PathBuilder) NodeState(org.apache.jackrabbit.core.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.core.state.ChildNodeEntry) NodeId(org.apache.jackrabbit.core.id.NodeId) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.core.id.PropertyId)

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