@GET public Response getAttachment( @PathParam("wikiName") String wikiName, @PathParam("spaceName") String spaceName, @PathParam("pageName") String pageName, @PathParam("attachmentName") String attachmentName, @PathParam("attachmentVersion") String attachmentVersion) throws XWikiException { DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false); Document doc = documentInfo.getDocument(); com.xpn.xwiki.api.Attachment xwikiAttachment = doc.getAttachment(attachmentName); if (xwikiAttachment == null) { throw new WebApplicationException(Status.NOT_FOUND); } /* Get the requested version */ final com.xpn.xwiki.api.Attachment xwikiAttachmentVersion = xwikiAttachment.getAttachmentRevision(attachmentVersion); if (xwikiAttachmentVersion == null) { throw new WebApplicationException(Status.NOT_FOUND); } return Response.ok() .type(xwikiAttachment.getMimeType()) .entity(xwikiAttachmentVersion.getContent()) .build(); }
private static void fillAttachment( Attachment attachment, ObjectFactory objectFactory, URI baseUri, com.xpn.xwiki.api.Attachment xwikiAttachment, String xwikiRelativeUrl, String xwikiAbsoluteUrl, XWiki xwikiApi, Boolean withPrettyNames) { Document doc = xwikiAttachment.getDocument(); attachment.setId( String.format("%s@%s", doc.getPrefixedFullName(), xwikiAttachment.getFilename())); attachment.setName(xwikiAttachment.getFilename()); attachment.setSize(xwikiAttachment.getFilesize()); attachment.setVersion(xwikiAttachment.getVersion()); attachment.setPageId(doc.getPrefixedFullName()); attachment.setPageVersion(doc.getVersion()); attachment.setMimeType(xwikiAttachment.getMimeType()); attachment.setAuthor(xwikiAttachment.getAuthor()); if (withPrettyNames) { attachment.setAuthorName(xwikiApi.getUserName(xwikiAttachment.getAuthor(), false)); } Calendar calendar = Calendar.getInstance(); calendar.setTime(xwikiAttachment.getDate()); attachment.setDate(calendar); attachment.setXwikiRelativeUrl(xwikiRelativeUrl); attachment.setXwikiAbsoluteUrl(xwikiAbsoluteUrl); String pageUri = uri(baseUri, PageResource.class, doc.getWiki(), doc.getSpace(), doc.getName()); Link pageLink = objectFactory.createLink(); pageLink.setHref(pageUri); pageLink.setRel(Relations.PAGE); attachment.getLinks().add(pageLink); }