Java Code Examples for org.apache.jackrabbit.webdav.io.OutputContext#getOutputStream()

The following examples show how to use org.apache.jackrabbit.webdav.io.OutputContext#getOutputStream() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IndexWriter.java    From archiva with Apache License 2.0 6 votes vote down vote up
public void write( OutputContext outputContext )
{
    outputContext.setModificationTime( new Date().getTime() );
    outputContext.setContentType( "text/html" );
    outputContext.setETag( "" ); // skygo ETag MRM-1127 seems to be fixed
    if ( outputContext.hasStream() )
    {
        PrintWriter writer = new PrintWriter( outputContext.getOutputStream() );
        writeDocumentStart( writer );
        try
        {
            writeHyperlinks( writer );
        }
        catch ( IOException e )
        {
            log.error("Could not write hyperlinks {}", e.getMessage(), e);
        }
        writeDocumentEnd( writer );
        writer.flush();
        writer.close();
    }
}
 
Example 2
Source File: DavUserPrincipal.java    From cosmo with Apache License 2.0 4 votes vote down vote up
private void writeHtmlRepresentation(OutputContext context)
    throws CosmoDavException, IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Writing html representation for user principal {}", getDisplayName());
    }

    context.setContentType(ContentTypeUtil.buildContentType("text/html", "UTF-8"));
    context.setModificationTime(getModificationTime());
    context.setETag(getETag());

    if (! context.hasStream()) {
        return;
    }

    PrintWriter writer =
        new PrintWriter(new OutputStreamWriter(context.getOutputStream(),
                                               "utf8"));
    try{
        writer.write("<html>\n<head><title>");
        writer.write(StringEscapeUtils.escapeHtml(getDisplayName()));
        writer.write("</title></head>\n");
        writer.write("<body>\n");
        writer.write("<h1>");
        writer.write(StringEscapeUtils.escapeHtml(getDisplayName()));
        writer.write("</h1>\n");

        writer.write("<h2>Properties</h2>\n");
        writer.write("<dl>\n");
        for (DavPropertyIterator i=getProperties().iterator(); i.hasNext();) {
            WebDavProperty prop = (WebDavProperty) i.nextProperty();
            Object value = prop.getValue();
            String text = null;
            if (value instanceof Element) {
                try {
                    text = DomWriter.write((Element)value);
                } catch (XMLStreamException e) {
                    LOG.warn("Error serializing value for property {}", prop.getName());
                }
            }
            if (text == null) {
                text = prop.getValueText();
            }
            writer.write("<dt>");
            writer.write(StringEscapeUtils.escapeHtml(prop.getName().toString()));
            writer.write("</dt><dd>");
            writer.write(StringEscapeUtils.escapeHtml(text));
            writer.write("</dd>\n");
        }
        writer.write("</dl>\n");

        WebDavResource parent = getParent();
        writer.write("<a href=\"");
        writer.write(parent.getResourceLocator().getHref(true));
        writer.write("\">");
        writer.write(StringEscapeUtils.escapeHtml(parent.getDisplayName()));
        writer.write("</a></li>\n");
        
        User user = getSecurityManager().getSecurityContext().getUser();
        if (user != null) {
            writer.write("<p>\n");
            DavResourceLocator homeLocator =
                getResourceLocator().getFactory().
                createHomeLocator(getResourceLocator().getContext(), user);
            writer.write("<a href=\"");
            writer.write(homeLocator.getHref(true));
            writer.write("\">");
            writer.write("Home collection");
            writer.write("</a><br>\n");
        }

        writer.write("</body>");
        writer.write("</html>\n");
    }finally{
        writer.close();
    }
}
 
