KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > module > CmsModule


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/module/CmsModule.java,v $
3  * Date : $Date: 2006/03/27 14:53:03 $
4  * Version: $Revision: 1.30 $
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.module;
33
34 import org.opencms.file.CmsObject;
35 import org.opencms.main.CmsIllegalArgumentException;
36 import org.opencms.main.CmsLog;
37 import org.opencms.security.CmsRole;
38 import org.opencms.security.CmsRoleViolationException;
39 import org.opencms.util.CmsFileUtil;
40 import org.opencms.util.CmsStringUtil;
41
42 import java.util.ArrayList JavaDoc;
43 import java.util.Collections JavaDoc;
44 import java.util.List JavaDoc;
45 import java.util.Map JavaDoc;
46 import java.util.SortedMap JavaDoc;
47 import java.util.StringTokenizer JavaDoc;
48 import java.util.TreeMap JavaDoc;
49
50 import org.apache.commons.logging.Log;
51
52 /**
53  * Describes an OpenCms module.<p>
54  *
55  * OpenCms modules provide a standard mechanism to extend the OpenCms functionality.
56  * Modules can contain VFS data, Java classes and a number of configuration options.<p>
57  *
58  * @author Alexander Kandzior
59  *
60  * @version $Revision: 1.30 $
61  *
62  * @since 6.0.0
63  *
64  * @see org.opencms.module.I_CmsModuleAction
65  * @see org.opencms.module.A_CmsModuleAction
66  */

67 public class CmsModule implements Comparable JavaDoc {
68
69     /** The default date for module created / installed if not provided. */
70     public static final long DEFAULT_DATE = 0L;
71
72     /** The log object for this class. */
73     private static final Log LOG = CmsLog.getLog(CmsModule.class);
74
75     /**
76      * The module property key name to specifiy additional resources which are
77      * part of a module outside of {system/modules}.
78      */

79     private static final String JavaDoc MODULE_PROPERTY_ADDITIONAL_RESOURCES = "additionalresources";
80
81     /** Character to separate additional resources specified in the module properties. */
82     private static final String JavaDoc MODULE_PROPERTY_ADDITIONAL_RESOURCES_SEPARATOR = ";";
83
84     /** The module action class name. */
85     private String JavaDoc m_actionClass;
86
87     /** Initialized module action instance. */
88     private I_CmsModuleAction m_actionInstance;
89
90     /** The email of the author of this module. */
91     private String JavaDoc m_authorEmail;
92
93     /** The name of the author of this module. */
94     private String JavaDoc m_authorName;
95
96     /** Flag to create the classes folders when creating the module. */
97     private boolean m_createClassesFolder;
98
99     /** Flag to create the elements folder when creating the module. */
100     private boolean m_createElementsFolder;
101
102     /** Flag to create the lib folder when creating the module. */
103     private boolean m_createLibFolder;
104
105     /** Flag to create the module folder when creating the module. */
106     private boolean m_createModuleFolder;
107
108     /** Flag to create the resources folder when creating the module. */
109     private boolean m_createResourcesFolder;
110
111     /** Flag to create the template folder when creating the module. */
112     private boolean m_createTemplateFolder;
113
114     /** The date this module was created by the author. */
115     private long m_dateCreated;
116
117     /** The date this module was installed. */
118     private long m_dateInstalled;
119
120     /** List of dependencies of this module. */
121     private List JavaDoc m_dependencies;
122
123     /** The description of this module. */
124     private String JavaDoc m_description;
125
126     /** The explorer type settings. */
127     private List JavaDoc m_explorerTypeSettings;
128
129     /** List of export points added by this module. */
130     private List JavaDoc m_exportPoints;
131
132     /** Indicates if this modules configuration has already been frozen. */
133     private boolean m_frozen;
134
135     /** The group of the module. */
136     private String JavaDoc m_group;
137
138     /** The name of this module, must be a valid Java package name. */
139     private String JavaDoc m_name;
140
141     /** The "nice" display name of this module. */
142     private String JavaDoc m_niceName;
143
144     /** The additional configuration parameters of this module. */
145     private SortedMap JavaDoc m_parameters;
146
147     /** List of VFS resources that belong to this module. */
148     private List JavaDoc m_resources;
149
150     /** The list of additional resource types. */
151     private List JavaDoc m_resourceTypes;
152
153     /** The name of the user who installed this module. */
154     private String JavaDoc m_userInstalled;
155
156     /** The version of this module. */
157     private CmsModuleVersion m_version;
158
159     /**
160      * Creates a new, empty CmsModule object.<p>
161      */

162     public CmsModule() {
163
164         m_version = new CmsModuleVersion(CmsModuleVersion.DEFAULT_VERSION);
165         m_resources = Collections.EMPTY_LIST;
166         m_exportPoints = Collections.EMPTY_LIST;
167         m_dependencies = Collections.EMPTY_LIST;
168     }
169
170     /**
171      * Creates a new module description with the specified values.<p>
172      *
173      * @param name the name of this module, must be a valid Java package name
174      * @param niceName the "nice" display name of this module
175      * @param group the group of this module
176      * @param actionClass the (optional) module class name
177      * @param description the description of this module
178      * @param version the version of this module
179      * @param authorName the name of the author of this module
180      * @param authorEmail the email of the author of this module
181      * @param dateCreated the date this module was created by the author
182      * @param userInstalled the name of the user who uploaded this module
183      * @param dateInstalled the date this module was uploaded
184      * @param dependencies a list of dependencies of this module
185      * @param exportPoints a list of export point added by this module
186      * @param resources a list of VFS resources that belong to this module
187      * @param parameters the parameters for this module
188      */

189     public CmsModule(
190         String JavaDoc name,
191         String JavaDoc niceName,
192         String JavaDoc group,
193         String JavaDoc actionClass,
194         String JavaDoc description,
195         CmsModuleVersion version,
196         String JavaDoc authorName,
197         String JavaDoc authorEmail,
198         long dateCreated,
199         String JavaDoc userInstalled,
200         long dateInstalled,
201         List JavaDoc dependencies,
202         List JavaDoc exportPoints,
203         List JavaDoc resources,
204         Map JavaDoc parameters) {
205
206         super();
207         m_name = name;
208         setNiceName(niceName);
209         setActionClass(actionClass);
210         setGroup(group);
211
212         if (CmsStringUtil.isEmpty(description)) {
213             m_description = "";
214         } else {
215             m_description = description;
216         }
217         m_version = version;
218         if (CmsStringUtil.isEmpty(authorName)) {
219             m_authorName = "";
220         } else {
221             m_authorName = authorName;
222         }
223         if (CmsStringUtil.isEmpty(authorEmail)) {
224             m_authorEmail = "";
225         } else {
226             m_authorEmail = authorEmail;
227         }
228         // remove milisecounds
229
m_dateCreated = (dateCreated / 1000L) * 1000L;
230         if (CmsStringUtil.isEmpty(userInstalled)) {
231             m_userInstalled = "";
232         } else {
233             m_userInstalled = userInstalled;
234         }
235         m_dateInstalled = (dateInstalled / 1000L) * 1000L;
236         if (dependencies == null) {
237             m_dependencies = Collections.EMPTY_LIST;
238         } else {
239             m_dependencies = Collections.unmodifiableList(dependencies);
240         }
241         if (exportPoints == null) {
242             m_exportPoints = Collections.EMPTY_LIST;
243         } else {
244             m_exportPoints = Collections.unmodifiableList(exportPoints);
245         }
246         if (resources == null) {
247             m_resources = Collections.EMPTY_LIST;
248         } else {
249             m_resources = Collections.unmodifiableList(resources);
250         }
251         if (parameters == null) {
252             //m_parameters = Collections.EMPTY_MAP;
253
m_parameters = new TreeMap JavaDoc();
254         } else {
255             m_parameters = new TreeMap JavaDoc(parameters);
256         }
257
258         initOldAdditionalResources();
259
260         if (LOG.isDebugEnabled()) {
261             LOG.debug(Messages.get().getBundle().key(Messages.LOG_MODULE_INSTANCE_CREATED_1, m_name));
262         }
263         m_resourceTypes = Collections.EMPTY_LIST;
264         m_explorerTypeSettings = Collections.EMPTY_LIST;
265     }
266
267     /**
268      * Checks if this module depends on another given module,
269      * will return the dependency, or <code>null</code> if no dependency was found.<p>
270      *
271      * @param module the other module to check against
272      * @return the dependency, or null if no dependency was found
273      */

274     public CmsModuleDependency checkDependency(CmsModule module) {
275
276         CmsModuleDependency otherDepdendency = new CmsModuleDependency(module.getName(), module.getVersion());
277
278         // loop through all the dependencies
279
for (int i = 0; i < m_dependencies.size(); i++) {
280             CmsModuleDependency dependency = (CmsModuleDependency)m_dependencies.get(i);
281             if (dependency.dependesOn(otherDepdendency)) {
282                 // short circuit here
283
return dependency;
284             }
285         }
286
287         // no dependency was found
288
return null;
289     }
290
291     /**
292      * Checks if all resources of the module are present.<p>
293      *
294      * @param cms an initialized OpenCms user context which must have read access to all module resources
295      *
296      * @throws CmsIllegalArgumentException in case not all module resources exist or can be read with the given OpenCms user context
297      */

298     public void checkResources(CmsObject cms) throws CmsIllegalArgumentException {
299
300         CmsFileUtil.checkResources(cms, getResources());
301     }
302
303     /**
304      * Clones a CmsModule which is not set to frozen.<p>
305      * This clones module can be used to be update the module information.
306      *
307      * @see java.lang.Object#clone()
308      */

309     public Object JavaDoc clone() {
310
311         // create a copy of the module
312
CmsModule result = new CmsModule(
313             m_name,
314             m_niceName,
315             m_group,
316             m_actionClass,
317             m_description,
318             m_version,
319             m_authorName,
320             m_authorEmail,
321             m_dateCreated,
322             m_userInstalled,
323             m_dateInstalled,
324             m_dependencies,
325             m_exportPoints,
326             m_resources,
327             m_parameters);
328         // and set its frozen state to false
329
result.m_frozen = false;
330
331         if (getExplorerTypes() != null) {
332             result.setExplorerTypes(new ArrayList JavaDoc(getExplorerTypes()));
333         }
334         if (getResourceTypes() != null) {
335             result.setResourceTypes(new ArrayList JavaDoc(getResourceTypes()));
336         }
337
338         if (getDependencies() != null) {
339             result.setDependencies(new ArrayList JavaDoc(getDependencies()));
340         }
341
342         result.setCreateClassesFolder(m_createClassesFolder);
343         result.setCreateElementsFolder(m_createElementsFolder);
344         result.setCreateLibFolder(m_createLibFolder);
345         result.setCreateModuleFolder(m_createModuleFolder);
346         result.setCreateResourcesFolder(m_createResourcesFolder);
347         result.setCreateTemplateFolder(m_createTemplateFolder);
348
349         result.setResources(new ArrayList JavaDoc(m_resources));
350         result.setExportPoints(new ArrayList JavaDoc(m_exportPoints));
351         return result;
352     }
353
354     /**
355      * @see java.lang.Comparable#compareTo(java.lang.Object)
356      */

357     public int compareTo(Object JavaDoc obj) {
358
359         if (obj == this) {
360             return 0;
361         }
362         if (obj instanceof CmsModule) {
363             return m_name.compareTo(((CmsModule)obj).m_name);
364         }
365         return 0;
366     }
367
368     /**
369      * Two instances of a module are considered equal if their name is equal.<p>
370      *
371      * @param obj the object to compare
372      *
373      * @return true if the objects are equal
374      *
375      * @see java.lang.Object#equals(java.lang.Object)
376      * @see #isIdentical(CmsModule)
377      */

378     public boolean equals(Object JavaDoc obj) {
379
380         if (obj == this) {
381             return true;
382         }
383         if (obj instanceof CmsModule) {
384             return ((CmsModule)obj).m_name.equals(m_name);
385         }
386         return false;
387     }
388
389     /**
390      * Returns the class name of this modules (optional) action class.<p>
391      *
392      * If this module does not use an action class,
393      * <code>null</code> is returned.<p>
394      *
395      * @return the class name of this modules (optional) action class
396      */

397     public String JavaDoc getActionClass() {
398
399         return m_actionClass;
400     }
401
402     /**
403      * Returns the module action instance of this module, or <code>null</code>
404      * if no module action instance is configured.<p>
405      *
406      * @return the module action instance of this module
407      */

408     public I_CmsModuleAction getActionInstance() {
409
410         return m_actionInstance;
411     }
412
413     /**
414      * Returns the email of the module author.<p>
415      *
416      * @return the email of the module author
417      */

418     public String JavaDoc getAuthorEmail() {
419
420         return m_authorEmail;
421     }
422
423     /**
424      * Returns the name of the author of this module.<p>
425      *
426      * @return the name of the author of this module
427      */

428     public String JavaDoc getAuthorName() {
429
430         return m_authorName;
431     }
432
433     /**
434      * Returns the date this module was created by the author.<p>
435      *
436      * @return the date this module was created by the author
437      */

438     public long getDateCreated() {
439
440         return m_dateCreated;
441     }
442
443     /**
444      * Returns the date this module was uploaded.<p>
445      *
446      * @return the date this module was uploaded
447      */

448     public long getDateInstalled() {
449
450         return m_dateInstalled;
451     }
452
453     /**
454      * Returns the list of dependencies of this module.<p>
455      *
456      * @return the list of dependencies of this module
457      */

458     public List JavaDoc getDependencies() {
459
460         return m_dependencies;
461     }
462
463     /**
464      * Returns the description of this module.<p>
465      *
466      * @return the description of this module
467      */

468     public String JavaDoc getDescription() {
469
470         return m_description;
471     }
472
473     /**
474      * Returns the list of explorer resource types that belong to this module.<p>
475      *
476      * @return the list of explorer resource types that belong to this module
477      */

478     public List JavaDoc getExplorerTypes() {
479
480         return m_explorerTypeSettings;
481     }
482
483     /**
484      * Returns the list of export point added by this module.<p>
485      *
486      * @return the list of export point added by this module
487      */

488     public List JavaDoc getExportPoints() {
489
490         return m_exportPoints;
491     }
492
493     /**
494      * Returns the group name of this module.<p>
495      *
496      * @return the group name of this module
497      */

498     public String JavaDoc getGroup() {
499
500         return m_group;
501     }
502
503     /**
504      * Returns the name of this module.<p>
505      *
506      * The module name must be a valid java package name.<p>
507      *
508      * @return the name of this module
509      */

510     public String JavaDoc getName() {
511
512         return m_name;
513     }
514
515     /**
516      * Returns the "nice" display name of this module.<p>
517      *
518      * @return the "nice" display name of this module
519      */

520     public String JavaDoc getNiceName() {
521
522         return m_niceName;
523     }
524
525     /**
526      * Returns a parameter value from the module parameters.<p>
527      *
528      * @param key the parameter to return the value for
529      * @return the parameter value from the module parameters
530      */

531     public String JavaDoc getParameter(String JavaDoc key) {
532
533         return (String JavaDoc)m_parameters.get(key);
534     }
535
536     /**
537      * Returns a parameter value from the module parameters,
538      * or a given default value in case the parameter is not set.<p>
539      *
540      * @param key the parameter to return the value for
541      * @param defaultValue the default value in case there is no value stored for this key
542      * @return the parameter value from the module parameters
543      */

544     public String JavaDoc getParameter(String JavaDoc key, String JavaDoc defaultValue) {
545
546         String JavaDoc value = (String JavaDoc)m_parameters.get(key);
547         return (value != null) ? value : defaultValue;
548     }
549
550     /**
551      * Returns the configured (immutable) module parameters.<p>
552      *
553      * @return the configured (immutable) module parameters
554      */

555     public SortedMap JavaDoc getParameters() {
556
557         return m_parameters;
558     }
559
560     /**
561      * Returns the list of VFS resources that belong to this module.<p>
562      *
563      * @return the list of VFS resources that belong to this module
564      */

565     public List JavaDoc getResources() {
566
567         return m_resources;
568     }
569
570     /**
571      * Returns the list of additional resource types that belong to this module.<p>
572      *
573      * @return the list of additional resource types that belong to this module
574      */

575     public List JavaDoc getResourceTypes() {
576
577         return m_resourceTypes;
578     }
579
580     /**
581      * Returns the name of the user who uploaded this module.<p>
582      *
583      * @return the name of the user who uploaded this module
584      */

585     public String JavaDoc getUserInstalled() {
586
587         return m_userInstalled;
588     }
589
590     /**
591      * Returns the version of this module.<p>
592      *
593      * @return the version of this module
594      */

595     public CmsModuleVersion getVersion() {
596
597         return m_version;
598     }
599
600     /**
601      * @see java.lang.Object#hashCode()
602      */

603     public int hashCode() {
604
605         return m_name.hashCode();
606     }
607
608     /**
609      * Returns the createClassesFolder flag.<p>
610      *
611      * @return the createClassesFolder flag
612      */

613     public boolean isCreateClassesFolder() {
614
615         return m_createClassesFolder;
616     }
617
618     /**
619      * Returns the createElementsFolder flag.<p>
620      *
621      * @return the createElementsFolder flag
622      */

623     public boolean isCreateElementsFolder() {
624
625         return m_createElementsFolder;
626     }
627
628     /**
629      * Returns the createLibFolder flag.<p>
630      *
631      * @return the createLibFolder flag
632      */

633     public boolean isCreateLibFolder() {
634
635         return m_createLibFolder;
636     }
637
638     /**
639      * Returns the createModuleFolder flag.<p>
640      *
641      * @return the createModuleFolder flag
642      */

643     public boolean isCreateModuleFolder() {
644
645         return m_createModuleFolder;
646     }
647
648     /**
649      * Returns the createResourcesFolder flag.<p>
650      *
651      * @return the createResourcesFolder flag
652      */

653     public boolean isCreateResourcesFolder() {
654
655         return m_createResourcesFolder;
656     }
657
658     /**
659      * Returns the createTemplateFolder flag.<p>
660      *
661      * @return the createTemplateFolder flag
662      */

663     public boolean isCreateTemplateFolder() {
664
665         return m_createTemplateFolder;
666     }
667
668     /**
669      * Checks if this module is identical with another module.<p>
670      *
671      * Modules A, B are <b>identical</b> if <i>all</i> values of A are equal to B.
672      * The values from {@link #getUserInstalled()} and {@link #getDateInstalled()}
673      * are ignored for this test.<p>
674      *
675      * Modules A, B are <b>equal</b> if just the name of A is equal to the name of B.<p>
676      *
677      * @param other the module to compare with
678      *
679      * @return if the modules are identical
680      *
681      * @see #equals(Object)
682      */

683     public boolean isIdentical(CmsModule other) {
684
685         // some code redundancy here but this is easier to debug
686
if (!isEqual(m_name, other.m_name)) {
687             return false;
688         }
689         if (!isEqual(m_niceName, other.m_niceName)) {
690             return false;
691         }
692         if (!isEqual(m_version, other.m_version)) {
693             return false;
694         }
695         if (!isEqual(m_actionClass, other.m_actionClass)) {
696             return false;
697         }
698         if (!isEqual(m_description, other.m_description)) {
699             return false;
700         }
701         if (!isEqual(m_authorName, other.m_authorName)) {
702             return false;
703         }
704         if (!isEqual(m_authorEmail, other.m_authorEmail)) {
705             return false;
706         }
707         if (m_dateCreated != other.m_dateCreated) {
708             return false;
709         }
710         return true;
711     }
712
713     /**
714      * Sets the class name of this modules (optional) action class.<p>
715      *
716      * Providing <code>null</code> as a value indicates that this module does not use an action class.<p>
717      *
718      * <i>Please note:</i>It's not possible to set the action class name once the module
719      * configuration has been frozen.<p>
720      *
721      * @param value the class name of this modules (optional) action class to set
722      */

723     public void setActionClass(String JavaDoc value) {
724
725         checkFrozen();
726         if (CmsStringUtil.isEmpty(value)) {
727             m_actionClass = null;
728         } else {
729             if (!CmsStringUtil.isValidJavaClassName(value)) {
730                 throw new CmsIllegalArgumentException(Messages.get().container(
731                     Messages.ERR_MODULE_ACTION_CLASS_2,
732                     value,
733                     getName()));
734             }
735             m_actionClass = value;
736         }
737     }
738
739     /**
740      * Sets the author email of this module.<p>
741      *
742      *
743      * <i>Please note:</i>It's not possible to set the modules author email once the module
744      * configuration has been frozen.<p>
745      *
746      * @param value the module description to set
747      */

748     public void setAuthorEmail(String JavaDoc value) {
749
750         checkFrozen();
751         m_authorEmail = value.trim();
752     }
753
754     /**
755      * Sets the author name of this module.<p>
756      *
757      *
758      * <i>Please note:</i>It's not possible to set the modules author name once the module
759      * configuration has been frozen.<p>
760      *
761      * @param value the module description to set
762      */

763     public void setAuthorName(String JavaDoc value) {
764
765         checkFrozen();
766         m_authorName = value.trim();
767     }
768
769     /**
770      * Sets the createClassesFolder flag.<p>
771      *
772      * @param createClassesFolder the createClassesFolder flag to set
773      */

774     public void setCreateClassesFolder(boolean createClassesFolder) {
775
776         m_createClassesFolder = createClassesFolder;
777     }
778
779     /**
780      * Sets the createElementsFolder flag.<p>
781      *
782      * @param createElementsFolder the createElementsFolder flag to set
783      */

784     public void setCreateElementsFolder(boolean createElementsFolder) {
785
786         m_createElementsFolder = createElementsFolder;
787     }
788
789     /**
790      * Sets the createLibFolder flag.<p>
791      *
792      * @param createLibFolder the createLibFolder flag to set
793      */

794     public void setCreateLibFolder(boolean createLibFolder) {
795
796         m_createLibFolder = createLibFolder;
797     }
798
799     /**
800      * Sets the createModuleFolder flag.<p>
801      *
802      * @param createModuleFolder the createModuleFolder flag to set
803      */

804     public void setCreateModuleFolder(boolean createModuleFolder) {
805
806         m_createModuleFolder = createModuleFolder;
807     }
808
809     /**
810      * Sets the createResourcesFolder flag.<p>
811      *
812      * @param createResourcesFolder the createResourcesFolder flag to set
813      */

814     public void setCreateResourcesFolder(boolean createResourcesFolder) {
815
816         m_createResourcesFolder = createResourcesFolder;
817     }
818
819     /**
820      * Sets the createTemplateFolder flag .<p>
821      *
822      * @param createTemplateFolder the createTemplateFolder flag to set
823      */

824     public void setCreateTemplateFolder(boolean createTemplateFolder) {
825
826         m_createTemplateFolder = createTemplateFolder;
827     }
828
829     /**
830      * Sets the date created of this module.<p>
831      *
832      *
833      * <i>Please note:</i>It's not possible to set the module date created once the module
834      * configuration has been frozen.<p>
835      *
836      * @param value the date created to set
837      */

838     public void setDateCreated(long value) {
839
840         checkFrozen();
841         m_dateCreated = value;
842     }
843
844     /**
845      * Sets the installation date of this module.<p>
846      *
847      *
848      * <i>Please note:</i>It's not possible to set the installation date once the module
849      * configuration has been frozen.<p>
850      *
851      * @param value the installation date this module
852      */

853     public void setDateInstalled(long value) {
854
855         checkFrozen();
856         m_dateInstalled = value;
857     }
858
859     /**
860      * Sets the list of module dependencies.<p>
861      *
862      * @param dependencies list of module dependencies
863      */

864     public void setDependencies(List JavaDoc dependencies) {
865
866         checkFrozen();
867         m_dependencies = dependencies;
868     }
869
870     /**
871      * Sets the description of this module.<p>
872      *
873      *
874      * <i>Please note:</i>It's not possible to set the modules description once the module
875      * configuration has been frozen.<p>
876      *
877      * @param value the module description to set
878      */

879     public void setDescription(String JavaDoc value) {
880
881         checkFrozen();
882         m_description = value.trim();
883     }
884
885     /**
886      * Sets the additional explorer types that belong to this module.<p>
887      *
888      * @param explorerTypeSettings the explorer type settings.
889      */

890     public void setExplorerTypes(List JavaDoc explorerTypeSettings) {
891
892         m_explorerTypeSettings = explorerTypeSettings;
893     }
894
895     /**
896      * Sets the exportpoints of this module.<p>
897      *
898      * @param exportPoints the exportpoints of this module.
899      */

900     public void setExportPoints(List JavaDoc exportPoints) {
901
902         m_exportPoints = exportPoints;
903     }
904
905     /**
906      * Sets the group name of this module.<p>
907      *
908      *
909      * <i>Please note:</i>It's not possible to set the modules group name once the module
910      * configuration has been frozen.<p>
911      *
912      * @param value the module group name to set
913      */

914     public void setGroup(String JavaDoc value) {
915
916         checkFrozen();
917         m_group = value;
918     }
919
920     /**
921      * Sets the name of this module.<p>
922      *
923      * The module name must be a valid java package name.<p>
924      *
925      * <i>Please note:</i>It's not possible to set the modules name once the module
926      * configuration has been frozen.<p>
927      *
928      * @param value the module name to set
929      */

930     public void setName(String JavaDoc value) {
931
932         checkFrozen();
933         if (!CmsStringUtil.isValidJavaClassName(value)) {
934             throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_MODULE_NAME_1, value));
935         }
936         m_name = value;
937     }
938
939     /**
940      * Sets the "nice" display name of this module.<p>
941      *
942      * <i>Please note:</i>It's not possible to set the modules "nice" name once the module
943      * configuration has been frozen.<p>
944      *
945      * @param value the "nice" display name of this module to set
946      */

947     public void setNiceName(String JavaDoc value) {
948
949         checkFrozen();
950         if (CmsStringUtil.isEmptyOrWhitespaceOnly(value)) {
951             m_niceName = getName();
952         } else {
953             m_niceName = value.trim();
954         }
955     }
956
957     /**
958      * Sets the parameters of this module.<p>
959      *
960      *
961      * <i>Please note:</i>It's not possible to set the module parameters once the module
962      * configuration has been frozen.<p>
963      *
964      * @param value the module parameters to set
965      */

966     public void setParameters(SortedMap JavaDoc value) {
967
968         checkFrozen();
969         m_parameters = value;
970     }
971
972     /**
973      * Sets the resources of this module.<p>
974      *
975      *
976      * <i>Please note:</i>It's not possible to set the module resources once the module
977      * configuration has been frozen.<p>
978      *
979      * @param value the module resources to set
980      */

981     public void setResources(List JavaDoc value) {
982
983         checkFrozen();
984         m_resources = value;
985     }
986
987     /**
988      * Sets the list of additional resource types that belong to this module.<p>
989      *
990      * @param resourceTypes list of additional resource types that belong to this module
991      */

992     public void setResourceTypes(List JavaDoc resourceTypes) {
993
994         m_resourceTypes = Collections.unmodifiableList(resourceTypes);
995     }
996
997     /**
998      * Sets the user who installed of this module.<p>
999      *
1000     *
1001     * <i>Please note:</i>It's not possible to set the user installed once the module
1002     * configuration has been frozen.<p>
1003     *
1004     * @param value the user who installed this module
1005     */

1006    public void setUserInstalled(String JavaDoc value) {
1007
1008        checkFrozen();
1009        m_userInstalled = value.trim();
1010    }
1011
1012    /**
1013     * Checks if this modules configuration is frozen.<p>
1014     *
1015     * @throws CmsIllegalArgumentException in case the configuration is already frozen
1016     */

1017    protected void checkFrozen() throws CmsIllegalArgumentException {
1018
1019        if (m_frozen) {
1020            throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_MODULE_FROZEN_1, getName()));
1021        }
1022    }
1023
1024    /**
1025     * Initializes this module, also freezing the module configuration.<p>
1026     *
1027     * @param cms an initialized OpenCms user context
1028     *
1029     * @throws CmsRoleViolationException if the given users does not have the <code>{@link CmsRole#MODULE_MANAGER}</code> role
1030     */

1031    protected void initialize(CmsObject cms) throws CmsRoleViolationException {
1032
1033        checkFrozen();
1034        // check if the user has the required permissions
1035
cms.checkRole(CmsRole.MODULE_MANAGER);
1036
1037        m_frozen = true;
1038        m_resources = Collections.unmodifiableList(m_resources);
1039    }
1040
1041    /**
1042     * Sets the module action instance for this module.<p>
1043     *
1044     * @param actionInstance the module action instance for this module
1045     */

