use of org.apache.jackrabbit.spi.commons.conversion.NamePathResolver in project jackrabbit by apache.
the class RepositoryServiceImpl method clone.
@Override
public void clone(SessionInfo sessionInfo, String srcWorkspaceName, NodeId srcNodeId, NodeId destParentNodeId, Name destName, boolean removeExisting) throws RepositoryException {
HttpPost request = null;
try {
request = new HttpPost(getWorkspaceURI(sessionInfo));
request.setHeader("Referer", request.getURI().toASCIIString());
addIfHeader(sessionInfo, request);
NamePathResolver resolver = getNamePathResolver(sessionInfo);
StringBuilder args = new StringBuilder();
args.append(srcWorkspaceName);
args.append(",");
args.append(resolver.getJCRPath(getPath(srcNodeId, sessionInfo, srcWorkspaceName)));
args.append(",");
String destParentPath = resolver.getJCRPath(getPath(destParentNodeId, sessionInfo));
String destPath = (destParentPath.endsWith("/") ? destParentPath + resolver.getJCRName(destName) : destParentPath + "/" + resolver.getJCRName(destName));
args.append(destPath);
args.append(",");
args.append(Boolean.toString(removeExisting));
List<BasicNameValuePair> nvps = Collections.singletonList(new BasicNameValuePair(PARAM_CLONE, args.toString()));
HttpEntity entity = new UrlEncodedFormEntity(nvps, Charset.forName("UTF-8"));
request.setEntity(entity);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
if (removeExisting) {
clearItemUriCache(sessionInfo);
}
} catch (IOException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(e, request);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
use of org.apache.jackrabbit.spi.commons.conversion.NamePathResolver in project jackrabbit by apache.
the class RepositoryServiceImpl method getItemInfos.
/**
* @see RepositoryService#getItemInfos(SessionInfo, ItemId)
*/
@Override
public Iterator<? extends ItemInfo> getItemInfos(SessionInfo sessionInfo, ItemId itemId) throws RepositoryException {
if (!itemId.denotesNode()) {
PropertyInfo propertyInfo = getPropertyInfo(sessionInfo, (PropertyId) itemId);
return Iterators.singleton(propertyInfo);
} else {
NodeId nodeId = (NodeId) itemId;
Path path = getPath(itemId, sessionInfo);
String uri = getURI(path, sessionInfo);
int depth = batchReadConfig.getDepth(path, this.getNamePathResolver(sessionInfo));
HttpGet request = new HttpGet(uri + "." + depth + ".json");
HttpResponse response = null;
try {
response = executeRequest(sessionInfo, request);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == DavServletResponse.SC_OK) {
HttpEntity entity = response.getEntity();
if (entity.getContentLength() == 0) {
// no JSON response -> no such node on the server
throw new ItemNotFoundException("No such item " + nodeId);
}
NamePathResolver resolver = getNamePathResolver(sessionInfo);
NodeInfoImpl nInfo = new NodeInfoImpl(nodeId, path);
ItemInfoJsonHandler handler = new ItemInfoJsonHandler(resolver, nInfo, getRootURI(sessionInfo), getQValueFactory(sessionInfo), getPathFactory(), getIdFactory());
JsonParser ps = new JsonParser(handler);
ps.parse(entity.getContent(), ContentType.get(entity).getCharset().name());
Iterator<? extends ItemInfo> it = handler.getItemInfos();
if (!it.hasNext()) {
throw new ItemNotFoundException("No such node " + uri);
}
return handler.getItemInfos();
} else {
throw ExceptionConverter.generate(new DavException(statusCode, "Unable to retrieve NodeInfo for " + uri), request);
}
} catch (IOException e) {
log.error("Internal error while retrieving NodeInfo.", e);
throw new RepositoryException(e.getMessage());
} finally {
request.releaseConnection();
}
}
}
use of org.apache.jackrabbit.spi.commons.conversion.NamePathResolver in project jackrabbit by apache.
the class RepositoryServiceImpl method getNamePathResolver.
private NamePathResolver getNamePathResolver(SessionInfoImpl sessionInfo) {
NamePathResolver resolver = sessionInfo.getNamePathResolver();
if (resolver == null) {
resolver = new NamePathResolverImpl(sessionInfo);
sessionInfo.setNamePathResolver(resolver);
}
return resolver;
}
use of org.apache.jackrabbit.spi.commons.conversion.NamePathResolver 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.commons.conversion.NamePathResolver in project jackrabbit by apache.
the class RepositoryServiceImpl method createUnRegisterNodeTypesProperty.
private DavProperty<List<XmlSerializable>> createUnRegisterNodeTypesProperty(SessionInfo sessionInfo, Name[] nodeTypeNames) throws IOException, RepositoryException {
NamePathResolver resolver = getNamePathResolver(sessionInfo);
List<XmlSerializable> val = new ArrayList<XmlSerializable>();
for (Name ntName : nodeTypeNames) {
final String jcrName = resolver.getJCRName(ntName);
val.add(new XmlSerializable() {
public Element toXml(Document document) {
Element ntNameElem = document.createElementNS(JcrRemotingConstants.NS_URI, JcrRemotingConstants.NS_PREFIX + ":" + JcrRemotingConstants.XML_NODETYPENAME);
org.w3c.dom.Text txt = document.createTextNode(jcrName);
ntNameElem.appendChild(txt);
return ntNameElem;
}
});
}
return new DefaultDavProperty<List<XmlSerializable>>(JcrRemotingConstants.JCR_NODETYPES_CND_LN, val, ItemResourceConstants.NAMESPACE, false);
}
Aggregations