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