Search in sources :

Example 21 with DavResource

use of org.apache.jackrabbit.webdav.DavResource in project jackrabbit by apache.

the class RootCollection method spool.

/**
     * Sets content lengths to '0' and retrieves the modification time.
     *
     * @param outputContext
     * @throws IOException
     * @see DavResource#spool(org.apache.jackrabbit.webdav.io.OutputContext)
     */
@Override
public void spool(OutputContext outputContext) throws IOException {
    if (outputContext.hasStream()) {
        Session session = getRepositorySession();
        Repository rep = session.getRepository();
        String repName = rep.getDescriptor(Repository.REP_NAME_DESC);
        String repURL = rep.getDescriptor(Repository.REP_VENDOR_URL_DESC);
        String repVersion = rep.getDescriptor(Repository.REP_VERSION_DESC);
        String repostr = repName + " " + repVersion;
        StringBuilder sb = new StringBuilder();
        sb.append("<html><head><title>");
        sb.append(repostr);
        sb.append("</title></head>");
        sb.append("<body><h2>").append(repostr).append("</h2>");
        sb.append("<h3>Available Workspace Resources:</h3><ul>");
        DavResourceIterator it = getMembers();
        while (it.hasNext()) {
            DavResource res = it.nextResource();
            sb.append("<li><a href=\"");
            sb.append(res.getHref());
            sb.append("\">");
            sb.append(res.getDisplayName());
            sb.append("</a></li>");
        }
        sb.append("</ul><hr size=\"1\"><em>Powered by <a href=\"");
        sb.append(repURL).append("\">").append(repName);
        sb.append("</a> ").append(repVersion);
        sb.append("</em></body></html>");
        outputContext.setContentLength(sb.length());
        outputContext.setModificationTime(getModificationTime());
        PrintWriter writer = new PrintWriter(new OutputStreamWriter(outputContext.getOutputStream(), "utf8"));
        writer.print(sb.toString());
        writer.close();
    } else {
        outputContext.setContentLength(0);
        outputContext.setModificationTime(getModificationTime());
    }
}
Also used : DavResourceIterator(org.apache.jackrabbit.webdav.DavResourceIterator) Repository(javax.jcr.Repository) DavResource(org.apache.jackrabbit.webdav.DavResource) OutputStreamWriter(java.io.OutputStreamWriter) Session(javax.jcr.Session) PrintWriter(java.io.PrintWriter)

Example 22 with DavResource

use of org.apache.jackrabbit.webdav.DavResource in project jackrabbit by apache.

the class VersionControlledItemCollection method merge.

/**
     * Merge the repository node represented by this resource according to the
     * information present in the given {@link MergeInfo} object.
     *
     * @param mergeInfo
     * @return <code>MultiStatus</code> recording all repository items modified
     * by this merge call as well as the resources that a client must modify to
     * complete the merge (see <a href="http://www.webdav.org/specs/rfc3253.html#METHOD_MERGE">RFC 3253</a>)
     * @throws org.apache.jackrabbit.webdav.DavException
     * @see org.apache.jackrabbit.webdav.version.VersionControlledResource#merge(org.apache.jackrabbit.webdav.version.MergeInfo)
     * @see Node#merge(String, boolean)
     */
//TODO: with jcr the node must not be versionable in order to perform Node.merge
@Override
public MultiStatus merge(MergeInfo mergeInfo) throws DavException {
    if (mergeInfo == null) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST);
    }
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    MultiStatus ms = new MultiStatus();
    try {
        // NOTE: RFC requires that all modified resources are reported in the
        // multistatus response. this doesn't work however with the remoting
        // there is no way to distinguish the 'failedId's from any other
        // resources that got modified by this merge operation -> omitted.
        // todo: RFC allows multiple href elements inside the DAV:source element
        String workspaceName = getLocatorFromHref(mergeInfo.getSourceHrefs()[0]).getWorkspaceName();
        String depth = DomUtil.getChildTextTrim(mergeInfo.getMergeElement(), DavConstants.XML_DEPTH, DavConstants.NAMESPACE);
        boolean isShallow = "0".equals(depth);
        NodeIterator failed = getVersionManager().merge(item.getPath(), workspaceName, !mergeInfo.isNoAutoMerge(), isShallow);
        // add resources to the multistatus, that failed to be merged
        while (failed.hasNext()) {
            Node failedNode = failed.nextNode();
            DavResourceLocator loc = getLocatorFromItem(failedNode);
            DavResource res = createResourceFromLocator(loc);
            ms.addResponse(new MultiStatusResponse(res, mergeInfo.getPropertyNameSet()));
        }
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
    return ms;
}
Also used : NodeIterator(javax.jcr.NodeIterator) DavResource(org.apache.jackrabbit.webdav.DavResource) DavException(org.apache.jackrabbit.webdav.DavException) Node(javax.jcr.Node) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) MultiStatus(org.apache.jackrabbit.webdav.MultiStatus) RepositoryException(javax.jcr.RepositoryException) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 23 with DavResource

