KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > commons > CmsAvailability


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/commons/CmsAvailability.java,v $
3  * Date : $Date: 2006/09/22 15:17:06 $
4  * Version: $Revision: 1.3 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.workplace.commons;
33
34 import org.opencms.file.CmsGroup;
35 import org.opencms.file.CmsObject;
36 import org.opencms.file.CmsProperty;
37 import org.opencms.file.CmsPropertyDefinition;
38 import org.opencms.file.CmsResource;
39 import org.opencms.file.CmsResourceFilter;
40 import org.opencms.jsp.CmsJspActionElement;
41 import org.opencms.main.CmsException;
42 import org.opencms.main.CmsIllegalArgumentException;
43 import org.opencms.main.CmsLog;
44 import org.opencms.main.OpenCms;
45 import org.opencms.security.CmsAccessControlEntry;
46 import org.opencms.security.CmsPermissionSet;
47 import org.opencms.security.I_CmsPrincipal;
48 import org.opencms.util.CmsStringUtil;
49 import org.opencms.widgets.CmsCalendarWidget;
50 import org.opencms.workplace.CmsMultiDialog;
51 import org.opencms.workplace.CmsWorkplace;
52 import org.opencms.workplace.CmsWorkplaceSettings;
53
54 import java.text.ParseException JavaDoc;
55 import java.util.ArrayList JavaDoc;
56 import java.util.Collection JavaDoc;
57 import java.util.HashMap JavaDoc;
58 import java.util.Iterator JavaDoc;
59 import java.util.List JavaDoc;
60 import java.util.Map JavaDoc;
61
62 import javax.servlet.http.HttpServletRequest JavaDoc;
63 import javax.servlet.http.HttpServletResponse JavaDoc;
64 import javax.servlet.jsp.JspException JavaDoc;
65 import javax.servlet.jsp.PageContext JavaDoc;
66
67 import org.apache.commons.logging.Log;
68
69 /**
70  * Provides methods for the resource availability/notification dialog.<p>
71  *
72  * The following files use this class:
73  * <ul>
74  * <li>/commons/availability.jsp
75  * </ul>
76  * <p>
77  *
78  * @author Jan Baudisch
79  * @author Andreas Zahner
80  *
81  * @version $Revision: 1.3 $
82  *
83  * @since 6.0.0
84  */

85 public class CmsAvailability extends CmsMultiDialog {
86
87     /** The dialog type. */
88     public static final String JavaDoc DIALOG_TYPE = "availability";
89
90     /** Request parameter name for the activation of the notifciation. */
91     public static final String JavaDoc PARAM_ENABLE_NOTIFICATION = "enablenotification";
92
93     /** Request parameter name for the expiredate. */
94     public static final String JavaDoc PARAM_EXPIREDATE = "expiredate";
95
96     /** Request parameter name for the leaveexpire. */
97     public static final String JavaDoc PARAM_LEAVEEXPIRE = "leaveexpire";
98
99     /** Request parameter name for the leaverelease. */
100     public static final String JavaDoc PARAM_LEAVERELEASE = "leaverelease";
101
102     /** Request parameter name for the recursive flag. */
103     public static final String JavaDoc PARAM_MODIFY_SIBLINGS = "modifysiblings";
104
105     /** Request parameter name for the activation of the notifciation. */
106     public static final String JavaDoc PARAM_NOTIFICATION_INTERVAL = "notificationinterval";
107
108     /** Request parameter name for the recursive flag. */
109     public static final String JavaDoc PARAM_RECURSIVE = "recursive";
110
111     /** Request parameter name for the releasedate. */
112     public static final String JavaDoc PARAM_RELEASEDATE = "releasedate";
113     
114     /** Request parameter name for the resetexpire. */
115     public static final String JavaDoc PARAM_RESETEXPIRE = "resetexpire";
116     
117     /** Request parameter name for the resetrelease. */
118     public static final String JavaDoc PARAM_RESETRELEASE = "resetrelease";
119     
120     /** The log object for this class. */
121     private static final Log LOG = CmsLog.getLog(CmsAvailability.class);
122     
123     private String JavaDoc m_paramEnablenotification;
124     private String JavaDoc m_paramExpiredate;
125     private String JavaDoc m_paramLeaveexpire;
126     private String JavaDoc m_paramModifysiblings;
127     private String JavaDoc m_paramNotificationinterval;
128     private String JavaDoc m_paramRecursive;
129     private String JavaDoc m_paramReleasedate;
130     private String JavaDoc m_paramResetexpire;
131     private String JavaDoc m_paramResetrelease;
132
133     /**
134      * Public constructor.<p>
135      *
136      * @param jsp an initialized JSP action element
137      */

138     public CmsAvailability(CmsJspActionElement jsp) {
139
140         super(jsp);
141     }
142
143     /**
144      * Public constructor with JSP variables.<p>
145      *
146      * @param context the JSP page context
147      * @param req the JSP request
148      * @param res the JSP response
149      */

150     public CmsAvailability(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
151
152         this(new CmsJspActionElement(context, req, res));
153     }
154
155     /**
156      * Returns a localized String for "Group", if the flag of a group ACE, and the localization for "User" otherwise.<p>
157      *
158      * @param flags the flags of the ACE
159      *
160      * @return localization for "Group", if the flag belongs to a group ACE
161      */

162     protected String JavaDoc getLocalizedType(int flags) {
163
164         if ((flags & CmsAccessControlEntry.ACCESS_FLAGS_USER) > 0) {
165             return key(Messages.GUI_LABEL_USER_0);
166         } else {
167             return key(Messages.GUI_LABEL_GROUP_0);
168         }
169     }
170
171     /**
172      *
173      * @see org.opencms.workplace.CmsDialog#actionCloseDialog()
174      */

175     public void actionCloseDialog() throws JspException JavaDoc {
176
177         // so that the explorer will be shown, if dialog is opened from e-mail
178
getSettings().getFrameUris().put("body", CmsWorkplace.VFS_PATH_VIEWS + "explorer/explorer_fs.jsp");
179         super.actionCloseDialog();
180     }
181
182     /**
183      * Performs the resource operation, will be called by the JSP page.<p>
184      *
185      * @throws JspException if problems including sub-elements occur
186      */

187     public void actionUpdate() throws JspException JavaDoc {
188
189         // save initialized instance of this class in request attribute for included sub-elements
190
getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this);
191
192         try {
193             if (performDialogOperation()) {
194                 // if no exception is caused and "true" is returned the dialog operation was successful
195
actionCloseDialog();
196             } else {
197                 // "false" returned, display "please wait" screen
198
getJsp().include(FILE_DIALOG_SCREEN_WAIT);
199             }
200         } catch (Throwable JavaDoc e) {
201             includeErrorpage(this, e);
202         }
203     }
204
205     /**
206      * Creates the checkbox to enable content notification for a resource.<p>
207      *
208      * @return HTML code for the enable_notification checkbox.
209      */

210     public String JavaDoc buildCheckboxEnableNotification() {
211
212         String JavaDoc propVal = null;
213         if (!isMultiOperation()) {
214             // get current settings for single resource dialog
215
try {
216                 propVal = getCms().readPropertyObject(
217                     getParamResource(),
218                     CmsPropertyDefinition.PROPERTY_ENABLE_NOTIFICATION,
219                     false).getValue();
220             } catch (CmsException e) {
221                 if (LOG.isInfoEnabled()) {
222                     LOG.info(e.getLocalizedMessage());
223                 }
224             }
225
226         }
227         if (CmsStringUtil.isEmpty(propVal)) {
228             propVal = CmsStringUtil.FALSE;
229         }
230         StringBuffer JavaDoc result = new StringBuffer JavaDoc(512);
231         result.append("<input type=\"checkbox\" style=\"text-align:left\" name=\"");
232         result.append(PARAM_ENABLE_NOTIFICATION);
233         if (Boolean.valueOf(propVal).booleanValue()) {
234             result.append("\" checked=\"checked");
235         }
236         result.append("\" value=\"true\">");
237         return result.toString();
238     }
239
240     /**
241      * Creates an the checkbox to modify all siblings.<p>
242      *
243      * If no siblings exist for this resource, an empty string will be returned.
244      *
245      * @return HTML code for the modify siblings checkbox.
246      */

247     public String JavaDoc buildCheckboxModifySiblings() {
248
249         StringBuffer JavaDoc result = new StringBuffer JavaDoc(254);
250         try {
251             if (isMultiOperation() || getCms().readSiblings(getParamResource(), CmsResourceFilter.ALL).size() > 1) {
252                 result.append("<tr>\n<td style=\"white-space:nowrap;\">");
253                 result.append(key(Messages.GUI_AVAILABILITY_MODIFY_SIBLINGS_0));
254                 result.append("</td>\n<td class=\"maxwidth\" style=\"padding-left: 5px;\">\n");
255                 result.append("<input type=\"checkbox\" name=\"");
256                 result.append(PARAM_MODIFY_SIBLINGS);
257                 result.append("\" value=\"true\" style=\"text-align:left\">\n</td>\n<td>&nbsp</td></tr>");
258             }
259         } catch (CmsException e) {
260             if (LOG.isInfoEnabled()) {
261                 LOG.info(e);
262             }
263         }
264         return result.toString();
265     }
266
267     /**
268      * Creates the "recursive" checkbox for touching subresources of folders.<p>
269      *
270      * @return the String with the checkbox input field or an empty String for folders.
271      */

