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.main.CmsIllegalArgumentException; 031import org.opencms.module.CmsModule.ExportMode; 032import org.opencms.util.CmsStringUtil; 033 034import java.util.Collections; 035import java.util.List; 036 037import org.dom4j.Element; 038 039/** 040 * Export parameters.<p> 041 * 042 * @since 7.0.4 043 */ 044public class CmsExportParameters { 045 046 /** Only resources modified after this time stamp will be exported. */ 047 private long m_contentAge; 048 049 /** If the account data should be exported. */ 050 private boolean m_exportAccountData; 051 052 /** Indicates if the resources are exported in one export .ZIP file (the default) or as individual files. */ 053 private boolean m_exportAsFiles; 054 055 /** If the project data should be exported. */ 056 private boolean m_exportProjectData; 057 058 /** If the resource data should be exported. */ 059 private boolean m_exportResourceData = true; 060 061 /** If the system folder should be included in the export.*/ 062 private boolean m_includeSystemFolder = true; 063 064 /** If unchanged files should be included in the export.*/ 065 private boolean m_includeUnchangedResources = true; 066 067 /** If set, only resources belonging to the current project will be exported. */ 068 private boolean m_inProject; 069 070 /** The module informations if to export a module. */ 071 private Element m_moduleInfo; 072 073 /** The file path, should be a zip file. */ 074 private String m_path; 075 076 /** If the resources should be recursively exported. */ 077 private boolean m_recursive = true; 078 079 /** The resources to export.*/ 080 private List<String> m_resources; 081 082 /** If set, the manifest.xml file will be generated with dtd info. */ 083 private boolean m_xmlValidation; 084 085 /** The export mode that should be used for the export. */ 086 private ExportMode m_exportMode = ExportMode.DEFAULT; 087 088 /** Resources for with meta data should be exported, even if not in the resources to export. 089 * That are super-folders of exported resources, where meta data should be kept in the export. 090 */ 091 private List<String> m_additionalResourcesToExportWithMetaData; 092 093 /** 094 * Constructor.<p> 095 */ 096 public CmsExportParameters() { 097 098 // empty constructor for the database export dialog 099 } 100 101 /** 102 * Constructor.<p> 103 * 104 * @param exportFile the zip file to export to 105 * @param moduleElement module informations in a Node for module export 106 * @param exportResourceData if the resource data has also to be exported 107 * @param exportUserdata if the account data has also to be exported 108 * @param exportProjectData if the project data has also to be exported 109 * @param resourcesToExport the paths of folders and files to export 110 * @param includeSystem if <code>true</code>, the system folder is included 111 * @param includeUnchanged <code>true</code>, if unchanged files should be included 112 * @param contentAge export contents changed after this date/time 113 * @param recursive recursive flag 114 * @param inProject if only resources in the current project are exported 115 * @param exportMode the export mode to use 116 */ 117 public CmsExportParameters( 118 String exportFile, 119 Element moduleElement, 120 boolean exportResourceData, 121 boolean exportUserdata, 122 boolean exportProjectData, 123 List<String> resourcesToExport, 124 boolean includeSystem, 125 boolean includeUnchanged, 126 long contentAge, 127 boolean recursive, 128 boolean inProject, 129 ExportMode exportMode) { 130 131 setPath(exportFile); 132 setResources(resourcesToExport); 133 setIncludeSystemFolder(includeSystem); 134 setIncludeUnchangedResources(includeUnchanged); 135 setModuleInfo(moduleElement); 136 setExportAccountData(exportUserdata); 137 setContentAge(contentAge); 138 setRecursive(recursive); 139 setExportResourceData(exportResourceData); 140 setExportProjectData(exportProjectData); 141 setInProject(inProject); 142 setExportAsFiles(false); 143 setExportMode(exportMode); 144 setAdditionalResourcesToExportWithMetaData(null); 145 } 146 147 /** 148 * Constructor.<p> 149 * 150 * @param exportFile the zip file to export to 151 * @param moduleElement module informations in a Node for module export 152 * @param exportResourceData if the resource data has also to be exported 153 * @param exportUserdata if the account data has also to be exported 154 * @param exportProjectData if the project data has also to be exported 155 * @param resourcesToExport the paths of folders and files to export 156 * @param includeSystem if <code>true</code>, the system folder is included 157 * @param includeUnchanged <code>true</code>, if unchanged files should be included 158 * @param contentAge export contents changed after this date/time 159 * @param recursive recursive flag 160 * @param inProject if only resources in the current project are exported 161 * @param exportMode the export mode to use 162 * @param additionalResourcesToExportWithMetaData the list of export-site relative paths of folders/files for 163 * which meta data should be exported, even if they do not belong the the resourcesToExport. 164 */ 165 public CmsExportParameters( 166 String exportFile, 167 Element moduleElement, 168 boolean exportResourceData, 169 boolean exportUserdata, 170 boolean exportProjectData, 171 List<String> resourcesToExport, 172 boolean includeSystem, 173 boolean includeUnchanged, 174 long contentAge, 175 boolean recursive, 176 boolean inProject, 177 ExportMode exportMode, 178 List<String> additionalResourcesToExportWithMetaData) { 179 180 setPath(exportFile); 181 setResources(resourcesToExport); 182 setIncludeSystemFolder(includeSystem); 183 setIncludeUnchangedResources(includeUnchanged); 184 setModuleInfo(moduleElement); 185 setExportAccountData(exportUserdata); 186 setContentAge(contentAge); 187 setRecursive(recursive); 188 setExportResourceData(exportResourceData); 189 setExportProjectData(exportProjectData); 190 setInProject(inProject); 191 setExportAsFiles(false); 192 setExportMode(exportMode); 193 setAdditionalResourcesToExportWithMetaData(additionalResourcesToExportWithMetaData); 194 } 195 196 /** 197 * Returns the content Age.<p> 198 * 199 * @return the content Age 200 */ 201 public long getContentAge() { 202 203 return m_contentAge; 204 } 205 206 /** 207 * Returns the export mode that should be used. 208 * 209 * @return the export mode that should be used. 210 */ 211 public ExportMode getExportMode() { 212 213 return m_exportMode; 214 } 215 216 /** 217 * Returns the module informations if to export a module.<p> 218 * 219 * @return the module informations if to export a module 220 */ 221 public Element getModuleInfo() { 222 223 return m_moduleInfo; 224 } 225 226 /** 227 * Returns the file path, should be a zip file.<p> 228 * 229 * @return the file path 230 */ 231 public String getPath() { 232 233 // ensure the export file name ends with ".zip" in case of ZIP file export 234 if ((m_path != null) && !isExportAsFiles() && !m_path.toLowerCase().endsWith(".zip")) { 235 m_path += ".zip"; 236 } 237 return m_path; 238 } 239 240 /** 241 * Returns the resources.<p> 242 * 243 * @return the resources 244 */ 245 public List<String> getResources() { 246 247 if (m_resources == null) { 248 return Collections.emptyList(); 249 } 250 return m_resources; 251 } 252 253 /** 254 * Returns the resources to export with (some additional) meta-data, even for reduced meta-data export. 255 * @return the resources to export with (some additional) meta-data, even for reduced meta-data export. 256 */ 257 public List<String> getResourcesToExportWithMetaData() { 258 259 return null != m_additionalResourcesToExportWithMetaData 260 ? m_additionalResourcesToExportWithMetaData 261 : Collections.emptyList(); 262 263 } 264 265 /** 266 * Checks if to export account data.<p> 267 * 268 * @return <code>true</code>, if to export account data 269 */ 270 public boolean isExportAccountData() { 271 272 return m_exportAccountData; 273 } 274 275 /** 276 * Indicates if the resources are exported in one export .ZIP file (the default) or as individual files.<p> 277 * 278 * @return <code>false</code> if the resources will be exported in a .ZIP file, 279 * <code>true</code> if the resources will be exported as individual files 280 */ 281 public boolean isExportAsFiles() { 282 283 return m_exportAsFiles; 284 } 285 286 /** 287 * Checks if to export project data.<p> 288 * 289 * @return <code>true</code>, if to export project data 290 */ 291 public boolean isExportProjectData() { 292 293 return m_exportProjectData; 294 } 295 296 /** 297 * Checks if to export resource data.<p> 298 * 299 * @return <code>true</code>, if to export resource data 300 */ 301 public boolean isExportResourceData() { 302 303 return m_exportResourceData; 304 } 305 306 /** 307 * Checks if to include the /system/ Folder.<p> 308 * 309 * @return <code>true</code>, if to include the /system/ Folder 310 */ 311 public boolean isIncludeSystemFolder() { 312 313 return m_includeSystemFolder; 314 } 315 316 /** 317 * Checks if to include unchanged resources.<p> 318 * 319 * @return <code>true</code>, if to include unchanged resources 320 */ 321 public boolean isIncludeUnchangedResources() { 322 323 return m_includeUnchangedResources; 324 } 325 326 /** 327 * Checks if to include only resources in the current project.<p> 328 * 329 * @return <code>true</code>, if to include only resources in the current project 330 */ 331 public boolean isInProject() { 332 333 return m_inProject; 334 } 335 336 /** 337 * Checks if to recurse the resources to export.<p> 338 * 339 * @return <code>true</code>, if to recurse the resources to export 340 */ 341 public boolean isRecursive() { 342 343 return m_recursive; 344 } 345 346 /** 347 * Checks if the manifest.xml file will be generated with dtd info.<p> 348 * 349 * @return the xml validation flag 350 */ 351 public boolean isXmlValidation() { 352 353 return m_xmlValidation; 354 } 355 356 /** 357 * The resources (folders) that should be exported with some metadata, even if not listed in the resources to export. 358 * If a folder is listed, the folder and all resources in the folder is exported with meta data. 359 * 360 * @param resourcesToExportWithMetaData the vfs paths of the resources. 361 */ 362 public void setAdditionalResourcesToExportWithMetaData(List<String> resourcesToExportWithMetaData) { 363 364 m_additionalResourcesToExportWithMetaData = resourcesToExportWithMetaData; 365 366 } 367 368 /** 369 * Sets the content Age.<p> 370 * 371 * @param contentAge the content Age to set 372 */ 373 public void setContentAge(long contentAge) { 374 375 if (contentAge < 0) { 376 String ageString = Long.toString(contentAge); 377 throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_BAD_CONTENT_AGE_1, ageString)); 378 } 379 m_contentAge = contentAge; 380 } 381 382 /** 383 * Sets if to export account data.<p> 384 * 385 * @param exportAccountData the flag to set 386 */ 387 public void setExportAccountData(boolean exportAccountData) { 388 389 m_exportAccountData = exportAccountData; 390 } 391 392 /** 393 * Controls if the resources are exported in one export .ZIP file (the default) or as individual files.<p> 394 * 395 * @param exportAsFiles if <code>false</code>, then the resources will be exported in a .ZIP file, 396 * otherwise as individual files 397 */ 398 public void setExportAsFiles(boolean exportAsFiles) { 399 400 m_exportAsFiles = exportAsFiles; 401 } 402 403 /** 404 * Sets the export mode. 405 * 406 * @param exportMode the export mode to set 407 */ 408 public void setExportMode(ExportMode exportMode) { 409 410 m_exportMode = null != exportMode ? exportMode : ExportMode.DEFAULT; 411 } 412 413 /** 414 * Sets if to export project data.<p> 415 * 416 * @param exportProjectData the flag to set 417 */ 418 public void setExportProjectData(boolean exportProjectData) { 419 420 m_exportProjectData = exportProjectData; 421 } 422 423 /** 424 * Sets if to export resource data.<p> 425 * 426 * @param exportResourceData the flag to set 427 */ 428 public void setExportResourceData(boolean exportResourceData) { 429 430 m_exportResourceData = exportResourceData; 431 } 432 433 /** 434 * Sets if to include the /system/ Folder.<p> 435 * 436 * @param includeSystemFolder the flag to set 437 */ 438 public void setIncludeSystemFolder(boolean includeSystemFolder) { 439 440 m_includeSystemFolder = includeSystemFolder; 441 } 442 443 /** 444 * Sets if to include unchanged resources.<p> 445 * 446 * @param includeUnchangedResources the flag to set 447 */ 448 public void setIncludeUnchangedResources(boolean includeUnchangedResources) { 449 450 m_includeUnchangedResources = includeUnchangedResources; 451 } 452 453 /** 454 * Sets if to only include files in the current project.<p> 455 * 456 * @param inProject the flag to set 457 */ 458 public void setInProject(boolean inProject) { 459 460 m_inProject = inProject; 461 } 462 463 /** 464 * Sets the module informations if to export a module.<p> 465 * 466 * @param moduleInfo the module info node to set 467 */ 468 public void setModuleInfo(Element moduleInfo) { 469 470 m_moduleInfo = moduleInfo; 471 } 472 473 /** 474 * Sets the file path, should be a zip file.<p> 475 * 476 * @param path the file path 477 */ 478 public void setPath(String path) { 479 480 if (CmsStringUtil.isEmpty(path) || !path.trim().equals(path)) { 481 throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_BAD_FILE_NAME_1, path)); 482 } 483 m_path = path; 484 } 485 486 /** 487 * Sets the recursive flag.<p> 488 * 489 * @param recursive the flag to set 490 */ 491 public void setRecursive(boolean recursive) { 492 493 m_recursive = recursive; 494 } 495 496 /** 497 * Sets the resources.<p> 498 * 499 * @param resources the resources to set 500 */ 501 public void setResources(List<String> resources) { 502 503 m_resources = resources; 504 } 505 506 /** 507 * Sets the xml validation flag. If set, the manifest.xml file will be generated with dtd info.<p> 508 * 509 * @param xmlValidation the xml validation flag to set 510 */ 511 public void setXmlValidation(boolean xmlValidation) { 512 513 m_xmlValidation = xmlValidation; 514 } 515}