KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/configuration/CmsImportExportConfiguration.java,v $
3  * Date : $Date: 2006/03/27 14:52:46 $
4  * Version: $Revision: 1.25 $
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.importexport.CmsImportExportManager;
35 import org.opencms.importexport.I_CmsImportExportHandler;
36 import org.opencms.main.CmsLog;
37 import org.opencms.security.I_CmsPrincipal;
38 import org.opencms.staticexport.CmsStaticExportExportRule;
39 import org.opencms.staticexport.CmsStaticExportManager;
40 import org.opencms.staticexport.CmsStaticExportRfsRule;
41
42 import java.io.File JavaDoc;
43 import java.util.Iterator JavaDoc;
44 import java.util.List JavaDoc;
45 import java.util.regex.Pattern JavaDoc;
46
47 import org.apache.commons.digester.Digester;
48
49 import org.dom4j.Element;
50
51 /**
52  * Import / export master configuration class.<p>
53  *
54  * @author Alexander Kandzior
55  *
56  * @version $Revision: 1.25 $
57  *
58  * @since 6.0.0
59  */

60 public class CmsImportExportConfiguration extends A_CmsXmlConfiguration implements I_CmsXmlConfiguration {
61
62     /** The name of the DTD for this configuration. */
63     public static final String JavaDoc CONFIGURATION_DTD_NAME = "opencms-importexport.dtd";
64
65     /** The name of the default XML file for this configuration. */
66     public static final String JavaDoc DEFAULT_XML_FILE_NAME = "opencms-importexport.xml";
67
68     /** Node that indicates page conversion. */
69     protected static final String JavaDoc N_CONVERT = "convert";
70
71     /** Node that contains a list of properties ignored during import. */
72     protected static final String JavaDoc N_IGNOREDPROPERTIES = "ignoredproperties";
73
74     /** The import immutable resources node. */
75     protected static final String JavaDoc N_IMMUTABLES = "immutables";
76
77     /** The node name of the import subconfiguration. */
78     protected static final String JavaDoc N_IMPORT = "import";
79
80     /** The main configuration node name. */
81     protected static final String JavaDoc N_IMPORTEXPORT = "importexport";
82
83     /** The node name of an individual import/export handler. */
84     protected static final String JavaDoc N_IMPORTEXPORTHANDLER = "importexporthandler";
85
86     /** Master node for import/export handlers. */
87     protected static final String JavaDoc N_IMPORTEXPORTHANDLERS = "importexporthandlers";
88
89     /** The node name of an individual import version class. */
90     protected static final String JavaDoc N_IMPORTVERSION = "importversion";
91
92     /** Master node for import version class names. */
93     protected static final String JavaDoc N_IMPORTVERSIONS = "importversions";
94
95     /** Node the contains an optional URL of old web application. */
96     protected static final String JavaDoc N_OLDWEBAPPURL = "oldwebappurl";
97
98     /** The import overwrite node name. */
99     protected static final String JavaDoc N_OVERWRITE = "overwrite";
100
101     /** An individual principal translation node. */
102     protected static final String JavaDoc N_PRINCIPALTRANSLATION = "principaltranslation";
103
104     /** The principal translation node. */
105     protected static final String JavaDoc N_PRINCIPALTRANSLATIONS = "principaltranslations";
106
107     /** The main configuration node for static export name. */
108     protected static final String JavaDoc N_STATICEXPORT = "staticexport";
109
110     /** The node name of the static export acceptcharset node. */
111     protected static final String JavaDoc N_STATICEXPORT_ACCEPTCHARSET = "acceptcharset";
112
113     /** The node name of the static export acceptlanguage node. */
114     protected static final String JavaDoc N_STATICEXPORT_ACCEPTLANGUAGE = "acceptlanguage";
115
116     /** The node name of the static export default node. */
117     protected static final String JavaDoc N_STATICEXPORT_DEFAULT = "defaultpropertyvalue";
118
119     /** The node name of the static export defualtsuffix node. */
120     protected static final String JavaDoc N_STATICEXPORT_DEFAULTSUFFIXES = "defaultsuffixes";
121
122     /** The node name of the static export rule description nodes. */
123     protected static final String JavaDoc N_STATICEXPORT_DESCRIPTION = "description";
124
125     /** The node name of the static export export-rule export node. */
126     protected static final String JavaDoc N_STATICEXPORT_EXPORT = "export-resources";
127
128     /** The node name of the static export exportheaders node. */
129     protected static final String JavaDoc N_STATICEXPORT_EXPORTHEADERS = "exportheaders";
130
131     /** The node name of the static export exportpath node. */
132     protected static final String JavaDoc N_STATICEXPORT_EXPORTPATH = "exportpath";
133
134     /** The node name of the static export export-rule node. */
135     protected static final String JavaDoc N_STATICEXPORT_EXPORTRULE = "export-rule";
136
137     /** The node name of the static export export-rules node. */
138     protected static final String JavaDoc N_STATICEXPORT_EXPORTRULES = "export-rules";
139
140     /** The node name of the static export exporturl node. */
141     protected static final String JavaDoc N_STATICEXPORT_EXPORTURL = "exporturl";
142
143     /** The node name of the static export handler node. */
144     protected static final String JavaDoc N_STATICEXPORT_HANDLER = "staticexporthandler";
145
146     /** The node name of the static export header node. */
147     protected static final String JavaDoc N_STATICEXPORT_HEADER = "header";
148
149     /** The node name of the static export export-rule modified node. */
150     protected static final String JavaDoc N_STATICEXPORT_MODIFIED = "modified-resources";
151
152     /** The node name of the static export rule name nodes. */
153     protected static final String JavaDoc N_STATICEXPORT_NAME = "name";
154
155     /** The node name of the static export plainoptimization node. */
156     protected static final String JavaDoc N_STATICEXPORT_PLAINOPTIMIZATION = "plainoptimization";
157
158     /** The node name of the static export regex node. */
159     protected static final String JavaDoc N_STATICEXPORT_REGEX = "regex";
160
161     /** The node name of the static export related-system-res node. */
162     protected static final String JavaDoc N_STATICEXPORT_RELATED_SYSTEM_RES = "related-system-res";
163
164     /** The node name of the static export relativelinks node. */
165     protected static final String JavaDoc N_STATICEXPORT_RELATIVELINKS = "userelativelinks";
166
167     /** The node name of the static export remoteaddr node. */
168     protected static final String JavaDoc N_STATICEXPORT_REMOTEADDR = "remoteaddr";
169
170     /** The node name of the static export rendersettings node. */
171     protected static final String JavaDoc N_STATICEXPORT_RENDERSETTINGS = "rendersettings";
172
173     /** The node name of the static export requestheaders node. */
174     protected static final String JavaDoc N_STATICEXPORT_REQUESTHEADERS = "requestheaders";
175
176     /** The node name of the static export resourcestorender node. */
177     protected static final String JavaDoc N_STATICEXPORT_RESOURCESTORENDER = "resourcestorender";
178
179     /** The node name of the static export rfx-prefix node. */
180     protected static final String JavaDoc N_STATICEXPORT_RFS_PREFIX = "rfs-prefix";
181
182     /** The node name of the static export rfx-rule node. */
183     protected static final String JavaDoc N_STATICEXPORT_RFS_RULE = "rfs-rule";
184
185     /** The node name of the static export rfx-rules node. */
186     protected static final String JavaDoc N_STATICEXPORT_RFS_RULES = "rfs-rules";
187
188     /** The node name of the static export rfx-rule source node. */
189     protected static final String JavaDoc N_STATICEXPORT_SOURCE = "source";
190
191     /** The node name of the static export suffix node. */
192     protected static final String JavaDoc N_STATICEXPORT_SUFFIX = "suffix";
193
194     /** The node name of the static export testresource node. */
195     protected static final String JavaDoc N_STATICEXPORT_TESTRESOURCE = "testresource";
196
197     /** The node name of the static export export-rule export uri node. */
198     protected static final String JavaDoc N_STATICEXPORT_URI = "uri";
199
200     /** The node name of the static export vfx-prefix node. */
201     protected static final String JavaDoc N_STATICEXPORT_VFS_PREFIX = "vfs-prefix";
202
203     /** The configured import/export manager. */
204     private CmsImportExportManager m_importExportManager;
205
206     /** The configured static export manager. */
207     private CmsStaticExportManager m_staticExportManager;
208
209     /**
210      * Public constructor, will be called by configuration manager.<p>
211      */

212     public CmsImportExportConfiguration() {
213
214         setXmlFileName(DEFAULT_XML_FILE_NAME);
215         if (CmsLog.INIT.isInfoEnabled()) {
216             CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_IMPORT_CONFIG_INIT_0));
217         }
218     }
219
220     /**
221      * @see org.opencms.configuration.I_CmsXmlConfiguration#addXmlDigesterRules(org.apache.commons.digester.Digester)
222      */

223     public void addXmlDigesterRules(Digester digester) {
224
225         // add finish rule
226
digester.addCallMethod("*/" + N_IMPORTEXPORT, "initializeFinished");
227
228         // creation of the import/export manager
229
digester.addObjectCreate("*/" + N_IMPORTEXPORT, CmsImportExportManager.class);
230         // import/export manager finished
231
digester.addSetNext("*/" + N_IMPORTEXPORT, "setImportExportManager");
232
233         // add rules for import/export handlers
234
digester.addObjectCreate(
235             "*/" + N_IMPORTEXPORT + "/" + N_IMPORTEXPORTHANDLERS + "/" + N_IMPORTEXPORTHANDLER,
236             A_CLASS,
237             CmsConfigurationException.class);
238         digester.addSetNext(
239             "*/" + N_IMPORTEXPORT + "/" + N_IMPORTEXPORTHANDLERS + "/" + N_IMPORTEXPORTHANDLER,
240             "addImportExportHandler");
241
242         // overwrite rule
243
digester.addCallMethod(
244             "*/" + N_IMPORTEXPORT + "/" + N_IMPORT + "/" + N_OVERWRITE,
245             "setOverwriteCollidingResources",
246             0);
247
248         // convert rule
249
digester.addCallMethod("*/" + N_IMPORTEXPORT + "/" + N_IMPORT + "/" + N_CONVERT, "setConvertToXmlPage", 0);
250
251         // old webapp rule
252
digester.addCallMethod("*/" + N_IMPORTEXPORT + "/" + N_IMPORT + "/" + N_OLDWEBAPPURL, "setOldWebAppUrl", 0);
253
254         // add rules for the import versions
255
digester.addObjectCreate("*/"
256             + N_IMPORTEXPORT
257             + "/"
258             + N_IMPORT
259             + "/"
260             + N_IMPORTVERSIONS
261             + "/"
262             + N_IMPORTVERSION, A_CLASS, CmsConfigurationException.class);
263         digester.addSetNext(
264             "*/" + N_IMPORTEXPORT + "/" + N_IMPORT + "/" + N_IMPORTVERSIONS + "/" + N_IMPORTVERSION,
265             "addImportVersionClass");
266
267         // add rules for the import immutables
268
digester.addCallMethod(
269             "*/" + N_IMPORTEXPORT + "/" + N_IMPORT + "/" + N_IMMUTABLES + "/" + N_RESOURCE,
270             "addImmutableResource",
271             1);
272         digester.addCallParam("*/" + N_IMPORTEXPORT + "/" + N_IMPORT + "/" + N_IMMUTABLES + "/" + N_RESOURCE, 0, A_URI);
273
274         // add rules for the import princial translations
275
digester.addCallMethod("*/"
276             + N_IMPORTEXPORT
277             + "/"
278             + N_IMPORT
279             + "/"
280             + N_PRINCIPALTRANSLATIONS
281             + "/"
282             + N_PRINCIPALTRANSLATION, "addImportPrincipalTranslation", 3);
283         digester.addCallParam("*/"
284             + N_IMPORTEXPORT
285             + "/"
286             + N_IMPORT
287             + "/"
288             + N_PRINCIPALTRANSLATIONS
289             + "/"
290             + N_PRINCIPALTRANSLATION, 0, A_TYPE);
291         digester.addCallParam("*/"
292             + N_IMPORTEXPORT
293             + "/"
294             + N_IMPORT
295             + "/"
296             + N_PRINCIPALTRANSLATIONS
297             + "/"
298             + N_PRINCIPALTRANSLATION, 1, A_FROM);
299         digester.addCallParam("*/"
300             + N_IMPORTEXPORT
301             + "/"
302             + N_IMPORT
303             + "/"
304             + N_PRINCIPALTRANSLATIONS
305             + "/"
306             + N_PRINCIPALTRANSLATION, 2, A_TO);
307
308         // add rules for the ignored properties
309
digester.addCallMethod(
310             "*/" + N_IMPORTEXPORT + "/" + N_IMPORT + "/" + N_IGNOREDPROPERTIES + "/" + N_PROPERTY,
311             "addIgnoredProperty",
312             1);
313         digester.addCallParam(
314             "*/" + N_IMPORTEXPORT + "/" + N_IMPORT + "/" + N_IGNOREDPROPERTIES + "/" + N_PROPERTY,
315             0,
316             A_NAME);
317
318         // creation of the static export manager
319
digester.addObjectCreate("*/" + N_STATICEXPORT, CmsStaticExportManager.class);
320         // static export manager finished
321
digester.addSetNext("*/" + N_STATICEXPORT, "setStaticExportManager");
322         // export enabled role
323
digester.addCallMethod("*/" + N_STATICEXPORT, "setExportEnabled", 1);
324         digester.addCallParam("*/" + N_STATICEXPORT, 0, A_ENABLED);
325         // mode rule
326
digester.addCallMethod("*/" + N_STATICEXPORT + "/" + N_STATICEXPORT_HANDLER, "setHandler", 0);
327         // exportpath rule
328
digester.addCallMethod("*/" + N_STATICEXPORT + "/" + N_STATICEXPORT_EXPORTPATH, "setExportPath", 0);
329         // default property rule
330
digester.addCallMethod("*/" + N_STATICEXPORT + "/" + N_STATICEXPORT_DEFAULT, "setDefault", 0);
331         // export suffix rule
332
digester.addCallMethod("*/"
333             + N_STATICEXPORT
334             + "/"
335             + N_STATICEXPORT_DEFAULTSUFFIXES
336             + "/"
337             + N_STATICEXPORT_SUFFIX, "setExportSuffix", 1);
338         digester.addCallParam("*/"
339             + N_STATICEXPORT
340             + "/"
341             + N_STATICEXPORT_DEFAULTSUFFIXES
342             + "/"
343             + N_STATICEXPORT_SUFFIX, 0, A_KEY);
344         // header rule
345
digester.addCallMethod(
346             "*/" + N_STATICEXPORT + "/" + N_STATICEXPORT_EXPORTHEADERS + "/" + N_STATICEXPORT_HEADER,
347             "setExportHeader",
348             0);
349         // accept-language rule
350
digester.addCallMethod("*/"
351             + N_STATICEXPORT
352             + "/"
353             + N_STATICEXPORT_REQUESTHEADERS
354             + "/"
355             + N_STATICEXPORT_ACCEPTLANGUAGE, "setAcceptLanguageHeader", 0);
356         // accept-charset rule
357
digester.addCallMethod("*/"
358             + N_STATICEXPORT
359             + "/"
360             + N_STATICEXPORT_REQUESTHEADERS
361             + "/"
362             + N_STATICEXPORT_ACCEPTCHARSET, "setAcceptCharsetHeader", 0);
363         // accept-charset rule
364
digester.addCallMethod("*/"
365             + N_STATICEXPORT
366             + "/"
367             + N_STATICEXPORT_REQUESTHEADERS
368             + "/"
369             + N_STATICEXPORT_REMOTEADDR, "setRemoteAddr", 0);
370         // rfs-prefix rule
371
digester.addCallMethod("*/"
372             + N_STATICEXPORT
373             + "/"
374             + N_STATICEXPORT_RENDERSETTINGS
375             + "/"
376             + N_STATICEXPORT_RFS_PREFIX, "setRfsPrefix", 0);
377         // vfs-prefix rule
378
digester.addCallMethod("*/"
379             + N_STATICEXPORT
380             + "/"
381             + N_STATICEXPORT_RENDERSETTINGS
382             + "/"
383             + N_STATICEXPORT_VFS_PREFIX, "setVfsPrefix", 0);
384         // relative links rule
385
digester.addCallMethod("*/"
386             + N_STATICEXPORT
387             + "/"
388             + N_STATICEXPORT_RENDERSETTINGS
389             + "/"
390             + N_STATICEXPORT_RELATIVELINKS, "setRelativeLinks", 0);
391         // exporturl rule
392
digester.addCallMethod("*/"
393             + N_STATICEXPORT
394             + "/"
395             + N_STATICEXPORT_RENDERSETTINGS
396             + "/"
397             + N_STATICEXPORT_EXPORTURL, "setExportUrl", 0);
398         // plain export optimization rule
399
digester.addCallMethod("*/"
400             + N_STATICEXPORT
401             + "/"
402             + N_STATICEXPORT_RENDERSETTINGS
403             + "/"
404             + N_STATICEXPORT_PLAINOPTIMIZATION, "setPlainExportOptimization", 0);
405         // test resource rule
406
digester.addCallMethod("*/"
407             + N_STATICEXPORT
408             + "/"
409             + N_STATICEXPORT_RENDERSETTINGS
410             + "/"
411             + N_STATICEXPORT_TESTRESOURCE, "setTestResource", 1);
412         digester.addCallParam("*/"
413             + N_STATICEXPORT
414             + "/"
415             + N_STATICEXPORT_RENDERSETTINGS
416             + "/"
417             + N_STATICEXPORT_TESTRESOURCE, 0, A_URI);
418         // resources to export rule
419
digester.addCallMethod("*/"
420             + N_STATICEXPORT
421             + "/"
422             + N_STATICEXPORT_RENDERSETTINGS
423             + "/"
424             + N_STATICEXPORT_RESOURCESTORENDER
425             + "/"
426             + N_STATICEXPORT_REGEX, "setExportFolderPattern", 0);
427
428         // export-rules configuration
429
String JavaDoc exportRulePath = "*/"
430             + N_STATICEXPORT
431             + "/"
432             + N_STATICEXPORT_RENDERSETTINGS
433             + "/"
434             + N_STATICEXPORT_RESOURCESTORENDER
435             + "/"
436             + N_STATICEXPORT_EXPORTRULES
437             + "/"
438             + N_STATICEXPORT_EXPORTRULE;
439         digester.addCallMethod(exportRulePath, "addExportRule", 2);
440         digester.addCallParam(exportRulePath + "/" + N_STATICEXPORT_NAME, 0);
441         digester.addCallParam(exportRulePath + "/" + N_STATICEXPORT_DESCRIPTION, 1);
442         digester.addCallMethod(
443             exportRulePath + "/" + N_STATICEXPORT_MODIFIED + "/" + N_STATICEXPORT_REGEX,
444             "addExportRuleRegex",
445             1);
446         digester.addCallParam(exportRulePath + "/" + N_STATICEXPORT_MODIFIED + "/" + N_STATICEXPORT_REGEX, 0);
447         digester.addCallMethod(
448             exportRulePath + "/" + N_STATICEXPORT_EXPORT + "/" + N_STATICEXPORT_URI,
449             "addExportRuleUri",
450             1);
451         digester.addCallParam(exportRulePath + "/" + N_STATICEXPORT_EXPORT + "/" + N_STATICEXPORT_URI, 0);
452
453         // rfs-rules configuration
454
String JavaDoc rfsRulePath = "*/"
455             + N_STATICEXPORT
456             + "/"
457             + N_STATICEXPORT_RENDERSETTINGS
458             + "/"
459             + N_STATICEXPORT_RFS_RULES
460             + "/"
461             + N_STATICEXPORT_RFS_RULE;
462         digester.addCallMethod(rfsRulePath, "addRfsRule", 6);
463         digester.addCallParam(rfsRulePath + "/" + N_STATICEXPORT_NAME, 0);
464         digester.addCallParam(rfsRulePath + "/" + N_STATICEXPORT_DESCRIPTION, 1);
465         digester.addCallParam(rfsRulePath + "/" + N_STATICEXPORT_SOURCE, 2);
466         digester.addCallParam(rfsRulePath + "/" + N_STATICEXPORT_RFS_PREFIX, 3);
467         digester.addCallParam(rfsRulePath + "/" + N_STATICEXPORT_EXPORTPATH, 4);
468         digester.addCallParam(rfsRulePath + "/" + N_STATICEXPORT_RELATIVELINKS, 5);
469         // rfs-rule related system resources
470
digester.addCallMethod(
471             rfsRulePath + "/" + N_STATICEXPORT_RELATED_SYSTEM_RES + "/" + N_STATICEXPORT_REGEX,
472             "addRfsRuleSystemRes",
473             1);
474         digester.addCallParam(rfsRulePath + "/" + N_STATICEXPORT_RELATED_SYSTEM_RES + "/" + N_STATICEXPORT_REGEX, 0);
475     }
476
477     /**
478      * @see org.opencms.configuration.I_CmsXmlConfiguration#generateXml(org.dom4j.Element)
479      */

