001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-setup/org/opencms/setup/xml/CmsXmlAddXmlContentWidgets.java,v $
003: * Date : $Date: 2008-03-01 11:10:27 $
004: * Version: $Revision: 1.4 $
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.setup.xml;
033:
034: import org.opencms.configuration.CmsConfigurationManager;
035: import org.opencms.configuration.CmsVfsConfiguration;
036: import org.opencms.configuration.I_CmsXmlConfiguration;
037: import org.opencms.widgets.CmsCategoryWidget;
038: import org.opencms.widgets.CmsDisplayWidget;
039: import org.opencms.widgets.CmsGroupWidget;
040: import org.opencms.widgets.CmsInputWidgetPlaintext;
041: import org.opencms.widgets.CmsLocalizationWidget;
042: import org.opencms.widgets.CmsMultiSelectWidget;
043: import org.opencms.widgets.CmsOrgUnitWidget;
044: import org.opencms.widgets.CmsPrincipalWidget;
045: import org.opencms.widgets.CmsRadioSelectWidget;
046: import org.opencms.widgets.CmsTextareaWidgetPlaintext;
047: import org.opencms.widgets.CmsUserWidget;
048:
049: import java.util.ArrayList;
050: import java.util.HashMap;
051: import java.util.Iterator;
052: import java.util.List;
053: import java.util.Map;
054:
055: import org.dom4j.Document;
056: import org.dom4j.Node;
057:
058: /**
059: * Adds the new xml content widgets.<p>
060: *
061: * @author Michael Moossen
062: *
063: * @version $Revision: 1.4 $
064: *
065: * @since 6.1.8
066: */
067: public class CmsXmlAddXmlContentWidgets extends A_CmsSetupXmlUpdate {
068:
069: private Map m_widgetData;
070:
071: /** List of xpaths to update. */
072: private List m_xpaths;
073:
074: /**
075: * @see org.opencms.setup.xml.I_CmsSetupXmlUpdate#getName()
076: */
077: public String getName() {
078:
079: return "Add new Xml Content widgets";
080: }
081:
082: /**
083: * @see org.opencms.setup.xml.I_CmsSetupXmlUpdate#getXmlFilename()
084: */
085: public String getXmlFilename() {
086:
087: return CmsVfsConfiguration.DEFAULT_XML_FILE_NAME;
088: }
089:
090: /**
091: * @see org.opencms.setup.xml.A_CmsSetupXmlUpdate#executeUpdate(org.dom4j.Document, java.lang.String)
092: */
093: protected boolean executeUpdate(Document document, String xpath) {
094:
095: Node node = document.selectSingleNode(xpath);
096: if (node == null) {
097: if (getXPathsToUpdate().contains(xpath)) {
098: Iterator it = getWidgetData().entrySet().iterator();
099: while (it.hasNext()) {
100: Map.Entry entry = (Map.Entry) it.next();
101: String widgetName = (String) entry.getKey();
102: String className = (String) entry.getValue();
103: if (xpath.indexOf(widgetName) > 0) {
104: CmsSetupXmlHelper.setValue(document, xpath
105: + "/@" + I_CmsXmlConfiguration.A_ALIAS,
106: widgetName);
107: CmsSetupXmlHelper.setValue(document, xpath
108: + "/@" + I_CmsXmlConfiguration.A_CLASS,
109: className);
110: break;
111: }
112: }
113: return true;
114: }
115: }
116: return false;
117: }
118:
119: /**
120: * @see org.opencms.setup.xml.A_CmsSetupXmlUpdate#getCommonPath()
121: */
122: protected String getCommonPath() {
123:
124: // /opencms/vfs/xmlcontent/widgets
125: StringBuffer xp = new StringBuffer(256);
126: xp.append("/").append(CmsConfigurationManager.N_ROOT);
127: xp.append("/").append(CmsVfsConfiguration.N_VFS);
128: xp.append("/").append(CmsVfsConfiguration.N_XMLCONTENT);
129: xp.append("/").append(CmsVfsConfiguration.N_WIDGETS);
130: return xp.toString();
131: }
132:
133: /**
134: * @see org.opencms.setup.xml.A_CmsSetupXmlUpdate#getXPathsToUpdate()
135: */
136: protected List getXPathsToUpdate() {
137:
138: if (m_xpaths == null) {
139: // "/opencms/vfs/xmlcontent/widgets/widget[@alias='widget']";
140: StringBuffer xp = new StringBuffer(256);
141: xp.append("/").append(CmsConfigurationManager.N_ROOT);
142: xp.append("/").append(CmsVfsConfiguration.N_VFS);
143: xp.append("/").append(CmsVfsConfiguration.N_XMLCONTENT);
144: xp.append("/").append(CmsVfsConfiguration.N_WIDGETS);
145: xp.append("/").append(CmsVfsConfiguration.N_WIDGET);
146: xp.append("[@").append(I_CmsXmlConfiguration.A_ALIAS);
147: xp.append("='");
148: m_xpaths = new ArrayList();
149: Iterator it = getWidgetData().entrySet().iterator();
150: while (it.hasNext()) {
151: Map.Entry entry = (Map.Entry) it.next();
152: String widgetName = (String) entry.getKey();
153: m_xpaths.add(xp.toString() + widgetName + "']");
154: }
155: }
156: return m_xpaths;
157: }
158:
159: /**
160: * Returns the widget data.<p>
161: *
162: * @return the widget data
163: */
164: private Map getWidgetData() {
165:
166: if (m_widgetData == null) {
167: m_widgetData = new HashMap();
168: m_widgetData.put("DisplayWidget", CmsDisplayWidget.class
169: .getName());
170: m_widgetData.put("MultiSelectWidget",
171: CmsMultiSelectWidget.class.getName());
172: m_widgetData.put("UserWidget", CmsUserWidget.class
173: .getName());
174: m_widgetData.put("GroupWidget", CmsGroupWidget.class
175: .getName());
176: m_widgetData.put("CategoryWidget", CmsCategoryWidget.class
177: .getName());
178: m_widgetData.put("LocalizationWidget",
179: CmsLocalizationWidget.class.getName());
180: m_widgetData.put("TextareaWidgetPlaintext",
181: CmsTextareaWidgetPlaintext.class.getName());
182: m_widgetData.put("StringWidgetPlaintext",
183: CmsInputWidgetPlaintext.class.getName());
184: m_widgetData.put("OrgUnitWidget", CmsOrgUnitWidget.class
185: .getName());
186: m_widgetData.put("PrincipalWidget",
187: CmsPrincipalWidget.class.getName());
188: m_widgetData.put("RadioSelectWidget",
189: CmsRadioSelectWidget.class.getName());
190: }
191: return m_widgetData;
192: }
193:
194: }
|