use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.
the class AttachmentVersionResourceImpl method getAttachment.
@Override
public Response getAttachment(String wikiName, String spaceName, String pageName, String attachmentName, String attachmentVersion) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false);
Document doc = documentInfo.getDocument();
com.xpn.xwiki.api.Attachment xwikiAttachment = doc.getAttachment(attachmentName);
if (xwikiAttachment == null) {
throw new WebApplicationException(Status.NOT_FOUND);
}
/* Get the requested version */
final com.xpn.xwiki.api.Attachment xwikiAttachmentVersion = xwikiAttachment.getAttachmentRevision(attachmentVersion);
if (xwikiAttachmentVersion == null) {
throw new WebApplicationException(Status.NOT_FOUND);
}
return Response.ok().type(xwikiAttachment.getMimeType()).entity(xwikiAttachmentVersion.getContent()).build();
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.
the class AbstractClassPropertyValuesProvider method getPropertyDefinition.
@SuppressWarnings("unchecked")
protected T getPropertyDefinition(ClassPropertyReference propertyReference) throws XWikiRestException {
try {
XWikiContext xcontext = this.xcontextProvider.get();
PropertyInterface property = xcontext.getWiki().getDocument(propertyReference, xcontext).getXClass().get(propertyReference.getName());
if (property == null) {
throw new XWikiRestException(String.format("Property [%s] not found.", this.entityReferenceSerializer.serialize(propertyReference)));
} else if (getPropertyType().isInstance(property)) {
return (T) property;
} else {
throw new XWikiRestException(String.format("This [%s] is not a [%s] property.", this.entityReferenceSerializer.serialize(propertyReference), getPropertyType().getSimpleName()));
}
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.
the class ClassPropertiesResourceImpl method getClassProperties.
@Override
public Properties getClassProperties(String wikiName, String className) throws XWikiRestException {
String database = Utils.getXWikiContext(componentManager).getWikiId();
try {
Utils.getXWikiContext(componentManager).setWikiId(wikiName);
com.xpn.xwiki.api.Class xwikiClass = Utils.getXWikiApi(componentManager).getClass(className);
if (xwikiClass == null) {
throw new WebApplicationException(Status.NOT_FOUND);
}
Class clazz = DomainObjectFactory.createClass(objectFactory, uriInfo.getBaseUri(), wikiName, xwikiClass);
Properties properties = objectFactory.createProperties();
properties.getProperties().addAll(clazz.getProperties());
String classUri = Utils.createURI(uriInfo.getBaseUri(), ClassResource.class, wikiName, xwikiClass.getName()).toString();
Link classLink = objectFactory.createLink();
classLink.setHref(classUri);
classLink.setRel(Relations.CLASS);
properties.getLinks().add(classLink);
return properties;
} catch (XWikiException e) {
throw new XWikiRestException(e);
} finally {
Utils.getXWikiContext(componentManager).setWikiId(database);
}
}
use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.
the class ClassResourceImpl method getClass.
@Override
public Class getClass(String wikiName, String className) throws XWikiRestException {
String database = Utils.getXWikiContext(componentManager).getWikiId();
try {
Utils.getXWikiContext(componentManager).setWikiId(wikiName);
com.xpn.xwiki.api.Class xwikiClass = Utils.getXWikiApi(componentManager).getClass(className);
if (xwikiClass == null) {
throw new WebApplicationException(Status.NOT_FOUND);
}
return this.utils.toRestClass(uriInfo.getBaseUri(), xwikiClass);
} catch (XWikiException e) {
throw new XWikiRestException(e);
} finally {
Utils.getXWikiContext(componentManager).setWikiId(database);
}
}
use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.
the class ClassesResourceImpl method getClasses.
@Override
public Classes getClasses(String wikiName, Integer start, Integer number) throws XWikiRestException {
String database = Utils.getXWikiContext(componentManager).getWikiId();
try {
getXWikiContext().setWikiId(wikiName);
List<String> classNames = Utils.getXWikiApi(componentManager).getClassList();
Collections.sort(classNames);
RangeIterable<String> ri = new RangeIterable<String>(classNames, start, number);
Classes classes = objectFactory.createClasses();
for (String className : ri) {
com.xpn.xwiki.api.Class xwikiClass = Utils.getXWikiApi(componentManager).getClass(className);
classes.getClazzs().add(this.utils.toRestClass(uriInfo.getBaseUri(), xwikiClass));
}
return classes;
} catch (XWikiException e) {
throw new XWikiRestException(e);
} finally {
Utils.getXWikiContext(componentManager).setWikiId(database);
}
}
Aggregations