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

The following examples show how to use org.apache.jackrabbit.webdav.io.OutputContext#hasStream() . 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: ArchivaDavResource.java    From archiva with Apache License 2.0 6 votes vote down vote up
@Override
public void spool( OutputContext outputContext )
    throws IOException
{
    if ( !isCollection() )
    {
        outputContext.setContentLength( asset.getSize());
        outputContext.setContentType( mimeTypes.getMimeType( asset.getName() ) );
    }

    if ( !isCollection() && outputContext.hasStream() )
    {
        repositoryStorage.consumeData( asset, is -> {copyStream(is, outputContext.getOutputStream());}, true );
    }
    else if ( outputContext.hasStream() )
    {
        IndexWriter writer = new IndexWriter( asset, logicalResource );
        writer.write( outputContext );
    }
}
 
Example 2
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 3
Source File: ExportContextImpl.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ExportContextImpl(Resource resource, OutputContext outputCtx) throws IOException {
	super(resource, (outputCtx != null) ? outputCtx.hasStream() : false);
	this.outputCtx = outputCtx;
	if (hasStream()) {
		// we need a tmp file, since the export could fail
		outFile = File.createTempFile("__exportcontext", "tmp");
	}
}
 
Example 4
Source File: DavFile.java    From cosmo with Apache License 2.0 5 votes vote down vote up
public void writeTo(OutputContext outputContext)
    throws CosmoDavException, IOException {
    if (! exists()) {
        throw new IllegalStateException("cannot spool a nonexistent resource");
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("Spooling file {}", getResourcePath());
    }

    FileItem content = (FileItem) getItem();

    String contentType =
        ContentTypeUtil.buildContentType(content.getContentType(),
                                content.getContentEncoding());
    outputContext.setContentType(contentType);

    if (content.getContentLanguage() != null) {
        outputContext.setContentLanguage(content.getContentLanguage());
    }

    long len = content.getContentLength() != null ?
        content.getContentLength().longValue() : 0;
    outputContext.setContentLength(len);
    outputContext.setModificationTime(getModificationTime());
    outputContext.setETag(getETag());

    if (! outputContext.hasStream()) {
        return;
    }
    if (content.getContentInputStream() == null) {
        return;
    }

    FileCopyUtils.copy(content.getContentInputStream(),
                 outputContext.getOutputStream());
}
 
Example 5
Source File: DavCalendarResource.java    From cosmo with Apache License 2.0 5 votes vote down vote up
public void writeTo(OutputContext outputContext)
    throws CosmoDavException, IOException {
    if (! exists()) {
        throw new IllegalStateException("cannot spool a nonexistent resource");
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("Spooling file {}", getResourcePath());
    }

    String contentType =
        ContentTypeUtil.buildContentType(ICALENDAR_MEDIA_TYPE, "UTF-8");
    outputContext.setContentType(contentType);
  
    // Get calendar
    Calendar calendar = getCalendar();
    
    // convert Calendar object to String, then to bytes (UTF-8)    
    byte[] calendarBytes = calendar.toString().getBytes("UTF-8");
    outputContext.setContentLength(calendarBytes.length);
    outputContext.setModificationTime(getModificationTime());
    outputContext.setETag(getETag());
    
    if (! outputContext.hasStream()) {
        return;
    }

    // spool calendar bytes
    ByteArrayInputStream bois = new ByteArrayInputStream(calendarBytes);
    FileCopyUtils.copy(bois, outputContext.getOutputStream());
}
 
Example 6
Source File: ArchivaVirtualDavResource.java    From archiva with Apache License 2.0 5 votes vote down vote up
@Override
public void spool( OutputContext outputContext ) {
    if ( outputContext.hasStream() )
    {
        List<StorageAsset> localResourceFiles = localResources.stream().filter(Objects::nonNull)
                .filter(repoAsset -> repoAsset.exists())
                .sorted(Comparator.comparing(o -> o.getName())).collect(Collectors.toList());

        IndexWriter writer = new IndexWriter(localResourceFiles, logicalResource );
        writer.write( outputContext );
    }
}
 
Example 7
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 8
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 9
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();
    }
}