use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.
the class ObjectResourceImpl method updateObject.
@Override
public Response updateObject(String wikiName, String spaceName, String pageName, String className, Integer objectNumber, Boolean minorRevision, Object restObject) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false);
Document doc = documentInfo.getDocument();
if (!doc.hasAccessLevel("edit", Utils.getXWikiUser(componentManager))) {
throw new WebApplicationException(Status.UNAUTHORIZED);
}
com.xpn.xwiki.api.Object xwikiObject = doc.getObject(className, objectNumber);
if (xwikiObject == null) {
throw new WebApplicationException(Status.NOT_FOUND);
}
this.factory.toObject(xwikiObject, restObject);
doc.save("", Boolean.TRUE.equals(minorRevision));
BaseObject baseObject = getBaseObject(doc, className, objectNumber);
return Response.status(Status.ACCEPTED).entity(this.factory.toRestObject(this.uriInfo.getBaseUri(), doc, baseObject, false, false)).build();
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
use of com.xpn.xwiki.api.Document 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);
}
}
use of com.xpn.xwiki.api.Document 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);
}
}
use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.
the class ModifiablePageResource method putPage.
public Response putPage(DocumentInfo documentInfo, Page page, Boolean minorRevision) throws XWikiException {
Document doc = documentInfo.getDocument();
// Save the document only if there is actually something to do if if the document does not exist
if (this.factory.toDocument(doc, page) || doc.isNew()) {
doc.save(page.getComment(), Boolean.TRUE.equals(minorRevision));
page = this.factory.toRestPage(uriInfo.getBaseUri(), uriInfo.getAbsolutePath(), doc, false, false, false, false, false);
if (documentInfo.isCreated()) {
return Response.created(uriInfo.getAbsolutePath()).entity(page).build();
} else {
return Response.status(Status.ACCEPTED).entity(page).build();
}
} else {
return Response.status(Status.NOT_MODIFIED).build();
}
}
use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.
the class PageChildrenResourceImpl method getPageChildren.
@Override
public Pages getPageChildren(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();
Pages pages = objectFactory.createPages();
/* Use an explicit query to improve performance */
String queryString = "select distinct doc.fullName from XWikiDocument as doc where doc.parent = :parent order by doc.fullName asc";
List<String> childPageFullNames = queryManager.createQuery(queryString, Query.XWQL).bindValue("parent", doc.getFullName()).setOffset(start).setLimit(number).execute();
for (String childPageFullName : childPageFullNames) {
String pageId = Utils.getPageId(wikiName, childPageFullName);
if (!Utils.getXWikiApi(componentManager).exists(pageId)) {
getLogger().warn("Page [{}] appears to be in space [{}] but no information is available.", pageName, spaceName);
} else {
Document childDoc = Utils.getXWikiApi(componentManager).getDocument(pageId);
/* We only add pages we have the right to access */
if (childDoc != null) {
pages.getPageSummaries().add(DomainObjectFactory.createPageSummary(objectFactory, uriInfo.getBaseUri(), childDoc, Utils.getXWikiApi(componentManager), withPrettyNames));
}
}
}
return pages;
} catch (Exception e) {
throw new XWikiRestException(e);
}
}
Aggregations