KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > setup > xml > CmsXmlUpdateLocalizationKeys


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/setup/xml/CmsXmlUpdateLocalizationKeys.java,v $
3  * Date : $Date: 2006/03/28 17:14:41 $
4  * Version: $Revision: 1.3 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.setup.xml;
33
34 import org.opencms.configuration.CmsConfigurationManager;
35 import org.opencms.configuration.CmsWorkplaceConfiguration;
36 import org.opencms.configuration.I_CmsXmlConfiguration;
37 import org.opencms.util.CmsStringUtil;
38 import org.opencms.xml.CmsXmlUtils;
39
40 import java.util.ArrayList JavaDoc;
41 import java.util.Iterator JavaDoc;
42 import java.util.List JavaDoc;
43
44 import org.dom4j.Branch;
45 import org.dom4j.Document;
46 import org.dom4j.Node;
47
48 /**
49  * Updates localization keys.<p>
50  *
51  * @author Michael Moossen
52  *
53  * @version $Revision: 1.3 $
54  *
55  * @since 6.1.8
56  */

57 public class CmsXmlUpdateLocalizationKeys extends A_CmsXmlWorkplace {
58
59     /** The new localization keys. */
60     private List JavaDoc m_newKeys;
61
62     /** The old localization keys. */
63     private List JavaDoc m_oldKeys;
64
65     /** List of xpaths to update. */
66     private List JavaDoc m_xpaths;
67
68     /**
69      * @see org.opencms.setup.xml.I_CmsSetupXmlUpdate#getName()
70      */

71     public String JavaDoc getName() {
72
73         return "Update localization keys";
74     }
75
76     /**
77      * Returns the new Keys.<p>
78      *
79      * @return the new Keys
80      */

81     public List JavaDoc getNewKeys() {
82
83         if (m_newKeys == null) {
84             m_newKeys = new ArrayList JavaDoc();
85             m_newKeys.add("GUI_EXPLORER_CONTEXT_LOCK_0");
86             m_newKeys.add("GUI_EXPLORER_CONTEXT_OVERRIDELOCK_0");
87             m_newKeys.add("GUI_EXPLORER_CONTEXT_UNLOCK_0");
88             m_newKeys.add("GUI_EXPLORER_CONTEXT_COPYTOPROJECT_0");
89             m_newKeys.add("GUI_EXPLORER_CONTEXT_PUBLISH_0");
90             m_newKeys.add("GUI_EXPLORER_CONTEXT_OPENGALLERY_0");
91             m_newKeys.add("GUI_EXPLORER_CONTEXT_RENAMEIMAGES_0");
92             m_newKeys.add("GUI_EXPLORER_CONTEXT_COMMENTIMAGES_0");
93             m_newKeys.add("GUI_EXPLORER_CONTEXT_PAGEEDIT_0");
94             m_newKeys.add("GUI_EXPLORER_CONTEXT_EDITSOURCE_0");
95             m_newKeys.add("GUI_EXPLORER_CONTEXT_EDITLINK_0");
96             m_newKeys.add("GUI_EXPLORER_CONTEXT_EDIT_0");
97             m_newKeys.add("GUI_EXPLORER_CONTEXT_COPY_0");
98             m_newKeys.add("GUI_EXPLORER_CONTEXT_MOVE_0");
99             m_newKeys.add("GUI_EXPLORER_CONTEXT_DELETE_0");
100             m_newKeys.add("GUI_EXPLORER_CONTEXT_REPLACE_0");
101             m_newKeys.add("GUI_EXPLORER_CONTEXT_TOUCH_0");
102             m_newKeys.add("GUI_EXPLORER_CONTEXT_AVAILABILITY_0");
103             m_newKeys.add("GUI_EXPLORER_CONTEXT_UNDOCHANGES_0");
104             m_newKeys.add("GUI_EXPLORER_CONTEXT_UNDELETE_0");
105             m_newKeys.add("GUI_EXPLORER_CONTEXT_SHOWSIBLINGS_0");
106             m_newKeys.add("GUI_EXPLORER_CONTEXT_ACCESS_0");
107             m_newKeys.add("GUI_EXPLORER_CONTEXT_SECURE_0");
108             m_newKeys.add("GUI_EXPLORER_CONTEXT_TYPE_0");
109             m_newKeys.add("GUI_EXPLORER_CONTEXT_CHNAV_0");
110             m_newKeys.add("GUI_EXPLORER_CONTEXT_EDITCONTROLFILE_0");
111             m_newKeys.add("GUI_EXPLORER_CONTEXT_HISTORY_0");
112             m_newKeys.add("GUI_EXPLORER_CONTEXT_PROPERTY_0");
113             m_newKeys.add("GUI_EXPLORER_CONTEXT_MOVE_MULTI_0");
114         }
115         return m_newKeys;
116     }
117
118     /**
119      * Returns the old Keys.<p>
120      *
121      * @return the old Keys
122      */

123     public List JavaDoc getOldKeys() {
124
125         if (m_oldKeys == null) {
126             m_oldKeys = new ArrayList JavaDoc();
127             m_oldKeys.add("explorer.context.lock");
128             m_oldKeys.add("explorer.context.overridelock");
129             m_oldKeys.add("explorer.context.unlock");
130             m_oldKeys.add("explorer.context.copytoproject");
131             m_oldKeys.add("explorer.context.publish");
132             m_oldKeys.add("explorer.context.opengallery");
133             m_oldKeys.add("explorer.context.renameimages");
134             m_oldKeys.add("explorer.context.commentimages");
135             m_oldKeys.add("explorer.context.pageedit");
136             m_oldKeys.add("explorer.context.editsource");
137             m_oldKeys.add("explorer.context.editlink");
138             m_oldKeys.add("explorer.context.edit");
139             m_oldKeys.add("explorer.context.copy");
140             m_oldKeys.add("explorer.context.move");
141             m_oldKeys.add("explorer.context.delete");
142             m_oldKeys.add("explorer.context.replace");
143             m_oldKeys.add("explorer.context.touch");
144             m_oldKeys.add("explorer.context.availability");
145             m_oldKeys.add("explorer.context.undochanges");
146             m_oldKeys.add("explorer.context.undelete");
147             m_oldKeys.add("explorer.context.showsiblings");
148             m_oldKeys.add("explorer.context.access");
149             m_oldKeys.add("explorer.context.secure");
150             m_oldKeys.add("explorer.context.type");
151             m_oldKeys.add("explorer.context.chnav");
152             m_oldKeys.add("explorer.context.editcontrolfile");
153             m_oldKeys.add("explorer.context.history");
154             m_oldKeys.add("explorer.context.property");
155             m_oldKeys.add("explorer.context.move.multi");
156         }
157         return m_oldKeys;
158     }
159
160     /**
161      * @see org.opencms.setup.xml.A_CmsSetupXmlUpdate#executeUpdate(org.dom4j.Document, java.lang.String)
162      */

163     protected boolean executeUpdate(Document document, String JavaDoc xpath) {
164
165         Node node = document.selectSingleNode(xpath);
166         if (node != null) {
167             String JavaDoc key = xpath.substring(10, xpath.length() - 7);
168             int pos = getOldKeys().indexOf(key);
169             CmsSetupXmlHelper.setValue(document, xpath, (String JavaDoc)getNewKeys().get(pos));
170             return true;
171         }
172         return false;
173     }
174
175     /**
176      * @see org.opencms.setup.xml.A_CmsSetupXmlUpdate#getCommonPath()
177      */

178     protected String JavaDoc getCommonPath() {
179
180         // /opencms/workplace/explorertypes
181
return new StringBuffer JavaDoc("/").append(CmsConfigurationManager.N_ROOT).append("/").append(
182             CmsWorkplaceConfiguration.N_WORKPLACE).append("/").append(CmsWorkplaceConfiguration.N_EXPLORERTYPES).toString();
183     }
184
185     /**
186      * @see org.opencms.setup.xml.A_CmsSetupXmlUpdate#getXPathsToUpdate()
187      */

188     protected List JavaDoc getXPathsToUpdate() {
189
190         if (m_xpaths == null) {
191             // //*[@key='${key}']/@key
192
StringBuffer JavaDoc xp = new StringBuffer JavaDoc(256);
193             xp.append("//*[@");
194             xp.append(I_CmsXmlConfiguration.A_KEY);
195             xp.append("='${key}']/@");
196             xp.append(I_CmsXmlConfiguration.A_KEY);
197
198             m_xpaths = new ArrayList JavaDoc();
199             Iterator JavaDoc it = getOldKeys().iterator();
200             while (it.hasNext()) {
201                 m_xpaths.add(CmsStringUtil.substitute(xp.toString(), "${key}", (String JavaDoc)it.next()));
202             }
203         }
204         return m_xpaths;
205     }
206
207     /**
208      * @see org.opencms.setup.xml.A_CmsSetupXmlUpdate#prepareDoc(org.dom4j.Document)
209      */

210     protected Document prepareDoc(Document doc) {
211
212         Document newDoc = super.prepareDoc(doc);
213         String JavaDoc xpath = getCommonPath();
214         Node node = doc.selectSingleNode(xpath);
215         CmsSetupXmlHelper.setValue(newDoc, CmsXmlUtils.removeLastComplexXpathElement(xpath), "");
216         node = (Node)node.clone();
217         node.setParent(null);
218         ((Branch)newDoc.selectSingleNode(CmsXmlUtils.removeLastComplexXpathElement(xpath))).add(node);
219         return newDoc;
220     }
221
222     /**
223      * @see org.opencms.setup.xml.A_CmsSetupXmlUpdate#updateDoc(org.dom4j.Document, org.dom4j.Document, java.lang.String)
224      */

225     protected void updateDoc(Document document, Document newDoc, String JavaDoc xpath) {
226
227         // do nothing
228
return;
229     }
230 }
Popular Tags