📄 cmsresourceutil.java
字号:
*
* <ul>
* <li>null: unchanged.</li>
* <li>true: locked in current project.</li>
* <li>false: not locked in current project.</li>
* </ul>
*
* @return the project state of the given resource
*/
public Boolean getProjectState() {
if (m_resource.getState() == CmsResource.STATE_UNCHANGED || !isInsideProject()) {
return null;
} else {
return new Boolean(getLockedInProjectId() == getReferenceProject().getId());
}
}
/**
* Returns the project to use to check project state.<p>
*
* @return the project to use to check project state
*/
public CmsProject getReferenceProject() {
if (m_referenceProject == null) {
if (m_request != null) {
m_referenceProject = m_request.currentProject();
}
}
return m_referenceProject;
}
/**
* Returns the resource.<p>
*
* @return the resource
*/
public CmsResource getResource() {
return m_resource;
}
/**
* Returns the resource type for the given resource.<p>
*
* @return the resource type for the given resource
*/
public I_CmsResourceType getResourceType() {
if (m_resourceType == null) {
try {
m_resourceType = OpenCms.getResourceManager().getResourceType(m_resource.getTypeId());
} catch (Throwable e) {
try {
m_resourceType = OpenCms.getResourceManager().getResourceType(
CmsResourceTypePlain.getStaticTypeId());
} catch (Throwable e1) {
// should never happen
m_resourceType = null;
}
}
}
return m_resourceType;
}
/**
* Returns the resource type id for the given resource.<p>
*
* @return the resource type id for the given resource
*/
public int getResourceTypeId() {
return getResourceType().getTypeId();
}
/**
* Returns the resource type name for the given resource.<p>
*
* @return the resource type name for the given resource
*/
public String getResourceTypeName() {
return getResourceType().getTypeName();
}
/**
* Returns the size of the given resource as a String.<p>
*
* For directories it returns {@link #SIZE_DIR}.<p>
*
* @return the size of the given resource as a String
*/
public String getSizeString() {
return m_resource.getLength() == -1 ? SIZE_DIR : "" + m_resource.getLength();
}
/**
* Returns resource state abbreviation.<p>
*
* @return resource state abbreviation
*/
public char getStateAbbreviation() {
int state = getResource().getState();
if (state >= 0 && state <= 3) {
return RESOURCE_STATE[state];
} else {
return RESOURCE_STATE[4];
}
}
/**
* Returns the state name for a resource.<p>
*
* Uses default locale if request context is <code>null</code>.<p>
*
* @return the state name for that resource
*/
public String getStateName() {
int state = m_resource.getState();
String name;
if (m_request == null) {
name = org.opencms.workplace.explorer.Messages.get().getBundle().key(
org.opencms.workplace.explorer.Messages.getStateKey(state));
} else {
name = org.opencms.workplace.explorer.Messages.get().getBundle(m_request.getLocale()).key(
org.opencms.workplace.explorer.Messages.getStateKey(state));
}
return name;
}
/**
* Returns the style class to use for the given resource.<p>
*
* @return style class name
*
* @see org.opencms.workplace.list.CmsListExplorerColumn#getExplorerStyleDef()
*/
public String getStyleClassName() {
if (isInsideProject() && isEditable()) {
switch (m_resource.getState()) {
case CmsResource.STATE_CHANGED:
return "fc";
case CmsResource.STATE_NEW:
return "fn";
case CmsResource.STATE_DELETED:
return "fd";
case CmsResource.STATE_UNCHANGED:
default:
return "nf";
}
}
return "fp";
}
/**
* Returns additional style sheets depending on publication constraints.<p>
*
* That is, depending on {@link CmsResource#getDateReleased()} and
* {@link CmsResource#getDateExpired()}.<p>
*
* @return additional style sheets depending on publication constraints
*/
public String getStyleRange() {
return isInRange() ? "" : "font-style:italic;";
}
/**
* Returns additional style sheets for the resource type icon depending on siblings.<p>
*
* That is, depending on {@link CmsResource#getSiblingCount()}
*
* Use it with the {@link #getIconPathExplorer} method.<p>
*
* @return additional style sheets depending on siblings
*/
public String getStyleSiblings() {
StringBuffer style = new StringBuffer(128);
if (m_resource.getSiblingCount() > 1) {
style.append("background-image:url(");
style.append(CmsWorkplace.getSkinUri());
style.append(getIconPathResourceType());
style.append("); background-position: 0px 0px; background-repeat: no-repeat; ");
}
return style.toString();
}
/**
* Returns the title of a resource.<p>
*
* @return the title for that resource
*/
public String getTitle() {
String title;
try {
title = getCms().readPropertyObject(
getCms().getSitePath(m_resource),
CmsPropertyDefinition.PROPERTY_TITLE,
false).getValue();
} catch (Throwable e) {
title = e.getMessage();
}
if (title == null) {
title = "";
}
return title;
}
/**
* Returns the name of the user who created the given resource.<p>
*
* @return the name of the user who created the given resource
*/
public String getUserCreated() {
String user = m_resource.getUserCreated().toString();
try {
user = getCms().readUser(m_resource.getUserCreated()).getName();
} catch (Throwable e) {
// ignore
}
return user;
}
/**
* Returns the name of the user who last modified the given resource.<p>
*
* @return the name of the user who last modified the given resource
*/
public String getUserLastModified() {
String user = m_resource.getUserLastModified().toString();
try {
user = getCms().readUser(m_resource.getUserLastModified()).getName();
} catch (Throwable e) {
// ignore
}
return user;
}
/**
* Returns <code>true</code> if the given resource is editable by the current user.<p>
*
* Retuns <code>false</code> if no request context is set.<p>
*
* @return <code>true</code> if the given resource is editable by the current user
*/
public boolean isEditable() {
if (m_request == null) {
return false;
}
CmsExplorerTypeSettings settings = OpenCms.getWorkplaceManager().getExplorerTypeSetting(getResourceTypeName());
if (settings != null) {
return settings.getAccess().getPermissions(getCms()).requiresWritePermission();
}
return false;
}
/**
* Returns <code>true</code> if the given resource has expired.<p>
*
* Retuns <code>true</code> if no request context is set.<p>
*
* @return <code>true</code> if the given resource has expired
*/
public boolean isExpired() {
if (m_request == null) {
return m_resource.getDateExpired() < System.currentTimeMillis();
}
return m_resource.getDateExpired() < m_request.getRequestTime();
}
/**
* Returns <code>true</code> if the given resource has been released and has not expired.<p>
*
* Retuns <code>false</code> if no request context is set.<p>
*
* @return <code>true</code> if the given resource has been released and has not expired
*/
public boolean isInRange() {
return isReleased() && !isExpired();
}
/**
* Returns <code>true</code> if the given resource is in the reference project.<p>
*
* Returns <code>false</code> if the request context is <code>null</code>.<p>
*
* @return <code>true</code> if the given resource is in the reference project
*
* @see #getReferenceProject()
*/
public boolean isInsideProject() {
if (m_projectResources == null) {
try {
m_projectResources = getCms().readProjectResources(getReferenceProject());
} catch (Throwable e) {
return false;
}
}
return CmsProject.isInsideProject(m_projectResources, m_resource);
}
/**
* Returns <code>true</code> if the given resource has been released.<p>
*
* @return <code>true</code> if the given resource has been released
*/
public boolean isReleased() {
if (m_request == null) {
return m_resource.getDateReleased() < System.currentTimeMillis();
}
return m_resource.getDateReleased() < m_request.getRequestTime();
}
/**
* Sets the cms context.<p>
*
* @param cms the cms context to set
*/
public void setCms(CmsObject cms) {
m_cms = cms;
m_request = cms.getRequestContext();
m_referenceProject = null;
m_projectResources = null;
}
/**
* Sets the project to use to check project state.<p>
*
* @param project the project to set
*/
public void setReferenceProject(CmsProject project) {
m_referenceProject = project;
m_projectResources = null;
}
/**
* Sets the resource.<p>
*
* @param resource the resource to set
*/
public void setResource(CmsResource resource) {
m_resource = resource;
m_lock = null;
m_resourceType = null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -