use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.
the class SpacesResourceImpl method getSpaces.
@Override
public Spaces getSpaces(String wikiName, Integer start, Integer number) throws XWikiRestException {
Spaces spaces = objectFactory.createSpaces();
try {
List<String> spaceNames = queryManager.getNamedQuery("getSpaces").addFilter(componentManager.<QueryFilter>getInstance(QueryFilter.class, "hidden")).setOffset(start).setLimit(number).setWiki(wikiName).execute();
for (String spaceName : spaceNames) {
List<String> spaceList = Utils.getSpacesFromSpaceId(spaceName);
String homeId = Utils.getPageId(wikiName, spaceList, "WebHome");
Document home = null;
XWiki xwikiApi = Utils.getXWikiApi(componentManager);
if (xwikiApi.hasAccessLevel("view", homeId)) {
if (xwikiApi.exists(homeId)) {
home = Utils.getXWikiApi(componentManager).getDocument(homeId);
}
spaces.getSpaces().add(DomainObjectFactory.createSpace(objectFactory, uriInfo.getBaseUri(), wikiName, spaceList, home));
}
}
} catch (Exception e) {
throw new XWikiRestException(e);
}
return spaces;
}
use of com.xpn.xwiki.api.Document 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);
}
}
use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.
the class ObjectAtPageVersionResourceImpl method getObject.
@Override
public Object getObject(String wikiName, String spaceName, String pageName, String version, String className, Integer objectNumber, Boolean withPrettyName) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, version, true, false);
Document doc = documentInfo.getDocument();
XWikiDocument xwikiDocument = Utils.getXWiki(componentManager).getDocument(doc.getDocumentReference(), Utils.getXWikiContext(componentManager));
xwikiDocument = Utils.getXWiki(componentManager).getDocument(xwikiDocument, doc.getVersion(), Utils.getXWikiContext(componentManager));
com.xpn.xwiki.objects.BaseObject baseObject = xwikiDocument.getObject(className, objectNumber);
if (baseObject == null) {
throw new WebApplicationException(Status.NOT_FOUND);
}
return DomainObjectFactory.createObject(objectFactory, uriInfo.getBaseUri(), Utils.getXWikiContext(componentManager), doc, baseObject, true, Utils.getXWikiApi(componentManager), withPrettyName);
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.
the class ObjectPropertiesAtPageVersionResourceImpl method getObjectProperties.
@Override
public Properties getObjectProperties(String wikiName, String spaceName, String pageName, String version, String className, Integer objectNumber, Boolean withPrettyNames) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, version, true, false);
Document doc = documentInfo.getDocument();
XWikiDocument xwikiDocument = Utils.getXWiki(componentManager).getDocument(doc.getDocumentReference(), Utils.getXWikiContext(componentManager));
xwikiDocument = Utils.getXWiki(componentManager).getDocument(xwikiDocument, doc.getVersion(), Utils.getXWikiContext(componentManager));
com.xpn.xwiki.objects.BaseObject baseObject = xwikiDocument.getObject(className, objectNumber);
if (baseObject == null) {
throw new WebApplicationException(Status.NOT_FOUND);
}
Object object = DomainObjectFactory.createObject(objectFactory, uriInfo.getBaseUri(), Utils.getXWikiContext(componentManager), doc, baseObject, true, Utils.getXWikiApi(componentManager), withPrettyNames);
Properties properties = objectFactory.createProperties();
properties.getProperties().addAll(object.getProperties());
String objectUri = Utils.createURI(uriInfo.getBaseUri(), ObjectAtPageVersionResource.class, doc.getWiki(), Utils.getSpacesFromSpaceId(doc.getSpace()), doc.getName(), version, object.getClassName(), object.getNumber()).toString();
Link objectLink = objectFactory.createLink();
objectLink.setHref(objectUri);
objectLink.setRel(Relations.OBJECT);
properties.getLinks().add(objectLink);
return properties;
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.
the class ObjectPropertyResourceImpl method getObjectProperty.
@Override
public Property getObjectProperty(String wikiName, String spaceName, String pageName, String className, Integer objectNumber, String propertyName, Boolean withPrettyNames) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false);
Document doc = documentInfo.getDocument();
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);
}
Object object = DomainObjectFactory.createObject(objectFactory, uriInfo.getBaseUri(), Utils.getXWikiContext(componentManager), doc, baseObject, false, Utils.getXWikiApi(componentManager), withPrettyNames);
for (Property property : object.getProperties()) {
if (property.getName().equals(propertyName)) {
String objectUri = Utils.createURI(uriInfo.getBaseUri(), ObjectResource.class, doc.getWiki(), Utils.getSpacesFromSpaceId(doc.getSpace()), doc.getName(), object.getClassName(), object.getNumber()).toString();
Link objectLink = objectFactory.createLink();
objectLink.setHref(objectUri);
objectLink.setRel(Relations.OBJECT);
property.getLinks().add(objectLink);
return property;
}
}
throw new WebApplicationException(Status.NOT_FOUND);
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
Aggregations