KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > frontend > admin > AclBinding


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.outerj.daisy.frontend.admin;
17
18 import org.apache.cocoon.forms.binding.AbstractCustomBinding;
19 import org.apache.cocoon.forms.formmodel.Widget;
20 import org.apache.cocoon.forms.formmodel.Repeater;
21 import org.apache.commons.jxpath.JXPathContext;
22 import org.outerj.daisy.repository.acl.*;
23
24 /**
25  * The binding for loading an ACL object into the form for editing the binding,
26  * and vice versa.
27  */

28 public class AclBinding extends AbstractCustomBinding {
29     protected void doLoad(Widget widget, JXPathContext jxPathContext) throws Exception JavaDoc {
30         Acl acl = (Acl) jxPathContext.getValue(".");
31         Repeater repeater = (Repeater) widget;
32
33         for (int i = 0; i < acl.size(); i++) {
34             Repeater.RepeaterRow objectRow = repeater.addRow();
35             AclObject aclObject = acl.get(i);
36             objectRow.getChild("expr").setValue(aclObject.getObjectExpr());
37
38             for (int j = 0; j < aclObject.size(); j++) {
39                 Repeater entryRepeater = (Repeater) objectRow.getChild("entries");
40                 Repeater.RepeaterRow entryRow = entryRepeater.addRow();
41                 AclEntry aclEntry = aclObject.get(j);
42                 entryRow.getChild("subjectType").setValue(aclEntry.getSubjectType());
43                 entryRow.getChild("subjectValue").setValue(new Long JavaDoc(aclEntry.getSubjectValue()));
44                 entryRow.getChild("readLivePerm").setValue(aclEntry.get(AclPermission.READ_LIVE));
45                 entryRow.getChild("readPerm").setValue(aclEntry.get(AclPermission.READ));
46                 entryRow.getChild("writePerm").setValue(aclEntry.get(AclPermission.WRITE));
47                 entryRow.getChild("publishPerm").setValue(aclEntry.get(AclPermission.PUBLISH));
48                 entryRow.getChild("deletePerm").setValue(aclEntry.get(AclPermission.DELETE));
49             }
50         }
51     }
52
53     protected void doSave(Widget widget, JXPathContext jxPathContext) throws Exception JavaDoc {
54         Repeater repeater = (Repeater) widget;
55         Acl acl = (Acl) jxPathContext.getValue(".");
56         acl.clear();
57         for (int i = 0; i < repeater.getSize(); i++) {
58             AclObject aclObject = acl.createNewObject((String JavaDoc) repeater.getRow(i).getChild("expr").getValue());
59
60             Repeater entryRepeater = (Repeater) repeater.getRow(i).getChild("entries");
61             for (int j = 0; j < entryRepeater.getSize(); j++) {
62                 Long JavaDoc subjectValue = (Long JavaDoc) entryRepeater.getRow(j).getChild("subjectValue").getValue();
63                 if (subjectValue == null)
64                     subjectValue = new Long JavaDoc(-1);
65                 AclEntry aclEntry = aclObject.createNewEntry((AclSubjectType) entryRepeater.getRow(j).getChild("subjectType").getValue(), subjectValue.longValue());
66
67                 AclActionType readLivePerm = (AclActionType) entryRepeater.getRow(j).getChild("readLivePerm").getValue();
68                 if (readLivePerm != AclActionType.DO_NOTHING)
69                     aclEntry.set(AclPermission.READ_LIVE, readLivePerm);
70
71                 AclActionType readPerm = (AclActionType) entryRepeater.getRow(j).getChild("readPerm").getValue();
72                 if (readPerm != AclActionType.DO_NOTHING)
73                     aclEntry.set(AclPermission.READ, readPerm);
74
75                 AclActionType writePerm = (AclActionType) entryRepeater.getRow(j).getChild("writePerm").getValue();
76                 if (writePerm != AclActionType.DO_NOTHING)
77                     aclEntry.set(AclPermission.WRITE, writePerm);
78
79                 AclActionType publishPerm = (AclActionType) entryRepeater.getRow(j).getChild("publishPerm").getValue();
80                 if (publishPerm != AclActionType.DO_NOTHING)
81                     aclEntry.set(AclPermission.PUBLISH, publishPerm);
82
83                 AclActionType deletePerm = (AclActionType) entryRepeater.getRow(j).getChild("deletePerm").getValue();
84                 if (deletePerm != AclActionType.DO_NOTHING)
85                     aclEntry.set(AclPermission.DELETE, deletePerm);
86
87                 aclObject.add(aclEntry);
88             }
89
90             acl.add(aclObject);
91         }
92     }
93 }
94
Popular Tags