KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/commons/CmsChacc.java,v $
3  * Date : $Date: 2006/03/27 14:52:18 $
4  * Version: $Revision: 1.24 $
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.CmsResource;
37 import org.opencms.file.CmsResourceFilter;
38 import org.opencms.jsp.CmsJspActionElement;
39 import org.opencms.main.CmsException;
40 import org.opencms.main.CmsLog;
41 import org.opencms.security.CmsAccessControlEntry;
42 import org.opencms.security.CmsAccessControlList;
43 import org.opencms.security.CmsPermissionSet;
44 import org.opencms.security.CmsRole;
45 import org.opencms.security.I_CmsPrincipal;
46 import org.opencms.util.CmsStringUtil;
47 import org.opencms.util.CmsUUID;
48 import org.opencms.workplace.CmsDialog;
49 import org.opencms.workplace.CmsWorkplaceSettings;
50
51 import java.util.ArrayList JavaDoc;
52 import java.util.HashMap JavaDoc;
53 import java.util.Iterator JavaDoc;
54 import java.util.List JavaDoc;
55 import java.util.Map JavaDoc;
56 import java.util.Set JavaDoc;
57
58 import javax.servlet.http.HttpServletRequest JavaDoc;
59 import javax.servlet.http.HttpServletResponse JavaDoc;
60 import javax.servlet.jsp.PageContext JavaDoc;
61
62 import org.apache.commons.logging.Log;
63
64 /**
65  * Provides methods for building the permission settings dialog.<p>
66  *
67  * The following files use this class:
68  * <ul>
69  * <li>/commons/chacc.jsp
70  * </ul>
71  * <p>
72  *
73  * @author Andreas Zahner
74  *
75  * @version $Revision: 1.24 $
76  *
77  * @since 6.0.0
78  */

79 public class CmsChacc extends CmsDialog {
80
81     /** Value for the action: add an access control entry. */
82     public static final int ACTION_ADDACE = 300;
83     
84     /** Value for the action: delete the permissions. */
85     public static final int ACTION_DELETE = 200;
86     
87     /** Value for the action: set the internal use flag. */
88     public static final int ACTION_INTERNALUSE = 400;
89
90     /** Request parameter value for the action: add an access control entry. */
91     public static final String JavaDoc DIALOG_ADDACE = "addace";
92     
93     /** Request parameter value for the action: delete the permissions. */
94     public static final String JavaDoc DIALOG_DELETE = "delete";
95     
96     /** Request parameter value for the action: set the internal use flag. */
97     public static final String JavaDoc DIALOG_INTERNALUSE = "internaluse";
98     
99     /** The dialog type. */
100     public static final String JavaDoc DIALOG_TYPE = "chacc";
101
102     /** Request parameter name for the inherit permissions parameter. */
103     public static final String JavaDoc PARAM_INHERIT = "inherit";
104     
105     /** Request parameter name for the internal use only flag. */
106     public static final String JavaDoc PARAM_INTERNAL = "internal";
107     
108     /** Request parameter name for the name parameter. */
109     public static final String JavaDoc PARAM_NAME = "name";
110     
111     /** Request parameter name for the overwrite inherited permissions parameter. */
112     public static final String JavaDoc PARAM_OVERWRITEINHERITED = "overwriteinherited";
113     
114     /** Request parameter name for the responsible parameter. */
115     public static final String JavaDoc PARAM_RESPONSIBLE = "responsible";
116     
117     /** Request parameter name for the type parameter. */
118     public static final String JavaDoc PARAM_TYPE = "type";
119     
120     /** Request parameter name for the view parameter. */
121     public static final String JavaDoc PARAM_VIEW = "view";
122
123     /** Constant for the request parameters suffix: allow. */
124     public static final String JavaDoc PERMISSION_ALLOW = "allow";
125     
126     /** Constant for the request parameters suffix: deny. */
127     public static final String JavaDoc PERMISSION_DENY = "deny";
128
129     /** The log object for this class. */
130     private static final Log LOG = CmsLog.getLog(CmsChacc.class);
131
132     /** PermissionSet of the current user for the resource. */
133     private CmsPermissionSet m_curPermissions;
134
135     /** Indicates if forms are editable by current user. */
136     private boolean m_editable;
137
138     /** Stores eventual error message Strings. */
139     private ArrayList JavaDoc m_errorMessages = new ArrayList JavaDoc();
140
141     /** Indicates if inheritance flags are set as hidden fields for resource folders. */
142     private boolean m_inherit;
143
144     /** The name parameter. */
145     private String JavaDoc m_paramName;
146     
147     /** The type parameter. */
148     private String JavaDoc m_paramType;
149
150     /** Stores all possible permission keys of a permission set. */
151     private Set m_permissionKeys = CmsPermissionSet.getPermissionKeys();
152
153     /** Marks if the inherited permissions information should be displayed. */
154     private boolean m_showInheritedPermissions;
155
156     /** The possible types of new access control entries. */
157     private String JavaDoc[] m_types = {I_CmsPrincipal.PRINCIPAL_GROUP, I_CmsPrincipal.PRINCIPAL_USER};
158
159     /** The possible type values of access control entries. */
160     private int[] m_typesInt = {CmsAccessControlEntry.ACCESS_FLAGS_GROUP, CmsAccessControlEntry.ACCESS_FLAGS_USER};
161
162     /** The possible localized types of new access control entries. */
163     private String JavaDoc[] m_typesLocalized = new String JavaDoc[2];
164
165     /**
166      * Public constructor.<p>
167      *
168      * @param jsp an initialized JSP action element
169      */

170     public CmsChacc(CmsJspActionElement jsp) {
171
172         super(jsp);
173         m_errorMessages.clear();
174     }
175
176     /**
177      * Public constructor with JSP variables.<p>
178      *
179      * @param context the JSP page context
180      * @param req the JSP request
181      * @param res the JSP response
182      */

183     public CmsChacc(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
184
185         this(new CmsJspActionElement(context, req, res));
186     }
187
188     /**
189      * Adds a new access control entry to the resource.<p>
190      *
191      * @return true if a new ace was created, otherwise false
192      */

193     public boolean actionAddAce() {
194
195         String JavaDoc file = getParamResource();
196         String JavaDoc name = getParamName();
197         String JavaDoc type = getParamType();
198         int arrayPosition = -1;
199         try {
200             arrayPosition = Integer.parseInt(type);
201         } catch (Exception JavaDoc e) {
202             // can usually be ignored
203
if (LOG.isInfoEnabled()) {
204                 LOG.info(e.getLocalizedMessage());
205             }
206         }
207
208         if (checkNewEntry(name, arrayPosition)) {
209             String JavaDoc permissionString = "";
210             if (getInheritOption() && getSettings().getUserSettings().getDialogPermissionsInheritOnFolder()) {
211                 // inherit permissions on folders if setting is enabled
212
permissionString = "+i";
213             }
214             try {
215                 // lock resource if autolock is enabled
216
checkLock(getParamResource());
217                 getCms().chacc(file, getTypes()[arrayPosition], name, permissionString);
218                 return true;
219             } catch (CmsException e) {
220                 m_errorMessages.add(e.getMessage());
221             }
222         }
223         return false;
224     }
225
226     /**
227      * Modifies the Internal Use flag of a resource.<p>
228      * @param request the Http servlet request
229      *
230      * @return true if the operation was was successfully removed, otherwise false
231      */

232     public boolean actionInternalUse(HttpServletRequest JavaDoc request) {
233
234         String JavaDoc internal = request.getParameter(PARAM_INTERNAL);
235
236         CmsResource resource;
237         boolean internalValue = false;
238         if (internal != null) {
239             internalValue = true;
240         }
241         try {
242             resource = getCms().readResource(getParamResource(), CmsResourceFilter.ALL);
243
244             int flags = resource.getFlags();
245
246             if (internalValue) {
247                 if ((flags & CmsResource.FLAG_INTERNAL) == 0) {
248                     flags += CmsResource.FLAG_INTERNAL;
249                 }
250             } else {
251                 if ((flags & CmsResource.FLAG_INTERNAL) > 0) {
252                     flags -= CmsResource.FLAG_INTERNAL;
253                 }
254             }
255
256             getCms().lockResource(getParamResource());
257             getCms().chflags(getParamResource(), flags);
258
259         } catch (CmsException e) {
260             m_errorMessages.add(key(Messages.ERR_MODIFY_INTERNAL_FLAG_0));
261             return false;
262         }
263         return true;
264     }
265
266     /**
267      * Modifies a present access control entry for a resource.<p>
268      *
269      * @param request the Http servlet request
270      * @return true if the modification worked, otherwise false
271      */

272     public boolean actionModifyAce(HttpServletRequest JavaDoc request) {
273
274         String JavaDoc file = getParamResource();
275
276         // get request parameters
277
String JavaDoc name = getParamName();
278         String JavaDoc type = getParamType();
279         String JavaDoc inherit = request.getParameter(PARAM_INHERIT);
280         String JavaDoc overWriteInherited = request.getParameter(PARAM_OVERWRITEINHERITED);
281         String JavaDoc responsible = request.getParameter(PARAM_RESPONSIBLE);
282         
283         // get the new permissions
284
Set permissionKeys = CmsPermissionSet.getPermissionKeys();
285         int allowValue = 0;
286         int denyValue = 0;
287         String JavaDoc key, param;
288         int value, paramInt;
289
290         Iterator JavaDoc i = permissionKeys.iterator();
291         // loop through all possible permissions
292
while (i.hasNext()) {
293             key = (String JavaDoc)i.next();
294             value = CmsPermissionSet.getPermissionValue(key);
295             // set the right allowed and denied permissions from request parameters
296
try {
297                 param = request.getParameter(value + PERMISSION_ALLOW);
298                 paramInt = Integer.parseInt(param);
299                 allowValue |= paramInt;
300             } catch (Exception JavaDoc e) {
301                 // can usually be ignored
302
if (LOG.isInfoEnabled()) {
303                     LOG.info(e.getLocalizedMessage());
304                 }
305             }
306             try {
307                 param = request.getParameter(value + PERMISSION_DENY);
308                 paramInt = Integer.parseInt(param);
309                 denyValue |= paramInt;
310             } catch (Exception JavaDoc e) {
311                 // can usually be ignored
312
if (LOG.isInfoEnabled()) {
313                     LOG.info(e.getLocalizedMessage());
314                 }
315             }
316
317         }
318
319         // get the current Ace to get the current ace flags
320
try {
321             List allEntries = getCms().getAccessControlEntries(file, false);
322             int flags = 0;
323             for (int k = 0; k < allEntries.size(); k++) {
324                 CmsAccessControlEntry curEntry = (CmsAccessControlEntry)allEntries.get(k);
325                 String JavaDoc curType = getEntryType(curEntry.getFlags());
326                 String JavaDoc curName = getCms().lookupPrincipal(curEntry.getPrincipal()).getName();
327                 if (curName.equals(name) && curType.equals(type)) {
328                     flags = curEntry.getFlags();
329                     break;
330                 }
331             }
332
333             // modify the ace flags to determine inheritance of the current ace
334
if (Boolean.valueOf(inherit).booleanValue()) {
335                 flags |= CmsAccessControlEntry.ACCESS_FLAGS_INHERIT;
336             } else {
337                 flags &= ~CmsAccessControlEntry.ACCESS_FLAGS_INHERIT;
338             }
339
340             // modify the ace flags to determine overwriting of inherited ace
341
if (Boolean.valueOf(overWriteInherited).booleanValue()) {
342                 flags |= CmsAccessControlEntry.ACCESS_FLAGS_OVERWRITE;
343             } else {
344                 flags &= ~CmsAccessControlEntry.ACCESS_FLAGS_OVERWRITE;
345             }
346             
347             if (Boolean.valueOf(responsible).booleanValue()) {
348                 flags |= CmsAccessControlEntry.ACCESS_FLAGS_RESPONSIBLE;
349             } else {
350                 flags &= ~CmsAccessControlEntry.ACCESS_FLAGS_RESPONSIBLE;
351             }
352
353             // lock resource if autolock is enabled
354
checkLock(getParamResource());
355             // try to change the access entry
356
getCms().chacc(file, type, name, allowValue, denyValue, flags);
357             return true;
358         } catch (CmsException e) {
359             m_errorMessages.add(key(Messages.ERR_CHACC_MODIFY_ENTRY_0));
360             return false;
361         }
362     }
363
364     /**
365      * Removes a present access control entry from the resource.<p>
366      *
367      * @return true if the ace was successfully removed, otherwise false
368      */

369     public boolean actionRemoveAce() {
370
371         String JavaDoc file = getParamResource();
372         String JavaDoc name = getParamName();
373         String JavaDoc type = getParamType();
374         try {
375             // lock resource if autolock is enabled
376
checkLock(getParamResource());
377             getCms().rmacc(file, type, name);
378             return true;
379         } catch (CmsException e) {
380             m_errorMessages.add(key(Messages.ERR_CHACC_DELETE_ENTRY_0));
381             return false;
382         }
383     }
384
385     /**
386      * Builds a String with HTML code to display the users access rights for the current resource.<p>
387      *
388      * @return HTML String with the access rights of the current user
389      */

390     public String JavaDoc buildCurrentPermissions() {
391
392         StringBuffer JavaDoc result = new StringBuffer JavaDoc(dialogToggleStart(key(Messages.GUI_PERMISSION_USER_0), "userpermissions", getSettings().getUserSettings().getDialogExpandUserPermissions()));
393         result.append(dialogWhiteBoxStart());
394         result.append(buildPermissionEntryForm(getSettings().getUser().getId(), getCurPermissions(), false, false));
395         result.append(dialogWhiteBoxEnd());
396         result.append("</div>\n");
397         return result.toString();
398     }
399
400     /**
401      * Returns the error messages if something went wrong.<p>
402      *
403      * @return all error messages
404      */

405     public String JavaDoc buildErrorMessages() {
406
407         StringBuffer JavaDoc result = new StringBuffer JavaDoc(8);
408         String JavaDoc errorMessages = getErrorMessagesString();
409         if (!"".equals(errorMessages)) {
410             result.append(dialogBlock(HTML_START, key(Messages.GUI_PERMISSION_ERROR_0), true));
411             result.append(errorMessages);
412             result.append(dialogBlockEnd());
413         }
414         return result.toString();
415     }
416
417     /**
418      * Builds a detail view selector.<p>
419      *
420      * @param wp the dialog object
421      * @return the HTML code for the detail view selector
422      */

423     public static String JavaDoc buildSummaryDetailsButtons(CmsDialog wp) {
424         StringBuffer JavaDoc result = new StringBuffer JavaDoc(512);
425         // create detail view selector
426
result.append("<table border=\"0\">\n<tr>\n\t<td>");
427         result.append(wp.key(Messages.GUI_PERMISSION_SELECT_VIEW_0));
428         result.append("</td>\n");
429         String JavaDoc selectedView = wp.getSettings().getPermissionDetailView();
430         result.append("\t<form action=\"").append(wp.getDialogUri()).append(
431             "\" method=\"post\" name=\"selectshortview\">\n");
432         result.append("\t<td>\n");
433         result.append("\t<input type=\"hidden\" name=\"");
434         result.append(PARAM_VIEW);
435         result.append("\" value=\"short\">\n");
436         // set parameters to show correct hidden input fields
437
wp.setParamAction(null);
438         result.append(wp.paramsAsHidden());
439         result.append("\t<input type=\"submit\" class=\"dialogbutton\" value=\"").append(wp.key(Messages.GUI_LABEL_SUMMARY_0)).append(
440             "\"");
441         if (!"long".equals(selectedView)) {
442             result.append(" disabled=\"disabled\"");
443         }
444         result.append(">\n");
445         result.append("\t</td>\n");
446         result.append("\t</form>\n\t<form action=\"").append(wp.getDialogUri()).append(
447             "\" method=\"post\" name=\"selectlongview\">\n");
448         result.append("\t<td>\n");
449         result.append("\t<input type=\"hidden\" name=\"");
450         result.append(PARAM_VIEW);
451         result.append("\" value=\"long\">\n");
452         result.append(wp.paramsAsHidden());
453         result.append("\t<input type=\"submit\" class=\"dialogbutton\" value=\"").append(wp.key(Messages.GUI_LABEL_DETAILS_0)).append(
454             "\"");
455         if ("long".equals(selectedView)) {
456             result.append(" disabled=\"disabled\"");
457         }
458         result.append(">\n");
459         result.append("\t</td>\n\t</form>\n");
460         result.append("</tr>\n</table>\n");
461         return result.toString();
462     }
463     
464     
465     /**
466      * Builds a String with HTML code to display the inherited and own access control entries of a resource.<p>
467      *
468      * @return HTML code for inherited and own entries of the current resource
469      */

470     public String JavaDoc buildRightsList() {
471
472         StringBuffer JavaDoc result = new StringBuffer JavaDoc(dialogToggleStart(key(Messages.GUI_PERMISSION_BEQUEATH_SUBFOLDER_0), "inheritedpermissions",
473             getSettings().getUserSettings().getDialogExpandInheritedPermissions() || getShowInheritedPermissions()));
474
475         //result.append(buildSummaryDetailsButtons(this));
476

477         // get all access control entries of the current file
478
List allEntries = new ArrayList JavaDoc();
479         try {
480             allEntries = getCms().getAccessControlEntries(getParamResource(), true);
481         } catch (CmsException e) {
482             // can usually be ignored
483
if (LOG.isInfoEnabled()) {
484                 LOG.info(e.getLocalizedMessage());
485             }
486         }
487
488         // store all parent folder ids together with path in a map
489
Map JavaDoc parents = new HashMap JavaDoc();
490         String JavaDoc path = CmsResource.getParentFolder(getParamResource());
491         List parentResources = new ArrayList JavaDoc();
492         try {
493             // get all parent folders of the current file
494
parentResources = getCms().readPath(path, CmsResourceFilter.IGNORE_EXPIRATION);
495         } catch (CmsException e) {
496             // can usually be ignored
497
if (LOG.isInfoEnabled()) {
498                 LOG.info(e.getLocalizedMessage());
499             }
500         }
501         Iterator JavaDoc k = parentResources.iterator();
502         while (k.hasNext()) {
503             // add the current folder to the map
504
CmsResource curRes = (CmsResource)k.next();
505             parents.put(curRes.getResourceId(), curRes.getRootPath());
506         }
507
508         // create new ArrayLists in which inherited and non inherited entries are stored
509
ArrayList JavaDoc ownEntries = new ArrayList JavaDoc(0);
510         ArrayList JavaDoc inheritedEntries = new ArrayList JavaDoc(0);
511
512         for (int i = 0; i < allEntries.size(); i++) {
513             CmsAccessControlEntry curEntry = (CmsAccessControlEntry)allEntries.get(i);
514             if (curEntry.isInherited()) {
515                 // add the entry to the inherited rights list for the "long" view
516
if ("long".equals(getSettings().getPermissionDetailView())) {
517                     inheritedEntries.add(curEntry);
518                 }
519             } else {
520                 // add the entry to the own rights list
521
ownEntries.add(curEntry);
522             }
523         }
524
525         // now create the inherited entries box
526
result.append(dialogWhiteBox(HTML_START));
527         result.append(buildInheritedList(inheritedEntries, parents));
528         result.append(dialogWhiteBox(HTML_END));
529
530         // close div that toggles visibility of inherited permissions
531
result.append("</div>");
532
533         // create the add user/group form
534
result.append(buildAddForm());
535
536         // create the resource entries box
537
result.append(buildResourceList(ownEntries));
538
539         return result.toString();
540     }
541
542     /**
543      * Returns the current users permission set on the resource.<p>
544      *
545      * @return the users permission set
546      */

547     public CmsPermissionSet getCurPermissions() {
548
549         return m_curPermissions;
550     }
551
552     /**
553      * Returns a list with all error messages which occured when trying to add a new access control entry.<p>
554      *
555      * @return List of error message Strings
556      */

557     public ArrayList JavaDoc getErrorMessages() {
558
559         return m_errorMessages;
560     }
561
562     /**
563      * Returns a String with all error messages occuring when trying to add a new access control entry.<p>
564      *
565      * @return String with error messages, separated by &lt;br&gt;
566      */

567     public String JavaDoc getErrorMessagesString() {
568
569         StringBuffer JavaDoc errors = new StringBuffer JavaDoc(8);
570         Iterator JavaDoc i = getErrorMessages().iterator();
571         while (i.hasNext()) {
572             errors.append((String JavaDoc)i.next());
573             if (i.hasNext()) {
574                 errors.append("<br>");
575             }
576         }
577         return errors.toString();
578     }
579
580     /**
581      * Returns the value of the name parameter,
582      * or null if this parameter was not provided.<p>
583      *
584      * The name parameter stores the name of the group or user.<p>
585      *
586      * @return the value of the name parameter
587      */

588     public String JavaDoc getParamName() {
589
590         return m_paramName;
591     }
592
593     /**
594      * Returns the value of the type parameter,
595      * or null if this parameter was not provided.<p>
596      *
597      * The type parameter stores the type of an ace (group or user).<p>
598      *
599      * @return the value of the type parameter
600      */

601     public String JavaDoc getParamType() {
602
603         return m_paramType;
604     }
605
606     /**
607      * Initializes some member variables to display the form with the right options for the current user.<p>
608      *
609      * This method must be called after initWorkplaceRequestValues().<p>
610      */

611     public void init() {
612
613         // the current user name
614
String JavaDoc userName = getSettings().getUser().getName();
615
616         if (m_typesLocalized[0] == null) {
617             m_typesLocalized[0] = key(Messages.GUI_LABEL_GROUP_0);
618             m_typesLocalized[1] = key(Messages.GUI_LABEL_USER_0);
619         }
620
621         // set flags to show editable or non editable entries
622
setEditable(false);
623         setInheritOption(false);
624         String JavaDoc resName = getParamResource();
625
626         try {
627             // get the current users' permissions
628
setCurPermissions(getCms().getPermissions(getParamResource(), userName));
629
630             // check if the current resource is a folder
631
CmsResource resource = getCms().readResource(getParamResource(), CmsResourceFilter.ALL);
632             if (resource.isFolder()) {
633                 // only folders have the inherit option activated
634
setInheritOption(true);
635                 if (! resName.endsWith("/")) {
636                     // append manually a "/" to folder name to avoid issues with check if resource is in project
637
resName += "/";
638                 }
639             }
640         } catch (CmsException e) {
641             // can usually be ignored
642
if (LOG.isInfoEnabled()) {
643                 LOG.info(e.getLocalizedMessage());
644             }
645         }
646         
647         // check the current users permission to change access control entries
648
if ((!getCms().getRequestContext().currentProject().isOnlineProject() && getCms().isInsideCurrentProject(resName))
649             && (getCms().hasRole(CmsRole.VFS_MANAGER) || ((m_curPermissions.getAllowedPermissions()
650             & CmsPermissionSet.PERMISSION_CONTROL) > 0 && !((m_curPermissions.getDeniedPermissions()
651             & CmsPermissionSet.PERMISSION_CONTROL) > 0)))) {
652             setEditable(true);
653         }
654     }
655
656     /**
657      * Sets the value of the name parameter.<p>
658      *
659      * @param value the value to set
660      */

661     public void setParamName(String JavaDoc value) {
662
663         m_paramName = value;
664     }
665
666     /**
667      * Sets the value of the type parameter.<p>
668      *
669      * @param value the value to set
670      */

671     public void setParamType(String JavaDoc value) {
672
673         m_paramType = value;
674     }
675
676     /**
677      * Validates the user input when creating a new access control entry.<p>
678      *
679      * @param name the name of the new user/group
680      * @param arrayPosition the position in the types array
681      * @return true if everything is ok, otherwise false
682      */

683     protected boolean checkNewEntry(String JavaDoc name, int arrayPosition) {
684
685         m_errorMessages.clear();
686         boolean inArray = false;
687         if (getTypes()[arrayPosition] != null) {
688             inArray = true;
689         }
690         if (!inArray) {
691             m_errorMessages.add(key(Messages.ERR_PERMISSION_SELECT_TYPE_0));
692         }
693         if (CmsStringUtil.isEmptyOrWhitespaceOnly(name)) {
694             m_errorMessages.add(key(Messages.ERR_MISSING_GROUP_OR_USER_NAME_0));
695         }
696         if (m_errorMessages.size() > 0) {
697             return false;
698         }
699         return true;
700     }
701
702     /**
703      * Returns the resource on which the specified access control entry was set.<p>
704      *
705      * @param entry the current access control entry
706      * @param parents the parent resources to determine the connected resource
707      * @return the resource name of the corresponding resource
708      */

709     protected String JavaDoc getConnectedResource(CmsAccessControlEntry entry, Map JavaDoc parents) {
710
711         CmsUUID resId = entry.getResource();
712         String JavaDoc resName = (String JavaDoc)parents.get(resId);
713         if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(resName)) {
714             return resName;
715         }
716         return resId.toString();
717     }
718
719     /**
720      * Returns the current editable flag for the user to change ACEs.<p>
721      *
722      * @return true if user can edit the permissions, otherwise false
723      */

724     protected boolean getEditable() {
725
726         return m_editable;
727     }
728
729     /**
730      * Determines the type of the current access control entry.<p>
731      *
732      * @param flags the value of the current flags
733      * @return String representation of the ace type
734      */

735     protected String JavaDoc getEntryType(int flags) {
736
737         for (int i = 0; i < getTypes().length; i++) {
738             if ((flags & getTypesInt()[i]) > 0) {
739                 return getTypes()[i];
740             }
741         }
742         return "Unknown";
743     }
744
745     /**
746      * Determines the int type of the current access control entry.<p>
747      *
748      * @param flags the value of the current flags
749      * @return int representation of the ace type as int
750      */

751     protected int getEntryTypeInt(int flags) {
752
753         for (int i = 0; i < getTypes().length; i++) {
754             if ((flags & getTypesInt()[i]) > 0) {
755                 return i;
756             }
757         }
758         return -1;
759     }
760
761     /**
762      * Returns if the access control entry can be inherited to subfolders and can overwrite inherited permissions.<p>
763      *
764      * @return true to show the checkbox, otherwise false
765      */

766     protected boolean getInheritOption() {
767
768         return m_inherit;
769     }
770
771     /**
772      * Returns if the inherited permissions information should be displayed.<p>
773      *
774      * @return true if the inherited permissions information should be displayed, otherwise false
775      */

