コード例 #1
0
  @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);
    }
  }
コード例 #2
0
  @GET
  public Spaces getSpaces(
      @PathParam("wikiName") String wikiName,
      @QueryParam("start") @DefaultValue("0") Integer start,
      @QueryParam("number") @DefaultValue("-1") Integer number)
      throws XWikiException, QueryException, ComponentLookupException {
    String database = Utils.getXWikiContext(componentManager).getDatabase();

    Spaces spaces = objectFactory.createSpaces();

    /* This try is just needed for executing the finally clause. */
    try {
      Utils.getXWikiContext(componentManager).setDatabase(wikiName);

      List<String> spaceNames =
          queryManager
              .getNamedQuery("getSpaces")
              .addFilter(componentManager.<QueryFilter>getInstance(QueryFilter.class, "hidden"))
              .setOffset(start)
              .setLimit(number)
              .execute();

      for (String spaceName : spaceNames) {
        String homeId = Utils.getPageId(wikiName, spaceName, "WebHome");
        Document home = null;

        XWiki xwikiApi = Utils.getXWikiApi(componentManager);
        if (xwikiApi.hasAccessLevel("view", homeId)) {
          if (xwikiApi.exists(homeId)) {
            home = Utils.getXWikiApi(componentManager).getDocument(homeId);
          }
          spaces
              .getSpaces()
              .add(
                  DomainObjectFactory.createSpace(
                      objectFactory, uriInfo.getBaseUri(), wikiName, spaceName, home));
        }
      }
    } finally {
      Utils.getXWikiContext(componentManager).setDatabase(database);
    }

    return spaces;
  }