Source Code Cross Referenced for CmsModuleXmlHandler.java in  » Content-Management-System » opencms » org » opencms » module » 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.module 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/module/CmsModuleXmlHandler.java,v $
003:         * Date   : $Date: 2008-02-27 12:05:44 $
004:         * Version: $Revision: 1.25 $
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.module;
033:
034:        import org.opencms.configuration.CmsVfsConfiguration;
035:        import org.opencms.configuration.CmsWorkplaceConfiguration;
036:        import org.opencms.configuration.I_CmsConfigurationParameterHandler;
037:        import org.opencms.configuration.I_CmsXmlConfiguration;
038:        import org.opencms.db.CmsExportPoint;
039:        import org.opencms.file.types.I_CmsResourceType;
040:        import org.opencms.main.CmsLog;
041:        import org.opencms.util.CmsDateUtil;
042:        import org.opencms.util.CmsStringUtil;
043:        import org.opencms.workplace.CmsWorkplace;
044:        import org.opencms.workplace.explorer.CmsExplorerTypeSettings;
045:
046:        import java.text.ParseException;
047:        import java.util.ArrayList;
048:        import java.util.Collections;
049:        import java.util.HashMap;
050:        import java.util.Iterator;
051:        import java.util.List;
052:        import java.util.Map;
053:        import java.util.SortedMap;
054:
055:        import org.apache.commons.digester.Digester;
056:        import org.apache.commons.logging.Log;
057:
058:        import org.dom4j.Document;
059:        import org.dom4j.DocumentHelper;
060:        import org.dom4j.Element;
061:
062:        /**
063:         * Adds the XML handler rules for import and export of a single module.<p>
064:         * 
065:         * @author Alexander Kandzior 
066:         * 
067:         * @version $Revision: 1.25 $ 
068:         * 
069:         * @since 6.0.0 
070:         */
071:        public class CmsModuleXmlHandler {
072:
073:            /** The "name" attribute. */
074:            public static final String A_NAME = "name";
075:
076:            /** The "version" attribute. */
077:            public static final String A_VERSION = "version";
078:
079:            /** The node name for the authoremail node. */
080:            public static final String N_AUTHOREMAIL = "authoremail";
081:
082:            /** The node name for the authorname node. */
083:            public static final String N_AUTHORNAME = "authorname";
084:
085:            /** The node name for the class node. */
086:            public static final String N_CLASS = "class";
087:
088:            /** The node name for the datecreated node. */
089:            public static final String N_DATECREATED = "datecreated";
090:
091:            /** The node name for the date installed node. */
092:            public static final String N_DATEINSTALLED = "dateinstalled";
093:
094:            /** The node name for the dependencies node. */
095:            public static final String N_DEPENDENCIES = "dependencies";
096:
097:            /** The node name for the dependency node. */
098:            public static final String N_DEPENDENCY = "dependency";
099:
100:            /** The node name for the description node. */
101:            public static final String N_DESCRIPTION = "description";
102:
103:            /** The node name for the group node. */
104:            public static final String N_GROUP = "group";
105:
106:            /** The node name for a module. */
107:            public static final String N_MODULE = "module";
108:
109:            /** The node name for the name node. */
110:            public static final String N_NAME = "name";
111:
112:            /** The node name for the nicename node. */
113:            public static final String N_NICENAME = "nicename";
114:
115:            /** The "param" node name for generic parameters. */
116:            public static final String N_PARAM = "param";
117:
118:            /** The node name for the parameters node. */
119:            public static final String N_PARAMETERS = "parameters";
120:
121:            /** The node name for the resources node. */
122:            public static final String N_RESOURCES = "resources";
123:
124:            /** The node name for the user installed node. */
125:            public static final String N_USERINSTALLED = "userinstalled";
126:
127:            /** The node name for the version node. */
128:            public static final String N_VERSION = "version";
129:
130:            /** The log object for this class. */
131:            private static final Log LOG = CmsLog
132:                    .getLog(CmsModuleXmlHandler.class);
133:
134:            /** The list of dependencies for a module. */
135:            private List m_dependencies;
136:
137:            /** The explorer type settings. */
138:            private List m_explorerTypeSettings;
139:
140:            /** The list of export points for a module. */
141:            private List m_exportPoints;
142:
143:            /** The generated module. */
144:            private CmsModule m_module;
145:
146:            /** Indicates if the module was an old (5.0.x) style module. */
147:            private boolean m_oldModule;
148:
149:            /** The module parameters. */
150:            private Map m_parameters;
151:
152:            /** The list of resources for a module. */
153:            private List m_resources;
154:
155:            /** The list of additional resource types. */
156:            private List m_resourceTypes;
157:
158:            /**
159:             * Public constructor, will be called by digester during import.<p> 
160:             */
161:            public CmsModuleXmlHandler() {
162:
163:                m_exportPoints = new ArrayList();
164:                m_dependencies = new ArrayList();
165:                m_resources = new ArrayList();
166:                m_parameters = new HashMap();
167:                m_resourceTypes = new ArrayList();
168:                m_explorerTypeSettings = new ArrayList();
169:            }
170:
171:            /**
172:             * Adds the XML digester rules for a single module.<p>
173:             * 
174:             * @param digester the digester to add the rules to
175:             */
176:            public static void addXmlDigesterRules(Digester digester) {
177:
178:                // add class generation rule
179:                digester.addObjectCreate("*/" + N_MODULE,
180:                        CmsModuleXmlHandler.class);
181:                digester.addSetNext("*/" + N_MODULE, "setModule");
182:
183:                // add rules for base module information
184:                digester.addCallMethod("*/" + N_MODULE, "createdModule", 11);
185:                digester.addCallParam("*/" + N_MODULE + "/" + N_NAME, 0);
186:                digester.addCallParam("*/" + N_MODULE + "/" + N_NICENAME, 1);
187:                digester.addCallParam("*/" + N_MODULE + "/" + N_GROUP, 2);
188:                digester.addCallParam("*/" + N_MODULE + "/" + N_CLASS, 3);
189:                digester.addCallParam("*/" + N_MODULE + "/" + N_DESCRIPTION, 4);
190:                digester.addCallParam("*/" + N_MODULE + "/" + N_VERSION, 5);
191:                digester.addCallParam("*/" + N_MODULE + "/" + N_AUTHORNAME, 6);
192:                digester.addCallParam("*/" + N_MODULE + "/" + N_AUTHOREMAIL, 7);
193:                digester.addCallParam("*/" + N_MODULE + "/" + N_DATECREATED, 8);
194:                digester.addCallParam("*/" + N_MODULE + "/" + N_USERINSTALLED,
195:                        9);
196:                digester.addCallParam("*/" + N_MODULE + "/" + N_DATEINSTALLED,
197:                        10);
198:
199:                // add rules for module dependencies
200:                digester.addCallMethod("*/" + N_MODULE + "/" + N_DEPENDENCIES
201:                        + "/" + N_DEPENDENCY, "addDependency", 2);
202:                digester.addCallParam("*/" + N_MODULE + "/" + N_DEPENDENCIES
203:                        + "/" + N_DEPENDENCY, 0, I_CmsXmlConfiguration.A_NAME);
204:                digester.addCallParam("*/" + N_MODULE + "/" + N_DEPENDENCIES
205:                        + "/" + N_DEPENDENCY, 1, A_VERSION);
206:
207:                // add rules for the module export points 
208:                digester.addCallMethod("*/" + N_MODULE + "/"
209:                        + I_CmsXmlConfiguration.N_EXPORTPOINTS + "/"
210:                        + I_CmsXmlConfiguration.N_EXPORTPOINT,
211:                        "addExportPoint", 2);
212:                digester.addCallParam("*/" + N_MODULE + "/"
213:                        + I_CmsXmlConfiguration.N_EXPORTPOINTS + "/"
214:                        + I_CmsXmlConfiguration.N_EXPORTPOINT, 0,
215:                        I_CmsXmlConfiguration.A_URI);
216:                digester.addCallParam("*/" + N_MODULE + "/"
217:                        + I_CmsXmlConfiguration.N_EXPORTPOINTS + "/"
218:                        + I_CmsXmlConfiguration.N_EXPORTPOINT, 1,
219:                        I_CmsXmlConfiguration.A_DESTINATION);
220:
221:                // add rules for the module resources 
222:                digester.addCallMethod("*/" + N_MODULE + "/" + N_RESOURCES
223:                        + "/" + I_CmsXmlConfiguration.N_RESOURCE,
224:                        "addResource", 1);
225:                digester.addCallParam("*/" + N_MODULE + "/" + N_RESOURCES + "/"
226:                        + I_CmsXmlConfiguration.N_RESOURCE, 0,
227:                        I_CmsXmlConfiguration.A_URI);
228:
229:                // add rules for the module parameters
230:                digester.addCallMethod("*/" + N_MODULE + "/" + N_PARAMETERS
231:                        + "/" + I_CmsXmlConfiguration.N_PARAM, "addParameter",
232:                        2);
233:                digester.addCallParam("*/" + N_MODULE + "/" + N_PARAMETERS
234:                        + "/" + I_CmsXmlConfiguration.N_PARAM, 0,
235:                        I_CmsXmlConfiguration.A_NAME);
236:                digester.addCallParam("*/" + N_MODULE + "/" + N_PARAMETERS
237:                        + "/" + I_CmsXmlConfiguration.N_PARAM, 1);
238:
239:                // generic <param> parameter rules
240:                digester
241:                        .addCallMethod(
242:                                "*/" + I_CmsXmlConfiguration.N_PARAM,
243:                                I_CmsConfigurationParameterHandler.ADD_PARAMETER_METHOD,
244:                                2);
245:                digester.addCallParam("*/" + I_CmsXmlConfiguration.N_PARAM, 0,
246:                        I_CmsXmlConfiguration.A_NAME);
247:                digester.addCallParam("*/" + I_CmsXmlConfiguration.N_PARAM, 1);
248:
249:                // add resource type rules from VFS
250:                CmsVfsConfiguration.addResourceTypeXmlRules(digester);
251:
252:                // add explorer type rules from workplace
253:                CmsWorkplaceConfiguration.addExplorerTypeXmlRules(digester);
254:
255:                // finally add all rules for backward compatibility with OpenCms 5.0
256:                addXmlDigesterRulesForVersion5Modules(digester);
257:            }
258:
259:            /**
260:             * Generates a detached XML element for a module.<p>
261:             * 
262:             * @param module the module to generate the XML element for
263:             * 
264:             * @return the detached XML element for the module
265:             */
266:            public static Element generateXml(CmsModule module) {
267:
268:                Document doc = DocumentHelper.createDocument();
269:
270:                Element moduleElement = doc.addElement(N_MODULE);
271:
272:                moduleElement.addElement(N_NAME).setText(module.getName());
273:                if (!module.getName().equals(module.getNiceName())) {
274:                    moduleElement.addElement(N_NICENAME).addCDATA(
275:                            module.getNiceName());
276:                } else {
277:                    moduleElement.addElement(N_NICENAME);
278:                }
279:                if (CmsStringUtil.isNotEmpty(module.getGroup())) {
280:                    moduleElement.addElement(N_GROUP)
281:                            .setText(module.getGroup());
282:                }
283:                if (CmsStringUtil.isNotEmpty(module.getActionClass())) {
284:                    moduleElement.addElement(N_CLASS).setText(
285:                            module.getActionClass());
286:                } else {
287:                    moduleElement.addElement(N_CLASS);
288:                }
289:                if (CmsStringUtil.isNotEmpty(module.getDescription())) {
290:                    moduleElement.addElement(N_DESCRIPTION).addCDATA(
291:                            module.getDescription());
292:                } else {
293:                    moduleElement.addElement(N_DESCRIPTION);
294:                }
295:                moduleElement.addElement(N_VERSION).setText(
296:                        module.getVersion().toString());
297:                if (CmsStringUtil.isNotEmpty(module.getAuthorName())) {
298:                    moduleElement.addElement(N_AUTHORNAME).addCDATA(
299:                            module.getAuthorName());
300:                } else {
301:                    moduleElement.addElement(N_AUTHORNAME);
302:                }
303:                if (CmsStringUtil.isNotEmpty(module.getAuthorEmail())) {
304:                    moduleElement.addElement(N_AUTHOREMAIL).addCDATA(
305:                            module.getAuthorEmail());
306:                } else {
307:                    moduleElement.addElement(N_AUTHOREMAIL);
308:                }
309:                if (module.getDateCreated() != CmsModule.DEFAULT_DATE) {
310:                    moduleElement.addElement(N_DATECREATED).setText(
311:                            CmsDateUtil.getHeaderDate(module.getDateCreated()));
312:                } else {
313:                    moduleElement.addElement(N_DATECREATED);
314:                }
315:
316:                if (CmsStringUtil.isNotEmpty(module.getUserInstalled())) {
317:                    moduleElement.addElement(N_USERINSTALLED).setText(
318:                            module.getUserInstalled());
319:                } else {
320:                    moduleElement.addElement(N_USERINSTALLED);
321:                }
322:                if (module.getDateInstalled() != CmsModule.DEFAULT_DATE) {
323:                    moduleElement.addElement(N_DATEINSTALLED).setText(
324:                            CmsDateUtil
325:                                    .getHeaderDate(module.getDateInstalled()));
326:                } else {
327:                    moduleElement.addElement(N_DATEINSTALLED);
328:                }
329:                Element dependenciesElement = moduleElement
330:                        .addElement(N_DEPENDENCIES);
331:                for (int i = 0; i < module.getDependencies().size(); i++) {
332:                    CmsModuleDependency dependency = (CmsModuleDependency) module
333:                            .getDependencies().get(i);
334:                    dependenciesElement.addElement(N_DEPENDENCY).addAttribute(
335:                            I_CmsXmlConfiguration.A_NAME, dependency.getName())
336:                            .addAttribute(A_VERSION,
337:                                    dependency.getVersion().toString());
338:                }
339:                Element exportpointsElement = moduleElement
340:                        .addElement(I_CmsXmlConfiguration.N_EXPORTPOINTS);
341:                for (int i = 0; i < module.getExportPoints().size(); i++) {
342:                    CmsExportPoint point = (CmsExportPoint) module
343:                            .getExportPoints().get(i);
344:                    exportpointsElement.addElement(
345:                            I_CmsXmlConfiguration.N_EXPORTPOINT).addAttribute(
346:                            I_CmsXmlConfiguration.A_URI, point.getUri())
347:                            .addAttribute(I_CmsXmlConfiguration.A_DESTINATION,
348:                                    point.getConfiguredDestination());
349:                }
350:                Element resourcesElement = moduleElement
351:                        .addElement(N_RESOURCES);
352:                for (int i = 0; i < module.getResources().size(); i++) {
353:                    String resource = (String) module.getResources().get(i);
354:                    resourcesElement.addElement(
355:                            I_CmsXmlConfiguration.N_RESOURCE).addAttribute(
356:                            I_CmsXmlConfiguration.A_URI, resource);
357:                }
358:                Element parametersElement = moduleElement
359:                        .addElement(N_PARAMETERS);
360:                SortedMap parameters = module.getParameters();
361:                if (parameters != null) {
362:                    List parameterList = new ArrayList(parameters.keySet());
363:                    Collections.sort(parameterList);
364:                    Iterator it = parameterList.iterator();
365:                    while (it.hasNext()) {
366:                        String name = (String) it.next();
367:                        String value = parameters.get(name).toString();
368:                        Element paramNode = parametersElement
369:                                .addElement(I_CmsXmlConfiguration.N_PARAM);
370:                        paramNode.addAttribute(I_CmsXmlConfiguration.A_NAME,
371:                                name);
372:                        paramNode.addText(value);
373:                    }
374:                }
375:
376:                // add resource types       
377:                List resourceTypes = module.getResourceTypes();
378:                if (resourceTypes.size() > 0) {
379:                    Element resourcetypesElement = moduleElement
380:                            .addElement(CmsVfsConfiguration.N_RESOURCETYPES);
381:                    CmsVfsConfiguration.generateResourceTypeXml(
382:                            resourcetypesElement, resourceTypes, true);
383:                }
384:
385:                List explorerTypes = module.getExplorerTypes();
386:                if (explorerTypes.size() > 0) {
387:                    Element explorerTypesElement = moduleElement
388:                            .addElement(CmsWorkplaceConfiguration.N_EXPLORERTYPES);
389:                    CmsWorkplaceConfiguration.generateExplorerTypesXml(
390:                            explorerTypesElement, explorerTypes, true);
391:                }
392:
393:                // return the modules node
394:                moduleElement.detach();
395:                return moduleElement;
396:            }
397:
398:            /**
399:             * Generates a (hopefully) valid Java class name from an invalid class name.<p>
400:             * 
401:             * All invalid characters are replaced by an underscore "_".
402:             * This is for example used to make sure old (5.0) modules can still be imported,
403:             * by converting the name to a valid class name.<p>
404:             * 
405:             * @param className the class name to make valid
406:             * 
407:             * @return a valid Java class name from an invalid class name
408:             */
409:            public static String makeValidJavaClassName(String className) {
410:
411:                StringBuffer result = new StringBuffer(className.length());
412:                int length = className.length();
413:                boolean nodot = true;
414:                for (int i = 0; i < length; i++) {
415:                    char ch = className.charAt(i);
416:                    if (nodot) {
417:                        if (ch == '.') {
418:                            // ignore, remove
419:                        } else if (Character.isJavaIdentifierStart(ch)) {
420:                            nodot = false;
421:                            result.append(ch);
422:                        } else {
423:                            result.append('_');
424:                        }
425:                    } else {
426:                        if (ch == '.') {
427:                            nodot = true;
428:                            result.append(ch);
429:                        } else if (Character.isJavaIdentifierPart(ch)) {
430:                            nodot = false;
431:                            result.append(ch);
432:                        } else {
433:                            result.append('_');
434:                        }
435:                    }
436:                }
437:                return result.toString();
438:            }
439:
440:            /**
441:             * Adds the digester rules for OpenCms version 5 modules.<p>
442:             * 
443:             * @param digester the digester to add the rules to
444:             */
445:            private static void addXmlDigesterRulesForVersion5Modules(
446:                    Digester digester) {
447:
448:                // mark method
449:                digester.addCallMethod("*/" + N_MODULE + "/author",
450:                        "setOldModule");
451:
452:                // base module information
453:                digester.addCallParam("*/" + N_MODULE + "/author", 6);
454:                digester.addCallParam("*/" + N_MODULE + "/email", 7);
455:                digester.addCallParam("*/" + N_MODULE + "/creationdate", 8);
456:
457:                // dependencies
458:                digester.addCallParam("*/" + N_MODULE
459:                        + "/dependencies/dependency/name", 0);
460:                digester.addCallParam("*/" + N_MODULE
461:                        + "/dependencies/dependency/minversion", 1);
462:
463:                // export points
464:                digester.addCallMethod("*/" + N_MODULE + "/exportpoint",
465:                        "addExportPoint", 2);
466:                digester.addCallParam("*/" + N_MODULE + "/exportpoint/source",
467:                        0);
468:                digester.addCallParam("*/" + N_MODULE
469:                        + "/exportpoint/destination", 1);
470:
471:                // parameters        
472:                digester.addCallMethod("*/" + N_MODULE + "/parameters/para",
473:                        "addParameter", 2);
474:                digester.addCallParam(
475:                        "*/" + N_MODULE + "/parameters/para/name", 0);
476:                digester.addCallParam("*/" + N_MODULE
477:                        + "/parameters/para/value", 1);
478:            }
479:
480:            /**
481:             * Adds a module dependency to the current module.<p>
482:             * 
483:             * @param name the module name of the dependency
484:             * @param version the module version of the dependency
485:             */
486:            public void addDependency(String name, String version) {
487:
488:                CmsModuleVersion moduleVersion = new CmsModuleVersion(version);
489:
490:                CmsModuleDependency dependency = new CmsModuleDependency(name,
491:                        moduleVersion);
492:                m_dependencies.add(dependency);
493:
494:                if (LOG.isDebugEnabled()) {
495:                    LOG.debug(Messages.get().getBundle().key(
496:                            Messages.LOG_ADD_MOD_DEPENDENCY_2, name, version));
497:                }
498:            }
499:
500:            /** 
501:             * Adds an explorer type setting object to the list of type settings.<p>
502:             * 
503:             * Adds the type setting as well to a map with the resource type name as key.
504:             * 
505:             * @param settings the explorer type settings
506:             */
507:            public void addExplorerTypeSetting(CmsExplorerTypeSettings settings) {
508:
509:                settings.setAddititionalModuleExplorerType(true);
510:                m_explorerTypeSettings.add(settings);
511:            }
512:
513:            /**
514:             * Adds an export point to the module configuration.<p>
515:             * 
516:             * @param uri the export point uri
517:             * @param destination the export point destination
518:             */
519:            public void addExportPoint(String uri, String destination) {
520:
521:                CmsExportPoint point = new CmsExportPoint(uri, destination);
522:                m_exportPoints.add(point);
523:                if (CmsLog.INIT.isInfoEnabled()
524:                        && (point.getDestinationPath() != null)) {
525:                    CmsLog.INIT.info(Messages.get().getBundle().key(
526:                            Messages.INIT_ADD_EXPORT_POINT_2, point.getUri(),
527:                            point.getDestinationPath()));
528:                }
529:            }
530:
531:            /**
532:             * Adds a module parameter to the module configuration.<p>
533:             * 
534:             * @param key the parameter key
535:             * @param value the parameter value
536:             */
537:            public void addParameter(String key, String value) {
538:
539:                if (CmsStringUtil.isNotEmpty(key)) {
540:                    key = key.trim();
541:                }
542:                if (CmsStringUtil.isNotEmpty(value)) {
543:                    value = value.trim();
544:                }
545:                m_parameters.put(key, value);
546:                if (LOG.isDebugEnabled()) {
547:                    LOG.debug(Messages.get().getBundle().key(
548:                            Messages.LOG_ADD_MOD_PARAM_KEY_2, key, value));
549:                }
550:            }
551:
552:            /**
553:             * Adds a resource to the list module resources.<p>
554:             * 
555:             * @param resource a resources uri in the OpenCms VFS
556:             */
557:            public void addResource(String resource) {
558:
559:                if (LOG.isDebugEnabled()) {
560:                    LOG.debug(Messages.get().getBundle().key(
561:                            Messages.LOG_ADD_MOD_RESOURCE_1, resource));
562:                }
563:                m_resources.add(resource);
564:            }
565:
566:            /**
567:             * Adds a new resource type to the internal list of loaded resource types.<p>
568:             *
569:             * @param resourceType the resource type to add
570:             * 
571:             * @see I_CmsResourceType#ADD_RESOURCE_TYPE_METHOD
572:             */
573:            public void addResourceType(I_CmsResourceType resourceType) {
574:
575:                resourceType.setAdditionalModuleResourceType(true);
576:                m_resourceTypes.add(resourceType);
577:            }
578:
579:            /**
580:             * Created a new module from the provided parameters.<p>
581:             * 
582:             * @param name the name of this module, usually looks like a java package name
583:             * @param niceName the "nice" display name of this module
584:             * @param group the group of the module
585:             * @param actionClass the (optional) module action class name
586:             * @param description the description of this module
587:             * @param version the version of this module
588:             * @param authorName the name of the author of this module
589:             * @param authorEmail the email of the module author
590:             * @param dateCreated the date this module was created by the author
591:             * @param userInstalled the name of the user who uploaded this module
592:             * @param dateInstalled the date this module was uploaded
593:             */
594:            public void createdModule(String name, String niceName,
595:                    String group, String actionClass, String description,
596:                    String version, String authorName, String authorEmail,
597:                    String dateCreated, String userInstalled,
598:                    String dateInstalled) {
599:
600:                String moduleName;
601:
602:                if (!CmsStringUtil.isValidJavaClassName(name)) {
603:                    // ensure backward compatibility with old (5.0) module names
604:                    LOG.error(Messages.get().getBundle().key(
605:                            Messages.LOG_INVALID_MOD_NAME_IMPORTED_1, name));
606:                    moduleName = makeValidJavaClassName(name);
607:                    LOG.error(Messages.get().getBundle().key(
608:                            Messages.LOG_CORRECTED_MOD_NAME_1, moduleName));
609:                } else {
610:                    moduleName = name;
611:                }
612:
613:                // parse the module version
614:                CmsModuleVersion moduleVersion = new CmsModuleVersion(version);
615:
616:                // parse date created
617:                long moduleDateCreated = CmsModule.DEFAULT_DATE;
618:                if (dateCreated != null) {
619:                    try {
620:                        moduleDateCreated = CmsDateUtil
621:                                .parseHeaderDate(dateCreated);
622:                    } catch (ParseException e) {
623:                        // noop
624:                    }
625:                }
626:
627:                // parse date installed
628:                long moduleDateInstalled = CmsModule.DEFAULT_DATE;
629:                if (dateInstalled != null) {
630:                    try {
631:                        moduleDateInstalled = CmsDateUtil
632:                                .parseHeaderDate(dateInstalled);
633:                    } catch (ParseException e1) {
634:                        // noop
635:                    }
636:                }
637:
638:                if (m_oldModule) {
639:                    // make sure module path is added to resources for "old" (5.0.x) modules
640:                    String modulePath = CmsWorkplace.VFS_PATH_MODULES + name
641:                            + "/";
642:                    m_resources.add(modulePath);
643:                }
644:
645:                // now create the module
646:                m_module = new CmsModule(moduleName, niceName, group,
647:                        actionClass, description, moduleVersion, authorName,
648:                        authorEmail, moduleDateCreated, userInstalled,
649:                        moduleDateInstalled, m_dependencies, m_exportPoints,
650:                        m_resources, m_parameters);
651:
652:                // set the additional resource types;
653:                m_module.setResourceTypes(m_resourceTypes);
654:
655:                // set the additional explorer types
656:                m_module.setExplorerTypes(m_explorerTypeSettings);
657:            }
658:
659:            /**
660:             * Returns the generated module.<p>
661:             * 
662:             * @return the generated module
663:             */
664:            public CmsModule getModule() {
665:
666:                return m_module;
667:            }
668:
669:            /** 
670:             * Sets the current imported module to an old (5.0.x) style module. 
671:             */
672:            public void setOldModule() {
673:
674:                m_oldModule = true;
675:                if (LOG.isDebugEnabled()) {
676:                    LOG.debug(Messages.get().getBundle().key(
677:                            Messages.LOG_OLD_MODULE_IMPORTED_0));
678:                }
679:            }
680:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.