Search in sources :

Example 11 with PropertyId

use of org.apache.jackrabbit.spi.PropertyId in project jackrabbit by apache.

the class RepositoryServiceImpl method getReferences.

/**
 * {@inheritDoc}
 */
public Iterator<PropertyId> getReferences(SessionInfo sessionInfo, NodeId nodeId, Name propertyName, boolean weakReferences) throws ItemNotFoundException, RepositoryException {
    SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
    Node node = getNode(nodeId, sInfo);
    String jcrName = (propertyName == null) ? null : sInfo.getNamePathResolver().getJCRName(propertyName);
    List<PropertyId> ids = new ArrayList<PropertyId>();
    PropertyIterator it;
    if (weakReferences) {
        it = node.getWeakReferences(jcrName);
    } else {
        it = node.getReferences(jcrName);
    }
    while (it.hasNext()) {
        ids.add(idFactory.createPropertyId(it.nextProperty(), sInfo.getNamePathResolver()));
    }
    return ids.iterator();
}
Also used : Node(javax.jcr.Node) ArrayList(java.util.ArrayList) PropertyIterator(javax.jcr.PropertyIterator) PropertyId(org.apache.jackrabbit.spi.PropertyId)

Example 12 with PropertyId

use of org.apache.jackrabbit.spi.PropertyId in project jackrabbit by apache.

the class WorkspaceItemStateFactory method createNodeState.

/**
 * Create the node state with the information from <code>info</code>.
 *
 * @param info the <code>NodeInfo</code> to use to create the <code>NodeState</code>.
 * @param entry  the hierarchy entry for of this state
 * @return the new <code>NodeState</code>.
 * @throws ItemNotFoundException
 * @throws RepositoryException
 */
private NodeState createNodeState(NodeInfo info, NodeEntry entry) throws ItemNotFoundException, RepositoryException {
    // Make sure the entry has the correct ItemId
    // this may not be the case, if the hierarchy has not been completely
    // resolved yet -> if uniqueID is present, set it on this entry or on
    // the appropriate parent entry
    String uniqueID = info.getId().getUniqueID();
    Path path = info.getId().getPath();
    if (path == null) {
        entry.setUniqueID(uniqueID);
    } else if (uniqueID != null) {
        // uniqueID that applies to a parent NodeEntry -> get parentEntry
        NodeEntry parent = getAncestor(entry, path.getLength());
        parent.setUniqueID(uniqueID);
    }
    int previousStatus = entry.getStatus();
    if (Status.isTransient(previousStatus) || Status.isStale(previousStatus)) {
        log.debug("Node has pending changes; omit resetting the state.");
        return entry.getNodeState();
    }
    // update NodeEntry from the information present in the NodeInfo (prop entries)
    List<Name> propNames = new ArrayList<Name>();
    for (Iterator<PropertyId> it = info.getPropertyIds(); it.hasNext(); ) {
        PropertyId pId = it.next();
        Name propertyName = pId.getName();
        propNames.add(propertyName);
    }
    try {
        entry.setPropertyEntries(propNames);
    } catch (ItemExistsException e) {
        // should not get here
        log.error("Internal error", e);
    }
    // unless the child-info are omitted by the SPI impl -> make sure
    // the child entries the node entry are initialized or updated.
    Iterator<ChildInfo> childInfos = info.getChildInfos();
    if (childInfos != null) {
        entry.setNodeEntries(childInfos);
    }
    // now build or update the nodestate itself
    NodeState tmp = new NodeState(entry, info, this, definitionProvider);
    entry.setItemState(tmp);
    NodeState nState = entry.getNodeState();
    if (previousStatus == Status._UNDEFINED_) {
        // tmp state was used as resolution for the given entry i.e. the
        // entry was not available before. otherwise the 2 states were
        // merged. see HierarchyEntryImpl#setItemState
        notifyCreated(nState);
    } else {
        notifyUpdated(nState, previousStatus);
    }
    return nState;
}
Also used : Path(org.apache.jackrabbit.spi.Path) ArrayList(java.util.ArrayList) ChildInfo(org.apache.jackrabbit.spi.ChildInfo) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.spi.PropertyId) NodeEntry(org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry) ItemExistsException(javax.jcr.ItemExistsException)

