KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > importexport > CmsImportExportManager


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/importexport/CmsImportExportManager.java,v $
3  * Date : $Date: 2006/03/27 14:52:54 $
4  * Version: $Revision: 1.30 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.importexport;
33
34 import org.opencms.configuration.CmsConfigurationException;
35 import org.opencms.file.CmsObject;
36 import org.opencms.i18n.CmsMessageContainer;
37 import org.opencms.main.CmsEvent;
38 import org.opencms.main.CmsException;
39 import org.opencms.main.CmsLog;
40 import org.opencms.main.I_CmsEventListener;
41 import org.opencms.main.OpenCms;
42 import org.opencms.report.I_CmsReport;
43 import org.opencms.security.CmsRole;
44 import org.opencms.security.CmsRoleViolationException;
45 import org.opencms.security.I_CmsPrincipal;
46 import org.opencms.xml.CmsXmlException;
47
48 import java.io.BufferedReader JavaDoc;
49 import java.io.File JavaDoc;
50 import java.io.FileReader JavaDoc;
51 import java.io.InputStream JavaDoc;
52 import java.io.Reader JavaDoc;
53 import java.util.ArrayList JavaDoc;
54 import java.util.Collections JavaDoc;
55 import java.util.HashMap JavaDoc;
56 import java.util.List JavaDoc;
57 import java.util.Map JavaDoc;
58 import java.util.zip.ZipEntry JavaDoc;
59 import java.util.zip.ZipFile JavaDoc;
60
61 import org.apache.commons.logging.Log;
62
63 import org.dom4j.Document;
64 import org.dom4j.io.SAXReader;
65
66 /**
67  * Provides information about how to handle imported resources.<p>
68  *
69  * @author Thomas Weckert
70  *
71  * @version $Revision: 1.30 $
72  *
73  * @since 6.0.0
74  *
75  * @see OpenCms#getImportExportManager()
76  */

77 public class CmsImportExportManager {
78
79     /** The name of the XML manifest file used for the description of exported OpenCms VFS properties and atributes. */
80     public static final String JavaDoc EXPORT_MANIFEST = "manifest.xml";
81
82     /** The current version of the OpenCms export (appears in the {@link #EXPORT_MANIFEST} header). */
83     public static final String JavaDoc EXPORT_VERSION = "4";
84
85     /**
86      * The name of the XML manifest file used for the description of exported OpenCms VFS properties and atributes.<p>
87      *
88      * @deprecated use {@link #EXPORT_MANIFEST} instead
89      */

90     public static final String JavaDoc EXPORT_XMLFILENAME = EXPORT_MANIFEST;
91
92     /** Tag in the {@link #EXPORT_MANIFEST} for the "access" node. */
93     public static final String JavaDoc N_ACCESS = "access";
94
95     /** Tag in the {@link #EXPORT_MANIFEST} for the "allowed" node, to identify allowed user permissions. */
96     public static final String JavaDoc N_ACCESSCONTROL_ALLOWEDPERMISSIONS = "allowed";
97
98     /** Tag in the {@link #EXPORT_MANIFEST} for the "denied" node, to identify denied user permissions. */
99     public static final String JavaDoc N_ACCESSCONTROL_DENIEDPERMISSIONS = "denied";
100
101     /** Tag in the {@link #EXPORT_MANIFEST} for the "accesscontrol" node, to identify access control entries. */
102     public static final String JavaDoc N_ACCESSCONTROL_ENTRIES = "accesscontrol";
103
104     /** Tag in the {@link #EXPORT_MANIFEST} for the "accessentry" node, to identify a single access control entry. */
105     public static final String JavaDoc N_ACCESSCONTROL_ENTRY = "accessentry";
106
107     /** Tag in the {@link #EXPORT_MANIFEST} for the "permissionset" node, to identify a permission set. */
108     public static final String JavaDoc N_ACCESSCONTROL_PERMISSIONSET = "permissionset";
109
110     /** Tag in the {@link #EXPORT_MANIFEST} for the "uuidprincipal" node, to identify a principal UUID. */
111     public static final String JavaDoc N_ACCESSCONTROL_PRINCIPAL = "uuidprincipal";
112
113     /** Tag for the "creator" node (appears in the {@link #EXPORT_MANIFEST} header). */
114     public static final String JavaDoc N_CREATOR = "creator";
115
116     /** Tag for the "createdate" node (appears in the {@link #EXPORT_MANIFEST} header). */
117     public static final String JavaDoc N_DATE = "createdate";
118
119     /** Tag in the {@link #EXPORT_MANIFEST} for the "datecreated" node, contains the date created VFS file attribute. */
120     public static final String JavaDoc N_DATECREATED = "datecreated";
121
122     /** Tag in the {@link #EXPORT_MANIFEST} for the "dateexpired" node, contains the expiration date VFS file attribute. */
123     public static final String JavaDoc N_DATEEXPIRED = "dateexpired";
124
125     /** Tag in the {@link #EXPORT_MANIFEST} for the "datelastmodified" node, contains the date last modified VFS file attribute. */
126     public static final String JavaDoc N_DATELASTMODIFIED = "datelastmodified";
127
128     /** Tag in the {@link #EXPORT_MANIFEST} for the "datereleased" node, contains the release date VFS file attribute. */
129     public static final String JavaDoc N_DATERELEASED = "datereleased";
130
131     /** Tag in the {@link #EXPORT_MANIFEST} for the "defaultgroup" node, for backward compatibility with OpenCms 5.x. */
132     public static final String JavaDoc N_DEFAULTGROUP = "defaultgroup";
133
134     /** Tag in the {@link #EXPORT_MANIFEST} for the "description" node, contains a users description test. */
135     public static final String JavaDoc N_DESCRIPTION = "description";
136
137     /** Tag in the {@link #EXPORT_MANIFEST} for the "destination" node, contains target VFS file name. */
138     public static final String JavaDoc N_DESTINATION = "destination";
139
140     /** Tag in the {@link #EXPORT_MANIFEST} for the "email" node, contains a users email. */
141     public static final String JavaDoc N_EMAIL = "email";
142
143     /** Tag in the {@link #EXPORT_MANIFEST} for the "export" node. */
144     public static final String JavaDoc N_EXPORT = "export";
145
146     /** Tag in the {@link #EXPORT_MANIFEST} for the "file" node, container node for all VFS resources. */
147     public static final String JavaDoc N_FILE = "file";
148
149     /** Tag in the {@link #EXPORT_MANIFEST} for the "firstname" node, contains a users first name. */
150     public static final String JavaDoc N_FIRSTNAME = "firstname";
151
152     /** Tag in the {@link #EXPORT_MANIFEST} for the "flags" node, contains the flags of a VFS resource. */
153     public static final String JavaDoc N_FLAGS = "flags";
154
155     /** Tag in the {@link #EXPORT_MANIFEST} for the "groupdata" node, contains a users group data. */
156     public static final String JavaDoc N_GROUPDATA = "groupdata";
157
158     /** Tag in the {@link #EXPORT_MANIFEST} for the "groupname" node, contains a groups name. */
159     public static final String JavaDoc N_GROUPNAME = "groupname";
160
161     /** Tag in the {@link #EXPORT_MANIFEST} for the "id" node, only required for backward compatibility with import version 2. */
162     public static final String JavaDoc N_ID = "id";
163
164     /** Tag in the {@link #EXPORT_MANIFEST}, starts the manifest info header. */
165     public static final String JavaDoc N_INFO = "info";
166
167     /** Tag in the {@link #EXPORT_MANIFEST} for the "lastmodified" node, only required for backward compatibility with import version 2. */
168     public static final String JavaDoc N_LASTMODIFIED = "lastmodified";
169
170     /** Tag in the {@link #EXPORT_MANIFEST} for the "lastname" node, contains a users last name. */
171     public static final String JavaDoc N_LASTNAME = "lastname";
172
173     /** Tag in the {@link #EXPORT_MANIFEST} for the "name" node, contains a users login name. */
174     public static final String JavaDoc N_NAME = "name";
175
176     /** Tag in the {@link #EXPORT_MANIFEST} for the "opencms_version" node, appears in the manifest info header. */
177     public static final String JavaDoc N_OC_VERSION = "opencms_version";
178
179     /** Tag in the {@link #EXPORT_MANIFEST} for the "parentgroup" node, contains a groups parent group name. */
180     public static final String JavaDoc N_PARENTGROUP = "parentgroup";
181
182     /** Tag in the {@link #EXPORT_MANIFEST} for the "password" node, contains a users encrypted password. */
183     public static final String JavaDoc N_PASSWORD = "password";
184
185     /** Tag in the {@link #EXPORT_MANIFEST} for the "project" node, appears in the manifest info header. */
186     public static final String JavaDoc N_PROJECT = "project";
187
188     /** Tag in the {@link #EXPORT_MANIFEST} for the "properties" node, starts the list of properties of a VFS resource. */
189     public static final String JavaDoc N_PROPERTIES = "properties";
190
191     /** Tag in the {@link #EXPORT_MANIFEST} for the "property" node, starts a property for a VFS resource. */
192     public static final String JavaDoc N_PROPERTY = "property";
193
194     /** Tag in the {@link #EXPORT_MANIFEST} for the "type" property attribute, contains a property type. */
195     public static final String JavaDoc N_PROPERTY_ATTRIB_TYPE = "type";
196
197     /** Tag in the {@link #EXPORT_MANIFEST} for the "shared" property type attribute value. */
198     public static final String JavaDoc N_PROPERTY_ATTRIB_TYPE_SHARED = "shared";
199
200     /** Tag in the {@link #EXPORT_MANIFEST} for the "source" node, contains the source path of a VFS resource in the import zip (or folder). */
201     public static final String JavaDoc N_SOURCE = "source";
202
203     /** Tag in the {@link #EXPORT_MANIFEST} for the "address" node, contains a users address. */
204     public static final String JavaDoc N_TAG_ADDRESS = "address";
205
206     /** Tag in the {@link #EXPORT_MANIFEST} for the "type" node, the resource type name of a VFS resource. */
207     public static final String JavaDoc N_TYPE = "type";
208
209     /** Tag in the {@link #EXPORT_MANIFEST} for the "user" node, starts the user data. */
210     public static final String JavaDoc N_USER = "user";
211
212     /** Tag in the {@link #EXPORT_MANIFEST} for the "usercreated" node, contains the name of the user who created the VFS resource. */
213     public static final String JavaDoc N_USERCREATED = "usercreated";
214
215     /** Tag in the {@link #EXPORT_MANIFEST} for the "userdata" node, starts the list of users. */
216     public static final String JavaDoc N_USERDATA = "userdata";
217
218     /** Tag in the {@link #EXPORT_MANIFEST} for the "usergroupdatas" node, starts the users group data. */
219     public static final String JavaDoc N_USERGROUPDATA = "usergroupdata";
220
221     /** Tag in the {@link #EXPORT_MANIFEST} for the "usergroups" node, starts the users group data. */
222     public static final String JavaDoc N_USERGROUPS = "usergroups";
223
224     /** Tag in the {@link #EXPORT_MANIFEST} for the "userinfo" node, contains the additional user info. */
225     public static final String JavaDoc N_USERINFO = "userinfo";
226
227     /** Tag in the {@link #EXPORT_MANIFEST} for the "userlastmodified" node, contains the name of the user who last modified the VFS resource. */
228     public static final String JavaDoc N_USERLASTMODIFIED = "userlastmodified";
229
230     /** Tag in the {@link #EXPORT_MANIFEST} for the "uuidresource" node, contains a the resource UUID of a VFS resource. */
231     public static final String JavaDoc N_UUIDRESOURCE = "uuidresource";
232
233     /** Tag in the {@link #EXPORT_MANIFEST} for the "uuidstructure" node, only required for backward compatibility with import version 2. */
234     public static final String JavaDoc N_UUIDSTRUCTURE = "uuidstructure";
235
236     /** Tag in the {@link #EXPORT_MANIFEST} for the "value" node, contains the value of a property. */
237     public static final String JavaDoc N_VALUE = "value";
238
239     /** Tag in the {@link #EXPORT_MANIFEST} for the "export_version" node, appears in the manifest info header. */
240     public static final String JavaDoc N_VERSION = "export_version";
241
242     /** The log object for this class. */
243     private static final Log LOG = CmsLog.getLog(CmsImportExportManager.class);
244
245     /** Boolean flag whether imported pages should be converted into XML pages. */
246     private boolean m_convertToXmlPage;
247
248     /** List of property keys that should be removed from imported resources. */
249     private List JavaDoc m_ignoredProperties;
250
251     /** List of immutable resources that should remain unchanged when resources are imported. */
252     private List JavaDoc m_immutableResources;
253
254     /** The initialized import/export handlers. */
255     private List JavaDoc m_importExportHandlers;
256
257     /** Import princial group translations. */
258     private Map JavaDoc m_importGroupTranslations;
259
260     /** Import princial user translations. */
261     private Map JavaDoc m_importUserTranslations;
262
263     /** The configured import versions class names. */
264     private List JavaDoc m_importVersionClasses;
265
266     /** Boolean flag whether colliding resources should be overwritten during the import. */
267     private boolean m_overwriteCollidingResources;
268
269     /** The URL of a 4.x OpenCms app. to import content correct into 5.x OpenCms apps. */
270     private String JavaDoc m_webAppUrl;
271
272     /**
273      * Creates a new instance for the import/export manager, will be called by the import/export configuration manager.
274      */

275     public CmsImportExportManager() {
276
277         if (LOG.isInfoEnabled()) {
278             LOG.info(Messages.get().getBundle().key(Messages.INIT_IMPORTEXPORT_INITIALIZING_0));
279         }
280
281         m_importExportHandlers = new ArrayList JavaDoc();
282         m_immutableResources = new ArrayList JavaDoc();
283         m_ignoredProperties = new ArrayList JavaDoc();
284         m_convertToXmlPage = true;
285         m_importGroupTranslations = new HashMap JavaDoc();
286         m_importUserTranslations = new HashMap JavaDoc();
287         m_overwriteCollidingResources = true;
288         m_importVersionClasses = new ArrayList JavaDoc();
289     }
290
291     /**
292      * Returns the "manifest.xml" of an available import resource as a dom4j document.<p>
293      *
294      * The manifest is either read as a ZIP entry, or from a subfolder of the specified
295      * file resource.<p>
296      *
297      * @param resource a File resource
298      * @return the "manifest.xml" as a dom4j document
299      */

300     public static Document getManifest(File JavaDoc resource) {
301
302         Document manifest = null;
303         ZipFile JavaDoc zipFile = null;
304         ZipEntry JavaDoc zipFileEntry = null;
305         InputStream JavaDoc input = null;
306         Reader JavaDoc reader = null;
307         SAXReader saxReader = null;
308         File JavaDoc manifestFile = null;
309
310         try {
311             if (resource.isFile()) {
312                 if (!resource.getName().toLowerCase().endsWith(".zip")) {
313                     // skip non-ZIP files
314
return null;
315                 }
316                 // create a Reader for a ZIP file
317
zipFile = new ZipFile JavaDoc(resource);
318                 zipFileEntry = zipFile.getEntry(EXPORT_MANIFEST);
319                 input = zipFile.getInputStream(zipFileEntry);
320                 // transform the manifest.xml file into a dom4j Document
321
saxReader = new SAXReader();
322                 manifest = saxReader.read(input);
323             } else if (resource.isDirectory()) {
324                 // create a Reader for a file in the file system
325
manifestFile = new File JavaDoc(resource, EXPORT_MANIFEST);
326                 reader = new BufferedReader JavaDoc(new FileReader JavaDoc(manifestFile));
327                 // transform the manifest.xml file into a dom4j Document
328
saxReader = new SAXReader();
329                 manifest = saxReader.read(reader);
330             }
331         } catch (Exception JavaDoc e) {
332             if (LOG.isDebugEnabled()) {
333                 LOG.debug(
334                     Messages.get().getBundle().key(Messages.LOG_IMPORTEXPORT_ERROR_READING_MANIFEST_1, resource),
335                     e);
336             }
337             manifest = null;
338         } finally {
339             try {
340                 if (reader != null) {
341                     reader.close();
342                 }
343             } catch (Exception JavaDoc e) {
344                 // noop
345
}
346         }
347
348         return manifest;
349     }
350
351     /**
352      * Adds a property name to the list of properties that should be removed from imported resources.<p>
353      *
354      * @param propertyName a property name
355      */

356     public void addIgnoredProperty(String JavaDoc propertyName) {
357
358         if (LOG.isDebugEnabled()) {
359             LOG.debug(Messages.get().getBundle().key(Messages.LOG_IMPORTEXPORT_IGNORING_PROPERTY_1, propertyName));
360         }
361         m_ignoredProperties.add(propertyName);
362     }
363
364     /**
365      * Adds a resource to the list of immutable resources that should remain
366      * unchanged when resources are imported.<p>
367      *
368      * @param immutableResource a resources uri in the OpenCms VFS
369      */

370     public void addImmutableResource(String JavaDoc immutableResource) {
371
372         if (LOG.isDebugEnabled()) {
373             LOG.debug(Messages.get().getBundle().key(
374                 Messages.LOG_IMPORTEXPORT_ADDED_IMMUTABLE_RESOURCE_1,
375                 immutableResource));
376         }
377         m_immutableResources.add(immutableResource);
378     }
379
380     /**
381      * Adds an import/export handler to the list of configured handlers.<p>
382      *
383      * @param handler the import/export handler to add
384      */

385     public void addImportExportHandler(I_CmsImportExportHandler handler) {
386
387         if (LOG.isDebugEnabled()) {
388             LOG.debug(Messages.get().getBundle().key(Messages.LOG_IMPORTEXPORT_ADDED_IMPORTEXPORT_HANDLER_1, handler));
389         }
390         m_importExportHandlers.add(handler);
391     }
392
393     /**
394      * Adds an import princial translation to the configuration.<p>
395      *
396      * @param type the princial type ("USER" or "GROUP")
397      * @param from the "from" translation source
398      * @param to the "to" translation target
399      */

400     public void addImportPrincipalTranslation(String JavaDoc type, String JavaDoc from, String JavaDoc to) {
401
402         if (LOG.isDebugEnabled()) {
403             LOG.debug(Messages.get().getBundle().key(
404                 Messages.LOG_IMPORTEXPORT_ADDED_PRINCIPAL_TRANSLATION_3,
405                 type,
406                 from,
407                 to));
408         }
409         if (I_CmsPrincipal.PRINCIPAL_GROUP.equalsIgnoreCase(type)) {
410             m_importGroupTranslations.put(from, to);
411             if (LOG.isInfoEnabled()) {
412                 LOG.info(Messages.get().getBundle().key(Messages.INIT_IMPORTEXPORT_ADDED_GROUP_TRANSLATION_2, from, to));
413             }
414         } else if (I_CmsPrincipal.PRINCIPAL_USER.equalsIgnoreCase(type)) {
415             m_importUserTranslations.put(from, to);
416             if (LOG.isInfoEnabled()) {
417                 LOG.info(Messages.get().getBundle().key(Messages.INIT_IMPORTEXPORT_ADDED_USER_TRANSLATION_2, from, to));
418             }
419         }
420     }
421
422     /**
423      * Adds a import version class name to the configuration.<p>
424      *
425      * @param importVersionClass the import version class name to add
426      */

427     public void addImportVersionClass(I_CmsImport importVersionClass) {
428
429         if (LOG.isDebugEnabled()) {
430             LOG.debug(Messages.get().getBundle().key(
431                 Messages.LOG_IMPORTEXPORT_ADDED_IMPORT_VERSION_1,
432                 importVersionClass));
433         }
434         m_importVersionClasses.add(importVersionClass);
435     }
436
437     /**
438      * Checks if imported pages should be converted into XML pages.<p>
439      *
440      * @return true, if imported pages should be converted into XML pages
441      */

442     public boolean convertToXmlPage() {
443
444         return m_convertToXmlPage;
445     }
446
447     /**
448      * Checks if the current user has permissions to export Cms data of a specified export handler,
449      * and if so, triggers the handler to write the export.<p>
450      *
451      * @param cms the current OpenCms context object
452      * @param handler handler containing the export data
453      * @param report a Cms report to print log messages
454      * @throws CmsRoleViolationException if the current user is not a allowed to export the OpenCms database
455      * @throws CmsImportExportException if operation was not successful
456      * @throws CmsConfigurationException if something goes wrong
457      * @see I_CmsImportExportHandler
458      */

459     public void exportData(CmsObject cms, I_CmsImportExportHandler handler, I_CmsReport report)
460     throws CmsConfigurationException, CmsImportExportException, CmsRoleViolationException {
461
462         cms.checkRole(CmsRole.EXPORT_DATABASE);
463         handler.exportData(cms, report);
464     }
465
466     /**
467      * Returns the list of property keys that should be removed from imported resources.<p>
468      *
469      * @return the list of property keys that should be removed from imported resources, or Collections.EMPTY_LIST
470      */

471     public List JavaDoc getIgnoredProperties() {
472
473         return m_ignoredProperties;
474     }
475
476     /**
477      * Returns the list of immutable resources that should remain unchanged when resources are
478      * imported.<p>
479      *
480      * Certain system resources should not be changed during import. This is the case for the main
481      * folders in the /system/ folder. Changes to these folders usually should not be imported to
482      * another system.<p>
483      *
484      * @return the list of immutable resources, or Collections.EMPTY_LIST
485      */

486     public List JavaDoc getImmutableResources() {
487
488         return m_immutableResources;
489     }
490
491     /**
492      * Returns an instance of an import/export handler implementation that is able to import
493      * a specified resource.<p>
494      *
495      * @param importFile the name (absolute path) of the resource (zipfile or folder) to be imported
496      * @return an instance of an import/export handler implementation
497      * @throws CmsImportExportException if somethong goes wrong
498      */

499     public I_CmsImportExportHandler getImportExportHandler(String JavaDoc importFile) throws CmsImportExportException {
500
501         Document manifest = null;
502         I_CmsImportExportHandler handler = null;
503
504         File JavaDoc file = new File JavaDoc(importFile);
505         if (!file.exists()) {
506             // file does not exist
507
CmsMessageContainer message = Messages.get().container(
508                 Messages.ERR_IMPORTEXPORT_ERROR_IMPORT_FILE_DOES_NOT_EXIST_1,
509                 importFile);
510             if (LOG.isDebugEnabled()) {
511                 LOG.debug(message.key());
512             }
513
514             throw new CmsImportExportException(message);
515         }
516
517         manifest = getManifest(file);
518         for (int i = 0; i < m_importExportHandlers.size(); i++) {
519             handler = (I_CmsImportExportHandler)m_importExportHandlers.get(i);
520             if (handler.matches(manifest)) {
521                 return handler;
522             }
523
524             handler = null;
525         }
526
527         if (handler == null) {
528
529             CmsMessageContainer message = Messages.get().container(
530                 Messages.ERR_IMPORTEXPORT_ERROR_NO_HANDLER_FOUND_1,
531                 importFile);
532             if (LOG.isDebugEnabled()) {
533                 LOG.debug(message.key());
534             }
535
536             throw new CmsImportExportException(message);
537         }
538
539         return null;
540     }
541
542     /**
543      * Returns the list of configured import/export handlers.<p>
544      *
545      * @return the list of configured import/export handlers
546      */

547     public List JavaDoc getImportExportHandlers() {
548
549         return m_importExportHandlers;
550     }
551
552     /**
553      * Returns the configured principal group translations.<p>
554      *
555      * @return the configured principal group translations
556      */

557     public Map JavaDoc getImportGroupTranslations() {
558
559         return m_importGroupTranslations;
560     }
561
562     /**
563      * Returns the configured principal user translations.<p>
564      *
565      * @return the configured principal user translations
566      */

567     public Map JavaDoc getImportUserTranslations() {
568
569         return m_importUserTranslations;
570     }
571
572     /**
573      * Returns the configured import version class names.<p>
574      *
575      * @return the configured import version class names
576      */

577     public List JavaDoc getImportVersionClasses() {
578
579         return m_importVersionClasses;
580     }
581
582     /**
583      * Returns the URL of a 4.x OpenCms app. (e.g. http://localhost:8080/opencms/opencms/)
584      * from which content was exported.<p>
585      *
586      * This setting is required to import content of 4.x OpenCms apps. correct into 5.x OpenCms apps.<p>
587      *
588      * @return the webAppUrl.
589      */

590     public String JavaDoc getOldWebAppUrl() {
591
592         return m_webAppUrl;
593     }
594
595     /**
596      * Checks if the current user has permissions to import data into the Cms,
597      * and if so, creates a new import handler instance that imports the data.<p>
598      *
599      * @param cms the current OpenCms context object
600      * @param importFile the name (absolute path) of the resource (zipfile or folder) to be imported
601      * @param importPath the name (absolute path) of the destination folder in the Cms if required, or null
602      * @param report a Cms report to print log messages
603      *
604      * @throws CmsRoleViolationException if the current user is not allowed to import the OpenCms database
605      * @throws CmsImportExportException if operation was not successful
606      * @throws CmsXmlException if the manifest of the import could not be unmarshalled
607      * @throws CmsException in case of errors accessing the VFS
608      *
609      * @see I_CmsImportExportHandler
610      */

611     public void importData(CmsObject cms, String JavaDoc importFile, String JavaDoc importPath, I_CmsReport report)
612     throws CmsImportExportException, CmsXmlException, CmsRoleViolationException, CmsException {
613
614         // check the required role permissions
615
cms.checkRole(CmsRole.IMPORT_DATABASE);
616
617         try {
618             OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_CLEAR_CACHES, Collections.EMPTY_MAP));
619             I_CmsImportExportHandler handler = getImportExportHandler(importFile);
620             handler.importData(cms, importFile, importPath, report);
621         } finally {
622             OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_CLEAR_CACHES, Collections.EMPTY_MAP));
623         }
624     }
625
626     /**
627      * Checks if colliding resources should be overwritten during the import.<p>
628      *
629      * @return true, if colliding resources should be overwritten during the import
630      * @see #setOverwriteCollidingResources(boolean)
631      */

