📄 cmsresource.java
字号:
resource = getFolderPath(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 true if the resource name is a folder name, i.e. ends with a "/".<p>
*
* @param resource the resource to check
* @return true if the resource name is a folder name, i.e. ends with a "/"
*/
public static boolean isFolder(String resource) {
return CmsStringUtil.isNotEmpty(resource) && (resource.charAt(resource.length() - 1) == '/');
}
/**
* Returns a clone of this Objects instance.<p>
*
* @return a clone of this instance
*/
public Object clone() {
CmsResource clone = new CmsResource(
m_structureId,
m_resourceId,
m_rootPath,
m_typeId,
m_isFolder,
m_flags,
m_projectLastModified,
m_state,
m_dateCreated,
m_userCreated,
m_dateLastModified,
m_userLastModified,
m_dateReleased,
m_dateExpired,
m_siblingCount,
m_length);
if (isTouched()) {
clone.setDateLastModified(m_dateLastModified);
}
return clone;
}
/**
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
public int compareTo(Object obj) {
if (obj == this) {
return 0;
}
if (obj instanceof CmsResource) {
return m_rootPath.compareTo(((CmsResource)obj).m_rootPath);
}
return 0;
}
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof CmsResource) {
return ((CmsResource)obj).m_structureId.equals(m_structureId);
}
return false;
}
/**
* Returns the date of the creation of this resource.<p>
*
* @return the date of the creation of this resource
*/
public long getDateCreated() {
return m_dateCreated;
}
/**
* Returns the expiration date this resource.<p>
*
* @return the expiration date of this resource
*/
public long getDateExpired() {
return m_dateExpired;
}
/**
* Returns the date of the last modification of this resource.<p>
*
* @return the date of the last modification of this resource
*/
public long getDateLastModified() {
return m_dateLastModified;
}
/**
* Returns the release date this resource.<p>
*
* @return the release date of this resource
*/
public long getDateReleased() {
return m_dateReleased;
}
/**
* Returns the flags of this resource.<p>
*
* @return the flags of this resource
*/
public int getFlags() {
return m_flags;
}
/**
* Returns the length of the resource.<p>
*
* If the resource is a file, then this is the byte size of the file content.
* If the resource is a folder, then the size is always -1.<p>
*
* @return the length of the content
*/
public int getLength() {
// make sure folders always have a -1 size
return m_isFolder ? -1 : m_length;
}
/**
* Returns the name of this resource, e.g. <code>index.html</code>.<p>
*
* @return the name of this resource
*/
public String getName() {
String name = getName(m_rootPath);
if (name.charAt(name.length() - 1) == '/') {
return name.substring(0, name.length() - 1);
} else {
return name;
}
}
/**
* Returns the id of the project where the resource has been last modified.<p>
*
* @return the id of the project where the resource has been last modified
*/
public int getProjectLastModified() {
return m_projectLastModified;
}
/**
* Returns the id of the resource database entry of this resource.<p>
*
* @return the id of the resource database entry
*/
public CmsUUID getResourceId() {
return m_resourceId;
}
/**
* Returns the name of a resource with it's full path from the root folder
* including the current site root,
* for example <code>/sites/default/myfolder/index.html</code>.<p>
*
* In a presentation level application usually the current site root must be
* cut of from the root path. Use {@link CmsObject#getSitePath(CmsResource)}
* to get the "absolute" path of a resource in the current site.<p>
*
* @return the name of a resource with it's full path from the root folder
* including the current site root
*
* @see CmsObject#getSitePath(CmsResource)
* @see CmsRequestContext#getSitePath(CmsResource)
* @see CmsRequestContext#removeSiteRoot(String)
*/
public String getRootPath() {
return m_rootPath;
}
/**
* Returns the number of siblings of the resource, also counting this resource.<p>
*
* If a resource has no sibling, the total sibling count for this resource is <code>1</code>,
* if a resource has <code>n</code> siblings, the sibling count is <code>n + 1</code>.<p>
*
* @return the number of siblings
*/
public int getSiblingCount() {
return m_siblingCount;
}
/**
* Returns the state of this resource.<p>
*
* This may be STATE_UNCHANGED, STATE_CHANGED, STATE_NEW or STATE_DELETED.<p>
*
* @return the state of this resource
*/
public int getState() {
return m_state;
}
/**
* Returns the id of the structure record of this resource.<p>
*
* @return the id of the structure record of this resource
*/
public CmsUUID getStructureId() {
return m_structureId;
}
/**
* Returns the resource type id for this resource.<p>
*
* @return the resource type id of this resource
*/
public int getTypeId() {
return m_typeId;
}
/**
* Returns the user id of the user who created this resource.<p>
*
* @return the user id
*/
public CmsUUID getUserCreated() {
return m_userCreated;
}
/**
* Returns the user id of the user who made the last change on this resource.<p>
*
* @return the user id of the user who made the last change<p>
*/
public CmsUUID getUserLastModified() {
return m_userLastModified;
}
/**
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
if (m_structureId != null) {
return m_structureId.hashCode();
}
return CmsUUID.getNullUUID().hashCode();
}
/**
* Returns <code>true</code> if the resource is a file, i.e. can have no sub-resources.<p>
*
* @return true if this resource is a file, false otherwise
*/
public boolean isFile() {
return !m_isFolder;
}
/**
* Returns <code>true</code> if the resource is a folder, i.e. can have sub-resources.<p>
*
* @return true if this resource is a folder, false otherwise
*/
public boolean isFolder() {
return m_isFolder;
}
/**
* Checks if the resource is internal.<p>
*
* This state is stored as bit 1 in the resource flags.<p>
*
* @return true if the resource is internal, otherwise false
*/
public boolean isInternal() {
return ((m_flags & FLAG_INTERNAL) > 0);
}
/**
* Checks if the link has to be labeled with a special icon in the explorer view.<p>
*
* This state is stored as bit 2 in the resource flags.<p>
*
* @return true if a link to the resource has to be labeled, otherwise false
*/
public boolean isLabeled() {
return ((m_flags & CmsResource.FLAG_LABELED) > 0);
}
/**
* Returns true if this resource was touched.<p>
*
* @return boolean true if this resource was touched
*/
public boolean isTouched() {
return m_isTouched;
}
/**
* Sets the expiration date this resource.<p>
*
* @param time the date to set
*/
public void setDateExpired(long time) {
m_dateExpired = time;
}
/**
* Sets the date of the last modification of this resource.<p>
*
* @param time the date to set
*/
public void setDateLastModified(long time) {
m_isTouched = true;
m_dateLastModified = time;
}
/**
* Sets the release date this resource.<p>
*
* @param time the date to set
*/
public void setDateReleased(long time) {
m_dateReleased = time;
}
/**
* Sets the flags of this resource.<p>
*
* @param flags int value with flag values to set
*/
public void setFlags(int flags) {
m_flags = flags;
}
/**
* Sets the state of this resource.<p>
*
* @param state the state to set
*/
public void setState(int state) {
m_state = state;
}
/**
* Sets the type of this resource.<p>
*
* @param type the type to set
*/
public void setType(int type) {
m_typeId = type;
}
/**
* Sets the user id of the user who changed this resource.<p>
*
* @param resourceLastModifiedByUserId the user id of the user who changed the resource
*/
public void setUserLastModified(CmsUUID resourceLastModifiedByUserId) {
m_userLastModified = resourceLastModifiedByUserId;
}
/**
* @see java.lang.Object#toString()
*/
public String toString() {
StringBuffer result = new StringBuffer();
result.append("[");
result.append(this.getClass().getName());
result.append(", path: ");
result.append(m_rootPath);
result.append(", structure id ");
result.append(m_structureId);
result.append(", resource id: ");
result.append(m_resourceId);
result.append(", type id: ");
result.append(m_typeId);
result.append(", folder: ");
result.append(m_isFolder);
result.append(", flags: ");
result.append(m_flags);
result.append(", project: ");
result.append(m_projectLastModified);
result.append(", state: ");
result.append(m_state);
result.append(", date created: ");
result.append(new java.util.Date(m_dateCreated));
result.append(", user created: ");
result.append(m_userCreated);
result.append(", date lastmodified: ");
result.append(new java.util.Date(m_dateLastModified));
result.append(", user lastmodified: ");
result.append(m_userLastModified);
result.append(", date released: ");
result.append(new java.util.Date(m_dateReleased));
result.append(", date expired: ");
result.append(new java.util.Date(m_dateExpired));
result.append(", size: ");
result.append(m_length);
result.append(" sibling count: ");
result.append(m_siblingCount);
result.append("]");
return result.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -