Search in sources :

Example 66 with Document

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

the class CommentResourceImpl method getComment.

@Override
public Comment getComment(String wikiName, String spaceName, String pageName, Integer id, Integer start, Integer number, Boolean withPrettyNames) throws XWikiRestException {
    try {
        DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false);
        Document doc = documentInfo.getDocument();
        Vector<com.xpn.xwiki.api.Object> xwikiComments = doc.getComments();
        for (com.xpn.xwiki.api.Object xwikiComment : xwikiComments) {
            if (id.equals(xwikiComment.getNumber())) {
                return DomainObjectFactory.createComment(objectFactory, uriInfo.getBaseUri(), doc, xwikiComment, Utils.getXWikiApi(componentManager), withPrettyNames);
            }
        }
        throw new WebApplicationException(Status.NOT_FOUND);
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) XWikiRestException(org.xwiki.rest.XWikiRestException) Document(com.xpn.xwiki.api.Document) XWikiException(com.xpn.xwiki.XWikiException)

Example 67 with Document

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

the class CommentsResourceImpl method getComments.

@Override
public Comments getComments(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();
        Comments comments = objectFactory.createComments();
        Vector<com.xpn.xwiki.api.Object> xwikiComments = doc.getComments();
        RangeIterable<com.xpn.xwiki.api.Object> ri = new RangeIterable<com.xpn.xwiki.api.Object>(xwikiComments, start, number);
        for (com.xpn.xwiki.api.Object xwikiComment : ri) {
            comments.getComments().add(DomainObjectFactory.createComment(objectFactory, uriInfo.getBaseUri(), doc, xwikiComment, Utils.getXWikiApi(componentManager), withPrettyNames));
        }
        return comments;
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    }
}
Also used : RangeIterable(org.xwiki.rest.internal.RangeIterable) Comments(org.xwiki.rest.model.jaxb.Comments) XWikiRestException(org.xwiki.rest.XWikiRestException) Document(com.xpn.xwiki.api.Document) XWikiException(com.xpn.xwiki.XWikiException)

Example 68 with Document

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

the class CommentsResourceImpl method postComment.

@Override
public Response postComment(String wikiName, String spaceName, String pageName, Comment comment) throws XWikiRestException {
    try {
        List<String> spaces = parseSpaceSegments(spaceName);
        DocumentInfo documentInfo = getDocumentInfo(wikiName, spaces, pageName, null, null, true, true);
        Document doc = documentInfo.getDocument();
        int id = doc.createNewObject("XWiki.XWikiComments");
        com.xpn.xwiki.api.Object commentObject = doc.getObject("XWiki.XWikiComments", id);
        commentObject.set("author", Utils.getXWikiUser(componentManager));
        commentObject.set("date", new Date());
        boolean save = false;
        if (comment.getHighlight() != null) {
            commentObject.set("highlight", comment.getHighlight());
            save = true;
        }
        if (comment.getText() != null) {
            commentObject.set("comment", comment.getText());
            save = true;
        }
        if (comment.getReplyTo() != null) {
            commentObject.set("replyto", comment.getReplyTo());
        }
        if (save) {
            doc.save();
            Comment createdComment = DomainObjectFactory.createComment(objectFactory, uriInfo.getBaseUri(), doc, commentObject, Utils.getXWikiApi(componentManager), false);
            return Response.created(Utils.createURI(uriInfo.getBaseUri(), CommentResource.class, wikiName, spaces, pageName, id)).entity(createdComment).build();
        }
        return null;
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    }
}
Also used : Comment(org.xwiki.rest.model.jaxb.Comment) XWikiRestException(org.xwiki.rest.XWikiRestException) Document(com.xpn.xwiki.api.Document) Date(java.util.Date) CommentResource(org.xwiki.rest.resources.comments.CommentResource) XWikiException(com.xpn.xwiki.XWikiException)

Example 69 with Document

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

the class CommentsVersionResourceImpl method getCommentsVersion.

@Override
public Comments getCommentsVersion(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();
        Comments comments = objectFactory.createComments();
        Vector<com.xpn.xwiki.api.Object> xwikiComments = doc.getComments();
        RangeIterable<com.xpn.xwiki.api.Object> ri = new RangeIterable<com.xpn.xwiki.api.Object>(xwikiComments, start, number);
        for (com.xpn.xwiki.api.Object xwikiComment : ri) {
            comments.getComments().add(DomainObjectFactory.createComment(objectFactory, uriInfo.getBaseUri(), doc, xwikiComment, Utils.getXWikiApi(componentManager), withPrettyNames));
        }
        return comments;
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    }
}
Also used : RangeIterable(org.xwiki.rest.internal.RangeIterable) Comments(org.xwiki.rest.model.jaxb.Comments) XWikiRestException(org.xwiki.rest.XWikiRestException) Document(com.xpn.xwiki.api.Document) XWikiException(com.xpn.xwiki.XWikiException)

Example 70 with Document

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

the class SpaceResourceImpl method getSpace.

@Override
public Space getSpace(String wikiName, String spaceName) throws XWikiRestException {
    String database = Utils.getXWikiContext(componentManager).getWikiId();
    List<String> spaces = parseSpaceSegments(spaceName);
    try {
        Utils.getXWikiContext(componentManager).setWikiId(wikiName);
        String homeId = Utils.getPageId(wikiName, spaces, "WebHome");
        Document home = null;
        if (Utils.getXWikiApi(componentManager).exists(homeId)) {
            home = Utils.getXWikiApi(componentManager).getDocument(homeId);
        }
        return DomainObjectFactory.createSpace(objectFactory, uriInfo.getBaseUri(), wikiName, spaces, home);
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    } finally {
        Utils.getXWikiContext(componentManager).setWikiId(database);
    }
}
Also used : XWikiRestException(org.xwiki.rest.XWikiRestException) 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