272     public String JavaDoc buildCheckRecursive() {
273
274         StringBuffer JavaDoc result = new StringBuffer JavaDoc(256);
275
276         // show the checkbox only for operation(s) on folder(s)
277
if (isOperationOnFolder()) {
278             result.append(dialogBlockStart(key(Messages.GUI_AVAILABILITY_NOTIFICATION_SUBRES_0)));
279             result.append("<table border=\"0\">");
280             result.append("<tr>\n\t<td style=\"white-space:nowrap;\">");
281             result.append(key(Messages.GUI_TOUCH_MODIFY_SUBRESOURCES_0));
282             result.append("</td><td class=\"maxwidth\" style=\"padding-left: 5px;\"><input type=\"checkbox\" style=\"text-align:left\" name=\"");
283             result.append(PARAM_RECURSIVE);
284             result.append("\" value=\"true\">&nbsp;</td>\n<td>&nbsp</td></tr>\n");
285             result.append("</table>");
286             result.append(dialogBlockEnd());
287             result.append(dialogSpacer());
288         }
289         return result.toString();
290     }
291
292     /**
293      * Creates an input field for the notification interval.<p>
294      *
295      * @return HTML code for the notification interval input field.
296      */

297     public String JavaDoc buildInputNotificationInterval() {
298
299         String JavaDoc propVal = null;
300         if (!isMultiOperation()) {
301             try {
302                 propVal = getCms().readPropertyObject(
303                     getParamResource(),
304                     CmsPropertyDefinition.PROPERTY_NOTIFICATION_INTERVAL,
305                     false).getValue();
306             } catch (CmsException e) {
307                 if (LOG.isInfoEnabled()) {
308                     LOG.info(e.getLocalizedMessage());
309                 }
310             }
311         }
312         if (CmsStringUtil.isEmpty(propVal)) {
313             propVal = "";
314         }
315         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
316
317         result.append("<input class=\"maxwidth\" type=\"text\" name=\"");
318         result.append(CmsAvailability.PARAM_NOTIFICATION_INTERVAL);
319         result.append("\" value=\"");
320         result.append(propVal);
321         result.append("\">");
322         return result.toString();
323     }
324
325     /**
326      * Builds a String with HTML code to display the responsibles of a resource.<p>
327      *
328      * @return HTML code for the responsibles of the current resource
329      */

330     public String JavaDoc buildResponsibleList() {
331
332         if (isMultiOperation()) {
333             // show no responsibles list for multi operation
334
return "";
335         } else {
336             // single resource operation, create list of responsibles
337
StringBuffer JavaDoc result = new StringBuffer JavaDoc(512);
338             result.append("<tr><td colspan=\"3\">");
339             List JavaDoc parentResources = new ArrayList JavaDoc();
340             Map JavaDoc responsibles = new HashMap JavaDoc();
341             CmsObject cms = getCms();
342             String JavaDoc resourceSitePath = cms.getRequestContext().removeSiteRoot(getParamResource());
343             try {
344                 // get all parent folders of the current file
345
parentResources = cms.readPath(getParamResource(), CmsResourceFilter.IGNORE_EXPIRATION);
346             } catch (CmsException e) {
347                 // can usually be ignored
348
if (LOG.isInfoEnabled()) {
349                     LOG.info(e.getLocalizedMessage());
350                 }
351             }
352             Iterator JavaDoc i = parentResources.iterator();
353             while (i.hasNext()) {
354                 CmsResource resource = (CmsResource)i.next();
355                 try {
356                     String JavaDoc sitePath = cms.getRequestContext().removeSiteRoot(resource.getRootPath());
357                     Iterator JavaDoc entries = cms.getAccessControlEntries(sitePath, false).iterator();
358                     while (entries.hasNext()) {
359                         CmsAccessControlEntry ace = (CmsAccessControlEntry)entries.next();
360                         if (ace.isResponsible()) {
361                             I_CmsPrincipal principal = cms.lookupPrincipal(ace.getPrincipal());
362                             responsibles.put(principal, resourceSitePath.equals(sitePath) ? null : sitePath);
363                         }
364                     }
365                 } catch (CmsException e) {
366                     // can usually be ignored
367
if (LOG.isInfoEnabled()) {
368                         LOG.info(e.getLocalizedMessage());
369                     }
370                 }
371             }
372
373             if (responsibles.size() == 0) {
374                 // no responsibles found
375
result.append(key(Messages.GUI_AVAILABILITY_NO_RESPONSIBLES_0));
376             } else {
377                 // found responsibles, create list
378
result.append(dialogToggleStart(key(Messages.GUI_AVAILABILITY_RESPONSIBLES_0), "responsibles", false));
379                 Collection JavaDoc parentFolders = new ArrayList JavaDoc(responsibles.values());
380                 parentFolders.remove(null);
381                 if (parentFolders.size() > 0) {
382                     result.append("<table border=\"0\">\n<tr>\n\t<td>");
383                     result.append(key(Messages.GUI_PERMISSION_SELECT_VIEW_0));
384                     result.append("</td>\n<td><input type=\"button\" onclick=\"toggleInheritInfo();\" value=\"");
385                     result.append(key(Messages.GUI_LABEL_DETAILS_0));
386                     result.append("\" id=\"button\"/></td></tr></table>");
387                 }
388                 result.append(dialogWhiteBoxStart());
389                 i = responsibles.keySet().iterator();
390                 for (int j = 0; i.hasNext(); j++) {
391                     I_CmsPrincipal principal = (I_CmsPrincipal)i.next();
392                     String JavaDoc image = "user.png";
393                     String JavaDoc localizedType = getLocalizedType(CmsAccessControlEntry.ACCESS_FLAGS_USER);
394                     if (principal instanceof CmsGroup) {
395                         image = "group.png";
396                         localizedType = getLocalizedType(CmsAccessControlEntry.ACCESS_FLAGS_GROUP);
397                     }
398                     result.append("<div class=\"dialogrow\"><img SRC=\"");
399                     result.append(getSkinUri());
400                     result.append("commons/");
401                     result.append(image);
402                     result.append("\" class=\"noborder\" width=\"16\" height=\"16\" alt=\"");
403                     result.append(localizedType);
404                     result.append("\" title=\"");
405                     result.append(localizedType);
406                     result.append("\">&nbsp;<span class=\"textbold\">");
407                     result.append(principal.getName());
408                     result.append("</span><div class=\"hide\" id=\"inheritinfo");
409                     result.append(j);
410                     result.append("\"><div class=\"dialogpermissioninherit\">");
411                     String JavaDoc resourceName = ((String JavaDoc)responsibles.get(principal));
412                     if (CmsStringUtil.isNotEmpty(resourceName)) {
413                         result.append(key(Messages.GUI_PERMISSION_INHERITED_FROM_1, new Object JavaDoc[] {resourceName}));
414                     }
415                     result.append("</div></div></div>\n");
416                 }
417                 result.append(dialogWhiteBoxEnd());
418                 result.append("</div>\n");
419                 result.append("</td></tr>");
420             }
421             return result.toString();
422         }
423     }
424
425     /**
426      * Creates the HTML JavaScript and stylesheet includes required by the calendar for the head of the page.<p>
427      *
428      * @return the necessary HTML code for the js and stylesheet includes
429      *
430      * @deprecated use {@link CmsCalendarWidget#calendarIncludes(java.util.Locale)}, this is just here so that old JSP still work
431      */

432     public String JavaDoc calendarIncludes() {
433
434         return CmsCalendarWidget.calendarIncludes(getLocale());
435     }
436
437     /**
438      * Generates the HTML to initialize the JavaScript calendar element on the end of a page.<p>
439      *
440      * @param inputFieldId the ID of the input field where the date is pasted to
441      * @param triggerButtonId the ID of the button which triggers the calendar
442      * @param align initial position of the calendar popup element
443      * @param singleClick if true, a single click selects a date and closes the calendar, otherwise calendar is closed by doubleclick
444      * @param weekNumbers show the week numbers in the calendar or not
445      * @param mondayFirst show monday as first day of week
446      * @param dateStatusFunc name of the function which determines if/how a date should be disabled
447      * @param showTime true if the time selector should be shown, otherwise false
448      * @return the HTML code to initialize a calendar poup element
449      *
450      * @deprecated use {@link CmsCalendarWidget#calendarInit(org.opencms.i18n.CmsMessages, String, String, String, boolean, boolean, boolean, String, boolean)}, this is just here so that old JSP still work
451      */

452     public String JavaDoc calendarInit(
453         String JavaDoc inputFieldId,
454         String JavaDoc triggerButtonId,
455         String JavaDoc align,
456         boolean singleClick,
457         boolean weekNumbers,
458         boolean mondayFirst,
459         String JavaDoc dateStatusFunc,
460         boolean showTime) {
461
462         return CmsCalendarWidget.calendarInit(
463             getMessages(),
464             inputFieldId,
465             triggerButtonId,
466             align,
467             singleClick,
468             weekNumbers,
469             mondayFirst,
470             dateStatusFunc,
471             showTime);
472     }
473
474     /**
475      * Returns the current date and time as String formatted in localized pattern.<p>
476      *
477      * @return the current date and time as String formatted in localized pattern
478      */

479     public String JavaDoc getCurrentDateTime() {
480
481         // get the current date & time
482
return CmsCalendarWidget.getCalendarLocalizedTime(getLocale(), getMessages(), System.currentTimeMillis());
483     }
484
485     /**
486      * Returns the current expiredate as String formatted in localized pattern.<p>
487      *
488      * @return the current expiredate as String formatted in localized pattern
489      */

490     public String JavaDoc getCurrentExpireDate() {
491
492         // get the expiration date
493
if (isMultiOperation()) {
494             return CmsTouch.DEFAULT_DATE_STRING;
495         } else {
496             try {
497                 CmsResource res = getCms().readResource(getParamResource(), CmsResourceFilter.IGNORE_EXPIRATION);
498                 if (res.getDateExpired() == CmsResource.DATE_EXPIRED_DEFAULT) {
499                     return CmsTouch.DEFAULT_DATE_STRING;
500                 } else {
501                     return CmsCalendarWidget.getCalendarLocalizedTime(getLocale(), getMessages(), res.getDateExpired());
502                 }
503             } catch (CmsException e) {
504                 return CmsCalendarWidget.getCalendarLocalizedTime(
505                     getLocale(),
506                     getMessages(),
507                     System.currentTimeMillis());
508             }
509         }
510     }
511
512     /**
513      * Returns the current releasedate as String formatted in localized pattern.<p>
514      *
515      * @return the current releasedate as String formatted in localized pattern
516      */

517     public String JavaDoc getCurrentReleaseDate() {
518
519         // get the release date
520
if (isMultiOperation()) {
521             return CmsTouch.DEFAULT_DATE_STRING;
522         } else {
523             try {
524                 CmsResource res = getCms().readResource(getParamResource(), CmsResourceFilter.IGNORE_EXPIRATION);
525                 if (res.getDateReleased() == CmsResource.DATE_RELEASED_DEFAULT) {
526                     return CmsTouch.DEFAULT_DATE_STRING;
527                 } else {
528                     return CmsCalendarWidget.getCalendarLocalizedTime(getLocale(), getMessages(), res.getDateReleased());
529                 }
530             } catch (CmsException e) {
531                 return CmsCalendarWidget.getCalendarLocalizedTime(
532                     getLocale(),
533                     getMessages(),
534                     System.currentTimeMillis());
535             }
536         }
537     }
538
539     /**
540      * Returns the value of the enable_notification parameter.<p>
541      *
542      * The enable_notification parameter if content notification is enabled for this resource.<p>
543      *
544      * @return the value of the enable_notification parameter
545      */

546     public String JavaDoc getParamEnablenotification() {
547
548         return m_paramEnablenotification;
549     }
550
551     /**
552      * Returns the value of the new expiredate parameter,
553      * or null if this parameter was not provided.<p>
554      *
555      * @return the value of the new expiredate parameter
556      */

557     public String JavaDoc getParamExpiredate() {
558
559         return m_paramExpiredate;
560     }
561
562     /**
563      * Returns the value of the leaveexpire parameter.<p>
564      *
565      * @return the value of the leaveexpire parameter
566      */

567     public String JavaDoc getParamLeaveexpire() {
568
569         return m_paramLeaveexpire;
570     }
571
572     /**
573      * Returns the value of the modify siblings parameter,
574      * or null if this parameter was not provided.<p>
575      *
576      * @return the value of the modify siblings
577      */

578     public String JavaDoc getParamModifysiblings() {
579
580         return m_paramModifysiblings;
581     }
582
583     /**
584      * Returns the value of the notification interval parameter,
585      * or null if this parameter was not provided.<p>
586      *
587      * @return the value of the notification interval parameter
588      */

589     public String JavaDoc getParamNotificationinterval() {
590
591         return m_paramNotificationinterval;
592     }
593
594     /**
595      * Returns the value of the recursive parameter,
596      * or null if this parameter was not provided.<p>
597      *
598      * The recursive parameter on folders decides if all subresources
599      * of the folder should be touched, too.<p>
600      *
601      * @return the value of the recursive parameter
602      */

603     public String JavaDoc getParamRecursive() {
604
605         return m_paramRecursive;
606     }
607
608     /**
609      * Returns the value of the new releasedate parameter,
610      * or null if this parameter was not provided.<p>
611      *
612      * The releasedate parameter stores the new releasedate as String.<p>
613      *
614      * @return the value of the new releasedate parameter
615      */

616     public String JavaDoc getParamReleasedate() {
617
618         return m_paramReleasedate;
619     }
620
621     /**
622      * Returns the value of the resetexpire parameter.<p>
623      *
624      * @return the value of the resetexpire parameter
625      */

626     public String JavaDoc getParamResetexpire() {
627
628         return m_paramResetexpire;
629     }
630
631     /**
632      * Returns the value of the resetrelease parameter.<p>
633      *
634      * @return the value of the resetrelease parameter
635      */

636     public String JavaDoc getParamResetrelease() {
637
638         return m_paramResetrelease;
639     }
640
641     /**
642      * Sets the value of the enable notification parameter.<p>
643      *
644      * @param value the value to set
645      */

646     public void setParamEnablenotification(String JavaDoc value) {
647
648         m_paramEnablenotification = value;
649     }
650
651     /**
652      * Sets the value of the expire date.<p>
653      *
654      * @param value the value to set
655      */

656     public void setParamExpiredate(String JavaDoc value) {
657
658         m_paramExpiredate = value;
659     }
660
661     /**
662      * Sets the value of the leaveexpire parameter.<p>
663      *
664      * @param paramLeaveexpire the value of the leaveexpire parameter
665      */

666     public void setParamLeaveexpire(String JavaDoc paramLeaveexpire) {
667
668         m_paramLeaveexpire = paramLeaveexpire;
669     }
670
671     /**
672      * Sets the value of the modify siblings parameter.<p>
673      *
674      * @param value the value to set
675      */

676     public void setParamModifysiblings(String JavaDoc value) {
677
678         m_paramModifysiblings = value;
679     }
680
681     /**
682      * Sets the value of the new timestamp parameter.<p>
683      *
684      * @param value the value to set
685      */

686     public void setParamNotificationinterval(String JavaDoc value) {
687
688         m_paramNotificationinterval = value;
689     }
690
691     /**
692      * Sets the value of the recursive parameter.<p>
693      *
694      * @param value the value to set
695      */

696     public void setParamRecursive(String JavaDoc value) {
697
698         m_paramRecursive = value;
699     }
700
701     /**
702      * Sets the value of the releasedate parameter.<p>
703      *
704      * @param value the value to set
705      */

706     public void setParamReleasedate(String JavaDoc value) {
707
708         m_paramReleasedate = value;
709     }
710
711     /**
712      * Sets the value of the resetexpire parameter.<p>
713      *
714      * @param paramResetexpire the value of the resetexpire parameter
715      */

716     public void setParamResetexpire(String JavaDoc paramResetexpire) {
717
718         m_paramResetexpire = paramResetexpire;
719     }
720
721     /**
722      * Sets the value of the resetrelease parameter.<p>
723      *
724      * @param paramResetrelease the value of the resetrelease parameter
725      */

726     public void setParamResetrelease(String JavaDoc paramResetrelease) {
727
728         m_paramResetrelease = paramResetrelease;
729     }
730
731     /**
732      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
733      */

734     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
735
736         // fill the parameter values in the get/set methods
737
fillParamValues(request);
738
739         // check the required permissions to modify the resource
740
if (!checkResourcePermissions(CmsPermissionSet.ACCESS_WRITE, false)) {
741             // no write permissions for the resource, set cancel action to close dialog
742
setParamAction(DIALOG_CANCEL);
743         }
744
745         // set the dialog type
746
setParamDialogtype(DIALOG_TYPE);
747
748         // set the action for the JSP switch
749
if (DIALOG_TYPE.equals(getParamAction())) {
750             setAction(ACTION_OK);
751         } else if (DIALOG_WAIT.equals(getParamAction())) {
752             setAction(ACTION_WAIT);
753         } else if (DIALOG_CANCEL.equals(getParamAction())) {
754             setAction(ACTION_CANCEL);
755         } else {
756             setAction(ACTION_DEFAULT);
757             // build title for dialog
758
setDialogTitle(
759                 Messages.GUI_AVAILABILITY_NOTIFICATION_SETTINGS_1,
760                 Messages.GUI_AVAILABILITY_NOTIFICATION_MULTI_2);
761         }
762     }
763
764     /**
765      * Modifies the release and expire date of a resource, and changes the notification interval. <p>
766      *
767      * @return true, if the operation was performed, otherwise false
768      * @throws CmsException if modification is not successful
769      */

770     protected boolean performDialogOperation() throws CmsException {
771
772         // check if the current resource is a folder for single operation
773
boolean isFolder = isOperationOnFolder();
774         // on folder deletion or multi operation display "please wait" screen, not for simple file deletion
775
if ((isMultiOperation() || isFolder) && !DIALOG_WAIT.equals(getParamAction())) {
776             // return false, this will trigger the "please wait" screen
777
return false;
778         }
779
780         // get the new release date for the resource(s) from request parameter
781
long releaseDate = CmsResource.DATE_RELEASED_DEFAULT;
782         boolean resetReleaseDate = Boolean.valueOf(getParamResetrelease()).booleanValue();
783         boolean leaveReleaseDate = false;
784         if (!resetReleaseDate) {
785             try {
786                 if ((CmsStringUtil.isNotEmptyOrWhitespaceOnly(getParamReleasedate()))
787                     && (!getParamReleasedate().startsWith(CmsTouch.DEFAULT_DATE_STRING))) {
788                     releaseDate = CmsCalendarWidget.getCalendarDate(getMessages(), getParamReleasedate(), true);
789                 } else {
790                     leaveReleaseDate = true;
791                 }
792             } catch (ParseException JavaDoc e) {
793                 throw new CmsException(
794                     Messages.get().container(Messages.ERR_PARSE_RELEASEDATE_1, getParamReleasedate()),
795                     e);
796             }
797         }
798
799         // get the new expire date for the resource(s) from request parameter
800
long expireDate = CmsResource.DATE_EXPIRED_DEFAULT;
801         boolean resetExpireDate = Boolean.valueOf(getParamResetexpire()).booleanValue();
802         boolean leaveExpireDate = false;
803         if (!resetExpireDate) {
804             try {
805                 if ((CmsStringUtil.isNotEmptyOrWhitespaceOnly(getParamExpiredate()))
806                     && (!getParamExpiredate().startsWith(CmsTouch.DEFAULT_DATE_STRING))) {
807                     expireDate = CmsCalendarWidget.getCalendarDate(getMessages(), getParamExpiredate(), true);
808                 } else {
809                     leaveExpireDate = true;
810                 }
811             } catch (ParseException JavaDoc e) {
812                 throw new CmsException(
813                     Messages.get().container(Messages.ERR_PARSE_EXPIREDATE_1, getParamExpiredate()),
814                     e);
815             }
816         }
817
818         // get the flag if the operation is recursive from request parameter
819
boolean modifyRecursive = Boolean.valueOf(getParamRecursive()).booleanValue();
820
821         // get the flag if the operation should be executed on resource siblings, too
822
boolean modifySiblings = Boolean.valueOf(getParamModifysiblings()).booleanValue();
823
824         // now iterate the resource(s)
825
Iterator JavaDoc i = getResourceList().iterator();
826         while (i.hasNext()) {
827             String JavaDoc resName = (String JavaDoc)i.next();
828             try {
829                 performSingleResource(
830                     resName,
831                     releaseDate,
832                     expireDate,
833                     leaveReleaseDate,
834                     leaveExpireDate,
835                     modifyRecursive,
836                     modifySiblings);
837             } catch (CmsException e) {
838                 // collect exceptions to create a detailed output
839
addMultiOperationException(e);
840             }
841         }
842         checkMultiOperationException(Messages.get(), Messages.ERR_AVAILABILITY_MULTI_0);
843
844         return true;
845     }
846
847     /**
848      * Performs the availability and notification operations on a single resource.<p>
849      *
850      * @param resName the VFS path of the resource
851      * @param releaseDate the new release date
852      * @param expireDate the new expiration date
853      * @param leaveRelease flag indicating if the release date should be left untouched
854      * @param leaveExpire flag indicating if the expiration date should be left untouched
855      * @param modifyRecursive flag indicating if the operation is recursive for folders
856      * @param modifySiblings flag indicating to include resource siblings
857      * @throws CmsException if the availability and notification operations fail
858      */

