001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software GmbH & Co. KG, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.configuration;
029
030import org.opencms.db.CmsUserExportSettings;
031import org.opencms.importexport.CmsExtendedHtmlImportDefault;
032import org.opencms.importexport.CmsImportExportManager;
033import org.opencms.importexport.CmsImportExportManager.TimestampMode;
034import org.opencms.importexport.I_CmsImport;
035import org.opencms.importexport.I_CmsImportExportHandler;
036import org.opencms.main.CmsLog;
037import org.opencms.repository.CmsRepositoryFilter;
038import org.opencms.repository.CmsRepositoryManager;
039import org.opencms.repository.I_CmsRepository;
040import org.opencms.security.I_CmsPrincipal;
041import org.opencms.staticexport.CmsStaticExportExportRule;
042import org.opencms.staticexport.CmsStaticExportManager;
043import org.opencms.staticexport.CmsStaticExportRfsRule;
044import org.opencms.util.CmsResourceTranslator;
045import org.opencms.util.CmsStringUtil;
046
047import java.io.File;
048import java.util.Iterator;
049import java.util.List;
050import java.util.Map;
051import java.util.Map.Entry;
052import java.util.regex.Pattern;
053
054import javax.xml.parsers.ParserConfigurationException;
055
056import org.apache.commons.digester3.Digester;
057import org.apache.commons.digester3.NodeCreateRule;
058import org.apache.commons.logging.Log;
059
060import org.dom4j.Element;
061import org.w3c.dom.NodeList;
062
063/**
064 * Import / export master configuration class.<p>
065 *
066 * @since 6.0.0
067 */
068public class CmsImportExportConfiguration extends A_CmsXmlConfiguration {
069
070    /** The name of the DTD for this configuration. */
071    public static final String CONFIGURATION_DTD_NAME = "opencms-importexport.dtd";
072
073    /** The name of the default XML file for this configuration. */
074    public static final String DEFAULT_XML_FILE_NAME = "opencms-importexport.xml";
075
076    /**  The node name of the column node. */
077    public static final String N_COLUMN = "column";
078
079    /**  The node name of the columns node. */
080    public static final String N_COLUMNS = "columns";
081
082    /** Node that indicates page conversion. */
083    public static final String N_CONVERT = "convert";
084
085    /** The node name of the export sub-configuration. */
086    public static final String N_EXPORT = "export";
087
088    /** The node name of the defaultexporttimestamps sub-configuration. */
089    public static final String N_EXPORT_DEFAULTTIMESTAMPMODES = "defaulttimestampmodes";
090
091    /** The node name of the resourcetype sub-configuration. */
092    public static final String N_EXPORT_RESOURCETYPENAME = "resourcetypename";
093
094    /** The node name of the timestamp sub-configuration. */
095    public static final String N_EXPORT_TIMESTAMPMODE = "timestampmode";
096
097    /**  The main configuration node for the extended html import. */
098    public static final String N_EXTHTMLIMPORT = "extendedhtmlimport";
099
100    /**  The node name of the html import destination node. */
101    public static final String N_EXTHTMLIMPORT_DESTINATION = "destination";
102
103    /**  The node name of the html import download gallery node. */
104    public static final String N_EXTHTMLIMPORT_DOWNLOAD = "download";
105
106    /**  The node name of the html import template node. */
107    public static final String N_EXTHTMLIMPORT_ELEMENT = "element";
108
109    /**  The node name of the html import encoding node. */
110    public static final String N_EXTHTMLIMPORT_ENCODING = "encoding";
111
112    /**  The node name of the html import image gallery node. */
113    public static final String N_EXTHTMLIMPORT_EXTERNALLINK = "externallink";
114
115    /**  The node name of the html import galleries node. */
116    public static final String N_EXTHTMLIMPORT_GALLERIES = "galleries";
117
118    /**  The node name of the html import image gallery node. */
119    public static final String N_EXTHTMLIMPORT_IMAGE = "image";
120
121    /**  The node name of the html import input node. */
122    public static final String N_EXTHTMLIMPORT_INPUT = "input";
123
124    /**  The node name of the html import overwritefiles node. */
125    public static final String N_EXTHTMLIMPORT_KEEPBROKENLINKS = "keepbrokenlinks";
126
127    /**  The node name of the html import locale node. */
128    public static final String N_EXTHTMLIMPORT_LOCALE = "locale";
129
130    /**  The node name of the html import overwritefiles node. */
131    public static final String N_EXTHTMLIMPORT_OVERWRITE = "overwritefiles";
132
133    /**  The node name of the html import pattern node. */
134    public static final String N_EXTHTMLIMPORT_PATTERN = "pattern";
135
136    /**  The node name of the html import end pattern node. */
137    public static final String N_EXTHTMLIMPORT_PATTERN_END = "end";
138
139    /**  The node name of the html import start pattern node. */
140    public static final String N_EXTHTMLIMPORT_PATTERN_START = "start";
141
142    /**  The node name of the html import settings node. */
143    public static final String N_EXTHTMLIMPORT_SETTINGS = "settings";
144
145    /**  The node name of the html import template node. */
146    public static final String N_EXTHTMLIMPORT_TEMPLATE = "template";
147
148    /** filetranslations node name. */
149    public static final String N_FILETRANSLATIONS = "filetranslations";
150
151    /** The node name of the repository filter node. */
152    public static final String N_FILTER = "filter";
153
154    /** Node that contains a list of properties ignored during import. */
155    public static final String N_IGNOREDPROPERTIES = "ignoredproperties";
156
157    /** The import immutable resources node. */
158    public static final String N_IMMUTABLES = "immutables";
159
160    /** The node name of the import sub-configuration. */
161    public static final String N_IMPORT = "import";
162
163    /** The main configuration node name. */
164    public static final String N_IMPORTEXPORT = "importexport";
165
166    /** The node name of an individual import/export handler. */
167    public static final String N_IMPORTEXPORTHANDLER = "importexporthandler";
168
169    /** Master node for import/export handlers. */
170    public static final String N_IMPORTEXPORTHANDLERS = "importexporthandlers";
171
172    /** The node name of an individual import version class. */
173    public static final String N_IMPORTVERSION = "importversion";
174
175    /** Master node for import version class names. */
176    public static final String N_IMPORTVERSIONS = "importversions";
177
178    /**  The node name of the static export handler node. */
179    public static final String N_LINKSUBSTITUTION_HANDLER = "linksubstitutionhandler";
180
181    /** Node the contains an optional URL of old web application. */
182    public static final String N_OLDWEBAPPURL = "oldwebappurl";
183
184    /** The import overwrite node name. */
185    public static final String N_OVERWRITE = "overwrite";
186
187    /** The node name of the repository params node. */
188    public static final String N_PARAMS = "params";
189
190    /** An individual principal translation node. */
191    public static final String N_PRINCIPALTRANSLATION = "principaltranslation";
192
193    /** The principal translation node. */
194    public static final String N_PRINCIPALTRANSLATIONS = "principaltranslations";
195
196    /**  The node name of the column node. */
197    public static final String N_PROTECTED_EXPORT = "protectedexport";
198
199    /** The node name of the repository filter regex node. */
200    public static final String N_REGEX = "regex";
201
202    /** The node name of the repositories node. */
203    public static final String N_REPOSITORIES = "repositories";
204
205    /** The node name of the repository node. */
206    public static final String N_REPOSITORY = "repository";
207
208    /**  The node name of the separator node. */
209    public static final String N_SEPARATOR = "separator";
210
211    /**  The main configuration node for static export name. */
212    public static final String N_STATICEXPORT = "staticexport";
213
214    /**  The node name of the static export acceptcharset node. */
215    public static final String N_STATICEXPORT_ACCEPTCHARSET = "acceptcharset";
216
217    /**  The node name of the static export acceptlanguage node. */
218    public static final String N_STATICEXPORT_ACCEPTLANGUAGE = "acceptlanguage";
219
220    /**  The node name of the static export default node. */
221    public static final String N_STATICEXPORT_DEFAULT = "defaultpropertyvalue";
222
223    /**  The node name of the static export defualtsuffix node. */
224    public static final String N_STATICEXPORT_DEFAULTSUFFIXES = "defaultsuffixes";
225
226    /**  The node name of the static export rule description nodes. */
227    public static final String N_STATICEXPORT_DESCRIPTION = "description";
228
229    /**  The node name of the static export export-rule export node. */
230    public static final String N_STATICEXPORT_EXPORT = "export-resources";
231
232    /**  The node name of the static export exportbackups node. */
233    public static final String N_STATICEXPORT_EXPORTBACKUPS = "exportbackups";
234
235    /**  The node name of the static export exportheaders node. */
236    public static final String N_STATICEXPORT_EXPORTHEADERS = "exportheaders";
237
238    /**  The node name of the static export exportpath node. */
239    public static final String N_STATICEXPORT_EXPORTPATH = "exportpath";
240
241    /**  The node name of the static export export-rule node. */
242    public static final String N_STATICEXPORT_EXPORTRULE = "export-rule";
243
244    /**  The node name of the static export export-rules node. */
245    public static final String N_STATICEXPORT_EXPORTRULES = "export-rules";
246
247    /**  The node name of the static export exporturl node. */
248    public static final String N_STATICEXPORT_EXPORTURL = "exporturl";
249
250    /**  The node name of the static export exportworkpath node. */
251    public static final String N_STATICEXPORT_EXPORTWORKPATH = "exportworkpath";
252
253    /**  The node name of the static export handler node. */
254    public static final String N_STATICEXPORT_HANDLER = "staticexporthandler";
255
256    /**  The node name of the static export header node. */
257    public static final String N_STATICEXPORT_HEADER = "header";
258
259    /**  The node name of the static export export-rule modified node. */
260    public static final String N_STATICEXPORT_MODIFIED = "modified-resources";
261
262    /**  The node name of the static export rule name nodes. */
263    public static final String N_STATICEXPORT_NAME = "name";
264
265    /**  The node name of the static export plainoptimization node. */
266    public static final String N_STATICEXPORT_PLAINOPTIMIZATION = "plainoptimization";
267
268    /**  The node name of the static export regex node. */
269    public static final String N_STATICEXPORT_REGEX = "regex";
270
271    /**  The node name of the static export related-system-res node. */
272    public static final String N_STATICEXPORT_RELATED_SYSTEM_RES = "related-system-res";
273
274    /**  The node name of the static export relativelinks node. */
275    public static final String N_STATICEXPORT_RELATIVELINKS = "userelativelinks";
276
277    /**  The node name of the static export remoteaddr node. */
278    public static final String N_STATICEXPORT_REMOTEADDR = "remoteaddr";
279
280    /**  The node name of the static export rendersettings node. */
281    public static final String N_STATICEXPORT_RENDERSETTINGS = "rendersettings";
282
283    /**  The node name of the static export requestheaders node. */
284    public static final String N_STATICEXPORT_REQUESTHEADERS = "requestheaders";
285
286    /**  The node name of the static export resourcestorender node. */
287    public static final String N_STATICEXPORT_RESOURCESTORENDER = "resourcestorender";
288
289    /**  The node name of the static export rfx-prefix node. */
290    public static final String N_STATICEXPORT_RFS_PREFIX = "rfs-prefix";
291
292    /**  The node name of the static export rfx-rule node. */
293    public static final String N_STATICEXPORT_RFS_RULE = "rfs-rule";
294
295    /**  The node name of the static export rfx-rules node. */
296    public static final String N_STATICEXPORT_RFS_RULES = "rfs-rules";
297
298    /**  The node name of the static export rfx-rule source node. */
299    public static final String N_STATICEXPORT_SOURCE = "source";
300
301    /**  The node name of the static export suffix node. */
302    public static final String N_STATICEXPORT_SUFFIX = "suffix";
303
304    /**  The node name of the static export testresource node. */
305    public static final String N_STATICEXPORT_TESTRESOURCE = "testresource";
306
307    /**  The node name of the static export export-rule export uri node. */
308    public static final String N_STATICEXPORT_URI = "uri";
309
310    /**  The node name of the static export vfx-prefix node. */
311    public static final String N_STATICEXPORT_VFS_PREFIX = "vfs-prefix";
312
313    /** The temporary export point path node. */
314    public static final String N_TEMP_EXPORTPONT_PATH = "temp-exportpoint-path";
315
316    /** translation node name. */
317    public static final String N_TRANSLATION = "translation";
318
319    /**  The node name of the user csv export node. */
320    public static final String N_USERCSVEXPORT = "usercsvexport";
321
322    /** Log instance for this class. */
323    private static final Log LOG = CmsLog.getLog(CmsImportExportConfiguration.class);
324
325    /** The configured import/export manager. */
326    private CmsImportExportManager m_importExportManager;
327
328    /** The configured repository manager. */
329    private CmsRepositoryManager m_repositoryManager;
330
331    /** The configured static export manager. */
332    private CmsStaticExportManager m_staticExportManager;
333
334    /**
335     * Adds an protected export point.<p>
336     *
337     * @param uri the source URI
338     * @param destination the export destination
339     */
340    public void addProtectedExportPoint(String uri, String destination) {
341
342        m_staticExportManager.addProtectedExportPoint(uri, destination);
343    }
344
345    /**
346     * @see org.opencms.configuration.I_CmsXmlConfiguration#addXmlDigesterRules(org.apache.commons.digester3.Digester)
347     */
348    public void addXmlDigesterRules(Digester digester) {
349
350        // add finish rule
351        digester.addCallMethod("*/" + N_IMPORTEXPORT, "initializeFinished");
352
353        // creation of the import/export manager
354        digester.addObjectCreate("*/" + N_IMPORTEXPORT, CmsImportExportManager.class);
355        // import/export manager finished
356        digester.addSetNext("*/" + N_IMPORTEXPORT, "setImportExportManager");
357
358        // add rules for import/export handlers
359        digester.addObjectCreate(
360            "*/" + N_IMPORTEXPORT + "/" + N_IMPORTEXPORTHANDLERS + "/" + N_IMPORTEXPORTHANDLER,
361            CmsConfigurationException.class.getName(),
362            A_CLASS);
363        digester.addSetNext(
364            "*/" + N_IMPORTEXPORT + "/" + N_IMPORTEXPORTHANDLERS + "/" + N_IMPORTEXPORTHANDLER,
365            "addImportExportHandler");
366
367        // overwrite rule
368        digester.addCallMethod(
369            "*/" + N_IMPORTEXPORT + "/" + N_IMPORT + "/" + N_OVERWRITE,
370            "setOverwriteCollidingResources",
371            0);
372
373        // convert rule
374        digester.addCallMethod("*/" + N_IMPORTEXPORT + "/" + N_IMPORT + "/" + N_CONVERT, "setConvertToXmlPage", 0);
375
376        // old webapp rule
377        digester.addCallMethod("*/" + N_IMPORTEXPORT + "/" + N_IMPORT + "/" + N_OLDWEBAPPURL, "setOldWebAppUrl", 0);
378
379        // add rules for the import versions
380        digester.addObjectCreate(
381            "*/" + N_IMPORTEXPORT + "/" + N_IMPORT + "/" + N_IMPORTVERSIONS + "/" + N_IMPORTVERSION,
382            CmsConfigurationException.class.getName(),
383            A_CLASS);
384        digester.addSetNext(
385            "*/" + N_IMPORTEXPORT + "/" + N_IMPORT + "/" + N_IMPORTVERSIONS + "/" + N_IMPORTVERSION,
386            "addImportVersionClass");
387
388        // add rules for the import immutables
389        digester.addCallMethod(
390            "*/" + N_IMPORTEXPORT + "/" + N_IMPORT + "/" + N_IMMUTABLES + "/" + N_RESOURCE,
391            "addImmutableResource",
392            1);
393        digester.addCallParam("*/" + N_IMPORTEXPORT + "/" + N_IMPORT + "/" + N_IMMUTABLES + "/" + N_RESOURCE, 0, A_URI);
394
395        // add rules for the import principal translations
396        digester.addCallMethod(
397            "*/" + N_IMPORTEXPORT + "/" + N_IMPORT + "/" + N_PRINCIPALTRANSLATIONS + "/" + N_PRINCIPALTRANSLATION,
398            "addImportPrincipalTranslation",
399            3);
400        digester.addCallParam(
401            "*/" + N_IMPORTEXPORT + "/" + N_IMPORT + "/" + N_PRINCIPALTRANSLATIONS + "/" + N_PRINCIPALTRANSLATION,
402            0,
403            A_TYPE);
404        digester.addCallParam(
405            "*/" + N_IMPORTEXPORT + "/" + N_IMPORT + "/" + N_PRINCIPALTRANSLATIONS + "/" + N_PRINCIPALTRANSLATION,
406            1,
407            A_FROM);
408        digester.addCallParam(
409            "*/" + N_IMPORTEXPORT + "/" + N_IMPORT + "/" + N_PRINCIPALTRANSLATIONS + "/" + N_PRINCIPALTRANSLATION,
410            2,
411            A_TO);
412
413        // add rules for the ignored properties
414        digester.addCallMethod(
415            "*/" + N_IMPORTEXPORT + "/" + N_IMPORT + "/" + N_IGNOREDPROPERTIES + "/" + N_PROPERTY,
416            "addIgnoredProperty",
417            1);
418        digester.addCallParam(
419            "*/" + N_IMPORTEXPORT + "/" + N_IMPORT + "/" + N_IGNOREDPROPERTIES + "/" + N_PROPERTY,
420            0,
421            A_NAME);
422
423        // add rules for export settings
424        digester.addCallMethod(
425            "*/"
426                + N_IMPORTEXPORT
427                + "/"
428                + N_EXPORT
429                + "/"
430                + N_EXPORT_DEFAULTTIMESTAMPMODES
431                + "/"
432                + N_EXPORT_TIMESTAMPMODE,
433            "addDefaultTimestampMode",
434            1);
435
436        digester.addCallParam(
437            "*/"
438                + N_IMPORTEXPORT
439                + "/"
440                + N_EXPORT
441                + "/"
442                + N_EXPORT_DEFAULTTIMESTAMPMODES
443                + "/"
444                + N_EXPORT_TIMESTAMPMODE,
445            0,
446            A_MODE);
447
448        digester.addCallMethod(
449            "*/"
450                + N_IMPORTEXPORT
451                + "/"
452                + N_EXPORT
453                + "/"
454                + N_EXPORT_DEFAULTTIMESTAMPMODES
455                + "/"
456                + N_EXPORT_TIMESTAMPMODE
457                + "/"
458                + N_EXPORT_RESOURCETYPENAME,
459            "addResourceTypeForDefaultTimestampMode",
460            1);
461
462        digester.addCallParam(
463            "*/"
464                + N_IMPORTEXPORT
465                + "/"
466                + N_EXPORT
467                + "/"
468                + N_EXPORT_DEFAULTTIMESTAMPMODES
469                + "/"
470                + N_EXPORT_TIMESTAMPMODE
471                + "/"
472                + N_EXPORT_RESOURCETYPENAME,
473            0);
474
475        digester.addCallMethod("*/" + N_IMPORTEXPORT + "/" + N_TEMP_EXPORTPONT_PATH, "addTempExportpointPath", 1);
476        digester.addCallParam("*/" + N_IMPORTEXPORT + "/" + N_TEMP_EXPORTPONT_PATH, 0);
477
478        // creation of the static export manager
479        digester.addObjectCreate("*/" + N_STATICEXPORT, CmsStaticExportManager.class);
480        // static export manager finished
481        digester.addSetNext("*/" + N_STATICEXPORT, "setStaticExportManager");
482        // export enabled role
483        digester.addCallMethod("*/" + N_STATICEXPORT, "setExportEnabled", 1);
484        digester.addCallParam("*/" + N_STATICEXPORT, 0, A_ENABLED);
485        // export handler rule
486        digester.addCallMethod("*/" + N_STATICEXPORT + "/" + N_STATICEXPORT_HANDLER, "setHandler", 0);
487        // link substitution handler rule
488        digester.addCallMethod(
489            "*/" + N_STATICEXPORT + "/" + N_LINKSUBSTITUTION_HANDLER,
490            "setLinkSubstitutionHandler",
491            0);
492        // exportpath rule
493        digester.addCallMethod("*/" + N_STATICEXPORT + "/" + N_STATICEXPORT_EXPORTPATH, "setExportPath", 0);
494        // exportworkpath rule
495        digester.addCallMethod("*/" + N_STATICEXPORT + "/" + N_STATICEXPORT_EXPORTWORKPATH, "setExportWorkPath", 0);
496        // exportbackups rule
497        digester.addCallMethod("*/" + N_STATICEXPORT + "/" + N_STATICEXPORT_EXPORTBACKUPS, "setExportBackups", 0);
498        // default property rule
499        digester.addCallMethod("*/" + N_STATICEXPORT + "/" + N_STATICEXPORT_DEFAULT, "setDefault", 0);
500        // export suffix rule
501        digester.addCallMethod(
502            "*/" + N_STATICEXPORT + "/" + N_STATICEXPORT_DEFAULTSUFFIXES + "/" + N_STATICEXPORT_SUFFIX,
503            "setExportSuffix",
504            1);
505        digester.addCallParam(
506            "*/" + N_STATICEXPORT + "/" + N_STATICEXPORT_DEFAULTSUFFIXES + "/" + N_STATICEXPORT_SUFFIX,
507            0,
508            A_KEY);
509        // header rule
510        digester.addCallMethod(
511            "*/" + N_STATICEXPORT + "/" + N_STATICEXPORT_EXPORTHEADERS + "/" + N_STATICEXPORT_HEADER,
512            "setExportHeader",
513            0);
514        // accept-language rule
515        digester.addCallMethod(
516            "*/" + N_STATICEXPORT + "/" + N_STATICEXPORT_REQUESTHEADERS + "/" + N_STATICEXPORT_ACCEPTLANGUAGE,
517            "setAcceptLanguageHeader",
518            0);
519        // accept-charset rule
520        digester.addCallMethod(
521            "*/" + N_STATICEXPORT + "/" + N_STATICEXPORT_REQUESTHEADERS + "/" + N_STATICEXPORT_ACCEPTCHARSET,
522            "setAcceptCharsetHeader",
523            0);
524        // accept-charset rule
525        digester.addCallMethod(
526            "*/" + N_STATICEXPORT + "/" + N_STATICEXPORT_REQUESTHEADERS + "/" + N_STATICEXPORT_REMOTEADDR,
527            "setRemoteAddr",
528            0);
529        // rfs-prefix rule
530        digester.addCallMethod(
531            "*/" + N_STATICEXPORT + "/" + N_STATICEXPORT_RENDERSETTINGS + "/" + N_STATICEXPORT_RFS_PREFIX,
532            "setRfsPrefix",
533            0);
534        // vfs-prefix rule
535        digester.addCallMethod(
536            "*/" + N_STATICEXPORT + "/" + N_STATICEXPORT_RENDERSETTINGS + "/" + N_STATICEXPORT_VFS_PREFIX,
537            "setVfsPrefix",
538            0);
539        // relative links rule
540        digester.addCallMethod(
541            "*/" + N_STATICEXPORT + "/" + N_STATICEXPORT_RENDERSETTINGS + "/" + N_STATICEXPORT_RELATIVELINKS,
542            "setRelativeLinks",
543            0);
544        // exporturl rule
545        digester.addCallMethod(
546            "*/" + N_STATICEXPORT + "/" + N_STATICEXPORT_RENDERSETTINGS + "/" + N_STATICEXPORT_EXPORTURL,
547            "setExportUrl",
548            0);
549        // plain export optimization rule
550        digester.addCallMethod(
551            "*/" + N_STATICEXPORT + "/" + N_STATICEXPORT_RENDERSETTINGS + "/" + N_STATICEXPORT_PLAINOPTIMIZATION,
552            "setPlainExportOptimization",
553            0);
554        // test resource rule
555        digester.addCallMethod(
556            "*/" + N_STATICEXPORT + "/" + N_STATICEXPORT_RENDERSETTINGS + "/" + N_STATICEXPORT_TESTRESOURCE,
557            "setTestResource",
558            1);
559        digester.addCallParam(
560            "*/" + N_STATICEXPORT + "/" + N_STATICEXPORT_RENDERSETTINGS + "/" + N_STATICEXPORT_TESTRESOURCE,
561            0,
562            A_URI);
563        // resources to export rule
564        digester.addCallMethod(
565            "*/"
566                + N_STATICEXPORT
567                + "/"
568                + N_STATICEXPORT_RENDERSETTINGS
569                + "/"
570                + N_STATICEXPORT_RESOURCESTORENDER
571                + "/"
572                + N_STATICEXPORT_REGEX,
573            "setExportFolderPattern",
574            0);
575
576        // export-rules configuration
577        String exportRulePath = "*/"
578            + N_STATICEXPORT
579            + "/"
580            + N_STATICEXPORT_RENDERSETTINGS
581            + "/"
582            + N_STATICEXPORT_RESOURCESTORENDER
583            + "/"
584            + N_STATICEXPORT_EXPORTRULES
585            + "/"
586            + N_STATICEXPORT_EXPORTRULE;
587        digester.addCallMethod(exportRulePath, "addExportRule", 2);
588        digester.addCallParam(exportRulePath + "/" + N_STATICEXPORT_NAME, 0);
589        digester.addCallParam(exportRulePath + "/" + N_STATICEXPORT_DESCRIPTION, 1);
590        digester.addCallMethod(
591            exportRulePath + "/" + N_STATICEXPORT_MODIFIED + "/" + N_STATICEXPORT_REGEX,
592            "addExportRuleRegex",
593            1);
594        digester.addCallParam(exportRulePath + "/" + N_STATICEXPORT_MODIFIED + "/" + N_STATICEXPORT_REGEX, 0);
595        digester.addCallMethod(
596            exportRulePath + "/" + N_STATICEXPORT_EXPORT + "/" + N_STATICEXPORT_URI,
597            "addExportRuleUri",
598            1);
599        digester.addCallParam(exportRulePath + "/" + N_STATICEXPORT_EXPORT + "/" + N_STATICEXPORT_URI, 0);
600
601        // rfs-rules configuration
602        String rfsRulePath = "*/"
603            + N_STATICEXPORT
604            + "/"
605            + N_STATICEXPORT_RENDERSETTINGS
606            + "/"
607            + N_STATICEXPORT_RFS_RULES
608            + "/"
609            + N_STATICEXPORT_RFS_RULE;
610        digester.addCallMethod(rfsRulePath, "addRfsRule", 8);
611        digester.addCallParam(rfsRulePath + "/" + N_STATICEXPORT_NAME, 0);
612        digester.addCallParam(rfsRulePath + "/" + N_STATICEXPORT_DESCRIPTION, 1);
613        digester.addCallParam(rfsRulePath + "/" + N_STATICEXPORT_SOURCE, 2);
614        digester.addCallParam(rfsRulePath + "/" + N_STATICEXPORT_RFS_PREFIX, 3);
615        digester.addCallParam(rfsRulePath + "/" + N_STATICEXPORT_EXPORTPATH, 4);
616        digester.addCallParam(rfsRulePath + "/" + N_STATICEXPORT_EXPORTWORKPATH, 5);
617        digester.addCallParam(rfsRulePath + "/" + N_STATICEXPORT_EXPORTBACKUPS, 6);
618        digester.addCallParam(rfsRulePath + "/" + N_STATICEXPORT_RELATIVELINKS, 7);
619        // rfs-rule related system resources
620        digester.addCallMethod(
621            rfsRulePath + "/" + N_STATICEXPORT_RELATED_SYSTEM_RES + "/" + N_STATICEXPORT_REGEX,
622            "addRfsRuleSystemRes",
623            1);
624        digester.addCallParam(rfsRulePath + "/" + N_STATICEXPORT_RELATED_SYSTEM_RES + "/" + N_STATICEXPORT_REGEX, 0);
625
626        // adds protected export rules
627        digester.addCallMethod(
628            "*/" + N_PROTECTED_EXPORT + "/" + N_STATICEXPORT_EXPORTPATH,
629            "setProtectedExportPath",
630            1);
631        digester.addCallParam("*/" + N_PROTECTED_EXPORT + "/" + N_STATICEXPORT_EXPORTPATH, 0);
632        // add rules for the protected export points
633        digester.addCallMethod(
634            "*/"
635                + N_PROTECTED_EXPORT
636                + "/"
637                + I_CmsXmlConfiguration.N_EXPORTPOINTS
638                + "/"
639                + I_CmsXmlConfiguration.N_EXPORTPOINT,
640            "addProtectedExportPoint",
641            2);
642        digester.addCallParam(
643            "*/"
644                + N_PROTECTED_EXPORT
645                + "/"
646                + I_CmsXmlConfiguration.N_EXPORTPOINTS
647                + "/"
648                + I_CmsXmlConfiguration.N_EXPORTPOINT,
649            0,
650            I_CmsXmlConfiguration.A_URI);
651        digester.addCallParam(
652            "*/"
653                + N_PROTECTED_EXPORT
654                + "/"
655                + I_CmsXmlConfiguration.N_EXPORTPOINTS
656                + "/"
657                + I_CmsXmlConfiguration.N_EXPORTPOINT,
658            1,
659            I_CmsXmlConfiguration.A_DESTINATION);
660
661        // add rules for the user data export
662        digester.addObjectCreate("*/" + N_USERCSVEXPORT, CmsUserExportSettings.class);
663        digester.addCallMethod("*/" + N_USERCSVEXPORT + "/" + N_SEPARATOR, "setSeparator", 0);
664        digester.addCallMethod("*/" + N_USERCSVEXPORT + "/" + N_COLUMNS + "/" + N_COLUMN, "addColumn", 0);
665        digester.addSetNext("*/" + N_USERCSVEXPORT, "setUserExportSettings");
666
667        // creation of the static repository manager
668        digester.addObjectCreate("*/" + N_REPOSITORIES, CmsRepositoryManager.class);
669        digester.addCallMethod("*/" + N_REPOSITORIES, I_CmsConfigurationParameterHandler.INIT_CONFIGURATION_METHOD);
670        digester.addSetNext("*/" + N_REPOSITORIES, "setRepositoryManager");
671
672        // repository
673        digester.addObjectCreate(
674            "*/" + N_REPOSITORIES + "/" + N_REPOSITORY,
675            CmsConfigurationException.class.getName(),
676            A_CLASS);
677
678        try {
679            digester.addRule(
680                "*/" + N_REPOSITORIES + "/" + N_REPOSITORY + "/" + N_FILETRANSLATIONS,
681                new NodeCreateRule() {
682
683                    @Override
684                    public void end(String namespace, String name) throws Exception {
685
686                        org.w3c.dom.Element elem = (org.w3c.dom.Element)digester.pop();
687                        boolean enabled = Boolean.parseBoolean(elem.getAttribute(A_ENABLED));
688                        NodeList translationElements = elem.getElementsByTagName(N_TRANSLATION);
689                        String[] translationStrings = new String[translationElements.getLength()];
690                        for (int i = 0; i < translationElements.getLength(); i++) {
691                            org.w3c.dom.Element translationElem = (org.w3c.dom.Element)translationElements.item(i);
692                            translationStrings[i] = translationElem.getTextContent();
693                        }
694                        CmsResourceTranslator translator = new CmsResourceTranslator(translationStrings, true);
695                        I_CmsRepository repo = (I_CmsRepository)(digester.peek());
696                        repo.setTranslation(translator, enabled);
697                    }
698                });
699        } catch (ParserConfigurationException e) {
700            LOG.error(e.getLocalizedMessage(), e);
701        }
702
703        // repository name
704        digester.addCallMethod("*/" + N_REPOSITORIES + "/" + N_REPOSITORY, "setName", 1);
705        digester.addCallParam("*/" + N_REPOSITORIES + "/" + N_REPOSITORY, 0, A_NAME);
706
707        // repository params
708        digester.addCallMethod(
709            "*/" + N_REPOSITORIES + "/" + N_REPOSITORY + "/" + N_PARAMS + "/" + N_PARAM,
710            I_CmsConfigurationParameterHandler.ADD_PARAMETER_METHOD,
711            2);
712        digester.addCallParam(
713            "*/" + N_REPOSITORIES + "/" + N_REPOSITORY + "/" + N_PARAMS + "/" + N_PARAM,
714            0,
715            I_CmsXmlConfiguration.A_NAME);
716        digester.addCallParam("*/" + N_REPOSITORIES + "/" + N_REPOSITORY + "/" + N_PARAMS + "/" + N_PARAM, 1);
717
718        // repository filter
719        digester.addObjectCreate(
720            "*/" + N_REPOSITORIES + "/" + N_REPOSITORY + "/" + N_FILTER,
721            CmsRepositoryFilter.class);
722
723        // repository filter type
724        digester.addCallMethod("*/" + N_REPOSITORIES + "/" + N_REPOSITORY + "/" + N_FILTER, "setType", 1);
725        digester.addCallParam("*/" + N_REPOSITORIES + "/" + N_REPOSITORY + "/" + N_FILTER, 0, A_TYPE);
726
727        // repository filter rules
728        digester.addCallMethod(
729            "*/" + N_REPOSITORIES + "/" + N_REPOSITORY + "/" + N_FILTER + "/" + N_REGEX,
730            "addFilterRule",
731            1);
732        digester.addCallParam("*/" + N_REPOSITORIES + "/" + N_REPOSITORY + "/" + N_FILTER + "/" + N_REGEX, 0);
733
734        digester.addSetNext("*/" + N_REPOSITORIES + "/" + N_REPOSITORY + "/" + N_FILTER, "setFilter");
735
736        digester.addSetNext("*/" + N_REPOSITORIES + "/" + N_REPOSITORY, "addRepositoryClass");
737
738        // create at least a repository manager though no repositories are configured
739        if (m_repositoryManager == null) {
740            m_repositoryManager = new CmsRepositoryManager(false);
741        }
742        // creation of the extended HTML importer
743        digester.addObjectCreate("*/" + N_EXTHTMLIMPORT, CmsExtendedHtmlImportDefault.class);
744        // extended HTML importer  finished
745        digester.addSetNext("*/" + N_EXTHTMLIMPORT, "setExtendedHtmlImportManager");
746        digester.addCallMethod("*/" + N_EXTHTMLIMPORT + "/" + N_EXTHTMLIMPORT_DESTINATION, "setDestinationDir", 0);
747        digester.addCallMethod("*/" + N_EXTHTMLIMPORT + "/" + N_EXTHTMLIMPORT_INPUT, "setInputDir", 0);
748        digester.addCallMethod(
749            "*/" + N_EXTHTMLIMPORT + "/" + N_EXTHTMLIMPORT_GALLERIES + "/" + N_EXTHTMLIMPORT_DOWNLOAD,
750            "setDownloadGallery",
751            0);
752        digester.addCallMethod(
753            "*/" + N_EXTHTMLIMPORT + "/" + N_EXTHTMLIMPORT_GALLERIES + "/" + N_EXTHTMLIMPORT_IMAGE,
754            "setImageGallery",
755            0);
756        digester.addCallMethod(
757            "*/" + N_EXTHTMLIMPORT + "/" + N_EXTHTMLIMPORT_GALLERIES + "/" + N_EXTHTMLIMPORT_EXTERNALLINK,
758            "setLinkGallery",
759            0);
760        digester.addCallMethod(
761            "*/" + N_EXTHTMLIMPORT + "/" + N_EXTHTMLIMPORT_SETTINGS + "/" + N_EXTHTMLIMPORT_TEMPLATE,
762            "setTemplate",
763            0);
764        digester.addCallMethod(
765            "*/" + N_EXTHTMLIMPORT + "/" + N_EXTHTMLIMPORT_SETTINGS + "/" + N_EXTHTMLIMPORT_ELEMENT,
766            "setElement",
767            0);
768        digester.addCallMethod(
769            "*/" + N_EXTHTMLIMPORT + "/" + N_EXTHTMLIMPORT_SETTINGS + "/" + N_EXTHTMLIMPORT_LOCALE,
770            "setLocale",
771            0);
772        digester.addCallMethod(
773            "*/" + N_EXTHTMLIMPORT + "/" + N_EXTHTMLIMPORT_SETTINGS + "/" + N_EXTHTMLIMPORT_ENCODING,
774            "setEncoding",
775            0);
776        digester.addCallMethod(
777            "*/"
778                + N_EXTHTMLIMPORT
779                + "/"
780                + N_EXTHTMLIMPORT_SETTINGS
781                + "/"
782                + N_EXTHTMLIMPORT_PATTERN
783                + "/"
784                + N_EXTHTMLIMPORT_PATTERN_START,
785            "setStartPattern",
786            0);
787        digester.addCallMethod(
788            "*/"
789                + N_EXTHTMLIMPORT
790                + "/"
791                + N_EXTHTMLIMPORT_SETTINGS
792                + "/"
793                + N_EXTHTMLIMPORT_PATTERN
794                + "/"
795                + N_EXTHTMLIMPORT_PATTERN_END,
796            "setEndPattern",
797            0);
798        digester.addCallMethod(
799            "*/" + N_EXTHTMLIMPORT + "/" + N_EXTHTMLIMPORT_SETTINGS + "/" + N_EXTHTMLIMPORT_OVERWRITE,
800            "setOverwrite",
801            0);
802        digester.addCallMethod(
803            "*/" + N_EXTHTMLIMPORT + "/" + N_EXTHTMLIMPORT_SETTINGS + "/" + N_EXTHTMLIMPORT_KEEPBROKENLINKS,
804            "setKeepBrokenLinks",
805            0);
806    }
807
808    /**
809     * @see org.opencms.configuration.I_CmsXmlConfiguration#generateXml(org.dom4j.Element)
810     */
811    public Element generateXml(Element parent) {
812
813        // generate import/export node and subnodes
814        Element importexportElement = parent.addElement(N_IMPORTEXPORT);
815
816        Element resourceloadersElement = importexportElement.addElement(N_IMPORTEXPORTHANDLERS);
817        List<I_CmsImportExportHandler> handlers = m_importExportManager.getImportExportHandlers();
818        Iterator<I_CmsImportExportHandler> handlerIt = handlers.iterator();
819        while (handlerIt.hasNext()) {
820            I_CmsImportExportHandler handler = handlerIt.next();
821            // add the handler node
822            Element loaderNode = resourceloadersElement.addElement(N_IMPORTEXPORTHANDLER);
823            loaderNode.addAttribute(A_CLASS, handler.getClass().getName());
824        }
825
826        Element importElement = importexportElement.addElement(N_IMPORT);
827
828        // <overwrite> node
829        importElement.addElement(N_OVERWRITE).setText(
830            String.valueOf(m_importExportManager.overwriteCollidingResources()));
831
832        // <convert> node
833        importElement.addElement(N_CONVERT).setText(String.valueOf(m_importExportManager.convertToXmlPage()));
834
835        // <oldwebappurl> node
836        if (m_importExportManager.getOldWebAppUrl() != null) {
837            importElement.addElement(N_OLDWEBAPPURL).setText(m_importExportManager.getOldWebAppUrl());
838        }
839
840        // <importversions> node
841        Element resourcetypesElement = importElement.addElement(N_IMPORTVERSIONS);
842        Iterator<I_CmsImport> importVersions = m_importExportManager.getImportVersionClasses().iterator();
843        while (importVersions.hasNext()) {
844            resourcetypesElement.addElement(N_IMPORTVERSION).addAttribute(
845                A_CLASS,
846                importVersions.next().getClass().getName());
847        }
848
849        // <immutables> node
850        Element immutablesElement = importElement.addElement(N_IMMUTABLES);
851        Iterator<String> immutables = m_importExportManager.getImmutableResources().iterator();
852        while (immutables.hasNext()) {
853            String uri = immutables.next();
854            immutablesElement.addElement(N_RESOURCE).addAttribute(A_URI, uri);
855        }
856
857        // <principaltranslations> node
858        Element principalsElement = importElement.addElement(N_PRINCIPALTRANSLATIONS);
859        Iterator<String> userTranslationKeys = m_importExportManager.getImportUserTranslations().keySet().iterator();
860        while (userTranslationKeys.hasNext()) {
861            String from = userTranslationKeys.next();
862            String to = m_importExportManager.getImportUserTranslations().get(from);
863            principalsElement.addElement(N_PRINCIPALTRANSLATION).addAttribute(
864                A_TYPE,
865                I_CmsPrincipal.PRINCIPAL_USER).addAttribute(A_FROM, from).addAttribute(A_TO, to);
866        }
867        Iterator<String> groupTranslationKeys = m_importExportManager.getImportGroupTranslations().keySet().iterator();
868        while (groupTranslationKeys.hasNext()) {
869            String from = groupTranslationKeys.next();
870            String to = m_importExportManager.getImportGroupTranslations().get(from);
871            principalsElement.addElement(N_PRINCIPALTRANSLATION).addAttribute(
872                A_TYPE,
873                I_CmsPrincipal.PRINCIPAL_GROUP).addAttribute(A_FROM, from).addAttribute(A_TO, to);
874        }
875
876        // <ignoredproperties> node
877        Element propertiesElement = importElement.addElement(N_IGNOREDPROPERTIES);
878        Iterator<String> ignoredProperties = m_importExportManager.getIgnoredProperties().iterator();
879        while (ignoredProperties.hasNext()) {
880            String property = ignoredProperties.next();
881            propertiesElement.addElement(N_PROPERTY).addAttribute(A_NAME, property);
882        }
883
884        // <export> node
885        Element exportElement = importexportElement.addElement(N_EXPORT);
886        Map<TimestampMode, List<String>> defaultTimestampModes = m_importExportManager.getDefaultTimestampModes();
887        if (!defaultTimestampModes.isEmpty()) {
888
889            // <defaulttimestampmodes>
890            Element defaultTimestampModesElement = exportElement.addElement(N_EXPORT_DEFAULTTIMESTAMPMODES);
891            for (TimestampMode mode : defaultTimestampModes.keySet()) {
892
893                // <timestampmode>
894                Element timestampModeElement = defaultTimestampModesElement.addElement(N_EXPORT_TIMESTAMPMODE);
895                timestampModeElement.addAttribute(A_MODE, mode.toString().toLowerCase());
896                for (String resourcetypeName : defaultTimestampModes.get(mode)) {
897
898                    // <resourcetypename>
899                    Element resourcetypeElement = timestampModeElement.addElement(N_EXPORT_RESOURCETYPENAME);
900                    resourcetypeElement.addText(resourcetypeName);
901                }
902            }
903        }
904
905        List<String> tempExportpointPaths = m_importExportManager.getTempExportPointPaths();
906        for (String path : tempExportpointPaths) {
907            importexportElement.addElement(N_TEMP_EXPORTPONT_PATH).addText(path);
908        }
909
910        // <staticexport> node
911        Element staticexportElement = parent.addElement(N_STATICEXPORT);
912        staticexportElement.addAttribute(A_ENABLED, m_staticExportManager.getExportEnabled());
913
914        // <staticexporthandler> node
915        staticexportElement.addElement(N_STATICEXPORT_HANDLER).addText(
916            m_staticExportManager.getHandler().getClass().getName());
917
918        // <linksubstitutionhandler> node
919        staticexportElement.addElement(N_LINKSUBSTITUTION_HANDLER).addText(
920            m_staticExportManager.getLinkSubstitutionHandler().getClass().getName());
921
922        // <exportpath> node
923        String exportPathUnmodified = m_staticExportManager.getExportPathForConfiguration();
924        // cut path seperator
925        if (exportPathUnmodified.endsWith(File.separator)) {
926            exportPathUnmodified = exportPathUnmodified.substring(0, exportPathUnmodified.length() - 1);
927        }
928        staticexportElement.addElement(N_STATICEXPORT_EXPORTPATH).addText(exportPathUnmodified);
929
930        // <exportworkpath> node
931        String exportWorkPathUnmodified = m_staticExportManager.getExportWorkPathForConfiguration();
932        if (exportWorkPathUnmodified != null) {
933            // cut path seperator
934            if (exportWorkPathUnmodified.endsWith(File.separator)) {
935                exportWorkPathUnmodified = exportWorkPathUnmodified.substring(0, exportWorkPathUnmodified.length() - 1);
936            }
937            staticexportElement.addElement(N_STATICEXPORT_EXPORTWORKPATH).addText(exportWorkPathUnmodified);
938        }
939
940        // <exportbackups> node
941        if (m_staticExportManager.getExportBackups() != null) {
942            String exportBackupsUnmodified = String.valueOf(m_staticExportManager.getExportBackups());
943            staticexportElement.addElement(N_STATICEXPORT_EXPORTBACKUPS).addText(exportBackupsUnmodified);
944        }
945
946        // <defaultpropertyvalue> node
947        staticexportElement.addElement(N_STATICEXPORT_DEFAULT).addText(m_staticExportManager.getDefault());
948
949        // <defaultsuffixes> node and its <suffix> sub nodes
950        Element defaultsuffixesElement = staticexportElement.addElement(N_STATICEXPORT_DEFAULTSUFFIXES);
951
952        Iterator<String> exportSuffixes = m_staticExportManager.getExportSuffixes().iterator();
953        while (exportSuffixes.hasNext()) {
954            String suffix = exportSuffixes.next();
955            Element suffixElement = defaultsuffixesElement.addElement(N_STATICEXPORT_SUFFIX);
956            suffixElement.addAttribute(A_KEY, suffix);
957        }
958
959        // <exportheaders> node and its <header> sub nodes
960        Iterator<String> exportHandlers = m_staticExportManager.getExportHeaders().iterator();
961        if (exportHandlers.hasNext()) {
962            Element exportheadersElement = staticexportElement.addElement(N_STATICEXPORT_EXPORTHEADERS);
963            while (exportHandlers.hasNext()) {
964                String header = exportHandlers.next();
965                exportheadersElement.addElement(N_STATICEXPORT_HEADER).addText(header);
966            }
967        }
968        // <requestheaders> node and the <acceptlanguage> and <acceptcharset> node
969        String acceptlanguage = m_staticExportManager.getAcceptLanguageHeader();
970        String acceptcharset = m_staticExportManager.getAcceptCharsetHeader();
971        String remoteaddr = m_staticExportManager.getRemoteAddr();
972        if ((acceptlanguage != null) || (acceptcharset != null) || (remoteaddr != null)) {
973            Element requestheadersElement = staticexportElement.addElement(N_STATICEXPORT_REQUESTHEADERS);
974            if (acceptlanguage != null) {
975                requestheadersElement.addElement(N_STATICEXPORT_ACCEPTLANGUAGE).addText(acceptlanguage);
976            }
977            if (acceptcharset != null) {
978                requestheadersElement.addElement(N_STATICEXPORT_ACCEPTCHARSET).addText(acceptcharset);
979            }
980            if (remoteaddr != null) {
981                requestheadersElement.addElement(N_STATICEXPORT_REMOTEADDR).addText(remoteaddr);
982            }
983        }
984
985        // <rendersettings> node
986        Element rendersettingsElement = staticexportElement.addElement(N_STATICEXPORT_RENDERSETTINGS);
987
988        // <rfsPrefix> node
989        rendersettingsElement.addElement(N_STATICEXPORT_RFS_PREFIX).addText(
990            m_staticExportManager.getRfsPrefixForConfiguration());
991
992        // <vfsPrefix> node
993        rendersettingsElement.addElement(N_STATICEXPORT_VFS_PREFIX).addText(
994            m_staticExportManager.getVfsPrefixForConfiguration());
995
996        // <userelativelinks> node
997        rendersettingsElement.addElement(N_STATICEXPORT_RELATIVELINKS).addText(
998            m_staticExportManager.getRelativeLinks());
999
1000        // <exporturl> node
1001        rendersettingsElement.addElement(N_STATICEXPORT_EXPORTURL).addText(
1002            m_staticExportManager.getExportUrlForConfiguration());
1003
1004        // <plainoptimization> node
1005        rendersettingsElement.addElement(N_STATICEXPORT_PLAINOPTIMIZATION).addText(
1006            m_staticExportManager.getPlainExportOptimization());
1007
1008        // <testresource> node
1009        Element testresourceElement = rendersettingsElement.addElement(N_STATICEXPORT_TESTRESOURCE);
1010        testresourceElement.addAttribute(A_URI, m_staticExportManager.getTestResource());
1011
1012        // <resourcestorender> node and <regx> subnodes
1013        Element resourcetorenderElement = rendersettingsElement.addElement(N_STATICEXPORT_RESOURCESTORENDER);
1014
1015        Iterator<String> exportFolderPatterns = m_staticExportManager.getExportFolderPatterns().iterator();
1016        while (exportFolderPatterns.hasNext()) {
1017            String pattern = exportFolderPatterns.next();
1018            resourcetorenderElement.addElement(N_STATICEXPORT_REGEX).addText(pattern);
1019        }
1020
1021        if (!m_staticExportManager.getExportRules().isEmpty()) {
1022            // <export-rules> node
1023            Element exportRulesElement = resourcetorenderElement.addElement(N_STATICEXPORT_EXPORTRULES);
1024
1025            Iterator<CmsStaticExportExportRule> exportRules = m_staticExportManager.getExportRules().iterator();
1026            while (exportRules.hasNext()) {
1027                CmsStaticExportExportRule rule = exportRules.next();
1028                // <export-rule> node
1029                Element exportRuleElement = exportRulesElement.addElement(N_STATICEXPORT_EXPORTRULE);
1030                exportRuleElement.addElement(N_STATICEXPORT_NAME).addText(rule.getName());
1031                exportRuleElement.addElement(N_STATICEXPORT_DESCRIPTION).addText(rule.getDescription());
1032                // <modified-resources> node and <regex> subnodes
1033                Element modifiedElement = exportRuleElement.addElement(N_STATICEXPORT_MODIFIED);
1034                Iterator<Pattern> itMods = rule.getModifiedResources().iterator();
1035                while (itMods.hasNext()) {
1036                    Pattern regex = itMods.next();
1037                    modifiedElement.addElement(N_STATICEXPORT_REGEX).addText(regex.pattern());
1038                }
1039                // <export-resources> node and <uri> subnodes
1040                Element exportResourcesElement = exportRuleElement.addElement(N_STATICEXPORT_EXPORT);
1041                Iterator<String> itExps = rule.getExportResourcePatterns().iterator();
1042                while (itExps.hasNext()) {
1043                    String uri = itExps.next();
1044                    exportResourcesElement.addElement(N_STATICEXPORT_URI).addText(uri);
1045                }
1046            }
1047        }
1048
1049        if (!m_staticExportManager.getRfsRules().isEmpty()) {
1050            // <rfs-rules> node
1051            Element rfsRulesElement = rendersettingsElement.addElement(N_STATICEXPORT_RFS_RULES);
1052
1053            Iterator<CmsStaticExportRfsRule> rfsRules = m_staticExportManager.getRfsRules().iterator();
1054            while (rfsRules.hasNext()) {
1055                CmsStaticExportRfsRule rule = rfsRules.next();
1056                // <rfs-rule> node and subnodes
1057                Element rfsRuleElement = rfsRulesElement.addElement(N_STATICEXPORT_RFS_RULE);
1058                rfsRuleElement.addElement(N_STATICEXPORT_NAME).addText(rule.getName());
1059                rfsRuleElement.addElement(N_STATICEXPORT_DESCRIPTION).addText(rule.getDescription());
1060                rfsRuleElement.addElement(N_STATICEXPORT_SOURCE).addText(rule.getSource().pattern());
1061                rfsRuleElement.addElement(N_STATICEXPORT_RFS_PREFIX).addText(rule.getRfsPrefixConfigured());
1062                rfsRuleElement.addElement(N_STATICEXPORT_EXPORTPATH).addText(rule.getExportPathConfigured());
1063                if (rule.getExportWorkPathConfigured() != null) {
1064                    rfsRuleElement.addElement(N_STATICEXPORT_EXPORTWORKPATH).addText(
1065                        rule.getExportWorkPathConfigured());
1066                }
1067                if (rule.getExportBackups() != null) {
1068                    rfsRuleElement.addElement(N_STATICEXPORT_EXPORTBACKUPS).addText(
1069                        String.valueOf(rule.getExportBackups()));
1070                }
1071                if (rule.getUseRelativeLinks() != null) {
1072                    rfsRuleElement.addElement(N_STATICEXPORT_RELATIVELINKS).addText(
1073                        rule.getUseRelativeLinks().toString());
1074                }
1075                Element relatedSystemRes = rfsRuleElement.addElement(N_STATICEXPORT_RELATED_SYSTEM_RES);
1076                Iterator<Pattern> itSystemRes = rule.getRelatedSystemResources().iterator();
1077                while (itSystemRes.hasNext()) {
1078                    Pattern sysRes = itSystemRes.next();
1079                    relatedSystemRes.addElement(N_STATICEXPORT_REGEX).addText(sysRes.pattern());
1080                }
1081            }
1082
1083        }
1084
1085        if (m_staticExportManager.getProtectedExportPath() != null) {
1086            Element streamingEl = parent.addElement(N_PROTECTED_EXPORT);
1087            streamingEl.addElement(N_STATICEXPORT_EXPORTPATH).setText(m_staticExportManager.getProtectedExportPath());
1088            Element exportpoints = streamingEl.addElement(I_CmsXmlConfiguration.N_EXPORTPOINTS);
1089            for (Entry<String, String> entry : m_staticExportManager.getProtectedExportPoints().entrySet()) {
1090                Element point = exportpoints.addElement(I_CmsXmlConfiguration.N_EXPORTPOINT);
1091                point.addAttribute(I_CmsXmlConfiguration.A_URI, entry.getKey());
1092                point.addAttribute(I_CmsXmlConfiguration.A_DESTINATION, entry.getValue());
1093            }
1094        }
1095
1096        if (m_importExportManager.getUserExportSettings() != null) {
1097            // <usercsvexport>
1098            Element userExportElement = parent.addElement(N_USERCSVEXPORT);
1099
1100            userExportElement.addElement(N_SEPARATOR).setText(
1101                m_importExportManager.getUserExportSettings().getSeparator());
1102            Element exportColumns = userExportElement.addElement(N_COLUMNS);
1103            List<String> exportColumnList = m_importExportManager.getUserExportSettings().getColumns();
1104            Iterator<String> itExportColumnList = exportColumnList.iterator();
1105            while (itExportColumnList.hasNext()) {
1106                exportColumns.addElement(N_COLUMN).setText(itExportColumnList.next());
1107            }
1108            // </usercsvexport>
1109        }
1110
1111        if (m_repositoryManager.isConfigured()) {
1112            List<I_CmsRepository> repositories = m_repositoryManager.getRepositories();
1113            if (repositories != null) {
1114
1115                // <repositories> node
1116                Element repositoriesElement = parent.addElement(N_REPOSITORIES);
1117
1118                Iterator<I_CmsRepository> repositoriesIt = repositories.iterator();
1119                while (repositoriesIt.hasNext()) {
1120
1121                    // <repository> node
1122                    I_CmsRepository repository = repositoriesIt.next();
1123                    Element repositoryElement = repositoriesElement.addElement(N_REPOSITORY);
1124                    repositoryElement.addAttribute(A_NAME, repository.getName());
1125                    repositoryElement.addAttribute(A_CLASS, repository.getClass().getName());
1126
1127                    // <params> node
1128                    CmsParameterConfiguration config = repository.getConfiguration();
1129                    if ((config != null) && (config.size() > 0)) {
1130                        Element paramsElement = repositoryElement.addElement(N_PARAMS);
1131                        config.appendToXml(paramsElement);
1132                    }
1133
1134                    // <filter> node
1135                    CmsRepositoryFilter filter = repository.getFilter();
1136                    if (filter != null) {
1137                        List<Pattern> rules = filter.getFilterRules();
1138                        if (rules.size() > 0) {
1139                            Element filterElement = repositoryElement.addElement(N_FILTER);
1140                            filterElement.addAttribute(A_TYPE, filter.getType());
1141
1142                            // <regex> nodes
1143                            Iterator<Pattern> it = rules.iterator();
1144                            while (it.hasNext()) {
1145                                Pattern rule = it.next();
1146                                filterElement.addElement(N_REGEX).addText(rule.pattern());
1147                            }
1148                        }
1149                    }
1150
1151                    CmsResourceTranslator translator = repository.getTranslation();
1152                    if (translator != null) {
1153                        boolean translationEnabled = repository.isTranslationEnabled();
1154                        Element fileTransElem = repositoryElement.addElement(N_FILETRANSLATIONS);
1155                        fileTransElem.addAttribute(A_ENABLED, "" + translationEnabled);
1156                        String[] translationStrings = translator.getTranslations();
1157                        for (String translation : translationStrings) {
1158                            fileTransElem.addElement(N_TRANSLATION).setText(translation);
1159                        }
1160                    }
1161                }
1162            }
1163        }
1164        CmsExtendedHtmlImportDefault htmlimport = m_importExportManager.getExtendedHtmlImportDefault(true);
1165        if (htmlimport != null) {
1166            // <extendedhtmlimport>
1167            Element htmlImportElement = parent.addElement(N_EXTHTMLIMPORT);
1168            // <destination> node
1169            if (!CmsStringUtil.isEmptyOrWhitespaceOnly(htmlimport.getDestinationDir())) {
1170                htmlImportElement.addElement(N_EXTHTMLIMPORT_DESTINATION).setText(htmlimport.getDestinationDir());
1171            }
1172            // <input> node
1173            if (!CmsStringUtil.isEmptyOrWhitespaceOnly(htmlimport.getInputDir())) {
1174                htmlImportElement.addElement(N_EXTHTMLIMPORT_INPUT).setText(htmlimport.getInputDir());
1175            }
1176
1177            // <galleries> node
1178            Element galleryElement = htmlImportElement.addElement(N_EXTHTMLIMPORT_GALLERIES);
1179            // <download> node
1180            if (!CmsStringUtil.isEmptyOrWhitespaceOnly(htmlimport.getDownloadGallery())) {
1181                galleryElement.addElement(N_EXTHTMLIMPORT_DOWNLOAD).setText(htmlimport.getDownloadGallery());
1182            }
1183            // <image> node
1184            if (!CmsStringUtil.isEmptyOrWhitespaceOnly(htmlimport.getImageGallery())) {
1185                galleryElement.addElement(N_EXTHTMLIMPORT_IMAGE).setText(htmlimport.getImageGallery());
1186            }
1187            // <externallink> node
1188            if (!CmsStringUtil.isEmptyOrWhitespaceOnly(htmlimport.getLinkGallery())) {
1189                galleryElement.addElement(N_EXTHTMLIMPORT_EXTERNALLINK).setText(htmlimport.getLinkGallery());
1190            }
1191
1192            // <settings> node
1193            Element settingElement = htmlImportElement.addElement(N_EXTHTMLIMPORT_SETTINGS);
1194            // <template> node
1195            settingElement.addElement(N_EXTHTMLIMPORT_TEMPLATE).setText(htmlimport.getTemplate());
1196            // <element> node
1197            settingElement.addElement(N_EXTHTMLIMPORT_ELEMENT).setText(htmlimport.getElement());
1198            // <locale> node
1199            settingElement.addElement(N_EXTHTMLIMPORT_LOCALE).setText(htmlimport.getLocale());
1200            // <encoding> node
1201            settingElement.addElement(N_EXTHTMLIMPORT_ENCODING).setText(htmlimport.getEncoding());
1202
1203            // <pattern> node
1204            Element patternElement = settingElement.addElement(N_EXTHTMLIMPORT_PATTERN);
1205            // <start> node
1206            if (!CmsStringUtil.isEmptyOrWhitespaceOnly(htmlimport.getStartPattern())) {
1207                patternElement.addElement(N_EXTHTMLIMPORT_PATTERN_START).setText(htmlimport.getStartPattern());
1208            }
1209            // <end> node
1210            if (!CmsStringUtil.isEmptyOrWhitespaceOnly(htmlimport.getEndPattern())) {
1211                patternElement.addElement(N_EXTHTMLIMPORT_PATTERN_END).setText(htmlimport.getEndPattern());
1212            }
1213
1214            // <overwrite> node
1215            settingElement.addElement(N_EXTHTMLIMPORT_OVERWRITE).setText(htmlimport.getOverwrite());
1216            // <keepbrokenlinks> node
1217            settingElement.addElement(N_EXTHTMLIMPORT_KEEPBROKENLINKS).setText(htmlimport.getKeepBrokenLinks());
1218            // </extendedhtmlimport>
1219        }
1220
1221        // return the configured node
1222        return importexportElement;
1223    }
1224
1225    /**
1226     * @see org.opencms.configuration.I_CmsXmlConfiguration#getDtdFilename()
1227     */
1228    public String getDtdFilename() {
1229
1230        return CONFIGURATION_DTD_NAME;
1231    }
1232
1233    /**
1234     * Returns the initialized import/export manager.<p>
1235     *
1236     * @return the initialized import/export manager
1237     */
1238    public CmsImportExportManager getImportExportManager() {
1239
1240        return m_importExportManager;
1241    }
1242
1243    /**
1244     * Returns the initialized repository manager.<p>
1245     *
1246     * @return the initialized repository manager
1247     */
1248    public CmsRepositoryManager getRepositoryManager() {
1249
1250        return m_repositoryManager;
1251    }
1252
1253    /**
1254     * Returns the initialized static export manager.<p>
1255     *
1256     * @return the initialized static export manager
1257     */
1258    public CmsStaticExportManager getStaticExportManager() {
1259
1260        return m_staticExportManager;
1261    }
1262
1263    /**
1264     * Will be called when configuration of this object is finished.<p>
1265     */
1266    public void initializeFinished() {
1267
1268        if (CmsLog.INIT.isInfoEnabled()) {
1269            CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_IMPORT_CONFIG_FINISHED_0));
1270        }
1271    }
1272
1273    /**
1274     * Sets the extendedHtmlImportManager.<p>
1275     *
1276     * @param extendedHtmlImportManager the extendedHtmlImportManager to set
1277     */
1278    public void setExtendedHtmlImportManager(CmsExtendedHtmlImportDefault extendedHtmlImportManager) {
1279
1280        m_importExportManager.setExtendedHtmlImportDefault(extendedHtmlImportManager);
1281    }
1282
1283    /**
1284     * Sets the generated import/export manager.<p>
1285     *
1286     * @param manager the import/export manager to set
1287     */
1288    public void setImportExportManager(CmsImportExportManager manager) {
1289
1290        m_importExportManager = manager;
1291        if (CmsLog.INIT.isInfoEnabled()) {
1292            CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_IMPORT_MANAGER_0));
1293        }
1294    }
1295
1296    /**
1297     * Sets the protected export path.<p>
1298     *
1299     * @param exportPath the export path to set
1300     */
1301    public void setProtectedExportPath(String exportPath) {
1302
1303        m_staticExportManager.setProtectedExportPath(exportPath);
1304    }
1305
1306    /**
1307     * Sets the generated repository manager.<p>
1308     *
1309     * @param manager the repository manager to set
1310     */
1311    public void setRepositoryManager(CmsRepositoryManager manager) {
1312
1313        m_repositoryManager = manager;
1314    }
1315
1316    /**
1317     * Sets the generated static export manager.<p>
1318     *
1319     * @param manager the static export manager to set
1320     */
1321    public void setStaticExportManager(CmsStaticExportManager manager) {
1322
1323        m_staticExportManager = manager;
1324        if (CmsLog.INIT.isInfoEnabled()) {
1325            CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_STATEXP_MANAGER_0));
1326        }
1327    }
1328
1329    /**
1330     * Sets the user settings for export and import.<p>
1331     *
1332     * @param userExportSettings the user settings for export and import
1333     */
1334    public void setUserExportSettings(CmsUserExportSettings userExportSettings) {
1335
1336        m_importExportManager.setUserExportSettings(userExportSettings);
1337    }
1338
1339    /**
1340     * @see org.opencms.configuration.A_CmsXmlConfiguration#initMembers()
1341     */
1342    @Override
1343    protected void initMembers() {
1344
1345        setXmlFileName(DEFAULT_XML_FILE_NAME);
1346        if (CmsLog.INIT.isInfoEnabled()) {
1347            CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_IMPORT_CONFIG_INIT_0));
1348        }
1349    }
1350
1351}