You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@empire-db.apache.org by do...@apache.org on 2008/08/06 11:34:45 UTC

svn commit: r683198 [6/8] - in /incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext: ./ .settings/ src/ src/META-INF/ src/org/ src/org/apache/ src/org/apache/empire/ src/org/apache/empire/struts2/ src/org/apache/empire/struts2/action/ src/org/apac...

Added: incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/EmpireTagSupport.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/EmpireTagSupport.java?rev=683198&view=auto
==============================================================================
--- incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/EmpireTagSupport.java (added)
+++ incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/EmpireTagSupport.java Wed Aug  6 02:34:41 2008
@@ -0,0 +1,457 @@
+package org.apache.empire.struts2.jsp.tags;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.jsp.JspException;
+
+import org.apache.commons.beanutils.BeanUtilsBean;
+import org.apache.commons.beanutils.PropertyUtilsBean;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.empire.commons.StringUtils;
+import org.apache.empire.struts2.action.ActionItemProperty;
+import org.apache.empire.struts2.html.HtmlWriter.HtmlTag;
+import org.apache.struts2.components.UIBean;
+import org.apache.struts2.views.jsp.ComponentTagSupport;
+import org.apache.struts2.views.util.UrlHelper;
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.LocaleProvider;
+import com.opensymphony.xwork2.TextProvider;
+
+
+public abstract class EmpireTagSupport extends ComponentTagSupport
+{
+    // Logger
+    protected static Log log = LogFactory.getLog(EmpireTagSupport.class);
+
+    protected boolean    autoResetParams = true;
+
+    protected String     cssClass;
+    protected String     cssStyle;
+
+    protected void resetParams()
+    {
+        this.id = null;
+        this.cssClass = null;
+        this.cssStyle = null;
+    }
+
+    public final void setCssClass(String cssClass)
+    {
+        this.cssClass = cssClass;
+    }
+
+    public final void setCssStyle(String cssStyle)
+    {
+        this.cssStyle = cssStyle;
+    }
+
+    @Override
+    public final void setId(String id)
+    {
+        super.setId(id);
+    }
+
+    @Override
+    public String getId()
+    {
+        return getString(this.id);
+    }
+    
+    @Override
+    protected void populateParams()
+    {
+        super.populateParams();
+
+        // Common UI Properties
+        if (component instanceof UIBean)
+        {
+            ((UIBean) component).setCssClass(cssClass);
+            ((UIBean) component).setCssStyle(cssStyle);
+        }
+    }
+
+    @Override
+    public int doEndTag()
+        throws JspException
+    {
+        if (autoResetParams)
+            resetParams();
+        // Render now
+        return super.doEndTag();
+    }
+
+    @Override
+    public void release()
+    {
+        log.debug("Releasing tag " + getClass().getName());
+        resetParams();
+        super.release();
+    }
+
+    // ------- Standard Attributes -------
+
+    protected void addStandardAttributes(HtmlTag tag, String defaultClass)
+    {
+        // HtmlTag div = w.startTag("div");
+        tag.addAttribute("id", getId());
+        tag.addAttribute("class", str(cssClass, defaultClass));
+        tag.addAttribute("style", cssStyle);
+        cssClass=null;
+        cssStyle=null;
+        setId(null);
+    }
+    
+    // ------- Misc -------
+    /*
+    private String getUrl(String action)
+    {
+        // Set onclick 
+        checkAction(action);
+        // Temporarily create Anchor component
+        AnchorComponent anchor = new AnchorComponent(getStack(), (HttpServletRequest) pageContext.getRequest(), (HttpServletResponse) pageContext.getResponse());
+        Container container = Dispatcher.getInstance().getContainer();
+        container.inject(anchor);
+        String url = anchor.getUrl(action);
+        anchor.end(null, null);
+        // Set Onlick
+        return url;
+    }
+    */
+    
+    protected Object getAction()
+    {
+        try {
+            return ActionContext.getContext().getActionInvocation().getAction();
+        } catch (Exception e) {
+            log.fatal("Unable to detect Action. Action Invocation not available!");
+            return "";
+        }
+    }
+    
+    protected String getActionName()
+    {
+        try {
+            return ActionContext.getContext().getActionInvocation().getProxy().getActionName();
+        } catch (Exception e) {
+            log.fatal("Unable to detect Action name. Action Invocation Proxy not available!");
+            return "";
+        }
+    }
+    
+    protected String getActionItemPropertyName()
+    {
+        Object action = getAction();
+        if (action instanceof ActionItemProperty)
+            return ((ActionItemProperty)action).getItemPropertyName();
+        // Default is id
+        return "item";
+    }
+    
+    // ------- URL generator -------
+
+    protected String getActionURL(String action, Map parameters)
+    {
+        HttpServletRequest httpRequest = (HttpServletRequest) pageContext.getRequest();        
+        HttpServletResponse httpResponse = (HttpServletResponse) pageContext.getResponse();        
+        // Get the uri
+        String uri = "/" + checkAction(action);
+        if (uri.indexOf('.')<0)
+            uri += ".action";
+        // now build the url
+        return UrlHelper.buildUrl(uri, httpRequest, httpResponse, parameters, null, true, true);
+    }
+    
+    // ------- Page Attribute Helpers ------
+
+    protected Object putPageAttribute(String name, Object value)
+    {
+        // Store Attribute on Page Scope
+        Object oldValue = pageContext.getAttribute(name);
+        pageContext.setAttribute(name, value);
+        return oldValue;
+    }
+
+    protected void removePageAttribute(String name, Object oldValue)
+    {
+        if ( oldValue!=null )
+             pageContext.setAttribute(name, oldValue);
+        else pageContext.removeAttribute(name);
+    }
+
+    protected Object getPageAttribute(String name, Object defValue)
+    {
+        Object o = pageContext.getAttribute(name);
+        return (o!=null) ? o : defValue;
+    }
+
+    // ------- Param Helper Methods -------
+
+    protected String str(String value, String defValue)
+    {
+        return ((value!=null) ? value : defValue);
+    }
+
+    protected Object getObject(Object value, Object defValue, Class asType)
+    {
+        if (value == null)
+        {
+            return defValue;
+        }
+        // Check String
+        if ((value instanceof String))
+        {
+            // Check Value
+            String strval = value.toString();
+            if (strval.startsWith("%{") && strval.endsWith("}"))
+            { // OGNL
+                strval = strval.substring(2, strval.length() - 1);
+                return getStack().findValue(strval, asType);
+            }
+            if (strval.startsWith("#"))
+            { // OGNL
+                return getStack().findValue(strval, asType);
+            }
+            if (strval.startsWith("$"))
+            { // Attribute on page, request, session or application (in this order)
+                strval = strval.substring(1);
+                if (strval.startsWith("$") == false)
+                    value = getAttribute(strval);
+                if (value == null)
+                    return defValue;
+            }
+        }
+        // Check Class
+        if (asType.isInstance(value))
+        { // make a cast
+            return asType.cast(value);
+        }
+        // Error
+        log.error("Cannot cast value of '" + value.toString() + " to class " + asType.toString());
+        return null;
+    }
+
+    protected final Object getObject(Object value, Object defValue)
+    {
+        return getObject(value, defValue, Object.class);
+    }
+    
+    protected String getString(Object value, String defValue)
+    {
+        if (value == null)
+            return defValue;
+        // Check String
+        if ((value instanceof String) == false)
+            return value.toString();
+        // Check Value
+        String strval = value.toString();
+        if (strval.startsWith("%{") && strval.endsWith("}"))
+        { // OGNL
+            strval = strval.substring(2, strval.length() - 1);
+            return (String) getStack().findValue(strval, String.class);
+        }
+        if (strval.startsWith("#"))
+        { // OGNL
+            return (String) getStack().findValue(strval, String.class);
+        }
+        if (strval.startsWith("$"))
+        { // Attribute on page, request, session or application (in this order)
+            strval = strval.substring(1);
+            if (strval.startsWith("$") == false)
+                return StringUtils.toString(getAttribute(strval));
+        }
+        if (strval.startsWith("!"))
+        { // Translations
+            strval = strval.substring(1);
+            if (strval.startsWith("!") == false)
+                return this.getTranslationFromKey(getString(strval, null));
+        }
+        // Just a string
+        return strval;
+    }
+
+    protected final String getString(Object value)
+    {
+        return getString(value, null);
+    }
+
+    protected final String getString(Object value, Object defValue)
+    {
+        String defValStr = ((defValue!=null) ? defValue.toString() : null);
+        return getString(value, defValStr);
+    }
+    
+    protected int getInt(Object value, int defValue)
+    {
+        if (value == null)
+            return defValue;
+        if (value instanceof String)
+            value = getObject(value, 0, Object.class);
+        if (value instanceof Number)
+            return ((Integer) value).intValue();
+        // Convert
+        try
+        {
+            return Integer.parseInt(value.toString());
+        } catch (Exception e)
+        {
+            return defValue;
+        }
+    }
+
+    protected boolean getBoolean(Object value, boolean defValue)
+    {
+        if (value == null)
+            return defValue;
+        if (value instanceof String)
+            value = getObject(value, 0, Object.class);
+        if (value instanceof Boolean)
+            return ((Boolean) value).booleanValue();
+        // Check for true or false
+        String txt = String.valueOf(value);
+        if (txt.equalsIgnoreCase("true"))
+            return true;
+        // Not boolean
+        return false;
+    }
+
+    protected Object getBeanProperty(Object bean, String property)
+    {
+        try
+        {   /*
+            if (log.isTraceEnabled())
+                log.trace(bean.getClass().getName() + ": setting property '" + property + "' to " + String.valueOf(value));
+            */
+            
+            // Get Property Value
+            PropertyUtilsBean pub = BeanUtilsBean.getInstance().getPropertyUtils();
+            return pub.getSimpleProperty(bean, property);
+            
+            // Check result
+            /*
+             * String res = BeanUtils.getProperty(bean, property); if (res!=value && res.equals(String.valueOf(value))==false) { //
+             * Property value cannot be set // (missing setter?) String msg = bean.getClass().getName() + ": unable to set
+             * property '" + property + "' to " + String.valueOf(value); return error(ERR_INTERNAL, msg); } else if
+             * (log.isInfoEnabled()) { log.info(bean.getClass().getName() + ": property '" + property + "' has been set to " +
+             * res); }
+             */
+            // done
+
+        } catch (IllegalAccessException e)
+        {   log.error(bean.getClass().getName() + ": unable to set property '" + property + "'");
+            return null;
+        } catch (InvocationTargetException e)
+        {   log.error(bean.getClass().getName() + ": unable to set property '" + property + "'");
+            return null;
+        } catch(NoSuchMethodException e) { 
+            log.warn(bean.getClass().getName() + ": cannot check value of property '" + property + "'");
+            return null;
+        }
+    }
+    
+    protected String checkAction(String action)
+    {
+        if (action == null )
+            return null;
+        // find Method separator
+        int i = action.indexOf('!');
+        if (i < 0)
+        {
+            log.warn("No link action method for for action " + action + " has been supplied! Page = " + getPageName());
+        }
+        else if (i==0)
+        {   // Only Method name given
+            return getActionName() + action;
+        }
+        return action;
+    }
+
+    protected String getPageName()
+    {
+        String page = pageContext.getPage().toString();
+        int lastDot = page.lastIndexOf('.');
+        int lastAt = page.indexOf('@');
+        if (lastDot > 0 && lastDot < lastAt)
+            page = page.substring(lastDot + 1, lastAt);
+        return page;
+    }
+
+    protected Object getAttribute(String attribute)
+    {
+        // Try Page Context
+        Object obj = pageContext.getAttribute(attribute);
+        if (obj != null)
+            return obj;
+        // Try Request
+        obj = pageContext.getRequest().getAttribute(attribute);
+        if (obj != null)
+            return obj;
+        // Try Session
+        obj = pageContext.getSession().getAttribute(attribute);
+        if (obj != null)
+            return obj;
+        // Try Application
+        return pageContext.getServletContext().getAttribute(attribute);
+    }
+    
+    // ------- Translation helpers -------
+
+    protected String getTranslation(String text)
+    {
+        if (text == null || text.length() == 0 || !text.startsWith("!"))
+            return text;
+        // If key starts with ! then return key.
+        String key = text.substring(1);
+        if (key.startsWith("!"))
+            return key;
+        // translate
+        return getTranslationFromKey(key);
+    }
+    
+    private TextProvider getTextProvider(Object action)
+    {
+        if (action instanceof TextProvider)
+            return ((TextProvider) action);
+        // Error
+        return null;
+    }
+    
+    protected Locale getLocale(Object action)
+    {
+        if (action instanceof LocaleProvider)
+            return ((LocaleProvider) action).getLocale();
+        // Use action context locale
+        return ActionContext.getContext().getLocale();
+    }
+
+    protected String getTranslationFromKey(String key)
+    {
+        Object action = getAction();
+        TextProvider tp = getTextProvider(action);
+        if (tp!=null)
+        {   // Text Provider found
+            String locale = getLocale(action).toString();  
+            String result = tp.getText(key);
+            if (result==null)
+            {
+                if (log.isErrorEnabled())
+                    log.error("No translation found for key=[" + key + "] on page " + getPageName() + " --> locale=" + locale);
+            }
+            else if (result.length()==0)
+            {
+                if (log.isInfoEnabled())
+                    log.info("Translation key [" + key + "] found, but value is empty! locale=" + locale );
+            }
+            else return result; 
+        } else
+        {   // Find text provider
+            log.error("No text provider available. Action does not implement TextProvider interface");
+        }
+        return "[" + key + "]";
+    }
+}

