/**
   * The main entry point of the example application.
   *
   * @param args command line arguments (ignored)
   * @throws Exception if an error occurs
   */
  public static void main(String[] args) throws Exception {
    Repository repository = new TransientRepository();
    Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
    try {
      Node root = session.getRootNode();

      // Import the XML file unless already imported
      if (!root.hasNode("importxml")) {
        System.out.print("Importing xml... ");

        // Create an unstructured node under which to import the XML
        Node node = root.addNode("importxml", "nt:unstructured");

        // Import the file "test.xml" under the created node
        FileInputStream xml = new FileInputStream("test.xml");
        session.importXML(node.getPath(), xml, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
        xml.close();
        session.save();
        System.out.println("done.");
      }

      // output the repository content
      dump(root);
    } finally {
      session.logout();
    }
  }
  private boolean removeNode(String path) {

    Resource templateResource = resourceResolver.getResource(path);
    if (templateResource != null) {
      Node nodeToDelete = templateResource.adaptTo(Node.class);

      if (nodeToDelete != null) {
        try {
          nodeToDelete.remove();
          TemplateUtils.saveNode(nodeToDelete);
          session.save();
          return true;
        } catch (VersionException ex) {
          java.util.logging.Logger.getLogger(TemplateManagerDeleteServlet.class.getName())
              .log(Level.SEVERE, null, ex);
        } catch (LockException ex) {
          java.util.logging.Logger.getLogger(TemplateManagerDeleteServlet.class.getName())
              .log(Level.SEVERE, null, ex);
        } catch (ConstraintViolationException ex) {
          java.util.logging.Logger.getLogger(TemplateManagerDeleteServlet.class.getName())
              .log(Level.SEVERE, null, ex);
        } catch (AccessDeniedException ex) {
          java.util.logging.Logger.getLogger(TemplateManagerDeleteServlet.class.getName())
              .log(Level.SEVERE, null, ex);
        } catch (RepositoryException ex) {
          java.util.logging.Logger.getLogger(TemplateManagerDeleteServlet.class.getName())
              .log(Level.SEVERE, null, ex);
        } finally {
          session.logout();
        }
      }
    }
    return false;
  }
 public void logout() {
   for (Session session : sessions.values()) {
     session.logout();
   }
   if (credentials instanceof SimpleCredentials) {
     SimpleCredentials simpleCredentials = (SimpleCredentials) credentials;
     JahiaLoginModule.removeToken(
         simpleCredentials.getUserID(), new String(simpleCredentials.getPassword()));
   }
   isLive = false;
   activeSessions.decrementAndGet();
 }
 public static void buildDefinitions(Session session) {
   log.info("started building node definitions");
   String nodeName = "";
   try {
     allNodes = new HashMap<String, VNodeDefinition>();
     Node rootNode = session.getNode("/jcr:system/jcr:nodeTypes");
     NodeIterator nodeIterator = rootNode.getNodes();
     while (nodeIterator.hasNext()) {
       Node node = nodeIterator.nextNode();
       nodeName = node.getName();
       VNodeDefinition vNodeDefinition = new VNodeDefinition(node);
       customizeDefinition(vNodeDefinition); // possibly customize this definition
       allNodes.put(nodeName, vNodeDefinition);
     }
     log.info("finished building nodes");
   } catch (RepositoryException re) {
     log.warn("Could not build node definitions, died at " + nodeName, re);
   } finally {
     if (session != null) session.logout();
   }
 }