Search in sources :

Example 1 with NamePathResolver

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);
    }
}
Also used : NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) DefaultNamePathResolver(org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver) DefaultNamePathResolver(org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver)

Example 2 with NamePathResolver

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();
        }
    }
}
Also used : NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) HttpEntity(org.apache.http.HttpEntity) DavException(org.apache.jackrabbit.webdav.DavException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) IOException(java.io.IOException)

Example 3 with NamePathResolver

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);
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) PropertyId(org.apache.jackrabbit.spi.PropertyId)

Example 4 with NamePathResolver

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();
        }
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) QValueValue(org.apache.jackrabbit.spi.commons.value.QValueValue) NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) QValue(org.apache.jackrabbit.spi.QValue) HttpEntity(org.apache.http.HttpEntity) ContentType(org.apache.http.entity.ContentType) InputStreamReader(java.io.InputStreamReader) DavException(org.apache.jackrabbit.webdav.DavException) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) IllegalNameException(org.apache.jackrabbit.spi.commons.conversion.IllegalNameException) QValue(org.apache.jackrabbit.spi.QValue) Value(javax.jcr.Value) QValueValue(org.apache.jackrabbit.spi.commons.value.QValueValue) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 5 with NamePathResolver

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();
        }
    }
}
Also used : NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) SearchInfo(org.apache.jackrabbit.webdav.search.SearchInfo) DavException(org.apache.jackrabbit.webdav.DavException) HttpResponse(org.apache.http.HttpResponse) MultiStatus(org.apache.jackrabbit.webdav.MultiStatus) RepositoryException(javax.jcr.RepositoryException) HttpSearch(org.apache.jackrabbit.webdav.client.methods.HttpSearch) IOException(java.io.IOException)

Aggregations

NamePathResolver (org.apache.jackrabbit.spi.commons.conversion.NamePathResolver)27 DefaultNamePathResolver (org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver)13 RepositoryException (javax.jcr.RepositoryException)10 IOException (java.io.IOException)7 HttpResponse (org.apache.http.HttpResponse)7 DavException (org.apache.jackrabbit.webdav.DavException)7 Name (org.apache.jackrabbit.spi.Name)5 ArrayList (java.util.ArrayList)4 ItemNotFoundException (javax.jcr.ItemNotFoundException)4 HttpEntity (org.apache.http.HttpEntity)4 Path (org.apache.jackrabbit.spi.Path)4 QValue (org.apache.jackrabbit.spi.QValue)4 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)4 Value (javax.jcr.Value)3 Privilege (javax.jcr.security.Privilege)3 DummyNamespaceResolver (org.apache.jackrabbit.spi.commons.conversion.DummyNamespaceResolver)3 InputStreamReader (java.io.InputStreamReader)2 Reader (java.io.Reader)2 Session (javax.jcr.Session)2 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)2