776     public boolean getShowInheritedPermissions() {
777
778         return m_showInheritedPermissions;
779     }
780
781     /**
782      * Returns a String array with the possible entry types.<p>
783      *
784      * @return the possible types
785      */

786     protected String JavaDoc[] getTypes() {
787
788         return m_types;
789     }
790
791     /**
792      * Returns an int array with possible entry types.<p>
793      *
794      * @return the possible types as int array
795      */

796     protected int[] getTypesInt() {
797
798         return m_typesInt;
799     }
800
801     /**
802      * Returns a String array with the possible localized entry types.<p>
803      *
804      * @return the possible localized types
805      */

806     protected String JavaDoc[] getTypesLocalized() {
807
808         return m_typesLocalized;
809     }
810
811     /**
812      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
813      */

814     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
815
816         // fill the parameter values in the get/set methods
817
fillParamValues(request);
818
819         // set the detail mode of the "inherited" list view
820
String JavaDoc detail = request.getParameter(PARAM_VIEW);
821         if (detail != null) {
822             settings.setPermissionDetailView(detail);
823             setShowInheritedPermissions(true);
824         }
825
826         // determine which action has to be performed
827
if (DIALOG_TYPE.equals(getParamAction())) {
828             setAction(ACTION_DEFAULT);
829         } else if (DIALOG_SET.equals(getParamAction())) {
830             setAction(ACTION_SET);
831         } else if (DIALOG_DELETE.equals(getParamAction())) {
832             setAction(ACTION_DELETE);
833         } else if (DIALOG_ADDACE.equals(getParamAction())) {
834             setAction(ACTION_ADDACE);
835         } else if (DIALOG_CANCEL.equals(getParamAction())) {
836             setAction(ACTION_CANCEL);
837         } else if (DIALOG_INTERNALUSE.equals(getParamAction())) {
838             setAction(ACTION_INTERNALUSE);
839         } else {
840             setAction(ACTION_DEFAULT);
841             // build the title for chacc dialog
842
setParamTitle(key(Messages.GUI_PERMISSION_CHANGE_1, new Object JavaDoc[] {CmsResource.getName(getParamResource())}));
843         }
844
845     }
846
847     /**
848      * Checks if a certain permission of a permission set is allowed.<p>
849      *
850      * @param p the current CmsPermissionSet
851      * @param value the int value of the permission to check
852      * @return true if the permission is allowed, otherwise false
853      */

