001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-setup/org/opencms/setup/xml/CmsXmlAddResourceHandlers.java,v $
003: * Date : $Date: 2008-02-27 12:05:37 $
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.setup.xml;
033:
034: import org.opencms.configuration.CmsConfigurationManager;
035: import org.opencms.configuration.CmsSystemConfiguration;
036: import org.opencms.configuration.I_CmsXmlConfiguration;
037: import org.opencms.file.history.CmsHistoryResourceHandler;
038: import org.opencms.main.CmsPermalinkResourceHandler;
039: import org.opencms.workplace.CmsWorkplaceLoginHandler;
040:
041: import java.util.ArrayList;
042: import java.util.List;
043:
044: import org.dom4j.Document;
045: import org.dom4j.Node;
046:
047: /**
048: * Adds the new init resource handler classes, from 6.2.3 to 7.0.x.<p>
049: *
050: * @author Michael Moossen
051: *
052: * @version $Revision: 1.2 $
053: *
054: * @since 6.9.2
055: */
056: public class CmsXmlAddResourceHandlers extends A_CmsSetupXmlUpdate {
057:
058: /** List of xpaths to update. */
059: private List m_xpaths;
060:
061: /**
062: * @see org.opencms.setup.xml.I_CmsSetupXmlUpdate#getName()
063: */
064: public String getName() {
065:
066: return "Add new init resource handler classes";
067: }
068:
069: /**
070: * @see org.opencms.setup.xml.I_CmsSetupXmlUpdate#getXmlFilename()
071: */
072: public String getXmlFilename() {
073:
074: return CmsSystemConfiguration.DEFAULT_XML_FILE_NAME;
075: }
076:
077: /**
078: * @see org.opencms.setup.xml.A_CmsSetupXmlUpdate#executeUpdate(org.dom4j.Document, java.lang.String)
079: */
080: protected boolean executeUpdate(Document document, String xpath) {
081:
082: Node node = document.selectSingleNode(xpath);
083: if (node == null) {
084: if (xpath.equals(getXPathsToUpdate().get(0))) {
085: CmsSetupXmlHelper.setValue(document, xpath + "/@"
086: + I_CmsXmlConfiguration.A_CLASS,
087: CmsWorkplaceLoginHandler.class.getName());
088: } else if (xpath.equals(getXPathsToUpdate().get(1))) {
089: CmsSetupXmlHelper.setValue(document, xpath + "/@"
090: + I_CmsXmlConfiguration.A_CLASS,
091: CmsPermalinkResourceHandler.class.getName());
092: } else if (xpath.equals(getXPathsToUpdate().get(2))) {
093: CmsSetupXmlHelper.setValue(document, xpath + "/@"
094: + I_CmsXmlConfiguration.A_CLASS,
095: CmsHistoryResourceHandler.class.getName());
096: }
097: return true;
098: }
099: return false;
100: }
101:
102: /**
103: * @see org.opencms.setup.xml.A_CmsSetupXmlUpdate#getCommonPath()
104: */
105: protected String getCommonPath() {
106:
107: // /opencms/system/resourceinit
108: StringBuffer xp = new StringBuffer(256);
109: xp.append("/").append(CmsConfigurationManager.N_ROOT);
110: xp.append("/").append(CmsSystemConfiguration.N_SYSTEM);
111: xp.append("/").append(CmsSystemConfiguration.N_RESOURCEINIT);
112: return xp.toString();
113: }
114:
115: /**
116: * @see org.opencms.setup.xml.A_CmsSetupXmlUpdate#getXPathsToUpdate()
117: */
118: protected List getXPathsToUpdate() {
119:
120: if (m_xpaths == null) {
121: // "/opencms/system/resourceinit/resourceinithandler[@class='...']";
122: StringBuffer xp = new StringBuffer(256);
123: xp.append("/").append(CmsConfigurationManager.N_ROOT);
124: xp.append("/").append(CmsSystemConfiguration.N_SYSTEM);
125: xp.append("/")
126: .append(CmsSystemConfiguration.N_RESOURCEINIT);
127: xp.append("/").append(
128: CmsSystemConfiguration.N_RESOURCEINITHANDLER);
129: xp.append("[@").append(I_CmsXmlConfiguration.A_CLASS);
130: xp.append("='");
131: m_xpaths = new ArrayList();
132: m_xpaths.add(xp.toString()
133: + CmsWorkplaceLoginHandler.class.getName() + "']");
134: m_xpaths.add(xp.toString()
135: + CmsPermalinkResourceHandler.class.getName()
136: + "']");
137: m_xpaths.add(xp.toString()
138: + CmsHistoryResourceHandler.class.getName() + "']");
139: }
140: return m_xpaths;
141: }
142:
143: }
|