Search in sources :

Example 16 with NamePathResolver

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

Example 17 with NamePathResolver

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();
        }
    }
}
Also used : NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) DavException(org.apache.jackrabbit.webdav.DavException) Element(org.w3c.dom.Element) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) QItemDefinition(org.apache.jackrabbit.spi.QItemDefinition) DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 18 with NamePathResolver

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();
        }
    }
}
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 19 with NamePathResolver

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();
        }
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) HttpEntity(org.apache.http.HttpEntity) DavException(org.apache.jackrabbit.webdav.DavException) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) NodeId(org.apache.jackrabbit.spi.NodeId) PropertyInfo(org.apache.jackrabbit.spi.PropertyInfo) ItemNotFoundException(javax.jcr.ItemNotFoundException) JsonParser(org.apache.jackrabbit.commons.json.JsonParser)

Example 20 with NamePathResolver

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

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