Source Code Cross Referenced for CmsMenuRuleTranslator.java in  » Content-Management-System » opencms » org » opencms » workplace » explorer » menu » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » opencms » org.opencms.workplace.explorer.menu 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/explorer/menu/CmsMenuRuleTranslator.java,v $
003:         * Date   : $Date: 2008-02-27 12:05:22 $
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.workplace.explorer.menu;
033:
034:        import org.opencms.main.OpenCms;
035:        import org.opencms.util.CmsStringUtil;
036:
037:        import java.util.Arrays;
038:        import java.util.HashMap;
039:        import java.util.List;
040:        import java.util.Map;
041:
042:        /**
043:         * Provides methods to translate the legacy rule Strings for the context menu entries to the new menu rule set definitions.<p>
044:         * 
045:         * @author Andreas Zahner  
046:         * 
047:         * @version $Revision: 1.4 $ 
048:         * 
049:         * @since 6.5.6 
050:         */
051:        public class CmsMenuRuleTranslator {
052:
053:            /** The legacy rule String for the direct publish item on files. */
054:            private static final String MENURULE_LEGACY_DP_FILE = "d d iaaa iaaa dddd";
055:
056:            /** The legacy rule String for the show siblings entry. */
057:            private static final String MENURULE_LEGACY_SHOWSIBLINGS = "a a aaaa aaaa aaaa";
058:
059:            /** The new menu rule set names used instead of the rule Strings. */
060:            private static final String[] MENURULES = new String[] {
061:                    "copytoproject", "lock", "changelock", "unlock",
062:                    "directpublish", "directpublish", "showlocks",
063:                    "undochanges", "undochanges", "undelete", "copy",
064:                    "standard", "permissions", "nondeleted", "showsiblings" };
065:
066:            /** The legacy menu rule Strings which were used in OpenCms 6. */
067:            private static final String[] MENURULES_LEGACY_STRINGS = new String[] {
068:                    "d a dddd dddd dddd", // copytoproject
069:                    "d d aaaa dddd dddd", // ...
070:                    "d d dddd dddd aaaa",
071:                    "d d dddd aaaa dddd",
072:                    "d d aaaa aaaa dddd", // directpublish (folder)
073:                    MENURULE_LEGACY_DP_FILE, // directpublish (file)
074:                    "d d aaaa aaaa aaaa",
075:                    "d d iiid aaid dddd", // undochanges (folder)
076:                    "d d iiid iaid dddd", // undochanges (file)
077:                    "d d ddda ddda dddd", "d d aaai aaai dddd",
078:                    "d d iiii aaai dddd", "a a iiii aaai dddd",
079:                    "a a aaai aaai aaai", // ...
080:                    MENURULE_LEGACY_SHOWSIBLINGS // showsiblings
081:            };
082:
083:            /** The rules applying for locked resources. */
084:            private static final Object[] TRANS_LOCKEDLOCKRULES = new Object[] {
085:                    new CmsMirPrSameLockedActive(),
086:                    new CmsMirPrSameLockedInvisible(),
087:                    new CmsMirPrSameLockedActiveNotDeletedAl(),
088:                    new CmsMirPrSameLockedActiveChangedAl(),
089:                    new CmsMirPrSameLockedActiveDeletedAl() };
090:
091:            /** The legacy rule Strings applying for locked resources. */
092:            private static final String[] TRANS_LOCKEDLOCKRULES_LEGACY = new String[] {
093:                    "aaaa", "dddd", "aaai", "aaid", "ddda" };
094:
095:            /** The legacy rule Strings as List applying for locked resources. */
096:            private static final List TRANS_LOCKEDLOCKRULES_LEGACY_LIST = Arrays
097:                    .asList(TRANS_LOCKEDLOCKRULES_LEGACY);
098:
099:            /** The rules applying for the Online project. */
100:            private static final Object[] TRANS_ONLINERULES = new Object[] {
101:                    new CmsMirPrOnlineActive(), new CmsMirPrOnlineInactive(),
102:                    new CmsMirPrOnlineInvisible() };
103:
104:            /** The legacy rule Strings applying for the Online project. */
105:            private static final String[] TRANS_ONLINERULES_LEGACY = new String[] {
106:                    "a", "i", "d" };
107:
108:            /** The legacy rule Strings as List applying for the Online project. */
109:            private static final List TRANS_ONLINERULES_LEGACY_LIST = Arrays
110:                    .asList(TRANS_ONLINERULES_LEGACY);
111:
112:            /** The rules applying for all other lock states. */
113:            private static final Object[] TRANS_OTHERLOCKRULES = new Object[] {
114:                    new CmsMirPrSameOtherlockActive(),
115:                    new CmsMirPrSameOtherlockInvisible(),
116:                    new CmsMirActiveNonDeleted() };
117:
118:            /** The legacy rule Strings applying for all other lock states. */
119:            private static final String[] TRANS_OTHERLOCKRULES_LEGACY = new String[] {
120:                    "aaaa", "dddd", "aaai" };
121:
122:            /** The legacy rule Strings as List applying for all other lock states. */
123:            private static final List TRANS_OTHERLOCKRULES_LEGACY_LIST = Arrays
124:                    .asList(TRANS_OTHERLOCKRULES_LEGACY);
125:
126:            /** The rules applying for other projects. */
127:            private static final Object[] TRANS_OTHERPROJECTRULES = new Object[] {
128:                    new CmsMirPrOtherActive(), new CmsMirPrOtherInactive(),
129:                    new CmsMirPrOtherInvisible() };
130:
131:            /** The legacy rule Strings applying for other pojects. */
132:            private static final String[] TRANS_OTHERPROJECTRULES_LEGACY = new String[] {
133:                    "a", "i", "d" };
134:
135:            /** The legacy rule Strings applying for other projects. */
136:            private static final List TRANS_OTHERPROJECTRULES_LEGACY_LIST = Arrays
137:                    .asList(TRANS_OTHERPROJECTRULES_LEGACY);
138:
139:            /** The rules applying for unlocked resources. */
140:            private static final Object[] TRANS_UNLOCKEDRULES = new Object[] {
141:                    new CmsMirPrSameUnlockedActive(),
142:                    new CmsMirPrSameUnlockedInactiveNoAl(),
143:                    new CmsMirPrSameUnlockedInvisible(),
144:                    new CmsMirPrSameUnlockedActiveNotDeletedNoAl(),
145:                    new CmsMirPrSameUnlockedActiveUnchanged(),
146:                    new CmsMirPrSameUnlockedInactiveNotDeletedNoAl(),
147:                    new CmsMirPrSameUnlockedActiveDeletedNoAl() };
148:
149:            /** The legacy rule Strings applying for unlocked resources. */
150:            private static final String[] TRANS_UNLOCKEDRULES_LEGACY = new String[] {
151:                    "aaaa", "iiii", "dddd", "aaai", "iaaa", "iiid", "ddda" };
152:
153:            /** The legacy rule Strings as List applying for unlocked resources. */
154:            private static final List TRANS_UNLOCKEDRULES_LEGACY_LIST = Arrays
155:                    .asList(TRANS_UNLOCKEDRULES_LEGACY);
156:
157:            /** The mappings from the legacy rule strings to the menu rule set names. */
158:            private Map m_ruleMappings;
159:
160:            /**
161:             * Empty constructor.<p>
162:             */
163:            public CmsMenuRuleTranslator() {
164:
165:                // nothing to do here
166:            }
167:
168:            /**
169:             * Creates a new menu rule set from the given legacy rule String.<p>
170:             * 
171:             * @param legacyRules the legacy rule String to parse
172:             * @return a menu rule set from the given legacy rule String
173:             */
174:            public CmsMenuRule createMenuRule(String legacyRules) {
175:
176:                legacyRules = substituteLegacyRules(legacyRules);
177:                CmsMenuRule menuRule = new CmsMenuRule();
178:                if (legacyRules
179:                        .equals(substituteLegacyRules(MENURULE_LEGACY_DP_FILE))) {
180:                    // special case: direct publish rule for files
181:                    menuRule
182:                            .addMenuItemRule((I_CmsMenuItemRule) TRANS_ONLINERULES[2]);
183:                    menuRule
184:                            .addMenuItemRule((I_CmsMenuItemRule) TRANS_OTHERPROJECTRULES[2]);
185:                    menuRule.addMenuItemRule(new CmsMirDirectPublish());
186:                } else if (legacyRules
187:                        .equals(substituteLegacyRules(MENURULE_LEGACY_SHOWSIBLINGS))) {
188:                    // special case: show siblings
189:                    menuRule.addMenuItemRule(new CmsMirShowSiblings());
190:                } else {
191:                    // get the rule for the online project
192:                    String currentRuleString = legacyRules.substring(0, 1);
193:                    int ruleIndex = TRANS_ONLINERULES_LEGACY_LIST
194:                            .indexOf(currentRuleString);
195:                    if (ruleIndex != -1) {
196:                        menuRule
197:                                .addMenuItemRule((I_CmsMenuItemRule) TRANS_ONLINERULES[ruleIndex]);
198:                    }
199:                    // get the rule for other project
200:                    currentRuleString = legacyRules.substring(1, 2);
201:                    ruleIndex = TRANS_OTHERPROJECTRULES_LEGACY_LIST
202:                            .indexOf(currentRuleString);
203:                    if (ruleIndex != -1) {
204:                        menuRule
205:                                .addMenuItemRule((I_CmsMenuItemRule) TRANS_OTHERPROJECTRULES[ruleIndex]);
206:                    }
207:                    // get the rule for unlocked case
208:                    currentRuleString = legacyRules.substring(2, 6);
209:                    ruleIndex = TRANS_UNLOCKEDRULES_LEGACY_LIST
210:                            .indexOf(currentRuleString);
211:                    if (ruleIndex != -1) {
212:                        menuRule
213:                                .addMenuItemRule((I_CmsMenuItemRule) TRANS_UNLOCKEDRULES[ruleIndex]);
214:                    }
215:                    // get the rule for exclusive lock
216:                    currentRuleString = legacyRules.substring(6, 10);
217:                    ruleIndex = TRANS_LOCKEDLOCKRULES_LEGACY_LIST
218:                            .indexOf(currentRuleString);
219:                    if (ruleIndex != -1) {
220:                        menuRule
221:                                .addMenuItemRule((I_CmsMenuItemRule) TRANS_LOCKEDLOCKRULES[ruleIndex]);
222:                    }
223:                    // get the rule for all other states
224:                    currentRuleString = legacyRules.substring(10);
225:                    ruleIndex = TRANS_OTHERLOCKRULES_LEGACY_LIST
226:                            .indexOf(currentRuleString);
227:                    if (ruleIndex != -1) {
228:                        menuRule
229:                                .addMenuItemRule((I_CmsMenuItemRule) TRANS_OTHERLOCKRULES[ruleIndex]);
230:                    }
231:                }
232:                // set a name for the rule
233:                menuRule.setName("rule_" + legacyRules.hashCode());
234:                return menuRule;
235:            }
236:
237:            /**
238:             * Returns the name of the matching default rule set definition for the given legacy rule String.<p>
239:             * 
240:             * If no matching rule set can be found, <code>null</code> is returned.<p>
241:             * 
242:             * @param legacyRules the legacy rule String
243:             * @return the name of the matching default rule set definition for the given legacy rule String
244:             */
245:            public String getMenuRuleName(String legacyRules) {
246:
247:                return (String) getRuleMappings().get(
248:                        substituteLegacyRules(legacyRules));
249:            }
250:
251:            /**
252:             * Returns if a matching default rule set definition is present for the given legacy rule String.<p>
253:             * 
254:             * @param legacyRules the legacy rule String
255:             * @return true if a matching default rule set definition is present for the given legacy rule String, otherwise false
256:             */
257:            public boolean hasMenuRule(String legacyRules) {
258:
259:                String ruleName = (String) getRuleMappings().get(
260:                        substituteLegacyRules(legacyRules));
261:                if (CmsStringUtil.isNotEmpty(ruleName)
262:                        && OpenCms.getWorkplaceManager() != null) {
263:                    return OpenCms.getWorkplaceManager().getMenuRule(ruleName) != null;
264:                }
265:                return false;
266:            }
267:
268:            /**
269:             * Returns the mappings of the legacy rule Strings to the default menu rule set names.<p>
270:             * 
271:             * @return the mappings of the legacy rule Strings to the default menu rule set names
272:             */
273:            protected Map getRuleMappings() {
274:
275:                if (m_ruleMappings == null) {
276:                    m_ruleMappings = new HashMap(
277:                            MENURULES_LEGACY_STRINGS.length);
278:                    for (int i = 0; i < MENURULES_LEGACY_STRINGS.length; i++) {
279:                        try {
280:                            String ruleName = MENURULES[i];
281:                            String legacyRule = substituteLegacyRules(MENURULES_LEGACY_STRINGS[i]);
282:                            m_ruleMappings.put(legacyRule, ruleName);
283:                        } catch (Exception e) {
284:                            // ignore, should not happen
285:                        }
286:                    }
287:                }
288:                return m_ruleMappings;
289:            }
290:
291:            /**
292:             * Removes all whitespaces from the given legacy rule String.<p>
293:             * 
294:             * @param legacyRules the legacy rule String to substitute
295:             * @return the legacy rule String without whitespaces
296:             */
297:            protected String substituteLegacyRules(String legacyRules) {
298:
299:                return CmsStringUtil.substitute(legacyRules, " ", "");
300:            }
301:
302:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.