use of org.xwiki.rest.XWikiRestException 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 org.xwiki.rest.XWikiRestException 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 org.xwiki.rest.XWikiRestException 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;
}
use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.
the class ModificationsResourceImpl method getModifications.
@Override
public History getModifications(String wikiName, Integer start, Integer number, String order, Long ts, Boolean withPrettyNames) throws XWikiRestException {
try {
History history = new History();
String query = String.format("select doc.space, doc.name, doc.language, rcs.id, rcs.date, rcs.author," + " rcs.comment from XWikiRCSNodeInfo as rcs, XWikiDocument as doc where rcs.id.docId = doc.id and" + " rcs.date > :date order by rcs.date %s, rcs.id.version1 %s, rcs.id.version2 %s", order, order, order);
List<Object> queryResult = null;
queryResult = queryManager.createQuery(query, Query.XWQL).bindValue("date", new Date(ts)).setLimit(number).setOffset(start).setWiki(wikiName).execute();
for (Object object : queryResult) {
Object[] fields = (Object[]) object;
String spaceId = (String) fields[0];
List<String> spaces = Utils.getSpacesFromSpaceId(spaceId);
String pageName = (String) fields[1];
String language = (String) fields[2];
if (language.equals("")) {
language = null;
}
XWikiRCSNodeId nodeId = (XWikiRCSNodeId) fields[3];
Timestamp timestamp = (Timestamp) fields[4];
Date modified = new Date(timestamp.getTime());
String modifier = (String) fields[5];
String comment = (String) fields[6];
HistorySummary historySummary = DomainObjectFactory.createHistorySummary(objectFactory, uriInfo.getBaseUri(), wikiName, spaces, pageName, language, nodeId.getVersion(), modifier, modified, comment, Utils.getXWikiApi(componentManager), withPrettyNames);
history.getHistorySummaries().add(historySummary);
}
return history;
} catch (QueryException e) {
throw new XWikiRestException(e);
}
}
use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.
the class AttachmentAtPageVersionResourceImpl method getAttachment.
@Override
public Response getAttachment(String wikiName, String spaceName, String pageName, String version, String attachmentName) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, version, true, false);
Document doc = documentInfo.getDocument();
final com.xpn.xwiki.api.Attachment xwikiAttachment = doc.getAttachment(attachmentName);
if (xwikiAttachment == null) {
throw new WebApplicationException(Status.NOT_FOUND);
}
return Response.ok().type(xwikiAttachment.getMimeType()).entity(xwikiAttachment.getContent()).build();
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
Aggregations