Added: incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/EmpireValueTagSupport.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/EmpireValueTagSupport.java?rev=683198&view=auto
==============================================================================
--- incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/EmpireValueTagSupport.java (added)
+++ incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/EmpireValueTagSupport.java Wed Aug  6 02:34:41 2008
@@ -0,0 +1,332 @@
+package org.apache.empire.struts2.jsp.tags;
+
+import org.apache.empire.commons.StringUtils;
+import org.apache.empire.data.Column;
+import org.apache.empire.data.ColumnExpr;
+import org.apache.empire.data.Record;
+import org.apache.empire.data.RecordData;
+
+public abstract class EmpireValueTagSupport extends EmpireTagSupport
+{
+    public static final String RECORD_ATTRIBUTE    = "record";
+    public static final String BEAN_ITEM_ATTRIBUTE = "bean";
+    public static final String PARENT_PROPERTY_ATTRIBUTE = "parentPropertyName";
+    
+    // Value
+    private ColumnExpr column;
+    private Object value;
+    private String field;
+    private String property;
+    private String parentProperty;
+    private RecordData record;
+    
+    @Override
+    protected void resetParams()
+    {
+        // Value
+        column = null;
+        value = null;
+        field = null;
+        property = null;
+        parentProperty = null;
+        record = null;
+        // Reset
+        super.resetParams();
+    }
+    
+    protected boolean hasValue()
+    {
+        return (property!=null || field!=null || value!=null);
+    }
+    
+    protected RecordData getRecordData()
+    {
+        if ( record==null )
+        {   // Set Record from Page Context
+            Object recObj = pageContext.getAttribute(RECORD_ATTRIBUTE);
+            if (recObj instanceof RecordData)
+                record = (RecordData)recObj;
+        }
+        return record;
+    }
+
+    protected Record getRecord()
+    {
+        if (getRecordData() instanceof Record)
+        {   // Yes, it's a Record
+            if (!((Record)record).isValid())
+            {   // Invalid Record 
+                log.warn("The record supplied is not valid!");
+                return null; 
+            }
+            return ((Record)record);
+        }
+        // Not a record
+        return null;
+    }
+    
+    protected Object getBean()
+    {
+        return pageContext.getAttribute(BEAN_ITEM_ATTRIBUTE);        
+    }
+    
+    protected ColumnExpr getColumnExpr()
+    {
+        if (column!=null)
+            return column;
+        if (value instanceof ColumnExpr)
+            return ((ColumnExpr)value);
+        if (field!=null)
+        {   // If record is not set, then try to read it from page context
+            if (getRecordData()!=null)
+            {   // get Column from field
+                return record.getColumnExpr(record.getFieldIndex(field));
+            }
+        }
+        return null; 
+    }
+    
+    protected Column getColumn()
+    {
+        ColumnExpr column = getColumnExpr();
+        if (column==null)
+            return null; 
+        // Get Update Column
+        return column.getSourceColumn();        
+    }
+    
+    protected String getControlType()
+    {
+        // Detect control type and readOnly state
+        Column column = getColumn();
+        if (column==null)
+        {   // log.debug("No Column supplied. Unable to detect control type. Using default.");
+            return "text"; 
+        }
+        return column.getControlType();
+    }
+    
+    protected String getTagName(String suppliedName)
+    {
+        if (StringUtils.isValid(suppliedName))
+            return suppliedName;
+        if (property != null)
+            return getFullPropertyName(property);
+        if (field != null)
+            return getFullPropertyName(field);
+        if (value instanceof ColumnExpr)
+            return getColumnPropertyName((ColumnExpr)value);
+        // Not Name provided 
+        log.error("Cannot detect name from value.");
+        return "";
+    }
+    
+    protected Object getValue()
+    {
+        if (value==null)
+        {   // Try property and field first
+            if (property != null)
+            {   // Value from Property
+                return getStack().findValue(getFullPropertyName(property), Object.class);
+            }
+            if (field != null)
+            {
+                return getRecordFieldValue(getRecordData(), field, null);            
+            }
+        }    
+        // Get Value
+        return getRecordValue(getRecordData(), value, null);
+    }
+    
+    protected String getStringValue()
+    {   // Convert value to String
+        return StringUtils.toString(getValue());
+    }
+    
+    protected String getItemValue(Object item)
+    {
+        if ((item instanceof String))
+        {   // Item is a field or property name
+            String str = item.toString();
+            if (str.length()==0)
+                return null; // Error: Item string is empty
+            // Starts with
+            char prefix = str.charAt(0);
+            if (prefix=='%' || prefix=='#' || prefix=='$')
+                return getString(str, null);
+            if (prefix=='!')
+                return ((String)item).substring(1);
+            if (prefix<'A')
+            {   log.error("Invalid property or field name supplied for item.");
+                return null;
+            }
+            // Item is property or field name 
+            if (property != null)
+            {
+                String fullName = getFullPropertyName(str);
+                return (String)getStack().findValue(fullName, String.class);
+            }
+            else
+            {
+                return StringUtils.toString(getRecordFieldValue(record, str, null));            
+            }
+        }
+        // Default
+        return StringUtils.toString(getRecordValue(record, item, null));
+    }
+    
+    protected String getPropertyFieldName()
+    {
+        if (property != null)
+            return getFullPropertyName(property);
+        if (field != null)
+            return getFullPropertyName(field);        
+        return null;
+    }
+    
+    protected String getFullPropertyName(String name)
+    {
+        // Get name from column
+        if ("*".equals(name) && column!=null)
+            name = column.getBeanPropertyName();
+        // Prepend parent Property name (if any)
+        if (parentProperty==null)
+            parentProperty = StringUtils.toString(getPageAttribute(PARENT_PROPERTY_ATTRIBUTE, null));
+        if (parentProperty!=null)
+            return parentProperty + "." + name;
+        // return the name
+        return name;
+    }
+    
+    protected String getColumnPropertyName(ColumnExpr col)
+    {
+        return getFullPropertyName(col.getName());
+    }
+    
+    protected boolean setPropertyNameFromValue()
+    {
+        if (property==null && (value instanceof String))
+        {
+            String strval = ((String)value);
+            if (strval.startsWith("%{") && strval.endsWith("}"))
+            { // It's a property Name
+                property = strval.substring(2, strval.length() - 1).trim();
+                return true;
+            }
+        }
+        return false;
+    }
+    
+    protected boolean hasDefaultValue()
+    {
+        return (value!=null && (property!=null || field!=null || column!=null));
+    }
+    
+    protected Object getDefaultValue()
+    {
+        // Try property and field first
+        if (property != null)
+        {   // Value from Property
+            return getStack().findValue(getFullPropertyName(property), Object.class);
+        }
+        if (field != null)
+        {
+            return getRecordFieldValue(getRecordData(), field, null);            
+        }
+        // Get Value
+        return getRecordValue(getRecordData(), null, null);
+    }
+
+    // ------- Internal -------
+    
+    private Object getRecordFieldValue(RecordData rec, String field, Object defValue)
+    {
+        // Field Param must be supplied
+        if (field==null)
+            return defValue;
+        // If record is not set, then try to read it from page context
+        if (rec!=null)
+        {   // Find field by name
+            int index = rec.getFieldIndex(field);
+            if (index>= 0)
+                return rec.getValue(index);
+            // Field not found 
+            log.error("Supplied field '" + field + "' not found in record.");
+        }
+        else
+        {   // Cannot find data source (record or bean)  
+            log.error("No record supplied for field value");
+        }
+        return defValue;
+    }
+    
+    private Object getRecordValue(RecordData rec, Object value, Object defValue)
+    {
+        // Find Record Value
+        if (value==null && column!=null)
+            value = column;
+        // Find Record Value
+        if (value instanceof ColumnExpr)
+        {
+            ColumnExpr column = ((ColumnExpr)value);
+            if (rec!=null)
+            {   // Find column by object first
+                int index = rec.getFieldIndex(column);
+                if (index<0)
+                {   // Column not found. Trying name
+                    log.debug("Column object '" + column.getName() + "' not found. Trying name.");
+                    index = rec.getFieldIndex( column.getName());
+                    if (index<0)
+                    {   // Column not found  
+                        log.error("Column '" + column.getName() + "' not found in record.");
+                        return null;
+                    }
+                }
+                // Get value from record
+                return rec.getValue(index);
+            }
+            else
+            {   // Check if Columns specifies a bean property
+                Object bean = getBean();
+                if (bean!=null)
+                {   // Property Name
+                    String prop = column.getBeanPropertyName();
+                    return getBeanProperty(bean, prop);
+                }
+            }
+            // Cannot find data source (record or bean)  
+            // log.warn("No record supplied for column value");
+            return defValue;
+        }
+        // getValue 
+        return this.getObject(value, defValue);
+    }
+
+    // -------------------------------- Property accessors -----------------------------
+    
+    public final void setField(String field)
+    {
+        this.field = StringUtils.validate(field);
+    }
+
+    public final void setProperty(String property)
+    {
+        this.property = StringUtils.validate(property);
+    }
+
+    public final void setRecord(RecordData record)
+    {
+        this.record = record;
+    }
+
+    public final void setValue(Object value)
+    {
+        this.value = value;
+    }
+
+    public final void setColumn(ColumnExpr column)
+    {
+        this.column = column;
+    }
+    
+}

