cmsresource.java
来自「找了很久才找到到源代码」· Java 代码 · 共 1,296 行 · 第 1/4 页
JAVA
1,296 行
if ((o1 == o2) || !(o1 instanceof CmsResource) || !(o2 instanceof CmsResource)) {
return 0;
}
CmsResource r1 = (CmsResource)o1;
CmsResource r2 = (CmsResource)o2;
return r1.getRootPath().compareToIgnoreCase(r2.getRootPath());
}
};
/**
* A comparator for the root path of two resources ignoring case differences, putting folders before files.<p>
*/
public static final Comparator COMPARE_ROOT_PATH_IGNORE_CASE_FOLDERS_FIRST = new Comparator() {
/**
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
public int compare(Object o1, Object o2) {
if ((o1 == o2) || !(o1 instanceof CmsResource) || !(o2 instanceof CmsResource)) {
return 0;
}
CmsResource r1 = (CmsResource)o1;
CmsResource r2 = (CmsResource)o2;
if (r1.isFolder() && !r2.isFolder()) {
return -1;
} else if (r2.isFolder() && !r1.isFolder()) {
return 1;
}
// if same type, compare the name of the resource
return r1.getRootPath().compareToIgnoreCase(r2.getRootPath());
}
};
/** Copy mode for copy resources as new resource. */
public static final CmsResourceCopyMode COPY_AS_NEW = CmsResourceCopyMode.MODE_COPY_AS_NEW;
/** Copy mode for copy resources as sibling. */
public static final CmsResourceCopyMode COPY_AS_SIBLING = CmsResourceCopyMode.MODE_COPY_AS_SIBLING;
/** Copy mode to preserve siblings during copy. */
public static final CmsResourceCopyMode COPY_PRESERVE_SIBLING = CmsResourceCopyMode.MODE_COPY_PRESERVE_SIBLING;
/** The default expiration date of a resource, which is: never expires. */
public static final long DATE_EXPIRED_DEFAULT = Long.MAX_VALUE;
/** The default release date of a resource, which is: always released. */
public static final long DATE_RELEASED_DEFAULT = 0;
/** A special date that indicates release and expiration information are to be ignored. */
public static final long DATE_RELEASED_EXPIRED_IGNORE = Long.MIN_VALUE;
/** Signals that siblings of this resource should not be deleted. */
public static final CmsResourceDeleteMode DELETE_PRESERVE_SIBLINGS = CmsResourceDeleteMode.MODE_DELETE_PRESERVE_SIBLINGS;
/** Signals that siblings of this resource should be deleted. */
public static final CmsResourceDeleteMode DELETE_REMOVE_SIBLINGS = CmsResourceDeleteMode.MODE_DELETE_REMOVE_SIBLINGS;
/** Flag to indicate that this is an internal resource, that can't be accessed directly. */
public static final int FLAG_INTERNAL = 512;
/** The resource is linked inside a site folder specified in the OpenCms configuration. */
public static final int FLAG_LABELED = 2;
/** Flag to indicate that this is a temporary resource. */
public static final int FLAG_TEMPFILE = 1024;
/** The name constraints when generating new resources. */
public static final String NAME_CONSTRAINTS = "-._~$";
/** Indicates if a resource has been changed in the offline version when compared to the online version. */
public static final CmsResourceState STATE_CHANGED = CmsResourceState.STATE_CHANGED;
/** Indicates if a resource has been deleted in the offline version when compared to the online version. */
public static final CmsResourceState STATE_DELETED = CmsResourceState.STATE_DELETED;
/**
* Special state value that indicates the current state must be kept on a resource,
* this value must never be written to the database.
*/
public static final CmsResourceState STATE_KEEP = CmsResourceState.STATE_KEEP;
/** Indicates if a resource is new in the offline version when compared to the online version. */
public static final CmsResourceState STATE_NEW = CmsResourceState.STATE_NEW;
/** Indicates if a resource is unchanged in the offline version when compared to the online version. */
public static final CmsResourceState STATE_UNCHANGED = CmsResourceState.STATE_UNCHANGED;
/** Flag for leaving a date unchanged during a touch operation. */
public static final long TOUCH_DATE_UNCHANGED = -1;
/** Indicates that the undo method will only undo content changes. */
public static final CmsResourceUndoMode UNDO_CONTENT = CmsResourceUndoMode.MODE_UNDO_CONTENT;
/** Indicates that the undo method will only recursive undo content changes. */
public static final CmsResourceUndoMode UNDO_CONTENT_RECURSIVE = CmsResourceUndoMode.MODE_UNDO_CONTENT_RECURSIVE;
/** Indicates that the undo method will undo move operations and content changes. */
public static final CmsResourceUndoMode UNDO_MOVE_CONTENT = CmsResourceUndoMode.MODE_UNDO_MOVE_CONTENT;
/** Indicates that the undo method will undo move operations and recursive content changes. */
public static final CmsResourceUndoMode UNDO_MOVE_CONTENT_RECURSIVE = CmsResourceUndoMode.MODE_UNDO_MOVE_CONTENT_RECURSIVE;
/** The vfs path of the sites master folder. */
public static final String VFS_FOLDER_SITES = "/sites";
/** The vfs path of the system folder. */
public static final String VFS_FOLDER_SYSTEM = "/system";
/** Serial version UID required for safe serialization. */
private static final long serialVersionUID = 257325098790850498L;
/** The date of the last modification of the content of this resource. */
protected long m_dateContent = System.currentTimeMillis();
/** The size of the content. */
protected int m_length;
/** The creation date of this resource. */
private long m_dateCreated;
/** The expiration date of this resource. */
private long m_dateExpired;
/** The date of the last modification of this resource. */
private long m_dateLastModified;
/** The release date of this resource. */
private long m_dateReleased;
/** The flags of this resource. */
private int m_flags;
/** Indicates if this resource is a folder or not. */
private boolean m_isFolder;
/** Boolean flag whether the timestamp of this resource was modified by a touch command. */
private boolean m_isTouched;
/** The project id where this resource has been last modified in. */
private CmsUUID m_projectLastModified;
/** The id of the resource database record. */
private CmsUUID m_resourceId;
/** The name of a resource with it's full path from the root folder including the current site root. */
private String m_rootPath;
/** The number of links that point to this resource. */
private int m_siblingCount;
/** The state of this resource. */
private CmsResourceState m_state;
/** The id of the structure database record. */
private CmsUUID m_structureId;
/** The resource type id of this resource. */
private int m_typeId;
/** The id of the user who created this resource. */
private CmsUUID m_userCreated;
/** The id of the user who modified this resource last. */
private CmsUUID m_userLastModified;
/** The version number of this resource. */
private int m_version;
/**
* Creates a new CmsRecource object.<p>
*
* @param structureId the id of this resources structure record
* @param resourceId the id of this resources resource record
* @param rootPath the root path to the resource
* @param type the type of this resource
* @param isFolder must be true if the resource is a folder, or false if it is a file
* @param flags the flags of this resource
* @param projectId the project id this resource was last modified in
* @param state the state of this resource
* @param dateCreated the creation date of this resource
* @param userCreated the id of the user who created this resource
* @param dateLastModified the date of the last modification of this resource
* @param userLastModified the id of the user who did the last modification of this resource
* @param dateReleased the release date of this resource
* @param dateExpired the expiration date of this resource
* @param linkCount the count of all siblings of this resource
* @param size the size of the file content of this resource
* @param dateContent the date of the last modification of the content of this resource
* @param version the version number of this resource
*/
public CmsResource(
CmsUUID structureId,
CmsUUID resourceId,
String rootPath,
int type,
boolean isFolder,
int flags,
CmsUUID projectId,
CmsResourceState state,
long dateCreated,
CmsUUID userCreated,
long dateLastModified,
CmsUUID userLastModified,
long dateReleased,
long dateExpired,
int linkCount,
int size,
long dateContent,
int version) {
m_structureId = structureId;
m_resourceId = resourceId;
m_rootPath = rootPath;
m_typeId = type;
m_isFolder = isFolder;
m_flags = flags;
m_projectLastModified = projectId;
m_state = state;
m_dateCreated = dateCreated;
m_userCreated = userCreated;
m_dateLastModified = dateLastModified;
m_userLastModified = userLastModified;
m_dateReleased = dateReleased;
m_dateExpired = dateExpired;
m_siblingCount = linkCount;
m_length = size;
m_dateContent = dateContent;
m_version = version;
m_isTouched = false;
}
/**
* Checks if the provided resource name is a valid resource name,
* that is contains only valid characters.<p>
*
* A resource name can only be composed of digits,
* standard ASCII letters and the symbols defined in {@link #NAME_CONSTRAINTS}.
* A resource name must also not contain only dots.<p>
*
* @param name the resource name to check
*
* @throws CmsIllegalArgumentException if the given resource name is not valid
*/
public static void checkResourceName(String name) throws CmsIllegalArgumentException {
if (CmsStringUtil.isEmptyOrWhitespaceOnly(name)) {
throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_BAD_RESOURCENAME_EMPTY_0, name));
}
CmsStringUtil.checkName(name, NAME_CONSTRAINTS, Messages.ERR_BAD_RESOURCENAME_4, Messages.get());
// check for filenames that have only dots (which will cause issues in the static export)
boolean onlydots = true;
// this must be done only for the last name (not for parent folders)
String lastName = CmsResource.getName(name);
int l = lastName.length();
for (int i = 0; i < l; i++) {
char c = lastName.charAt(i);
if ((c != '.') && (c != '/')) {
onlydots = false;
}
}
if (onlydots) {
throw new CmsIllegalArgumentException(Messages.get().container(
Messages.ERR_BAD_RESOURCENAME_DOTS_1,
lastName));
}
}
/**
* Returns the folder path of the resource with the given name.<p>
*
* If the resource name denotes a folder (that is ends with a "/"), the complete path of the folder
* is returned (not the parent folder path).<p>
*
* This is achieved by just cutting of everything behind the last occurrence 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 getFolderPath(String resource) {
return resource.substring(0, resource.lastIndexOf('/') + 1);
}
/**
* Returns the name of a resource without the path information.<p>
*
* The resource name of a file is the name of the file.
* The resource name of a folder is the folder name with trailing "/".
* The resource name of the root folder is <code>/</code>.<p>
*
* Example: <code>/system/workplace/</code> has the resource name <code>workplace/</code>.
*
* @param resource the resource to get the name for
* @return the name of a resource without the path information
*/
public static String getName(String resource) {
if ("/".equals(resource)) {
return "/";
}
// 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 resource.substring(parent.lastIndexOf('/') + 1);
}
/**
* Returns the absolute parent folder name of a resource.<p>
*
* The parent resource of a file is the folder of the file.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?