use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.
the class CommentVersionResourceImpl method getCommentVersion.
@Override
public Comment getCommentVersion(String wikiName, String spaceName, String pageName, String version, Integer id, Integer start, Integer number, Boolean withPrettyNames) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, version, true, false);
Document doc = documentInfo.getDocument();
Vector<com.xpn.xwiki.api.Object> xwikiComments = doc.getComments();
for (com.xpn.xwiki.api.Object xwikiComment : xwikiComments) {
if (id.equals(xwikiComment.getNumber())) {
return DomainObjectFactory.createComment(objectFactory, uriInfo.getBaseUri(), doc, xwikiComment, Utils.getXWikiApi(componentManager), withPrettyNames);
}
}
throw new WebApplicationException(Status.NOT_FOUND);
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.
the class PageTranslationsResourceImpl method getTranslations.
@Override
public Translations getTranslations(String wikiName, String spaceName, String pageName) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false);
Document doc = documentInfo.getDocument();
return DomainObjectFactory.createTranslations(objectFactory, uriInfo.getBaseUri(), doc);
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.
the class AbstractDatabaseSearchSource method search.
@Override
public List<SearchResult> search(String partialQueryString, String wikiName, String wikis, boolean hasProgrammingRights, String orderField, String order, boolean distinct, int number, int start, Boolean withPrettyNames, String className, UriInfo uriInfo) throws Exception {
XWikiContext xwikiContext = this.xcontextProvider.get();
XWiki xwikiApi = new XWiki(xwikiContext.getWiki(), xwikiContext);
if (partialQueryString == null || StringUtils.startsWithIgnoreCase(partialQueryString, "select")) {
return Collections.emptyList();
}
String queryString = resolveQuery(distinct, partialQueryString);
Query query = this.queryManager.createQuery(queryString, this.queryLanguage);
query.setLimit(number).setOffset(start);
query.setWiki(wikiName);
List<Object> queryResult = query.execute();
WikiReference wikiReference = new WikiReference(wikiName);
/* Build the result. */
List<SearchResult> result = new ArrayList<>();
for (Object object : queryResult) {
Object[] fields = (Object[]) object;
String fullName = (String) fields[0];
String language = (String) fields[3];
DocumentReference documentReference = this.resolver.resolve(fullName, wikiReference);
/* Check if the user has the right to see the found document */
if (this.authorization.hasAccess(Right.VIEW, documentReference)) {
Document doc = xwikiApi.getDocument(documentReference);
String title = doc.getDisplayTitle();
SearchResult searchResult = this.objectFactory.createSearchResult();
searchResult.setType("page");
searchResult.setId(doc.getPrefixedFullName());
searchResult.setPageFullName(doc.getFullName());
searchResult.setTitle(title);
searchResult.setWiki(wikiName);
searchResult.setSpace(doc.getSpace());
searchResult.setPageName(doc.getName());
searchResult.setVersion(doc.getVersion());
searchResult.setAuthor(doc.getAuthor());
Calendar calendar = Calendar.getInstance();
calendar.setTime(doc.getDate());
searchResult.setModified(calendar);
if (withPrettyNames) {
searchResult.setAuthorName(xwikiApi.getUserName(doc.getAuthor(), false));
}
/*
* Avoid to return object information if the user is not authenticated. This will prevent crawlers to
* retrieve information such as email addresses and passwords from user's profiles.
*/
if (StringUtils.isNotEmpty(className) && xwikiContext.getUserReference() != null) {
XWikiDocument xdocument = xwikiContext.getWiki().getDocument(doc.getDocumentReference(), xwikiContext);
BaseObject baseObject = xdocument.getObject(className);
if (baseObject != null) {
searchResult.setObject(this.modelFactory.toRestObject(uriInfo.getBaseUri(), doc, baseObject, false, false));
}
}
String pageUri;
if (StringUtils.isBlank(language)) {
pageUri = Utils.createURI(uriInfo.getBaseUri(), PageResource.class, wikiName, Utils.getSpacesHierarchy(documentReference.getLastSpaceReference()), documentReference.getName()).toString();
} else {
searchResult.setLanguage(language);
pageUri = Utils.createURI(uriInfo.getBaseUri(), PageTranslationResource.class, wikiName, Utils.getSpacesHierarchy(documentReference.getLastSpaceReference()), documentReference.getName(), language).toString();
}
Link pageLink = new Link();
pageLink.setHref(pageUri);
pageLink.setRel(Relations.PAGE);
searchResult.getLinks().add(pageLink);
result.add(searchResult);
}
}
return result;
}
use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.
the class ZipExplorerTest method testGetFileLink.
public void testGetFileLink() throws Exception {
Mock mockDocument = mock(XWikiDocument.class);
mockDocument.expects(once()).method("getAttachmentURL").will(returnValue("http://server/xwiki/bin/download/Main/Document/zipfile.zip"));
Document document = new Document((XWikiDocument) mockDocument.proxy(), null);
String link = this.plugin.getFileLink(document, "zipfile.zip", "filename", null);
Assert.assertEquals("http://server/xwiki/bin/download/Main/Document/zipfile.zip/filename", link);
}
use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.
the class ZipExplorerTest method testGetFileList.
public void testGetFileList() throws Exception {
XWikiDocument document = createXWikiDocumentWithZipFileAttachment();
List<String> entries = this.plugin.getFileList(new Document(document, null), "zipfile.zip", null);
Assert.assertEquals(2, entries.size());
Assert.assertEquals("Directory/File.txt", entries.get(0));
Assert.assertEquals("File2.txt", entries.get(1));
}
Aggregations