Nuxeo ECM Projects 5.4.3-SNAPSHOT

org.nuxeo.ecm.webengine.samples
Class DocumentsObject

java.lang.Object
  extended by org.nuxeo.ecm.webengine.model.impl.AbstractResource<ResourceTypeImpl>
      extended by org.nuxeo.ecm.webengine.model.impl.DefaultObject
          extended by org.nuxeo.ecm.webengine.samples.DocumentsObject
All Implemented Interfaces:
Resource, Adaptable
Direct Known Subclasses:
ExtendedDocumentsObject

public class DocumentsObject
extends DefaultObject

Working with Nuxeo Documents.

Nuxeo Documents are transparently mapped to WebObjects so that you can easily access your documents through WebEngine.

Nuxeo Documents are defined by a document type and can be structured in a hierarchy based on their type. The ancestor of all document types is the "Document" type.

Document types are transparently mapped to WebObject types, so that you don't need to explicitly declare WebObjects that expose documents. By default all documents are exposed as DocumentObject instances (which is an WebObject). If you need specific control over your document type you need then to explicitly declare a new WebObject using the same type name as your document type. This way, the default binding to DocumentObject will be replaced with your own WebObject.

Note that it is recommended to subclass the DocumentObject when redefining document WebObjects.

Also, Documents as WebObjects may have a set of facets. Documents facets are transparently exposed as WebObject facets. When redefining the WebObject used to expose a Document you can add new facets using @WebObject annotation (these new facets that are not existing at document level but only at WebObject level).

To work with documents you need first to get a view on the repository. This can be done using the following methods:
DocumentFactory.getDocumentRoot(ctx, path) or DocumentFactory.getDocument(ctx, path)
The difference between the two methods is that the getDocumentRoot is also setting the newly created document WebObject as the root of the request chain. The document WebObject created using the DocumentFactory helper class will represent the root of your repository view. To go deeper in the repository tree you can use the newDocument methods on the DocumentObject instance.

Remember that when working with documents you may need to log in to be able to access the repository. (it depends on whether or not the repository root is accessible to Anonymous user) For this reason we provide in this example a way to login into the repository. This also demonstrates how to handle errors in WebEngine. The mechanism is simple: At your module root resource level you redefine a method SamplesRoot public Object handleError(WebApplicationException e) that will be invoked each time an uncatched exception is thrown during the request. From that method you should return a suitable response to render the error. To ensure exceptions are correctly redirected to your error handler you must catch all exceptions thrown in your resource methods and rethrowing them as following: ... } catch (Throwable t) { throw WebException.wrap(t); } . The exception wrapping is automatically converting exceptions to the ones defined by WebEngine model.

Author:
Bogdan Stefanescu

Constructor Summary
DocumentsObject()
           
 
Method Summary
 Object doGet()
           
 Object getRepositoryView()
          Get a repository view rooted under "/default-domain".
 
Methods inherited from class org.nuxeo.ecm.webengine.model.impl.DefaultObject
disptachAdapter, isAdapter
 
Methods inherited from class org.nuxeo.ecm.webengine.model.impl.AbstractResource
checkGuard, dispose, getActiveAdapter, getAdapter, getContext, getFacets, getLinks, getModule, getName, getNext, getNextSegment, getPath, getPrevious, getTemplate, getTrailingPath, getType, getURL, getView, hasFacet, initialize, isInstanceOf, isRoot, newAdapter, newObject, redirect, setNext, setPrevious, setRoot, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DocumentsObject

public DocumentsObject()
Method Detail

doGet

public Object doGet()

getRepositoryView

public Object getRepositoryView()
Get a repository view rooted under "/default-domain".


Nuxeo ECM Projects 5.4.3-SNAPSHOT

Copyright © 2011 Nuxeo SAS. All Rights Reserved.