use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.
the class PageResourceImpl method getPage.
@Override
public Page getPage(String wikiName, String spaceName, String pageName, Boolean withPrettyNames, Boolean withObjects, Boolean withXClass, Boolean withAttachments) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false);
Document doc = documentInfo.getDocument();
URI baseUri = uriInfo.getBaseUri();
Page page = this.factory.toRestPage(baseUri, uriInfo.getAbsolutePath(), doc, false, withPrettyNames, withObjects, withXClass, withAttachments);
return page;
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.
the class AttachmentHistoryResourceImpl method getAttachmentHistory.
@Override
public Attachments getAttachmentHistory(String wikiName, String spaceName, String pageName, String attachmentName, Integer start, Integer number) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false);
Document doc = documentInfo.getDocument();
final com.xpn.xwiki.api.Attachment xwikiAttachment = doc.getAttachment(attachmentName);
if (xwikiAttachment == null) {
throw new WebApplicationException(Status.NOT_FOUND);
}
Attachments attachments = new Attachments();
Version[] versions = xwikiAttachment.getVersions();
List<Version> versionList = new ArrayList<Version>();
for (Version version : versions) {
versionList.add(version);
}
RangeIterable<Version> ri = new RangeIterable<Version>(versionList, start, number);
for (Version version : ri) {
com.xpn.xwiki.api.Attachment xwikiAttachmentAtVersion = xwikiAttachment.getAttachmentRevision(version.toString());
URL url = Utils.getXWikiContext(componentManager).getURLFactory().createAttachmentRevisionURL(attachmentName, spaceName, doc.getName(), version.toString(), null, wikiName, Utils.getXWikiContext(componentManager));
String attachmentXWikiAbsoluteUrl = url.toString();
String attachmentXWikiRelativeUrl = Utils.getXWikiContext(componentManager).getURLFactory().getURL(url, Utils.getXWikiContext(componentManager));
attachments.getAttachments().add(DomainObjectFactory.createAttachmentAtVersion(objectFactory, uriInfo.getBaseUri(), xwikiAttachmentAtVersion, attachmentXWikiRelativeUrl, attachmentXWikiAbsoluteUrl, Utils.getXWikiApi(componentManager), false));
}
return attachments;
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.
the class AttachmentResourceImpl method putAttachment.
@Override
public Response putAttachment(String wikiName, String spaceName, String pageName, String attachmentName, byte[] content) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, true);
Document doc = documentInfo.getDocument();
if (!doc.hasAccessLevel("edit", Utils.getXWikiUser(componentManager))) {
throw new WebApplicationException(Status.UNAUTHORIZED);
}
/* Attach the file */
AttachmentInfo attachmentInfo = storeAttachment(doc, attachmentName, content);
if (attachmentInfo.isAlreadyExisting()) {
return Response.status(Status.ACCEPTED).entity(attachmentInfo.getAttachment()).build();
} else {
return Response.created(uriInfo.getAbsolutePath()).entity(attachmentInfo.getAttachment()).build();
}
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.
the class AttachmentResourceImpl method deleteAttachment.
@Override
public void deleteAttachment(String wikiName, String spaceName, String pageName, String attachmentName) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, true);
Document doc = documentInfo.getDocument();
if (!doc.hasAccessLevel("edit", Utils.getXWikiUser(componentManager))) {
throw new WebApplicationException(Status.UNAUTHORIZED);
}
com.xpn.xwiki.api.Attachment xwikiAttachment = doc.getAttachment(attachmentName);
if (xwikiAttachment == null) {
throw new WebApplicationException(Status.NOT_FOUND);
}
XWikiDocument xwikiDocument = Utils.getXWiki(componentManager).getDocument(doc.getDocumentReference(), Utils.getXWikiContext(componentManager));
XWikiAttachment baseXWikiAttachment = xwikiDocument.getAttachment(attachmentName);
xwikiDocument.removeAttachment(baseXWikiAttachment);
Utils.getXWiki(componentManager).saveDocument(xwikiDocument, "Deleted attachment [" + baseXWikiAttachment.getFilename() + "]", Utils.getXWikiContext(componentManager));
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.
the class AttachmentVersionResourceImpl method getAttachment.
@Override
public Response getAttachment(String wikiName, String spaceName, String pageName, String attachmentName, String attachmentVersion) throws XWikiRestException {
try {
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();
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
Aggregations