Example 3
Source File: DavOutboxCollection.java    From cosmo with Apache License 2.0 4 votes vote down vote up
private void writeHtmlDirectoryIndex(OutputContext context)
    throws CosmoDavException, IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Writing html directory index for {}", getDisplayName());
    }
    context.setContentType(ContentTypeUtil.buildContentType("text/html", "UTF-8"));
    // no modification time or etag

    if (! context.hasStream()) {
        return;
    }

    PrintWriter writer =
        new PrintWriter(new OutputStreamWriter(context.getOutputStream(),
                                               "utf8"));
    try{
        writer.write("<html>\n<head><title>");
        writer.write(StringEscapeUtils.escapeHtml(getDisplayName()));
        writer.write("</title></head>\n");
        writer.write("<body>\n");
        writer.write("<h1>");
        writer.write(StringEscapeUtils.escapeHtml(getDisplayName()));
        writer.write("</h1>\n");

        writer.write("<h2>Properties</h2>\n");
        writer.write("<dl>\n");
        for (DavPropertyIterator i=getProperties().iterator(); i.hasNext();) {
            WebDavProperty prop = (WebDavProperty) i.nextProperty();
            Object value = prop.getValue();
            String text = null;
            if (value instanceof Element) {
                try {
                    text = DomWriter.write((Element)value);
                } catch (XMLStreamException e) {
                    LOG.warn("Error serializing value for property " + prop.getName());
                }
            }
            if (text == null) {
                text = prop.getValueText();
            }
            writer.write("<dt>");
            writer.write(StringEscapeUtils.escapeHtml(prop.getName().toString()));
            writer.write("</dt><dd>");
            writer.write(StringEscapeUtils.escapeHtml(text));
            writer.write("</dd>\n");
        }
        writer.write("</dl>\n");

        User user = getSecurityManager().getSecurityContext().getUser();
        if (user != null) {
            writer.write("<p>\n");
            DavResourceLocator homeLocator =
                getResourceLocator().getFactory().
                createHomeLocator(getResourceLocator().getContext(), user);
            writer.write("<a href=\"");
            writer.write(homeLocator.getHref(true));
            writer.write("\">");
            writer.write("Home collection");
            writer.write("</a><br>\n");

            DavResourceLocator principalLocator = 
                getResourceLocator().getFactory().
                createPrincipalLocator(getResourceLocator().getContext(),
                                       user);
            writer.write("<a href=\"");
            writer.write(principalLocator.getHref(false));
            writer.write("\">");
            writer.write("Principal resource");
            writer.write("</a><br>\n");
        }

        writer.write("</body>");
        writer.write("</html>\n");
    }finally{
        writer.close();
    }
}
 
Example 4
Source File: DavInboxCollection.java    From cosmo with Apache License 2.0 4 votes vote down vote up
private void writeHtmlDirectoryIndex(OutputContext context) throws CosmoDavException, IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Writing html directory index for {}", getDisplayName());
    }
    context.setContentType(ContentTypeUtil.buildContentType("text/html", "UTF-8"));
    // no modification time or etag

    if (!context.hasStream()) {
        return;
    }

    PrintWriter writer = new PrintWriter(new OutputStreamWriter(context.getOutputStream(), "utf8"));
    try {
        writer.write("<html>\n<head><title>");
        writer.write(StringEscapeUtils.escapeHtml(getDisplayName()));
        writer.write("</title></head>\n");
        writer.write("<body>\n");
        writer.write("<h1>");
        writer.write(StringEscapeUtils.escapeHtml(getDisplayName()));
        writer.write("</h1>\n");

        writer.write("<h2>Properties</h2>\n");
        writer.write("<dl>\n");
        for (DavPropertyIterator i = getProperties().iterator(); i.hasNext();) {
            WebDavProperty prop = (WebDavProperty) i.nextProperty();
            Object value = prop.getValue();
            String text = null;
            if (value instanceof Element) {
                try {
                    text = DomWriter.write((Element) value);
                } catch (XMLStreamException e) {
                    LOG.warn("Error serializing value for property {}", prop.getName());
                }
            }
            if (text == null) {
                text = prop.getValueText();
            }
            writer.write("<dt>");
            writer.write(StringEscapeUtils.escapeHtml(prop.getName().toString()));
            writer.write("</dt><dd>");
            writer.write(StringEscapeUtils.escapeHtml(text));
            writer.write("</dd>\n");
        }
        writer.write("</dl>\n");

        User user = getSecurityManager().getSecurityContext().getUser();
        if (user != null) {
            writer.write("<p>\n");
            DavResourceLocator homeLocator = getResourceLocator().getFactory()
                    .createHomeLocator(getResourceLocator().getContext(), user);
            writer.write("<a href=\"");
            writer.write(homeLocator.getHref(true));
            writer.write("\">");
            writer.write("Home collection");
            writer.write("</a><br>\n");

            DavResourceLocator principalLocator = getResourceLocator().getFactory()
                    .createPrincipalLocator(getResourceLocator().getContext(), user);
            writer.write("<a href=\"");
            writer.write(principalLocator.getHref(false));
            writer.write("\">");
            writer.write("Principal resource");
            writer.write("</a><br>\n");
        }

        writer.write("</body>");
        writer.write("</html>\n");
    } finally {
        writer.close();
    }
}