cmsresource.java
来自「找了很久才找到到源代码」· Java 代码 · 共 1,296 行 · 第 1/4 页
JAVA
1,296 行
/*
* File : $Source: /usr/local/cvs/opencms/src/org/opencms/file/CmsResource.java,v $
* Date : $Date: 2007-08-24 13:20:51 $
* Version: $Revision: 1.48 $
*
* This library is part of OpenCms -
* the Open Source Content Management System
*
* Copyright (c) 2002 - 2007 Alkacon Software GmbH (http://www.alkacon.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about Alkacon Software GmbH, please see the
* company website: http://www.alkacon.com
*
* For further information about OpenCms, please see the
* project website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.opencms.file;
import org.opencms.db.CmsResourceState;
import org.opencms.main.CmsIllegalArgumentException;
import org.opencms.util.A_CmsModeIntEnumeration;
import org.opencms.util.CmsStringUtil;
import org.opencms.util.CmsUUID;
import java.io.Serializable;
import java.util.Comparator;
/**
* Base class for all OpenCms VFS resources like <code>{@link CmsFile}</code> or <code>{@link CmsFolder}</code>.<p>
*
* The OpenCms VFS resource is an important object for using the OpenCms API.
* Basically, all entries in the OpenCms VFS are considered to be "resources".
* Currently, only two types of resources exists:<ul>
* <li>Files, which are represented by the subclass {@link CmsFile}.
* <li>Folders (also called Directories), which are represented by the subclass {@link CmsFolder}.
* </ul>
*
* If you have a resource, you can use {@link #isFile()} or {@link #isFolder()} to learn what kind of
* subclass you have. Please note that this is usually not required, as the only real difference between a
* {@link CmsFile} and a {@link CmsResource} is that the {@link CmsFile} also has the contents of the file,
* which you can obtain using {@link CmsFile#getContents()}. As long as you don't need the content, you can
* use the {@link CmsResource} for everything else. This is even more true for a {@link CmsFolder}, here you
* will need the subclass only in special cases, since the signature is identical to {@link CmsResource}.<p>
*
* A OpenCms VFS resource can have any number of properties attached, which are represented by a {@link CmsProperty}.
* To read the properties for a resource, use {@link CmsObject#readPropertyObject(CmsResource, String, boolean)}
* or use {@link CmsObject#readPropertyObjects(CmsResource, boolean)} to read all properties of the resource.<p>
*
* @author Alexander Kandzior
* @author Michael Emmerich
*
* @version $Revision: 1.48 $
*
* @since 6.0.0
*/
public class CmsResource extends Object implements Cloneable, Serializable, Comparable {
/**
* Enumeration class for resource copy modes.<p>
*/
public static final class CmsResourceCopyMode extends A_CmsModeIntEnumeration {
/** Copy mode for copy resources as new resource. */
protected static final CmsResourceCopyMode MODE_COPY_AS_NEW = new CmsResourceCopyMode(1);
/** Copy mode for copy resources as sibling. */
protected static final CmsResourceCopyMode MODE_COPY_AS_SIBLING = new CmsResourceCopyMode(2);
/** Copy mode to preserve siblings during copy. */
protected static final CmsResourceCopyMode MODE_COPY_PRESERVE_SIBLING = new CmsResourceCopyMode(3);
/** Version id required for safe serialization. */
private static final long serialVersionUID = 9081630878178799137L;
/**
* Private constructor.<p>
*
* @param mode the copy mode integer representation
*/
private CmsResourceCopyMode(int mode) {
super(mode);
}
/**
* Returns the copy mode object from the old copy mode integer.<p>
*
* @param mode the old copy mode integer
*
* @return the copy mode object
*/
public static CmsResourceCopyMode valueOf(int mode) {
switch (mode) {
case 1:
return CmsResourceCopyMode.MODE_COPY_AS_NEW;
case 2:
return CmsResourceCopyMode.MODE_COPY_AS_SIBLING;
case 3:
default:
return CmsResourceCopyMode.MODE_COPY_PRESERVE_SIBLING;
}
}
}
/**
* Enumeration class for resource delete modes.<p>
*/
public static final class CmsResourceDeleteMode extends A_CmsModeIntEnumeration {
/** Signals that siblings of this resource should not be deleted. */
protected static final CmsResourceDeleteMode MODE_DELETE_PRESERVE_SIBLINGS = new CmsResourceDeleteMode(1);
/** Signals that siblings of this resource should be deleted. */
protected static final CmsResourceDeleteMode MODE_DELETE_REMOVE_SIBLINGS = new CmsResourceDeleteMode(2);
/** Version id required for safe serialization. */
private static final long serialVersionUID = 2010402524576925865L;
/**
* Private constructor.<p>
*
* @param mode the delete mode integer representation
*/
private CmsResourceDeleteMode(int mode) {
super(mode);
}
/**
* Returns the delete mode object from the old delete mode integer.<p>
*
* @param mode the old delete mode integer
*
* @return the delete mode object
*/
public static CmsResourceDeleteMode valueOf(int mode) {
switch (mode) {
case 1:
return CmsResourceDeleteMode.MODE_DELETE_PRESERVE_SIBLINGS;
case 2:
default:
return CmsResourceDeleteMode.MODE_DELETE_REMOVE_SIBLINGS;
}
}
}
/**
* Enumeration class for resource undo changes modes.<p>
*/
public static final class CmsResourceUndoMode extends A_CmsModeIntEnumeration {
/** Indicates that the undo method will only undo content changes. */
public static final CmsResourceUndoMode MODE_UNDO_CONTENT = new CmsResourceUndoMode(1);
/** Indicates that the undo method will only recursive undo content changes. */
public static final CmsResourceUndoMode MODE_UNDO_CONTENT_RECURSIVE = new CmsResourceUndoMode(2);
/** Indicates that the undo method will undo move operations and content changes. */
public static final CmsResourceUndoMode MODE_UNDO_MOVE_CONTENT = new CmsResourceUndoMode(3);
/** Indicates that the undo method will undo move operations and recursive content changes. */
public static final CmsResourceUndoMode MODE_UNDO_MOVE_CONTENT_RECURSIVE = new CmsResourceUndoMode(4);
/** Version id required for safe serialization. */
private static final long serialVersionUID = 3521620626485212068L;
/**
* private constructor.<p>
*
* @param mode the undo changes mode integer representation
*/
private CmsResourceUndoMode(int mode) {
super(mode);
}
/**
* Returns the undo mode object from the old undo mode integer.<p>
*
* @param mode the old undo mode integer
*
* @return the undo mode object
*/
public static CmsResourceUndoMode valueOf(int mode) {
switch (mode) {
case 1:
return CmsResourceUndoMode.MODE_UNDO_CONTENT;
case 2:
return CmsResourceUndoMode.MODE_UNDO_CONTENT_RECURSIVE;
case 3:
return CmsResourceUndoMode.MODE_UNDO_MOVE_CONTENT;
case 4:
default:
return CmsResourceUndoMode.MODE_UNDO_MOVE_CONTENT_RECURSIVE;
}
}
/**
* Returns a mode that includes the move operation with the same semantic as this mode.<p>
*
* @return a mode that includes the move operation with the same semantic as this mode
*/
public CmsResourceUndoMode includeMove() {
if (!isUndoMove()) {
// keep the same semantic but including move
return CmsResourceUndoMode.valueOf(getMode() + 2);
}
return this;
}
/**
* Returns <code>true</code> if this undo operation is recursive.<p>
*
* @return <code>true</code> if this undo operation is recursive
*/
public boolean isRecursive() {
return getMode() > CmsResource.UNDO_CONTENT.getMode();
}
/**
* Returns <code>true</code> if this undo mode will undo move operations.<p>
*
* @return <code>true</code> if this undo mode will undo move operations
*/
public boolean isUndoMove() {
return getMode() > CmsResource.UNDO_CONTENT_RECURSIVE.getMode();
}
/**
* @see java.lang.Object#toString()
*/
public String toString() {
return String.valueOf(getMode());
}
}
/**
* A comparator for the release date of two resources.<p>
*
* If the release date of a resource is not set, the
* creation date is used instead.<p>
*/
public static final Comparator COMPARE_DATE_RELEASED = 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;
long date1 = r1.getDateReleased();
if (date1 == CmsResource.DATE_RELEASED_DEFAULT) {
// use last modification date if release date is not set
date1 = r1.getDateLastModified();
}
long date2 = r2.getDateReleased();
if (date2 == CmsResource.DATE_RELEASED_DEFAULT) {
// use last modification date if release date is not set
date2 = r2.getDateLastModified();
}
return (date1 > date2) ? -1 : (date1 < date2) ? 1 : 0;
}
};
/**
* A comparator for the root path of two resources.<p>
*/
public static final Comparator COMPARE_ROOT_PATH = 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;
return r1.getRootPath().compareTo(r2.getRootPath());
}
};
/**
* A comparator for the root path of two resources ignoring case differences.<p>
*/
public static final Comparator COMPARE_ROOT_PATH_IGNORE_CASE = new Comparator() {
/**
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
public int compare(Object o1, Object o2) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?