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();
}
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;
}
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());
}
}
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();
}
}
}
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;
}
Aggregations