コード例 #1
0
 /**
  * {@inheritDoc}
  *
  * @see
  *     org.modeshape.graph.request.processor.RequestProcessor#process(org.modeshape.graph.request.ReadAllPropertiesRequest)
  */
 @Override
 public void process(ReadAllPropertiesRequest request) {
   if (request == null) return;
   try {
     Workspace workspace = workspaceFor(request.inWorkspace());
     Node node = workspace.node(request.at());
     Location actualLocation = workspace.locationFor(node);
     request.setActualLocationOfNode(actualLocation);
     // Read the properties ...
     for (PropertyIterator iter = node.getProperties(); iter.hasNext(); ) {
       request.addProperty(workspace.propertyFor(iter.nextProperty()));
     }
     // Add in the 'jcr:uuid' property ...
     if (actualLocation.hasIdProperties()) {
       request.addProperty(workspace.propertyFor(ModeShapeLexicon.UUID, actualLocation.getUuid()));
     }
     // Get the number of children ...
     NodeIterator childIter = node.getNodes();
     int numChildren = (int) childIter.getSize();
     if (numChildren == -1) {
       numChildren = 0;
       while (childIter.hasNext()) {
         childIter.nextNode();
         ++numChildren;
       }
     }
     request.setNumberOfChildren(numChildren);
     setCacheableInfo(request);
   } catch (Throwable e) {
     request.setError(e);
   }
 }
コード例 #2
0
ファイル: JsonItemWriter.java プロジェクト: JEBailey/sling
  /** Dump given node in JSON, optionally recursing into its child nodes */
  protected void dump(Node node, JSONWriter w, int currentRecursionLevel, int maxRecursionLevels)
      throws RepositoryException, JSONException {

    w.object();
    PropertyIterator props = node.getProperties();

    // the node's actual properties
    while (props.hasNext()) {
      Property prop = props.nextProperty();

      if (propertyNamesToIgnore != null && propertyNamesToIgnore.contains(prop.getName())) {
        continue;
      }

      writeProperty(w, prop);
    }

    // the child nodes
    if (recursionLevelActive(currentRecursionLevel, maxRecursionLevels)) {
      final NodeIterator children = node.getNodes();
      while (children.hasNext()) {
        final Node n = children.nextNode();
        dumpSingleNode(n, w, currentRecursionLevel, maxRecursionLevels);
      }
    }

    w.endObject();
  }
コード例 #3
0
 /**
  * {@inheritDoc}
  *
  * @see
  *     org.modeshape.graph.request.processor.RequestProcessor#process(org.modeshape.graph.request.ReadNodeRequest)
  */
 @Override
 public void process(ReadNodeRequest request) {
   if (request == null) return;
   try {
     Workspace workspace = workspaceFor(request.inWorkspace());
     Node node = workspace.node(request.at());
     Location actualLocation = workspace.locationFor(node);
     request.setActualLocationOfNode(actualLocation);
     // Read the children ...
     for (NodeIterator iter = node.getNodes(); iter.hasNext(); ) {
       request.addChild(workspace.locationFor(iter.nextNode()));
     }
     // Read the properties ...
     for (PropertyIterator iter = node.getProperties(); iter.hasNext(); ) {
       request.addProperty(workspace.propertyFor(iter.nextProperty()));
     }
     // Add in the 'jcr:uuid' property ...
     if (actualLocation.hasIdProperties()) {
       request.addProperty(workspace.propertyFor(ModeShapeLexicon.UUID, actualLocation.getUuid()));
     }
     setCacheableInfo(request);
   } catch (Throwable e) {
     request.setError(e);
   }
 }
コード例 #4
0
ファイル: Utils.java プロジェクト: RandomStuffs22/ecms
 public static NodeIterator getAuthorizedChildNodes(Node node) throws Exception {
   NodeIterator iter = node.getNodes();
   while (iter.hasNext()) {
     if (!PermissionUtil.canRead(iter.nextNode())) iter.remove();
   }
   return iter;
 }
