use of org.apache.jackrabbit.spi.commons.conversion.NamePathResolver in project jackrabbit by apache.
the class OnWorkspaceInconsistency method logError.
/**
* Logs a generic workspace inconsistency error.
*
* @param exception the exception that was thrown when working on the workspace
* @param handler the query handler.
* @param path the path of the parent node.
* @param node the parent node state.
* @param child the child node entry, for which no node state could be
* found.
* @throws RepositoryException if another error occurs not related to item
* state reading.
*/
public void logError(ItemStateException exception, QueryHandler handler, Path path, NodeState node, ChildNodeEntry child) throws RepositoryException {
if (log.isErrorEnabled()) {
NamePathResolver resolver = new DefaultNamePathResolver(handler.getContext().getNamespaceRegistry());
StringBuilder err = new StringBuilder();
err.append("Workspace inconsistency error on node ");
err.append(resolver.getJCRPath(path));
err.append(" (");
err.append(node.getNodeId());
err.append(") with child ");
err.append(resolver.getJCRName(child.getName()));
err.append(" (");
err.append(child.getId());
err.append(").");
log.error(err.toString(), exception);
}
}
use of org.apache.jackrabbit.spi.commons.conversion.NamePathResolver in project jackrabbit by apache.
the class RepositoryServiceImpl method copy.
@Override
public void copy(SessionInfo sessionInfo, String srcWorkspaceName, NodeId srcNodeId, NodeId destParentNodeId, Name destName) throws RepositoryException {
if (srcWorkspaceName.equals(sessionInfo.getWorkspaceName())) {
super.copy(sessionInfo, srcWorkspaceName, srcNodeId, destParentNodeId, destName);
return;
}
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);
List<BasicNameValuePair> nvps = Collections.singletonList(new BasicNameValuePair(PARAM_COPY, args.toString()));
HttpEntity entity = new UrlEncodedFormEntity(nvps, Charset.forName("UTF-8"));
request.setEntity(entity);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
} 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 getPath.
private Path getPath(ItemId itemId, SessionInfo sessionInfo, String workspaceName) throws RepositoryException {
if (itemId.denotesNode()) {
Path p = itemId.getPath();
String uid = itemId.getUniqueID();
if (uid == null) {
return p;
} else {
NamePathResolver resolver = getNamePathResolver(sessionInfo);
String uri = super.getItemUri(itemId, sessionInfo, workspaceName);
String rootUri = getRootURI(sessionInfo);
String jcrPath;
if (uri.startsWith(rootUri)) {
jcrPath = uri.substring(rootUri.length());
} else {
log.warn("ItemURI " + uri + " doesn't start with rootURI (" + rootUri + ").");
// fallback:
// calculated uri does not start with the rootURI
// -> search /jcr:root and start sub-string behind.
String rootSegment = Text.escapePath(JcrRemotingConstants.ROOT_ITEM_RESOURCEPATH);
jcrPath = uri.substring(uri.indexOf(rootSegment) + rootSegment.length());
}
jcrPath = Text.unescape(jcrPath);
return resolver.getQPath(jcrPath);
}
} else {
PropertyId pId = (PropertyId) itemId;
Path parentPath = getPath(pId.getParentId(), sessionInfo, workspaceName);
return getPathFactory().create(parentPath, pId.getName(), true);
}
}
use of org.apache.jackrabbit.spi.commons.conversion.NamePathResolver in project jackrabbit by apache.
the class RepositoryServiceImpl method getPropertyInfo.
@Override
public PropertyInfo getPropertyInfo(SessionInfo sessionInfo, PropertyId propertyId) throws RepositoryException {
HttpGet request = null;
try {
String uri = getItemUri(propertyId, sessionInfo);
request = new HttpGet(uri);
HttpResponse response = executeRequest(sessionInfo, request);
int status = response.getStatusLine().getStatusCode();
if (status != DavServletResponse.SC_OK) {
throw ExceptionConverter.generate(new DavException(status, response.getStatusLine().getReasonPhrase()));
}
Path path = uriResolver.getQPath(uri, sessionInfo);
HttpEntity entity = response.getEntity();
ContentType ct = ContentType.get(entity);
boolean isMultiValued;
QValue[] values;
int type;
NamePathResolver resolver = getNamePathResolver(sessionInfo);
if (ct != null && ct.getMimeType().startsWith("jcr-value")) {
type = JcrValueType.typeFromContentType(ct.getMimeType());
QValue v;
if (type == PropertyType.BINARY) {
v = getQValueFactory().create(entity.getContent());
} else {
Reader reader = new InputStreamReader(entity.getContent(), ct.getCharset());
StringBuffer sb = new StringBuffer();
int c;
while ((c = reader.read()) > -1) {
sb.append((char) c);
}
Value jcrValue = valueFactory.createValue(sb.toString(), type);
if (jcrValue instanceof QValueValue) {
v = ((QValueValue) jcrValue).getQValue();
} else {
v = ValueFormat.getQValue(jcrValue, resolver, getQValueFactory());
}
}
values = new QValue[] { v };
isMultiValued = false;
} else if (ct != null && ct.getMimeType().equals("text/xml")) {
// jcr:values property spooled
values = getValues(entity.getContent(), resolver, propertyId);
type = (values.length > 0) ? values[0].getType() : loadType(uri, getClient(sessionInfo), propertyId, sessionInfo, resolver);
isMultiValued = true;
} else {
throw new ItemNotFoundException("Unable to retrieve the property with id " + saveGetIdString(propertyId, resolver));
}
return new PropertyInfoImpl(propertyId, path, type, isMultiValued, values);
} 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 executeQuery.
@Override
public QueryInfo executeQuery(SessionInfo sessionInfo, String statement, String language, Map<String, String> namespaces, long limit, long offset, Map<String, QValue> values) throws RepositoryException {
HttpSearch request = null;
try {
String uri = uriResolver.getWorkspaceUri(sessionInfo.getWorkspaceName());
SearchInfo sInfo = new SearchInfo(language, ItemResourceConstants.NAMESPACE, statement, namespaces);
if (limit != -1) {
sInfo.setNumberResults(limit);
}
if (offset != -1) {
sInfo.setOffset(offset);
}
if (!(values == null || values.isEmpty())) {
throw new UnsupportedOperationException("Implementation missing: JCR-2107");
}
request = new HttpSearch(uri, sInfo);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
MultiStatus ms = request.getResponseBodyAsMultiStatus(response);
NamePathResolver resolver = getNamePathResolver(sessionInfo);
return new QueryInfoImpl(ms, idFactory, resolver, valueFactory, getQValueFactory());
} catch (IOException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
Aggregations