854     protected boolean isAllowed(CmsPermissionSet p, int value) {
855
856         if ((p.getAllowedPermissions() & value) > 0) {
857             return true;
858         }
859         return false;
860     }
861
862     /**
863      * Checks if a certain permission of a permission set is denied.<p>
864      *
865      * @param p the current CmsPermissionSet
866      * @param value the int value of the permission to check
867      * @return true if the permission is denied, otherwise false
868      */

869     protected boolean isDenied(CmsPermissionSet p, int value) {
870
871         if ((p.getDeniedPermissions() & value) > 0) {
872             return true;
873         }
874         return false;
875     }
876
877     /**
878      * Check if the current permissions are inherited to subresources.<p>
879      *
880      * @param flags value of all flags of the current entry
881      * @return true if permissions are inherited to subresources, otherwise false
882      */

883     protected boolean isInheriting(int flags) {
884
885         if ((flags & CmsAccessControlEntry.ACCESS_FLAGS_INHERIT) > 0) {
886             return true;
887         }
888         return false;
889     }
890
891     /**
892      * Check if the current permissions are overwriting the inherited ones.<p>
893      *
894      * @param flags value of all flags of the current entry
895      * @return true if permissions are overwriting the inherited ones, otherwise false
896      */

897     protected boolean isOverWritingInherited(int flags) {
898
899         if ((flags & CmsAccessControlEntry.ACCESS_FLAGS_OVERWRITE) > 0) {
900             return true;
901         }
902         return false;
903     }
904
905     /**
906      * Check if the user is a responsible for the resource.<p>
907      *
908      * @param flags value of all flags of the current entry
909      * @return true if user is responsible for the resource, otherwise false
910      */

911     protected boolean isResponsible(int flags) {
912
913         if ((flags & CmsAccessControlEntry.ACCESS_FLAGS_RESPONSIBLE) > 0) {
914             return true;
915         }
916         return false;
917     }
918     
919     /**
920      * Sets the current users permissions on the resource.
921      * This is set in the init() method.<p>
922      *
923      * @param value the CmsPermissionSet
924      */

925     protected void setCurPermissions(CmsPermissionSet value) {
926
927         m_curPermissions = value;
928     }
929
930     /**
931      * Sets the editable flag for the forms.
932      * This is set in the init() method.<p>
933      *
934      * @param value true if user can edit the permissions, otherwise false
935      */

936     protected void setEditable(boolean value) {
937
938         m_editable = value;
939     }
940
941     /**
942      * Sets if the access control entry can be inherited to subfolders and can overwrite inherited permissions.<p>
943      *
944      * This is set in the init() method.<p>
945      *
946      * @param value set to true for folders, otherwise false
947      */

948     protected void setInheritOption(boolean value) {
949
950         m_inherit = value;
951     }
952
953     /**
954      * Sets if the inherited permissions information should be displayed.<p>
955      *
956      * @param showInheritedPermissions true if the inherited permissions information should be displayed, otherwise false
957      */

958     protected void setShowInheritedPermissions(boolean showInheritedPermissions) {
959
960         m_showInheritedPermissions = showInheritedPermissions;
961     }
962
963     /**
964      * Builds a String with HTML code to display the form to add a new access control entry for the current resource.<p>
965      *
966      * @return HTML String with the form
967      */

968     private String JavaDoc buildAddForm() {
969
970         StringBuffer JavaDoc result = new StringBuffer JavaDoc(256);
971
972         // only display form if the current user has the "control" right
973
if (getEditable()) {
974             result.append(dialogSpacer());
975             result.append(dialogBlockStart(key(Messages.GUI_PERMISSION_ADD_ACE_0)));
976
977             // get all possible entry types
978
ArrayList JavaDoc options = new ArrayList JavaDoc();
979             ArrayList JavaDoc optionValues = new ArrayList JavaDoc();
980             for (int i = 0; i < getTypes().length; i++) {
981                 options.add(getTypesLocalized()[i]);
982                 optionValues.add(Integer.toString(i));
983             }
984
985             // create the input form for adding an ace
986
result.append("<form action=\"").append(getDialogUri()).append(
987                 "\" method=\"post\" name=\"add\" class=\"nomargin\">\n");
988             // set parameters to show correct hidden input fields
989
setParamAction(DIALOG_ADDACE);
990             setParamType(null);
991             setParamName(null);
992             result.append(paramsAsHidden());
993             result.append("<table border=\"0\" width=\"100%\">\n");
994             result.append("<tr>\n");
995             result.append("\t<td>").append(buildSelect("name=\"" + PARAM_TYPE + "\"", options, optionValues, -1)).append("</td>\n");
996             result.append("\t<td class=\"maxwidth\"><input type=\"text\" class=\"maxwidth\" name=\"");
997             result.append(PARAM_NAME);
998             result.append("\" value=\"\"></td>\n");
999             result.append("\t<td><input class=\"dialogbutton\" style=\"width: 60px;\" type=\"button\" value=\"");
1000            result.append(key(Messages.GUI_LABEL_SEARCH_0)).append(
1001                "\" onClick=\"javascript:openDialogWin('chaccbrowser.jsp','UserGroup');\"></td>\n");
1002            result.append("\t<td><input class=\"dialogbutton\" type=\"submit\" value=\"").append(key(Messages.GUI_LABEL_ADD_0)).append(
1003                "\"></td>\n");
1004            result.append("</tr>\n");
1005            result.append("</form>\n");
1006            result.append("</table>\n");
1007
1008            result.append(dialogBlockEnd());
1009        }
1010        return result.toString();
1011    }
1012
1013    /**
1014     * Builds a StringBuffer with HTML code to show a list of all inherited access control entries.<p>
1015     *
1016     * @param entries ArrayList with all entries to show for the long view
1017     * @param parents Map of parent resources needed to get the connected resources for the detailed view
1018     * @return StringBuffer with HTML code for all entries
1019     */

