1 31 32 package org.opencms.workplace.commons; 33 34 import org.opencms.db.CmsPublishList; 35 import org.opencms.file.CmsProject; 36 import org.opencms.file.CmsResource; 37 import org.opencms.file.CmsResourceFilter; 38 import org.opencms.jsp.CmsJspActionElement; 39 import org.opencms.lock.CmsLock; 40 import org.opencms.main.CmsException; 41 import org.opencms.main.CmsLog; 42 import org.opencms.security.CmsPermissionSet; 43 import org.opencms.util.CmsDateUtil; 44 import org.opencms.util.CmsStringUtil; 45 import org.opencms.workplace.CmsReport; 46 import org.opencms.workplace.CmsWorkplaceManager; 47 import org.opencms.workplace.CmsWorkplaceSettings; 48 import org.opencms.workplace.threads.CmsPublishThread; 49 import org.opencms.workplace.threads.CmsXmlDocumentLinkValidatorThread; 50 51 import java.text.DateFormat ; 52 import java.util.ArrayList ; 53 import java.util.Date ; 54 import java.util.Iterator ; 55 import java.util.List ; 56 57 import javax.servlet.http.HttpServletRequest ; 58 import javax.servlet.http.HttpServletResponse ; 59 import javax.servlet.jsp.JspException ; 60 import javax.servlet.jsp.PageContext ; 61 62 import org.apache.commons.logging.Log; 63 64 80 public class CmsPublishProject extends CmsReport { 81 82 83 public static final int ACTION_UNLOCK_CONFIRMATION = 200; 84 85 86 public static final int ACTION_UNLOCK_CONFIRMED = 210; 87 88 89 public static final String DIALOG_TYPE = "publishproject"; 90 91 92 public static final String DIALOG_UNLOCK_CONFIRMATION = "unlockconfirmation"; 93 94 95 public static final String DIALOG_UNLOCK_CONFIRMED = "unlockconfirmed"; 96 97 98 public static final String PARAM_PUBLISHSIBLINGS = "publishsiblings"; 99 100 101 public static final String PARAM_SUBRESOURCES = "subresources"; 102 103 104 private static final Log LOG = CmsLog.getLog(CmsPublishProject.class); 105 106 private String m_paramDirectpublish; 107 private String m_paramModifieddate; 108 private String m_paramModifieduser; 109 private String m_paramProjectid; 110 private String m_paramProjectname; 111 private String m_paramPublishsiblings; 112 private String m_paramResourcename; 113 private String m_paramSubresources; 114 115 120 public CmsPublishProject(CmsJspActionElement jsp) { 121 122 super(jsp); 123 } 124 125 132 public CmsPublishProject(PageContext context, HttpServletRequest req, HttpServletResponse res) { 133 134 this(new CmsJspActionElement(context, req, res)); 135 } 136 137 142 public void actionReport() throws JspException { 143 144 getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this); 146 switch (getAction()) { 147 case ACTION_REPORT_END: 148 actionCloseDialog(); 149 break; 150 case ACTION_REPORT_UPDATE: 151 setParamAction(REPORT_UPDATE); 152 getJsp().include(FILE_REPORT_OUTPUT); 153 154 break; 155 case ACTION_REPORT_BEGIN: 156 case ACTION_CONFIRMED: 157 default: 158 try { 159 List publishResources = null; 160 boolean directPublish = Boolean.valueOf(getParamDirectpublish()).booleanValue(); 161 162 if (directPublish) { 163 publishResources = new ArrayList (getResourceList().size()); 165 Iterator i = getResourceList().iterator(); 166 while (i.hasNext()) { 167 String resName = (String )i.next(); 168 try { 169 CmsResource res = getCms().readResource(resName, CmsResourceFilter.ALL); 170 publishResources.add(res); 171 CmsLock lock = getCms().getLock(resName); 173 if (! lock.isNullLock()) { 174 getCms().unlockResource(resName); 176 } 177 } catch (CmsException e) { 178 addMultiOperationException(e); 179 } 180 } 181 checkMultiOperationException(Messages.get(), Messages.ERR_PUBLISH_MULTI_UNLOCK_0); 183 } else { 184 if (getCms().getRequestContext().currentProject().getType() == CmsProject.PROJECT_TYPE_TEMPORARY) { 185 setParamRefreshWorkplace(CmsStringUtil.TRUE); 187 } 188 } 189 190 if (showUnlockConfirmation()) { 191 if (directPublish) { 193 Iterator i = getResourceList().iterator(); 195 while (i.hasNext()) { 196 String resName = (String )i.next(); 197 try { 198 CmsResource res = getCms().readResource(resName, CmsResourceFilter.ALL); 199 if (res.isFolder()) { 200 String folderName = resName; 201 if (!folderName.endsWith("/")) { 202 folderName += "/"; 203 } 204 getCms().lockResource(folderName); 205 getCms().unlockResource(folderName); 206 } 207 } catch (CmsException e) { 208 addMultiOperationException(e); 209 } 210 } 211 checkMultiOperationException(Messages.get(), Messages.ERR_PUBLISH_MULTI_UNLOCK_0); 213 } else { 214 getCms().unlockProject(Integer.parseInt(getParamProjectid())); 216 } 217 } 218 219 CmsPublishList publishList = null; 220 if (directPublish) { 221 boolean publishSubResources = Boolean.valueOf(getParamSubresources()).booleanValue(); 223 publishList = getCms().getPublishList( 224 publishResources, 225 Boolean.valueOf(getParamPublishsiblings()).booleanValue(), 226 publishSubResources); 227 getCms().checkPublishPermissions(publishList); 228 } 229 230 CmsXmlDocumentLinkValidatorThread thread = new CmsXmlDocumentLinkValidatorThread( 232 getCms(), 233 publishList, 234 getSettings()); 235 setParamAction(REPORT_BEGIN); 236 setParamThread(thread.getUUID().toString()); 237 238 setParamThreadHasNext(CmsStringUtil.TRUE); 240 setParamReportContinueKey(Messages.GUI_PUBLISH_CONTINUE_BROKEN_LINKS_0); 242 getJsp().include(FILE_REPORT_OUTPUT); 243 244 } catch (Throwable e) { 245 includeErrorpage(this, e); 247 } 248 } 249 } 250 251 256 public String buildCheckSiblings() { 257 258 CmsResource res = null; 259 if (! isMultiOperation()) { 260 try { 261 res = getCms().readResource(getParamResource(), CmsResourceFilter.ALL); 262 } catch (CmsException e) { 263 if (LOG.isInfoEnabled()) { 265 LOG.info(e.getLocalizedMessage()); 266 } 267 } 268 } 269 StringBuffer result = new StringBuffer (128); 270 boolean showSiblingCheckBox = false; 271 if (isMultiOperation() || (res != null && res.isFile() && res.getSiblingCount() > 1) || (res != null && res.isFolder())) { 272 274 result.append(dialogSpacer()); 275 result.append("<input type=\"checkbox\" name=\""); 276 result.append(PARAM_PUBLISHSIBLINGS); 277 result.append("\" value=\"true\""); 278 if (getSettings().getUserSettings().getDialogPublishSiblings()) { 280 result.append(" checked=\"checked\""); 281 } 282 result.append("> "); 283 result.append(key(Messages.GUI_PUBLISH_ALLSIBLINGS_0)); 284 showSiblingCheckBox = true; 285 } 286 if (isOperationOnFolder()) { 287 if (showSiblingCheckBox) { 289 result.append("<br>"); 290 } 291 result.append("<input type=\"checkbox\" name=\""); 292 result.append(PARAM_SUBRESOURCES); 293 result.append("\" value=\"true\" checked=\"checked\"> "); 294 if (isMultiOperation()) { 295 result.append(key(Messages.GUI_PUBLISH_MULTI_SUBRESOURCES_0)); 296 } else { 297 result.append(key(Messages.GUI_PUBLISH_SUBRESOURCES_0)); 298 } 299 } 300 return result.toString(); 301 } 302 303 308 public String getParamDirectpublish() { 309 310 return m_paramDirectpublish; 311 } 312 313 318 public String getParamModifieddate() { 319 320 return m_paramModifieddate; 321 } 322 323 328 public String getParamModifieduser() { 329 330 return m_paramModifieduser; 331 } 332 333 338 public String getParamProjectid() { 339 340 return m_paramProjectid; 341 } 342 343 348 public String getParamProjectname() { 349 350 return m_paramProjectname; 351 } 352 353 358 public String getParamPublishsiblings() { 359 360 return m_paramPublishsiblings; 361 } 362 363 368 public String getParamResourcename() { 369 370 return m_paramResourcename; 371 } 372 373 378 public String getParamSubresources() { 379 380 return m_paramSubresources; 381 } 382 383 388 public void setParamDirectpublish(String value) { 389 390 m_paramDirectpublish = value; 391 } 392 393 398 public void setParamModifieddate(String value) { 399 400 m_paramModifieddate = value; 401 } 402 403 408 public void setParamModifieduser(String value) { 409 410 m_paramModifieduser = value; 411 } 412 413 418 public void setParamProjectid(String value) { 419 420 m_paramProjectid = value; 421 } 422 423 428 public void setParamProjectname(String value) { 429 430 m_paramProjectname = value; 431 } 432 433 438 public void setParamPublishsiblings(String value) { 439 440 m_paramPublishsiblings = value; 441 } 442 443 448 public void setParamResourcename(String value) { 449 450 m_paramResourcename = value; 451 } 452 453 458 public void setParamSubresources(String paramSubresources) { 459 460 m_paramSubresources = paramSubresources; 461 } 462 463 466 protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) { 467 468 fillParamValues(request); 470 setParamDialogtype(DIALOG_TYPE); 472 474 if (CmsStringUtil.isNotEmpty(getParamResource()) || isMultiOperation()) { 475 setParamDirectpublish(CmsStringUtil.TRUE); 476 } 477 if (DIALOG_CONFIRMED.equals(getParamAction())) { 479 if (showUnlockConfirmation()) { 480 setAction(ACTION_UNLOCK_CONFIRMATION); 482 } else { 483 setAction(ACTION_CONFIRMED); 485 } 486 } else if (DIALOG_UNLOCK_CONFIRMED.equals(getParamAction())) { 487 setAction(ACTION_CONFIRMED); 488 } else if (REPORT_UPDATE.equals(getParamAction())) { 489 setAction(ACTION_REPORT_UPDATE); 490 } else if (REPORT_BEGIN.equals(getParamAction())) { 491 setAction(ACTION_REPORT_BEGIN); 492 } else if (REPORT_END.equals(getParamAction())) { 493 if (Boolean.valueOf(getParamThreadHasNext()).booleanValue()) { 494 startPublishThread(); 496 497 setParamAction(REPORT_UPDATE); 498 setAction(ACTION_REPORT_UPDATE); 499 } else { 500 setAction(ACTION_REPORT_END); 502 } 503 } else if (DIALOG_CANCEL.equals(getParamAction())) { 504 setAction(ACTION_CANCEL); 505 } else { 506 setAction(ACTION_DEFAULT); 507 if (Boolean.valueOf(getParamDirectpublish()).booleanValue()) { 509 if (!getCms().isManagerOfProject() 511 && !checkResourcePermissions(CmsPermissionSet.ACCESS_DIRECT_PUBLISH, false)) { 512 setAction(ACTION_CANCEL); 514 return; 515 } 516 computePublishResource(); 518 setDialogTitle(Messages.GUI_PUBLISH_RESOURCE_1, Messages.GUI_PUBLISH_MULTI_2); 520 } else { 521 setParamTitle(key(Messages.GUI_PUBLISH_PROJECT_0)); 523 computePublishProject(); 525 } 527 } 528 } 529 530 533 private void computePublishProject() { 534 535 String projectId = getParamProjectid(); 536 int id; 537 if (CmsStringUtil.isEmptyOrWhitespaceOnly(projectId)) { 538 id = getCms().getRequestContext().currentProject().getId(); 540 setParamProjectname(getCms().getRequestContext().currentProject().getName()); 541 setParamProjectid("" + id); 542 } else { 543 id = Integer.parseInt(projectId); 544 try { 545 setParamProjectname(getCms().readProject(id).getName()); 546 } catch (CmsException e) { 547 LOG.error(Messages.get().getBundle().key(Messages.LOG_SET_PROJECT_NAME_FAILED_0), e); 548 } 549 } 550 } 551 552 555 private void computePublishResource() { 556 557 if (! isMultiOperation()) { 558 try { 559 CmsResource res = getCms().readResource(getParamResource(), CmsResourceFilter.ALL); 560 setParamResourcename(res.getName()); 561 setParamModifieddate(CmsDateUtil.getDateTime( 562 new Date (res.getDateLastModified()), 563 DateFormat.SHORT, 564 getLocale())); 565 setParamModifieduser(getCms().readUser(res.getUserLastModified()).getName()); 566 } catch (CmsException e) { 567 LOG.error(Messages.get().getBundle().key(Messages.LOG_COMPUTING_PUBRES_FAILED_0), e); 568 } 569 } 570 } 571 572 577 private boolean showUnlockConfirmation() { 578 579 try { 580 if (Boolean.valueOf(getParamDirectpublish()).booleanValue()) { 581 if (isOperationOnFolder()) { 583 int count = 0; 584 Iterator i = getResourceList().iterator(); 585 while (i.hasNext()) { 586 String resName = (String )i.next(); 587 CmsResource res = getCms().readResource(resName, CmsResourceFilter.ALL); 588 if ((res.getState() != CmsResource.STATE_DELETED) && res.isFolder()) { 589 count += getCms().countLockedResources(resName); 590 } 591 } 592 return (count > 0); 593 } 594 } else { 595 int id = Integer.parseInt(getParamProjectid()); 597 return (getCms().countLockedResources(id) > 0); 598 } 599 } catch (CmsException e) { 600 LOG.error(Messages.get().getBundle().key(Messages.LOG_DISPLAY_UNLOCK_INF_FAILED_0), e); 601 } 602 return false; 603 } 604 605 610 private void startPublishThread() { 611 612 CmsPublishList publishList = getSettings().getPublishList(); 614 CmsWorkplaceSettings settings = (CmsWorkplaceSettings)getJsp().getRequest().getSession().getAttribute( 615 CmsWorkplaceManager.SESSION_WORKPLACE_SETTINGS); 616 CmsPublishThread thread = new CmsPublishThread(getCms(), publishList, settings); 617 618 setParamThread(thread.getUUID().toString()); 620 setParamThreadHasNext(CmsStringUtil.FALSE); 621 622 thread.start(); 624 } 625 626 } 627 | Popular Tags |