use of org.xwiki.rest.internal.RangeIterable in project xwiki-platform by xwiki.
the class ClassesResourceImpl method getClasses.
@Override
public Classes getClasses(String wikiName, Integer start, Integer number) throws XWikiRestException {
String database = Utils.getXWikiContext(componentManager).getWikiId();
try {
getXWikiContext().setWikiId(wikiName);
List<String> classNames = Utils.getXWikiApi(componentManager).getClassList();
Collections.sort(classNames);
RangeIterable<String> ri = new RangeIterable<String>(classNames, start, number);
Classes classes = objectFactory.createClasses();
for (String className : ri) {
com.xpn.xwiki.api.Class xwikiClass = Utils.getXWikiApi(componentManager).getClass(className);
classes.getClazzs().add(this.utils.toRestClass(uriInfo.getBaseUri(), xwikiClass));
}
return classes;
} catch (XWikiException e) {
throw new XWikiRestException(e);
} finally {
Utils.getXWikiContext(componentManager).setWikiId(database);
}
}
use of org.xwiki.rest.internal.RangeIterable 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 org.xwiki.rest.internal.RangeIterable 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 org.xwiki.rest.internal.RangeIterable in project xwiki-platform by xwiki.
the class PagesForTagsResourceImpl method getTags.
@Override
public Pages getTags(String wikiName, String tagNames, Integer start, Integer number, Boolean withPrettyNames) throws XWikiRestException {
String database = Utils.getXWikiContext(componentManager).getWikiId();
try {
Pages pages = objectFactory.createPages();
Utils.getXWikiContext(componentManager).setWikiId(wikiName);
String[] tagNamesArray = tagNames.split(",");
List<String> documentNames = new ArrayList<String>();
for (String tagName : tagNamesArray) {
List<String> documentNamesForTag = getDocumentsWithTag(tagName);
/* Avoid duplicates */
for (String documentName : documentNamesForTag) {
if (!documentNames.contains(documentName)) {
documentNames.add(documentName);
}
}
}
RangeIterable<String> ri = new RangeIterable<String>(documentNames, start, number);
for (String documentName : ri) {
Document doc = Utils.getXWikiApi(componentManager).getDocument(documentName);
if (doc != null) {
pages.getPageSummaries().add(DomainObjectFactory.createPageSummary(objectFactory, uriInfo.getBaseUri(), doc, Utils.getXWikiApi(componentManager), withPrettyNames));
}
}
return pages;
} catch (Exception e) {
throw new XWikiRestException(e);
} finally {
Utils.getXWikiContext(componentManager).setWikiId(database);
}
}
Aggregations