/*
 * Copyright 2009 Kantega AS
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package no.kantega.publishing.api.taglibs.content;

import no.kantega.commons.log.Log;
import no.kantega.publishing.api.taglibs.content.util.AttributeTagHelper;
import no.kantega.publishing.common.data.Content;
import no.kantega.publishing.common.data.enums.AttributeDataType;
import no.kantega.publishing.common.data.enums.AttributeProperty;
import no.kantega.publishing.security.SecuritySession;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.jstl.core.ConditionalTagSupport;

/**
 *
 */
public class AttributeExistsTag extends ConditionalTagSupport {
    private static final String SOURCE = "aksess.AttributeExistsTag";

    private String name = null;
    private String contentId = null;
    private String collection = null;
    private boolean negate = false;
    private int attributeType = AttributeDataType.CONTENT_DATA;
    private Content contentObject = null;
    private String repeater;

    private boolean inheritFromAncestors = false;

    public void setName(String name) {
        this.name = name.toLowerCase();
    }

    public void setCollection(String collection) {
        this.collection = collection;
    }

    public void setContentid(String contentId) {
        if (contentId != null && contentId.length() == 0) {
            contentId = null;
        }
        this.contentId = contentId;
    }

    public void setObj(Content obj) {
        this.contentObject = obj;
    }

    public void setNegate(boolean negate) {
        this.negate = negate;
    }

    public void setAttributetype(String attr) {
        if (attr.equalsIgnoreCase("metadata")) {
            attributeType = AttributeDataType.META_DATA;
        } else {
            attributeType = AttributeDataType.CONTENT_DATA;
        }
    }

    public void setInheritfromancestors(boolean inheritFromAncestors) {
        this.inheritFromAncestors = inheritFromAncestors;
    }

    public void setRepeater(String repeater) {
        this.repeater = repeater;
    }

    protected boolean condition() {
        try {
            if (contentObject == null) {
                contentObject = AttributeTagHelper.getContent(pageContext, collection, contentId, repeater);
            }
            GetAttributeCommand cmd = new GetAttributeCommand();
            cmd.setName(AttributeTagHelper.getAttributeName(pageContext, name, repeater));
            cmd.setProperty(AttributeProperty.VALUE);
            cmd.setAttributeType(attributeType);

            SecuritySession session = SecuritySession.getInstance((HttpServletRequest)pageContext.getRequest());

            String result = AttributeTagHelper.getAttribute(session, contentObject, cmd, inheritFromAncestors);
            if (result != null && result.length() > 0) {
                return !negate;
            }
        } catch (Exception e) {
            System.err.println(e);
            Log.error(SOURCE, e, null, null);
        }

        return negate;
    }

    public int doEndTag() throws JspException  {
        contentId = null;
        name = null;
        collection = null;
        attributeType = AttributeDataType.CONTENT_DATA;
        negate = false;
        inheritFromAncestors = false;
        contentObject = null;
        repeater = null;
        
        return super.doEndTag();
    }
}

@@ -643,117 +643,8 @@
 t;%0A%0A
-import no.kantega.commons.log.Log;%0Aimport no.kantega.publishing.api.taglibs.content.util.AttributeTagHelper;%0A
 impo
@@ -730,31 +730,25 @@
 on.data.
-enums.A
+a
 ttribute
 DataType
@@ -743,417 +743,123 @@
 bute
-DataType;%0Aimport no.kantega.publishing.common.data.enums.AttributeProperty;%0Aimport no.kantega.publishing.security.SecuritySession;%0A%0Aimport javax.servlet.http.HttpServletRequest;%0Aimport javax.servlet.jsp.JspException;%0Aimport javax.servlet.jsp.jstl.core.ConditionalTagSupport;%0A%0A/**%0A *%0A */%0Apublic class AttributeExistsTag extends ConditionalTagSupport %7B%0A    private static final String SOURCE = %22aksess.A
+s.Attribute;%0A%0Aimport static org.apache.commons.lang.StringUtils.isNotBlank;%0A%0A/**%0A * Determines whether an a
 ttribute
 Exis
@@ -858,1801 +858,210 @@
 bute
-E
+ e
 xists
-Tag%22;%0A%0A    private String name = null;%0A    private String contentId = null;%0A    private String collection = null;%0A    private boolean negate = false;%0A    private int attributeType = AttributeDataType.CONTENT_DATA;%0A    private Content contentObject = null;%0A    private String repeater;%0A%0A    private boolean inheritFromAncestors = false;%0A%0A    public void setName(String name) %7B%0A        this.name = name.toLowerCase();%0A    %7D%0A%0A    public void setCollection(String collection) %7B%0A        this.collection = collection;%0A    %7D%0A%0A    public void setContentid(String contentId) %7B%0A        if (contentId != null && contentId.length() == 0) %7B%0A            contentId = null;%0A        %7D%0A        this.contentId = contentId;%0A    %7D%0A%0A    public void setObj(Content obj) %7B%0A        this.contentObject = obj;%0A    %7D%0A%0A    public void setNegate(boolean negate) %7B%0A        this.negate = negate;%0A    %7D%0A%0A    public void setAttributetype(String attr) %7B%0A        if (attr.equalsIgnoreCase(%22metadata%22)) %7B%0A            attributeType = AttributeDataType.META_DATA;%0A        %7D else %7B%0A            attributeType = AttributeDataType.CONTENT_DATA;%0A        %7D%0A    %7D%0A%0A    public void setInheritfromancestors(boolean inheritFromAncestors) %7B%0A        this.inheritFromAncestors = inheritFromAncestors;%0A    %7D%0A%0A    public void setRepeater(String repeater) %7B%0A        this.repeater = repeater;%0A    %7D%0A%0A    protected boolean condition() %7B%0A        try %7B%0A            if (contentObject == null) %7B%0A                contentObject = AttributeTagHelper.getContent(pageContext, collection, contentId, repeater);%0A            %7D%0A            GetAttributeCommand cmd = new GetAttributeCommand();%0A            cmd.setName(AttributeTagHelper.getAttributeName(pageContext, name, repeater));%0A            cmd.setProperty(AttributeProperty.VALUE);%0A            cmd.set
+ and has value.%0A * @see AttributeNotExistsTag%0A */%0Apublic class AttributeExistsTag extends AbstractAttributeConditionTag %7B%0A%0A%0A    @Override%0A    protected boolean evaluateCondition(Content content, 
 Attr
@@ -1069,13 +1069,9 @@
 bute
-Type(
+ 
 attr
@@ -1079,834 +1079,79 @@
 bute
-Type);%0A%0A            SecuritySession session = SecuritySession.getInstance((HttpServletRequest)pageContext.getRequest());%0A%0A            String result = AttributeTagHelper.getAttribute(session, contentObject, cmd, inheritFromAncestors);%0A            if (result != null && result.length() %3E 0) %7B%0A                return !negate;%0A            %7D%0A        %7D catch (Exception e) %7B%0A            System.err.println(e);%0A            Log.error(SOURCE, e, null, null);%0A        %7D%0A%0A        return negate;%0A    %7D%0A%0A    public int doEndTag() throws JspException  %7B%0A        contentId = null;%0A        name = null;%0A        collection = null;%0A        attributeType = AttributeDataType.CONTENT_DATA;%0A        negate = false;%0A        inheritFromAncestors = false;%0A        contentObject = null;%0A        repeater = null;%0A        %0A        return super.doEndTag(
+) %7B%0A        return attribute != null && isNotBlank(attribute.getValue()
 );%0A 

Tag did not handle repeater after refactoring Cherry-picked from trunk