Search in sources :

Example 1 with DavResourceIterator

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

the class DirListingExportHandler method exportContent.

/**
     * @see IOHandler#exportContent(ExportContext, DavResource)
     */
public boolean exportContent(ExportContext context, DavResource resource) throws IOException {
    if (!canExport(context, resource)) {
        throw new IOException(getName() + ": Cannot export " + context.getExportRoot());
    }
    // properties (content length undefined)
    context.setModificationTime(new Date().getTime());
    context.setContentType("text/html", "UTF-8");
    context.setETag("");
    // data
    if (context.hasStream()) {
        PrintWriter writer = new PrintWriter(new OutputStreamWriter(context.getOutputStream(), "utf8"));
        try {
            Item item = context.getExportRoot();
            Repository rep = item.getSession().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);
            writer.print("<html><head><title>");
            writer.print(Text.encodeIllegalHTMLCharacters(repName));
            writer.print(" ");
            writer.print(Text.encodeIllegalHTMLCharacters(repVersion));
            writer.print(" ");
            writer.print(Text.encodeIllegalHTMLCharacters(resource.getResourcePath()));
            writer.print("</title></head>");
            writer.print("<body><h2>");
            writer.print(Text.encodeIllegalHTMLCharacters(resource.getResourcePath()));
            writer.print("</h2><ul>");
            writer.print("<li><a href=\"..\">..</a></li>");
            DavResourceIterator iter = resource.getMembers();
            while (iter.hasNext()) {
                DavResource child = iter.nextResource();
                String label = Text.getName(child.getResourcePath());
                writer.print("<li><a href=\"");
                writer.print(Text.encodeIllegalHTMLCharacters(child.getHref()));
                writer.print("\">");
                writer.print(Text.encodeIllegalHTMLCharacters(label));
                writer.print("</a></li>");
            }
            writer.print("</ul><hr size=\"1\"><em>Powered by <a href=\"");
            writer.print(Text.encodeIllegalHTMLCharacters(repURL));
            writer.print("\">");
            writer.print(Text.encodeIllegalHTMLCharacters(repName));
            writer.print("</a> version ");
            writer.print(Text.encodeIllegalHTMLCharacters(repVersion));
            writer.print("</em></body></html>");
        } catch (RepositoryException e) {
            // should not occur
            log.debug(e.getMessage());
        }
        writer.close();
    }
    return true;
}
Also used : DavResourceIterator(org.apache.jackrabbit.webdav.DavResourceIterator) Item(javax.jcr.Item) Repository(javax.jcr.Repository) DavResource(org.apache.jackrabbit.webdav.DavResource) OutputStreamWriter(java.io.OutputStreamWriter) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) Date(java.util.Date) PrintWriter(java.io.PrintWriter)

Example 2 with DavResourceIterator

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

the class CompareBaselineReport method getVersions.

private void getVersions(DavResource collection, List<VersionResource> vList) throws DavException {
    DavResourceIterator it = collection.getMembers();
    while (it.hasNext()) {
        DavResource member = it.nextResource();
        if (member instanceof VersionControlledResource) {
            String href = new HrefProperty(member.getProperty(VersionControlledResource.CHECKED_IN)).getHrefs().get(0);
            DavResourceLocator locator = member.getLocator();
            DavResourceLocator vLocator = locator.getFactory().createResourceLocator(locator.getPrefix(), href);
            DavResource v = member.getFactory().createResource(vLocator, member.getSession());
            if (v instanceof VersionResource) {
                vList.add((VersionResource) v);
            } else {
                log.error("Internal error: DAV:checked-in property must point to a VersionResource.");
            }
        }
        if (member.isCollection()) {
            getVersions(member, vList);
        }
    }
}
Also used : DavResourceIterator(org.apache.jackrabbit.webdav.DavResourceIterator) DavResource(org.apache.jackrabbit.webdav.DavResource) HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) VersionResource(org.apache.jackrabbit.webdav.version.VersionResource) VersionControlledResource(org.apache.jackrabbit.webdav.version.VersionControlledResource) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator)

Example 3 with DavResourceIterator

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

the class WorkspaceResourceImpl method spool.

/**
     * @param outputContext
     * @throws IOException
     */
@Override
public void spool(OutputContext outputContext) throws IOException {
    outputContext.setProperty("Link", "<?" + EventJournalResourceImpl.RELURIFROMWORKSPACE + ">; title=\"Event Journal\"; rel=alternate; type=\"" + AtomFeedConstants.MEDIATYPE + "\"");
    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>");
        sb.append("<link rel=alternate type=\"" + AtomFeedConstants.MEDIATYPE + "\" title=\"Event Journal\" href=\"?" + EventJournalResourceImpl.RELURIFROMWORKSPACE + "\">");
        sb.append("</head>");
        sb.append("<body><h2>").append(repostr).append("</h2><ul>");
        sb.append("<li><a href=\"..\">..</a></li>");
        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 4 with DavResourceIterator

use of org.apache.jackrabbit.webdav.DavResourceIterator 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 5 with DavResourceIterator

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

the class ExpandPropertyReport method addResponses.

/**
     * Fills the specified <code>MultiStatus</code> object by generating a
     * <code>MultiStatusResponse</code> for the given resource (and
     * its member according to the depth value).
     *
     * @param res
     * @param depth
     * @param ms
     * @see #getResponse(DavResource, Iterator)
     */
private void addResponses(DavResource res, int depth, MultiStatus ms) {
    MultiStatusResponse response = getResponse(res, propertyElements);
    ms.addResponse(response);
    if (depth > 0 && res.isCollection()) {
        DavResourceIterator it = res.getMembers();
        while (it.hasNext()) {
            addResponses(it.nextResource(), depth - 1, ms);
        }
    }
}
Also used : DavResourceIterator(org.apache.jackrabbit.webdav.DavResourceIterator) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse)

Aggregations

DavResourceIterator (org.apache.jackrabbit.webdav.DavResourceIterator)5 DavResource (org.apache.jackrabbit.webdav.DavResource)4 OutputStreamWriter (java.io.OutputStreamWriter)3 PrintWriter (java.io.PrintWriter)3 Repository (javax.jcr.Repository)3 Session (javax.jcr.Session)2 IOException (java.io.IOException)1 Date (java.util.Date)1 Item (javax.jcr.Item)1 RepositoryException (javax.jcr.RepositoryException)1 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)1 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)1 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)1 VersionControlledResource (org.apache.jackrabbit.webdav.version.VersionControlledResource)1 VersionResource (org.apache.jackrabbit.webdav.version.VersionResource)1