Search in sources :

Example 41 with TemplateScalarModel

use of freemarker.template.TemplateScalarModel in project alfresco-repository by Alfresco.

the class HasPermissionMethod method exec.

/**
 * @see freemarker.template.TemplateMethodModel#exec(java.util.List)
 */
public Object exec(List args) throws TemplateModelException {
    int result = 0;
    if (args.size() == 2) {
        // arg 0 must be a wrapped TemplateNode object
        BeanModel arg0 = (BeanModel) args.get(0);
        // arg 1 must be a String permission name
        String permission;
        Object arg1 = args.get(1);
        if (arg1 instanceof TemplateScalarModel) {
            permission = ((TemplateScalarModel) arg1).getAsString();
            if (arg0.getWrappedObject() instanceof TemplateNode) {
                // test to see if this node has the permission
                if (((TemplateNode) arg0.getWrappedObject()).hasPermission(permission)) {
                    result = 1;
                }
            }
        }
    }
    return Integer.valueOf(result);
}
Also used : BeanModel(freemarker.ext.beans.BeanModel) TemplateScalarModel(freemarker.template.TemplateScalarModel)

Aggregations

TemplateScalarModel (freemarker.template.TemplateScalarModel)41 TemplateModel (freemarker.template.TemplateModel)18 TemplateModelException (freemarker.template.TemplateModelException)18 TemplateHashModel (freemarker.template.TemplateHashModel)9 TemplateSequenceModel (freemarker.template.TemplateSequenceModel)9 IOException (java.io.IOException)9 TemplateNumberModel (freemarker.template.TemplateNumberModel)8 Environment (freemarker.core.Environment)7 BeanModel (freemarker.ext.beans.BeanModel)7 TemplateMethodModelEx (freemarker.template.TemplateMethodModelEx)7 SimpleScalar (freemarker.template.SimpleScalar)6 Test (org.junit.Test)6 SimpleSequence (freemarker.template.SimpleSequence)5 Template (freemarker.template.Template)5 TemplateNodeModel (freemarker.template.TemplateNodeModel)5 Writer (java.io.Writer)5 Map (java.util.Map)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 TemplateBooleanModel (freemarker.template.TemplateBooleanModel)4 TemplateException (freemarker.template.TemplateException)3