コード例 #5
0
  /** TODO: Not fully implemented SEE: DirectSearchModule.getKeywordMapLive() */
  public static synchronized void refreshUserDocKeywords(Session session)
      throws RepositoryException {
    log.info("refreshUserDocKeywords({})", session);
    String statement = "/jcr:root/" + Repository.ROOT + "/element(*,okm:document)";

    try {
      Workspace workspace = session.getWorkspace();
      QueryManager queryManager = workspace.getQueryManager();
      Query query = queryManager.createQuery(statement, Query.XPATH);
      javax.jcr.query.QueryResult qResult = query.execute();
      Map<String, Set<String>> userDocKeywords = new HashMap<String, Set<String>>();

      for (NodeIterator nit = qResult.getNodes(); nit.hasNext(); ) {
        Node docNode = nit.nextNode();
        Value[] keywords = docNode.getProperty(Property.KEYWORDS).getValues();
        Set<String> keywordSet = new HashSet<String>();

        for (int i = 0; i < keywords.length; i++) {
          keywordSet.add(keywords[i].getString());
        }

        userDocKeywords.put(docNode.getUUID(), keywordSet);
      }

      // userDocumentKeywordsMgr.put(session.getUserID(), userDocKeywords);
    } catch (javax.jcr.RepositoryException e) {
      log.error(e.getMessage(), e);
      throw new RepositoryException(e.getMessage(), e);
    }

    log.info("refreshUserDocKeywords: void");
  }
コード例 #6
0
 private static void traverseNodes(Node node, int currentLevel) throws Exception {
   System.out.println(node.getPath());
   NodeIterator children = node.getNodes();
   while (children.hasNext()) {
     traverseNodes(children.nextNode(), currentLevel + 1);
   }
 }
コード例 #7
0
ファイル: FontConfigImpl.java プロジェクト: tiennv90/SVN
 protected void activate(final ComponentContext ctx) {
   if (TMP_DIR != null) {
     File tmpDir = new File(TMP_DIR);
     fontsDir = new File(tmpDir, "fonts." + UUID.randomUUID());
     fontsDir.mkdir();
     fontsDir.deleteOnExit();
     Session session = null;
     try {
       session = repo.loginAdministrative(repo.getDefaultWorkspace());
       if (session.nodeExists(FONT_CONFIG)) {
         configFile = createFile(session.getNode(FONT_CONFIG));
       }
       if (session.nodeExists(FONT_CONFIG_FONTS)) {
         Node fonts = session.getNode(FONT_CONFIG_FONTS);
         NodeIterator children = fonts.getNodes();
         while (children.hasNext()) {
           createFile((Node) children.next());
         }
       }
     } catch (RepositoryException e) {
       logger.error("Failed exporting FOP font data.", e);
     } finally {
       if (session != null) {
         session.logout();
       }
     }
   }
 }
コード例 #8
0
  /** 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());
    }
  }
  private void checkCustomProperties(Session session) throws javax.jcr.RepositoryException {

    NodeTypeManager nodetypeManager = new NodeTypeManager();
    // Check and create required custom properties
    javax.jcr.Node systemNode = JCRUtils.getSystemNode(session);
    if (systemNode.hasNode(JLibraryConstants.JLIBRARY_CUSTOM_PROPERTIES)) {
      javax.jcr.Node propertiesNode =
          systemNode.getNode(JLibraryConstants.JLIBRARY_CUSTOM_PROPERTIES);
      NodeIterator it = propertiesNode.getNodes();
      while (it.hasNext()) {
        javax.jcr.Node propsNode = (javax.jcr.Node) it.next();
        CustomPropertyDefinition propdef = new CustomPropertyDefinition();
        propdef.setName(
            propsNode.getProperty(JLibraryConstants.JLIBRARY_PROPERTY_NAME).getString());
        propdef.setType(
            (int) propsNode.getProperty(JLibraryConstants.JLIBRARY_PROPERTY_TYPE).getLong());
        propdef.setMultivalued(
            propsNode.getProperty(JLibraryConstants.JLIBRARY_PROPERTY_MULTIVALUED).getBoolean());
        propdef.setAutocreated(
            propsNode.getProperty(JLibraryConstants.JLIBRARY_PROPERTY_AUTOCREATED).getBoolean());
        if (propsNode.hasProperty(JLibraryConstants.JLIBRARY_PROPERTY_DEFAULT)) {
          propdef.setDefaultValues(
              propsNode.getProperty(JLibraryConstants.JLIBRARY_PROPERTY_DEFAULT).getValues());
        }

        logger.info("Registering property : " + propdef);
        nodetypeManager.registerCustomProperty(session, propdef);
      }
    }
  }
コード例 #10
0
  @Test
  @FixFor("MODE-2109 ")
  public void shouldOnlyAllowCloningInSomeCases() throws Exception {
    session.getWorkspace().createWorkspace("other");

    try {
      session.getRootNode().addNode("col1", "test:smallCollection");
      Node regular = session.getRootNode().addNode("regular");
      regular.addNode("regular1");
      session.save();

      // cloning a large collection is not allowed
      JcrWorkspace workspace = session.getWorkspace();
      try {
        workspace.clone(workspace.getName(), "/col1", "/regular", false);
        fail("Should not allow cloning");
      } catch (ConstraintViolationException e) {
        // expected
      }

      // clone a regular node into a large collection
      JcrSession otherSession = repository.login("other");
      Node col2 = otherSession.getRootNode().addNode("col2", "test:smallCollection");
      col2.addNode("child1");
      otherSession.save();

      otherSession.getWorkspace().clone(workspace.getName(), "/regular", "/col2/regular", false);
      NodeIterator nodes = otherSession.getNode("/col2").getNodes();
      assertEquals(2, nodes.getSize());
    } finally {
      session.getWorkspace().deleteWorkspace("other");
    }
  }
コード例 #11
0
 private void puttoList(List<Node> lstNode, NodeIterator nodeIter) {
   if (nodeIter != null) {
     while (nodeIter.hasNext()) {
       lstNode.add(nodeIter.nextNode());
     }
   }
 }
コード例 #12
0
 /**
  * get user by name in range with sql statement
  *
  * @param username
  */
 public User getUserByNameLimtSQL(String username) {
   username.replaceAll("\"", "\\\"").replaceAll("-", StringUtils.EMPTY);
   username = username.trim();
   SessionProvider sProvider = SessionProvider.createSystemProvider();
   StringBuffer queryString = new StringBuffer("Select * from " + BookNodeTypes.EXO_USER);
   queryString.append(" where " + BookNodeTypes.EXO_USER_NAME + " = '" + username + "'");
   try {
     QueryManager queryManager = getSession(sProvider).getWorkspace().getQueryManager();
     QueryImpl query = (QueryImpl) queryManager.createQuery(queryString.toString(), Query.SQL);
     query.setOffset(0L);
     query.setLimit(3L);
     QueryResult result = query.execute();
     NodeIterator nodes = result.getNodes();
     if (nodes.getSize() > 0) {
       Node node = nodes.nextNode();
       return createUserByNode(node);
     }
     return null;
   } catch (RepositoryException re) {
     log.error("Can not get user by name", re);
     return null;
   } finally {
     sProvider.close();
   }
 }
コード例 #13
0
 /**
  * Returns the nodes in <code>it</code> as an array of Nodes.
  *
  * @param it the NodeIterator.
  * @return the elements of the iterator as an array of Nodes.
  */
 protected Node[] toArray(NodeIterator it) {
   List nodes = new ArrayList();
   while (it.hasNext()) {
     nodes.add(it.nextNode());
   }
   return (Node[]) nodes.toArray(new Node[nodes.size()]);
 }
コード例 #14
0
  @Test
  public void ferrari_has_two_doors() throws RepositoryException {
    Node ferrari = session.getNode("/cars/ferrari");
    NodeIterator nodeIterator = ferrari.getNodes("catalog:door");

    assertThat(nodeIterator.getSize(), is(2L));
  }
コード例 #15
0
  @Test
  public void ferrari_has_four_wheels() throws RepositoryException {
    Node ferrari = session.getNode("/cars/ferrari");
    NodeIterator nodeIterator = ferrari.getNodes("catalog:wheel");

    assertThat(nodeIterator.getSize(), is(4L));
  }
