use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.
the class ObjectPropertyResourceImpl method updateObjectProperty.
@Override
public Response updateObjectProperty(String wikiName, String spaceName, String pageName, String className, Integer objectNumber, String propertyName, Boolean minorRevision, Property property) 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);
}
XWikiDocument xwikiDocument = Utils.getXWiki(componentManager).getDocument(doc.getDocumentReference(), Utils.getXWikiContext(componentManager));
com.xpn.xwiki.objects.BaseObject baseObject = xwikiDocument.getObject(className, objectNumber);
if (baseObject == null) {
throw new WebApplicationException(Status.NOT_FOUND);
}
baseObject.set(propertyName, property.getValue(), Utils.getXWikiContext(componentManager));
doc.save("", Boolean.TRUE.equals(minorRevision));
baseObject = xwikiDocument.getObject(className, objectNumber);
Object object = DomainObjectFactory.createObject(objectFactory, uriInfo.getBaseUri(), Utils.getXWikiContext(componentManager), doc, baseObject, false, Utils.getXWikiApi(componentManager), false);
for (Property p : object.getProperties()) {
if (p.getName().equals(propertyName)) {
return Response.status(Status.ACCEPTED).entity(p).build();
}
}
throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.
the class PageTranslationResourceImpl method getPageTranslation.
@Override
public Page getPageTranslation(String wikiName, String spaceName, String pageName, String language, Boolean withPrettyNames) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, language, null, true, false);
Document doc = documentInfo.getDocument();
return this.factory.toRestPage(this.uriInfo.getBaseUri(), this.uriInfo.getAbsolutePath(), doc, false, withPrettyNames, false, false, false);
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.
the class PageTranslationVersionResourceImpl method getPageTranslationVersion.
@Override
public Page getPageTranslationVersion(String wikiName, String spaceName, String pageName, String language, String version, Boolean withPrettyNames) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, language, version, true, false);
Document doc = documentInfo.getDocument();
return DomainObjectFactory.createPage(objectFactory, uriInfo.getBaseUri(), uriInfo.getAbsolutePath(), doc, false, Utils.getXWikiApi(componentManager), withPrettyNames);
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.
the class PageVersionResourceImpl method getPageVersion.
@Override
public Page getPageVersion(String wikiName, String spaceName, String pageName, String version, Boolean withPrettyNames) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, version, true, false);
Document doc = documentInfo.getDocument();
return DomainObjectFactory.createPage(objectFactory, uriInfo.getBaseUri(), uriInfo.getAbsolutePath(), doc, true, Utils.getXWikiApi(componentManager), withPrettyNames);
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.
the class PagesResourceImpl method getPages.
@Override
public Pages getPages(String wikiName, String spaceName, Integer start, Integer number, String parentFilterExpression, String order, Boolean withPrettyNames) throws XWikiRestException {
String database = Utils.getXWikiContext(componentManager).getWikiId();
List<String> spaces = parseSpaceSegments(spaceName);
String spaceId = Utils.getLocalSpaceId(spaces);
Pages pages = objectFactory.createPages();
try {
Utils.getXWikiContext(componentManager).setWikiId(wikiName);
Query query = ("date".equals(order)) ? queryManager.createQuery("select doc.name from Document doc where doc.space=:space and language='' order by doc.date desc", "xwql") : queryManager.getNamedQuery("getSpaceDocsName");
/* Use an explicit query to improve performance */
List<String> pageNames = query.addFilter(componentManager.<QueryFilter>getInstance(QueryFilter.class, "hidden")).bindValue("space", spaceId).setOffset(start).setLimit(number).execute();
Pattern parentFilter = null;
if (parentFilterExpression != null) {
if (parentFilterExpression.equals("null")) {
parentFilter = Pattern.compile("");
} else {
parentFilter = Pattern.compile(parentFilterExpression);
}
}
for (String pageName : pageNames) {
String pageFullName = Utils.getPageId(wikiName, spaces, pageName);
if (!Utils.getXWikiApi(componentManager).exists(pageFullName)) {
getLogger().warn("Page [{}] appears to be in space [{}] but no information is available.", pageName, spaceId);
} else {
Document doc = Utils.getXWikiApi(componentManager).getDocument(pageFullName);
/* We only add pages we have the right to access */
if (doc != null) {
boolean add = true;
Document parent = Utils.getParentDocument(doc, Utils.getXWikiApi(componentManager));
if (parentFilter != null) {
String parentId = "";
if (parent != null && !parent.isNew()) {
parentId = parent.getPrefixedFullName();
}
add = parentFilter.matcher(parentId).matches();
}
if (add) {
pages.getPageSummaries().add(DomainObjectFactory.createPageSummary(objectFactory, uriInfo.getBaseUri(), doc, Utils.getXWikiApi(componentManager), withPrettyNames));
}
}
}
}
} catch (Exception e) {
throw new XWikiRestException(e);
} finally {
Utils.getXWikiContext(componentManager).setWikiId(database);
}
return pages;
}
Aggregations