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