use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.
the class DefaultAttachmentConverter method convert.
@Override
public List<Attachment> convert(List<XWikiAttachment> attachments) {
XWikiContext xwikiContext = getXWikiContext();
List<Attachment> attachmentList = new ArrayList<>();
for (XWikiAttachment attachment : attachments) {
attachmentList.add(new Attachment(new Document(attachment.getDoc(), xwikiContext), attachment, xwikiContext));
}
return attachmentList;
}
use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.
the class ModelFactory method toRestAttachment.
public Attachment toRestAttachment(URI baseUri, com.xpn.xwiki.api.Attachment xwikiAttachment, String xwikiRelativeUrl, String xwikiAbsoluteUrl, Boolean withPrettyNames, boolean versionURL) {
Attachment attachment = this.objectFactory.createAttachment();
Document doc = xwikiAttachment.getDocument();
attachment.setId(String.format("%s@%s", doc.getPrefixedFullName(), xwikiAttachment.getFilename()));
attachment.setName(xwikiAttachment.getFilename());
attachment.setSize(xwikiAttachment.getFilesize());
attachment.setVersion(xwikiAttachment.getVersion());
attachment.setPageId(doc.getPrefixedFullName());
attachment.setPageVersion(doc.getVersion());
attachment.setMimeType(xwikiAttachment.getMimeType());
attachment.setAuthor(xwikiAttachment.getAuthor());
if (withPrettyNames) {
XWikiContext xcontext = xcontextProvider.get();
attachment.setAuthorName(xcontext.getWiki().getUserName(xwikiAttachment.getAuthor(), null, false, xcontext));
}
Calendar calendar = Calendar.getInstance();
calendar.setTime(xwikiAttachment.getDate());
attachment.setDate(calendar);
attachment.setXwikiRelativeUrl(xwikiRelativeUrl);
attachment.setXwikiAbsoluteUrl(xwikiAbsoluteUrl);
String pageUri = Utils.createURI(baseUri, PageResource.class, doc.getWiki(), Utils.getSpacesFromSpaceId(doc.getSpace()), doc.getName()).toString();
Link pageLink = objectFactory.createLink();
pageLink.setHref(pageUri);
pageLink.setRel(Relations.PAGE);
attachment.getLinks().add(pageLink);
String attachmentUri;
if (versionURL) {
attachmentUri = Utils.createURI(baseUri, AttachmentVersionResource.class, doc.getWiki(), Utils.getSpacesFromSpaceId(doc.getSpace()), doc.getName(), xwikiAttachment.getFilename(), xwikiAttachment.getVersion()).toString();
} else {
attachmentUri = Utils.createURI(baseUri, AttachmentResource.class, doc.getWiki(), Utils.getSpacesFromSpaceId(doc.getSpace()), doc.getName(), xwikiAttachment.getFilename()).toString();
}
Link attachmentLink = objectFactory.createLink();
attachmentLink.setHref(attachmentUri);
attachmentLink.setRel(Relations.ATTACHMENT_DATA);
attachment.getLinks().add(attachmentLink);
return attachment;
}
use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.
the class Utils method getPageFullName.
/**
* Get the page full name given its components.
*
* @param wikiName
* @param spaces
* @param pageName
* @return The page full name.
*/
public static String getPageFullName(String wikiName, List<String> spaces, String pageName) {
XWikiDocument xwikiDocument = new XWikiDocument(new DocumentReference(wikiName, spaces, pageName));
Document document = new Document(xwikiDocument, null);
return document.getFullName();
}
use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.
the class Utils method getObjectId.
/**
* Get the object id given its components.
*
* @param wikiName
* @param spaces
* @param pageName
* @param className
* @param objectNumber
* @return The object id.
*/
public static String getObjectId(String wikiName, List<String> spaces, String pageName, String className, int objectNumber) {
XWikiDocument xwikiDocument = new XWikiDocument(new DocumentReference(wikiName, spaces, pageName));
Document document = new Document(xwikiDocument, null);
return String.format("%s:%s[%d]", document.getPrefixedFullName(), className, objectNumber);
}
use of com.xpn.xwiki.api.Document in project xwiki-platform by xwiki.
the class WatchListJobManager method getJobs.
/**
* Get the list of available jobs (list of {@link XWikiDocument}).
*
* @param context Context of the request
* @return the list of available jobs
*/
public List<Document> getJobs(XWikiContext context) {
String oriDatabase = context.getWikiId();
List<Object> params = new ArrayList<Object>();
List<Document> results = new ArrayList<Document>();
try {
context.setWikiId(context.getMainXWiki());
params.add(WATCHLIST_JOB_CLASS);
List<String> docNames = context.getWiki().getStore().searchDocumentsNames(", BaseObject obj where doc.fullName=obj.name and obj.className=?", 0, 0, params, context);
for (String docName : docNames) {
XWikiDocument doc = context.getWiki().getDocument(docName, context);
results.add(new Document(doc, context));
}
} catch (Exception e) {
LOGGER.error("error getting list of available watchlist jobs", e);
} finally {
context.setWikiId(oriDatabase);
}
return results;
}
Aggregations