1 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 28 public class AclBinding extends AbstractCustomBinding { 29 protected void doLoad(Widget widget, JXPathContext jxPathContext) throws Exception { 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 (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 { 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 ) 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 subjectValue = (Long ) entryRepeater.getRow(j).getChild("subjectValue").getValue(); 63 if (subjectValue == null) 64 subjectValue = new Long (-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 |