org.apache.jackrabbit.webdav.io.OutputContext Java Examples
The following examples show how to use
org.apache.jackrabbit.webdav.io.OutputContext.
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 |
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: ArchivaDavResource.java From archiva with Apache License 2.0 | 6 votes |
@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 #3
Source File: ExportContextImpl.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
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: ArchivaVirtualDavResource.java From archiva with Apache License 2.0 | 5 votes |
@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 #5
Source File: DavCalendarResource.java From cosmo with Apache License 2.0 | 5 votes |
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: DavFile.java From cosmo with Apache License 2.0 | 5 votes |
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 #7
Source File: DavOutboxCollection.java From cosmo with Apache License 2.0 | 4 votes |
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 #8
Source File: DavInboxCollection.java From cosmo with Apache License 2.0 | 4 votes |
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 |
public void writeTo(OutputContext outputContext) throws CosmoDavException, IOException { writeHtmlDirectoryIndex(outputContext); }
Example #10
Source File: DavResourceBase.java From cosmo with Apache License 2.0 | 4 votes |
public void spool(OutputContext outputContext) throws IOException { throw new UnsupportedOperationException(); }
Example #11
Source File: DavCollectionBase.java From cosmo with Apache License 2.0 | 4 votes |
public void writeTo(OutputContext out) throws CosmoDavException, IOException { writeHtmlDirectoryIndex(out); }
Example #12
Source File: DavCollectionBase.java From cosmo with Apache License 2.0 | 4 votes |
public void spool(OutputContext outputContext) throws IOException { throw new UnsupportedOperationException(); }
Example #13
Source File: DavOutboxCollection.java From cosmo with Apache License 2.0 | 4 votes |
public void writeTo(OutputContext outputContext) throws CosmoDavException, IOException { writeHtmlDirectoryIndex(outputContext); }
Example #14
Source File: WebDavResource.java From cosmo with Apache License 2.0 | 4 votes |
void writeTo(OutputContext out) throws CosmoDavException, IOException;
Example #15
Source File: DavUserPrincipalCollection.java From cosmo with Apache License 2.0 | 4 votes |
public void writeTo(OutputContext outputContext) throws CosmoDavException, IOException { throw new UnsupportedOperationException(); }
Example #16
Source File: DavUserPrincipal.java From cosmo with Apache License 2.0 | 4 votes |
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 #17
Source File: DavUserPrincipal.java From cosmo with Apache License 2.0 | 4 votes |
public void writeTo(OutputContext context) throws CosmoDavException, IOException { writeHtmlRepresentation(context); }
Example #18
Source File: DavResourceImpl.java From document-management-software with GNU Lesser General Public License v3.0 | 4 votes |
/** * @see org.apache.jackrabbit.webdav.simple.DavResourceImpl#getExportContext(OutputContext) */ protected ExportContext getExportContext(OutputContext outputCtx) throws IOException { return new ExportContextImpl(this.resource, outputCtx); }
Example #19
Source File: DavResourceImpl.java From document-management-software with GNU Lesser General Public License v3.0 | 3 votes |
/** * If this resource exists and the specified context is not * <code>null</code> this implementation build a new {@link ExportContext} * based on the specified context and forwards the export to its * <code>IOManager</code>. If the * {@link IOManager#exportContent(ExportContext, DavResource)} fails, an * <code>IOException</code> is thrown. * * @see DavResource#spool(OutputContext) * @see ResourceConfig#getIOManager() * * @throws IOException if the export fails */ public void spool(OutputContext outputContext) throws IOException { if (exists() && outputContext != null) { ExportContext exportCtx = getExportContext(outputContext); if (!config.getIOManager().exportContent(exportCtx, this)) { throw new IOException("Unexpected Error while spooling resource."); } } }
Example #20
Source File: AbstractWebdavServlet.java From document-management-software with GNU Lesser General Public License v3.0 | 2 votes |
/** * Return a new <code>OutputContext</code> used for spooling resource * properties and the resource content * * @param response the DAV response * @param out stream of the output * * @return the output context * * @see #doPut(WebdavRequest, WebdavResponse, DavResource) * @see #doPost(WebdavRequest, WebdavResponse, DavResource) * @see #doMkCol(WebdavRequest, WebdavResponse, DavResource) */ protected OutputContext getOutputContext(DavServletResponse response, OutputStream out) { return new OutputContextImpl(response, out); }
Example #21
Source File: BaseProvider.java From cosmo with Apache License 2.0 | 2 votes |
/** * * @param response * DavResponse * @param withEntity * boolean * @return OutputContext * @throws IOException */ protected OutputContext createOutputContext(DavResponse response, boolean withEntity) throws IOException { OutputStream out = withEntity ? response.getOutputStream() : null; return new OutputContextImpl(response, out); }