Exemplo n.º 1
0
  public File getLiveFileByFileName(String fileName, Folder folder) throws DotDataException {

    Identifier id = APILocator.getIdentifierAPI().find(folder);

    HibernateUtil hu = new HibernateUtil(File.class);
    hu.setSQLQuery(liveFileByName);
    hu.setParam(id.getPath());
    hu.setParam(fileName);

    return (File) hu.load();
  }
Exemplo n.º 2
0
  public List<NavResult> getChildren() throws Exception {
    if (children == null && hostId != null && folderId != null) {
      // lazy loadinge children
      Host host = APILocator.getHostAPI().find(hostId, sysuser, true);
      Folder folder = APILocator.getFolderAPI().find(folderId, sysuser, true);
      Identifier ident = APILocator.getIdentifierAPI().find(folder);
      NavResult lazyMe = NavTool.getNav(host, ident.getPath());
      children = lazyMe.getChildren();
      childrenFolderIds = lazyMe.getChildrenFolderIds();
    }
    if (children != null) {
      ArrayList<NavResult> list = new ArrayList<NavResult>();
      for (NavResult nn : children) {
        if (nn.isFolder()) {
          // for folders we avoid returning the same instance
          // it could be changed elsewhere and we need it to
          // load its children lazily
          NavResult ff = new NavResult(folderId, nn.hostId, nn.folderId);
          ff.setTitle(nn.getTitle());
          ff.setHref(nn.getHref());
          ff.setOrder(nn.getOrder());
          ff.setType(nn.getType());
          ff.setPermissionId(nn.getPermissionId());
          list.add(ff);
        } else {
          list.add(nn);
        }
      }

      if (checkPermissions) {
        // now filtering permissions
        List<NavResult> allow = new ArrayList<NavResult>(list.size());
        Context ctx = (VelocityContext) VelocityServlet.velocityCtx.get();
        HttpServletRequest req = (HttpServletRequest) ctx.get("request");
        User currentUser = WebAPILocator.getUserWebAPI().getLoggedInUser(req);
        if (currentUser == null) currentUser = APILocator.getUserAPI().getAnonymousUser();
        for (NavResult nv : list) {
          try {
            if (APILocator.getPermissionAPI()
                .doesUserHavePermission(nv, PermissionAPI.PERMISSION_READ, currentUser)) {
              allow.add(nv);
            }
          } catch (Exception ex) {
            Logger.error(this, ex.getMessage(), ex);
          }
        }
        return allow;
      } else return list;
    } else {
      return new ArrayList<NavResult>();
    }
  }