コード例 #16
0
 @Override
 protected void internalRemove(String key) throws MessagingException {
   try {
     Session session = login();
     try {
       String name = ISO9075.encode(Text.escapeIllegalJcrChars(key));
       QueryManager manager = session.getWorkspace().getQueryManager();
       @SuppressWarnings("deprecation")
       Query query =
           manager.createQuery(
               "/jcr:root/" + MAIL_PATH + "//element(" + name + ",james:mail)", Query.XPATH);
       NodeIterator nodes = query.execute().getNodes();
       if (nodes.hasNext()) {
         while (nodes.hasNext()) {
           nodes.nextNode().remove();
         }
         session.save();
         logger.info("Mail " + key + " removed from repository");
       } else {
         logger.warn("Mail " + key + " not found");
       }
     } finally {
       session.logout();
     }
   } catch (RepositoryException e) {
     throw new MessagingException("Unable to remove message: " + key, e);
   }
 }
コード例 #17
0
  @Override
  protected void internalStore(Mail mail) throws MessagingException, IOException {
    try {
      Session session = login();
      try {
        String name = Text.escapeIllegalJcrChars(mail.getName());
        final String xpath = "/jcr:root/" + MAIL_PATH + "//element(" + name + ",james:mail)";

        QueryManager manager = session.getWorkspace().getQueryManager();
        @SuppressWarnings("deprecation")
        Query query = manager.createQuery(xpath, Query.XPATH);
        NodeIterator iterator = query.execute().getNodes();

        if (iterator.hasNext()) {
          while (iterator.hasNext()) {
            setMail(iterator.nextNode(), mail);
          }
        } else {
          Node parent = session.getRootNode().getNode(MAIL_PATH);
          Node node = parent.addNode(name, "james:mail");
          Node resource = node.addNode("jcr:content", "nt:resource");
          resource.setProperty("jcr:mimeType", "message/rfc822");
          setMail(node, mail);
        }
        session.save();
        logger.info("Mail " + mail.getName() + " stored in repository");
      } finally {
        session.logout();
      }
    } catch (IOException e) {
      throw new MessagingException("Unable to store message: " + mail.getName(), e);
    } catch (RepositoryException e) {
      throw new MessagingException("Unable to store message: " + mail.getName(), e);
    }
  }
コード例 #18
0
  private void purgeHistory(Node fileNode, Session session, PentahoJcrConstants pentahoJcrConstants)
      throws RepositoryException {
    // Delete all previous versions of this node
    VersionManager versionManager = session.getWorkspace().getVersionManager();
    if (JcrRepositoryFileUtils.isPentahoFolder(pentahoJcrConstants, fileNode)) {
      // go down to children
      NodeIterator nodes = fileNode.getNodes();
      while (nodes.hasNext()) {
        Node next = (Node) nodes.next();
        purgeHistory(next, session, pentahoJcrConstants);
      }
    } else if (JcrRepositoryFileUtils.isPentahoFile(pentahoJcrConstants, fileNode)
        && fileNode.isNodeType(pentahoJcrConstants.getPHO_MIX_VERSIONABLE())) {
      VersionHistory versionHistory = versionManager.getVersionHistory(fileNode.getPath());

      VersionIterator allVersions = versionHistory.getAllVersions();
      while (allVersions.hasNext()) {
        Version next = (Version) allVersions.next();
        String name = next.getName();
        // Root version cannot be deleted, the remove below will take care of that.
        if (!JCR_ROOT_VERSION.equals(name)) {
          versionHistory.removeVersion(name);
        }
      }
    }
  }
コード例 #19
0
 public Mail retrieve(String key) throws MessagingException {
   try {
     Session session = login();
     try {
       String name = toSafeName(key);
       QueryManager manager = session.getWorkspace().getQueryManager();
       @SuppressWarnings("deprecation")
       Query query =
           manager.createQuery(
               "/jcr:root/" + MAIL_PATH + "//element(" + name + ",james:mail)", Query.XPATH);
       NodeIterator iterator = query.execute().getNodes();
       if (iterator.hasNext()) {
         return getMail(iterator.nextNode());
       } else {
         return null;
       }
     } finally {
       session.logout();
     }
   } catch (IOException e) {
     throw new MessagingException("Unable to retrieve message: " + key, e);
   } catch (RepositoryException e) {
     throw new MessagingException("Unable to retrieve message: " + key, e);
   }
 }
