Exemplo n.º 1
0
  /**
   * Helper to convert a path into an indexed path which uniquely identifies a node
   *
   * @param nodeRef
   * @param path
   * @return
   */
  private Path createIndexedPath(NodeRef nodeRef, Path path) {
    // Add indexes for same name siblings
    // TODO: Look at more efficient approach
    for (int i = path.size() - 1; i >= 0; i--) {
      Path.Element pathElement = path.get(i);
      if (i > 0 && pathElement instanceof Path.ChildAssocElement) {
        int index = 1; // for xpath index compatibility
        String searchPath = path.subPath(i).toPrefixString(namespaceService);
        List<NodeRef> siblings =
            searchService.selectNodes(nodeRef, searchPath, null, namespaceService, false);
        if (siblings.size() > 1) {
          ChildAssociationRef childAssoc = ((Path.ChildAssocElement) pathElement).getRef();
          NodeRef childRef = childAssoc.getChildRef();
          for (NodeRef sibling : siblings) {
            if (sibling.equals(childRef)) {
              childAssoc.setNthSibling(index);
              break;
            }
            index++;
          }
        }
      }
    }

    return path;
  }
Exemplo n.º 2
0
  /**
   * @see org.alfresco.web.action.ActionEvaluator#evaluate(org.alfresco.web.bean.repository.Node)
   */
  public boolean evaluate(Node node) {
    final FacesContext fc = FacesContext.getCurrentInstance();
    final ServiceRegistry services = Repository.getServiceRegistry(fc);
    final NavigationBean navigator =
        (NavigationBean) FacesHelper.getManagedBean(fc, NavigationBean.BEAN_NAME);

    // get the path to the current name - compare last element with the Forms folder name
    final Path path = navigator.getCurrentNode().getNodePath();
    final Path.Element element = path.get(path.size() - 1);
    final String endPath = element.getPrefixedString(services.getNamespaceService());

    // check we have the permission to create nodes in that Forma folder
    return (Application.getContentFormsFolderName(fc).equals(endPath)
        && navigator.getCurrentNode().hasPermission(PermissionService.ADD_CHILDREN));
  }
Exemplo n.º 3
0
  /**
   * Return relative path between from and to references within export root
   *
   * @param fromRef from reference
   * @param toRef to reference
   * @return path
   */
  private Path createPath(NodeRef rootRef, NodeRef fromRef, NodeRef toRef) {
    // Check that item exists first
    if (!nodeService.exists(toRef)) {
      // return null path
      return null;
    }

    // Check whether item is the root node of the store
    // If so, always return absolute path
    if (toRef.equals(nodeService.getRootNode(toRef.getStoreRef()))) {
      return nodeService.getPath(toRef);
    }

    // construct relative path
    Path rootPath = createIndexedPath(rootRef, nodeService.getPath(rootRef));
    Path fromPath = createIndexedPath(fromRef, nodeService.getPath(fromRef));
    Path toPath = createIndexedPath(toRef, nodeService.getPath(toRef));
    Path relativePath = null;

    try {
      // Determine if 'to path' is a category
      // TODO: This needs to be resolved in a more appropriate manner - special support is
      //       required for categories.
      for (int i = 0; i < toPath.size(); i++) {
        Path.Element pathElement = toPath.get(i);
        if (pathElement.getPrefixedString(namespaceService).equals("cm:categoryRoot")) {
          Path.ChildAssocElement childPath = (Path.ChildAssocElement) pathElement;
          relativePath = new Path();
          relativePath.append(
              new Path.ChildAssocElement(
                  new ChildAssociationRef(null, null, null, childPath.getRef().getParentRef())));
          relativePath.append(toPath.subPath(i + 1, toPath.size() - 1));
          break;
        }
      }

      if (relativePath == null) {
        // Determine if from node is relative to export tree
        int i = 0;
        while (i < rootPath.size()
            && i < fromPath.size()
            && rootPath.get(i).equals(fromPath.get(i))) {
          i++;
        }
        if (i == rootPath.size()) {
          // Determine if to node is relative to export tree
          i = 0;
          while (i < rootPath.size()
              && i < toPath.size()
              && rootPath.get(i).equals(toPath.get(i))) {
            i++;
          }
          if (i == rootPath.size()) {
            // build relative path between from and to
            relativePath = new Path();
            for (int p = 0; p < fromPath.size() - i; p++) {
              relativePath.append(new Path.ParentElement());
            }
            if (i < toPath.size()) {
              relativePath.append(toPath.subPath(i, toPath.size() - 1));
            }
          }
        }
      }

      if (relativePath == null) {
        // default to absolute path
        relativePath = toPath;
      }
    } catch (Throwable e) {
      String msg =
          "Failed to determine relative path: root path="
              + rootPath
              + "; from path="
              + fromPath
              + "; to path="
              + toPath;
      throw new ExporterException(msg, e);
    }

    return relativePath;
  }
Exemplo n.º 4
0
  protected Set<String> getPaths(boolean primaryOnly) throws AfException {

    if (isNew()) {
      throw new AfException("this object is new, you can not get any paths");
    }

    if (!nodeRef.getStoreRef().equals(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE)) {
      throw new AfException("you cannot query the object's paths that is not in workspace");
    }

    NodeService nodeService = ServiceHelper.getNodeService(afSession);

    List<Path> ps = nodeService.getPaths(nodeRef, primaryOnly);
    Set<String> paths = new HashSet<String>();

    //		NodeRef parent = AFCHelper.getNodeRefByPath(afSession, "/");

    for (Path p : ps) {

      StringBuffer realPath = new StringBuffer();

      int length = p.size();
      for (int i = 0; i < length; i++) {

        QName qname = QName.createQName(p.get(i).getElementString());
        String fname = qname.getLocalName();

        if (fname.equals("/") || fname.equals("company_home")) {
          continue;
        } else if ("system".equals(fname) && i == 1) {
          break;
        }

        realPath.append('/');
        if (i == length - 1) {
          realPath.append(getObjectName());
        } else {
          realPath.append(ISO9075.decode(fname));
        }
      }

      if (realPath.length() != 0) {
        paths.add(realPath.toString());
      }
    }

    //		for (Path p : ps) {
    //
    //			NodeRef tmpParent = parent;
    //
    //			String realPath = "";
    //			for (int i = 0; i < p.size(); i++) {
    //				QName qname = QName.createQName(p.get(i).getElementString());
    //				String fname = qname.getLocalName();
    //
    //				if (fname.equals("/") || fname.equals("company_home")) {
    //					continue;
    //				}
    //
    //				String name = ISO9075.decode(fname);
    //
    //				tmpParent = getChildByAssName(nodeService, tmpParent, name);
    //
    //				if (tmpParent == null) {
    //					break;
    //				}
    //
    //				realPath += "/" + getNodeName(nodeService, tmpParent);
    //
    //			}
    //
    //			if (!realPath.equals("")) {
    // 				paths.add(realPath);
    //			}
    //
    //		}
    return paths;
  }