Search in sources :

Example 1 with Document

use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.

the class DefaultAttachmentConverter method convert.

@Override
public List<Attachment> convert(List<XWikiAttachment> attachments) {
    XWikiContext xwikiContext = getXWikiContext();
    List<Attachment> attachmentList = new ArrayList<>();
    for (XWikiAttachment attachment : attachments) {
        attachmentList.add(new Attachment(new Document(attachment.getDoc(), xwikiContext), attachment, xwikiContext));
    }
    return attachmentList;
}
Also used : ArrayList(java.util.ArrayList) XWikiContext(com.xpn.xwiki.XWikiContext) Attachment(com.xpn.xwiki.api.Attachment) XWikiAttachment(com.xpn.xwiki.doc.XWikiAttachment) XWikiAttachment(com.xpn.xwiki.doc.XWikiAttachment) Document(com.xpn.xwiki.api.Document)

Example 2 with Document

use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.

the class ModelFactory method toRestAttachment.

public Attachment toRestAttachment(URI baseUri, com.xpn.xwiki.api.Attachment xwikiAttachment, String xwikiRelativeUrl, String xwikiAbsoluteUrl, Boolean withPrettyNames, boolean versionURL) {
    Attachment attachment = this.objectFactory.createAttachment();
    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) {
        XWikiContext xcontext = xcontextProvider.get();
        attachment.setAuthorName(xcontext.getWiki().getUserName(xwikiAttachment.getAuthor(), null, false, xcontext));
    }
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(xwikiAttachment.getDate());
    attachment.setDate(calendar);
    attachment.setXwikiRelativeUrl(xwikiRelativeUrl);
    attachment.setXwikiAbsoluteUrl(xwikiAbsoluteUrl);
    String pageUri = Utils.createURI(baseUri, PageResource.class, doc.getWiki(), Utils.getSpacesFromSpaceId(doc.getSpace()), doc.getName()).toString();
    Link pageLink = objectFactory.createLink();
    pageLink.setHref(pageUri);
    pageLink.setRel(Relations.PAGE);
    attachment.getLinks().add(pageLink);
    String attachmentUri;
    if (versionURL) {
        attachmentUri = Utils.createURI(baseUri, AttachmentVersionResource.class, doc.getWiki(), Utils.getSpacesFromSpaceId(doc.getSpace()), doc.getName(), xwikiAttachment.getFilename(), xwikiAttachment.getVersion()).toString();
    } else {
        attachmentUri = Utils.createURI(baseUri, AttachmentResource.class, doc.getWiki(), Utils.getSpacesFromSpaceId(doc.getSpace()), doc.getName(), xwikiAttachment.getFilename()).toString();
    }
    Link attachmentLink = objectFactory.createLink();
    attachmentLink.setHref(attachmentUri);
    attachmentLink.setRel(Relations.ATTACHMENT_DATA);
    attachment.getLinks().add(attachmentLink);
    return attachment;
}
Also used : PageResource(org.xwiki.rest.resources.pages.PageResource) Calendar(java.util.Calendar) XWikiContext(com.xpn.xwiki.XWikiContext) Attachment(org.xwiki.rest.model.jaxb.Attachment) Document(com.xpn.xwiki.api.Document) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) Link(org.xwiki.rest.model.jaxb.Link)

Example 3 with Document

use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.

the class Utils method getPageFullName.

/**
 * Get the page full name given its components.
 *
 * @param wikiName
 * @param spaces
 * @param pageName
 * @return The page full name.
 */
public static String getPageFullName(String wikiName, List<String> spaces, String pageName) {
    XWikiDocument xwikiDocument = new XWikiDocument(new DocumentReference(wikiName, spaces, pageName));
    Document document = new Document(xwikiDocument, null);
    return document.getFullName();
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) Document(com.xpn.xwiki.api.Document) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 4 with Document

use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.

the class Utils method getObjectId.

/**
 * Get the object id given its components.
 *
 * @param wikiName
 * @param spaces
 * @param pageName
 * @param className
 * @param objectNumber
 * @return The object id.
 */
public static String getObjectId(String wikiName, List<String> spaces, String pageName, String className, int objectNumber) {
    XWikiDocument xwikiDocument = new XWikiDocument(new DocumentReference(wikiName, spaces, pageName));
    Document document = new Document(xwikiDocument, null);
    return String.format("%s:%s[%d]", document.getPrefixedFullName(), className, objectNumber);
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) Document(com.xpn.xwiki.api.Document) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 5 with Document

use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.

the class WatchListJobManager method getJobs.

/**
 * Get the list of available jobs (list of {@link XWikiDocument}).
 *
 * @param context Context of the request
 * @return the list of available jobs
 */
public List<Document> getJobs(XWikiContext context) {
    String oriDatabase = context.getWikiId();
    List<Object> params = new ArrayList<Object>();
    List<Document> results = new ArrayList<Document>();
    try {
        context.setWikiId(context.getMainXWiki());
        params.add(WATCHLIST_JOB_CLASS);
        List<String> docNames = context.getWiki().getStore().searchDocumentsNames(", BaseObject obj where doc.fullName=obj.name and obj.className=?", 0, 0, params, context);
        for (String docName : docNames) {
            XWikiDocument doc = context.getWiki().getDocument(docName, context);
            results.add(new Document(doc, context));
        }
    } catch (Exception e) {
        LOGGER.error("error getting list of available watchlist jobs", e);
    } finally {
        context.setWikiId(oriDatabase);
    }
    return results;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ArrayList(java.util.ArrayList) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) Document(com.xpn.xwiki.api.Document) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

Document (com.xpn.xwiki.api.Document)97 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)60 XWikiException (com.xpn.xwiki.XWikiException)41 XWikiRestException (org.xwiki.rest.XWikiRestException)40 DocumentReference (org.xwiki.model.reference.DocumentReference)37 BaseObject (com.xpn.xwiki.objects.BaseObject)24 Test (org.junit.Test)23 WebApplicationException (javax.ws.rs.WebApplicationException)22 ArrayList (java.util.ArrayList)16 Attachment (com.xpn.xwiki.api.Attachment)14 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)14 Vector (java.util.Vector)12 Link (org.xwiki.rest.model.jaxb.Link)10 XWikiContext (com.xpn.xwiki.XWikiContext)9 AbstractComponentTest (com.celements.common.test.AbstractComponentTest)7 Date (java.util.Date)7 XWiki (com.xpn.xwiki.api.XWiki)6 RangeIterable (org.xwiki.rest.internal.RangeIterable)6 Object (org.xwiki.rest.model.jaxb.Object)6 XWiki (com.xpn.xwiki.XWiki)5