Search in sources :

Example 76 with Document

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);
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) WebApplicationException(javax.ws.rs.WebApplicationException) XWikiRestException(org.xwiki.rest.XWikiRestException) Object(org.xwiki.rest.model.jaxb.Object) Document(com.xpn.xwiki.api.Document) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) Property(org.xwiki.rest.model.jaxb.Property) XWikiException(com.xpn.xwiki.XWikiException)

Example 77 with Document

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);
    }
}
Also used : XWikiRestException(org.xwiki.rest.XWikiRestException) Document(com.xpn.xwiki.api.Document) XWikiException(com.xpn.xwiki.XWikiException)

Example 78 with Document

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);
    }
}
Also used : XWikiRestException(org.xwiki.rest.XWikiRestException) Document(com.xpn.xwiki.api.Document) XWikiException(com.xpn.xwiki.XWikiException)

Example 79 with Document

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);
    }
}
Also used : XWikiRestException(org.xwiki.rest.XWikiRestException) Document(com.xpn.xwiki.api.Document) XWikiException(com.xpn.xwiki.XWikiException)

Example 80 with Document

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;
}
Also used : Pages(org.xwiki.rest.model.jaxb.Pages) Pattern(java.util.regex.Pattern) QueryFilter(org.xwiki.query.QueryFilter) Query(org.xwiki.query.Query) XWikiRestException(org.xwiki.rest.XWikiRestException) Document(com.xpn.xwiki.api.Document) XWikiRestException(org.xwiki.rest.XWikiRestException)

Aggregations

Document (com.xpn.xwiki.api.Document)97 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)60 XWikiException (com.xpn.xwiki.XWikiException)41 XWikiRestException (org.xwiki.rest.XWikiRestException)40 DocumentReference (org.xwiki.model.reference.DocumentReference)37 BaseObject (com.xpn.xwiki.objects.BaseObject)24 Test (org.junit.Test)23 WebApplicationException (javax.ws.rs.WebApplicationException)22 ArrayList (java.util.ArrayList)16 Attachment (com.xpn.xwiki.api.Attachment)14 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)14 Vector (java.util.Vector)12 Link (org.xwiki.rest.model.jaxb.Link)10 XWikiContext (com.xpn.xwiki.XWikiContext)9 AbstractComponentTest (com.celements.common.test.AbstractComponentTest)7 Date (java.util.Date)7 XWiki (com.xpn.xwiki.api.XWiki)6 RangeIterable (org.xwiki.rest.internal.RangeIterable)6 Object (org.xwiki.rest.model.jaxb.Object)6 XWiki (com.xpn.xwiki.XWiki)5