コード例 #20
0
  @Override
  public List<JcrNode> childNodes(String path) throws RemoteException {
    List<JcrNode> children = null;
    if (path == null || path.trim().length() == 0) {
      return Collections.emptyList();
    }
    try {
      Node node = (Node) session().getItem(path);
      NodeIterator it = node.getNodes();
      children = new ArrayList<JcrNode>((int) it.getSize());

      while (it.hasNext()) {
        Node n = it.nextNode();
        JcrNode childNode = new JcrNode(n.getName(), n.getPath(), n.getPrimaryNodeType().getName());
        childNode.setProperties(getProperties(n));
        childNode.setAcessControlList(getAccessList(session().getAccessControlManager(), node));
        childNode.setMixins(mixins(n));
        childNode.setPropertyDefs(propertyDefs(n));
        children.add(childNode);
      }

    } catch (PathNotFoundException e) {
      log.log(Level.FINER, e.getLocalizedMessage());
    } catch (RepositoryException e) {
      log.log(Level.SEVERE, "Unexpected error", e);
      throw new RemoteException(e.getMessage());
    }

    return children;
  }
コード例 #21
0
 /**
  * get user by name with xpath
  *
  * @param username
  * @return
  */
 public User getUserByNameXPath(String username) {
   username.replaceAll("\"", "\\\"").replaceAll("-", StringUtils.EMPTY);
   username = username.trim();
   SessionProvider sProvider = SessionProvider.createSystemProvider();
   StringBuffer queryString =
       new StringBuffer(
           "//element(*, "
               + BookNodeTypes.EXO_USER
               + ")[(jcr:like(@"
               + BookNodeTypes.EXO_USER_NAME
               + ",'%"
               + username
               + "%'"
               + ") and @"
               + BookNodeTypes.EXO_USER_ADDRESS
               + "='Hanoi'"
               + ")]");
   try {
     QueryManager queryManager = getSession(sProvider).getWorkspace().getQueryManager();
     Query query = queryManager.createQuery(queryString.toString(), Query.XPATH);
     QueryResult result = query.execute();
     NodeIterator nodes = result.getNodes();
     if (nodes.getSize() > 0) {
       Node node = nodes.nextNode();
       PropertyReader reader = new PropertyReader(node);
       return createUserByNode(node);
     }
     return null;
   } catch (RepositoryException re) {
     log.error("Can not get user by name(XPath)", re);
     return null;
   } finally {
     sProvider.close();
   }
 }
コード例 #22
0
 /**
  * search book by name with like condition(using SQL)
  *
  * @param name The name of book
  * @return List<Book>
  */
 public List<Book> searchBookByNameLikeSQL(String name) {
   /* replace "" sign and - sign */
   name.replaceAll("\"", "\\\"").replaceAll("-", StringUtils.EMPTY);
   /* create query string */
   StringBuffer sb = new StringBuffer("Select * from " + BookNodeTypes.EXO_BOOK);
   sb.append(" where " + BookNodeTypes.EXO_BOOK_NAME + " like '%" + name + "%'");
   SessionProvider sProvider = SessionProvider.createSystemProvider();
   try {
     /* create QueryManager from session */
     QueryManager queryManager = getSession(sProvider).getWorkspace().getQueryManager();
     /* create Query object */
     Query query = queryManager.createQuery(sb.toString(), Query.SQL);
     /* execute query and return result to QueryResult */
     QueryResult result = query.execute();
     /* transfer data to NodeIterator */
     NodeIterator nodes = result.getNodes();
     List<Book> books = new ArrayList<Book>();
     while (nodes.hasNext()) {
       Node node = nodes.nextNode();
       books.add(createBookByNode(node));
     }
     return books;
   } catch (RepositoryException re) {
     log.error("Can not find book", re);
     return null;
   } finally {
     sProvider.close();
   }
 }