1020    private StringBuffer JavaDoc buildInheritedList(ArrayList JavaDoc entries, Map JavaDoc parents) {
1021
1022        StringBuffer JavaDoc result = new StringBuffer JavaDoc(32);
1023        String JavaDoc view = getSettings().getPermissionDetailView();
1024        Iterator JavaDoc i;
1025
1026        // display the long view
1027
if ("long".equals(view)) {
1028            i = entries.iterator();
1029            while (i.hasNext()) {
1030                CmsAccessControlEntry curEntry = (CmsAccessControlEntry)i.next();
1031                // build the list with enabled extended view and resource name
1032
result.append(buildPermissionEntryForm(curEntry, false, true, getConnectedResource(curEntry, parents)));
1033            }
1034        } else {
1035            // show the short view, use an ACL to build the list
1036
try {
1037                // get the inherited ACL of the parent folder
1038
CmsAccessControlList acList = getCms().getAccessControlList(getParamResource(), true);
1039                Set principalSet = acList.getPrincipals();
1040                i = principalSet.iterator();
1041                while (i.hasNext()) {
1042                    CmsUUID principalId = (CmsUUID)i.next();
1043                    I_CmsPrincipal principal = getCms().lookupPrincipal(principalId);
1044                    CmsPermissionSet permissions = acList.getPermissions(principal);
1045                    // build the list with enabled extended view only
1046
result.append(buildPermissionEntryForm(principalId, permissions, false, true));
1047                }
1048            } catch (CmsException e) {
1049                // can usually be ignored
1050
if (LOG.isInfoEnabled()) {
1051                    LOG.info(e.getLocalizedMessage());
1052                }
1053            }
1054        }
1055        return result;
1056    }
1057
1058    /**
1059     * Builds a String with HTML code to display the form to add a new access control entry for the current resource.<p>
1060     *
1061     * @return HTML String with the form
1062     */

1063    private String JavaDoc buildInternalForm() {
1064
1065        StringBuffer JavaDoc result = new StringBuffer JavaDoc(128);
1066
1067        CmsResource resource = null;
1068        boolean internal = false;
1069
1070        // try to read the internal flag from the resource
1071
try {
1072            resource = getCms().readResource(getParamResource(), CmsResourceFilter.ALL);
1073            internal = ((resource.getFlags() & CmsResource.FLAG_INTERNAL) > 0);
1074        } catch (CmsException e) {
1075            // an error occured reading the resource
1076
LOG.error(e.getLocalizedMessage());
1077        }
1078
1079        if ((resource != null) && (resource.isFile())) {
1080            // only show internal checkbox on files
1081
result.append("<form action=\"").append(getDialogUri()).append(
1082                "\" method=\"post\" name=\"internal\" class=\"nomargin\">\n");
1083            result.append("<table border=\"0\" width=\"100%\">\n");
1084            result.append("<tr>\n");
1085            result.append("\t<td class=\"dialogpermissioncell\">").append(key(Messages.GUI_PERMISSION_INTERNAL_0));
1086            result.append(" <input type=\"checkbox\" name=\"");
1087            result.append(PARAM_INTERNAL);
1088            result.append("\" value=\"true\"");
1089            if (internal) {
1090                result.append(" checked=\"checked\"");
1091            }
1092            if (!getEditable()) {
1093                result.append(" disabled=\"disabled\"");
1094            }
1095            result.append(" ></td>\n");
1096            if (getEditable()) {
1097                result.append("<td><input type=\"submit\" class=\"dialogbutton\" value=\"").append(
1098                    key(Messages.GUI_LABEL_SET_0)).append("\">");
1099            }
1100            result.append("</td>\n");
1101            result.append("</tr>\n");
1102            result.append("</table>\n");
1103            setParamAction(DIALOG_INTERNALUSE);
1104            setParamType(null);
1105            setParamName(null);
1106            result.append(paramsAsHidden());
1107            result.append("</form>\n");
1108        }
1109        return result.toString();
1110
1111    }
1112
1113    /**
1114     * Creates an HTML input form for the current access control entry.<p>
1115     *
1116     * @param entry the current access control entry
1117     * @param editable boolean to determine if the form is editable
1118     * @param extendedView boolean to determine if the view is selectable with DHTML
1119     * @param inheritRes the resource name from which the ace is inherited
1120     * @return StringBuffer with HTML code of the form
1121     */

