1 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 ; 42 import java.util.List ; 43 44 import org.dom4j.Document; 45 import org.dom4j.Element; 46 47 56 public class CmsVfsImportExportHandler implements I_CmsImportExportHandler { 57 58 59 private long m_contentAge; 60 61 62 private String m_description; 63 64 65 private List m_exportPaths; 66 67 68 private boolean m_exportUserdata; 69 70 71 private boolean m_exportWebusers; 72 73 74 private String m_fileName; 75 76 77 private boolean m_includeSystem; 78 79 80 private boolean m_includeUnchanged; 81 82 83 private boolean m_recursive; 84 85 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 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 129 public long getContentAge() { 130 131 return m_contentAge; 132 } 133 134 137 public String getDescription() { 138 139 return m_description; 140 } 141 142 147 public List getExportPaths() { 148 149 return m_exportPaths; 150 } 151 152 157 public String getFileName() { 158 159 return m_fileName; 160 } 161 162 165 public synchronized void importData(CmsObject cms, String importFile, String 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 179 public boolean isExportUserdata() { 180 181 return m_exportUserdata; 182 } 183 184 189 public boolean isExportWebusers() { 190 191 return m_exportWebusers; 192 } 193 194 199 public boolean isIncludeSystem() { 200 201 return m_includeSystem; 202 } 203 204 209 public boolean isIncludeUnchanged() { 210 211 return m_includeUnchanged; 212 } 213 214 219 public boolean isRecursive() { 220 221 return m_recursive; 222 } 223 224 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 244 public void setContentAge(long contentAge) { 245 246 if (contentAge < 0) { 247 String 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 256 public void setDescription(String description) { 257 258 m_description = description; 259 } 260 261 266 public void setExportPaths(List exportPaths) { 267 268 m_exportPaths = exportPaths; 269 } 270 271 276 public void setExportUserdata(boolean exportUserdata) { 277 278 m_exportUserdata = exportUserdata; 279 } 280 281 286 public void setExportWebusers(boolean exportWebusers) { 287 288 m_exportWebusers = exportWebusers; 289 } 290 291 296 public void setFileName(String 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 309 public void setIncludeSystem(boolean excludeSystem) { 310 311 m_includeSystem = excludeSystem; 312 } 313 314 319 public void setIncludeUnchanged(boolean excludeUnchanged) { 320 321 m_includeUnchanged = excludeUnchanged; 322 } 323 324 329 public void setRecursive(boolean recursive) { 330 331 m_recursive = recursive; 332 } 333 334 337 protected void finalize() throws Throwable { 338 339 try { 340 if (m_exportPaths != null) { 341 m_exportPaths.clear(); 342 } 343 m_exportPaths = null; 344 } catch (Exception e) { 345 } finally { 347 super.finalize(); 348 } 349 } 350 } 351 | Popular Tags |