use of org.apache.jackrabbit.spi.commons.conversion.NamePathResolver in project jackrabbit by apache.
the class NamePathResolverImpl method create.
public static NamePathResolver create(NamespaceMappings nsMappings) {
NameResolver nResolver = new NameResolverImpl(nsMappings);
PathResolver pResolver = new ParsingPathResolver(PATH_FACTORY, nResolver);
return new NamePathResolverImpl(nResolver, pResolver);
}
use of org.apache.jackrabbit.spi.commons.conversion.NamePathResolver in project jackrabbit by apache.
the class RepositoryServiceImpl method getItemDefinition.
/**
*
* @param sessionInfo
* @param itemId
* @return
* @throws RepositoryException
*/
private QItemDefinition getItemDefinition(SessionInfo sessionInfo, ItemId itemId) throws RepositoryException {
// set of properties to be retrieved
DavPropertyNameSet nameSet = new DavPropertyNameSet();
nameSet.add(JcrRemotingConstants.JCR_DEFINITION_LN, ItemResourceConstants.NAMESPACE);
nameSet.add(DavPropertyName.RESOURCETYPE);
HttpPropfind request = null;
try {
String uri = getItemUri(itemId, sessionInfo);
request = new HttpPropfind(uri, nameSet, DEPTH_0);
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 item definition for " + saveGetIdString(itemId, sessionInfo));
}
if (mresponses.length > 1) {
throw new RepositoryException("Internal error: ambigous item definition found '" + saveGetIdString(itemId, sessionInfo) + "'.");
}
DavPropertySet propertySet = mresponses[0].getProperties(DavServletResponse.SC_OK);
// check if definition matches the type of the id
DavProperty<?> rType = propertySet.get(DavPropertyName.RESOURCETYPE);
if (rType.getValue() == null && itemId.denotesNode()) {
throw new RepositoryException("Internal error: requested node definition and got property definition.");
}
NamePathResolver resolver = getNamePathResolver(sessionInfo);
// build the definition
QItemDefinition definition = null;
DavProperty<?> prop = propertySet.get(JcrRemotingConstants.JCR_DEFINITION_LN, ItemResourceConstants.NAMESPACE);
if (prop != null) {
Object value = prop.getValue();
if (value != null && value instanceof Element) {
Element idfElem = (Element) value;
if (itemId.denotesNode()) {
definition = DefinitionUtil.createQNodeDefinition(null, idfElem, resolver);
} else {
definition = DefinitionUtil.createQPropertyDefinition(null, idfElem, resolver, getQValueFactory());
}
}
}
if (definition == null) {
throw new RepositoryException("Unable to retrieve definition for item with id '" + saveGetIdString(itemId, resolver) + "'.");
}
return definition;
} catch (IOException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(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 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;
}
Aggregations