001: /*
002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/importexport/CmsVfsImportExportHandler.java,v $
003: * Date : $Date: 2008-02-27 12:05:48 $
004: * Version: $Revision: 1.26 $
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.CmsException;
036: import org.opencms.main.CmsIllegalArgumentException;
037: import org.opencms.module.CmsModuleXmlHandler;
038: import org.opencms.report.I_CmsReport;
039: import org.opencms.security.CmsRoleViolationException;
040: import org.opencms.util.CmsStringUtil;
041: import org.opencms.xml.CmsXmlException;
042:
043: import java.util.List;
044:
045: import org.dom4j.Document;
046: import org.dom4j.Element;
047:
048: /**
049: * Import/export handler implementation for VFS data.<p>
050: *
051: * @author Thomas Weckert
052: *
053: * @version $Revision: 1.26 $
054: *
055: * @since 6.0.0
056: */
057: public class CmsVfsImportExportHandler implements
058: I_CmsImportExportHandler {
059:
060: /** The description of this import/export handler. */
061: private long m_contentAge;
062:
063: /** The description of this import/export handler.<p> */
064: private String m_description;
065:
066: /** The export parameters. */
067: private CmsExportParameters m_exportParams;
068:
069: /** The VFS paths to be exported. */
070: private List m_exportPaths;
071:
072: /** The name of the export file in the real file system. */
073: private boolean m_exportUserdata;
074:
075: /** The name of the export file in the real file system.<p> */
076: private String m_fileName;
077:
078: /** The import parameters. */
079: private CmsImportParameters m_importParams;
080:
081: /** Boolean flag to decide whether VFS resources under /system/ should be exported or not. */
082: private boolean m_includeSystem;
083:
084: /** Boolean flag to decide whether unchanged resources should be exported or not. */
085: private boolean m_includeUnchanged;
086:
087: /** Boolean flag to indicate that only the resources of the current project should be exported. */
088: private boolean m_projectOnly;
089:
090: /** Boolean flag to indicate if the folders are exported recursively or not. */
091: private boolean m_recursive;
092:
093: /**
094: * Creates a new VFS import/export handler.<p>
095: */
096: public CmsVfsImportExportHandler() {
097:
098: super ();
099: m_description = Messages.get().getBundle().key(
100: Messages.GUI_CMSIMPORTHANDLER_DEFAULT_DESC_0);
101: }
102:
103: /**
104: * @see org.opencms.importexport.I_CmsImportExportHandler#exportData(org.opencms.file.CmsObject, org.opencms.report.I_CmsReport)
105: */
106: public void exportData(CmsObject cms, I_CmsReport report)
107: throws CmsImportExportException, CmsRoleViolationException {
108:
109: CmsExportParameters parameters = getExportParams();
110: if (parameters == null) {
111: parameters = new CmsExportParameters(getFileName(), null,
112: true, isExportUserdata(), false, getExportPaths(),
113: isIncludeSystem(), isIncludeUnchanged(),
114: getContentAge(), isRecursive(), isProjectOnly());
115: }
116:
117: report.println(Messages.get().container(
118: Messages.RPT_EXPORT_DB_BEGIN_0),
119: I_CmsReport.FORMAT_HEADLINE);
120: new CmsExport(cms, report).exportData(parameters);
121: report.println(Messages.get().container(
122: Messages.RPT_EXPORT_DB_END_0),
123: I_CmsReport.FORMAT_HEADLINE);
124: }
125:
126: /**
127: * Returns the timestamp to limit the resources to be exported by date.<p>
128: *
129: * Only resources that have been modified after this date will be exported.<p>
130: *
131: * @return the timestamp to limit the resources to be exported by date
132: *
133: * @deprecated use {@link #setExportParams(CmsExportParameters)} instead
134: */
135: public long getContentAge() {
136:
137: return m_contentAge;
138: }
139:
140: /**
141: * @see org.opencms.importexport.I_CmsImportExportHandler#getDescription()
142: */
143: public String getDescription() {
144:
145: return m_description;
146: }
147:
148: /**
149: * Returns the export parameters.<p>
150: *
151: * @return the export parameters
152: */
153: public CmsExportParameters getExportParams() {
154:
155: return m_exportParams;
156: }
157:
158: /**
159: * Returns the list with VFS paths to be exported.<p>
160: *
161: * @return the list with VFS paths to be exported
162: *
163: * @deprecated use {@link #setExportParams(CmsExportParameters)} instead
164: */
165: public List getExportPaths() {
166:
167: return m_exportPaths;
168: }
169:
170: /**
171: * Returns the name of the export file in the real file system.<p>
172: *
173: * @return the name of the export file in the real file system
174: *
175: * @deprecated use {@link #setExportParams(CmsExportParameters)} instead
176: */
177: public String getFileName() {
178:
179: return m_fileName;
180: }
181:
182: /**
183: * Returns the import parameters.<p>
184: *
185: * @return the import parameters
186: */
187: public CmsImportParameters getImportParameters() {
188:
189: return m_importParams;
190: }
191:
192: /**
193: * @see org.opencms.importexport.I_CmsImportExportHandler#importData(CmsObject, I_CmsReport)
194: */
195: public synchronized void importData(CmsObject cms,
196: I_CmsReport report) throws CmsImportExportException,
197: CmsXmlException, CmsRoleViolationException {
198:
199: report.println(Messages.get().container(
200: Messages.RPT_IMPORT_DB_BEGIN_0),
201: I_CmsReport.FORMAT_HEADLINE);
202:
203: CmsImport vfsImport = new CmsImport(cms, report);
204: vfsImport.importData(getImportParameters());
205:
206: report.println(Messages.get().container(
207: Messages.RPT_IMPORT_DB_END_0),
208: I_CmsReport.FORMAT_HEADLINE);
209: }
210:
211: /**
212: * @see org.opencms.importexport.I_CmsImportExportHandler#importData(org.opencms.file.CmsObject, java.lang.String, java.lang.String, org.opencms.report.I_CmsReport)
213: *
214: * @deprecated use {@link #importData(CmsObject, I_CmsReport)} instead
215: */
216: public void importData(CmsObject cms, String importFile,
217: String importPath, I_CmsReport report)
218: throws CmsXmlException, CmsImportExportException,
219: CmsRoleViolationException, CmsException {
220:
221: CmsImportParameters parameters = new CmsImportParameters(
222: importFile, importPath, true);
223:
224: setImportParameters(parameters);
225:
226: importData(cms, report);
227: }
228:
229: /**
230: * Returns the boolean flag to decide whether user/group data should be exported or not.<p>
231: *
232: * @return true, if user/group data should be exported
233: *
234: * @deprecated use {@link #setExportParams(CmsExportParameters)} instead
235: */
236: public boolean isExportUserdata() {
237:
238: return m_exportUserdata;
239: }
240:
241: /**
242: * Returns the boolean flag to decide whether VFS resources under /system/ should be exported or not.<p>
243: *
244: * @return true, if VFS resources under /system/ should not be exported
245: *
246: * @deprecated use {@link #setExportParams(CmsExportParameters)} instead
247: */
248: public boolean isIncludeSystem() {
249:
250: return m_includeSystem;
251: }
252:
253: /**
254: * Returns the boolean flag to decide whether unchanged resources should be exported or not.<p>
255: *
256: * @return true, if unchanged resources should not be exported
257: *
258: * @deprecated use {@link #setExportParams(CmsExportParameters)} instead
259: */
260: public boolean isIncludeUnchanged() {
261:
262: return m_includeUnchanged;
263: }
264:
265: /**
266: * Returns the projectOnly.<p>
267: *
268: * @return the projectOnly
269: *
270: * @deprecated use {@link #setExportParams(CmsExportParameters)} instead
271: */
272: public boolean isProjectOnly() {
273:
274: return m_projectOnly;
275: }
276:
277: /**
278: * Returns the recursive flag.<p>
279: *
280: * @return the recursive flag
281: *
282: * @deprecated use {@link #setExportParams(CmsExportParameters)} instead
283: */
284: public boolean isRecursive() {
285:
286: return m_recursive;
287: }
288:
289: /**
290: * @see org.opencms.importexport.I_CmsImportExportHandler#matches(org.dom4j.Document)
291: */
292: public boolean matches(Document manifest) {
293:
294: Element rootElement = manifest.getRootElement();
295: boolean hasModuleNode = (rootElement.selectNodes(
296: "./" + CmsModuleXmlHandler.N_MODULE + "/"
297: + CmsModuleXmlHandler.N_NAME).size() > 0);
298: boolean hasInfoNode = (rootElement.selectNodes(
299: "./" + CmsImportExportManager.N_INFO).size() == 1);
300:
301: return (!hasModuleNode && hasInfoNode);
302: }
303:
304: /**
305: * Sets the timestamp to limit the resources to be exported by date.<p>
306: *
307: * Only resources that have been modified after this date will be exported.<p>
308: *
309: * @param contentAge the timestamp to limit the resources to be exported by date
310: *
311: * @deprecated use {@link #setExportParams(CmsExportParameters)} instead
312: */
313: public void setContentAge(long contentAge) {
314:
315: if (contentAge < 0) {
316: String ageString = Long.toString(contentAge);
317: throw new CmsIllegalArgumentException(Messages.get()
318: .container(Messages.ERR_BAD_CONTENT_AGE_1,
319: ageString));
320: }
321: m_contentAge = contentAge;
322: }
323:
324: /**
325: * @see org.opencms.importexport.I_CmsImportExportHandler#setDescription(java.lang.String)
326: */
327: public void setDescription(String description) {
328:
329: m_description = description;
330: }
331:
332: /**
333: * Sets the export parameters.<p>
334: *
335: * @param exportParams the parameters to set
336: */
337: public void setExportParams(CmsExportParameters exportParams) {
338:
339: m_exportParams = exportParams;
340: }
341:
342: /**
343: * Sets the list with VFS paths to be exported.<p>
344: *
345: * @param exportPaths the list with VFS paths to be exported
346: *
347: * @deprecated use {@link #setExportParams(CmsExportParameters)} instead
348: */
349: public void setExportPaths(List exportPaths) {
350:
351: m_exportPaths = exportPaths;
352: }
353:
354: /**
355: * Sets the boolean flag to decide whether user/group data should be exported or not.<p>
356: *
357: * @param exportUserdata true, if user/group data should not be exported
358: *
359: * @deprecated use {@link #setExportParams(CmsExportParameters)} instead
360: */
361: public void setExportUserdata(boolean exportUserdata) {
362:
363: m_exportUserdata = exportUserdata;
364: }
365:
366: /**
367: * Sets the name of the export file in the real file system.<p>
368: *
369: * @param fileName the name of the export file in the real file system
370: *
371: * @deprecated use {@link #setExportParams(CmsExportParameters)} instead
372: */
373: public void setFileName(String fileName) {
374:
375: if (CmsStringUtil.isEmpty(fileName)
376: || !fileName.trim().equals(fileName)) {
377: throw new CmsIllegalArgumentException(Messages.get()
378: .container(Messages.ERR_BAD_FILE_NAME_1, fileName));
379: }
380: m_fileName = fileName;
381: }
382:
383: /**
384: * Sets the import parameters.<p>
385: *
386: * @param importParams the parameters to set
387: */
388: public void setImportParameters(CmsImportParameters importParams) {
389:
390: m_importParams = importParams;
391: }
392:
393: /**
394: * Sets the boolean flag to decide whether VFS resources under /system/ should be exported or not.<p>
395: *
396: * @param excludeSystem true, if VFS resources under /system/ should not be exported
397: *
398: * @deprecated use {@link #setExportParams(CmsExportParameters)} instead
399: */
400: public void setIncludeSystem(boolean excludeSystem) {
401:
402: m_includeSystem = excludeSystem;
403: }
404:
405: /**
406: * Sets the boolean flag to decide whether unchanged resources should be exported or not.<p>
407: *
408: * @param excludeUnchanged true, if unchanged resources should not be exported
409: *
410: * @deprecated use {@link #setExportParams(CmsExportParameters)} instead
411: */
412: public void setIncludeUnchanged(boolean excludeUnchanged) {
413:
414: m_includeUnchanged = excludeUnchanged;
415: }
416:
417: /**
418: * Sets the projectOnly.<p>
419: *
420: * @param projectOnly the projectOnly to set
421: *
422: * @deprecated use {@link #setExportParams(CmsExportParameters)} instead
423: */
424: public void setProjectOnly(boolean projectOnly) {
425:
426: m_projectOnly = projectOnly;
427: }
428:
429: /**
430: * Sets the recursive flag.<p>
431: *
432: * @param recursive the recursive flag to set
433: *
434: * @deprecated use {@link #setExportParams(CmsExportParameters)} instead
435: */
436: public void setRecursive(boolean recursive) {
437:
438: m_recursive = recursive;
439: }
440: }
|