Added: incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/FlexDivTag.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/FlexDivTag.java?rev=683198&view=auto
==============================================================================
--- incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/FlexDivTag.java (added)
+++ incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/FlexDivTag.java Wed Aug  6 02:34:41 2008
@@ -0,0 +1,96 @@
+/*
+ * ESTEAM Software GmbH, 11.07.2007
+ */
+package org.apache.empire.struts2.jsp.tags;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.jsp.JspException;
+
+import org.apache.empire.struts2.html.HtmlTagDictionary;
+import org.apache.empire.struts2.html.HtmlWriter;
+import org.apache.empire.struts2.html.HtmlTagDictionary.FlexDivRenderInfo;
+import org.apache.empire.struts2.html.HtmlWriter.HtmlTag;
+import org.apache.struts2.components.Component;
+
+import com.opensymphony.xwork2.util.ValueStack;
+
+
+@SuppressWarnings("serial")
+public class FlexDivTag extends EmpireTagSupport
+{
+    // Type of tag
+    protected String type;
+    
+    // Temporary
+    FlexDivRenderInfo flexDivRenderInfo = null;
+    
+    @Override
+    protected void resetParams()
+    {
+        type = null;
+        // reset
+        super.resetParams();
+    }
+
+    @Override
+    public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res)
+    {
+        log.fatal("No Bean available for flex-tag");
+        return null;
+    }
+
+    @Override
+    public int doStartTag()
+        throws JspException
+    {
+        String userAgent = getUserAgent();
+        // User-Agent
+        HtmlTagDictionary dic = HtmlTagDictionary.getInstance();
+        flexDivRenderInfo = dic.FlexDivTag(type, userAgent);
+        if (flexDivRenderInfo!=null)
+        {   // Render Flex Div
+            HtmlWriter w = new HtmlWriter(pageContext.getOut());
+            HtmlTag tag = w.startTag(flexDivRenderInfo.tag);
+            tag.addAttribute("id", getId());
+            tag.addAttribute("class", cssClass);
+            tag.addAttributes(flexDivRenderInfo.attributes);
+            tag.beginBody(flexDivRenderInfo.bodyBegin);
+        }
+        // return super.doStartTag();
+        return EVAL_BODY_INCLUDE;
+    }
+
+    @Override
+    public int doEndTag()
+        throws JspException
+    {
+        // Render End Tag
+        if (flexDivRenderInfo!=null)
+        {   // End flexible Tag
+            HtmlWriter w = new HtmlWriter(pageContext.getOut());
+            HtmlTag tag = w.continueTag(flexDivRenderInfo.tag, true);
+            tag.endTag(flexDivRenderInfo.bodyEnd);
+            flexDivRenderInfo = null;
+        }
+        // return super.doEndTag();
+        resetParams();
+        return EVAL_PAGE;
+    }
+    
+    private String getUserAgent()
+    {
+        ServletRequest req = pageContext.getRequest();
+        if (req instanceof HttpServletRequest)
+            return ((HttpServletRequest)req).getHeader("User-Agent");
+        // Not detectable
+        return "";
+    }
+
+    public void setType(String type)
+    {
+        this.type = type;
+    }
+
+}

Added: incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/FloatClearTag.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/FloatClearTag.java?rev=683198&view=auto
==============================================================================
--- incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/FloatClearTag.java (added)
+++ incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/FloatClearTag.java Wed Aug  6 02:34:41 2008
@@ -0,0 +1,47 @@
+/*
+ * ESTEAM Software GmbH, 06.07.2007
+ */
+package org.apache.empire.struts2.jsp.tags;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.BodyTagSupport;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.empire.struts2.html.HtmlTagDictionary;
+
+
+@SuppressWarnings("serial")
+public class FloatClearTag extends BodyTagSupport
+{
+    // Logger
+    protected static Log log = LogFactory.getLog(FloatClearTag.class);
+    
+    @Override
+    public int doStartTag()
+        throws JspException
+    {
+        // super.doStartTag();
+        // Write the float clear statement
+        HtmlTagDictionary dic = HtmlTagDictionary.getInstance();
+        String clear = dic.FloatClear();
+        if (clear!=null)
+        {   // Print the clear statement
+            try {
+                pageContext.getOut().print(clear);
+            } catch (Exception e) {
+                log.error("Unable to write to output stream.", e);
+            }
+        }
+        // done, no body!
+        return SKIP_BODY; 
+    }
+
+    @Override
+    public int doEndTag()
+        throws JspException
+    {
+        // return super.doEndTag();
+        return EVAL_PAGE;
+    }
+}

