@Override public void spool(OutputContext outputContext) throws IOException { // Protect against direct url referencing. if (!getContext().hasAccess("view", attachment.getDoc().getFullName())) { throw new IOException("Access rights violation."); } outputContext.setContentLanguage(attachment.getDoc().getLanguage()); outputContext.setContentLength(attachment.getLongSize()); outputContext.setContentType(getContext().getMimeType(attachment)); outputContext.setETag(DavConstants.modificationDateFormat.format(getModificationTime())); outputContext.setModificationTime(getModificationTime()); if (exists()) { OutputStream out = outputContext.getOutputStream(); if (null != out) { try { out.write(getContext().getContent(attachment)); out.flush(); } catch (DavException ex) { throw new IOException(ex.getMessage()); } } } }
protected Attachment newAttachment(Attachment att, XWikiAttachment xAtt, XWikiContext context) { att.setAttDate(xAtt.getDate().getTime()); att.setAuthor(xAtt.getAuthor()); att.setFilename(xAtt.getFilename()); att.setId(xAtt.getId()); att.setImage(xAtt.isImage(context)); att.setMimeType(xAtt.getMimeType(context)); att.setLongSize(xAtt.getLongSize()); att.setDownloadUrl(context.getWiki().getExternalAttachmentURL(xAtt.getDoc().getFullName(), xAtt.getFilename(), context)); return att; }
solrDocument.addField(FieldUtils.MIME_TYPE, attachment.getMimeType(xcontext)); solrDocument.addField(FieldUtils.ATTACHMENT_DATE, attachment.getDate()); solrDocument.addField(FieldUtils.ATTACHMENT_SIZE, attachment.getLongSize());
solrDocument.setField(FieldUtils.ATTACHMENT_SIZE, attachment.getLongSize()); solrDocument.setField(FieldUtils.ATTACHMENT_SIZE_SORT, attachment.getLongSize());
@Override public void serialize(final XWikiAttachment attach, final XMLWriter writer) throws IOException { final Element docel = new DOMElement(ROOT_ELEMENT_NAME); docel.addAttribute(SERIALIZER_PARAM, THIS_SERIALIZER); writer.writeOpen(docel); writer.write(new DOMElement(FILENAME).addText(attach.getFilename())); writer.write(new DOMElement(FILESIZE).addText(attach.getLongSize() + "")); writer.write(new DOMElement(AUTHOR).addText(attach.getAuthor())); writer.write(new DOMElement(VERSION).addText(attach.getVersion())); writer.write(new DOMElement(COMMENT).addText(attach.getComment())); writer.write(new DOMElement(DATE).addText(attach.getDate().getTime() + "")); writer.writeClose(docel); } }
@Override public void init(XWikiDavResource parent, String name, String relativePath) throws DavException { super.init(parent, name, relativePath); if (parent.exists()) { this.attachment = ((DavPage) parent).getDocument().getAttachment(this.name); } if (exists()) { String timeStamp = DavConstants.creationDateFormat.format(attachment.getDate()); getProperties().add(new DefaultDavProperty(DavPropertyName.CREATIONDATE, timeStamp)); timeStamp = DavConstants.modificationDateFormat.format(attachment.getDate()); getProperties().add( new DefaultDavProperty(DavPropertyName.GETLASTMODIFIED, timeStamp)); getProperties().add(new DefaultDavProperty(DavPropertyName.GETETAG, timeStamp)); getProperties().add( new DefaultDavProperty(DavPropertyName.GETCONTENTTYPE, getContext().getMimeType( attachment))); getProperties().add( new DefaultDavProperty(DavPropertyName.GETCONTENTLANGUAGE, attachment.getDoc() .getLanguage())); getProperties() .add( new DefaultDavProperty(DavPropertyName.GETCONTENTLENGTH, attachment .getLongSize())); } }