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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations