Update of 
/var/cvs/contributions/CMSContainer/cmsc/taglib/src/java/com/finalist/cmsc/taglib/security
In directory 
james.mmbase.org:/tmp/cvs-serv1874/cmsc/taglib/src/java/com/finalist/cmsc/taglib/security

Modified Files:
        ProtectedTag.java 
Log Message:
CMSC-783 - inverse attribute for cmsc:protected tag


See also: 
http://cvs.mmbase.org/viewcvs/contributions/CMSContainer/cmsc/taglib/src/java/com/finalist/cmsc/taglib/security
See also: http://www.mmbase.org/jira/browse/CMSC-783


Index: ProtectedTag.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer/cmsc/taglib/src/java/com/finalist/cmsc/taglib/security/ProtectedTag.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- ProtectedTag.java   17 Dec 2007 20:30:52 -0000      1.1
+++ ProtectedTag.java   3 Mar 2008 15:11:09 -0000       1.2
@@ -22,6 +22,12 @@
 
 public class ProtectedTag extends SimpleTagSupport {
 
+   /**
+    * Attribute that determines whether or not this tag actually just works the
+    * other way around.
+    */
+   private boolean inverse = false;
+
    @Override
    public void doTag() throws JspException, IOException {
       PageContext ctx = (PageContext) getJspContext();
@@ -31,9 +37,34 @@
       // handle body, call any nested tags
       JspFragment frag = getJspBody();
       if (frag != null) {
-         if (ls != null && ls.isAuthenticated()) {
+         // normally display only when authenticated
+         boolean processBody = !isInverse() && (ls != null) && 
ls.isAuthenticated();
+
+         // or display when inversed and *not* authenticated
+         processBody = (processBody || (isInverse() && (ls == null || 
!ls.isAuthenticated())));
+
+         if (processBody) {
             frag.invoke(null);
          }
       }
    }
+
+   /**
+    * Returns the value of the inverse attribute. Defaults to false.
+    *
+    * @return the inverse
+    */
+   public boolean isInverse() {
+      return inverse;
+   }
+
+   /**
+    * Sets the value of the inverse attribute.
+    *
+    * @param inverse
+    *           the inverse to set
+    */
+   public void setInverse(boolean inverse) {
+      this.inverse = inverse;
+   }
 }
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to