コード例 #23
0
ファイル: JCRStore.java プロジェクト: sunnygao/liferay-portal
  public String[] getFileNames(long companyId, long repositoryId) throws SystemException {

    List<String> fileNames = new ArrayList<String>();

    Session session = null;

    try {
      session = JCRFactoryUtil.createSession();

      Node rootNode = getRootNode(session, companyId);

      Node repositoryNode = getFolderNode(rootNode, repositoryId);

      NodeIterator itr = repositoryNode.getNodes();

      while (itr.hasNext()) {
        Node node = (Node) itr.next();

        NodeType primaryNodeType = node.getPrimaryNodeType();

        String primaryNodeTypeName = primaryNodeType.getName();

        if (primaryNodeTypeName.equals(JCRConstants.NT_FILE)) {
          fileNames.add(node.getName());
        }
      }
    } catch (Exception e) {
      throw new SystemException(e);
    } finally {
      JCRFactoryUtil.closeSession(session);
    }

    return fileNames.toArray(new String[0]);
  }
コード例 #24
0
 /**
  * search book by name with limit of result(using SQL)
  *
  * @param name The name of book
  * @return List<Book>
  */
 public List<Book> searchBookByNameLimitSQL(String name) {
   /* replace "" sign and - sign */
   name = name.replaceAll("\"", "\\\"").replaceAll("-", StringUtils.EMPTY);
   /* create query string */
   StringBuffer sb = new StringBuffer("Select * from " + BookNodeTypes.EXO_BOOK);
   SessionProvider sProvider = SessionProvider.createSystemProvider();
   try {
     /* create QueryManager from session */
     QueryManager queryManager = getSession(sProvider).getWorkspace().getQueryManager();
     /* create QueryImpl object */
     QueryImpl query = (QueryImpl) queryManager.createQuery(sb.toString(), QueryImpl.SQL);
     /* set offset(which first record will be get) */
     query.setOffset(2);
     /* set limit(how many record will be get after offset) */
     query.setLimit(3);
     /* execute query and return result to QueryResult */
     QueryResult result = query.execute();
     /* transfer data to NodeIterator */
     NodeIterator nodes = result.getNodes();
     List<Book> books = new ArrayList<Book>();
     while (nodes.hasNext()) {
       Node node = nodes.nextNode();
       books.add(createBookByNode(node));
     }
     return books;
   } catch (RepositoryException re) {
     log.error("Can not find book", re);
     return null;
   } finally {
     sProvider.close();
   }
 }
コード例 #25
0
 /**
  * get all book in workspace
  *
  * @return List<Book>
  */
 public List<Book> getAllBook() {
   /* create query string */
   StringBuffer sb = new StringBuffer("Select * from " + BookNodeTypes.EXO_BOOK);
   SessionProvider sProvider = SessionProvider.createSystemProvider();
   try {
     /* create QueryManager from session */
     QueryManager queryManager = getSession(sProvider).getWorkspace().getQueryManager();
     /* create Query object */
     Query query = queryManager.createQuery(sb.toString(), Query.SQL);
     /* execute query and return result to QueryResult */
     QueryResult result = query.execute();
     /* transfer data to NodeIterator */
     NodeIterator nodes = result.getNodes();
     List<Book> books = new ArrayList<Book>();
     while (nodes.hasNext()) {
       Node node = nodes.nextNode();
       books.add(createBookByNode(node));
     }
     return books;
   } catch (RepositoryException re) {
     log.error("Can not find book", re);
     return null;
   } finally {
     sProvider.close();
   }
 }
コード例 #26
0
  @Test
  @FixFor("MODE-2109 ")
  public void shouldNotSupportRenamingsButShouldSupportMove() throws Exception {
    Node col1 = session.getRootNode().addNode("col1", "test:smallCollection");
    session.getRootNode().addNode("col2", "test:smallCollection");
    col1.addNode("child1");
    col1.addNode("child2");
    session.save();

    try {
      // reject renamings
      session.move("/col1/child1", "/col1/child3");
      fail("Renamings should not be supported for large collections");
    } catch (ConstraintViolationException e) {
      // expected
    }

    // but allow a normal move
    session.move("/col1/child1", "/col2/child1");
    session.save();
    NodeIterator nodes = session.getNode("/col1").getNodes();
    assertEquals(1, nodes.getSize());
    assertEquals("/col1/child2", nodes.nextNode().getPath());
    nodes = session.getNode("/col2").getNodes();
    assertEquals(1, nodes.getSize());
    assertEquals("/col2/child1", nodes.nextNode().getPath());
  }
