Example #1
0
 /**
  * Get an item by a ItemLocation object.
  *
  * @param itemLocation the ItemLocation object
  * @return an item
  */
 public static final Item getItemByLocation(final ItemLocation itemLocation) {
   Session session = null;
   try {
     ManageableRepository repository = WCMCoreUtils.getRepository();
     session =
         (itemLocation.isSystemSession
                 ? WCMCoreUtils.getSystemSessionProvider()
                 : WCMCoreUtils.getUserSessionProvider())
             .getSession(itemLocation.getWorkspace(), repository);
     if (itemLocation.getUUID() != null) return session.getNodeByUUID(itemLocation.getUUID());
     else {
       return session.getItem(itemLocation.getPath());
     }
   } catch (PathNotFoundException pne) {
     return null;
   } catch (Exception e) {
     return null;
   }
 }
Example #2
0
  @Override
  public List<Mail> getCategorizedMails(String token, String categoryId)
      throws RepositoryException, DatabaseException {
    log.debug("getCategorizedMails({}, {})", token, categoryId);
    List<Mail> mails = new ArrayList<Mail>();
    Session session = null;

    try {
      if (token == null) {
        session = JCRUtils.getSession();
      } else {
        session = JcrSessionManager.getInstance().get(token);
      }

      Node category = session.getNodeByUUID(categoryId);

      for (PropertyIterator it = category.getReferences(); it.hasNext(); ) {
        Property refProp = it.nextProperty();

        if (com.openkm.bean.Property.CATEGORIES.equals(refProp.getName())) {
          Node node = refProp.getParent();

          if (node.isNodeType(Mail.TYPE)) {
            Mail mail = BaseMailModule.getProperties(session, node);
            mails.add(mail);
          }
        }
      }
    } catch (javax.jcr.RepositoryException e) {
      log.error(e.getMessage(), e);
      throw new RepositoryException(e.getMessage(), e);
    } finally {
      if (token == null) JCRUtils.logout(session);
    }

    log.debug("getCategorizedMails: {}", mails);
    return mails;
  }
Example #3
0
  /**
   * gets a Node list from a NodeLocation list
   *
   * @param locationList NodeLocation list
   * @return the Node list
   */
  @SuppressWarnings("unchecked")
  public static final List getNodeListByLocationList(final List locationList) {
    List ret = new ArrayList();
    try {
      ManageableRepository repository = WCMCoreUtils.getRepository();
      SessionProvider systemSessionProvider = WCMCoreUtils.getSystemSessionProvider();
      SessionProvider sessionProvider = WCMCoreUtils.getUserSessionProvider();
      String systemWorkspace = repository.getConfiguration().getSystemWorkspaceName();
      Session session = null;
      Node node;
      for (Object obj : locationList)
        if (obj instanceof NodeLocation) {
          node = null;
          try {
            NodeLocation location = (NodeLocation) obj;
            session =
                (systemWorkspace.equals(location.getWorkspace()) || location.isSystemSession)
                    ? systemSessionProvider.getSession(location.getWorkspace(), repository)
                    : sessionProvider.getSession(location.getWorkspace(), repository);

            node =
                location.getUUID() != null
                    ? session.getNodeByUUID(location.getUUID())
                    : (Node) session.getItem(location.getPath());
            ret.add(node);
          } catch (Exception e) {
            if (LOG.isWarnEnabled()) {
              LOG.warn(e.getMessage());
            }
          }
        } else {
          ret.add(obj);
        }
    } catch (Exception e) {
      return ret;
    }
    return ret;
  }
Example #4
0
 public Node getNodeByUUID(String uuid, String workspaceName) throws Exception {
   ManageableRepository repo =
       getApplicationComponent(RepositoryService.class).getCurrentRepository();
   Session session = WCMCoreUtils.getSystemSessionProvider().getSession(workspaceName, repo);
   return session.getNodeByUUID(uuid);
 }