📄 cmsrelationtype.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/org/opencms/relations/CmsRelationType.java,v $
* Date : $Date: 2007-08-13 16:30:03 $
* Version: $Revision: 1.3 $
*
* 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.relations;
import org.opencms.main.CmsIllegalArgumentException;
import org.opencms.main.CmsInitException;
import org.opencms.main.OpenCms;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
/**
* Wrapper class for
* the different types of relations.<p>
*
* The possibles values are:<br>
* <ul>
* <li>{@link #HYPERLINK}</li>
* <li>{@link #EMBEDDED_IMAGE}</li>
* <li>{@link #EMBEDDED_OBJECT}</li>
* <li>{@link #XML_STRONG}</li>
* <li>{@link #XML_WEAK}</li>
* <li>{@link #JSP_STRONG}</li>
* <li>{@link #JSP_WEAK}</li>
* <li>{@link #OU_RESOURCE}</li>
* <li>{@link #CATEGORY}</li>
* </ul>
* <p>
*
* User defined relation types are also available.<p>
*
* @author Michael Moossen
*
* @version $Revision: 1.3 $
*
* @since 6.3.0
*/
public final class CmsRelationType implements Serializable {
// the following strings must not be public because they confuse the interface
// this means we can't sort this class members according to standard
/** String prefix for 'JSP relations. */
private static final String PREFIX_JSP = "JSP_";
/** String prefix for XML relations. */
private static final String PREFIX_XML = "XML_";
/** String constant for "STRONG" relations. */
private static final String VALUE_STRONG = "STRONG";
/** String constant for "WEAK" relations. */
private static final String VALUE_WEAK = "WEAK";
/** Constant for the category of an <code>OpenCmsVfsFile</code>. */
public static final CmsRelationType CATEGORY = new CmsRelationType(9, "CATEGORY", false, false);
/** Constant for the <code><img src=''></code> tag in a html page/element. */
public static final CmsRelationType EMBEDDED_IMAGE = new CmsRelationType(2, "IMG", true, true);
/** Constant for the <code><embed src=''></code> tag in a html page/element. */
public static final CmsRelationType EMBEDDED_OBJECT = new CmsRelationType(7, "OBJECT", true, true);
/** Constant for the <code><a href=''></code> tag in a html page/element. */
public static final CmsRelationType HYPERLINK = new CmsRelationType(1, "A", false, true);
/** Constant for the all types of links in a jsp file using the <code>link.strong</code> macro. */
public static final CmsRelationType JSP_STRONG = new CmsRelationType(5, PREFIX_JSP + VALUE_STRONG, true, true);
/** Constant for the all types of links in a jsp file using the <code>link.weak</code> macro. */
public static final CmsRelationType JSP_WEAK = new CmsRelationType(6, PREFIX_JSP + VALUE_WEAK, false, true);
/** Constant for the organizational units resource associations. */
public static final CmsRelationType OU_RESOURCE = new CmsRelationType(8, "OU", false, false);
/** Constant for the <code>OpenCmsVfsFile</code> values in xml content that were defined as 'strong' links. */
public static final CmsRelationType XML_STRONG = new CmsRelationType(3, PREFIX_XML + VALUE_STRONG, true, true);
/** Constant for the <code>OpenCmsVfsFile</code> values in xml content that were defined as 'weak' links. */
public static final CmsRelationType XML_WEAK = new CmsRelationType(4, PREFIX_XML + VALUE_WEAK, false, true);
/** Serial version UID required for safe serialization. */
private static final long serialVersionUID = -4060567973007877250L;
/** Constant indicating the starting mode for user defined relation types. */
private static final int USER_DEFINED_MODE_LIMIT = 100;
/** Array constant for all available system relation types. */
private static final CmsRelationType[] VALUE_ARRAY = {
HYPERLINK,
EMBEDDED_IMAGE,
XML_STRONG,
XML_WEAK,
JSP_STRONG,
JSP_WEAK,
EMBEDDED_OBJECT,
OU_RESOURCE,
CATEGORY};
/** Flag to indicate if the relations of this type are parsed from the content or not. */
private final boolean m_defInContent;
/** Internal representation. */
private final int m_id;
/** Some name for this relation type, ie. for <link> tag representation. */
private final String m_name;
/** Flag to indicate if the relations of this type are strong or weak. */
private final boolean m_strong;
/**
* Public constructor for user defined relation types.<p>
*
* @param id the id of the relation type
* @param name the name of the relation
* @param type the type of relation type, strong or weak
*/
public CmsRelationType(int id, String name, String type) {
m_name = name.toUpperCase();
if (OpenCms.getRunLevel() > OpenCms.RUNLEVEL_2_INITIALIZING) {
// allow relation type definitions only during startup
throw new CmsInitException(Messages.get().container(Messages.ERR_RELATION_TYPE_INIT_1, m_name));
}
m_strong = type.toUpperCase().equals(VALUE_STRONG);
m_defInContent = false;
m_id = USER_DEFINED_MODE_LIMIT + id;
}
/**
* Private constructor for system relation types.<p>
*
* @param id the internal representation
* @param name the name of the relation
* @param strong if the relation is strong or weak
* @param defInContent <code>true</code> if the link is defined in the content
*/
private CmsRelationType(int id, String name, boolean strong, boolean defInContent) {
m_id = id;
m_name = name;
m_strong = strong;
m_defInContent = defInContent;
}
/**
* Returns all relation types in the given list that define relations in the content.<p>
*
* @param relationTypes the collection of relation types to filter
*
* @return a list of {@link CmsRelationType} objects
*/
public static List filterDefinedInContent(Collection relationTypes) {
List list = new ArrayList(relationTypes);
Iterator it = list.iterator();
while (it.hasNext()) {
CmsRelationType type = (CmsRelationType)it.next();
if (!type.isDefinedInContent()) {
it.remove();
}
}
return list;
}
/**
* Returns all internal defined relation types in the given list.<p>
*
* @param relationTypes the collection of relation types to filter
*
* @return a list of {@link CmsRelationType} objects
*/
public static List filterInternal(Collection relationTypes) {
List list = new ArrayList(relationTypes);
Iterator it = list.iterator();
while (it.hasNext()) {
CmsRelationType type = (CmsRelationType)it.next();
if (!type.isInternal()) {
it.remove();
}
}
return list;
}
/**
* Returns all relation types in the given list that are not defined in the content.<p>
*
* @param relationTypes the collection of relation types to filter
*
* @return a list of {@link CmsRelationType} objects
*/
public static List filterNotDefinedInContent(Collection relationTypes) {
List list = new ArrayList(relationTypes);
Iterator it = list.iterator();
while (it.hasNext()) {
CmsRelationType type = (CmsRelationType)it.next();
if (type.isDefinedInContent()) {
it.remove();
}
}
return list;
}
/**
* Returns all strong relation types in the given list.<p>
*
* @param relationTypes the collection of relation types to filter
*
* @return a list of {@link CmsRelationType} objects
*/
public static List filterStrong(Collection relationTypes) {
List list = new ArrayList(relationTypes);
Iterator it = list.iterator();
while (it.hasNext()) {
CmsRelationType type = (CmsRelationType)it.next();
if (!type.isStrong()) {
it.remove();
}
}
return list;
}
/**
* Returns all user defined relation types in the given list.<p>
*
* @param relationTypes the collection of relation types to filter
*
* @return a list of {@link CmsRelationType} objects
*/
public static List filterUserDefined(Collection relationTypes) {
List list = new ArrayList(relationTypes);
Iterator it = list.iterator();
while (it.hasNext()) {
CmsRelationType type = (CmsRelationType)it.next();
if (type.isInternal()) {
it.remove();
}
}
return list;
}
/**
* Returns all weak relation types in the given list.<p>
*
* @param relationTypes the collection of relation types to filter
*
* @return a list of {@link CmsRelationType} objects
*/
public static List filterWeak(Collection relationTypes) {
List list = new ArrayList(relationTypes);
Iterator it = list.iterator();
while (it.hasNext()) {
CmsRelationType type = (CmsRelationType)it.next();
if (type.isStrong()) {
it.remove();
}
}
return list;
}
/**
* Returns all relation types.<p>
*
* @return a list of {@link CmsRelationType} objects
*/
public static List getAll() {
List all = new ArrayList(Arrays.asList(VALUE_ARRAY));
all.addAll(OpenCms.getResourceManager().getRelationTypes());
return Collections.unmodifiableList(all);
}
/**
* Returns all relation types for relations defined in the content.<p>
*
* @return a list of {@link CmsRelationType} objects
*/
public static List getAllDefinedInContent() {
return filterDefinedInContent(getAll());
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -