KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > configuration > CmsVfsConfiguration


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/configuration/CmsVfsConfiguration.java,v $
3  * Date : $Date: 2006/09/22 15:17:02 $
4  * Version: $Revision: 1.41 $
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.configuration;
33
34 import org.opencms.file.CmsProperty;
35 import org.opencms.file.collectors.I_CmsResourceCollector;
36 import org.opencms.file.types.I_CmsResourceType;
37 import org.opencms.loader.CmsMimeType;
38 import org.opencms.loader.CmsResourceManager;
39 import org.opencms.loader.I_CmsResourceLoader;
40 import org.opencms.main.CmsLog;
41 import org.opencms.main.OpenCms;
42 import org.opencms.util.CmsResourceTranslator;
43 import org.opencms.widgets.I_CmsWidget;
44 import org.opencms.xml.CmsXmlContentTypeManager;
45 import org.opencms.xml.types.I_CmsXmlSchemaType;
46
47 import java.util.ArrayList JavaDoc;
48 import java.util.Collections JavaDoc;
49 import java.util.Iterator JavaDoc;
50 import java.util.List JavaDoc;
51 import java.util.Map JavaDoc;
52
53 import org.apache.commons.digester.Digester;
54
55 import org.dom4j.Element;
56
57 /**
58  * VFS master configuration class.<p>
59  *
60  * @author Alexander Kandzior
61  *
62  * @version $Revision: 1.41 $
63  *
64  * @since 6.0.0
65  */

66 public class CmsVfsConfiguration extends A_CmsXmlConfiguration implements I_CmsXmlConfiguration {
67
68     /** The widget attribute. */
69     public static final String JavaDoc A_DEFAULTWIDGET = "defaultwidget";
70
71     /** The extension attribute name. */
72     public static final String JavaDoc A_EXTENSION = "extension";
73
74     /** The source attribute name. */
75     public static final String JavaDoc A_SOURCE = "source";
76
77     /** The target attribute name. */
78     public static final String JavaDoc A_TARGET = "target";
79
80     /** The name of the DTD for this configuration. */
81     public static final String JavaDoc CONFIGURATION_DTD_NAME = "opencms-vfs.dtd";
82
83     /** The name of the default XML file for this configuration. */
84     public static final String JavaDoc DEFAULT_XML_FILE_NAME = "opencms-vfs.xml";
85
86     /** The collector node name. */
87     public static final String JavaDoc N_COLLECTOR = "collector";
88
89     /** The collectors node name. */
90     public static final String JavaDoc N_COLLECTORS = "collectors";
91
92     /** The copy-resource node name.*/
93     public static final String JavaDoc N_COPY_RESOURCE = "copy-resource";
94
95     /** The copy-resources node name.*/
96     public static final String JavaDoc N_COPY_RESOURCES = "copy-resources";
97
98     /** The defaultfile node name. */
99     public static final String JavaDoc N_DEFAULTFILE = "defaultfile";
100
101     /** The defaultfiles node name. */
102     public static final String JavaDoc N_DEFAULTFILES = "defaultfiles";
103
104     /** File translations node name. */
105     public static final String JavaDoc N_FILETRANSLATIONS = "filetranslations";
106
107     /** Folder translations node name. */
108     public static final String JavaDoc N_FOLDERTRANSLATIONS = "foldertranslations";
109
110     /** The node name of an individual resource loader. */
111     public static final String JavaDoc N_LOADER = "loader";
112
113     /** The mapping node name. */
114     public static final String JavaDoc N_MAPPING = "mapping";
115
116     /** The mappings node name. */
117     public static final String JavaDoc N_MAPPINGS = "mappings";
118
119     /** The mimetype node name. */
120     public static final String JavaDoc N_MIMETYPE = "mimetype";
121
122     /** The mimetypes node name. */
123     public static final String JavaDoc N_MIMETYPES = "mimetypes";
124
125     /** The properties node name. */
126     public static final String JavaDoc N_PROPERTIES = "properties";
127
128     /** The resource loaders node name. */
129     public static final String JavaDoc N_RESOURCELOADERS = "resourceloaders";
130
131     /** The main resource node name. */
132     public static final String JavaDoc N_RESOURCES = "resources";
133
134     /** The resource types node name. */
135     public static final String JavaDoc N_RESOURCETYPES = "resourcetypes";
136
137     /** The schematype node name. */
138     public static final String JavaDoc N_SCHEMATYPE = "schematype";
139
140     /** The schematypes node name. */
141     public static final String JavaDoc N_SCHEMATYPES = "schematypes";
142
143     /** Individual translation node name. */
144     public static final String JavaDoc N_TRANSLATION = "translation";
145
146     /** The translations master node name. */
147     public static final String JavaDoc N_TRANSLATIONS = "translations";
148
149     /** The node name of an individual resource type. */
150     public static final String JavaDoc N_TYPE = "type";
151
152     /** The node name for the version history. */
153     public static final String JavaDoc N_VERSIONHISTORY = "versionhistory";
154
155     /** The main vfs configuration node name. */
156     public static final String JavaDoc N_VFS = "vfs";
157
158     /** The widget node name. */
159     public static final String JavaDoc N_WIDGET = "widget";
160
161     /** The widgets node name. */
162     public static final String JavaDoc N_WIDGETS = "widgets";
163
164     /** The xmlcontent node name. */
165     public static final String JavaDoc N_XMLCONTENT = "xmlcontent";
166
167     /** The xmlcontents node name. */
168     public static final String JavaDoc N_XMLCONTENTS = "xmlcontents";
169
170     /** The configured XML content type manager. */
171     CmsXmlContentTypeManager m_xmlContentTypeManager;
172
173     /** The list of configured default files. */
174     private List JavaDoc m_defaultFiles;
175
176     /** Controls if file translation is enabled. */
177     private boolean m_fileTranslationEnabled;
178
179     /** The list of file translations. */
180     private List JavaDoc m_fileTranslations;
181
182     /** Controls if folder translation is enabled. */
183     private boolean m_folderTranslationEnabled;
184
185     /** The list of folder translations. */
186     private List JavaDoc m_folderTranslations;
187
188     /** The configured resource manager. */
189     private CmsResourceManager m_resourceManager;
190
191     /**
192      * Public constructor, will be called by configuration manager.<p>
193      */

194     public CmsVfsConfiguration() {
195
196         setXmlFileName(DEFAULT_XML_FILE_NAME);
197         m_fileTranslations = new ArrayList JavaDoc();
198         m_folderTranslations = new ArrayList JavaDoc();
199         m_defaultFiles = new ArrayList JavaDoc();
200         if (CmsLog.INIT.isInfoEnabled()) {
201             CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_VFS_CONFIG_INIT_0));
202         }
203     }
204
205     /**
206      * Adds the resource type rules to the given digester.<p>
207      *
208      * @param digester the digester to add the rules to
209      */

210     public static void addResourceTypeXmlRules(Digester digester) {
211
212         // add rules for resource types
213
digester.addFactoryCreate("*/" + N_RESOURCETYPES + "/" + N_TYPE, CmsDigesterResourceTypeCreationFactory.class);
214
215         digester.addCallMethod(
216             "*/" + N_RESOURCETYPES + "/" + N_TYPE,
217             I_CmsConfigurationParameterHandler.INIT_CONFIGURATION_METHOD,
218             3);
219         // please note: the resource types use a special version of the init method with 3 parameters
220
digester.addCallParam("*/" + N_RESOURCETYPES + "/" + N_TYPE, 0, A_NAME);
221         digester.addCallParam("*/" + N_RESOURCETYPES + "/" + N_TYPE, 1, A_ID);
222         digester.addCallParam("*/" + N_RESOURCETYPES + "/" + N_TYPE, 2, A_CLASS);
223
224         digester.addSetNext("*/" + N_RESOURCETYPES + "/" + N_TYPE, I_CmsResourceType.ADD_RESOURCE_TYPE_METHOD);
225
226         // add rules for default properties
227
digester.addObjectCreate(
228             "*/" + N_RESOURCETYPES + "/" + N_TYPE + "/" + N_PROPERTIES + "/" + N_PROPERTY,
229             CmsProperty.class);
230         digester.addCallMethod("*/"
231             + N_RESOURCETYPES
232             + "/"
233             + N_TYPE
234             + "/"
235             + N_PROPERTIES
236             + "/"
237             + N_PROPERTY
238             + "/"
239             + N_NAME, "setName", 1);
240         digester.addCallParam("*/"
241             + N_RESOURCETYPES
242             + "/"
243             + N_TYPE
244             + "/"
245             + N_PROPERTIES
246             + "/"
247             + N_PROPERTY
248             + "/"
249             + N_NAME, 0);
250
251         digester.addCallMethod("*/"
252             + N_RESOURCETYPES
253             + "/"
254             + N_TYPE
255             + "/"
256             + N_PROPERTIES
257             + "/"
258             + N_PROPERTY
259             + "/"
260             + N_VALUE, "setValue", 2);
261         digester.addCallParam("*/"
262             + N_RESOURCETYPES
263             + "/"
264             + N_TYPE
265             + "/"
266             + N_PROPERTIES
267             + "/"
268             + N_PROPERTY
269             + "/"
270             + N_VALUE, 0);
271         digester.addCallParam("*/"
272             + N_RESOURCETYPES
273             + "/"
274             + N_TYPE
275             + "/"
276             + N_PROPERTIES
277             + "/"
278             + N_PROPERTY
279             + "/"
280             + N_VALUE, 1, A_TYPE);
281
282         digester.addSetNext(
283             "*/" + N_RESOURCETYPES + "/" + N_TYPE + "/" + N_PROPERTIES + "/" + N_PROPERTY,
284             "addDefaultProperty");
285
286         // extension mapping rules
287
digester.addCallMethod(
288             "*/" + N_RESOURCETYPES + "/" + N_TYPE + "/" + N_MAPPINGS + "/" + N_MAPPING,
289             I_CmsResourceType.ADD_MAPPING_METHOD,
290             1);
291         digester.addCallParam("*/" + N_RESOURCETYPES + "/" + N_TYPE + "/" + N_MAPPINGS + "/" + N_MAPPING, 0, A_SUFFIX);
292
293         // copy resource rules
294
digester.addCallMethod(
295             "*/" + N_RESOURCETYPES + "/" + N_TYPE + "/" + N_COPY_RESOURCES + "/" + N_COPY_RESOURCE,
296             "addCopyResource",
297             3);
298         digester.addCallParam(
299             "*/" + N_RESOURCETYPES + "/" + N_TYPE + "/" + N_COPY_RESOURCES + "/" + N_COPY_RESOURCE,
300             0,
301             A_SOURCE);
302         digester.addCallParam(
303             "*/" + N_RESOURCETYPES + "/" + N_TYPE + "/" + N_COPY_RESOURCES + "/" + N_COPY_RESOURCE,
304             1,
305             A_TARGET);
306         digester.addCallParam(
307             "*/" + N_RESOURCETYPES + "/" + N_TYPE + "/" + N_COPY_RESOURCES + "/" + N_COPY_RESOURCE,
308             2,
309             A_TYPE);
310     }
311
312     /**
313      * Creates the xml output for resourcetype nodes.<p>
314      *
315      * @param startNode the startnode to add all rescource types to
316      * @param resourceTypes the list of resource types
317      * @param module flag, signaling to add them module resource types or not
318      */

319     public static void generateResourceTypeXml(Element startNode, List JavaDoc resourceTypes, boolean module) {
320
321         for (int i = 0; i < resourceTypes.size(); i++) {
322             I_CmsResourceType resType = (I_CmsResourceType)resourceTypes.get(i);
323             // only add this resource type to the xml output, if it is no additional type defined
324
// in a module
325
if (resType.isAdditionalModuleResourceType() == module) {
326                 Element resourceType = startNode.addElement(N_TYPE).addAttribute(A_CLASS, resType.getClassName());
327                 // add type id and type name
328
resourceType.addAttribute(A_NAME, resType.getTypeName());
329                 resourceType.addAttribute(A_ID, String.valueOf(resType.getTypeId()));
330                 // add resource mappings
331
List JavaDoc mappings = resType.getConfiguredMappings();
332                 if ((mappings != null) && (mappings.size() > 0)) {
333                     Element mappingsNode = resourceType.addElement(N_MAPPINGS);
334                     for (int j = 0; j < mappings.size(); j++) {
335                         Element mapping = mappingsNode.addElement(N_MAPPING);
336                         mapping.addAttribute(A_SUFFIX, (String JavaDoc)mappings.get(j));
337                     }
338                 }
339                 // add default properties
340
List JavaDoc properties = resType.getConfiguredDefaultProperties();
341                 if ((properties != null) && (properties.size() > 0)) {
342                     Element propertiesNode = resourceType.addElement(N_PROPERTIES);
343                     Iterator JavaDoc p = properties.iterator();
344                     while (p.hasNext()) {
345                         CmsProperty property = (CmsProperty)p.next();
346                         Element propertyNode = propertiesNode.addElement(N_PROPERTY);
347                         propertyNode.addElement(N_NAME).addText(property.getName());
348                         if (property.getStructureValue() != null) {
349                             propertyNode.addElement(N_VALUE).addCDATA(property.getStructureValue());
350                         }
351                         if (property.getResourceValue() != null) {
352                             propertyNode.addElement(N_VALUE).addAttribute(A_TYPE, CmsProperty.TYPE_SHARED).addCDATA(
353                                 property.getResourceValue());
354                         }
355                     }
356                 }
357                 // add copy resources
358
List JavaDoc copyRes = resType.getConfiguredCopyResources();
359                 if ((copyRes != null) && (copyRes.size() > 0)) {
360                     Element copyResNode = resourceType.addElement(N_COPY_RESOURCES);
361                     Iterator JavaDoc p = copyRes.iterator();
362                     while (p.hasNext()) {
363                         CmsConfigurationCopyResource cRes = (CmsConfigurationCopyResource)p.next();
364                         Element cNode = copyResNode.addElement(N_COPY_RESOURCE);
365                         cNode.addAttribute(A_SOURCE, cRes.getSource());
366                         if (!cRes.isTargetWasNull()) {
367                             cNode.addAttribute(A_TARGET, cRes.getTarget());
368                         }
369                         if (!cRes.isTypeWasNull()) {
370                             cNode.addAttribute(A_TYPE, cRes.getTypeString());
371                         }
372                     }
373                 }
374                 // add optional parameters
375
Map JavaDoc prop = resType.getConfiguration();
376                 if (prop != null) {
377                     List JavaDoc sortedRuntimeProperties = new ArrayList JavaDoc(prop.keySet());
378                     Collections.sort(sortedRuntimeProperties);
379                     Iterator JavaDoc it = sortedRuntimeProperties.iterator();
380                     while (it.hasNext()) {
381                         String JavaDoc key = (String JavaDoc)it.next();
382                         // create <param name="">value</param> subnodes
383
Object JavaDoc val = prop.get(key);
384                         resourceType.addElement(N_PARAM).addAttribute(A_NAME, key).addText(String.valueOf(val));
385                         }
386                     }
387                 }
388             }
389         }
390
391     /**
392      * Adds a directory default file.<p>
393      *
394      * @param defaultFile the directory default file to add
395      */

396     public void addDefaultFile(String JavaDoc defaultFile) {
397
398         m_defaultFiles.add(defaultFile);
399         if (CmsLog.INIT.isInfoEnabled()) {
400             CmsLog.INIT.info(Messages.get().getBundle().key(
401                 Messages.INIT_VFS_DEFAULT_FILE_2,
402                 new Integer JavaDoc(m_defaultFiles.size()),
403                 defaultFile));
404         }
405     }
406
407     /**
408      * Adds one file translation rule.<p>
409      *
410      * @param translation the file translation rule to add
411      */

412     public void addFileTranslation(String JavaDoc translation) {
413
414         m_fileTranslations.add(translation);
415         if (CmsLog.INIT.isInfoEnabled()) {
416             CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_VFS_ADD_FILE_TRANSLATION_1, translation));
417         }
418     }
419
420     /**
421      * Adds one folder translation rule.<p>
422      *
423      * @param translation the folder translation rule to add
424      */

425     public void addFolderTranslation(String JavaDoc translation) {
426
427         m_folderTranslations.add(translation);
428         if (CmsLog.INIT.isInfoEnabled()) {
429             CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_VFS_ADD_FOLDER_TRANSLATION_1, translation));
430         }
431     }
432
433     /**
434      * @see org.opencms.configuration.I_CmsXmlConfiguration#addXmlDigesterRules(org.apache.commons.digester.Digester)
435      */

436     public void addXmlDigesterRules(Digester digester) {
437
438         // add finish rule
439
digester.addCallMethod("*/" + N_VFS, "initializeFinished");
440
441         // creation of the resource manager
442
digester.addObjectCreate("*/" + N_VFS + "/" + N_RESOURCES, CmsResourceManager.class);
443         digester.addCallMethod(
444             "*/" + N_VFS + "/" + N_RESOURCES,
445             I_CmsConfigurationParameterHandler.INIT_CONFIGURATION_METHOD);
446         digester.addSetNext("*/" + N_VFS + "/" + N_RESOURCES, "setResourceManager");
447
448         // add rules for resource loaders
449
digester.addObjectCreate(
450             "*/" + N_VFS + "/" + N_RESOURCES + "/" + N_RESOURCELOADERS + "/" + N_LOADER,
451             A_CLASS,
452             CmsConfigurationException.class);
453         digester.addCallMethod(
454             "*/" + N_VFS + "/" + N_RESOURCES + "/" + N_RESOURCELOADERS + "/" + N_LOADER,
455             I_CmsConfigurationParameterHandler.INIT_CONFIGURATION_METHOD);
456         digester.addSetNext("*/" + N_VFS + "/" + N_RESOURCES + "/" + N_RESOURCELOADERS + "/" + N_LOADER, "addLoader");
457
458         // add rules for resource types
459
addResourceTypeXmlRules(digester);
460
461         // add rules for VFS content collectors
462
digester.addCallMethod(
463             "*/" + N_VFS + "/" + N_RESOURCES + "/" + N_COLLECTORS + "/" + N_COLLECTOR,
464             "addContentCollector",
465             2);
466         digester.addCallParam("*/" + N_VFS + "/" + N_RESOURCES + "/" + N_COLLECTORS + "/" + N_COLLECTOR, 0, A_CLASS);
467         digester.addCallParam("*/" + N_VFS + "/" + N_RESOURCES + "/" + N_COLLECTORS + "/" + N_COLLECTOR, 1, A_ORDER);
468
469         // add MIME type rules
470
digester.addCallMethod(
471             "*/" + N_VFS + "/" + N_RESOURCES + "/" + N_MIMETYPES + "/" + N_MIMETYPE,
472             "addMimeType",
473             2);
474         digester.addCallParam("*/" + N_VFS + "/" + N_RESOURCES + "/" + N_MIMETYPES + "/" + N_MIMETYPE, 0, A_EXTENSION);
475         digester.addCallParam("*/" + N_VFS + "/" + N_RESOURCES + "/" + N_MIMETYPES + "/" + N_MIMETYPE, 1, A_TYPE);
476
477         // generic <param> parameter rules
478
digester.addCallMethod(
479             "*/" + I_CmsXmlConfiguration.N_PARAM,
480             I_CmsConfigurationParameterHandler.ADD_PARAMETER_METHOD,
481             2);
482         digester.addCallParam("*/" + I_CmsXmlConfiguration.N_PARAM, 0, I_CmsXmlConfiguration.A_NAME);
483         digester.addCallParam("*/" + I_CmsXmlConfiguration.N_PARAM, 1);
484
485         // add rule for default files
486
digester.addCallMethod("*/" + N_VFS + "/" + N_DEFAULTFILES + "/" + N_DEFAULTFILE, "addDefaultFile", 1);
487         digester.addCallParam("*/" + N_VFS + "/" + N_DEFAULTFILES + "/" + N_DEFAULTFILE, 0, A_NAME);
488
489         // add rules for file translations
490
digester.addCallMethod(
491             "*/" + N_VFS + "/" + N_TRANSLATIONS + "/" + N_FILETRANSLATIONS + "/" + N_TRANSLATION,
492             "addFileTranslation",
493             0);
494         digester.addCallMethod(
495             "*/" + N_VFS + "/" + N_TRANSLATIONS + "/" + N_FILETRANSLATIONS,
496             "setFileTranslationEnabled",
497             1);
498         digester.addCallParam("*/" + N_VFS + "/" + N_TRANSLATIONS + "/" + N_FILETRANSLATIONS, 0, A_ENABLED);
499
500         // add rules for file translations
501
digester.addCallMethod(
502             "*/" + N_VFS + "/" + N_TRANSLATIONS + "/" + N_FOLDERTRANSLATIONS + "/" + N_TRANSLATION,
503             "addFolderTranslation",
504             0);
505         digester.addCallMethod(
506             "*/" + N_VFS + "/" + N_TRANSLATIONS + "/" + N_FOLDERTRANSLATIONS,
507             "setFolderTranslationEnabled",
508             1);
509         digester.addCallParam("*/" + N_VFS + "/" + N_TRANSLATIONS + "/" + N_FOLDERTRANSLATIONS, 0, A_ENABLED);
510
511         // XML content type manager creation rules
512
digester.addObjectCreate("*/" + N_VFS + "/" + N_XMLCONTENT, CmsXmlContentTypeManager.class);
513         digester.addSetNext("*/" + N_VFS + "/" + N_XMLCONTENT, "setXmlContentTypeManager");
514
515         // XML content widgets add rules
516
digester.addCallMethod("*/" + N_VFS + "/" + N_XMLCONTENT + "/" + N_WIDGETS + "/" + N_WIDGET, "addWidget", 2);
517         digester.addCallParam("*/" + N_VFS + "/" + N_XMLCONTENT + "/" + N_WIDGETS + "/" + N_WIDGET, 0, A_CLASS);
518         digester.addCallParam("*/" + N_VFS + "/" + N_XMLCONTENT + "/" + N_WIDGETS + "/" + N_WIDGET, 1, A_ALIAS);
519
520         // XML content schema type add rules
521
digester.addCallMethod(
522             "*/" + N_VFS + "/" + N_XMLCONTENT + "/" + N_SCHEMATYPES + "/" + N_SCHEMATYPE,
523             "addSchemaType",
524             2);
525         digester.addCallParam("*/" + N_VFS + "/" + N_XMLCONTENT + "/" + N_SCHEMATYPES + "/" + N_SCHEMATYPE, 0, A_CLASS);
526         digester.addCallParam(
527             "*/" + N_VFS + "/" + N_XMLCONTENT + "/" + N_SCHEMATYPES + "/" + N_SCHEMATYPE,
528             1,
529             A_DEFAULTWIDGET);
530     }
531
532     /**
533      * @see org.opencms.configuration.I_CmsXmlConfiguration#generateXml(org.dom4j.Element)
534      */

535     public Element generateXml(Element parent) {
536
537         if (OpenCms.getRunLevel() >= OpenCms.RUNLEVEL_3_SHELL_ACCESS) {
538             m_resourceManager = OpenCms.getResourceManager();
539             m_xmlContentTypeManager = OpenCms.getXmlContentTypeManager();
540             m_defaultFiles = OpenCms.getDefaultFiles();
541         }
542
543         // generate vfs node and subnodes
544
Element vfs = parent.addElement(N_VFS);
545
546         // add resources main element
547
Element resources = vfs.addElement(N_RESOURCES);
548
549         // add resource loader
550
Element resourceloadersElement = resources.addElement(N_RESOURCELOADERS);
551         List JavaDoc loaders = m_resourceManager.getLoaders();
552         for (int i = 0; i < loaders.size(); i++) {
553             I_CmsResourceLoader loader = (I_CmsResourceLoader)loaders.get(i);
554             // add the loader node
555
Element loaderNode = resourceloadersElement.addElement(N_LOADER);
556             loaderNode.addAttribute(A_CLASS, loader.getClass().getName());
557             Map JavaDoc loaderConfiguration = loader.getConfiguration();
558             if (loaderConfiguration != null) {
559                 Iterator JavaDoc it = loaderConfiguration.keySet().iterator();
560                 while (it.hasNext()) {
561                     String JavaDoc name = (String JavaDoc)it.next();
562                     String JavaDoc value = loaderConfiguration.get(name).toString();
563                     Element paramNode = loaderNode.addElement(N_PARAM);
564                     paramNode.addAttribute(A_NAME, name);
565                     paramNode.addText(value);
566                 }
567             }
568         }
569
570         // add resource types
571
Element resourcetypesElement = resources.addElement(N_RESOURCETYPES);
572         List JavaDoc resourceTypes = m_resourceManager.getResourceTypes();
573         generateResourceTypeXml(resourcetypesElement, resourceTypes, false);
574
575         // add VFS content collectors
576
Element collectorsElement = resources.addElement(N_COLLECTORS);
577         Iterator JavaDoc it = m_resourceManager.getRegisteredContentCollectors().iterator();
578         while (it.hasNext()) {
579             I_CmsResourceCollector collector = (I_CmsResourceCollector)it.next();
580             collectorsElement.addElement(N_COLLECTOR).addAttribute(A_CLASS, collector.getClass().getName()).addAttribute(
581                 A_ORDER,
582                 String.valueOf(collector.getOrder()));
583         }
584
585         // add MIME types
586
Element mimeTypesElement = resources.addElement(N_MIMETYPES);
587         it = m_resourceManager.getMimeTypes().iterator();
588         while (it.hasNext()) {
589             CmsMimeType type = (CmsMimeType)it.next();
590             mimeTypesElement.addElement(N_MIMETYPE).addAttribute(A_EXTENSION, type.getExtension()).addAttribute(
591                 A_TYPE,
592                 type.getType());
593         }
594
595         // add default file names
596
Element defaultFileElement = vfs.addElement(N_DEFAULTFILES);
597         it = m_defaultFiles.iterator();
598         while (it.hasNext()) {
599             defaultFileElement.addElement(N_DEFAULTFILE).addAttribute(A_NAME, (String JavaDoc)it.next());
600         }
601
602         // add translation rules
603
Element translationsElement = vfs.addElement(N_TRANSLATIONS);
604
605         // file translation rules
606
Element fileTransElement = translationsElement.addElement(N_FILETRANSLATIONS).addAttribute(
607             A_ENABLED,
608             String.valueOf(m_fileTranslationEnabled));
609         it = m_fileTranslations.iterator();
610         while (it.hasNext()) {
611             fileTransElement.addElement(N_TRANSLATION).setText(it.next().toString());
612         }
613
614         // folder translation rules
615
Element folderTransElement = translationsElement.addElement(N_FOLDERTRANSLATIONS).addAttribute(
616             A_ENABLED,
617             String.valueOf(m_folderTranslationEnabled));
618         it = m_folderTranslations.iterator();
619         while (it.hasNext()) {
620             folderTransElement.addElement(N_TRANSLATION).setText(it.next().toString());
621         }
622
623         // XML content configuration
624
Element xmlContentsElement = vfs.addElement(N_XMLCONTENT);
625
626         // XML widgets
627
Element xmlWidgetsElement = xmlContentsElement.addElement(N_WIDGETS);
628         it = m_xmlContentTypeManager.getRegisteredWidgetNames().iterator();
629         while (it.hasNext()) {
630             String JavaDoc widget = (String JavaDoc)it.next();
631             Element widgetElement = xmlWidgetsElement.addElement(N_WIDGET).addAttribute(A_CLASS, widget);
632             String JavaDoc alias = m_xmlContentTypeManager.getRegisteredWidgetAlias(widget);
633             if (alias != null) {
634                 widgetElement.addAttribute(A_ALIAS, alias);
635             }
636         }
637
638         // XML content types
639
Element xmlSchemaTypesElement = xmlContentsElement.addElement(N_SCHEMATYPES);
640         it = m_xmlContentTypeManager.getRegisteredSchemaTypes().iterator();
641         while (it.hasNext()) {
642             I_CmsXmlSchemaType type = (I_CmsXmlSchemaType)it.next();
643             I_CmsWidget widget = m_xmlContentTypeManager.getWidgetDefault(type.getTypeName());
644             xmlSchemaTypesElement.addElement(N_SCHEMATYPE).addAttribute(A_CLASS, type.getClass().getName()).addAttribute(
645                 A_DEFAULTWIDGET,
646                 widget.getClass().getName());
647         }
648
649         // return the vfs node
650
return vfs;
651     }
652
653     /**
654      * Returns the (umodifiable) list of configured directory default files.<p>
655      *
656      * @return the (umodifiable) list of configured directory default files
657      */

658     public List JavaDoc getDefaultFiles() {
659
660         return Collections.unmodifiableList(m_defaultFiles);
661     }
662
663     /**
664      * @see org.opencms.configuration.I_CmsXmlConfiguration#getDtdFilename()
665      */

666     public String JavaDoc getDtdFilename() {
667
668         return CONFIGURATION_DTD_NAME;
669     }
670
671     /**
672      * Returns the file resource translator that has been initialized
673      * with the configured file translation rules.<p>
674      *
675      * @return the file resource translator
676      */

677     public CmsResourceTranslator getFileTranslator() {
678
679         String JavaDoc[] array = m_fileTranslationEnabled ? new String JavaDoc[m_fileTranslations.size()] : new String JavaDoc[0];
680         for (int i = 0; i < m_fileTranslations.size(); i++) {
681             array[i] = (String JavaDoc)m_fileTranslations.get(i);
682         }
683         return new CmsResourceTranslator(array, true);
684     }
685
686     /**
687      * Returns the folder resource translator that has been initialized
688      * with the configured folder translation rules.<p>
689      *
690      * @return the folder resource translator
691      */

692     public CmsResourceTranslator getFolderTranslator() {
693
694         String JavaDoc[] array = m_folderTranslationEnabled ? new String JavaDoc[m_folderTranslations.size()] : new String JavaDoc[0];
695         for (int i = 0; i < m_folderTranslations.size(); i++) {
696             array[i] = (String JavaDoc)m_folderTranslations.get(i);
697         }
698         return new CmsResourceTranslator(array, false);
699     }
700
701     /**
702      * Returns the initialized resource manager.<p>
703      *
704      * @return the initialized resource manager
705      */

706     public CmsResourceManager getResourceManager() {
707
708         return m_resourceManager;
709     }
710
711     /**
712      * Returns the configured XML content type manager.<p>
713      *
714      * @return the configured XML content type manager
715      */

716     public CmsXmlContentTypeManager getXmlContentTypeManager() {
717
718         return m_xmlContentTypeManager;
719     }
720
721     /**
722      * Will be called when configuration of this object is finished.<p>
723      */

724     public void initializeFinished() {
725
726         if (CmsLog.INIT.isInfoEnabled()) {
727             CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_VFS_CONFIG_FINISHED_0));
728         }
729     }
730
731     /**
732      * Enables or disables the file translation rules.<p>
733      *
734      * @param value if <code>"true"</code>, file translation is enabled, otherwise it is disabled
735      */

736     public void setFileTranslationEnabled(String JavaDoc value) {
737
738         m_fileTranslationEnabled = Boolean.valueOf(value).booleanValue();
739         if (CmsLog.INIT.isInfoEnabled()) {
740             if (m_fileTranslationEnabled) {
741                 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_VFS_FILE_TRANSLATION_ENABLE_0));
742             } else {
743                 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_VFS_FILE_TRANSLATION_DISABLE_0));
744             }
745         }
746     }
747
748     /**
749      * Enables or disables the folder translation rules.<p>
750      *
751      * @param value if <code>"true"</code>, folder translation is enabled, otherwise it is disabled
752      */

753     public void setFolderTranslationEnabled(String JavaDoc value) {
754
755         m_folderTranslationEnabled = Boolean.valueOf(value).booleanValue();
756         if (CmsLog.INIT.isInfoEnabled()) {
757             if (m_folderTranslationEnabled) {
758                 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_VFS_FOLDER_TRANSLATION_ENABLE_0));
759             } else {
760                 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_VFS_FOLDER_TRANSLATION_DISABLE_0));
761             }
762         }
763     }
764
765     /**
766      * Sets the generated resource manager.<p>
767      *
768      * @param manager the resource manager to set
769      */

770     public void setResourceManager(CmsResourceManager manager) {
771
772         m_resourceManager = manager;
773     }
774
775     /**
776      * Sets the generated XML content type manager.<p>
777      *
778      * @param manager the generated XML content type manager to set
779      */

780     public void setXmlContentTypeManager(CmsXmlContentTypeManager manager) {
781
782         if (CmsLog.INIT.isInfoEnabled()) {
783             CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_VFS_XML_CONTENT_FINISHED_0));
784         }
785         m_xmlContentTypeManager = manager;
786     }
787
788 }
Popular Tags