jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Jackrabbit Wiki] Update of "ExamplesPage" by BearGiles
Date Mon, 11 May 2009 16:04:06 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Jackrabbit Wiki" for change notification.

The following page has been changed by BearGiles:
http://wiki.apache.org/jackrabbit/ExamplesPage

The comment on the change is:
Added example of creating customer node type/namespace using CND.

------------------------------------------------------------------------------
      }
  }}}
  
+ === Register a Node Type [CND] ===
+ 
+ Register one or more node types using CND.  CND is described in
+ http://jackrabbit.apache.org/node-type-notation.html.
+ 
+ {{{
+     public void createCustomNodeTypes(Session session)
+         throws RepositoryException, IOException {
+ 
+         // Get the JackrabbitNodeTypeManager from the Workspace.
+         // Note that it must be cast from the generic JCR NodeTypeManager to
+         // the  Jackrabbit-specific implementation.
+         // (see: http://jackrabbit.apache.org/node-types.html)
+         JackrabbitNodeTypeManager manager =
+            (JackrabbitNodeTypeManager) session.getWorkspace().getNodeTypeManager();
+ 
+         // Register the custom node types defined in the CND file
+         InputStream is = Thread.currentThread().getContextClassLoader()
+                              .getResourceAsStream("com/example/jcr/custom.cnd");
+         manager.registerNodeTypes(is, JackrabbitNodeTypeManager.TEXT_X_JCR_CND);
+     }
+ }}}
+ 
+ You can automatically install your node types/namespace during initialization.
+ (This is why the method above pulls the file as classloader resource).
+ 
+ {{{
+     public Session setup(Credentials cred)
+         throws RepositoryException, IOException {
+         Session session;
+ 
+         session = repository.login(cred);
+  
+         // create 'custom' namespace if necessary
+         Workspace workspace = session.getWorkspace();
+         NamespaceRegistry reg = workspace.getNamespaceRegistry();
+ 
+         if (!Arrays.asList(reg.getPrefixes()).contains("custom")) {
+             createCustomNodeTypes(session);
+         }
+ 
+         return session;
+     }
+ }}}
  
  === Versioning Basics ===
  

Mime
View raw message