/**
   * Imports custom node types into repository
   *
   * @param session JCR session
   * @param cndFile CND file with node types definition
   */
  public static void importCustomNodeTypes(Session session, InputStream cndFile) {
    if (logger.isInfoEnabled()) {
      logger.info("Importing custom node types into repository");
    }
    NodeType[] nodeTypes = new NodeType[0];
    try {
      nodeTypes =
          CndImporter.registerNodeTypes(
              new BufferedReader(new InputStreamReader(cndFile)), session);
    } catch (ParseException e) {
      logger.error("Failed to parse CND file with repository custom node types. " + e.getMessage());
    } catch (RepositoryException e) {
      logger.error("Failed to import custom node types into repository. " + e.getMessage());
    } catch (IOException e) {
      logger.error(
          "IO Exception while importing custom node types into repository. " + e.getMessage());
    }

    if (logger.isDebugEnabled()) {
      logger.debug("Registered node types: ");
      for (NodeType nt : nodeTypes) {
        logger.debug("\t" + nt.getName());
      }
    }
  }
Exemplo n.º 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;
 }