use of org.apache.jackrabbit.webdav.DavResource in project jackrabbit by apache.

the class LocateByUuidReport method init.

/**
     * @see Report#init(DavResource, ReportInfo)
     */
@Override
public void init(DavResource resource, ReportInfo info) throws DavException {
    // delegate basic validation to super class
    super.init(resource, info);
    // make also sure, the info contains a DAV:href child element
    if (!info.containsContentElement(DavConstants.XML_HREF, DavConstants.NAMESPACE)) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "dcr:locate-by-uuid element must at least contain a single DAV:href child.");
    }
    // immediately build the final multistatus element
    try {
        Element hrefElem = info.getContentElement(DavConstants.XML_HREF, DavConstants.NAMESPACE);
        String uuid = DomUtil.getTextTrim(hrefElem);
        DavResourceLocator resourceLoc = resource.getLocator();
        Node n = getRepositorySession().getNodeByUUID(uuid);
        DavResourceLocator loc = resourceLoc.getFactory().createResourceLocator(resourceLoc.getPrefix(), resourceLoc.getWorkspacePath(), n.getPath(), false);
        DavResource locatedResource = resource.getFactory().createResource(loc, resource.getSession());
        ms = new MultiStatus();
        ms.addResourceProperties(locatedResource, info.getPropertyNameSet(), info.getDepth());
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
}
Also used : JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavResource(org.apache.jackrabbit.webdav.DavResource) DavException(org.apache.jackrabbit.webdav.DavException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) Element(org.w3c.dom.Element) Node(javax.jcr.Node) MultiStatus(org.apache.jackrabbit.webdav.MultiStatus) RepositoryException(javax.jcr.RepositoryException) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 24 with DavResource

use of org.apache.jackrabbit.webdav.DavResource in project jackrabbit by apache.

the class DavResourceImpl method getCollection.

/**
     * @see DavResource#getCollection()
     */
public DavResource getCollection() {
    DavResource parent = null;
    if (getResourcePath() != null && !getResourcePath().equals("/")) {
        String parentPath = Text.getRelativeParent(getResourcePath(), 1);
        if (parentPath.equals("")) {
            parentPath = "/";
        }
        DavResourceLocator parentloc = locator.getFactory().createResourceLocator(locator.getPrefix(), locator.getWorkspacePath(), parentPath);
        try {
            parent = factory.createResource(parentloc, session);
        } catch (DavException e) {
        // should not occur
        }
    }
    return parent;
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavException(org.apache.jackrabbit.webdav.DavException) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 25 with DavResource

use of org.apache.jackrabbit.webdav.DavResource in project jackrabbit by apache.

the class VersionControlledResourceImpl method getVersionHistory.

/**
     * Returns the {@link javax.jcr.version.VersionHistory} associated with the repository node.
     * If the node is not versionable an exception is thrown.
     *
     * @return the {@link VersionHistoryResource} associated with this resource.
     * @throws org.apache.jackrabbit.webdav.DavException
     * @see org.apache.jackrabbit.webdav.version.VersionControlledResource#getVersionHistory()
     * @see javax.jcr.Node#getVersionHistory()
     */
public VersionHistoryResource getVersionHistory() throws DavException {
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    if (!isVersionControlled()) {
        throw new DavException(DavServletResponse.SC_FORBIDDEN);
    }
    try {
        VersionHistory vh = getNode().getVersionHistory();
        DavResourceLocator loc = getLocatorFromNode(vh);
        DavResource vhr = createResourceFromLocator(loc);
        if (vhr instanceof VersionHistoryResource) {
            return (VersionHistoryResource) vhr;
        } else {
            // severe error since resource factory doesn't behave correctly.
            throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
    } catch (RepositoryException e) {
        throw new JcrDavException(e);
    }
}
Also used : JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavResource(org.apache.jackrabbit.webdav.DavResource) DavException(org.apache.jackrabbit.webdav.DavException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) VersionHistoryResource(org.apache.jackrabbit.webdav.version.VersionHistoryResource) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Aggregations

DavResource (org.apache.jackrabbit.webdav.DavResource)40 DavException (org.apache.jackrabbit.webdav.DavException)21 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)19 RepositoryException (javax.jcr.RepositoryException)16 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)7 ArrayList (java.util.ArrayList)6 Node (javax.jcr.Node)6 VersionHistory (javax.jcr.version.VersionHistory)6 DavResourceIteratorImpl (org.apache.jackrabbit.webdav.DavResourceIteratorImpl)5 Version (javax.jcr.version.Version)4 DavResourceIterator (org.apache.jackrabbit.webdav.DavResourceIterator)4 OutputStreamWriter (java.io.OutputStreamWriter)3 PrintWriter (java.io.PrintWriter)3 Item (javax.jcr.Item)3 NodeIterator (javax.jcr.NodeIterator)3 Repository (javax.jcr.Repository)3 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)3 Session (javax.jcr.Session)2 VersionIterator (javax.jcr.version.VersionIterator)2 MultiStatus (org.apache.jackrabbit.webdav.MultiStatus)2