jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ivan Latysh <ivanlat...@gmail.com>
Subject Re: Deploying custom node types in jackrabbit
Date Mon, 18 Feb 2008 13:25:47 GMT
Manolo Gomez Lopez wrote:

> But I also see that forcing an API method invocation as the *only* way of
> registering node types maybe is not the best solution for all deployment
> scenarios.
[skipped]

Custom node type register is 15 minute job, here is an example of how it can be 
done.

       // get node type manager
       NodeTypeManagerImpl ntmgr = (NodeTypeManagerImpl) 
workspace.getNodeTypeManager();
       logger.info("Registering node types.");
       InputStream cnd = 
DefaultRepository.class.getClassLoader().getResourceAsStream("custom-node-types.cnd");
       // prepare string builder
       ByteArrayOutputStream sb = new ByteArrayOutputStream(1024);
       // read node definition
       copy(cnd, sb, 1024);
       // parse and register node definition
       StringTokenizer st = new StringTokenizer(sb.toString(), "\\[", true);
       while (st.hasMoreTokens()) {
         String nd = st.nextToken();
         if ("[".equals(nd) && st.hasMoreTokens()) nd += st.nextToken();
         try {
           logger.debug("Registering node type {" + nd + "}");
           ntmgr.registerNodeTypes(new ByteArrayInputStream(nd.getBytes()), 
JackrabbitNodeTypeManager.TEXT_X_JCR_CND);
         } catch (Exception e) {
           if (null != e.getCause() && 
e.getCause().getMessage().contains("already exists")) {
             logger.debug("Node {" + nd + "} already registered.", e);
           } else {
             logger.error("Unable to register node type {" + sb + "}", e);
           }
         }
       }

   public static void copy(InputStream in, OutputStream out, int buffer) throws 
IOException {
     byte[] buf = new byte[buffer];
     int read;
     while ((read = in.read(buf)) > 0) {
       out.write(buf, 0, read);
     }
   }


-- 
Ivan Latysh
IvanLatysh@gmail.com

Mime
View raw message