1 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 ; 41 import java.util.Iterator ; 42 import java.util.List ; 43 44 import org.dom4j.Branch; 45 import org.dom4j.Document; 46 import org.dom4j.Node; 47 48 57 public class CmsXmlUpdateLocalizationKeys extends A_CmsXmlWorkplace { 58 59 60 private List m_newKeys; 61 62 63 private List m_oldKeys; 64 65 66 private List m_xpaths; 67 68 71 public String getName() { 72 73 return "Update localization keys"; 74 } 75 76 81 public List getNewKeys() { 82 83 if (m_newKeys == null) { 84 m_newKeys = new ArrayList (); 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 123 public List getOldKeys() { 124 125 if (m_oldKeys == null) { 126 m_oldKeys = new ArrayList (); 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 163 protected boolean executeUpdate(Document document, String xpath) { 164 165 Node node = document.selectSingleNode(xpath); 166 if (node != null) { 167 String key = xpath.substring(10, xpath.length() - 7); 168 int pos = getOldKeys().indexOf(key); 169 CmsSetupXmlHelper.setValue(document, xpath, (String )getNewKeys().get(pos)); 170 return true; 171 } 172 return false; 173 } 174 175 178 protected String getCommonPath() { 179 180 return new StringBuffer ("/").append(CmsConfigurationManager.N_ROOT).append("/").append( 182 CmsWorkplaceConfiguration.N_WORKPLACE).append("/").append(CmsWorkplaceConfiguration.N_EXPLORERTYPES).toString(); 183 } 184 185 188 protected List getXPathsToUpdate() { 189 190 if (m_xpaths == null) { 191 StringBuffer xp = new StringBuffer (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 (); 199 Iterator it = getOldKeys().iterator(); 200 while (it.hasNext()) { 201 m_xpaths.add(CmsStringUtil.substitute(xp.toString(), "${key}", (String )it.next())); 202 } 203 } 204 return m_xpaths; 205 } 206 207 210 protected Document prepareDoc(Document doc) { 211 212 Document newDoc = super.prepareDoc(doc); 213 String 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 225 protected void updateDoc(Document document, Document newDoc, String xpath) { 226 227 return; 229 } 230 } | Popular Tags |