1 31 32 package org.opencms.db; 33 34 import org.opencms.file.CmsProject; 35 import org.opencms.file.CmsResource; 36 import org.opencms.main.CmsIllegalArgumentException; 37 import org.opencms.util.CmsFileUtil; 38 import org.opencms.util.CmsUUID; 39 40 import java.util.ArrayList ; 41 import java.util.Collections ; 42 import java.util.Iterator ; 43 import java.util.List ; 44 45 66 public class CmsPublishList { 67 68 69 private List m_deletedFolderList; 70 71 72 private List m_directPublishResources; 73 74 75 private List m_fileList; 76 77 78 private List m_folderList; 79 80 81 private int m_projectId; 82 83 84 private CmsUUID m_publishHistoryId; 85 86 87 private boolean m_publishSiblings; 88 89 90 private boolean m_publishSubResources; 91 92 97 public CmsPublishList(CmsProject project) { 98 99 this(project, null, false, true); 100 } 101 102 108 public CmsPublishList(CmsResource directPublishResource, boolean publishSiblings) { 109 110 this(null, Collections.singletonList(directPublishResource), publishSiblings, true); 111 } 112 113 119 public CmsPublishList(List directPublishResources, boolean publishSiblings) { 120 121 this(null, directPublishResources, publishSiblings, true); 122 } 123 124 131 public CmsPublishList(List directPublishResources, boolean publishSiblings, boolean publishSubResources) { 132 133 this(null, directPublishResources, publishSiblings, publishSubResources); 134 } 135 136 144 private CmsPublishList( 145 CmsProject project, 146 List directPublishResources, 147 boolean publishSiblings, 148 boolean publishSubResources) { 149 150 m_fileList = new ArrayList (); 151 m_folderList = new ArrayList (); 152 m_deletedFolderList = new ArrayList (); 153 m_publishHistoryId = new CmsUUID(); 154 m_publishSiblings = publishSiblings; 155 m_publishSubResources = publishSubResources; 156 m_projectId = (project != null) ? project.getId() : -1; 157 if (directPublishResources != null) { 158 m_directPublishResources = Collections.unmodifiableList(CmsFileUtil.removeRedundantResources(directPublishResources)); 160 } 161 } 162 163 168 public List getDeletedFolderList() { 169 170 return m_deletedFolderList; 171 } 172 173 181 public List getDirectPublishResources() { 182 183 return m_directPublishResources; 184 } 185 186 191 public List getFileList() { 192 193 return Collections.unmodifiableList(m_fileList); 194 } 195 196 201 public List getFolderList() { 202 203 return Collections.unmodifiableList(m_folderList); 204 } 205 206 212 public int getProjectId() { 213 214 return m_projectId; 215 } 216 217 222 public CmsUUID getPublishHistoryId() { 223 224 return m_publishHistoryId; 225 } 226 227 232 public boolean isDirectPublish() { 233 234 return m_projectId < 0; 235 } 236 237 242 public boolean isPublishSiblings() { 243 244 return m_publishSiblings; 245 } 246 247 252 public boolean isPublishSubResources() { 253 254 return m_publishSubResources; 255 } 256 257 260 public String toString() { 261 262 StringBuffer result = new StringBuffer (); 263 result.append("\n[\n"); 264 if (isDirectPublish()) { 265 result.append("direct publish of resources: ").append(m_directPublishResources.toString()).append("\n"); 266 } else { 267 result.append("publish of project: ").append(m_projectId).append("\n"); 268 } 269 result.append("publish history ID: ").append(m_publishHistoryId.toString()).append("\n"); 270 result.append("resources: ").append(m_fileList.toString()).append("\n"); 271 result.append("folders: ").append(m_folderList.toString()).append("\n"); 272 result.append("]\n"); 273 return result.toString(); 274 } 275 276 282 protected void addFile(CmsResource resource) throws CmsIllegalArgumentException { 283 284 286 if (resource.isFolder()) { 287 throw new CmsIllegalArgumentException(Messages.get().container( 288 Messages.ERR_PUBLISH_NO_CMS_FILE_1, 289 resource.getRootPath())); 290 } 291 292 if (resource.getState() == CmsResource.STATE_UNCHANGED) { 293 throw new CmsIllegalArgumentException(Messages.get().container( 294 Messages.ERR_PUBLISH_UNCHANGED_RESOURCE_1, 295 resource.getRootPath())); 296 } 297 298 if (!m_fileList.contains(resource)) { 299 m_fileList.add(resource); 302 } 303 } 304 305 312 protected void addFiles(List list) throws IllegalArgumentException { 313 314 316 Iterator i = list.iterator(); 317 while (i.hasNext()) { 318 addFile((CmsResource)i.next()); 319 } 320 } 321 322 328 protected void addFolder(CmsResource resource) throws IllegalArgumentException { 329 330 332 if (resource.isFile()) { 333 throw new CmsIllegalArgumentException(Messages.get().container( 334 Messages.ERR_PUBLISH_NO_FOLDER_1, 335 resource.getRootPath())); 336 } 337 338 if (resource.getState() == CmsResource.STATE_UNCHANGED) { 339 throw new CmsIllegalArgumentException(Messages.get().container( 340 Messages.ERR_PUBLISH_UNCHANGED_RESOURCE_1, 341 resource.getRootPath())); 342 } 343 344 if (resource.getState() == CmsResource.STATE_DELETED) { 345 m_deletedFolderList.add(resource); 346 } else { 347 m_folderList.add(resource); 348 } 349 } 350 351 358 protected void addFolders(List list) throws IllegalArgumentException { 359 360 362 Iterator i = list.iterator(); 363 while (i.hasNext()) { 364 addFolder((CmsResource)i.next()); 365 } 366 } 367 368 371 protected void finalize() throws Throwable { 372 373 try { 374 if (m_fileList != null) { 375 m_fileList.clear(); 376 } 377 m_fileList = null; 378 379 if (m_folderList != null) { 380 m_folderList.clear(); 381 } 382 m_folderList = null; 383 384 if (m_deletedFolderList != null) { 385 m_deletedFolderList.clear(); 386 } 387 m_deletedFolderList = null; 388 } catch (Throwable t) { 389 } 391 392 super.finalize(); 393 } 394 395 400 protected List getFolderListInstance() { 401 402 return m_folderList; 404 } 405 406 409 protected void initialize() { 410 411 if (m_folderList != null) { 412 Collections.sort(m_folderList, CmsResource.COMPARE_ROOT_PATH); 414 } 415 416 if (m_fileList != null) { 417 Collections.sort(m_fileList, CmsResource.COMPARE_ROOT_PATH); 419 } 420 421 if (m_deletedFolderList != null) { 422 Collections.sort(m_deletedFolderList, CmsResource.COMPARE_ROOT_PATH); 424 Collections.reverse(m_deletedFolderList); 425 } 426 } 427 428 435 protected boolean remove(CmsResource resource) { 436 437 return m_fileList.remove(resource); 439 } 440 } | Popular Tags |