1122    private StringBuffer JavaDoc buildPermissionEntryForm(
1123        CmsAccessControlEntry entry,
1124        boolean editable,
1125        boolean extendedView,
1126        String JavaDoc inheritRes) {
1127
1128        StringBuffer JavaDoc result = new StringBuffer JavaDoc(8);
1129
1130        // get name and type of the current entry
1131
I_CmsPrincipal principal = getCms().lookupPrincipal(entry.getPrincipal());
1132        String JavaDoc name = (principal != null) ? principal.getName() : entry.getPrincipal().toString();
1133        String JavaDoc type = getEntryType(entry.getFlags());
1134
1135        if (name == null) {
1136            name = "";
1137        }
1138
1139        // set the parameters for the hidden fields
1140
setParamType(type);
1141        setParamName(name);
1142
1143        // set id value for html attributes
1144
String JavaDoc idValue = type + name + entry.getResource();
1145
1146        // get the localized type label
1147
String JavaDoc typeLocalized = getTypesLocalized()[getEntryTypeInt(entry.getFlags())];
1148
1149        // determine the right image to display
1150
String JavaDoc typeImg = getEntryType(entry.getFlags()).toLowerCase();
1151
1152        // get all permissions of the current entry
1153
CmsPermissionSet permissions = entry.getPermissions();
1154
1155        // build String for disabled check boxes
1156
String JavaDoc disabled = "";
1157        if (!editable) {
1158            disabled = " disabled=\"disabled\"";
1159        }
1160
1161        // build the heading
1162
result.append(dialogRow(HTML_START));
1163        if (extendedView) {
1164            // for extended view, add toggle symbol and link to output
1165
result.append("<a HREF=\"javascript:toggleDetail('").append(idValue).append("');\">");
1166            result.append("<img SRC=\"").append(getSkinUri()).append("commons/plus.png\" class=\"noborder\" id=\"ic-").append(
1167                idValue).append("\"></a>");
1168        }
1169        result.append("<img SRC=\"").append(getSkinUri()).append("commons/");
1170        result.append(typeImg);
1171        result.append(".png\" class=\"noborder\" width=\"16\" height=\"16\" alt=\"");
1172        result.append(typeLocalized);
1173        result.append("\" title=\"");
1174        result.append(typeLocalized);
1175        result.append("\">&nbsp;<span class=\"textbold\">");
1176        result.append(name);
1177        result.append("</span>");
1178
1179        if (extendedView) {
1180            // for extended view, add short permissions and hidden div
1181
result.append("&nbsp;(").append(entry.getPermissions().getPermissionString()).append(entry.getResponsibleString()).append(")");
1182            result.append(dialogRow(HTML_END));
1183            // show the resource from which the ace is inherited if present
1184
if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(inheritRes)) {
1185                result.append("<div class=\"dialogpermissioninherit\">");
1186                result.append(key(Messages.GUI_PERMISSION_INHERITED_FROM_1, new Object JavaDoc[] {inheritRes}));
1187                result.append("</div>\n");
1188            }
1189            result.append("<div id =\"").append(idValue).append("\" class=\"hide\">");
1190        } else {
1191            result.append(dialogRow(HTML_END));
1192        }
1193
1194        result.append("<table class=\"dialogpermissiondetails\">\n");
1195
1196        // build the form depending on the editable flag
1197
if (editable) {
1198            result.append("<form action=\"").append(getDialogUri()).append(
1199                "\" method=\"post\" class=\"nomargin\" name=\"set").append(idValue).append("\">\n");
1200            // set parameters to show correct hidden input fields
1201
setParamAction(DIALOG_SET);
1202            result.append(paramsAsHidden());
1203        } else {
1204            result.append("<form class=\"nomargin\">\n");
1205        }
1206
1207        // build headings for permission descriptions
1208
result.append("<tr>\n");
1209        result.append("\t<td class=\"dialogpermissioncell\"><span class=\"textbold\" unselectable=\"on\">");
1210        result.append(key(Messages.GUI_PERMISSION_0)).append("</span></td>\n");
1211        result.append("\t<td class=\"dialogpermissioncell textcenter\"><span class=\"textbold\" unselectable=\"on\">");
1212        result.append(key(Messages.GUI_PERMISSION_ALLOWED_0)).append("</span></td>\n");
1213        result.append("\t<td class=\"dialogpermissioncell textcenter\"><span class=\"textbold\" unselectable=\"on\">");
1214        result.append(key(Messages.GUI_PERMISSION_DENIED_0)).append("</span></td>\n");
1215        result.append("</tr>");
1216
1217        Iterator JavaDoc i = m_permissionKeys.iterator();
1218
1219        // show all possible permissions in the form
1220
while (i.hasNext()) {
1221            String JavaDoc key = (String JavaDoc)i.next();
1222            int value = CmsPermissionSet.getPermissionValue(key);
1223            String JavaDoc keyMessage = key(key);
1224            result.append("<tr>\n");
1225            result.append("\t<td class=\"dialogpermissioncell\">").append(keyMessage).append("</td>\n");
1226            result.append("\t<td class=\"dialogpermissioncell textcenter\"><input type=\"checkbox\" name=\"");
1227            result.append(value).append(PERMISSION_ALLOW).append("\" value=\"").append(value).append("\"").append(
1228                disabled);
1229            if (isAllowed(permissions, value)) {
1230                result.append(" checked=\"checked\"");
1231            }
1232            result.append("></td>\n");
1233            result.append("\t<td class=\"dialogpermissioncell textcenter\"><input type=\"checkbox\" name=\"");
1234            result.append(value).append(PERMISSION_DENY).append("\" value=\"").append(value).append("\"").append(
1235                disabled);
1236            if (isDenied(permissions, value)) {
1237                result.append(" checked=\"checked\"");
1238            }
1239            result.append("></td>\n");
1240            result.append("</tr>\n");
1241        }
1242
1243        // show overwrite checkbox and buttons only for editable entries
1244
if (editable) {
1245
1246            // show owner checkbox
1247
result.append("<tr>\n");
1248            result.append("\t<td class=\"dialogpermissioncell\">").append(key(Messages.GUI_LABEL_RESPONSIBLE_0)).append(
1249                "</td>\n");
1250            result.append("\t<td class=\"dialogpermissioncell textcenter\">");
1251            result.append("<input type=\"checkbox\" name=\"").append(PARAM_RESPONSIBLE).append(
1252                "\" value=\"true\"").append(disabled);
1253            if (isResponsible(entry.getFlags())) {
1254                result.append(" checked=\"checked\"");
1255            }
1256            result.append("></td>\n");
1257            result.append("\t<td class=\"dialogpermissioncell\">&nbsp;</td>\n");
1258            result.append("</tr>\n");
1259
1260            // show overwrite inherited checkbox
1261
result.append("<tr>\n");
1262            result.append("\t<td class=\"dialogpermissioncell\">").append(key(Messages.GUI_PERMISSION_OVERWRITE_INHERITED_0)).append(
1263                "</td>\n");
1264            result.append("\t<td class=\"dialogpermissioncell textcenter\">");
1265            result.append("<input type=\"checkbox\" name=\"").append(PARAM_OVERWRITEINHERITED).append(
1266                "\" value=\"true\"").append(disabled);
1267            if (isOverWritingInherited(entry.getFlags())) {
1268                result.append(" checked=\"checked\"");
1269            }
1270            result.append("></td>\n");
1271            result.append("\t<td class=\"dialogpermissioncell\">&nbsp;</td>\n");
1272            result.append("</tr>\n");
1273
1274            // show inherit permissions checkbox on folders
1275
if (getInheritOption()) {
1276                result.append("<tr>\n");
1277                result.append("\t<td class=\"dialogpermissioncell\">").append(key(Messages.GUI_PERMISSION_INHERIT_ON_SUBFOLDERS_0)).append(
1278                    "</td>\n");
1279                result.append("\t<td class=\"dialogpermissioncell textcenter\">");
1280                result.append("<input type=\"checkbox\" name=\"").append(PARAM_INHERIT).append("\" value=\"true\"").append(
1281                    disabled);
1282                if (isInheriting(entry.getFlags())) {
1283                    result.append(" checked=\"checked\"");
1284                }
1285                result.append("></td>\n");
1286                result.append("\t<td class=\"dialogpermissioncell\">&nbsp;</td>\n");
1287                result.append("</tr>\n");
1288            }
1289
1290            // show "set" and "delete" buttons
1291
result.append("<tr>\n");
1292            result.append("\t<td>&nbsp;</td>\n");
1293            result.append("\t<td class=\"textcenter\"><input class=\"dialogbutton\" type=\"submit\" value=\"").append(
1294                key(Messages.GUI_LABEL_SET_0)).append("\"></form></td>\n");
1295            result.append("\t<td class=\"textcenter\">\n");
1296            // build the form for the "delete" button
1297
result.append("\t\t<form class=\"nomargin\" action=\"").append(getDialogUri()).append(
1298                "\" method=\"post\" name=\"delete").append(idValue).append("\">\n");
1299            // set parameters to show correct hidden input fields
1300
setParamAction(DIALOG_DELETE);
1301            result.append(paramsAsHidden());
1302            result.append("\t\t<input class=\"dialogbutton\" type=\"submit\" value=\"").append(key(Messages.GUI_LABEL_DELETE_0)).append(
1303                "\">\n");
1304            result.append("\t\t</form>\n");
1305            result.append("\t</td>\n");
1306            result.append("</tr>\n");
1307        } else {
1308            // close the form
1309
result.append("</form>\n");
1310        }
1311
1312        result.append("</table>\n");
1313        if (extendedView) {
1314            // close the hidden div for extended view
1315
result.append("</div>");
1316        }
1317
1318        return result;
1319    }
1320
1321    /**
1322     * @see #buildPermissionEntryForm(CmsAccessControlEntry, boolean, boolean, String)
1323     *
1324     * @param id the UUID of the principal of the permission set
1325     * @param curSet the current permission set
1326     * @param editable boolean to determine if the form is editable
1327     * @param extendedView boolean to determine if the view is selectable with DHTML
1328     * @return String with HTML code of the form
1329     */

