/**
  * Get total number of news for current state. (Performs additional JCR-SQL2 query to obtain
  * count!)
  *
  * @param path Start node path in hierarchy
  * @return long Number of news
  */
 public int getNewsCount(String path) throws RepositoryException {
   final String sqlNewsItems = buildQuery(path, NEWS_NODE_TYPE);
   return IteratorUtils.toList(
           QueryUtil.search(
               NewsWorkspaceUtil.COLLABORATION,
               sqlNewsItems,
               Query.JCR_SQL2,
               NewsNodeTypes.News.NAME))
       .size();
 }
  public static List<Node> getWrappedNodesFromQuery(
      String query, String nodeTypeName, String workspace) throws RepositoryException {
    final List<Node> itemsListPaged = new ArrayList<Node>(0);
    final NodeIterator items = QueryUtil.search(workspace, query, Query.JCR_SQL2, nodeTypeName);

    while (items.hasNext()) {
      itemsListPaged.add(new I18nNodeWrapper(items.nextNode()));
    }

    return itemsListPaged;
  }
  /**
   * Query items using JCR SQL2 syntax.
   *
   * @param query Query string
   * @param maxResultSize Max results returned
   * @param pageNumber paging number
   * @return List<Node> List of nodes
   * @throws javax.jcr.RepositoryException
   */
  public static List<Node> getWrappedNodesFromQuery(
      String query, int maxResultSize, int pageNumber, String nodeTypeName, String workspace)
      throws RepositoryException {
    final List<Node> itemsListPaged = new ArrayList<Node>(0);
    final NodeIterator items = QueryUtil.search(workspace, query, Query.JCR_SQL2, nodeTypeName);

    // Paging result set
    final int startRow = (maxResultSize * (pageNumber - 1));
    if (startRow > 0) {
      try {
        items.skip(startRow);
      } catch (NoSuchElementException e) {
        // log.error("No more blog items found beyond this item number: " + startRow);
      }
    }

    int count = 1;
    while (items.hasNext() && count <= maxResultSize) {
      itemsListPaged.add(new I18nNodeWrapper(items.nextNode()));
      count++;
    }

    return itemsListPaged;
  }