632     public boolean overwriteCollidingResources() {
633
634         return m_overwriteCollidingResources;
635     }
636
637     /**
638      * Sets if imported pages should be converted into XML pages.<p>
639      *
640      * @param convertToXmlPage true, if imported pages should be converted into XML pages.
641      */

642     public void setConvertToXmlPage(boolean convertToXmlPage) {
643
644         if (LOG.isDebugEnabled()) {
645             LOG.debug(Messages.get().getBundle().key(
646                 Messages.LOG_IMPORTEXPORT_SET_CONVERT_PARAMETER_1,
647                 Boolean.toString(convertToXmlPage)));
648         }
649         m_convertToXmlPage = convertToXmlPage;
650     }
651
652     /**
653      * Sets if imported pages should be converted into XML pages.<p>
654      *
655      * @param convertToXmlPage <code>"true"</code>, if imported pages should be converted into XML pages.
656      */

657     public void setConvertToXmlPage(String JavaDoc convertToXmlPage) {
658
659         setConvertToXmlPage(Boolean.valueOf(convertToXmlPage).booleanValue());
660     }
661
662     /**
663      * Sets the URL of a 4.x OpenCms app. (e.g. http://localhost:8080/opencms/opencms/)
664      * from which content was exported.<p>
665      *
666      * This setting is required to import content of 4.x OpenCms apps. correct into 5.x OpenCms apps.<p>
667      *
668      * @param webAppUrl a URL of the a OpenCms app. (e.g. http://localhost:8080/opencms/opencms/)
669      */

670     public void setOldWebAppUrl(String JavaDoc webAppUrl) {
671
672         if (LOG.isDebugEnabled()) {
673             LOG.debug(Messages.get().getBundle().key(Messages.LOG_IMPORTEXPORT_SET_OLD_WEBAPP_URL_1, webAppUrl));
674         }
675         m_webAppUrl = webAppUrl;
676     }
677
678     /**
679      * Sets whether colliding resources should be overwritten during the import for a
680      * specified import implementation.<p>
681      *
682      * v1 and v2 imports (without resource UUIDs in the manifest) *MUST* overwrite colliding
683      * resources. Don't forget to set this flag back to it's original value in v1 and v2
684      * import implementations!<p>
685      *
686      * This flag must be set to false to force imports > v2 to move colliding resources to
687      * /system/lost-found/.<p>
688      *
689      * The import implementation has to take care to set this flag correct!<p>
690      *
691      * @param overwriteCollidingResources true if colliding resources should be overwritten during the import
692      */

693     public void setOverwriteCollidingResources(boolean overwriteCollidingResources) {
694
695         if (LOG.isDebugEnabled()) {
696             LOG.debug(Messages.get().getBundle().key(
697                 Messages.LOG_IMPORTEXPORT_SET_OVERWRITE_PARAMETER_1,
698                 Boolean.toString(overwriteCollidingResources)));
699         }
700         m_overwriteCollidingResources = overwriteCollidingResources;
701     }
702
703     /**
704      * @see CmsImportExportManager#setOverwriteCollidingResources(boolean)
705      *
706      * @param overwriteCollidingResources <code>"true"</code> if colliding resources should be overwritten during the import
707      */

708     public void setOverwriteCollidingResources(String JavaDoc overwriteCollidingResources) {
709
710         setOverwriteCollidingResources(Boolean.valueOf(overwriteCollidingResources).booleanValue());
711     }
712
713     /**
714      * Returns the translated name for the given group name.<p>
715      *
716      * If no matching name is found, the given group name is returned.<p>
717      *
718      * @param name the group name to translate
719      * @return the translated name for the given group name
720      */

721     public String JavaDoc translateGroup(String JavaDoc name) {
722
723         if (m_importGroupTranslations == null) {
724             return name;
725         }
726         String JavaDoc match = (String JavaDoc)m_importGroupTranslations.get(name);
727         if (match != null) {
728             return match;
729         } else {
730             return name;
731         }
732     }
733
734     /**
735      * Returns the translated name for the given user name.<p>
736      *
737      * If no matching name is found, the given user name is returned.<p>
738      *
739      * @param name the user name to translate
740      * @return the translated name for the given user name
741      */

742     public String JavaDoc translateUser(String JavaDoc name) {
743
744         if (m_importUserTranslations == null) {
745             return name;
746         }
747         String JavaDoc match = (String JavaDoc)m_importUserTranslations.get(name);
748         if (match != null) {
749             return match;
750         } else {
751             return name;
752         }
753     }
754
755     /**
756      * @see java.lang.Object#finalize()
757      */

758     protected void finalize() throws Throwable JavaDoc {
759
760         try {
761             if (m_immutableResources != null) {
762                 m_immutableResources.clear();
763             }
764             m_immutableResources = null;
765
766             if (m_ignoredProperties != null) {
767                 m_ignoredProperties.clear();
768             }
769             m_ignoredProperties = null;
770         } catch (Throwable JavaDoc t) {
771             // noop
772
} finally {
773             super.finalize();
774         }
775     }
776 }
Popular Tags