public Property getProperty(Object object, String propertyName) { for (Property property : object.getProperties()) { if (property.getName().equals(propertyName)) { return property; } } return null; }
@GET public Property getClassProperty( @PathParam("wikiName") String wikiName, @PathParam("className") String className, @PathParam("propertyName") String propertyName) throws XWikiException { String database = Utils.getXWikiContext(componentManager).getDatabase(); try { Utils.getXWikiContext(componentManager).setDatabase(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); for (Property property : clazz.getProperties()) { if (property.getName().equals(propertyName)) { String classUri = UriBuilder.fromUri(uriInfo.getBaseUri()) .path(ClassResource.class) .build(wikiName, xwikiClass.getName()) .toString(); Link classLink = objectFactory.createLink(); classLink.setHref(classUri); classLink.setRel(Relations.CLASS); property.getLinks().add(classLink); return property; } } throw new WebApplicationException(Status.NOT_FOUND); } finally { Utils.getXWiki(componentManager).setDatabase(database); } }
@Override public Property getObjectProperty( String wikiName, String spaceName, String pageName, String version, String className, Integer objectNumber, String propertyName, Boolean withPrettyNames) throws XWikiRestException { try { DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, version, true, false); Document doc = documentInfo.getDocument(); XWikiDocument xwikiDocument = Utils.getXWiki(componentManager) .getDocument(doc.getPrefixedFullName(), Utils.getXWikiContext(componentManager)); xwikiDocument = Utils.getXWiki(componentManager) .getDocument( xwikiDocument, doc.getVersion(), Utils.getXWikiContext(componentManager)); com.xpn.xwiki.objects.BaseObject baseObject = xwikiDocument.getObject(className, objectNumber); if (baseObject == null) { throw new WebApplicationException(Status.NOT_FOUND); } Object object = DomainObjectFactory.createObject( objectFactory, uriInfo.getBaseUri(), Utils.getXWikiContext(componentManager), doc, baseObject, true, Utils.getXWikiApi(componentManager), withPrettyNames); for (Property property : object.getProperties()) { if (property.getName().equals(propertyName)) { String objectUri = Utils.createURI( uriInfo.getBaseUri(), ObjectAtPageVersionResource.class, doc.getWiki(), doc.getSpace(), doc.getName(), version, object.getClassName(), object.getNumber()) .toString(); Link objectLink = objectFactory.createLink(); objectLink.setHref(objectUri); objectLink.setRel(Relations.OBJECT); property.getLinks().add(objectLink); return property; } } throw new WebApplicationException(Status.NOT_FOUND); } catch (XWikiException e) { throw new XWikiRestException(e); } }