1330    private StringBuffer JavaDoc buildPermissionEntryForm(
1331        CmsUUID id,
1332        CmsPermissionSet curSet,
1333        boolean editable,
1334        boolean extendedView) {
1335
1336        String JavaDoc fileName = getParamResource();
1337        int flags = 0;
1338        try {
1339            // TODO: a more elegant way to determine user/group of current id
1340
try {
1341                getCms().readGroup(id);
1342                flags = CmsAccessControlEntry.ACCESS_FLAGS_GROUP;
1343            } catch (CmsException e) {
1344                try {
1345                    getCms().readUser(id);
1346                    flags = CmsAccessControlEntry.ACCESS_FLAGS_USER;
1347                } catch (CmsException exc) {
1348                    // can usually be ignored
1349
if (LOG.isInfoEnabled()) {
1350                        LOG.info(e.getLocalizedMessage());
1351                    }
1352                }
1353            }
1354            CmsResource res = getCms().readResource(fileName, CmsResourceFilter.ALL);
1355            CmsAccessControlEntry entry = new CmsAccessControlEntry(res.getResourceId(), id, curSet, flags);
1356            return buildPermissionEntryForm(entry, editable, extendedView, null);
1357        } catch (CmsException e) {
1358            // can usually be ignored
1359
if (LOG.isInfoEnabled()) {
1360                LOG.info(e.getLocalizedMessage());
1361            }
1362            return new StringBuffer JavaDoc("");
1363        }
1364    }
1365
1366    /**
1367     * Builds a StringBuffer with HTML code for the access control entries of a resource.<p>
1368     *
1369     * @param entries all access control entries for the resource
1370     * @return StringBuffer with HTML code for all entries
1371     */

1372    private StringBuffer JavaDoc buildResourceList(ArrayList JavaDoc entries) {
1373
1374        StringBuffer JavaDoc result = new StringBuffer JavaDoc(256);
1375        Iterator JavaDoc i = entries.iterator();
1376        boolean hasEntries = i.hasNext();
1377
1378        if (hasEntries || !getInheritOption()) {
1379            // create headline for resource entries
1380
result.append(dialogSubheadline(key(Messages.GUI_PERMISSION_TITLE_0)));
1381        }
1382
1383        // create the internal form
1384
result.append(buildInternalForm());
1385
1386        if (hasEntries) {
1387            // only create output if entries are present
1388
result.append(dialogSpacer());
1389            // open white box
1390
result.append(dialogWhiteBox(HTML_START));
1391
1392            // list all entries
1393
while (i.hasNext()) {
1394                CmsAccessControlEntry curEntry = (CmsAccessControlEntry)i.next();
1395                result.append(buildPermissionEntryForm(curEntry, this.getEditable(), false, null));
1396                if (i.hasNext()) {
1397                    result.append(dialogSeparator());
1398                }
1399            }
1400
1401            // close white box
1402
result.append(dialogWhiteBox(HTML_END));
1403        }
1404        return result;
1405    }
1406
1407    /**
1408     * Builds a String with HTML code to display the responsibles of a resource.<p>
1409     *
1410     * @param show true the responsible list is open
1411     * @return HTML code for the responsibles of the current resource
1412     */

1413    public String JavaDoc buildResponsibleList(boolean show) {
1414    
1415        List parentResources = new ArrayList JavaDoc();
1416        Map JavaDoc responsibles = new HashMap JavaDoc();
1417        CmsObject cms = getCms();
1418        String JavaDoc resourceSitePath = cms.getRequestContext().removeSiteRoot(getParamResource());
1419        try {
1420            // get all parent folders of the current file
1421
parentResources = cms.readPath(getParamResource(), CmsResourceFilter.IGNORE_EXPIRATION);
1422        } catch (CmsException e) {
1423            // can usually be ignored
1424
if (CmsChacc.LOG.isInfoEnabled()) {
1425                CmsChacc.LOG.info(e.getLocalizedMessage());
1426            }
1427        }
1428        Iterator JavaDoc i = parentResources.iterator();
1429        while (i.hasNext()) {
1430            CmsResource resource = (CmsResource)i.next();
1431            try {
1432                String JavaDoc sitePath = resource.getRootPath();
1433                Iterator JavaDoc entries = cms.getAccessControlEntries(cms.getRequestContext().removeSiteRoot(sitePath), false).iterator();
1434                while (entries.hasNext()) {
1435                    CmsAccessControlEntry ace = (CmsAccessControlEntry)entries.next();
1436                    if (ace.isResponsible()) {
1437                        I_CmsPrincipal principal = cms.lookupPrincipal(ace.getPrincipal());
1438                        responsibles.put(principal, sitePath);
1439                    }
1440                }
1441            } catch (CmsException e) {
1442                // can usually be ignored
1443
if (LOG.isInfoEnabled()) {
1444                    LOG.info(e.getLocalizedMessage());
1445                }
1446            }
1447        }
1448    
1449        if (responsibles.size() == 0) {
1450            
1451            return key(Messages.GUI_AVAILABILITY_NO_RESPONSIBLES_0);
1452        }
1453        StringBuffer JavaDoc result = new StringBuffer JavaDoc(512);
1454        result.append(dialogToggleStart(key(Messages.GUI_AVAILABILITY_RESPONSIBLES_0), "responsibles", show));
1455        
1456        result.append(dialogWhiteBoxStart());
1457        i = responsibles.keySet().iterator();
1458        while (i.hasNext()) {
1459            I_CmsPrincipal principal = (I_CmsPrincipal)i.next();
1460            String JavaDoc image = "user.png";
1461            if (principal instanceof CmsGroup) {
1462                image = "group.png";
1463            }
1464            result.append("<div class=\"dialogrow\"><img SRC=\"");
1465            result.append(getSkinUri());
1466            result.append("commons/");
1467            result.append(image);
1468            result.append("\" class=\"noborder\" width=\"16\" height=\"16\" alt=\"Group\" title=\"Group\">&nbsp;<span class=\"textbold\">");
1469            result.append(principal.getName());
1470            result.append("</span>");
1471            if ("long".equals(getSettings().getPermissionDetailView())) {
1472                result.append("<div class=\"dialogpermissioninherit\">");
1473                String JavaDoc resourceName = ((String JavaDoc)responsibles.get(principal));
1474                if (!resourceSitePath.equals(resourceName)) {
1475                    result.append(key(Messages.GUI_PERMISSION_INHERITED_FROM_1, new Object JavaDoc[] {resourceName}));
1476                }
1477                result.append("</div>");
1478            }
1479            result.append("</div>\n");
1480        }
1481        result.append(dialogWhiteBoxEnd());
1482        result.append("</div>\n");
1483        return result.toString();
1484    }
1485
1486}
1487
Popular Tags