480     public Element generateXml(Element parent) {
481
482         // generate import/export node and subnodes
483
Element importexportElement = parent.addElement(N_IMPORTEXPORT);
484
485         Element resourceloadersElement = importexportElement.addElement(N_IMPORTEXPORTHANDLERS);
486         List JavaDoc handlers = m_importExportManager.getImportExportHandlers();
487         Iterator JavaDoc i = handlers.iterator();
488         while (i.hasNext()) {
489             I_CmsImportExportHandler handler = (I_CmsImportExportHandler)i.next();
490             // add the handler node
491
Element loaderNode = resourceloadersElement.addElement(N_IMPORTEXPORTHANDLER);
492             loaderNode.addAttribute(A_CLASS, handler.getClass().getName());
493         }
494
495         Element importElement = importexportElement.addElement(N_IMPORT);
496
497         // <overwrite> node
498
importElement.addElement(N_OVERWRITE).setText(
499             (new Boolean JavaDoc(m_importExportManager.overwriteCollidingResources())).toString());
500
501         // <convert> node
502
importElement.addElement(N_CONVERT).setText((new Boolean JavaDoc(m_importExportManager.convertToXmlPage())).toString());
503
504         // <oldwebappurl> node
505
if (m_importExportManager.getOldWebAppUrl() != null) {
506             importElement.addElement(N_OLDWEBAPPURL).setText(m_importExportManager.getOldWebAppUrl());
507         }
508
509         // <importversions> node
510
Element resourcetypesElement = importElement.addElement(N_IMPORTVERSIONS);
511         i = m_importExportManager.getImportVersionClasses().iterator();
512         while (i.hasNext()) {
513             resourcetypesElement.addElement(N_IMPORTVERSION).addAttribute(A_CLASS, i.next().getClass().getName());
514         }
515
516         // <immutables> node
517
Element immutablesElement = importElement.addElement(N_IMMUTABLES);
518         i = m_importExportManager.getImmutableResources().iterator();
519         while (i.hasNext()) {
520             String JavaDoc uri = (String JavaDoc)i.next();
521             immutablesElement.addElement(N_RESOURCE).addAttribute(A_URI, uri);
522         }
523
524         // <principaltranslations> node
525
Element principalsElement = importElement.addElement(N_PRINCIPALTRANSLATIONS);
526         i = m_importExportManager.getImportUserTranslations().keySet().iterator();
527         while (i.hasNext()) {
528             String JavaDoc from = (String JavaDoc)i.next();
529             String JavaDoc to = (String JavaDoc)m_importExportManager.getImportUserTranslations().get(from);
530             principalsElement.addElement(N_PRINCIPALTRANSLATION).addAttribute(A_TYPE, I_CmsPrincipal.PRINCIPAL_USER).addAttribute(
531                 A_FROM,
532                 from).addAttribute(A_TO, to);
533         }
534         i = m_importExportManager.getImportGroupTranslations().keySet().iterator();
535         while (i.hasNext()) {
536             String JavaDoc from = (String JavaDoc)i.next();
537             String JavaDoc to = (String JavaDoc)m_importExportManager.getImportGroupTranslations().get(from);
538             principalsElement.addElement(N_PRINCIPALTRANSLATION).addAttribute(A_TYPE, I_CmsPrincipal.PRINCIPAL_GROUP).addAttribute(
539                 A_FROM,
540                 from).addAttribute(A_TO, to);
541         }
542
543         // <ignoredproperties> node
544
Element propertiesElement = importElement.addElement(N_IGNOREDPROPERTIES);
545         i = m_importExportManager.getIgnoredProperties().iterator();
546         while (i.hasNext()) {
547             String JavaDoc property = (String JavaDoc)i.next();
548             propertiesElement.addElement(N_PROPERTY).addAttribute(A_NAME, property);
549         }
550
551         // <staticexport> node
552
Element staticexportElement = parent.addElement(N_STATICEXPORT);
553         staticexportElement.addAttribute(A_ENABLED, m_staticExportManager.getExportEnabled());
554
555         // <staticexporthandler> node
556
staticexportElement.addElement(N_STATICEXPORT_HANDLER).addText(
557             m_staticExportManager.getHandler().getClass().getName());
558
559         // <exportpath> node
560
String JavaDoc exportPathUnmodified = m_staticExportManager.getExportPathForConfiguration();
561         // cut path seperator
562
if (exportPathUnmodified.endsWith(File.separator)) {
563             exportPathUnmodified = exportPathUnmodified.substring(0, exportPathUnmodified.length() - 1);
564         }
565         staticexportElement.addElement(N_STATICEXPORT_EXPORTPATH).addText(exportPathUnmodified);
566
567         // <defaultpropertyvalue> node
568
staticexportElement.addElement(N_STATICEXPORT_DEFAULT).addText(m_staticExportManager.getDefault());
569
570         // <defaultsuffixes> node and its <suffix> sub nodes
571
Element defaultsuffixesElement = staticexportElement.addElement(N_STATICEXPORT_DEFAULTSUFFIXES);
572
573         i = m_staticExportManager.getExportSuffixes().iterator();
574         while (i.hasNext()) {
575             String JavaDoc suffix = (String JavaDoc)i.next();
576             Element suffixElement = defaultsuffixesElement.addElement(N_STATICEXPORT_SUFFIX);
577             suffixElement.addAttribute(A_KEY, suffix);
578         }
579
580         // <exportheaders> node and its <header> sub nodes
581
i = m_staticExportManager.getExportHeaders().iterator();
582         if (i.hasNext()) {
583             Element exportheadersElement = staticexportElement.addElement(N_STATICEXPORT_EXPORTHEADERS);
584             while (i.hasNext()) {
585                 String JavaDoc header = (String JavaDoc)i.next();
586                 exportheadersElement.addElement(N_STATICEXPORT_HEADER).addText(header);
587             }
588         }
589         // <requestheaders> node and the <acceptlanguage> and <acceptcharset> node
590
String JavaDoc acceptlanguage = m_staticExportManager.getAcceptLanguageHeader();
591         String JavaDoc acceptcharset = m_staticExportManager.getAcceptCharsetHeader();
592         String JavaDoc remoteaddr = m_staticExportManager.getRemoteAddr();
593         if ((acceptlanguage != null) || (acceptcharset != null) || (remoteaddr != null)) {
594             Element requestheadersElement = staticexportElement.addElement(N_STATICEXPORT_REQUESTHEADERS);
595             if (acceptlanguage != null) {
596                 requestheadersElement.addElement(N_STATICEXPORT_ACCEPTLANGUAGE).addText(acceptlanguage);
597             }
598             if (acceptcharset != null) {
599                 requestheadersElement.addElement(N_STATICEXPORT_ACCEPTCHARSET).addText(acceptcharset);
600             }
601             if (remoteaddr != null) {
602                 requestheadersElement.addElement(N_STATICEXPORT_REMOTEADDR).addText(remoteaddr);
603             }
604         }
605
606         // <rendersettings> node
607
Element rendersettingsElement = staticexportElement.addElement(N_STATICEXPORT_RENDERSETTINGS);
608
609         // <rfsPrefix> node
610
rendersettingsElement.addElement(N_STATICEXPORT_RFS_PREFIX).addText(
611             m_staticExportManager.getRfsPrefixForConfiguration());
612
613         // <vfsPrefix> node
614
rendersettingsElement.addElement(N_STATICEXPORT_VFS_PREFIX).addText(
615             m_staticExportManager.getVfsPrefixForConfiguration());
616
617         // <userelativelinks> node
618
rendersettingsElement.addElement(N_STATICEXPORT_RELATIVELINKS).addText(m_staticExportManager.getRelativeLinks());
619
620         // <exporturl> node
621
rendersettingsElement.addElement(N_STATICEXPORT_EXPORTURL).addText(
622             m_staticExportManager.getExportUrlForConfiguration());
623
624         // <plainoptimization> node
625
rendersettingsElement.addElement(N_STATICEXPORT_PLAINOPTIMIZATION).addText(
626             m_staticExportManager.getPlainExportOptimization());
627
628         // <testresource> node
629
Element testresourceElement = rendersettingsElement.addElement(N_STATICEXPORT_TESTRESOURCE);
630         testresourceElement.addAttribute(A_URI, m_staticExportManager.getTestResource());
631
632         // <resourcestorender> node and <regx> subnodes
633
Element resourcetorenderElement = rendersettingsElement.addElement(N_STATICEXPORT_RESOURCESTORENDER);
634
635         i = m_staticExportManager.getExportFolderPatterns().iterator();
636         while (i.hasNext()) {
637             String JavaDoc pattern = (String JavaDoc)i.next();
638             resourcetorenderElement.addElement(N_STATICEXPORT_REGEX).addText(pattern);
639         }
640
641         if (!m_staticExportManager.getExportRules().isEmpty()) {
642             // <export-rules> node
643
Element exportRulesElement = resourcetorenderElement.addElement(N_STATICEXPORT_EXPORTRULES);
644
645             i = m_staticExportManager.getExportRules().iterator();
646             while (i.hasNext()) {
647                 CmsStaticExportExportRule rule = (CmsStaticExportExportRule)i.next();
648                 // <export-rule> node
649
Element exportRuleElement = exportRulesElement.addElement(N_STATICEXPORT_EXPORTRULE);
650                 exportRuleElement.addElement(N_STATICEXPORT_NAME).addText(rule.getName());
651                 exportRuleElement.addElement(N_STATICEXPORT_DESCRIPTION).addText(rule.getDescription());
652                 // <modified-resources> node and <regex> subnodes
653
Element modifiedElement = exportRuleElement.addElement(N_STATICEXPORT_MODIFIED);
654                 Iterator JavaDoc itMods = rule.getModifiedResources().iterator();
655                 while (itMods.hasNext()) {
656                     Pattern JavaDoc regex = (Pattern JavaDoc)itMods.next();
657                     modifiedElement.addElement(N_STATICEXPORT_REGEX).addText(regex.pattern());
658                 }
659                 // <export-resources> node and <uri> subnodes
660
Element exportElement = exportRuleElement.addElement(N_STATICEXPORT_EXPORT);
661                 Iterator JavaDoc itExps = rule.getExportResourcePatterns().iterator();
662                 while (itExps.hasNext()) {
663                     String JavaDoc uri = (String JavaDoc)itExps.next();
664                     exportElement.addElement(N_STATICEXPORT_URI).addText(uri);
665                 }
666             }
667         }
668
669         if (!m_staticExportManager.getRfsRules().isEmpty()) {
670             // <rfs-rules> node
671
Element rfsRulesElement = rendersettingsElement.addElement(N_STATICEXPORT_RFS_RULES);
672
673             i = m_staticExportManager.getRfsRules().iterator();
674             while (i.hasNext()) {
675                 CmsStaticExportRfsRule rule = (CmsStaticExportRfsRule)i.next();
676                 // <rfs-rule> node and subnodes
677
Element rfsRuleElement = rfsRulesElement.addElement(N_STATICEXPORT_RFS_RULE);
678                 rfsRuleElement.addElement(N_STATICEXPORT_NAME).addText(rule.getName());
679                 rfsRuleElement.addElement(N_STATICEXPORT_DESCRIPTION).addText(rule.getDescription());
680                 rfsRuleElement.addElement(N_STATICEXPORT_SOURCE).addText(rule.getSource().pattern());
681                 rfsRuleElement.addElement(N_STATICEXPORT_RFS_PREFIX).addText(rule.getRfsPrefixConfigured());
682                 rfsRuleElement.addElement(N_STATICEXPORT_EXPORTPATH).addText(rule.getExportPathConfigured());
683                 if (rule.getUseRelativeLinks() != null) {
684                     rfsRuleElement.addElement(N_STATICEXPORT_RELATIVELINKS).addText(
685                         rule.getUseRelativeLinks().toString());
686                 }
687                 Element relatedSystemRes = rfsRuleElement.addElement(N_STATICEXPORT_RELATED_SYSTEM_RES);
688                 Iterator JavaDoc itSystemRes = rule.getRelatedSystemResources().iterator();
689                 while (itSystemRes.hasNext()) {
690                     Pattern JavaDoc sysRes = (Pattern JavaDoc)itSystemRes.next();
691                     relatedSystemRes.addElement(N_STATICEXPORT_REGEX).addText(sysRes.pattern());
692                 }
693             }
694
695         }
696         // return the configured node
697
return importexportElement;
698     }
699
700     /**
701      * @see org.opencms.configuration.I_CmsXmlConfiguration#getDtdFilename()
702      */

703     public String JavaDoc getDtdFilename() {
704
705         return CONFIGURATION_DTD_NAME;
706     }
707
708     /**
709      * Returns the initialized import/export manager.<p>
710      *
711      * @return the initialized import/export manager
712      */

713     public CmsImportExportManager getImportExportManager() {
714
715         return m_importExportManager;
716     }
717
718     /**
719      * Returns the initialized static export manager.<p>
720      *
721      * @return the initialized static export manager
722      */

723     public CmsStaticExportManager getStaticExportManager() {
724
725         return m_staticExportManager;
726     }
727
728     /**
729      * Will be called when configuration of this object is finished.<p>
730      */

731     public void initializeFinished() {
732
733         if (CmsLog.INIT.isInfoEnabled()) {
734             CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_IMPORT_CONFIG_FINISHED_0));
735         }
736     }
737
738     /**
739      * Sets the generated import/export manager.<p>
740      *
741      * @param manager the import/export manager to set
742      */

743     public void setImportExportManager(CmsImportExportManager manager) {
744
745         m_importExportManager = manager;
746         if (CmsLog.INIT.isInfoEnabled()) {
747             CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_IMPORT_MANAGER_0));
748         }
749     }
750
751     /**
752      * Sets the generated static export manager.<p>
753      *
754      * @param manager the static export manager to set
755      */

756     public void setStaticExportManager(CmsStaticExportManager manager) {
757
758         m_staticExportManager = manager;
759         if (CmsLog.INIT.isInfoEnabled()) {
760             CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_STATEXP_MANAGER_0));
761         }
762     }
763 }
Popular Tags