Added: incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/FormPartTag.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/FormPartTag.java?rev=683198&view=auto
==============================================================================
--- incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/FormPartTag.java (added)
+++ incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/FormPartTag.java Wed Aug  6 02:34:41 2008
@@ -0,0 +1,346 @@
+package org.apache.empire.struts2.jsp.tags;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.jsp.JspException;
+
+import org.apache.empire.commons.ObjectUtils;
+import org.apache.empire.commons.StringUtils;
+import org.apache.empire.data.Column;
+import org.apache.empire.data.ColumnExpr;
+import org.apache.empire.data.DataType;
+import org.apache.empire.data.Record;
+import org.apache.empire.data.RecordData;
+import org.apache.empire.db.DBDatabase;
+import org.apache.empire.db.DBRecord;
+import org.apache.empire.struts2.actionsupport.ActionBase;
+import org.apache.empire.struts2.html.HtmlTagDictionary;
+import org.apache.empire.struts2.html.HtmlWriter;
+import org.apache.empire.struts2.html.HtmlWriter.HtmlTag;
+import org.apache.struts2.components.Component;
+
+import com.opensymphony.xwork2.util.ValueStack;
+
+
+@SuppressWarnings("serial")
+public class FormPartTag extends EmpireTagSupport // FormTag
+{
+    public static final String DISABLEDMODE_ATTRIBUTE = "defaultDisabledMode";
+    public static final String CONTROLSIZE_ATTRIBUTE = "defaultControlSize";
+    public static final String NULLVALUE_ATTRIBUTE = "defaultNullValue";
+    public static final String READONLY_ATTRIBUTE = "readOnly";
+
+    // FormPartTag
+    protected RecordData record;
+    protected Object bean;
+    protected Object controlSize;
+    protected Object nullValue;
+    protected String disabledMode;
+    protected String property;
+    protected Object hiddenFields;
+    protected Object wrap;
+    
+    // temporary internal use
+    private Object oldRecord;
+    private Object oldBean;
+    private Object oldControlSize;
+    private Object oldDisabledMode;
+    private Object oldNullValue;
+    private Object oldProperty;
+    
+    /*
+     * Clears all params since tag is reused
+     */
+    @Override
+    protected void resetParams()
+    {
+        // RecordFormTag
+        record = null;
+        controlSize = null;
+        disabledMode = null;
+        nullValue = null;
+        property = null;
+        hiddenFields = null;
+        wrap = null;
+        // reset
+        super.resetParams();
+    }
+
+    @Override
+    public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res)
+    {
+        return null;
+    }
+    
+    public boolean useBean()
+    {
+        return false;
+    }
+    
+    protected boolean renderReadOnlyFields()
+    {
+        return getBoolean(hiddenFields, false);        
+    }
+    
+    protected boolean renderWrapperTag()
+    {
+        return getBoolean(wrap, true);
+    }
+    
+    @Override
+    public int doStartTag() throws JspException
+    {
+        int result = (useBean() ? super.doStartTag() : EVAL_BODY_INCLUDE);
+        // Set default Property name
+        if (property== null && record!=null)
+            property = getActionItemPropertyName();
+        // Set Record
+        if (record!= null)
+            oldRecord = putPageAttribute(EmpireValueTagSupport.RECORD_ATTRIBUTE, record);
+        if (bean!=null)
+            oldBean = putPageAttribute(EmpireValueTagSupport.BEAN_ITEM_ATTRIBUTE, bean);
+        // Parent Property
+        if (property!= null)
+            oldProperty = putPageAttribute(EmpireValueTagSupport.PARENT_PROPERTY_ATTRIBUTE, property);
+        // DisabledMode
+        if (disabledMode!=null)
+            oldDisabledMode = putPageAttribute(DISABLEDMODE_ATTRIBUTE, disabledMode);
+        // ControlSize
+        if (ObjectUtils.isEmpty(controlSize)==false)
+            oldControlSize = putPageAttribute(CONTROLSIZE_ATTRIBUTE, getString(controlSize));
+        // NullValue
+        if (ObjectUtils.isEmpty(nullValue)==false)
+            oldNullValue = putPageAttribute(NULLVALUE_ATTRIBUTE, getObject(nullValue, null));
+        // Set additional Params
+        if (record!=null && renderReadOnlyFields())
+        {   // set hidden Values
+            HtmlWriter w = new HtmlWriter(pageContext.getOut());
+            renderHiddenField(w, str(property, getActionItemPropertyName()), getRecordKey());
+            // Add Read Only field
+            renderReadOnlyColumns(w);
+        }
+        // Write Form Wrapper Tag
+        if (renderWrapperTag())
+        {   // Write Form Wrapper Tag
+            if (useBean())
+                setId(null); // Id has already be used for componentBean
+            // Render Tag
+            HtmlTagDictionary dic = HtmlTagDictionary.getInstance();  
+            HtmlWriter w = new HtmlWriter(pageContext.getOut());
+            HtmlTag wrapTag  = w.startTag( dic.FormPartWrapperTag());
+            addStandardAttributes(wrapTag, dic.FormPartWrapperClass());
+            wrapTag.addAttributes(dic.FormPartWrapperAttributes());
+            wrapTag.beginBody(true);
+        }
+        // do Start
+        return result;
+    }
+
+    @Override
+    public int doEndTag() throws JspException
+    {
+        // Close Wrapper Tag
+        if (renderWrapperTag())
+        {   // Close Form Wrapper Tag
+            HtmlTagDictionary dic = HtmlTagDictionary.getInstance();  
+            HtmlWriter w = new HtmlWriter(pageContext.getOut());
+            HtmlTag wrap = w.continueTag(dic.FormPartWrapperTag(), true);
+            wrap.endTag();
+        }
+        // NullValue
+        if (nullValue!=null)
+            removePageAttribute(NULLVALUE_ATTRIBUTE, oldNullValue);
+        oldNullValue = null;
+        // ControlSize
+        if (controlSize!=null)
+            removePageAttribute(CONTROLSIZE_ATTRIBUTE, oldControlSize);
+        oldControlSize = null;
+        // DisabledMode
+        if (disabledMode!=null)
+            removePageAttribute(DISABLEDMODE_ATTRIBUTE, oldDisabledMode);
+        disabledMode = null;
+        // Parent Property
+        if (property!= null)
+            removePageAttribute(EmpireValueTagSupport.PARENT_PROPERTY_ATTRIBUTE, oldProperty);
+        oldProperty = null;
+        // Bean
+        if (bean!= null)
+            removePageAttribute(EmpireValueTagSupport.BEAN_ITEM_ATTRIBUTE, oldBean);
+        oldBean = null;
+        // Record
+        if (record!= null)
+            removePageAttribute(EmpireValueTagSupport.RECORD_ATTRIBUTE, oldRecord);
+        oldRecord = null;
+        // done
+        if (useBean())
+        {   // Cleanup Bean
+            return super.doEndTag();
+        }
+        else
+        {   // Dont use Bean
+            resetParams();
+            return EVAL_PAGE;
+        }
+    }
+    
+    private String getRecordKey()
+    {
+        if ((record instanceof Record)==false)
+            return null; // not supported
+        // find Action
+        Record rec = (Record)record;
+        if (rec.isValid()==false)
+        {   log.error("Unable to detect record key. Record supplied is not valid!");
+            return null;
+        }
+        Object action = this.pageContext.getRequest().getAttribute("action");
+        if (action instanceof ActionBase)
+        {
+            return ((ActionBase)action).getRecordKeyString(rec);
+        }
+        // Assemble 
+        StringBuffer key = new StringBuffer();
+        Column [] keyCols = rec.getKeyColumns();
+        for (int i=0; i<keyCols.length; i++)
+        {
+            if (i>0) 
+                key.append("/");
+            key.append(StringUtils.valueOf(rec.getValue(keyCols[i])));
+        }
+        return key.toString();
+    }
+
+    private void renderHiddenField(HtmlWriter w, String name, String value)
+    {
+        HtmlTag item = w.startTag("input");
+        item.addAttribute("type", "hidden");
+        item.addAttribute("name",  name);
+        item.addAttribute("value", value);
+        item.endTag(true);
+    }
+
+    private void renderReadOnlyColumns(HtmlWriter w)
+    {
+        if (record instanceof Record && ((Record)record).isValid())
+        {   // Special Timestamp Logic
+            Column timestamp = null;
+            if (record instanceof DBRecord)
+            {   // Only for instances of DBRecord!
+                timestamp = ((DBRecord)record).getRowSet().getTimestampColumn();
+            }
+            // Key Columns
+            Record rec = (Record)record;
+            Column [] keyCols = rec.getKeyColumns();
+            String sysdate = DBDatabase.SYSDATE.toString();
+            int count = rec.getFieldCount();
+            for (int i=0; i<count; i++)
+            {
+                Column column = rec.getColumn(i);
+                if (column==null)
+                    continue;
+                if (column!=timestamp)
+                {   // Check if column was modified
+                    if (rec.wasModified(column)==false || rec.isFieldReadOnly(column)==false)
+                        continue;
+                    // Check whether column is a key column
+                    if (isKeyColumn(column, keyCols))
+                        continue;
+                }
+                // Check for Null-Value
+                if (record.isNull(i))
+                    continue;
+                // Add hidden field
+                String value = StringUtils.toString(record.getValue(i)); 
+                if (column.getDataType()==DataType.DATETIME && sysdate.equals(value)==false)
+                {   // Special for Timestamps
+                    Date date = ObjectUtils.getDate(record.getValue(i));
+                    value = formatDate(date, "yyyy-MM-dd HH:mm:ss.S");
+                }
+                else if (column.getDataType()==DataType.DATE && sysdate.equals(value)==false)
+                {   // Special for Timestamps
+                    Date date = ObjectUtils.getDate(record.getValue(i));
+                    value = formatDate(date, "yyyy-MM-dd");
+                }
+                // Add hidden field
+                renderHiddenField(w, getColumnPropertyName(column, property), value);
+            }
+        }
+    }
+    
+    private String formatDate(Date date, String format)
+    {
+        try {
+            SimpleDateFormat sdf = new SimpleDateFormat(format);
+            return sdf.format(date);
+        } catch(Exception e) {
+            log.error("Unable to format date", e);
+            return StringUtils.valueOf(date);
+        }
+    }
+    
+    private boolean isKeyColumn(Column column, Column[] keyCols)
+    {
+        if (keyCols!=null)
+        {
+            for (int i=0; i<keyCols.length; i++)
+                if (keyCols[i]==column)
+                    return true;
+        }
+        return false;
+    }
+
+    private String getColumnPropertyName(ColumnExpr col, String property)
+    {
+        String name = col.getName();
+        if (property==null)
+            return name+ "!";
+        // A full name
+        return property + "." + name + "!";
+    }
+    
+    // ------- Setters -------
+
+    public void setControlSize(Object controlSize)
+    {
+        this.controlSize = controlSize;
+    }
+
+    public void setNullValue(Object nullValue)
+    {
+        this.nullValue = nullValue;
+    }
+
+    public void setProperty(String property)
+    {
+        this.property = property;
+    }
+
+    public void setRecord(RecordData record)
+    {
+        this.record = record;
+    }
+
+    public void setBean(Object bean)
+    {
+        this.bean = bean;
+    }
+
+    public void setHiddenFields(Object hiddenFields)
+    {
+        this.hiddenFields = hiddenFields;
+    }
+
+    public void setDisabledMode(String disabledMode)
+    {
+        this.disabledMode = disabledMode;
+    }
+
+    public void setWrap(Object wrap)
+    {
+        this.wrap = wrap;
+    }
+
+}

Added: incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/FormSubmitTag.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/FormSubmitTag.java?rev=683198&view=auto
==============================================================================
--- incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/FormSubmitTag.java (added)
+++ incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/FormSubmitTag.java Wed Aug  6 02:34:41 2008
@@ -0,0 +1,204 @@
+/*
+ * ESTEAM Software GmbH, 06.07.2007
+ */
+package org.apache.empire.struts2.jsp.tags;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.jsp.JspException;
+
+import org.apache.empire.struts2.html.HtmlTagDictionary;
+import org.apache.empire.struts2.html.HtmlWriter;
+import org.apache.empire.struts2.html.HtmlWriter.HtmlTag;
+import org.apache.struts2.components.Component;
+
+import com.opensymphony.xwork2.util.ValueStack;
+
+
+@SuppressWarnings("serial")
+public class FormSubmitTag extends EmpireTagSupport
+{
+    // Properties
+    protected String text; 
+    protected String action;
+    protected Object redirect;
+    protected Object disabled;
+    protected String tabindex;
+    protected String onclick;
+    protected Object embed;
+    protected String name;
+    
+    @Override
+    protected void resetParams()
+    {
+        text = null; 
+        name = null;
+        action = null;
+        disabled = null;
+        tabindex = null;
+        onclick = null;
+        redirect = null;
+        embed = null;
+        // reset
+        super.resetParams();
+    }
+    
+    @Override
+    public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res)
+    {
+        // Create Anchor Component
+        log.error("No Bean avaliable for Submit tag.");
+        return null; 
+    }
+
+    @Override
+    protected void populateParams()
+    {
+        log.error("Illegar mehtod call.");
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public int doStartTag() throws JspException
+    {
+        HtmlTagDictionary dic = HtmlTagDictionary.getInstance();
+        HtmlWriter w = new HtmlWriter(pageContext.getOut());
+        // Wrap button like an input control
+        if (getBoolean(embed, false))
+        {
+            // the wrapper (only if renderLabel && renderControl are both true)
+            HtmlTag wrapper = w.startTag( dic.InputWrapperTag());
+            wrapper.addAttribute("class", dic.InputWrapperClass());
+            wrapper.beginBody(true);
+            
+            HtmlTag wrapCtrl = w.startTag( dic.SubmitControlTag());
+            wrapCtrl.addAttribute("class", dic.SubmitControlClass());
+            wrapCtrl.addAttributes(dic.SubmitControlAttributes());
+            wrapCtrl.beginBody();
+        }
+        // Button
+        renderButtonStart(w);
+        // return usesBody ? EVAL_BODY_BUFFERED : EVAL_BODY_INCLUDE;
+        return EVAL_BODY_INCLUDE;
+    }
+    
+    @SuppressWarnings("unchecked")
+    @Override
+    public int doEndTag() throws JspException
+    {
+        HtmlTagDictionary dic = HtmlTagDictionary.getInstance();
+        HtmlWriter w = new HtmlWriter(pageContext.getOut());
+        // End Button
+        renderButtonEnd(w);
+        // Has Wrappers
+        if (getBoolean(embed, false))
+        {   // End Control Wrapper 
+            HtmlTag wrapCtrl = w.continueTag( dic.SubmitControlTag(), true);
+            wrapCtrl.endTag();
+            // End Wrapper 
+            HtmlTag wrapper = w.continueTag( dic.InputWrapperTag(), true);
+            wrapper.endTag();
+        }    
+        // done
+        resetParams();
+        // Done
+        return EVAL_PAGE;
+    }
+    
+    private void renderButtonStart(HtmlWriter w)
+    {
+        // Tabel cell tag
+        HtmlTag button = w.startTag("button");
+        button.addAttribute("id",   getId());
+        button.addAttribute("type", "submit");
+        button.addAttribute("name", getButtonName());
+        // General Attributes
+        button.addAttribute("onclick", onclick);
+        button.addAttribute("disabled", getBoolean(disabled, false));
+        button.addAttribute("tabindex", getString (tabindex, null));
+        // Commmon
+        button.addAttribute("class", getButtonClass());
+        button.addAttribute("style", cssStyle);
+        // Button Text
+        button.beginBody(getString(text));
+    }
+
+    private void renderButtonEnd(HtmlWriter w)
+    {
+        // Write End Tag
+        HtmlTag menu = w.continueTag ("button", true);
+        menu.endTag();
+    }
+    
+    private String getButtonName()
+    {
+        if (name!=null)
+        {
+            if (action!=null)
+            {
+                log.warn("Name is set on submit button. Action property is ignored! " + action);
+            }
+            return name;
+        }
+        // Method given?
+        if (action==null)
+        {
+            return null;
+        }
+        // Set Name from method
+        String call = (getBoolean(redirect, false) ? "redirect-action:" : "action:");
+        return call + checkAction(action);
+    }
+    
+    private String getButtonClass()
+    {
+        // get Default Class
+        if (cssClass!=null)
+            return cssClass;
+        // Get Class from Dictionary
+        HtmlTagDictionary dic = HtmlTagDictionary.getInstance();
+        return dic.SubmitClass();
+    }
+    
+    // ------- Property setters -------
+
+    public void setAction(String action)
+    {
+        this.action = action;
+    }
+
+    public void setDisabled(Object disabled)
+    {
+        this.disabled = disabled;
+    }
+
+    public void setOnclick(String onclick)
+    {
+        this.onclick = onclick;
+    }
+
+    public void setTabindex(String tabindex)
+    {
+        this.tabindex = tabindex;
+    }
+
+    public void setText(String text)
+    {
+        this.text = text;
+    }
+
+    public void setRedirect(Object redirect)
+    {
+        this.redirect = redirect;
+    }
+
+    public void setEmbed(Object embed)
+    {
+        this.embed = embed;
+    }
+
+    public void setName(String name)
+    {
+        this.name = name;
+    }
+}

Added: incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/FormTag.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/FormTag.java?rev=683198&view=auto
==============================================================================
--- incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/FormTag.java (added)
+++ incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/FormTag.java Wed Aug  6 02:34:41 2008
@@ -0,0 +1,159 @@
+package org.apache.empire.struts2.jsp.tags;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.jsp.JspException;
+
+import org.apache.empire.struts2.html.HtmlTagDictionary;
+import org.apache.empire.struts2.jsp.components.FormComponent;
+import org.apache.struts2.components.Component;
+
+import com.opensymphony.xwork2.util.ValueStack;
+
+
+@SuppressWarnings("serial")
+public class FormTag extends FormPartTag // FormTag
+{
+    // FormTag
+    protected String action;
+    protected String name;
+    protected String onsubmit;
+    protected Object readOnly;
+    protected String target;
+    protected String enctype;
+    protected String method;
+    
+    /*
+     * InputControlTag Constructor
+     */
+    public FormTag()
+    {
+        this.method = "post";
+    }
+
+    /*
+     * Clears all params since tag is reused
+     */
+    @Override
+    protected void resetParams()
+    {
+        // FormTag
+        action = null;
+        name = null;
+        onsubmit = null;
+        readOnly = null;
+        target = null;
+        enctype = null;
+        // method = null; // Don't reset this
+        // reset
+        super.resetParams();
+    }
+    
+    @Override
+    public boolean useBean()
+    {
+        return true;
+    }
+    
+    @Override
+    public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res)
+    {
+        return new FormComponent(stack, req, res);
+    }
+    
+    @Override
+    protected void populateParams()
+    {
+        action = checkAction(action);
+
+        if (onsubmit==null)
+            onsubmit= HtmlTagDictionary.getInstance().FormDefaultOnSubmitScript();
+        
+        super.populateParams();
+
+        // Form Component
+        FormComponent comp = (FormComponent)component;
+        comp.setAction(action);
+        comp.setName(name);
+        comp.setOnsubmit(onsubmit);
+        comp.setTarget(target);
+        comp.setEnctype(enctype);
+        comp.setMethod(method);
+        comp.setReadOnly(getBoolean(readOnly, false));
+    }
+    
+    @Override
+    public int doStartTag() throws JspException
+    {
+        int result = super.doStartTag();
+        // Set default Property name
+        if (getBoolean(readOnly, false))
+            putPageAttribute(READONLY_ATTRIBUTE, true);
+        // do Start
+        return result;
+    }
+
+    @Override
+    public int doEndTag() throws JspException
+    {
+        // Remove Read Only
+        if (getBoolean(readOnly, false))
+            removePageAttribute(READONLY_ATTRIBUTE, null);
+        // done
+        return super.doEndTag();
+    }
+    
+    @Override
+    protected boolean renderReadOnlyFields()
+    {
+        if (getBoolean(readOnly, false)==true)
+            return false;
+        // Default is to render the hidden fields
+        return getBoolean(hiddenFields, true);        
+    }
+
+    @Override
+    protected boolean renderWrapperTag()
+    {
+        HtmlTagDictionary dic = HtmlTagDictionary.getInstance();  
+        return getBoolean(wrap, dic.FormDefaultRenderWrapper());
+    }
+    
+    // ------- Setters -------
+
+    public void setAction(String action)
+    {
+        this.action = action;
+    }
+
+    public void setEnctype(String enctype)
+    {
+        this.enctype = enctype;
+    }
+
+    public void setMethod(String method)
+    {
+        this.method = method;
+    }
+
+    public void setName(String name)
+    {
+        this.name = name;
+    }
+
+    public void setOnsubmit(String onsubmit)
+    {
+        this.onsubmit = onsubmit;
+    }
+
+    public void setTarget(String target)
+    {
+        this.target = target;
+    }
+
+    public void setReadOnly(Object readOnly)
+    {
+        this.readOnly = readOnly;
+    }
+
+}

Added: incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/InputControlTag.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/InputControlTag.java?rev=683198&view=auto
==============================================================================
--- incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/InputControlTag.java (added)
+++ incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/InputControlTag.java Wed Aug  6 02:34:41 2008
@@ -0,0 +1,290 @@
+package org.apache.empire.struts2.jsp.tags;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.empire.commons.ObjectUtils;
+import org.apache.empire.commons.Options;
+import org.apache.empire.commons.StringUtils;
+import org.apache.empire.data.Column;
+import org.apache.empire.data.Record;
+import org.apache.empire.struts2.jsp.components.InputControlComponent;
+import org.apache.empire.struts2.jsp.controls.InputControl;
+import org.apache.empire.struts2.jsp.controls.InputControlManager;
+import org.apache.struts2.components.Component;
+
+import com.opensymphony.xwork2.util.ValueStack;
+
+
+@SuppressWarnings("serial")
+public class InputControlTag extends EmpireValueTagSupport // AbstractUITag
+{
+    // InputControlTag
+    protected Column    column;
+    protected Options   options;
+    protected String    controlType;
+    protected String    render;         // 'label', 'control' or 'all'
+    protected String    disabledMode;   // 'simple' or 'control'
+    protected String    format;  
+    protected Object    hsize;
+    protected Object    vsize;
+    
+    // AbstractUITag
+    protected String    name;
+    protected String    label;
+    protected String    labelClass;
+    protected String    labelStyle;
+    protected Object    required;
+    protected Object    disabled;
+    protected String    tabindex;
+    protected String    onclick;
+    protected String    onchange;
+    protected String    onfocus;
+    protected String    onblur;
+    protected Object    nullValue;
+    
+    /*
+     * Clears all params since tag is reused
+     */
+    @Override
+    protected void resetParams()
+    {
+        // Release All Variables
+        column = null;
+        options = null;
+        controlType = null;
+        render = null;
+        disabledMode = null;
+        format = null;
+        hsize = null;
+        vsize = null;
+        // AbstractUITag
+        name = null;
+        label = null;
+        labelClass = null;
+        labelStyle = null;
+        required = null;
+        disabled = null;
+        onclick = null;
+        onchange = null;
+        onfocus = null;
+        onblur = null;
+        tabindex = null;
+        nullValue = null;
+        // super
+        super.resetParams();
+    }
+
+    @Override
+    public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res)
+    {
+        // Detect control type and readOnly state
+        if (controlType==null)
+            controlType = getControlType();
+        // Create
+        InputControl control = InputControlManager.getControl(controlType);
+        if (control == null)
+            control = InputControlManager.getControl("text");
+        // Create component
+        return new InputControlComponent(control, stack, req, res);
+    }
+
+    @Override
+    protected void populateParams()
+    {
+        super.populateParams();
+        
+        if (disabledMode==null)
+            disabledMode= StringUtils.toString(getPageAttribute(FormPartTag.DISABLEDMODE_ATTRIBUTE, null));
+
+        // Init Component
+        InputControlComponent comp = (InputControlComponent) component;
+        
+        // Control Component
+        comp.setOptions( getLookupOptions() );
+        comp.setColumn(  column );
+        comp.setRecordValue( getValue() );
+        comp.setNullValue( getObject(nullValue, getPageAttribute(FormPartTag.NULLVALUE_ATTRIBUTE, null )));
+        // Set Value
+
+        // InputControlComponent
+        comp.setName (getString( name,  getControlName() ));
+        comp.setLabel(getString( label, getTranslation( column.getTitle()) ));
+        comp.setLabelClass( this.labelClass );
+        comp.setLabelStyle( this.labelStyle );
+        comp.setRequired( isRequired() ? "true" : "false" );
+        comp.setReadOnly( isReadOnly() ); // berücksichtigt disabled!
+        comp.setRenderType(render);
+        comp.setDisabledMode(disabledMode);
+
+        // Common UI
+        comp.setFormat(format);
+        comp.setHSize( getString(hsize, getPageAttribute(FormPartTag.CONTROLSIZE_ATTRIBUTE, null )));
+        comp.setVSize( getString(vsize) );
+        comp.setOnclick(onclick);
+        comp.setOnchange(onchange);
+        comp.setOnfocus(onfocus);
+        comp.setOnblur(onblur);
+        comp.setTabindex(getString(tabindex));
+    }
+
+    private boolean isReadOnly()
+    {
+        if (disabled!=null)
+            return getBoolean(disabled, false);
+        // Default
+        Object readOnly = getPageAttribute(FormPartTag.READONLY_ATTRIBUTE, null);
+        if (readOnly!=null && ObjectUtils.getBoolean(readOnly))
+            return true; // Form is read Only
+        // Detect only if record is supplied!
+        Record record = getRecord(); 
+        if (record!=null)
+            return record.isFieldReadOnly(column);
+        else if (getRecordData()!=null)
+            return true; // Only a record data object
+        else if (getBean()!=null)
+            return column.isReadOnly();
+        // Render editable
+        return false;
+    }
+
+    private boolean isRequired()
+    {
+        if (required!=null)
+            return getBoolean(required, false);        
+        if (getRecord()!=null || getBean()!=null)
+            return column.isRequired();
+        // Default
+        return false;
+    }
+    
+    private String getControlName()
+    {
+        // Direct propety Name
+        String name = getPropertyFieldName();
+        if (name!=null)
+            return name;
+        // Use Column Name
+        return getColumnPropertyName(column);
+    }
+
+    private Options getLookupOptions()
+    {
+        if (options == null)
+        { // Get List from Column
+            Record rec = getRecord();
+            if (rec!=null && rec.isValid())
+            { // Options from Record
+                return rec.getFieldOptions(column);
+            } else
+            { // Options from column
+                return column.getOptions();
+            }
+        }
+        // Set List
+        return options;
+    }
+
+    // ********* All Setters *********
+
+    public void setColumn(Column column)
+    {
+        this.column = column;
+        super.setColumn(column);
+    }
+
+    public void setOptions(Options options)
+    {
+        this.options = options;
+    }
+
+    public void setRender(String render)
+    {
+        this.render = render;
+    }
+
+    public void setDisabledMode(String disabledMode)
+    {
+        this.disabledMode = disabledMode;
+    }
+
+    public void setFormat(String format)
+    {
+        this.format = format;
+    }
+
+    public void setDisabled(Object disabled)
+    {
+        this.disabled = disabled;
+    }
+
+    public void setLabel(String label)
+    {
+        this.label = label;
+    }
+
+    public void setLabelClass(String labelClass)
+    {
+        this.labelClass = labelClass;
+    }
+
+    public void setLabelStyle(String labelStyle)
+    {
+        this.labelStyle = labelStyle;
+    }
+
+    public void setName(String name)
+    {
+        this.name = name;
+    }
+
+    public void setRequired(Object required)
+    {
+        this.required = required;
+    }
+
+    public void setTabindex(String tabindex)
+    {
+        this.tabindex = tabindex;
+    }
+
+    public void setHsize(Object hsize)
+    {
+        this.hsize = hsize;
+    }
+
+    public void setVsize(Object vsize)
+    {
+        this.vsize = vsize;
+    }
+
+    public void setNullValue(Object nullValue)
+    {
+        this.nullValue = nullValue;
+    }
+
+    public void setOnclick(String onclick)
+    {
+        this.onclick = onclick;
+    }
+
+    public void setControlType(String controlType)
+    {
+        this.controlType = controlType;
+    }
+
+    public void setOnblur(String onblur)
+    {
+        this.onblur = onblur;
+    }
+
+    public void setOnchange(String onchange)
+    {
+        this.onchange = onchange;
+    }
+
+    public void setOnfocus(String onfocus)
+    {
+        this.onfocus = onfocus;
+    }
+}