859     protected void performSingleResource(
860         String JavaDoc resName,
861         long releaseDate,
862         long expireDate,
863         boolean leaveRelease,
864         boolean leaveExpire,
865         boolean modifyRecursive,
866         boolean modifySiblings) throws CmsException {
867
868         List JavaDoc resources = new ArrayList JavaDoc();
869         if (modifySiblings) {
870             // modify all siblings of a resource
871
resources = getCms().readSiblings(resName, CmsResourceFilter.IGNORE_EXPIRATION);
872         } else {
873             // modify only resource without siblings
874
resources.add(getCms().readResource(resName, CmsResourceFilter.IGNORE_EXPIRATION));
875         }
876         Iterator JavaDoc i = resources.iterator();
877         while (i.hasNext()) {
878             CmsResource resource = (CmsResource)i.next();
879             String JavaDoc resourcePath = getCms().getRequestContext().removeSiteRoot(resource.getRootPath());
880             // lock resource if autolock is enabled
881
checkLock(resourcePath);
882             if (!leaveRelease && !leaveExpire) {
883                 if (expireDate < releaseDate) {
884                     throw new CmsIllegalArgumentException(Messages.get().container(
885                         Messages.ERR_AVAILABILITY_BAD_TIMEWINDOW_0));
886                 }
887             }
888             // modify release and expire date of the resource if desired
889
if (! leaveRelease) {
890                 getCms().setDateReleased(resourcePath, releaseDate, modifyRecursive);
891             }
892             if (! leaveExpire) {
893                 getCms().setDateExpired(resourcePath, expireDate, modifyRecursive);
894             }
895             // write notification settings
896
writeProperty(
897                 resourcePath,
898                 CmsPropertyDefinition.PROPERTY_NOTIFICATION_INTERVAL,
899                 getParamNotificationinterval());
900             writeProperty(
901                 resourcePath,
902                 CmsPropertyDefinition.PROPERTY_ENABLE_NOTIFICATION,
903                 getParamEnablenotification());
904         }
905     }
906
907     /**
908      * Writes a property value for a resource.<p>
909      *
910      * @param resourcePath the path of the resource
911      * @param propertyName the name of the property
912      * @param propertyValue the new value of the property
913      * @throws CmsException if something goes wrong
914      */

915     protected void writeProperty(String JavaDoc resourcePath, String JavaDoc propertyName, String JavaDoc propertyValue) throws CmsException {
916
917         if (CmsStringUtil.isEmpty(propertyValue)) {
918             propertyValue = CmsProperty.DELETE_VALUE;
919         }
920
921         CmsProperty newProp = new CmsProperty();
922         newProp.setName(propertyName);
923         CmsProperty oldProp = getCms().readPropertyObject(resourcePath, propertyName, false);
924         if (oldProp.isNullProperty()) {
925             // property value was not already set
926
if (OpenCms.getWorkplaceManager().isDefaultPropertiesOnStructure()) {
927                 newProp.setStructureValue(propertyValue);
928             } else {
929                 newProp.setResourceValue(propertyValue);
930             }
931         } else {
932             if (oldProp.getStructureValue() != null) {
933                 newProp.setStructureValue(propertyValue);
934                 newProp.setResourceValue(oldProp.getResourceValue());
935             } else {
936                 newProp.setResourceValue(propertyValue);
937             }
938         }
939
940         newProp.setAutoCreatePropertyDefinition(true);
941
942         String JavaDoc oldStructureValue = oldProp.getStructureValue();
943         String JavaDoc newStructureValue = newProp.getStructureValue();
944         if (CmsStringUtil.isEmpty(oldStructureValue)) {
945             oldStructureValue = CmsProperty.DELETE_VALUE;
946         }
947         if (CmsStringUtil.isEmpty(newStructureValue)) {
948             newStructureValue = CmsProperty.DELETE_VALUE;
949         }
950
951         String JavaDoc oldResourceValue = oldProp.getResourceValue();
952         String JavaDoc newResourceValue = newProp.getResourceValue();
953         if (CmsStringUtil.isEmpty(oldResourceValue)) {
954             oldResourceValue = CmsProperty.DELETE_VALUE;
955         }
956         if (CmsStringUtil.isEmpty(newResourceValue)) {
957             newResourceValue = CmsProperty.DELETE_VALUE;
958         }
959
960         // change property only if it has been changed
961
if (!oldResourceValue.equals(newResourceValue) || !oldStructureValue.equals(newStructureValue)) {
962             getCms().writePropertyObject(resourcePath, newProp);
963         }
964     }
965 }
Popular Tags