Example 13 with PropertyId

use of org.apache.jackrabbit.spi.PropertyId in project jackrabbit by apache.

the class PropertyInfoImpl method createSerializablePropertyInfo.

/**
 * Creates a new serializable property info for the given
 * <code>PropertyInfo</code>.
 *
 * @param propertyInfo
 */
public static PropertyInfo createSerializablePropertyInfo(PropertyInfo propertyInfo, IdFactory idFactory) {
    if (propertyInfo instanceof Serializable) {
        return propertyInfo;
    } else {
        NodeId parentId = propertyInfo.getId().getParentId();
        parentId = idFactory.createNodeId(parentId.getUniqueID(), parentId.getPath());
        PropertyId propId = idFactory.createPropertyId(parentId, propertyInfo.getId().getName());
        return new PropertyInfoImpl(propertyInfo.getPath(), propId, propertyInfo.getType(), propertyInfo.isMultiValued(), propertyInfo.getValues());
    }
}
Also used : Serializable(java.io.Serializable) NodeId(org.apache.jackrabbit.spi.NodeId) PropertyId(org.apache.jackrabbit.spi.PropertyId)

Example 14 with PropertyId

use of org.apache.jackrabbit.spi.PropertyId in project jackrabbit by apache.

the class RepositoryServiceImpl method getNodeInfo.