Added: incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/ItemListTag.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/ItemListTag.java?rev=683198&view=auto
==============================================================================
--- incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/ItemListTag.java (added)
+++ incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/ItemListTag.java Wed Aug  6 02:34:41 2008
@@ -0,0 +1,407 @@
+package org.apache.empire.struts2.jsp.tags;
+
+import java.io.Writer;
+import java.util.Iterator;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.PageContext;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.empire.db.DBReader;
+import org.apache.struts2.components.Component;
+import org.apache.struts2.components.IteratorComponent;
+import org.apache.struts2.util.MakeIterator;
+import org.apache.struts2.views.jsp.IteratorStatus;
+import org.apache.struts2.views.jsp.IteratorTag;
+
+import com.opensymphony.xwork2.util.ValueStack;
+
+
+@SuppressWarnings("serial")
+public class ItemListTag extends IteratorTag
+{
+    // Logger
+    protected static Log log = LogFactory.getLog(ItemListTag.class);
+
+    public static class ItemIteratorComponent extends IteratorComponent
+    {
+        private PageContext pageContext;
+        private boolean isReader;
+        private Object oldSource;
+        private Object srcObject;
+
+        public ItemIteratorComponent(ValueStack stack, PageContext pageContext, Object source, Iterator iterator)
+        {
+            super(stack);
+            // set iterator
+            this.pageContext = pageContext;
+            this.iterator = iterator;
+            this.isReader =(source instanceof DBReader);
+            this.srcObject = source;
+            // Store Reader on Page Context
+            if (isReader)
+            {
+                oldSource = pageContext.getAttribute(EmpireValueTagSupport.RECORD_ATTRIBUTE);
+                pageContext.setAttribute(EmpireValueTagSupport.RECORD_ATTRIBUTE, source);
+            }
+            else
+            {
+                oldSource = pageContext.getAttribute(EmpireValueTagSupport.BEAN_ITEM_ATTRIBUTE);
+                pageContext.setAttribute(EmpireValueTagSupport.BEAN_ITEM_ATTRIBUTE, null);
+            }
+        }        
+        
+        public void dispose()
+        {
+            String pageAttribute;
+            if (isReader)
+            {   // Close Reader
+                ((DBReader)srcObject).close();
+                pageAttribute = EmpireValueTagSupport.RECORD_ATTRIBUTE; 
+            }
+            else
+            {   // Bean List
+                pageAttribute = EmpireValueTagSupport.BEAN_ITEM_ATTRIBUTE; 
+            }
+            // Remove Source
+            if (oldSource!=null)
+                pageContext.setAttribute(pageAttribute, oldSource);
+            else
+                pageContext.removeAttribute(pageAttribute);
+            // done
+            pageContext = null;
+            oldSource = null;
+            srcObject = null;
+        }
+
+        @SuppressWarnings("unchecked")
+        @Override
+        public boolean start(Writer writer)
+        {
+            if (iterator==null)
+            {
+                log.error("No Iterator for ItemListTag supplied. Ignoring body");
+                return false;
+            }    
+            
+            // Create an iterator status if the status attribute was set.
+            if (statusAttr != null) {
+                statusState = new IteratorStatus.StatusState();
+                status = new IteratorStatus(statusState);
+            }
+
+            // we don't need this
+            /*
+            if (value == null) {
+                value = "top";
+            }
+            iterator = MakeIterator.convert(findValue(value));
+            */
+
+            // get the first
+            ValueStack stack = getStack();
+            if ((iterator != null) && iterator.hasNext())
+            {
+                Object currentValue = iterator.next();
+                if (currentValue!=null)
+                {
+                    stack.push(currentValue);
+                    String id = getId();
+
+                    if ((id != null))
+                    {
+                        //pageContext.setAttribute(id, currentValue);
+                        //pageContext.setAttribute(id, currentValue, PageContext.REQUEST_SCOPE);
+                        stack.getContext().put(id, currentValue);
+                    }
+
+                    // Status object
+                    if (statusAttr != null)
+                    {
+                        statusState.setLast((isReader==false) ? !iterator.hasNext() : false); 
+                        oldStatus = stack.getContext().get(statusAttr);
+                        stack.getContext().put(statusAttr, status);
+                    }
+
+                    // Set current Value
+                    if (isReader==false)
+                        pageContext.setAttribute(EmpireValueTagSupport.BEAN_ITEM_ATTRIBUTE, currentValue);
+                    
+                    // Return with valid iterator
+                    return true;
+                }
+            }
+            // Make sure iterator is set to null!
+            iterator = null;
+            // Not more Records
+            super.end(writer, "");
+            return false;
+        }
+
+        @SuppressWarnings("unchecked")
+        @Override
+        public boolean end(Writer writer, String body)
+        {
+            if (isReader)
+            {   // A reader list
+                IteratorStatus tmpStatus = status;
+                status = null;
+                // Iterate
+                boolean result = super.end(writer, body);
+                status = tmpStatus;
+                if (status!=null)
+                {
+                    if (result==true)
+                    {
+                        statusState.next(); // Increase counter
+                        // statusState.setLast(!iterator.hasNext());
+                    }
+                    else 
+                    {
+                        if (oldStatus == null) {
+                            stack.getContext().put(statusAttr, null);
+                        } else {
+                            stack.getContext().put(statusAttr, oldStatus);
+                        }
+                    }
+                }
+                // done
+                return result;
+            }
+            else
+            {   // A bean list
+                boolean result = super.end(writer, body);
+                if (result)
+                {   // Set current Value
+                    ValueStack stack = getStack();
+                    pageContext.setAttribute(EmpireValueTagSupport.BEAN_ITEM_ATTRIBUTE, stack.peek());
+                }
+                return result;
+            }
+        }    
+        
+    }
+
+    // Properties
+    private Object source;
+    private Object maxItems;
+    private String property;
+
+    // Temporay
+    private Object sourceObject;     
+    private Object oldProperty;
+    private Object oldStatusAttr;
+
+    /*
+     * Constructor
+     */
+    public ItemListTag()
+    {
+        // Default constructor
+    }
+
+    /*
+     * Clears all params since tag is reused
+     */
+    public void resetParams()
+    {
+        // Optional
+        source = null;
+        maxItems = null;
+        statusAttr = null;
+        sourceObject = null;
+    }
+    
+    @Override
+    public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res)
+    {
+        // Make Iterator
+        Iterator iterator = getIterator(sourceObject);
+        // Create Compontent
+        return new ItemIteratorComponent(stack, pageContext, sourceObject, iterator);
+    }
+
+    @Override
+    public int doStartTag() throws JspException
+    {
+        // Reader
+        sourceObject = getSourceObject(source);
+        if (source==null)
+        {   log.error("No reader or beanlist supplied for e:list tag. Skipping body.");
+            property = null;
+            return SKIP_BODY;
+        }
+        // Set Status Attribute Name and store it on page context
+        oldStatusAttr = pageContext.getAttribute(TableRowTag.ITERATOR_STATUS_ATTRIBUTE);
+        if (oldStatusAttr!=null)
+            statusAttr = oldStatusAttr.toString() + "Nested";
+        else
+            statusAttr = "listStatusAttrName";
+        pageContext.setAttribute(TableRowTag.ITERATOR_STATUS_ATTRIBUTE, statusAttr);
+        // Parent Property
+        if (property!= null)
+        {
+            oldProperty = pageContext.getAttribute(EmpireValueTagSupport.PARENT_PROPERTY_ATTRIBUTE);
+            pageContext.setAttribute(EmpireValueTagSupport.PARENT_PROPERTY_ATTRIBUTE, property);
+        }
+        // do Start
+        return super.doStartTag();
+    }
+
+    @Override
+    public int doEndTag() throws JspException
+    {
+        // Parent Property
+        if (property!= null)
+            removePageAttribute(EmpireValueTagSupport.PARENT_PROPERTY_ATTRIBUTE, oldProperty);
+        oldProperty = null;
+        // Status Attribute
+        if (statusAttr!= null)
+            removePageAttribute(TableRowTag.ITERATOR_STATUS_ATTRIBUTE, oldStatusAttr);
+        oldStatusAttr = null;
+        // Remove Component
+        if (component!=null)
+           ((ItemIteratorComponent)component).dispose();
+        // End
+        resetParams();
+        return super.doEndTag();
+    }
+
+    // ------- Helpers -------
+
+    private void removePageAttribute(String name, Object oldValue)
+    {
+        if ( oldValue!=null )
+             pageContext.setAttribute(name, oldValue);
+        else pageContext.removeAttribute(name);
+    }
+    
+    private Object getSourceObject(Object value)
+    {
+        // Check String
+        if ((value instanceof String))
+        {
+            // Check Value
+            String strval = value.toString();
+            if (strval.startsWith("%{") && strval.endsWith("}"))
+            { // OGNL
+                strval = strval.substring(2, strval.length() - 1);
+                value = getStack().findValue(strval);
+            }
+            else if (strval.startsWith("#"))
+            { // OGNL
+                value = getStack().findValue(strval);
+            }
+            else if (strval.startsWith("$"))
+            { // Attribute on page, request, session or application (in this order)
+                strval = strval.substring(1);
+                if (strval.startsWith("$") == false)
+                    value = getAttribute(strval);
+                if (value == null)
+                    return null;
+            }
+        }
+        return value;
+    }
+    
+    private Iterator getIterator(Object value)
+    {
+        // 
+        if (value instanceof DBReader)
+        {
+            // Create Component
+            int maxCount = getIntValue(maxItems, -1);
+            return ((DBReader)value).iterator(maxCount);
+        }
+        // Error
+        if (MakeIterator.isIterable(value)==false)
+        {
+            log.error("Cannot make an iterator of class " + value.getClass().getName());
+            return null;
+        }
+        // Done
+        return MakeIterator.convert(value);
+    }
+    
+    private int getIntValue(Object value, int defValue)
+    {
+        if (value==null)
+            return defValue;
+        if (value instanceof String)
+        {
+            // Check Value
+            String strval = value.toString();
+            if (strval.startsWith("%{") && strval.endsWith("}"))
+            { // OGNL
+                strval = strval.substring(2, strval.length() - 1);
+                value = getStack().findValue(strval, java.lang.Integer.class);
+            }
+            if (strval.startsWith("#"))
+            { // OGNL
+                value = getStack().findValue(strval, java.lang.Integer.class);
+            }
+            if (strval.startsWith("$"))
+            { // Attribute on page, request, session or application (in this order)
+                strval = strval.substring(1);
+                if (strval.startsWith("$") == false)
+                    value = getAttribute(strval);
+                if (value == null)
+                    return defValue;
+            }
+        }
+        // Check Type
+        if (value instanceof Integer)
+        {
+            return ((Integer)value).intValue();
+        }
+        // Parse String
+        try 
+        {   // Get Integer from String   
+            return Integer.parseInt(value.toString());
+            
+        } catch(Exception e) {
+            // failed to convert
+            log.error("getIntFromString: given value is not a number!");
+            return defValue;
+        }
+    }
+
+    protected Object getAttribute(String attribute)
+    {
+        // Try Page
+        Object obj = pageContext.getAttribute(attribute);
+        if (obj != null)
+            return obj;
+        // Try Request
+        obj = pageContext.getRequest().getAttribute(attribute);
+        if (obj != null)
+            return obj;
+        // Try Session
+        obj = pageContext.getSession().getAttribute(attribute);
+        if (obj != null)
+            return obj;
+        // Try Application
+        return pageContext.getServletContext().getAttribute(attribute);
+    }
+    
+    // ------- Property accessors -------
+
+    public void setSource(Object source)
+    {
+        this.source = source;
+    }
+
+    public void setMaxItems(Object maxItems)
+    {
+        this.maxItems = maxItems;
+    }
+
+    public void setProperty(String property)
+    {
+        this.property = property;
+    }
+
+}

