001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/frontend/templatetwo/CmsPresetSelectWidget.java,v $
003: * Date : $Date: 2008-02-27 12:05:30 $
004: * Version: $Revision: 1.2 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.frontend.templatetwo;
033:
034: import org.opencms.file.CmsObject;
035: import org.opencms.file.CmsPropertyDefinition;
036: import org.opencms.file.CmsResource;
037: import org.opencms.file.CmsResourceFilter;
038: import org.opencms.main.CmsException;
039: import org.opencms.widgets.CmsSelectWidget;
040: import org.opencms.widgets.CmsSelectWidgetOption;
041: import org.opencms.widgets.I_CmsWidget;
042: import org.opencms.widgets.I_CmsWidgetDialog;
043: import org.opencms.widgets.I_CmsWidgetParameter;
044:
045: import java.util.ArrayList;
046: import java.util.Iterator;
047: import java.util.List;
048:
049: /**
050: * Displays all existing presets in a select widget.<p>
051: *
052: * @author Peter Bonrad
053: *
054: * @version $Revision: 1.2 $
055: *
056: * @since 7.0.4
057: */
058: public class CmsPresetSelectWidget extends CmsSelectWidget {
059:
060: /** The resource type id of the preset. */
061: public static final int PRESET_TYPE_ID = 70;
062:
063: /**
064: * Creates a new select site widget.<p>
065: */
066: public CmsPresetSelectWidget() {
067:
068: super ("");
069: }
070:
071: /**
072: * Creates a select widget with the configuration.<p>
073: *
074: * @param configuration the configuration (possible options) for the select box
075: */
076: public CmsPresetSelectWidget(String configuration) {
077:
078: super (configuration);
079: }
080:
081: /**
082: * @see org.opencms.widgets.I_CmsWidget#newInstance()
083: */
084: public I_CmsWidget newInstance() {
085:
086: return new CmsPresetSelectWidget(getConfiguration());
087: }
088:
089: /**
090: *@see org.opencms.widgets.A_CmsSelectWidget#parseSelectOptions(CmsObject, I_CmsWidgetDialog, I_CmsWidgetParameter)
091: */
092: protected List parseSelectOptions(CmsObject cms,
093: I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) {
094:
095: List result = new ArrayList();
096:
097: try {
098: List resources = cms.readResources("/",
099: CmsResourceFilter.DEFAULT
100: .addRequireType(PRESET_TYPE_ID), true);
101: Iterator iter = resources.iterator();
102: while (iter.hasNext()) {
103: CmsResource res = (CmsResource) iter.next();
104:
105: String title = cms.readPropertyObject(res,
106: CmsPropertyDefinition.PROPERTY_TITLE, false)
107: .getValue();
108: result.add(new CmsSelectWidgetOption(cms
109: .getSitePath(res), false, title, ""));
110: }
111: } catch (CmsException e) {
112: // noop
113: }
114:
115: return result;
116: }
117: }
|