1046    /*package*/void setActionInstance(I_CmsModuleAction actionInstance) {
1047
1048        m_actionInstance = actionInstance;
1049
1050    }
1051
1052    /**
1053     * Resolves the module property "additionalresources" to the resource list and
1054     * vice versa.<p>
1055     *
1056     * This "special" module property is required as long as we do not have a new
1057     * GUI for editing of module resource entries. Once we have the new GUI, the
1058     * handling of "additionalresources" will be moved to the import of the module
1059     * and done only if the imported module is a 5.0 module.<p>
1060     */

1061    private void initOldAdditionalResources() {
1062
1063        SortedMap JavaDoc parameters = new TreeMap JavaDoc(m_parameters);
1064        List JavaDoc resources = new ArrayList JavaDoc(m_resources);
1065
1066        String JavaDoc additionalResources;
1067        additionalResources = (String JavaDoc)parameters.get(MODULE_PROPERTY_ADDITIONAL_RESOURCES);
1068        if (additionalResources != null) {
1069            StringTokenizer JavaDoc tok = new StringTokenizer JavaDoc(
1070                additionalResources,
1071                MODULE_PROPERTY_ADDITIONAL_RESOURCES_SEPARATOR);
1072            while (tok.hasMoreTokens()) {
1073                String JavaDoc resource = tok.nextToken().trim();
1074                if ((!"-".equals(resource)) && (!resources.contains(resource))) {
1075                    resources.add(resource);
1076                }
1077            }
1078        }
1079
1080        m_resources = resources;
1081    }
1082
1083    /**
1084     * Checks if two objects are either both null, or equal.<p>
1085     *
1086     * @param a the first object to check
1087     * @param b the second object to check
1088     * @return true if the two object are either both null, or equal
1089     */

1090    private boolean isEqual(Object JavaDoc a, Object JavaDoc b) {
1091
1092        if (a == null) {
1093            return (b == null);
1094        }
1095        if (b == null) {
1096            return false;
1097        }
1098        return a.equals(b);
1099    }
1100}
Popular Tags