Added: incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/LinkTag.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/LinkTag.java?rev=683198&view=auto
==============================================================================
--- incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/LinkTag.java (added)
+++ incubator/empire-db/trunk/struts2-ext/Empire-struts2-ext/src/org/apache/empire/struts2/jsp/tags/LinkTag.java Wed Aug  6 02:34:41 2008
@@ -0,0 +1,153 @@
+package org.apache.empire.struts2.jsp.tags;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.jsp.JspException;
+
+import org.apache.empire.struts2.jsp.components.AnchorComponent;
+import org.apache.struts2.components.Component;
+
+import com.opensymphony.xwork2.util.ValueStack;
+
+
+@SuppressWarnings("serial")
+public class LinkTag extends EmpireTagSupport // AbstractRemoteCallUITag
+{
+    // LinkTag
+    protected String action;
+    protected Object item;
+    protected String text;
+    protected Object disabled;
+    protected String target;
+    protected String param;
+    protected String onclick;
+    protected Object visible;
+
+    public LinkTag()
+    {
+        // Default constructor
+    }
+
+    /*
+     * Clears all params since tag is reused
+     */
+    @Override
+    protected void resetParams()
+    {
+        // LinkTag
+        action = null;
+        item = null;
+        text = null;
+        disabled = null;
+        target = null;
+        param = null;
+        onclick = null;
+        visible = null;
+        // call base
+        super.resetParams();
+    }
+
+    @Override
+    public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res)
+    {
+        return new AnchorComponent(stack, req, res);
+    }
+
+    @Override
+    protected void populateParams()
+    {
+        // Checks action param and warns if method is not supplied
+        action = checkAction(action);
+
+        /*
+        if (onclick == null)
+            onclick = HtmlTagDictionary.getInstance().AnchorDefaultOnClickScript();
+        */    
+
+        super.populateParams();
+
+        AnchorComponent anchor = (AnchorComponent) component;
+        // Set item param
+        if (item != null)
+        {
+            anchor.addParameter(str(param, getActionItemPropertyName()), getString(item));
+        }
+        // get Href
+        anchor.setAction(action);
+        anchor.setText(getString(text));
+        anchor.setDisabled(getBoolean(disabled, false));
+        anchor.setTargets(target);
+        anchor.setOnclick(onclick);
+    }
+
+    @Override
+    public int doStartTag()
+        throws JspException
+    {
+        // check visibility
+        if (getBoolean(visible, true)==false)
+        {   // not visible
+            return SKIP_BODY;
+        }
+        // Render Link
+        return super.doStartTag();
+    }
+
+    @Override
+    public int doEndTag()
+        throws JspException
+    {
+        // check visibility
+        if (getBoolean(visible, true)==false)
+        {   // Not visible
+            if (autoResetParams)
+                resetParams();
+            return EVAL_PAGE;
+        }    
+        // End tag
+        return super.doEndTag();
+    }
+
+    // -------------------------------- Property accessors -----------------------------
+
+    public void setAction(String action)
+    {
+        this.action = action;
+    }
+
+    public void setItem(Object item)
+    {
+        this.item = item;
+    }
+
+    public void setText(String text)
+    {
+        this.text = text;
+    }
+
+    public void setDisabled(Object disabled)
+    {
+        this.disabled = disabled;
+    }
+
+    public void setTarget(String target)
+    {
+        this.target = target;
+    }
+
+    public void setParam(String param)
+    {
+        this.param = param;
+    }
+
+    public void setOnclick(String onclick)
+    {
+        this.onclick = onclick;
+    }
+
+    public void setVisible(Object visible)
+    {
+        this.visible = visible;
+    }
+
+}