コード例 #27
0
 /**
  * Checks if the {@link QueryResult} is ordered according order property in direction of related
  * argument.
  *
  * @param queryResult to be tested
  * @param propName Name of the porperty to order by
  * @param descending if <code>true</code> order has to be descending
  * @throws RepositoryException
  * @throws NotExecutableException in case of less than two results or all results have same size
  *     of value in its order-property
  */
 protected void evaluateResultOrder(QueryResult queryResult, String propName, boolean descending)
     throws RepositoryException, NotExecutableException {
   NodeIterator nodes = queryResult.getNodes();
   if (getSize(nodes) < 2) {
     fail("Workspace does not contain sufficient content to test ordering on result nodes.");
   }
   // need to re-aquire nodes, {@link #getSize} may consume elements.
   nodes = queryResult.getNodes();
   int changeCnt = 0;
   String last = descending ? "\uFFFF" : "";
   while (nodes.hasNext()) {
     String value = nodes.nextNode().getProperty(propName).getString();
     int cp = value.compareTo(last);
     // if value changed evaluate if the ordering is correct
     if (cp != 0) {
       changeCnt++;
       if (cp > 0 && descending) {
         fail("Repository doesn't order properly descending");
       } else if (cp < 0 && !descending) {
         fail("Repository doesn't order properly ascending");
       }
     }
     last = value;
   }
   if (changeCnt < 1) {
     fail("Workspace does not contain distinct values for " + propName);
   }
 }
コード例 #28
0
ファイル: JCRRaoImpl.java プロジェクト: smolnij/woowtest
  @Override
  public ImportantFile[] listFiles(String path) {
    ArrayList<ImportantFile> importantFiles = new ArrayList<ImportantFile>();
    try {
      NodeIterator itr = session.getRootNode().getNodes();
      if (path != null && !path.equals("")) {
        itr = session.getNode(path).getNodes();
      }

      while (itr.hasNext()) {
        Node currentNode = itr.nextNode();
        if (!isNodeVisible(currentNode)) {
          continue;
        }
        ImportantFile iF = new ImportantFile(currentNode.getPath(), isNodeFolder(currentNode));
        importantFiles.add(iF);

        //				PropertyIterator pi = currentNode.getProperties("jcr:primaryType");
        //				while (pi.hasNext()) {
        //					Property p = pi.nextProperty();
        //					LOG.debug("name - " + p.getName());
        //					LOG.debug("value - " + p.getValue());
        //				}

      }

    } catch (RepositoryException e) {
      LOG.error(e);
    }
    return importantFiles.toArray(new ImportantFile[importantFiles.size()]);
  }
コード例 #29
0
  @Test
  @FixFor("MODE-2109 ")
  public void shouldNotSupportSNS() throws Exception {
    Node col = session.getRootNode().addNode("smallCol", "test:smallCollection");
    col.addNode("child");

    try {
      col.addNode("child");
      fail("Unorderable collections should not support SNS");
    } catch (javax.jcr.ItemExistsException e) {
      // expected
    }
    session.refresh(false);
    col = session.getRootNode().addNode("smallCol", "test:smallCollection");
    col.addNode("child");
    session.save();
    col = session.getRootNode().getNode("smallCol");

    try {
      col.addNode("child");
      fail("Unorderable collections should not support SNS");
    } catch (javax.jcr.ItemExistsException e) {
      // expected
    }

    col.getNode("child").remove();
    Node child = col.addNode("child");
    child.setProperty("test", "test");
    session.save();

    NodeIterator nodes = session.getNode("/smallCol").getNodes();
    assertEquals(1, nodes.getSize());
    child = nodes.nextNode();
    assertEquals("test", child.getProperty("test").getString());
  }
コード例 #30
0
 public List<String> findPathList(String queryString) throws RepositoryException {
   List<String> result = new ArrayList<>();
   NodeIterator iterator = findNodes(queryString);
   while (iterator.hasNext()) {
     result.add(iterator.nextNode().getPath());
   }
   return result;
 }