📄 cmsselectwidgetxmlcontenttype.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/frontend/templateone/form/CmsSelectWidgetXmlcontentType.java,v $
* Date : $Date: 2006/03/27 14:52:20 $
* Version: $Revision: 1.2 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (C) 2002 - 2004 Alkacon Software (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, 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.frontend.templateone.form;
import org.opencms.file.CmsFile;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsProperty;
import org.opencms.file.CmsPropertyDefinition;
import org.opencms.file.CmsRequestContext;
import org.opencms.file.CmsResource;
import org.opencms.file.CmsResourceFilter;
import org.opencms.i18n.CmsLocaleManager;
import org.opencms.loader.CmsLoaderException;
import org.opencms.main.CmsException;
import org.opencms.main.CmsIllegalArgumentException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.util.CmsMacroResolver;
import org.opencms.util.CmsStringUtil;
import org.opencms.widgets.CmsSelectWidget;
import org.opencms.widgets.CmsSelectWidgetOption;
import org.opencms.widgets.I_CmsWidget;
import org.opencms.widgets.I_CmsWidgetDialog;
import org.opencms.widgets.I_CmsWidgetParameter;
import org.opencms.xml.content.CmsXmlContent;
import org.opencms.xml.content.CmsXmlContentFactory;
import org.opencms.xml.types.I_CmsXmlContentValue;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;
import org.apache.commons.logging.Log;
/**
*
* A select widget that recursively collects all {@link org.opencms.xml.content.CmsXmlContent}
* resources of a given type (name) under a given path and creates select options that contain the
* xmlcontents field value specified by a name (xpath) as display String and the xmlcontents path
* (given) as the value.
* <p>
*
* The configuration String has to be of the following form: <br>
*
* <pre>
* "folder=<vfspath>|displayOptionMacro=<macro>|resourcetypeName=<typename>|sortMacro=<macro>[|propertyname=propertyvalue]*
* </pre>
*
* where
*
* <pre>
* <macro>
* </pre>
*
* is a String containing valid OpenCms macros or xpath expression in the form:
*
* <pre>
* "You are viewing: ${property.Title} "
* </pre>
*
* or
*
* <pre>
* "${xpath.Firstname} ${xpath.Lastname}, Nocakla inc."
* </pre>
*
* in which the xpath macros will be replaced with
* {@link org.opencms.xml.A_CmsXmlDocument#getValue(String, Locale)}
*
* <pre>
* <vfspath>
* </pre>
*
* is a valid resource path to a folder in the VFS where search is started from,
*
* <pre>
* <typename>
* </pre>
*
* is a resource type name defined in opencms-modules.xml and
*
* <pre>
* [|propertyname = propertyvalue]*
* </pre>
*
* is a arbitrary number of properties value mappings that have to exist on the resources to show.
* <p>
*
*
* <h3>Please note</h3>
* <p>
* <ul>
* <li>The widget will not offer xmlcontents that are in a different locale than the current page
* that displays it. <br>
* Only if the "matching" xmlcontent has defined a language node for the locale that is set on the
* page for this widget and the xpath expression to display is not empty, the xmlcontent will be
* selectable. </li>
* <li>If sortMacro is missing the values will be sorted alphabetically by their resolved display
* option (from the displayOptionMacro).</li>
* </ul>
* </p>
*
* @author Achim Westermann
*
* @version $Revision: 1.2 $
*
* @since 6.1.3
*
*/
public class CmsSelectWidgetXmlcontentType extends CmsSelectWidget {
/**
* A {@link CmsSelectWidgetOption} that is bundled with a corresponding resource that may be
* selected.
* <p>
*
* @author Achim Westermann
*
* @version $Revision: 1.2 $
*
* @since 6.1.6
*
*/
private static final class CmsResourceSelectWidgetOption extends CmsSelectWidgetOption {
/** The resource to select. */
private CmsResource m_resource;
/**
* Creates a non-default select option with the resource to select, the resource's name as
* the display text and no help text.
* <p>
*
* @param resource The resource of this selection.
*
*/
public CmsResourceSelectWidgetOption(CmsResource resource) {
this(resource, false);
}
/**
* Creates a select option with the resource to select, the resource's name as the display
* text and no help text that is potentially the default selection (argument isDefault).
* <p>
*
* @param resource The resource of this selection.
*
* @param isDefault true, if this option is the default option (preselected.
*
*/
public CmsResourceSelectWidgetOption(CmsResource resource, boolean isDefault) {
this(resource, isDefault, resource.getName());
}
/**
*
* Creates a select option with the resource to select, the given optionText as the display
* text and no help text that is potentially the default selection (argument isDefault).
* <p>
*
* @param resource The resource of this selection.
*
* @param isDefault true, if this option is the default option (preselected.
*
* @param optionText the text to display for this option.
*/
public CmsResourceSelectWidgetOption(CmsResource resource, boolean isDefault, String optionText) {
this(resource, isDefault, optionText, null);
}
/**
* Creates a select option with the resource to select, the given optionText as the display
* text and the given help text that is potentially the default selection (argument
* isDefault).
* <p>
*
* @param resource The resource of this selection.
*
* @param isDefault true, if this option is the default option (preselected.
*
* @param optionText the text to display for this option.
*
* @param helpText The help text to display.
*/
public CmsResourceSelectWidgetOption(CmsResource resource, boolean isDefault, String optionText, String helpText) {
super(resource.getRootPath(), isDefault, optionText, helpText);
m_resource = resource;
}
/**
* Returns the resource that is selectable.
* <p>
*
* @return the resource that is selectable.
*/
CmsResource getResource() {
return m_resource;
}
}
/**
* Compares two {@link CmsResourceSelectWidgetOption} instances by any resource related value
* that may be accessed via a {@link CmsMacroResolver} (except message keys).
* <p>
*
* @author Achim Westermann
*
* @version $Revision: 1.2 $
*
* @since 6.1.6
*
*/
private final class CmsResourceSelectWidgetOptionComparator implements Comparator {
/** The {@link CmsMacroResolver} compatible macro to resolve for comparison. * */
private String m_comparatorMacro;
/** To access resource related values with the {@link CmsMacroResolver} for comparison. * */
private CmsObject m_macroCmsObjectInner;
/** The {@link CmsMacroResolver} to use for macro resolvation for comparison. * */
private CmsMacroResolver m_macroResolverInner;
/**
* Creates a comparator that will resolve the {@link CmsResource} related values with the
* given macro expression.
* <p>
*
* @param cms will be cloned and used for macro - resolvation.
*
* @param comparatorMacro the macro to use to find the resource related strings to compare.
*
* @throws CmsException if sth. goes wrong.
*
* @see CmsMacroResolver
*/
private CmsResourceSelectWidgetOptionComparator(CmsObject cms, String comparatorMacro)
throws CmsException {
if (CmsStringUtil.isEmpty(comparatorMacro)) {
m_comparatorMacro = "${opencms.filename}";
} else {
m_comparatorMacro = comparatorMacro;
}
m_macroCmsObjectInner = OpenCms.initCmsObject(cms);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -