KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/importexport/CmsVfsImportExportHandler.java,v $
3  * Date : $Date: 2006/03/27 14:52:54 $
4  * Version: $Revision: 1.21 $
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.file.CmsObject;
35 import org.opencms.main.CmsIllegalArgumentException;
36 import org.opencms.report.I_CmsReport;
37 import org.opencms.security.CmsRoleViolationException;
38 import org.opencms.util.CmsStringUtil;
39 import org.opencms.xml.CmsXmlException;
40
41 import java.util.Collections JavaDoc;
42 import java.util.List JavaDoc;
43
44 import org.dom4j.Document;
45 import org.dom4j.Element;
46
47 /**
48  * Import/export handler implementation for VFS data.<p>
49  *
50  * @author Thomas Weckert
51  *
52  * @version $Revision: 1.21 $
53  *
54  * @since 6.0.0
55  */

56 public class CmsVfsImportExportHandler implements I_CmsImportExportHandler {
57
58     /** Timestamp to limit the resources to be exported by date.<p> */
59     private long m_contentAge;
60
61     /** The description of this import/export handler.<p> */
62     private String JavaDoc m_description;
63
64     /** The VFS paths to be exported.<p> */
65     private List JavaDoc m_exportPaths;
66
67     /** Boolean flag to decide whether user/group data should be exported or not.<p> */
68     private boolean m_exportUserdata;
69
70     /** Boolean flag to decide whether webuser data should be exported or not.<p> */
71     private boolean m_exportWebusers;
72
73     /** The name of the export file in the real file system.<p> */
74     private String JavaDoc m_fileName;
75
76     /** Boolean flag to decide whether VFS resources under /system/ should be exported or not.<p> */
77     private boolean m_includeSystem;
78
79     /** Boolean flag to decide whether unchanged resources should be exported or not.<p> */
80     private boolean m_includeUnchanged;
81
82     /** Boolean flag to indicate if the folders are exported recursively or not. */
83     private boolean m_recursive;
84
85     /**
86      * Creates a new VFS import/export handler.<p>
87      */

88     public CmsVfsImportExportHandler() {
89
90         super();
91         m_description = Messages.get().getBundle().key(Messages.GUI_CMSIMPORTHANDLER_DEFAULT_DESC_0);
92         m_includeSystem = false;
93         m_includeUnchanged = true;
94         m_exportUserdata = true;
95         m_exportWebusers = false;
96         m_exportPaths = Collections.EMPTY_LIST;
97         m_recursive = true;
98     }
99
100     /**
101      * @see org.opencms.importexport.I_CmsImportExportHandler#exportData(org.opencms.file.CmsObject, org.opencms.report.I_CmsReport)
102      */

103     public void exportData(CmsObject cms, I_CmsReport report)
104     throws CmsImportExportException, CmsRoleViolationException {
105
106         report.println(Messages.get().container(Messages.RPT_EXPORT_DB_BEGIN_0), I_CmsReport.FORMAT_HEADLINE);
107         new CmsExport(
108             cms,
109             getFileName(),
110             getExportPaths(),
111             isIncludeSystem(),
112             isIncludeUnchanged(),
113             null,
114             isExportUserdata(),
115             isExportWebusers(),
116             getContentAge(),
117             report,
118             isRecursive());
119         report.println(Messages.get().container(Messages.RPT_EXPORT_DB_END_0), I_CmsReport.FORMAT_HEADLINE);
120     }
121
122     /**
123      * Returns the timestamp to limit the resources to be exported by date.<p>
124      *
125      * Only resources that have been modified after this date will be exported.<p>
126      *
127      * @return the timestamp to limit the resources to be exported by date
128      */

129     public long getContentAge() {
130
131         return m_contentAge;
132     }
133
134     /**
135      * @see org.opencms.importexport.I_CmsImportExportHandler#getDescription()
136      */

137     public String JavaDoc getDescription() {
138
139         return m_description;
140     }
141
142     /**
143      * Returns the list with VFS paths to be exported.<p>
144      *
145      * @return the list with VFS paths to be exported
146      */

147     public List JavaDoc getExportPaths() {
148
149         return m_exportPaths;
150     }
151
152     /**
153      * Returns the name of the export file in the real file system.<p>
154      *
155      * @return the name of the export file in the real file system
156      */

157     public String JavaDoc getFileName() {
158
159         return m_fileName;
160     }
161
162     /**
163      * @see org.opencms.importexport.I_CmsImportExportHandler#importData(org.opencms.file.CmsObject, java.lang.String, java.lang.String, org.opencms.report.I_CmsReport)
164      */

165     public synchronized void importData(CmsObject cms, String JavaDoc importFile, String JavaDoc importPath, I_CmsReport report)
166     throws CmsImportExportException, CmsXmlException, CmsRoleViolationException {
167
168         report.println(Messages.get().container(Messages.RPT_IMPORT_DB_BEGIN_0), I_CmsReport.FORMAT_HEADLINE);
169         CmsImport vfsImport = new CmsImport(cms, importFile, importPath, report);
170         vfsImport.importResources();
171         report.println(Messages.get().container(Messages.RPT_IMPORT_DB_END_0), I_CmsReport.FORMAT_HEADLINE);
172     }
173
174     /**
175      * Returns the boolean flag to decide whether user/group data should be exported or not.<p>
176      *
177      * @return true, if user/group data should be exported
178      */

179     public boolean isExportUserdata() {
180
181         return m_exportUserdata;
182     }
183
184     /**
185      * Returns the boolean flag to decide whether webusers should be exported or not.<p>
186      *
187      * @return true, if webusers should be exported
188      */

189     public boolean isExportWebusers() {
190
191         return m_exportWebusers;
192     }
193
194     /**
195      * Returns the boolean flag to decide whether VFS resources under /system/ should be exported or not.<p>
196      *
197      * @return true, if VFS resources under /system/ should not be exported
198      */

199     public boolean isIncludeSystem() {
200
201         return m_includeSystem;
202     }
203
204     /**
205      * Returns the boolean flag to decide whether unchanged resources should be exported or not.<p>
206      *
207      * @return true, if unchanged resources should not be exported
208      */

209     public boolean isIncludeUnchanged() {
210
211         return m_includeUnchanged;
212     }
213
214     /**
215      * Returns the recursive flag.<p>
216      *
217      * @return the recursive flag
218      */

219     public boolean isRecursive() {
220
221         return m_recursive;
222     }
223
224     /**
225      * @see org.opencms.importexport.I_CmsImportExportHandler#matches(org.dom4j.Document)
226      */

227     public boolean matches(Document manifest) {
228
229         Element rootElement = manifest.getRootElement();
230
231         boolean hasModuleNode = (rootElement.selectNodes("./module/name").size() > 0);
232         boolean hasFileNodes = (rootElement.selectNodes("./files/file").size() > 0);
233
234         return (!hasModuleNode && hasFileNodes);
235     }
236
237     /**
238      * Sets the timestamp to limit the resources to be exported by date.<p>
239      *
240      * Only resources that have been modified after this date will be exported.<p>
241      *
242      * @param contentAge the timestamp to limit the resources to be exported by date
243      */

244     public void setContentAge(long contentAge) {
245
246         if (contentAge < 0) {
247             String JavaDoc ageString = Long.toString(contentAge);
248             throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_BAD_CONTENT_AGE_1, ageString));
249         }
250         m_contentAge = contentAge;
251     }
252
253     /**
254      * @see org.opencms.importexport.I_CmsImportExportHandler#setDescription(java.lang.String)
255      */

256     public void setDescription(String JavaDoc description) {
257
258         m_description = description;
259     }
260
261     /**
262      * Sets the list with VFS paths to be exported.<p>
263      *
264      * @param exportPaths the list with VFS paths to be exported
265      */

266     public void setExportPaths(List JavaDoc exportPaths) {
267
268         m_exportPaths = exportPaths;
269     }
270
271     /**
272      * Sets the boolean flag to decide whether user/group data should be exported or not.<p>
273      *
274      * @param exportUserdata true, if user/group data should not be exported
275      */

276     public void setExportUserdata(boolean exportUserdata) {
277
278         m_exportUserdata = exportUserdata;
279     }
280
281     /**
282      * Sets the boolean flag to decide whether webusers should be exported or not.<p>
283      *
284      * @param exportWebusers true, if webusers should not be exported
285      */

286     public void setExportWebusers(boolean exportWebusers) {
287
288         m_exportWebusers = exportWebusers;
289     }
290
291     /**
292      * Sets the name of the export file in the real file system.<p>
293      *
294      * @param fileName the name of the export file in the real file system
295      */

296     public void setFileName(String JavaDoc fileName) {
297
298         if (CmsStringUtil.isEmpty(fileName) || !fileName.trim().equals(fileName)) {
299             throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_BAD_FILE_NAME_1, fileName));
300         }
301         m_fileName = fileName;
302     }
303
304     /**
305      * Sets the boolean flag to decide whether VFS resources under /system/ should be exported or not.<p>
306      *
307      * @param excludeSystem true, if VFS resources under /system/ should not be exported
308      */

309     public void setIncludeSystem(boolean excludeSystem) {
310
311         m_includeSystem = excludeSystem;
312     }
313
314     /**
315      * Sets the boolean flag to decide whether unchanged resources should be exported or not.<p>
316      *
317      * @param excludeUnchanged true, if unchanged resources should not be exported
318      */

319     public void setIncludeUnchanged(boolean excludeUnchanged) {
320
321         m_includeUnchanged = excludeUnchanged;
322     }
323
324     /**
325      * Sets the recursive flag.<p>
326      *
327      * @param recursive the recursive flag to set
328      */

329     public void setRecursive(boolean recursive) {
330
331         m_recursive = recursive;
332     }
333
334     /**
335      * @see java.lang.Object#finalize()
336      */

337     protected void finalize() throws Throwable JavaDoc {
338
339         try {
340             if (m_exportPaths != null) {
341                 m_exportPaths.clear();
342             }
343             m_exportPaths = null;
344         } catch (Exception JavaDoc e) {
345             // noop
346
} finally {
347             super.finalize();
348         }
349     }
350 }
351
Popular Tags