001: /*
002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/importexport/CmsImport.java,v $
003: * Date : $Date: 2008-02-27 12:05:48 $
004: * Version: $Revision: 1.48 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.importexport;
033:
034: import org.opencms.file.CmsObject;
035: import org.opencms.main.CmsEvent;
036: import org.opencms.main.I_CmsEventListener;
037: import org.opencms.main.OpenCms;
038: import org.opencms.report.I_CmsReport;
039: import org.opencms.security.CmsRole;
040: import org.opencms.security.CmsRoleViolationException;
041: import org.opencms.xml.CmsXmlException;
042:
043: import java.util.Collections;
044: import java.util.Iterator;
045: import java.util.List;
046:
047: /**
048: * Holds the functionality to import resources from the file system
049: * or a zip file into the OpenCms VFS.<p>
050: *
051: * @author Andreas Zahner
052: * @author Alexander Kandzior
053: * @author Michael Emmerich
054: * @author Thomas Weckert
055: *
056: * @version $Revision: 1.48 $
057: *
058: * @since 6.0.0
059: */
060: public class CmsImport {
061:
062: /** The cms context. */
063: protected CmsObject m_cms;
064:
065: /** The output report. */
066: protected I_CmsReport m_report;
067:
068: /** Stores all import interface implementations .*/
069: protected List m_importImplementations;
070:
071: /**
072: * Constructs a new uninitialized import, required for special subclass data import.<p>
073: */
074: public CmsImport() {
075:
076: // empty
077: super ();
078: }
079:
080: /**
081: * Constructs a new import object which imports the resources from an OpenCms
082: * export zip file or a folder in the "real" file system.<p>
083: *
084: * @param cms the cms context
085: * @param report the output report
086: *
087: * @throws CmsRoleViolationException if the current user dies not have role permissions to import the database
088: */
089: public CmsImport(CmsObject cms, I_CmsReport report)
090: throws CmsRoleViolationException {
091:
092: // check the role permissions
093: OpenCms.getRoleManager().checkRole(cms,
094: CmsRole.DATABASE_MANAGER);
095:
096: // set member variables
097: m_importImplementations = OpenCms.getImportExportManager()
098: .getImportVersionClasses();
099: m_cms = cms;
100: m_report = report;
101: }
102:
103: /**
104: * Imports the resources and writes them to the cms VFS, even if there
105: * already exist files with the same name.<p>
106: *
107: * @param parameters the import parameters
108: *
109: * @throws CmsImportExportException if something goes wrong
110: * @throws CmsXmlException if the manifest of the import file could not be unmarshalled
111: */
112: public void importData(CmsImportParameters parameters)
113: throws CmsImportExportException, CmsXmlException {
114:
115: boolean run = false;
116:
117: try {
118: // now find the correct import implementation
119: Iterator i = m_importImplementations.iterator();
120: while (i.hasNext()) {
121: I_CmsImport importVersion = (I_CmsImport) i.next();
122: if (importVersion.matches(parameters)) {
123: m_report.println(
124: Messages.get().container(
125: Messages.RPT_IMPORT_VERSION_1,
126: String.valueOf(importVersion
127: .getVersion())),
128: I_CmsReport.FORMAT_NOTE);
129: // this is the correct import version, so call it for the import process
130: importVersion.importData(m_cms, m_report,
131: parameters);
132: run = true;
133: break;
134: }
135: }
136: if (!run) {
137: m_report.println(Messages.get().container(
138: Messages.RPT_IMPORT_DB_NO_CLASS_0),
139: I_CmsReport.FORMAT_WARNING);
140: }
141: } finally {
142: OpenCms.fireCmsEvent(new CmsEvent(
143: I_CmsEventListener.EVENT_CLEAR_OFFLINE_CACHES,
144: Collections.EMPTY_MAP));
145: }
146: }
147: }
|