use of org.xwiki.rest.internal.RangeIterable in project xwiki-platform by xwiki.
the class BaseAttachmentsResource method getAttachmentsForDocument.
protected Attachments getAttachmentsForDocument(Document doc, int start, int number, Boolean withPrettyNames) {
Attachments attachments = objectFactory.createAttachments();
List<com.xpn.xwiki.api.Attachment> xwikiAttachments = doc.getAttachmentList();
RangeIterable<com.xpn.xwiki.api.Attachment> ri = new RangeIterable<com.xpn.xwiki.api.Attachment>(xwikiAttachments, start, number);
for (com.xpn.xwiki.api.Attachment xwikiAttachment : ri) {
URL url = Utils.getXWikiContext(componentManager).getURLFactory().createAttachmentURL(xwikiAttachment.getFilename(), doc.getSpace(), doc.getName(), "download", null, doc.getWiki(), Utils.getXWikiContext(componentManager));
String attachmentXWikiAbsoluteUrl = url.toString();
String attachmentXWikiRelativeUrl = Utils.getXWikiContext(componentManager).getURLFactory().getURL(url, Utils.getXWikiContext(componentManager));
attachments.getAttachments().add(DomainObjectFactory.createAttachment(objectFactory, uriInfo.getBaseUri(), xwikiAttachment, attachmentXWikiRelativeUrl, attachmentXWikiAbsoluteUrl, Utils.getXWikiApi(componentManager), withPrettyNames));
}
return attachments;
}
use of org.xwiki.rest.internal.RangeIterable in project xwiki-platform by xwiki.
the class ObjectsForClassNameResourceImpl method getObjects.
@Override
public Objects getObjects(String wikiName, String spaceName, String pageName, String className, Integer start, Integer number, Boolean withPrettyNames) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false);
Document doc = documentInfo.getDocument();
Objects objects = objectFactory.createObjects();
List<com.xpn.xwiki.objects.BaseObject> objectList = getBaseObjects(doc, className);
RangeIterable<com.xpn.xwiki.objects.BaseObject> ri = new RangeIterable<com.xpn.xwiki.objects.BaseObject>(objectList, start, number);
for (com.xpn.xwiki.objects.BaseObject object : ri) {
// By deleting objects, some of them might become null, so we must check for this
if (object != null) {
objects.getObjectSummaries().add(DomainObjectFactory.createObjectSummary(objectFactory, uriInfo.getBaseUri(), Utils.getXWikiContext(componentManager), doc, object, false, Utils.getXWikiApi(componentManager), withPrettyNames));
}
}
return objects;
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
use of org.xwiki.rest.internal.RangeIterable in project xwiki-platform by xwiki.
the class ObjectsAtPageVersionResourceImpl method getObjects.
@Override
public Objects getObjects(String wikiName, String spaceName, String pageName, String version, Integer start, Integer number, Boolean withPrettyNames) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, version, true, false);
Document doc = documentInfo.getDocument();
Objects objects = objectFactory.createObjects();
List<com.xpn.xwiki.objects.BaseObject> objectList = getBaseObjects(doc);
RangeIterable<com.xpn.xwiki.objects.BaseObject> ri = new RangeIterable<com.xpn.xwiki.objects.BaseObject>(objectList, start, number);
for (com.xpn.xwiki.objects.BaseObject object : ri) {
/* By deleting objects, some of them might become null, so we must check for this */
if (object != null) {
objects.getObjectSummaries().add(DomainObjectFactory.createObjectSummary(objectFactory, uriInfo.getBaseUri(), Utils.getXWikiContext(componentManager), doc, object, true, Utils.getXWikiApi(componentManager), withPrettyNames));
}
}
return objects;
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
use of org.xwiki.rest.internal.RangeIterable in project xwiki-platform by xwiki.
the class ObjectsResourceImpl method getObjects.
@Override
public Objects getObjects(String wikiName, String spaceName, String pageName, Integer start, Integer number, Boolean withPrettyNames) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false);
Document doc = documentInfo.getDocument();
Objects objects = objectFactory.createObjects();
List<BaseObject> objectList = getBaseObjects(doc);
RangeIterable<BaseObject> ri = new RangeIterable<BaseObject>(objectList, start, number);
for (BaseObject object : ri) {
/* By deleting objects, some of them might become null, so we must check for this */
if (object != null) {
objects.getObjectSummaries().add(DomainObjectFactory.createObjectSummary(objectFactory, uriInfo.getBaseUri(), Utils.getXWikiContext(componentManager), doc, object, false, Utils.getXWikiApi(componentManager), withPrettyNames));
}
}
return objects;
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
use of org.xwiki.rest.internal.RangeIterable 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);
}
}
Aggregations