Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 1029 → Rev 1030

/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/RightTagBase.java
File deleted
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/NoRightsTag.java
File deleted
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/DeleteableTag.java
File deleted
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/MethodTagBase.java
File deleted
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/NotDeleteableTag.java
File deleted
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/NotEditableTag.java
File deleted
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/ViewableTag.java
File deleted
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/NotViewableTag.java
File deleted
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/RightsTag.java
File deleted
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/EditableTag.java
File deleted
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/permission/RightTagBase.java
0,0 → 1,64
package ak.hostadmiral.core.taglib.permission;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
 
import org.apache.struts.util.RequestUtils;
 
import ak.hostadmiral.core.model.User;
import ak.hostadmiral.core.model.ModelObject;
 
public abstract class RightTagBase
extends TagSupport
{
protected User user;
protected ModelObject object;
 
protected String name;
 
public String getName()
{
return name;
}
 
public void setName(String name)
{
this.name = name;
}
 
public void release()
{
super.release();
name = null;
user = null;
}
 
public int doStartTag()
throws JspException
{
user = (User)RequestUtils.lookup(pageContext, "user", "session");
 
Object obj = RequestUtils.lookup(pageContext, name, null);
if(obj == null)
throw new JspException(name + " is null");
if(!(obj instanceof ModelObject))
throw new JspException(name + " must be a ModelObject, but is " + obj.getClass());
 
object = (ModelObject)obj;
 
if(condition())
return EVAL_BODY_INCLUDE;
else
return SKIP_BODY;
}
 
public int doEndTag()
throws JspException
{
return EVAL_PAGE;
}
 
protected abstract boolean condition()
throws JspException;
}
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/permission/EditableTag.java
0,0 → 1,13
package ak.hostadmiral.core.taglib.permission;
 
import javax.servlet.jsp.JspException;
 
public class EditableTag
extends RightTagBase
{
protected boolean condition()
throws JspException
{
return object.editableBy(user);
}
}
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/permission/NotEditableTag.java
0,0 → 1,13
package ak.hostadmiral.core.taglib.permission;
 
import javax.servlet.jsp.JspException;
 
public class NotEditableTag
extends RightTagBase
{
protected boolean condition()
throws JspException
{
return !object.editableBy(user);
}
}
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/permission/MethodTagBase.java
0,0 → 1,63
package ak.hostadmiral.core.taglib.permission;
 
import java.lang.reflect.Method;
import javax.servlet.jsp.JspException;
 
import ak.hostadmiral.core.model.User;
import org.apache.struts.util.RequestUtils;
 
public abstract class MethodTagBase
extends RightTagBase
{
protected String method;
 
public String getMethod()
{
return method;
}
 
public void setMethod(String method)
{
this.method = method;
}
 
public void release()
{
super.release();
method = null;
}
 
protected boolean condition()
throws JspException
{
Method m;
Object value;
 
// find method
try {
m = object.getClass().getMethod(method, new Class[] { User.class } );
}
catch(NoSuchMethodException ex) {
throw new JspException("Method " + method
+ " with parameter of type user not found");
}
 
// invoke it
try {
value = m.invoke(object, new Object[] { user } );
}
catch(Exception ex) {
throw new JspException("Cannot call " + method + ": " + ex.getMessage());
}
 
// check value type
if(!(value instanceof Boolean))
throw new JspException("Return type of method " + method
+ " must be java.lang.Boolean");
 
return condition(((Boolean)value).booleanValue());
}
 
protected abstract boolean condition(boolean value)
throws JspException;
}
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/permission/NoRightsTag.java
0,0 → 1,15
package ak.hostadmiral.core.taglib.permission;
 
import javax.servlet.jsp.JspException;
 
import org.apache.struts.util.RequestUtils;
 
public class NoRightsTag
extends MethodTagBase
{
protected boolean condition(boolean value)
throws JspException
{
return !value;
}
}
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/permission/ViewableTag.java
0,0 → 1,13
package ak.hostadmiral.core.taglib.permission;
 
import javax.servlet.jsp.JspException;
 
public class ViewableTag
extends RightTagBase
{
protected boolean condition()
throws JspException
{
return object.viewableBy(user);
}
}
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/permission/NotViewableTag.java
0,0 → 1,13
package ak.hostadmiral.core.taglib.permission;
 
import javax.servlet.jsp.JspException;
 
public class NotViewableTag
extends RightTagBase
{
protected boolean condition()
throws JspException
{
return !object.viewableBy(user);
}
}
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/permission/RightsTag.java
0,0 → 1,15
package ak.hostadmiral.core.taglib.permission;
 
import javax.servlet.jsp.JspException;
 
import org.apache.struts.util.RequestUtils;
 
public class RightsTag
extends MethodTagBase
{
protected boolean condition(boolean value)
throws JspException
{
return value;
}
}
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/permission/DeleteableTag.java
0,0 → 1,13
package ak.hostadmiral.core.taglib.permission;
 
import javax.servlet.jsp.JspException;
 
public class DeleteableTag
extends RightTagBase
{
protected boolean condition()
throws JspException
{
return object.deleteableBy(user);
}
}
/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/permission/NotDeleteableTag.java
0,0 → 1,13
package ak.hostadmiral.core.taglib.permission;
 
import javax.servlet.jsp.JspException;
 
public class NotDeleteableTag
extends RightTagBase
{
protected boolean condition()
throws JspException
{
return !object.deleteableBy(user);
}
}