Search in sources :

Example 1 with RangeIterable

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;
}
Also used : RangeIterable(org.xwiki.rest.internal.RangeIterable) XWikiAttachment(com.xpn.xwiki.doc.XWikiAttachment) Attachment(org.xwiki.rest.model.jaxb.Attachment) Attachments(org.xwiki.rest.model.jaxb.Attachments) URL(java.net.URL)

Example 2 with RangeIterable

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);
    }
}
Also used : RangeIterable(org.xwiki.rest.internal.RangeIterable) XWikiRestException(org.xwiki.rest.XWikiRestException) Document(com.xpn.xwiki.api.Document) Objects(org.xwiki.rest.model.jaxb.Objects) XWikiException(com.xpn.xwiki.XWikiException)

Example 3 with RangeIterable

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);
    }
}
Also used : RangeIterable(org.xwiki.rest.internal.RangeIterable) XWikiRestException(org.xwiki.rest.XWikiRestException) Document(com.xpn.xwiki.api.Document) Objects(org.xwiki.rest.model.jaxb.Objects) XWikiException(com.xpn.xwiki.XWikiException)

Example 4 with RangeIterable

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);
    }
}
Also used : RangeIterable(org.xwiki.rest.internal.RangeIterable) XWikiRestException(org.xwiki.rest.XWikiRestException) Objects(org.xwiki.rest.model.jaxb.Objects) Document(com.xpn.xwiki.api.Document) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiException(com.xpn.xwiki.XWikiException) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 5 with RangeIterable

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);
    }
}
Also used : RangeIterable(org.xwiki.rest.internal.RangeIterable) WebApplicationException(javax.ws.rs.WebApplicationException) XWikiRestException(org.xwiki.rest.XWikiRestException) ArrayList(java.util.ArrayList) Document(com.xpn.xwiki.api.Document) Attachments(org.xwiki.rest.model.jaxb.Attachments) URL(java.net.URL) Version(org.suigeneris.jrcs.rcs.Version) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

RangeIterable (org.xwiki.rest.internal.RangeIterable)9 XWikiRestException (org.xwiki.rest.XWikiRestException)8 XWikiException (com.xpn.xwiki.XWikiException)7 Document (com.xpn.xwiki.api.Document)7 Objects (org.xwiki.rest.model.jaxb.Objects)3 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Attachments (org.xwiki.rest.model.jaxb.Attachments)2 Comments (org.xwiki.rest.model.jaxb.Comments)2 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 BaseObject (com.xpn.xwiki.objects.BaseObject)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Version (org.suigeneris.jrcs.rcs.Version)1 QueryException (org.xwiki.query.QueryException)1 Attachment (org.xwiki.rest.model.jaxb.Attachment)1 Classes (org.xwiki.rest.model.jaxb.Classes)1 Pages (org.xwiki.rest.model.jaxb.Pages)1