Search in sources :

Example 21 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 22 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 23 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)

Example 24 with NamePathResolver

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

Example 25 with NamePathResolver

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);
}
Also used : NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) XmlSerializable(org.apache.jackrabbit.webdav.xml.XmlSerializable) Text(org.apache.jackrabbit.util.Text) Document(org.w3c.dom.Document) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName) Name(org.apache.jackrabbit.spi.Name)

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