⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmsresource.java

📁 内容管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * The parent resource of a file is the folder of the file.
     * The parent resource of a folder is the parent folder.
     * The parent resource of the root folder is <code>null</code>.<p>
     * 
     * Example: <code>/system/workplace/</code> has the parent <code>/system/</code>.
     * 
     * @return the calculated parent absolute folder path, or <code>null</code> for the root folder 
     */
     public String getParent() {
        return getParent(getAbsolutePath());
     }
     
    /**
     * Returns the absolute parent folder name of a resource.<p>
     * 
     * The parent resource of a file is the folder of the file.
     * The parent resource of a folder is the parent folder.
     * The parent resource of the root folder is <code>null</code>.<p>
     * 
     * Example: <code>/system/workplace/</code> has the parent <code>/system/</code>.
     * 
     * @param resource the resource to find the parent folder for
     * @return the calculated parent absolute folder path, or <code>null</code> for the root folder 
     */
    public static String getParent(String resource) {
        if (C_ROOT.equals(resource)) return null;
        // remove the last char, for a folder this will be "/", for a file it does not matter
        String parent = (resource.substring(0, resource.length() - 1));
        // now as the name does not end with "/", check for the last "/" which is the parent folder name
        return parent.substring(0, parent.lastIndexOf("/") + 1);
    }
    
    /**
     * Returns the folder path of this resource,
     * if the resource is a folder, the complete path of the folder is returned 
     * (not the parent folder path).<p>
     * 
     * Example: Returns <code>/system/def/</code> for the
     * resource <code>/system/def/file.html</code> and 
     * <code>/system/def/</code> for the (folder) resource <code>/system/def/</code>.
     * 
     * Does not append the repository information to the result, 
     * i.e. <code>/system/def/</code> will be returned, not <code>/default/vfs/system/def/</code>.
     *
     * @return the folder of this resource
     */
    public String getPath() {
        return getPath(getAbsolutePath());
    }
    
    /**
     * Returns the folder path of the resource with the given name,
     * if the resource is a folder (i.e. ends with a "/"), the complete path of the folder 
     * is returned (not the parent folder path).<p>
     * 
     * This is achived by just cutting of everthing behind the last occurence of a "/" character
     * in the String, no check if performed if the resource exists or not in the VFS, 
     * only resources that end with a "/" are considered to be folders.
     * 
     * Example: Returns <code>/system/def/</code> for the
     * resource <code>/system/def/file.html</code> and 
     * <code>/system/def/</code> for the (folder) resource <code>/system/def/</code>..
     *
     * @param resource the name of a resource
     * @return the folder of the given resource
     */
    public static String getPath(String resource) {
        return resource.substring(0, resource.lastIndexOf("/") + 1);
    }
        
    /**
     * Returns the name of a parent folder of the given resource, 
     * that is either minus levels up 
     * from the current folder, or that is plus levels down from the 
     * root folder.<p>
     * 
     * @param resource the name of a resource
     * @param number of levels to walk up or down
     * @return the name of a parent folder of the given resource, 
     * that is either minus levels up 
     * from the current folder, or that is plus levels down from the 
     * root folder
     */
    public static String getPathPart(String resource, int level) {
        resource = getPath(resource); 
        String result = null;
        int pos = 0, count = 0;
        if (level >= 0) {
            // Walk down from the root folder /
            while ((count < level) && (pos > -1)) {
                count ++;
                pos = resource.indexOf('/', pos+1);
            }
        } else {
            // Walk up from the current folder
            pos = resource.length();
            while ((count > level) && (pos > -1)) {
                count--;
                pos = resource.lastIndexOf('/', pos-1);
            }      
        }
        if (pos > -1) {
            // To many levels walked
            result = resource.substring(0, pos+1);
        } else {
            // Add trailing slash
            result = (level < 0)?"/":resource;
        }        
        return result;
    }
    
    /**
     * Returns the directory level of a resource.<p>
     * 
     * The root folder "/" has level 0,
     * a folder "/foo/" would have level 1,
     * a folfer "/foo/bar/" level 2 etc.<p> 
     * 
     * @return the directory level of a resource
     */
    public static int getPathLevel(String resource) {
        int level = -1;
        int pos = 0;
        while (resource.indexOf('/', pos) >= 0) {
            pos = resource.indexOf('/', pos) + 1;
            level++;
        }
        return level;
    }    
        
    /**
     * Gets the Parent database id for this resource.
     *
     * @return the Parent database id of this resource.
     */
    public int getParentId() {
        return m_parentId;
    }
          
    /**
     * Returns the project id for this resource.
     *
     * @return the project id for this resource.
     */
    public int getProjectId() {
        return m_projectId;
    }
      
    /**
     * Gets the database id for this resource.
     *
     * @return the database id of this resource.
     */
     public int getResourceId(){
        return m_resourceId;
     }
    /**
     * Gets the userId from the user who made the last change.
     *
     * @return the userId from the user who made the last change.
     */
     public int getResourceLastModifiedBy(){
        return m_resourceLastModifiedBy;
     }
    /**
     * Returns the state of this resource.<BR/>
     * This may be C_STATE_UNCHANGED, C_STATE_CHANGED, C_STATE_NEW or C_STATE_DELETED.
     *
     * @return the state of this resource.
     */
      public int getState() {
      return m_state;
      }
    /**
     * Gets the type id for this resource.
     *
     * @return the type id of this resource.
     */
     public int getType() {
       return m_resourceType;
     }
    /**
     * Gets the project id of the project that has locked this resource.
     *
     * @return the project id.
     */
     public int getLockedInProject() {
       return m_lockedInProject;
     }
     /**
      * Checks if a resource belongs to a project.
      * @param project The project which the resources is checked about.
      * @return true if the resource is in the project, false otherwise.
      */
     public boolean inProject(CmsProject project){
         boolean inProject=false;
         if (project.getId() == m_projectId) {
             inProject=true;
         }
         return inProject;
     }
    /**
     * Determines, if this resource is a file.
     *
     * @return true, if this resource is a file, else it returns false.
     */
      public boolean isFile() {
         boolean isFile=true;
         if (m_resourceName.endsWith("/")){
             isFile=false;
         }
         return isFile;
      }
    /**
     * Determines, if this resource is a folder.
     *
     * @return true, if this resource is a folder, else it returns false.
     */
      public boolean isFolder(){
         boolean isFolder=false;
         if (m_resourceName.endsWith("/")){
             isFolder=true;
         }
         return isFolder;

      }
    /**
     * Determines, if this resource is locked by a user.
     *
     * @return true, if this resource is locked by a user, else it returns false.
     */
      public boolean isLocked() {
          boolean isLocked=true;
          //check if the user id in the locked by field is the unknown user id.
          if (m_lockedBy == C_UNKNOWN_ID) {
              isLocked=false;
          }
          return isLocked;
      }
    /**
     * Returns the user idthat locked this resource.
     *
     * @return the user id that locked this resource.
     * If this resource is free it returns the unknown user id.
     */
      public int isLockedBy() {
        return m_lockedBy;
      }
     /**
     * Sets the accessflags of this resource.
     *
     * @param The new accessflags of this resource.
     */
      public void setAccessFlags(int flags){
          m_accessFlags=flags;
      }
    /**
     * Sets the File id for this resource.
     *
     * @param The File id of this resource.
     */
    public void setFileId(int fileId){
        m_fileId = fileId;
    }
     /**
     * Sets the flags of this resource.
     *
     * @param The new flags of this resource.
     */
      void setFlags(int flags){
          m_resourceFlags=flags;
      }
    /**
     * Sets the groupId of this resource.
     *
     * @param The new groupId of this resource.
     */
      public void setGroupId(int group) {
          m_group= group;
      }
     /**
     * Sets launcher classname for this resource.
     *
     * @param The new launcher classname for this resource.
     */
     void setLauncherClassname(String name) {
      m_launcherClassname=name;
         }
     /**
     * Sets launcher the type id for this resource.
     *
     * @param The new launcher type id of this resource.
     */
     public void setLauncherType(int type){
         m_launcherType=type;
     }
     /**
     * Sets the the user id that locked this resource.
     *
     * @param The new the user id that locked this resource.
     */
     public void setLocked(int id) {
          m_lockedBy=id;
      }
     /**
     * Sets the parent database id for this resource.
     *
     * @param The new database id of this resource.
     */
    public void setParentId(int parentId){
        m_parentId = parentId;
    }
    /**
     * Sets the user id from the user who changes the resource.
     *
     * @param The userId from the user who changes the resource.
     */
    void setResourceLastModifiedBy(int resourceLastModifiedBy){
        m_resourceLastModifiedBy = resourceLastModifiedBy;
    }
      /**
     * Sets the state of this resource.
     *
     * @param The new state of this resource.
     */
      public void setState(int state) {
          m_state=state;
      }
     /**
     * Sets the type id for this resource.
     *
     * @param The new type id of this resource.
     */
     public void setType(int type) {
         m_resourceType=type;
     }
    /**
     * Sets the userId of this resource.
     *
     * @param The new userId of this resource.
     */
    public  void setUserId(int user) {
          m_user = user;
      }

    /**
     * Sets the projectId of this resource.
     *
     * @param The new projectId of this resource.
     */
    public  void setProjectId(int project) {
          m_projectId = project;
      }


    /**
     * Sets the projectId in which this resource is locked.
     *
     * @param The new projectId of this resource.
     */
    public  void setLockedInProject(int project) {
          m_lockedInProject = project;
      }

    /**
     * Returns a string-representation for this object.
     * This can be used for debugging.
     *
     * @return string-representation for this object.
     */
      public String toString() {
        StringBuffer output=new StringBuffer();
        output.append("[Resource]:");
        output.append(m_resourceName);
        output.append(" ID: ");
        output.append(m_resourceId);
        output.append(" ParentID: ");
        output.append(m_parentId);
        output.append(" , Project=");
        output.append(m_projectId);
        output.append(" , User=");
        output.append(m_user);
        output.append(" , Group=");
        output.append(m_group);
        output.append(" : Access=");
        output.append(getFlagString());
        output.append(" : Resource-type=");
        output.append(getType());
        output.append(" : Locked=");
        output.append(isLockedBy());
        output.append(" : length=");
        output.append(getLength());
        output.append(" : state=");
        output.append(getState());
        return output.toString();
      }
	/**
	 * Returns the isTouched.
	 * @return boolean
	 */
	public boolean isTouched() {
		return m_isTouched;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -