Example #1
0
  /**
   * Returns the registry node which wraps a node of type "exo:registry" (the whole registry tree)
   *
   * @response {code} "entryStream" : the output stream corresponding registry node which wraps a
   *     node of type "exo:registry" (the whole registry tree) {code} Example : {code:xml} <registry
   *     xlinks:href="http://localhost:8080/portal/rest/registry/"> <GroovyScript2RestLoader
   *     xlinks:href="http://localhost:8080/portal/rest/registry/exo:services/GroovyScript2RestLoader"/>
   *     <Audit xlinks:href="http://localhost:8080/portal/rest/registry/exo:services/Audit"/>
   *     </registry> {code} @LevelAPI Experimental
   */
  @GET
  @Produces(MediaType.APPLICATION_XML)
  public Response getRegistry(@Context UriInfo uriInfo) {
    SessionProvider sessionProvider = sessionProviderService.getSessionProvider(null);
    try {
      RegistryNode registryEntry = regService.getRegistry(sessionProvider);
      if (registryEntry != null) {
        Node registryNode = registryEntry.getNode();
        NodeIterator registryIterator = registryNode.getNodes();
        Document entry =
            SecurityHelper.doPrivilegedExceptionAction(
                new PrivilegedExceptionAction<Document>() {
                  public Document run() throws Exception {
                    return DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
                  }
                });

        String fullURI = uriInfo.getRequestUri().toString();
        XlinkHref xlinkHref = new XlinkHref(fullURI);
        Element root = entry.createElement(REGISTRY);
        xlinkHref.putToElement(root);
        while (registryIterator.hasNext()) {
          NodeIterator entryIterator = registryIterator.nextNode().getNodes();
          while (entryIterator.hasNext()) {
            Node node = entryIterator.nextNode();
            Element xmlNode = entry.createElement(node.getName());
            xlinkHref.putToElement(xmlNode, node.getPath().substring(EXO_REGISTRY.length()));
            root.appendChild(xmlNode);
          }
        }
        entry.appendChild(root);
        return Response.ok(new DOMSource(entry), "text/xml").build();
      }
      return Response.status(Response.Status.NOT_FOUND).build();
    } catch (Exception e) {
      LOG.error("Get registry failed", e);
      throw new WebApplicationException(e);
    }
  }