Ejemplo n.º 1
0
  /*
   * (non-Javadoc)
   * @see
   * org.exoplatform.services.wcm.publication.WCMComposer#getContent(java.lang
   * .String, java.lang.String, java.lang.String, java.util.HashMap)
   */
  public Node getContent(
      String workspace,
      String nodeIdentifier,
      HashMap<String, String> filters,
      SessionProvider sessionProvider)
      throws Exception {
    String mode = filters.get(FILTER_MODE);
    String version = filters.get(FILTER_VERSION);
    String visibility = filters.get(FILTER_VISIBILITY);
    String remoteUser = getRemoteUser();
    String repository = null;

    try {
      repository = repositoryService.getCurrentRepository().getConfiguration().getName();
    } catch (Exception e) {
      if (LOG.isWarnEnabled()) {
        LOG.warn(e.getMessage());
      }
    }

    if (workspace == null) {
      if (nodeIdentifier.lastIndexOf("/") == 0) nodeIdentifier = nodeIdentifier.substring(1);
      String[] params = nodeIdentifier.split("/");
      workspace = params[1];
      try {
        nodeIdentifier = nodeIdentifier.substring(repository.length() + workspace.length() + 1);
      } catch (Exception e) {
        if (LOG.isWarnEnabled()) {
          LOG.warn(e.getMessage());
        }
      }
    }

    Node node = null;
    try {
      if (WCMComposer.VISIBILITY_PUBLIC.equals(visibility) && MODE_LIVE.equals(mode)) {
        sessionProvider =
            remoteUser == null
                ? aclSessionProviderService.getAnonymSessionProvider()
                : aclSessionProviderService.getACLSessionProvider(getAnyUserACL());
      }
      node = wcmService.getReferencedContent(sessionProvider, workspace, nodeIdentifier);
    } catch (RepositoryException e) {
      node = getNodeByCategory(nodeIdentifier);
    }
    if (version == null || !BASE_VERSION.equals(version)) {
      node = getViewableContent(node, filters);
    }

    return node;
  }
Ejemplo n.º 2
0
  public Result getPaginatedContents(
      NodeLocation nodeLocation, HashMap<String, String> filters, SessionProvider sessionProvider)
      throws Exception {
    String path = nodeLocation.getPath();
    String workspace = nodeLocation.getWorkspace();

    String mode = filters.get(FILTER_MODE);
    String version = filters.get(FILTER_VERSION);
    String orderBy = filters.get(FILTER_ORDER_BY);
    String orderType = filters.get(FILTER_ORDER_TYPE);
    String visibility = filters.get(FILTER_VISIBILITY);
    long offset = (filters.get(FILTER_OFFSET) != null) ? new Long(filters.get(FILTER_OFFSET)) : 0;
    long totalSize = (filters.get(FILTER_TOTAL) != null) ? new Long(filters.get(FILTER_TOTAL)) : 0;

    String remoteUser = getRemoteUser();

    if (MODE_EDIT.equals(mode) && "publication:liveDate".equals(orderBy)) {
      orderBy = "exo:dateModified";
      filters.put(FILTER_ORDER_BY, orderBy);
    }
    if (MODE_LIVE.equals(mode) && "exo:title".equals(orderBy)) {
      orderBy = "exo:titlePublished " + orderType + ", exo:title";
      filters.put(FILTER_ORDER_BY, orderBy);
    }

    if (LOG.isDebugEnabled())
      LOG.debug(
          "##### " + path + ":" + version + ":" + remoteUser + ":" + orderBy + ":" + orderType);

    NodeIterator nodeIterator;
    if (totalSize == 0) {
      SessionProvider systemProvider = WCMCoreUtils.getSystemSessionProvider();
      nodeIterator = getViewableContents(workspace, path, filters, systemProvider, false);
      if (nodeIterator != null) {
        totalSize = nodeIterator.getSize();
      }
    }

    if (WCMComposer.VISIBILITY_PUBLIC.equals(visibility) && MODE_LIVE.equals(mode)) {
      sessionProvider =
          remoteUser == null
              ? aclSessionProviderService.getAnonymSessionProvider()
              : aclSessionProviderService.getACLSessionProvider(getAnyUserACL());
    }

    nodeIterator = getViewableContents(workspace, path, filters, sessionProvider, true);
    List<Node> nodes = new ArrayList<Node>();
    Node node = null, viewNode = null;
    if (nodeIterator != null) {
      while (nodeIterator.hasNext()) {
        node = nodeIterator.nextNode();
        viewNode = getViewableContent(node, filters);
        if (viewNode != null) {
          nodes.add(viewNode);
        }
      }
    }
    Result result = new Result(nodes, offset, totalSize, nodeLocation, filters);

    return result;
  }
Ejemplo n.º 3
0
  public List<Node> getContents(
      String workspace,
      String path,
      HashMap<String, String> filters,
      SessionProvider sessionProvider)
      throws Exception {
    String mode = filters.get(FILTER_MODE);
    String version = filters.get(FILTER_VERSION);
    String orderBy = filters.get(FILTER_ORDER_BY);
    String orderType = filters.get(FILTER_ORDER_TYPE);
    String visibility = filters.get(FILTER_VISIBILITY);
    String remoteUser = null;
    if (WCMComposer.VISIBILITY_PUBLIC.equals(visibility)) {
      remoteUser = "******";
    } else {
      remoteUser = getRemoteUser();
    }

    if (MODE_EDIT.equals(mode) && "publication:liveDate".equals(orderBy)) {
      orderBy = "exo:dateModified";
      filters.put(FILTER_ORDER_BY, orderBy);
    }
    if ("exo:title".equals(orderBy)) {
      if (MODE_LIVE.equals(mode)) {
        orderBy = "exo:titlePublished " + orderType + ", exo:title";
      }
      if ("exo:taxonomy".equals(this.getTypeFromPath(workspace, path, sessionProvider))) {
        orderBy = "exo:name " + orderType + ", " + orderBy;
      }
      filters.put(FILTER_ORDER_BY, orderBy);
    }

    List<Node> nodes = new ArrayList<Node>();
    try {
      if (WCMComposer.VISIBILITY_PUBLIC.equals(visibility)
          && MODE_LIVE.equals(mode)
          && remoteUser != null) {
        sessionProvider = aclSessionProviderService.getACLSessionProvider(getAnyUserACL());
      }
      if (LOG.isDebugEnabled())
        LOG.debug(
            "##### " + path + ":" + version + ":" + remoteUser + ":" + orderBy + ":" + orderType);
      NodeIterator nodeIterator =
          getViewableContents(workspace, path, filters, sessionProvider, false);

      Node node = null, viewNode = null;
      while (nodeIterator != null && nodeIterator.hasNext()) {
        node = nodeIterator.nextNode();
        viewNode = getViewableContent(node, filters);
        if (viewNode != null) {
          nodes.add(viewNode);
        }
      }
    } catch (Exception e) {
      if (LOG.isWarnEnabled()) {
        LOG.warn(e.getMessage());
      }
    }

    return nodes;
  }