Exemplo n.º 1
0
  /** {@inheritDoc} */
  public JCRNodeWrapper getFrozenVersionAsRegular(Node objectNode, JCRStoreProvider provider)
      throws RepositoryException {
    try {
      VersionHistory vh =
          objectNode
              .getSession()
              .getWorkspace()
              .getVersionManager()
              .getVersionHistory(objectNode.getPath());

      Version v = null;
      if (versionLabel != null) {
        v = JCRVersionService.findVersionByLabel(vh, versionLabel);
      }
      if (v == null && versionDate != null) {
        v = JCRVersionService.findClosestVersion(vh, versionDate);
      }

      if (v == null) {
        throw new PathNotFoundException();
      }

      Node frozen = v.getNode(Constants.JCR_FROZENNODE);

      return provider.getNodeWrapper(frozen, this);
    } catch (UnsupportedRepositoryOperationException e) {
      if (getVersionDate() == null && getVersionLabel() == null) {
        logger.error("Error while retrieving frozen version", e);
      }
    }
    return null;
  }
Exemplo n.º 2
0
 /**
  * pesquisa A*
  *
  * @param table_list lista de tabelas
  * @param visited_tables lista de tabelas visitadas
  * @param final_table tabela final/pretendida
  * @return
  */
 public static Node aStarSearch(PriorityQueue<Node> table_list, int[][] final_table) {
   int[][] current_table = new int[3][3];
   int depth = 0;
   String path = new String();
   while (!table_list.isEmpty()) {
     List child_nodes = new List();
     Node current_node = table_list.poll();
     path = current_node.getPath();
     depth = current_node.getDepth();
     current_table = current_node.getTable();
     /*
     System.out.println("custo: "+cost+"depth: "+depth);
     System.out.println("Tabela: ");
     for(int i=0;i<3;i++){
     	for(int j=0;j<3;j++)
     		System.out.print(current_table[i][j]);
     	System.out.println();
     }
     */
     if (isSolution(current_table, final_table)) return new Node(current_table, depth, path, null);
     child_nodes = playBFS(child_nodes, current_table, depth, path);
     // verifica se algum dos filhos já foi visitado
     while (!child_nodes.isEmpty()) {
       int d = child_nodes.getDepth();
       String s = child_nodes.getPath();
       int[][] child_table = child_nodes.remove();
       int c = d + getDistanceTo(child_table, final_table);
       Node child = new Node(child_table, d, s, c, null);
       table_list.add(child);
     }
   }
   throw new Error("Nao encontrou solucao");
 }
Exemplo n.º 3
0
 /**
  * pesquisa gulosa
  *
  * @param table_list lista de tabelas
  * @param visited_tables lista de tabelas visitadas
  * @param final_table tabela final/pretendida
  */
 public static Node greedySearch(
     PriorityQueue<Node> table_list, List visited_tables, int[][] final_table) {
   int[][] current_table = new int[3][3];
   int depth = 0;
   String path = new String();
   while (!table_list.isEmpty()) {
     List child_nodes = new List();
     Node current_node = table_list.poll();
     path = current_node.getPath();
     depth = current_node.getDepth();
     current_table = current_node.getTable();
     if (isSolution(current_table, final_table)) return new Node(current_table, depth, path, null);
     visited_tables.addFirst(current_table, depth, path);
     child_nodes = playBFS(child_nodes, current_table, depth, path);
     // verifica se algum dos filhos já foi visitado
     while (!child_nodes.isEmpty()) {
       int d = child_nodes.getDepth();
       String s = child_nodes.getPath();
       int[][] child_table = child_nodes.remove();
       if (!visited_tables.contains(child_table)) {
         int c = getDistanceTo(child_table, final_table);
         Node child = new Node(child_table, d, s, c, null);
         table_list.add(child);
       }
     }
   }
   throw new Error("Nao encontrou solucao");
 }
  /** Recursively outputs the contents of the given node. */
  private static void dump(Node node) throws RepositoryException {
    // First output the node path
    System.out.println(node.getPath());
    // Skip the virtual (and large!) jcr:system subtree
    if (node.getName().equals("jcr:system")) {
      return;
    }

    // Then output the properties
    PropertyIterator properties = node.getProperties();
    while (properties.hasNext()) {
      Property property = properties.nextProperty();
      if (property.getDefinition().isMultiple()) {
        // A multi-valued property, print all values
        Value[] values = property.getValues();
        for (int i = 0; i < values.length; i++) {
          System.out.println(property.getPath() + " = " + values[i].getString());
        }
      } else {
        // A single-valued property
        System.out.println(property.getPath() + " = " + property.getString());
      }
    }

    // Finally output all the child nodes recursively
    NodeIterator nodes = node.getNodes();
    while (nodes.hasNext()) {
      dump(nodes.nextNode());
    }
  }
  /**
   * 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();
    }
  }
Exemplo n.º 6
0
  public Node storeAsNode(String absPath)
      throws ItemExistsException, PathNotFoundException, VersionException,
          ConstraintViolationException, LockException, UnsupportedRepositoryOperationException,
          RepositoryException {
    Node queryNode = m_session.getRootNode().addNode(absPath, "nt:query");

    queryNode.setProperty("jcr:statement", getStatement());
    queryNode.setProperty("jcr:language", getLanguage());

    m_storedQueryPath = queryNode.getPath();

    return queryNode;
  }
Exemplo n.º 7
0
 /**
  * Performs check out of the specified node.
  *
  * @param node the node to perform the check out
  * @see VersionManager#checkout(String) for details
  */
 public void checkout(Node node)
     throws UnsupportedRepositoryOperationException, LockException, RepositoryException {
   while (!node.isCheckedOut()) {
     if (!node.isNodeType("mix:versionable") && !node.isNodeType("mix:simpleVersionable")) {
       node = node.getParent();
     } else {
       String absPath = node.getPath();
       VersionManager versionManager = getWorkspace().getVersionManager();
       if (!versionManager.isCheckedOut(absPath)) {
         versionManager.checkout(absPath);
       }
       return;
     }
   }
 }
Exemplo n.º 8
0
 private JCRNodeWrapper dereference(JCRNodeWrapper parent, String refPath)
     throws RepositoryException {
   JCRStoreProvider provider = parent.getProvider();
   JCRNodeWrapper wrapper;
   Node referencedNode = parent.getRealNode().getProperty("j:node").getNode();
   String fullPath = parent.getPath() + DEREF_SEPARATOR + refPath;
   if (parent.getPath().startsWith(referencedNode.getPath())) {
     throw new PathNotFoundException(fullPath);
   }
   String refRootName = StringUtils.substringBefore(refPath, "/");
   if (!referencedNode.getName().equals(refRootName)) {
     throw new PathNotFoundException(fullPath);
   }
   refPath = StringUtils.substringAfter(refPath, "/");
   if (refPath.equals("")) {
     wrapper = provider.getNodeWrapper(referencedNode, fullPath, parent, this);
   } else {
     Node node = referencedNode.getNode(refPath);
     wrapper = provider.getNodeWrapper(node, fullPath, null, this);
   }
   sessionCacheByPath.put(fullPath, wrapper);
   return wrapper;
 }