/**
   * Registors the custome node types for the jackrabbit-jcr-demo application from a given CND file.
   * Location of the CND file is given as an initial parameter
   *
   * @throws ServletException is thrown when registration not possible.
   */
  private void registerCustomNodeTypes() throws ServletException {

    // location of the CND file is kept as a servelt init parameter in the web.xml
    String cndPath = getInitParameter("cnd.path");
    String ocmPath = getInitParameter("ocm.path");

    try {

      Workspace ws = session.getWorkspace();

      NodeTypeManagerImpl ntTypeMgr = (NodeTypeManagerImpl) ws.getNodeTypeManager();

      // Registors the custom node types and namespaces
      InputStream inputStream = getServletContext().getResourceAsStream(cndPath);
      ntTypeMgr.registerNodeTypes(inputStream, JackrabbitNodeTypeManager.TEXT_X_JCR_CND, true);

      InputStream nodeTypeStream = getServletContext().getResourceAsStream(ocmPath);
      ntTypeMgr.registerNodeTypes(nodeTypeStream, JackrabbitNodeTypeManager.TEXT_XML, true);

      // Register a namespace to be used with in the program
      // ex. for a username "nandana" we can use demo:nandana
      NamespaceRegistryImpl nsReg =
          (NamespaceRegistryImpl) session.getWorkspace().getNamespaceRegistry();
      nsReg.safeRegisterNamespace("demo", "http://code.google.com/p/jackrabbit-jcr-demo");
      nsReg.safeRegisterNamespace("ocm", "http://jackrabbit.apache.org/ocm");

      log("JACKRABBIT-JCR-DEMO: Custom Node types registered  ...");

    } catch (RepositoryException e) {
      throw new ServletException("Failed to registor node types", e);
    } catch (IOException e) {
      throw new ServletException("Error occured while accessing the file" + cndPath, e);
    }
  }
예제 #2
0
 public static boolean registerNodeType(
     Session session, String systemId, Reader reader, boolean reregisterExisting)
     throws IOException, RepositoryException {
   try {
     Workspace wsp = session.getWorkspace();
     CndImporter.registerNodeTypes(
         reader,
         systemId,
         wsp.getNodeTypeManager(),
         wsp.getNamespaceRegistry(),
         session.getValueFactory(),
         reregisterExisting);
   } catch (RepositoryException re) {
     if (isReRegisterBuiltinNodeType(re)) {
       log.debug("Attempt to re-register built-in node type, RepositoryException ignored", re);
     } else {
       throw re;
     }
   } catch (ParseException e) {
     throw new IOException("Unable to parse CND Input: " + e.getMessage());
   }
   return true;
 }