@Override
public NodeInfo getNodeInfo(SessionInfo sessionInfo, NodeId nodeId) throws RepositoryException {
    // set of properties to be retrieved
    DavPropertyNameSet nameSet = new DavPropertyNameSet();
    nameSet.add(JcrRemotingConstants.JCR_INDEX_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(JcrRemotingConstants.JCR_PARENT_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(JcrRemotingConstants.JCR_NAME_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(JcrRemotingConstants.JCR_PRIMARYNODETYPE_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(JcrRemotingConstants.JCR_MIXINNODETYPES_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(JcrRemotingConstants.JCR_REFERENCES_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(JcrRemotingConstants.JCR_UUID_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(JcrRemotingConstants.JCR_PATH_LN, ItemResourceConstants.NAMESPACE);
    nameSet.add(DavPropertyName.RESOURCETYPE);
    HttpPropfind request = null;
    try {
        String uri = getItemUri(nodeId, sessionInfo);
        request = new HttpPropfind(uri, nameSet, DEPTH_1);
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
        MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
        if (mresponses.length < 1) {
            throw new ItemNotFoundException("Unable to retrieve the node with id " + saveGetIdString(nodeId, sessionInfo));
        }
        MultiStatusResponse nodeResponse = null;
        List<MultiStatusResponse> childResponses = new ArrayList<MultiStatusResponse>();
        for (MultiStatusResponse mresponse : mresponses) {
            if (isSameResource(uri, mresponse)) {
                nodeResponse = mresponse;
            } else {
                childResponses.add(mresponse);
            }
        }
        if (nodeResponse == null) {
            throw new ItemNotFoundException("Unable to retrieve the node " + saveGetIdString(nodeId, sessionInfo));
        }
        DavPropertySet propSet = nodeResponse.getProperties(DavServletResponse.SC_OK);
        Object type = propSet.get(DavPropertyName.RESOURCETYPE).getValue();
        if (type == null) {
            // the given id points to a Property instead of a Node
            throw new ItemNotFoundException("No node for id " + saveGetIdString(nodeId, sessionInfo));
        }
        NamePathResolver resolver = getNamePathResolver(sessionInfo);
        NodeId parentId = getParentId(uri, propSet, sessionInfo);
        NodeInfoImpl nInfo = buildNodeInfo(uri, nodeResponse, parentId, propSet, sessionInfo, resolver);
        for (MultiStatusResponse resp : childResponses) {
            DavPropertySet childProps = resp.getProperties(DavServletResponse.SC_OK);
            if (childProps.contains(DavPropertyName.RESOURCETYPE) && childProps.get(DavPropertyName.RESOURCETYPE).getValue() != null) {
                // any other resource type than default (empty) is represented by a node item
                // --> build child info object
                nInfo.addChildInfo(buildChildInfo(childProps, sessionInfo));
            } else {
                PropertyId childId = uriResolver.buildPropertyId(nInfo.getId(), resp, sessionInfo.getWorkspaceName(), getNamePathResolver(sessionInfo));
                nInfo.addPropertyId(childId);
            }
        }
        return nInfo;
    } catch (IOException e) {
        throw new RepositoryException(e);
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } catch (NameException e) {
        throw new RepositoryException(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) DavException(org.apache.jackrabbit.webdav.DavException) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) PropertyId(org.apache.jackrabbit.spi.PropertyId) DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) IllegalNameException(org.apache.jackrabbit.spi.commons.conversion.IllegalNameException) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) NodeId(org.apache.jackrabbit.spi.NodeId) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 15 with PropertyId

use of org.apache.jackrabbit.spi.PropertyId in project jackrabbit by apache.

the class RepositoryServiceImpl method buildPropertyInfos.

private List<PropertyInfo> buildPropertyInfos(NodeInfo nInfo) throws RepositoryException {
    List<PropertyInfo> l = new ArrayList<PropertyInfo>(3);
    NodeId nid = nInfo.getId();
    Path nPath = nInfo.getPath();
    if (nid.getPath() == null) {
        PropertyId id = getIdFactory().createPropertyId(nid, NameConstants.JCR_UUID);
        QValue[] vs = new QValue[] { getQValueFactory().create(nid.getUniqueID(), PropertyType.STRING) };
        Path p = getPathFactory().create(nPath, NameConstants.JCR_UUID, true);
        PropertyInfo pi = new PropertyInfoImpl(id, p, PropertyType.STRING, false, vs);
        l.add(pi);
    }
    Name pName = NameConstants.JCR_PRIMARYTYPE;
    QValue[] vs = new QValue[] { getQValueFactory().create(nInfo.getNodetype()) };
    PropertyInfo pi = new PropertyInfoImpl(getIdFactory().createPropertyId(nid, pName), getPathFactory().create(nPath, pName, true), PropertyType.NAME, false, vs);
    l.add(pi);
    Name[] mixins = nInfo.getMixins();
    if (mixins.length > 0) {
        pName = NameConstants.JCR_MIXINTYPES;
        vs = new QValue[mixins.length];
        for (int i = 0; i < mixins.length; i++) {
            vs[i] = getQValueFactory().create(mixins[i]);
        }
        pi = new PropertyInfoImpl(getIdFactory().createPropertyId(nid, pName), getPathFactory().create(nPath, pName, true), PropertyType.NAME, true, vs);
        l.add(pi);
    }
    return l;
}
Also used : Path(org.apache.jackrabbit.spi.Path) QValue(org.apache.jackrabbit.spi.QValue) ArrayList(java.util.ArrayList) NodeId(org.apache.jackrabbit.spi.NodeId) PropertyInfo(org.apache.jackrabbit.spi.PropertyInfo) PropertyId(org.apache.jackrabbit.spi.PropertyId) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName) Name(org.apache.jackrabbit.spi.Name)

Aggregations

PropertyId (org.apache.jackrabbit.spi.PropertyId)21 NodeId (org.apache.jackrabbit.spi.NodeId)13 Name (org.apache.jackrabbit.spi.Name)10 RepositoryException (javax.jcr.RepositoryException)8 ArrayList (java.util.ArrayList)6 Path (org.apache.jackrabbit.spi.Path)6 PropertyInfo (org.apache.jackrabbit.spi.PropertyInfo)5 QValue (org.apache.jackrabbit.spi.QValue)5 Batch (org.apache.jackrabbit.spi.Batch)4 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)4 IOException (java.io.IOException)3 ItemNotFoundException (javax.jcr.ItemNotFoundException)3 DavPropertySet (org.apache.jackrabbit.webdav.property.DavPropertySet)3 Serializable (java.io.Serializable)2 Node (javax.jcr.Node)2 HttpResponse (org.apache.http.HttpResponse)2 ChildInfo (org.apache.jackrabbit.spi.ChildInfo)2 ItemId (org.apache.jackrabbit.spi.ItemId)2 ItemInfo (org.apache.jackrabbit.spi.ItemInfo)2 NamePathResolver (org.apache.jackrabbit.spi.commons.conversion.NamePathResolver)2