You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2008/02/06 01:46:02 UTC

svn commit: r618842 [2/3] - in /myfaces/tomahawk/branches/1_2_0/core: ./ src/main/java-templates/org/apache/myfaces/component/html/ext/ src/main/java-templates/org/apache/myfaces/custom/buffer/ src/main/java-templates/org/apache/myfaces/custom/checkbox...

Added: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/component/html/ext/AbstractHtmlSelectOneRadio.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/component/html/ext/AbstractHtmlSelectOneRadio.java?rev=618842&view=auto
==============================================================================
--- myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/component/html/ext/AbstractHtmlSelectOneRadio.java (added)
+++ myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/component/html/ext/AbstractHtmlSelectOneRadio.java Tue Feb  5 16:45:49 2008
@@ -0,0 +1,223 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.myfaces.component.html.ext;
+
+import java.util.Iterator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.component.UserRoleAware;
+import org.apache.myfaces.component.UserRoleUtils;
+import org.apache.myfaces.component.html.util.HtmlComponentUtils;
+import org.apache.myfaces.shared_tomahawk.component.DisplayValueOnlyCapable;
+import org.apache.myfaces.shared_tomahawk.component.EscapeCapable;
+import org.apache.myfaces.shared_tomahawk.renderkit.JSFAttr;
+import org.apache.myfaces.shared_tomahawk.util.MessageUtils;
+
+import javax.faces.FacesException;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.el.EvaluationException;
+import javax.faces.el.MethodBinding;
+import javax.faces.validator.Validator;
+import javax.faces.validator.ValidatorException;
+
+/**
+ * @author Leonardo Uribe (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+abstract class AbstractHtmlSelectOneRadio
+        extends javax.faces.component.html.HtmlSelectOneRadio
+        implements UserRoleAware, DisplayValueOnlyCapable, EscapeCapable
+{
+    
+    public static final String DEFAULT_RENDERER_TYPE ="org.apache.myfaces.Radio";
+
+    private static Log log = LogFactory.getLog(AbstractHtmlSelectOneRadio.class);
+    
+    public String getClientId(FacesContext context)
+    {
+        String clientId = HtmlComponentUtils.getClientId(this, getRenderer(context), context);
+        if (clientId == null)
+        {
+            clientId = super.getClientId(context);
+        }
+
+        return clientId;
+    }
+
+    public boolean isRendered()
+    {
+        if (!UserRoleUtils.isVisibleOnUserRole(this)) return false;
+        return super.isRendered();
+    }
+    
+    private static void callValidators(FacesContext context, UIComponent input, Object convertedValue)
+    {
+        if(!(input instanceof EditableValueHolder))
+            throw new FacesException("param input not of type EditableValueHolder, but of : "+input.getClass().getName());
+
+        EditableValueHolder holder = (EditableValueHolder) input;
+
+        Validator[] validators = holder.getValidators();
+        for (int i = 0; i < validators.length; i++)
+        {
+            Validator validator = validators[i];
+            try
+            {
+                validator.validate(context, input, convertedValue);
+            }
+            catch (ValidatorException e)
+            {
+                holder.setValid(false);
+                FacesMessage facesMessage = e.getFacesMessage();
+                if (facesMessage != null)
+                {
+                    facesMessage.setSeverity(FacesMessage.SEVERITY_ERROR);
+                    context.addMessage(input.getClientId(context), facesMessage);
+                }
+            }
+        }
+
+        MethodBinding validatorBinding = holder.getValidator();
+        if (validatorBinding != null)
+        {
+            try
+            {
+                validatorBinding.invoke(context, new Object[] {context, input, convertedValue});
+            }
+            catch (EvaluationException e)
+            {
+                holder.setValid(false);
+                Throwable cause = e.getCause();
+                if (cause instanceof ValidatorException)
+                {
+                    FacesMessage facesMessage = ((ValidatorException) cause).getFacesMessage();
+                    if (facesMessage != null)
+                    {
+                        facesMessage.setSeverity(FacesMessage.SEVERITY_ERROR);
+                        context.addMessage(input.getClientId(context), facesMessage);
+                    }
+                }
+                else
+                {
+                    throw e;
+                }
+            }
+        }
+    }
+    
+    private static boolean getBooleanValue(String attribute, Object value, boolean defaultValue)
+    {
+        if(value instanceof Boolean)
+        {
+            return ((Boolean) value).booleanValue();
+        }
+        else if(value instanceof String)
+        {
+            return Boolean.valueOf((String) value).booleanValue();
+        }
+        else if(value != null)
+        {
+            log.error("value for attribute "+attribute+
+                    " must be instanceof 'Boolean' or 'String', is of type : "+value.getClass());
+
+            return defaultValue;
+        }
+
+        return defaultValue;
+    }
+    
+    /**
+     * Overridden method, as with extended seletOne, value doesn't necessarily
+     * have to be contained within select list, for example, when forceId="true" and
+     * forceIdIndex="false" then component may be used in datatable.
+     */
+    protected void validateValue(FacesContext context, Object value)
+    {
+        //Is this radio button used within a datatable (forceId=true and forceIdIndex=false)
+        boolean forceId = getBooleanValue(JSFAttr.FORCE_ID_ATTR,
+                this.getAttributes().get(JSFAttr.FORCE_ID_ATTR), false);
+
+//      see if the originally supplied id should be used
+        boolean forceIdIndex = getBooleanValue(JSFAttr.FORCE_ID_INDEX_ATTR,
+                this.getAttributes().get(JSFAttr.FORCE_ID_INDEX_ATTR), true);
+
+        boolean dataTable = forceId && !forceIdIndex;
+
+        if (!dataTable)
+        {
+            super.validateValue(context, value);
+        }
+        else
+        {
+            //Specific behavior for data tables, or other scenarios where forceId is
+            //true and forceIdIndex is false
+
+            //Check if empty
+            boolean empty = value == null
+                    || (value instanceof String && ((String) value).length() == 0);
+
+            //Check required and empty
+            if (isRequired() && empty)
+            {
+              //Only add this message once, not for every radio button in set
+                String clientId = this.getClientId(context);
+                Iterator messages = context.getMessages(clientId);
+                boolean messageExists = messages.hasNext();
+
+                if(!messageExists)
+                {
+                    //Add message
+                    FacesMessage message = MessageUtils.getMessage(REQUIRED_MESSAGE_ID, new Object[]{clientId});
+                    message.setSeverity(FacesMessage.SEVERITY_WARN);
+                    context.addMessage(clientId, message);
+
+                    setValid(false);
+                }
+                return;
+            }
+
+            //Call validators
+            if (!empty)
+            {
+                callValidators(context, this, value);
+            }
+        }
+    }
+    
+    public abstract Boolean getDisplayValueOnly();
+    
+    public boolean isSetDisplayValueOnly(){
+        return getDisplayValueOnly() != null ? true : false;  
+    }
+    
+    public boolean isDisplayValueOnly(){
+        return getDisplayValueOnly() != null ? getDisplayValueOnly() : false;
+    }
+    
+    public abstract void setDisplayValueOnly(Boolean b);
+    public void setDisplayValueOnly(boolean displayValueOnly){
+        this.setDisplayValueOnly((Boolean) Boolean.valueOf(displayValueOnly));
+    }
+    
+    
+}

Propchange: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/component/html/ext/AbstractHtmlSelectOneRadio.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/component/html/ext/AbstractHtmlSelectOneRadio.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/buffer/AbstractBuffer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/buffer/AbstractBuffer.java?rev=618842&view=auto
==============================================================================
--- myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/buffer/AbstractBuffer.java (added)
+++ myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/buffer/AbstractBuffer.java Tue Feb  5 16:45:49 2008
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.myfaces.custom.buffer;
+
+import javax.el.ValueExpression;
+import javax.faces.component.UIComponentBase;
+import javax.faces.context.FacesContext;
+
+/**
+ * A component that renders its child components into an in-memory buffer rather than
+ * render them directly to the response stream.
+ * <p>
+ * Property "into" is an EL expression that specifies where to store a String holding
+ * the results of rendering all the children of this component; this is assigned to
+ * after rendering of this component (and its children) is complete.
+ * <p>
+ * Typically, an h:output tag is then used later in the same page to output the buffer
+ * contents.
+ * <p>
+ * This can be useful with JSF1.1/JSP2.0 to work around the well-known problem where
+ * on first render of a page, a component "A" cannot reference a component "B" which is
+ * defined later in the page because it has not yet been created. A solution is to define
+ * "B" before "A", but wrapped in a Buffer component. Component A can then be rendered
+ * and successfully reference "B" because it now exists. And later in the page, the buffer
+ * contents can then be output, preserving the original layout.
+ * <p>
+ * This can also be useful when rendering the same data block multiple times within a page.
+ * For example, a datatable can be rendered with a datascroller both before and after it;
+ * first render the table into a buffer B1, then render the datascroller into a buffer B2,
+ * then output buffers B2,B1,B2.
+ * 
+ * @author Sylvain Vieujot (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+abstract class AbstractBuffer extends UIComponentBase
+{
+    
+    protected abstract String getLocalInto();
+    
+    public abstract void setInto(String into);
+
+    void fill(String content, FacesContext facesContext){
+        ValueExpression intoVB;
+
+        if (getLocalInto() == null) {
+            intoVB = getValueExpression("into");
+            setInto(intoVB.getExpressionString());
+        } else {
+            intoVB = facesContext.getApplication().
+            getExpressionFactory().createValueExpression(
+                    facesContext.getELContext(), getLocalInto(), Object.class );
+        }
+
+        intoVB.setValue(facesContext.getELContext(), content);
+    }
+}

Propchange: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/buffer/AbstractBuffer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/buffer/AbstractBuffer.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/checkbox/AbstractHtmlCheckbox.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/checkbox/AbstractHtmlCheckbox.java?rev=618842&view=auto
==============================================================================
--- myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/checkbox/AbstractHtmlCheckbox.java (added)
+++ myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/checkbox/AbstractHtmlCheckbox.java Tue Feb  5 16:45:49 2008
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.myfaces.custom.checkbox;
+
+import org.apache.myfaces.component.UserRoleAware;
+import javax.faces.component.UIComponentBase;
+
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Leonardo Uribe (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+abstract class AbstractHtmlCheckbox
+        extends UIComponentBase implements UserRoleAware
+{
+
+    public static final String FOR_ATTR = "for".intern();
+    public static final String INDEX_ATTR = "index".intern();
+
+}

Propchange: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/checkbox/AbstractHtmlCheckbox.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/checkbox/AbstractHtmlCheckbox.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/collapsiblepanel/AbstractHtmlCollapsiblePanel.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/collapsiblepanel/AbstractHtmlCollapsiblePanel.java?rev=618842&view=auto
==============================================================================
--- myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/collapsiblepanel/AbstractHtmlCollapsiblePanel.java (added)
+++ myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/collapsiblepanel/AbstractHtmlCollapsiblePanel.java Tue Feb  5 16:45:49 2008
@@ -0,0 +1,200 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.myfaces.custom.collapsiblepanel;
+
+import java.io.IOException;
+import java.util.Iterator;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIInput;
+
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.component.UserRoleAware;
+import org.apache.myfaces.custom.collapsiblepanel.HtmlHeaderLink;
+
+/**
+ * @author Leonardo Uribe (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+abstract class AbstractHtmlCollapsiblePanel
+        extends UIInput implements UserRoleAware
+{
+
+    private boolean _currentlyCollapsed;
+    
+    public void setCurrentlyCollapsed(boolean collapsed)
+    {
+        _currentlyCollapsed = collapsed;
+    }
+
+    public boolean isCurrentlyCollapsed()
+    {
+        return _currentlyCollapsed;
+    }
+    
+    //private static final Log log = LogFactory.getLog(HtmlCollapsiblePanel.class);
+
+    public void processDecodes(FacesContext context)
+    {
+        if (context == null) throw new NullPointerException("context");
+
+        initialiseVars(context);
+
+        if (!isRendered()) return;
+
+        try
+        {
+            decode(context);
+        }
+        catch (RuntimeException e)
+        {
+            context.renderResponse();
+            throw e;
+        }
+
+        UIComponent headerComponent = getFacet("header");
+
+        if(headerComponent != null)
+        {
+            for (Iterator it = headerComponent.getChildren().iterator(); it.hasNext(); )
+            {
+                UIComponent child = (UIComponent)it.next();
+
+                if(!(child instanceof HtmlHeaderLink))
+                {
+                    child.processDecodes(context);
+                }
+            }
+        }
+
+        if(isCurrentlyCollapsed())
+        {
+            UIComponent component = getFacet("closedContent");
+
+            if(component != null)
+            {
+                component.processDecodes(context);
+            }
+        }
+        else
+        {
+            for (Iterator it = getChildren().iterator(); it.hasNext(); )
+            {
+                UIComponent child = (UIComponent)it.next();
+                child.processDecodes(context);
+            }
+        }
+        
+        removeVars(context);
+    }
+
+    public String getClientId(FacesContext context)
+    {
+        return super.getClientId(context);
+    }
+
+    public void processUpdates(FacesContext context)
+    {
+        initialiseVars(context);
+
+        super.processUpdates(context);
+
+        removeVars(context);
+    }
+    
+    public abstract String getVar();
+    
+    public abstract String getTitleVar();
+    
+    public abstract String getTitle();
+
+    private void initialiseVars(FacesContext context)
+    {
+        if(getVar()!=null)
+        {
+            context.getExternalContext().getRequestMap().put(getVar(),
+                            Boolean.valueOf(isCollapsed()));
+        }
+
+        if(getTitleVar()!=null)
+        {
+            context.getExternalContext().getRequestMap().put(getTitleVar(),
+                            getTitle());
+        }
+    }
+
+    private void removeVars(FacesContext context)
+    {
+        if(getVar()!=null)
+        {
+            context.getExternalContext().getRequestMap().remove(getVar());
+        }
+
+        if(getTitleVar()!=null)
+        {
+            context.getExternalContext().getRequestMap().remove(getTitleVar());
+        }
+    }
+
+    public void processValidators(FacesContext context)
+    {
+        initialiseVars(context);
+
+        super.processValidators(context);
+
+        removeVars(context);
+    }
+
+    public void encodeChildren(FacesContext context) throws IOException
+    {
+        initialiseVars(context);
+
+        super.encodeChildren(context);
+
+        removeVars(context);
+    }
+
+    public void updateModel(FacesContext context)
+    {
+        super.updateModel(context);
+    }
+
+    public boolean isCollapsed()
+    {
+        return isCollapsed(getValue());
+    }
+
+    public static boolean isCollapsed(Object collapsedValue)
+    {
+        Object value = collapsedValue;
+
+        if(value instanceof Boolean)
+        {
+            return ((Boolean) value).booleanValue();
+        }
+        else if (value instanceof String)
+        {
+            return Boolean.valueOf((String) value).booleanValue();
+        }
+
+        return true;
+    }
+        
+}

Propchange: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/collapsiblepanel/AbstractHtmlCollapsiblePanel.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/collapsiblepanel/AbstractHtmlCollapsiblePanel.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/column/AbstractHtmlSimpleColumn.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/column/AbstractHtmlSimpleColumn.java?rev=618842&view=auto
==============================================================================
--- myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/column/AbstractHtmlSimpleColumn.java (added)
+++ myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/column/AbstractHtmlSimpleColumn.java Tue Feb  5 16:45:49 2008
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.myfaces.custom.column;
+
+import javax.el.ValueExpression;
+import javax.faces.component.UIColumn;
+
+/**
+ * @author Leonardo Uribe (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+abstract class AbstractHtmlSimpleColumn
+        extends UIColumn implements HtmlColumn
+{
+    
+}

Propchange: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/column/AbstractHtmlSimpleColumn.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/column/AbstractHtmlSimpleColumn.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/datalist/AbstractHtmlDataList.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/datalist/AbstractHtmlDataList.java?rev=618842&view=auto
==============================================================================
--- myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/datalist/AbstractHtmlDataList.java (added)
+++ myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/datalist/AbstractHtmlDataList.java Tue Feb  5 16:45:49 2008
@@ -0,0 +1,210 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.myfaces.custom.datalist;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.component.html.util.HtmlComponentUtils;
+import org.apache.myfaces.shared_tomahawk.util._ComponentUtils;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Manfred Geiler (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+abstract class AbstractHtmlDataList
+        extends org.apache.myfaces.component.html.ext.HtmlDataTableHack
+{
+	private static Log log = LogFactory.getLog(HtmlDataList.class);
+    private static final int PROCESS_DECODES = 1;
+    private static final int PROCESS_VALIDATORS = 2; // not currently in use
+    private static final int PROCESS_UPDATES = 3; // not currently in use
+
+    /**
+     * Throws NullPointerException if context is null.  Sets row index to -1, 
+     * calls processChildren, sets row index to -1.
+     */
+
+    public void processDecodes(FacesContext context)
+    {
+
+        if (context == null)
+            throw new NullPointerException("context");
+        if (!isRendered())
+            return;
+
+        setRowIndex(-1);
+        processChildren(context, PROCESS_DECODES);
+        setRowIndex(-1);
+    }
+
+    public void processUpdates(FacesContext context)
+    {
+        if (context == null)
+            throw new NullPointerException("context");
+        if (!isRendered())
+            return;
+
+        setRowIndex(-1);
+        processChildren(context, PROCESS_UPDATES);
+        setRowIndex(-1);
+    }
+
+    public void processValidators(FacesContext context)
+    {
+        if (context == null)
+            throw new NullPointerException("context");
+        if (!isRendered())
+            return;
+
+        setRowIndex(-1);
+        processChildren(context, PROCESS_VALIDATORS);
+        setRowIndex(-1);    }
+
+    /**
+     * Iterates over all children, processes each according to the specified 
+     * process action if the child is rendered.
+     */
+
+    public void processChildren(FacesContext context, int processAction)
+    {
+        // use this method for processing other than decode ?
+        int first = getFirst();
+        int rows = getRows();
+        int last = rows == 0 ? getRowCount() : first + rows;
+
+        if (log.isTraceEnabled())
+        {
+            log.trace("processing " + getChildCount()
+                            + " children: starting at " + first
+                            + ", ending at " + last);
+        }
+
+        for (int rowIndex = first; last == -1 || rowIndex < last; rowIndex++)
+        {
+
+            setRowIndex(rowIndex);
+
+            if (!isRowAvailable())
+            {
+                if (log.isTraceEnabled())
+                {
+                    log.trace("scrolled past the last row, aborting");
+                }
+                break;
+            }
+
+            for (Iterator it = getChildren().iterator(); it.hasNext();)
+            {
+                UIComponent child = (UIComponent) it.next();
+                if (child.isRendered())
+                    process(context, child, processAction);
+            }
+        }
+    }
+
+    /**
+     * Copy and pasted from UIData in order to maintain binary compatibility.
+     */
+
+    private void process(FacesContext context, UIComponent component,
+            int processAction)
+    {
+        switch (processAction)
+        {
+        case PROCESS_DECODES:
+            component.processDecodes(context);
+            break;
+        case PROCESS_VALIDATORS:
+            component.processValidators(context);
+            break;
+        case PROCESS_UPDATES:
+            component.processUpdates(context);
+            break;
+        }
+    }
+    
+    public String getClientId(FacesContext context)
+    {
+        String clientId = HtmlComponentUtils.getClientId(
+                this,getRenderer(context),context);
+
+        if(clientId==null)
+        {
+            return super.getClientId(context);
+        }
+        else
+        {
+            int rowIndex = getRowIndex();
+            if (rowIndex == -1)
+            {
+                return clientId;
+            }
+            else
+            {
+                return clientId + "_" + rowIndex;
+            }
+        }
+    }
+    
+    public abstract String getRowCountVar();
+    
+    public abstract String getRowIndexVar();
+
+    public void setRowIndex(int rowIndex)
+    {
+        super.setRowIndex(rowIndex);
+        String rowIndexVar = getRowIndexVar();
+        String rowCountVar = getRowCountVar();
+        if (rowIndexVar != null || rowCountVar != null)
+        {
+            Map requestMap = FacesContext.getCurrentInstance().getExternalContext().getRequestMap();
+            if (rowIndex >= 0)
+            {
+                //regular row index, update request scope variables
+                if (rowIndexVar != null)
+                {
+                    requestMap.put(getRowIndexVar(), new Integer(rowIndex));
+                }
+                if (rowCountVar != null)
+                {
+                    requestMap.put(getRowCountVar(), new Integer(getRowCount()));
+                }
+            }
+            else
+            {
+                //rowIndex == -1 means end of loop --> remove request scope variables
+                if (rowIndexVar != null)
+                {
+                    requestMap.remove(getRowIndexVar());
+                }
+                if (rowCountVar != null)
+                {
+                    requestMap.remove(getRowCountVar());
+                }
+            }
+        }
+    }
+
+}

Propchange: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/datalist/AbstractHtmlDataList.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/datalist/AbstractHtmlDataList.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/datascroller/AbstractHtmlDataScroller.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/datascroller/AbstractHtmlDataScroller.java?rev=618842&view=auto
==============================================================================
--- myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/datascroller/AbstractHtmlDataScroller.java (added)
+++ myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/datascroller/AbstractHtmlDataScroller.java Tue Feb  5 16:45:49 2008
@@ -0,0 +1,537 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.myfaces.custom.datascroller;
+
+import javax.faces.FacesException;
+import javax.faces.component.ActionSource;
+import javax.faces.component.StateHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIData;
+import javax.faces.context.FacesContext;
+import javax.faces.el.EvaluationException;
+import javax.faces.el.MethodBinding;
+import javax.faces.el.ValueBinding;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.ActionEvent;
+import javax.faces.event.ActionListener;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.PhaseId;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.component.html.ext.HtmlPanelGroup;
+
+/**
+ * A component which works together with a UIData component to allow a
+ * user to view a large list of data one "page" at a time, and navigate
+ * between pages.
+ *  
+ * @author Thomas Spiegl (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+abstract class AbstractHtmlDataScroller extends HtmlPanelGroup implements ActionSource, StateHolder
+{
+    private static final Log log = LogFactory.getLog(HtmlDataScroller.class);
+
+    private static final String FIRST_FACET_NAME = "first";
+    private static final String LAST_FACET_NAME = "last";
+    private static final String NEXT_FACET_NAME = "next";
+    private static final String PREVIOUS_FACET_NAME = "previous";
+    private static final String FAST_FORWARD_FACET_NAME = "fastforward";
+    private static final String FAST_REWIND_FACET_NAME = "fastrewind";
+
+    private static final String TABLE_LAYOUT = "table";
+    private static final String LIST_LAYOUT = "list";
+    private static final String SINGLE_LIST_LAYOUT = "singleList";
+    private static final String SINGLE_TABLE_LAYOUT = "singleTable";
+
+    public static final String FACET_FIRST = "first".intern();
+    public static final String FACET_PREVIOUS = "previous".intern();
+    public static final String FACET_NEXT = "next".intern();
+    public static final String FACET_LAST = "last".intern();
+    public static final String FACET_FAST_FORWARD = "fastf".intern();
+    public static final String FACET_FAST_REWIND = "fastr".intern();
+
+    // just for caching the associated uidata
+    private transient UIData _UIData;
+
+    private transient Boolean _listLayout;
+
+    private transient Boolean _singleElementLayout;
+
+    public boolean isListLayout()
+    {
+        if(_listLayout == null)
+        {
+            String layout=getLayout();
+            if(layout == null || layout.equals(TABLE_LAYOUT) || layout.equals(SINGLE_TABLE_LAYOUT))
+                _listLayout = Boolean.FALSE;
+            else if(layout.equals(LIST_LAYOUT) || layout.equals(SINGLE_LIST_LAYOUT))
+            {
+                _listLayout = Boolean.TRUE;
+            }
+            else
+            {
+                log.error("Invalid layout-parameter : "+layout +" provided. Defaulting to table-layout.");
+                _listLayout = Boolean.FALSE;
+            }
+        }
+
+        return _listLayout.booleanValue();
+    }
+
+    public boolean isSingleElementLayout()
+    {
+        if(_singleElementLayout == null)
+        {
+            String layout=getLayout();
+            if(layout == null || layout.equals(SINGLE_LIST_LAYOUT) || layout.equals(SINGLE_TABLE_LAYOUT))
+                _singleElementLayout = Boolean.TRUE;
+            else
+                _singleElementLayout = Boolean.FALSE;
+        }
+
+        return _singleElementLayout.booleanValue();
+    }
+
+    /**
+     * Catch any attempts to queue events for this component, and ensure
+     * the event's phase is set appropriately. Events are expected to be
+     * queued by this component's renderer.
+     * <p>
+     * When this component is marked "immediate", any ActionEvent will
+     * be marked to fire in the "apply request values" phase. When this
+     * component is not immediate the event will fire during the
+     * "invoke application" phase instead.
+     */
+    public void queueEvent(FacesEvent event)
+    {
+        if (event != null && event instanceof ActionEvent)
+        {
+            if (isImmediate())
+            {
+                event.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
+            }
+            else
+            {
+                event.setPhaseId(PhaseId.INVOKE_APPLICATION);
+            }
+        }
+        super.queueEvent(event);
+    }
+    
+    public abstract int getFastStep();    
+
+    /**
+     * Invoke any action listeners attached to this class.
+     * <p>
+     * After listener invocation, the associated UIData's properties get
+     * updated:
+     * <ul>
+     * <li>if the user selected an absolute page# then setFirst is called with
+     * uiData.getRows() * pageNumber.
+     * <li>if the user selected the "first page" option then setFirst(0) is called.
+     * <li>if the user selected the "previous page" option then setFirst is decremented
+     * by uiData.getRows().
+     * <li>if the user selected the "fast rewind" option then setFirst is decremented
+     * by uiData.getRows() * fastStep.
+     * <li>next, fast-forward and last options have the obvious effect.
+     * </ul>
+     */
+    public void broadcast(FacesEvent event) throws AbortProcessingException
+    {
+        super.broadcast(event);
+
+        if (event instanceof ScrollerActionEvent)
+        {
+            ScrollerActionEvent scrollerEvent = (ScrollerActionEvent) event;
+
+            broadcastToActionListener(scrollerEvent);
+            
+            // huh? getUIData never returns null.
+            UIData uiData = getUIData();
+            if (uiData == null)
+            {
+                return;
+            }
+
+            int pageindex = scrollerEvent.getPageIndex();
+            if (pageindex == -1)
+            {
+                String facet = scrollerEvent.getScrollerfacet();
+                if (FACET_FIRST.equals(facet))
+                {
+                    setFirst(uiData, 0);
+                }
+                else if (FACET_PREVIOUS.equals(facet))
+                {
+                    int previous = uiData.getFirst() - uiData.getRows();
+                    if (previous >= 0)
+                        setFirst(uiData, previous);
+                }
+                else if (FACET_NEXT.equals(facet))
+                {
+                    int next = uiData.getFirst() + uiData.getRows();
+                    if (next < uiData.getRowCount())
+                        setFirst(uiData, next);
+                }
+                else if (FACET_FAST_FORWARD.equals(facet))
+                {
+                    int fastStep = getFastStep();
+                    if (fastStep <= 0)
+                        fastStep = 1;
+                    int next = uiData.getFirst() + uiData.getRows() * fastStep;
+                    int rowcount = uiData.getRowCount();
+                    if (next >= rowcount)
+                        next = (rowcount - 1) - ((rowcount - 1) % uiData.getRows());
+                    setFirst(uiData, next);
+                }
+                else if (FACET_FAST_REWIND.equals(facet))
+                {
+                    int fastStep = getFastStep();
+                    if (fastStep <= 0)
+                        fastStep = 1;
+                    int previous = uiData.getFirst() - uiData.getRows() * fastStep;
+                    if (previous < 0)
+                        previous = 0;
+                    setFirst(uiData, previous);
+                }
+                else if (FACET_LAST.equals(facet))
+                {
+                    int rowcount = uiData.getRowCount();
+                    int rows = uiData.getRows();
+                    int delta = rowcount % rows;
+                    int first = delta > 0 && delta < rows ? rowcount - delta : rowcount - rows;
+                    if (first >= 0)
+                    {
+                        setFirst(uiData, first);
+                    }
+                    else
+                    {
+                        setFirst(uiData, 0);
+                    }
+                }
+            }
+            else
+            {
+                int pageCount = getPageCount();
+                if (pageindex > pageCount)
+                {
+                    pageindex = pageCount;
+                }
+                if (pageindex <= 0)
+                {
+                    pageindex = 1;
+                }
+                setFirst(uiData, uiData.getRows() * (pageindex - 1));
+            }
+        }
+    }
+
+    protected void setFirst(UIData uiData, int value) {
+        //there might be special cases where the first-property of the data-table
+        //is bound to a backing bean. If this happens, the user probably wants
+        //the data-scroller to update this backing-bean value - if not, you can always
+        //override this method in a subclass.
+        if(uiData.getValueBinding("first")!=null)
+        {
+            ValueBinding vb = uiData.getValueBinding("first");
+            vb.setValue(getFacesContext(),new Integer(value));
+        }
+        else
+        {
+            uiData.setFirst(value);
+        }
+    }
+
+    /**
+     * @param event
+     */
+    protected void broadcastToActionListener(ScrollerActionEvent event)
+    {
+        FacesContext context = getFacesContext();
+
+        MethodBinding actionListenerBinding = getActionListener();
+        if (actionListenerBinding != null)
+        {
+            try
+            {
+                actionListenerBinding.invoke(context, new Object[] {event});
+            }
+            catch (EvaluationException e)
+            {
+                Throwable cause = e.getCause();
+                if (cause != null && cause instanceof AbortProcessingException)
+                {
+                    throw (AbortProcessingException)cause;
+                }
+                throw e;
+            }
+        }
+        
+        ActionListener defaultActionListener
+                = context.getApplication().getActionListener();
+        if (defaultActionListener != null)
+        {
+            defaultActionListener.processAction((ActionEvent)event);
+        }
+    }
+
+    /**
+     * @return int
+     */
+    public UIData getUIData()
+    {
+        if (_UIData == null)
+        {
+            _UIData = findUIData();
+        }
+        return _UIData;
+    }
+
+    /**
+     * @return the page index of the uidata
+     */
+    public int getPageIndex()
+    {
+        UIData uiData = getUIData();
+        int rows = uiData.getRows();
+        if (0 == rows)
+        {
+            throw new FacesException("You need to set a value to the 'rows' attribute of component '" + uiData.getClientId(getFacesContext()) + "'" );
+        }
+
+        int pageIndex;
+        if (rows > 0)
+        {
+            pageIndex = uiData.getFirst() / rows + 1;
+        }
+        else
+        {
+            log.warn("DataTable " + uiData.getClientId(FacesContext.getCurrentInstance())
+                            + " has invalid rows attribute.");
+            pageIndex = 0;
+        }
+        if (uiData.getFirst() % rows > 0)
+        {
+            pageIndex++;
+        }
+        return pageIndex;
+    }
+
+    /**
+     * @return the page count of the uidata
+     */
+    public int getPageCount()
+    {
+        UIData uiData = getUIData();
+        int rows = uiData.getRows();
+        int pageCount;
+        if (rows > 0)
+        {
+            pageCount = rows <= 0 ? 1 : uiData.getRowCount() / rows;
+            if (uiData.getRowCount() % rows > 0)
+            {
+                pageCount++;
+            }
+        }
+        else
+        {
+            rows = 1;
+            pageCount = 1;
+        }
+        return pageCount;
+    }
+
+    /**
+     * @return int
+     */
+    public int getRowCount()
+    {
+        return getUIData().getRowCount();
+    }
+
+    /**
+     * @return int
+     */
+    public int getRows()
+    {
+        return getUIData().getRows();
+    }
+
+    /**
+     * @return int
+     */
+    public int getFirstRow()
+    {
+        return getUIData().getFirst();
+    }
+
+    public abstract String getFor();
+    
+    /**
+     * Find the UIData component associated with this scroller.
+     * <p>
+     * If the "for" attribute is not null then that value is used to find the
+     * specified component by id. Both "relative" and "absolute" ids are allowed;
+     * see method UIComponent.findComponent for details.
+     * <p>
+     * If the "for" attribute is not defined, then this component is expected to
+     * be a child of a UIData component.
+     * 
+     * @throws IllegalArgumentException if an associated UIData component
+     * cannot be found.
+     */
+    protected UIData findUIData()
+    {
+        String forStr = getFor();
+        UIComponent forComp;
+        if (forStr == null)
+        {
+            // DataScroller may be a child of uiData
+            forComp = getParent();
+        }
+        else
+        {
+            forComp = findComponent(forStr);
+        }
+        if (forComp == null)
+        {
+            throw new IllegalArgumentException(
+                    "could not find UIData referenced by attribute dataScroller@for = '"
+                    + forStr + "'");
+        }
+        else if (!(forComp instanceof UIData))
+        {
+            throw new IllegalArgumentException(
+                "uiComponent referenced by attribute dataScroller@for = '"
+                + forStr + "' must be of type " + UIData.class.getName()
+                + ", not type " + forComp.getClass().getName());
+        }
+        return (UIData) forComp;
+    }
+
+    public void setFirst(UIComponent first)
+    {
+        getFacets().put(FIRST_FACET_NAME, first);
+    }
+
+    public UIComponent getFirst()
+    {
+        return (UIComponent) getFacets().get(FIRST_FACET_NAME);
+    }
+
+    public void setLast(UIComponent last)
+    {
+        getFacets().put(LAST_FACET_NAME, last);
+    }
+
+    public UIComponent getLast()
+    {
+        return (UIComponent) getFacets().get(LAST_FACET_NAME);
+    }
+
+    public void setNext(UIComponent next)
+    {
+        getFacets().put(NEXT_FACET_NAME, next);
+    }
+
+    public UIComponent getNext()
+    {
+        return (UIComponent) getFacets().get(NEXT_FACET_NAME);
+    }
+
+    public void setFastForward(UIComponent previous)
+    {
+        getFacets().put(FAST_FORWARD_FACET_NAME, previous);
+    }
+
+    public UIComponent getFastForward()
+    {
+        return (UIComponent) getFacets().get(FAST_FORWARD_FACET_NAME);
+    }
+
+    public void setFastRewind(UIComponent previous)
+    {
+        getFacets().put(FAST_REWIND_FACET_NAME, previous);
+    }
+
+    public UIComponent getFastRewind()
+    {
+        return (UIComponent) getFacets().get(FAST_REWIND_FACET_NAME);
+    }
+
+    public void setPrevious(UIComponent previous)
+    {
+        getFacets().put(PREVIOUS_FACET_NAME, previous);
+    }
+
+    public UIComponent getPrevious()
+    {
+        return (UIComponent) getFacets().get(PREVIOUS_FACET_NAME);
+    }
+
+    public boolean getRendersChildren()
+    {
+        return true;
+    }
+
+    /**
+     * @see javax.faces.component.ActionSource#getAction()
+     */
+    public MethodBinding getAction()
+    {
+        // not used
+        return null;
+    }
+
+    /**
+     * @see javax.faces.component.ActionSource#setAction(javax.faces.el.MethodBinding)
+     */
+    public void setAction(MethodBinding action)
+    {
+        throw new UnsupportedOperationException(
+                        "defining an action is not supported. use an actionlistener");
+    }
+
+    /**
+     * @see javax.faces.component.ActionSource#addActionListener(javax.faces.event.ActionListener)
+     */
+    public void addActionListener(ActionListener listener)
+    {
+        addFacesListener(listener);
+    }
+
+    /**
+     * @see javax.faces.component.ActionSource#getActionListeners()
+     */
+    public ActionListener[] getActionListeners()
+    {
+        return (ActionListener[]) getFacesListeners(ActionListener.class);
+    }
+
+    /**
+     * @see javax.faces.component.ActionSource#removeActionListener(javax.faces.event.ActionListener)
+     */
+    public void removeActionListener(ActionListener listener)
+    {
+        removeFacesListener(listener);
+    }
+    
+}

Propchange: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/datascroller/AbstractHtmlDataScroller.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/datascroller/AbstractHtmlDataScroller.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/date/AbstractHtmlInputDate.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/date/AbstractHtmlInputDate.java?rev=618842&view=auto
==============================================================================
--- myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/date/AbstractHtmlInputDate.java (added)
+++ myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/date/AbstractHtmlInputDate.java Tue Feb  5 16:45:49 2008
@@ -0,0 +1,267 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.myfaces.custom.date;
+
+import java.io.Serializable;
+import java.text.ParseException;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.myfaces.component.UserRoleAware;
+import org.apache.myfaces.component.UserRoleUtils;
+import org.apache.myfaces.component.html.util.HtmlComponentUtils;
+import org.apache.myfaces.component.html.ext.HtmlInputText;
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Sylvain Vieujot (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+abstract class AbstractHtmlInputDate
+        extends HtmlInputText implements UserRoleAware
+{
+
+    /**
+     * Overriden to support the force id, since the parent is not an extended component 
+     */
+    public String getClientId(FacesContext context)
+    {
+        String clientId = HtmlComponentUtils.getClientId(this, getRenderer(context), context);
+        if (clientId == null)
+        {
+            clientId = super.getClientId(context);
+        }
+
+        return clientId;
+    }
+        
+    public boolean isRendered(){
+        if (!UserRoleUtils.isVisibleOnUserRole(this)) return false;
+        return super.isRendered();
+    }
+    
+    public abstract String getTimeZone();
+    
+    public abstract String getType();
+    
+    public abstract boolean isAmpm();
+    
+    public UserData getUserData(Locale currentLocale){
+        return new UserData((Date) getValue(), currentLocale, getTimeZone(), isAmpm(), getType());
+    }    
+
+    public static class UserData implements Serializable {
+        private static final long serialVersionUID = -6507279524833267707L;
+        private String day;
+        private String month;
+        private String year;
+        private String hours;
+        private String minutes;
+        private String seconds;
+        private TimeZone timeZone = null;
+        private String ampm;
+        private boolean uses_ampm;
+        private String type;
+
+        public UserData(Date date, Locale currentLocale, String _timeZone, boolean uses_ampm, String type){
+            this.uses_ampm = uses_ampm;
+            this.type = type;
+
+            Calendar calendar = Calendar.getInstance(currentLocale);
+            if (_timeZone != null) {
+                timeZone = TimeZone.getTimeZone(_timeZone);
+                calendar.setTimeZone(timeZone);
+            }
+            
+            if(date == null)
+                return;
+          
+            calendar.setTime( date );
+            day = Integer.toString(calendar.get(Calendar.DAY_OF_MONTH));
+            month = Integer.toString(calendar.get(Calendar.MONTH)+1);
+            year = Integer.toString(calendar.get(Calendar.YEAR));
+            if (uses_ampm) {
+                int int_hours = calendar.get(Calendar.HOUR);
+                // ampm hours must be in range 0-11 to be handled right; we have to handle "12" specially
+                if (int_hours == 0) {
+                    int_hours = 12;
+                }
+                hours = Integer.toString(int_hours);
+                ampm = Integer.toString(calendar.get(Calendar.AM_PM));
+            } else {
+                hours = Integer.toString(calendar.get(Calendar.HOUR_OF_DAY));
+            }
+            minutes = Integer.toString(calendar.get(Calendar.MINUTE));
+            seconds = Integer.toString(calendar.get(Calendar.SECOND));
+        }
+
+        public Date parse() throws ParseException{
+            Date retDate = null;
+            Calendar tempCalendar=Calendar.getInstance();
+            tempCalendar.setLenient(Boolean.FALSE.booleanValue());
+            if (timeZone != null)
+                   tempCalendar.setTimeZone(timeZone);
+            try{
+                if(!isSubmitValid(uses_ampm, type)) {
+                    return null;
+                }
+                
+                if(! (type.equals( "time" ) || type.equals( "short_time" )) ) {
+                    tempCalendar.set(Calendar.DAY_OF_MONTH,Integer.parseInt(day));
+                    tempCalendar.set(Calendar.MONTH,Integer.parseInt(month)-1);
+                    tempCalendar.set(Calendar.YEAR,Integer.parseInt(year));
+                }
+
+                if(! type.equals( "date" )) {
+                    
+                    if (uses_ampm) {
+                        int int_hours = Integer.parseInt(hours);
+                        // ampm hours must be in range 0-11 to be handled right; we have to handle "12" specially
+                        if (int_hours == 12) {
+                            int_hours = 0;
+                        }
+                        tempCalendar.set(Calendar.HOUR,int_hours);
+                        tempCalendar.set(Calendar.AM_PM,Integer.parseInt(ampm));
+                    } else {
+                        tempCalendar.set(Calendar.HOUR_OF_DAY,Integer.parseInt(hours));
+                    }
+                    tempCalendar.set(Calendar.MINUTE,Integer.parseInt(minutes));
+                    
+                    if (seconds != null & (type.equals("full") || type.equals("time") || type.equals("short_time"))) {
+                        tempCalendar.set(Calendar.SECOND,Integer.parseInt(seconds));
+                    }
+                }
+                tempCalendar.set(Calendar.MILLISECOND, 0);
+                retDate = tempCalendar.getTime();
+            } catch (NumberFormatException e) {
+                throw new ParseException(e.getMessage(),0);
+            } catch (IllegalArgumentException e) {
+                throw new ParseException(e.getMessage(),0);
+            } 
+            return retDate;
+        }
+
+        private String formatedInt(String toFormat){
+            if( toFormat == null )
+                return null;
+
+            int i = -1;
+            try{
+                i = Integer.parseInt( toFormat );
+            }catch(NumberFormatException nfe){
+                return toFormat;
+            }
+            if( i >= 0 && i < 10 )
+                return "0"+i;
+            return Integer.toString(i);
+        }
+        
+        private boolean isDateSubmitted(boolean usesAmpm, String type) {
+            boolean isDateSubmitted = ! (StringUtils.isEmpty(getDay()) && ((getMonth() == null) || getMonth().equals("-1")) && StringUtils.isEmpty(getYear()));
+            if(usesAmpm)
+                isDateSubmitted = isDateSubmitted || isAmpmSubmitted();
+            return isDateSubmitted;
+        }
+        
+        private boolean isTimeSubmitted(boolean usesAmpm, String type) {
+            boolean isTimeSubmitted = ! (StringUtils.isEmpty(getHours()) && StringUtils.isEmpty(getMinutes()));
+            if(type.equals("time") || type.equals("full"))
+                isTimeSubmitted = isTimeSubmitted || ! StringUtils.isEmpty(getSeconds());
+            if(usesAmpm)
+                isTimeSubmitted = isTimeSubmitted || isAmpmSubmitted();
+            return isTimeSubmitted;
+        }
+        
+        private boolean isSubmitValid(boolean usesAmpm, String type) {
+            if(type.equals("date"))
+                return isDateSubmitted(usesAmpm, type);
+            else if(type.equals("time") || (type.equals("short_time")))
+                return isTimeSubmitted(usesAmpm, type);
+            else if(type.equals("full") || type.equals("both"))
+                return isDateSubmitted(usesAmpm, type) || isTimeSubmitted(usesAmpm, type);
+            else
+                return false;
+        }
+        
+        private boolean isAmpmSubmitted() {
+            if(getAmpm() == null)
+                return false;
+            else
+                return ! getAmpm().equals("-1");
+        }
+
+        public String getDay() {
+            return formatedInt( day );
+        }
+        public void setDay(String day) {
+            this.day = day;
+        }
+
+        public String getMonth() {
+            return month;
+        }
+        public void setMonth(String month) {
+            this.month = month;
+        }
+
+        public String getYear() {
+            return year;
+        }
+        public void setYear(String year) {
+            this.year = year;
+        }
+
+        public String getHours() {
+            return formatedInt( hours );
+        }
+        public void setHours(String hours) {
+            this.hours = hours;
+        }
+        public String getMinutes() {
+            return formatedInt( minutes );
+        }
+        public void setMinutes(String minutes) {
+            this.minutes = minutes;
+        }
+
+        public String getSeconds() {
+            return formatedInt( seconds );
+        }
+        public void setSeconds(String seconds) {
+            this.seconds = seconds;
+        }
+        
+        public String getAmpm() {
+            return ampm;
+        }
+        public void setAmpm(String ampm) {
+            this.ampm = ampm;
+        }
+        
+        public String getType() {
+            return type;
+        }
+        public void setType(String type) {
+            this.type = type;
+        }
+    }
+}

Propchange: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/date/AbstractHtmlInputDate.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/date/AbstractHtmlInputDate.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/date/HtmlDateRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/date/HtmlDateRenderer.java?rev=618842&r1=618841&r2=618842&view=diff
==============================================================================
--- myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/date/HtmlDateRenderer.java (original)
+++ myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/date/HtmlDateRenderer.java Tue Feb  5 16:45:49 2008
@@ -35,7 +35,7 @@
 import org.apache.myfaces.custom.calendar.HtmlCalendarRenderer;
 import org.apache.myfaces.custom.calendar.FunctionCallProvider;
 import org.apache.myfaces.custom.calendar.HtmlCalendarRenderer.CalendarDateTimeConverter;
-import org.apache.myfaces.custom.date.HtmlInputDate.UserData;
+import org.apache.myfaces.custom.date.AbstractHtmlInputDate.UserData;
 import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
 import org.apache.myfaces.shared_tomahawk.renderkit.JSFAttr;
 import org.apache.myfaces.shared_tomahawk.renderkit.html.util.JavascriptUtils;

Added: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/div/AbstractDiv.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/div/AbstractDiv.java?rev=618842&view=auto
==============================================================================
--- myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/div/AbstractDiv.java (added)
+++ myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/div/AbstractDiv.java Tue Feb  5 16:45:49 2008
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.myfaces.custom.div;
+
+import org.apache.myfaces.custom.htmlTag.HtmlTag;
+
+/**
+ * @author Leonardo Uribe (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+abstract class AbstractDiv
+        extends HtmlTag
+{
+
+    /**///getValue
+    public Object getValue() {
+        return "div";
+      }
+        
+}

Propchange: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/div/AbstractDiv.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/div/AbstractDiv.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/fileupload/AbstractHtmlInputFileUpload.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/fileupload/AbstractHtmlInputFileUpload.java?rev=618842&view=auto
==============================================================================
--- myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/fileupload/AbstractHtmlInputFileUpload.java (added)
+++ myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/fileupload/AbstractHtmlInputFileUpload.java Tue Feb  5 16:45:49 2008
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.myfaces.custom.fileupload;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.html.HtmlInputText;
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.component.UserRoleAware;
+import org.apache.myfaces.component.UserRoleUtils;
+import org.apache.myfaces.shared_tomahawk.util.MessageUtils;
+
+/**
+ * @author Manfred Geiler (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+abstract class AbstractHtmlInputFileUpload
+        extends HtmlInputText
+        implements UserRoleAware
+{
+    private static final String SIZE_LIMIT_EXCEEDED = "sizeLimitExceeded";
+    private static final String FILEUPLOAD_MAX_SIZE = "org.apache.myfaces.custom.fileupload.maxSize";
+    private static final String FILEUPLOAD_EXCEPTION = "org.apache.myfaces.custom.fileupload.exception";
+    public static final String SIZE_LIMIT_MESSAGE_ID = "org.apache.myfaces.FileUpload.SIZE_LIMIT";
+    
+    public void setUploadedFile(UploadedFile upFile)
+    {
+        setValue(upFile);
+    }
+
+    public UploadedFile getUploadedFile()
+    {
+        return (UploadedFile)getValue();
+    }
+
+    public boolean isRendered()
+    {
+        if (!UserRoleUtils.isVisibleOnUserRole(this)) return false;
+        return super.isRendered();
+    }
+    
+    protected void validateValue(FacesContext context, Object convertedValue)
+    {
+        super.validateValue(context, convertedValue);
+        
+        if (isValid())
+        {
+              String exception =
+                (String) context.getExternalContext().getRequestMap().get(FILEUPLOAD_EXCEPTION);
+              
+              if(exception != null ) {
+                if(exception.equals(SIZE_LIMIT_EXCEEDED)) {
+                  Integer maxSize =
+                    (Integer) context.getExternalContext().getRequestMap().get(FILEUPLOAD_MAX_SIZE);
+                  MessageUtils.addMessage(FacesMessage.SEVERITY_ERROR,
+                              SIZE_LIMIT_MESSAGE_ID, new Object[] { getId(),
+                                      maxSize},
+                              getClientId(context), context);
+                  setValid(false);
+                }else {
+                  throw new IllegalStateException("other exceptions not handled yet, exception : "+exception);
+                }
+             }
+         }
+     }
+
+    
+}

Propchange: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/fileupload/AbstractHtmlInputFileUpload.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/fileupload/AbstractHtmlInputFileUpload.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/htmlTag/AbstractHtmlTag.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/htmlTag/AbstractHtmlTag.java?rev=618842&view=auto
==============================================================================
--- myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/htmlTag/AbstractHtmlTag.java (added)
+++ myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/htmlTag/AbstractHtmlTag.java Tue Feb  5 16:45:49 2008
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.myfaces.custom.htmlTag;
+
+import org.apache.myfaces.component.UserRoleAware;
+import org.apache.myfaces.component.UserRoleUtils;
+import org.apache.myfaces.component.html.util.HtmlComponentUtils;
+
+import javax.faces.component.UIOutput;
+
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Leonardo Uribe (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+abstract class AbstractHtmlTag
+        extends UIOutput implements UserRoleAware
+{
+
+    public String getClientId(FacesContext context)
+    {
+        String clientId = HtmlComponentUtils.getClientId(this, getRenderer(context), context);
+        if (clientId == null)
+        {
+            clientId = super.getClientId(context);
+        }
+
+        return clientId;
+    }
+
+    public boolean isRendered()
+    {
+        if (!UserRoleUtils.isVisibleOnUserRole(this)) return false;
+        return super.isRendered();
+    }
+        
+}

Propchange: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/htmlTag/AbstractHtmlTag.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/htmlTag/AbstractHtmlTag.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/inputTextHelp/HtmlTextHelpRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/inputTextHelp/HtmlTextHelpRenderer.java?rev=618842&r1=618841&r2=618842&view=diff
==============================================================================
--- myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/inputTextHelp/HtmlTextHelpRenderer.java (original)
+++ myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/inputTextHelp/HtmlTextHelpRenderer.java Tue Feb  5 16:45:49 2008
@@ -42,6 +42,10 @@
 {
     private static final String JAVASCRIPT_ENCODED = "org.apache.myfaces.inputTextHelp.JAVASCRIPT_ENCODED";
 
+    public static final String JS_FUNCTION_SELECT_TEXT = "selectText";
+    public static final String JS_FUNCTION_RESET_HELP = "resetHelpValue";
+
+
     protected void renderNormal(FacesContext facesContext, UIComponent component) throws IOException
     {
         if(component instanceof HtmlInputTextHelp)
@@ -118,10 +122,10 @@
                 HtmlRendererUtils.renderHTMLAttributes(writer, component,
                                                        HTML.INPUT_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED_AND_ONFOCUS_AND_ONCLICK);
                 writer.writeAttribute(HTML.ONFOCUS_ATTR,
-                                      HtmlInputTextHelp.JS_FUNCTION_SELECT_TEXT + "('" +
+                                      JS_FUNCTION_SELECT_TEXT + "('" +
                                       getHelpText(component) + "', '" + id +"')", null);
                 writer.writeAttribute(HTML.ONCLICK_ATTR,
-                                      HtmlInputTextHelp.JS_FUNCTION_SELECT_TEXT + "('" +
+                                      JS_FUNCTION_SELECT_TEXT + "('" +
                                       getHelpText(component) + "', '" + id +"')", null);
 
             }
@@ -132,10 +136,10 @@
                     HtmlRendererUtils.renderHTMLAttributes(writer, component,
                                                            HTML.INPUT_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED_AND_ONFOCUS_AND_ONCLICK);
                     writer.writeAttribute(HTML.ONFOCUS_ATTR,
-                                          HtmlInputTextHelp.JS_FUNCTION_RESET_HELP + "('" +
+                                          JS_FUNCTION_RESET_HELP + "('" +
                                           getHelpText(component) + "', '" + id +"')", null);
                 writer.writeAttribute(HTML.ONCLICK_ATTR,
-                                      HtmlInputTextHelp.JS_FUNCTION_RESET_HELP + "('" +
+                                      JS_FUNCTION_RESET_HELP + "('" +
                                       getHelpText(component) + "', '" + id +"')", null);
                 }
                 else

Added: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/layout/AbstractHtmlPanelLayout.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/layout/AbstractHtmlPanelLayout.java?rev=618842&view=auto
==============================================================================
--- myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/layout/AbstractHtmlPanelLayout.java (added)
+++ myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/layout/AbstractHtmlPanelLayout.java Tue Feb  5 16:45:49 2008
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.myfaces.custom.layout;
+
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.html.HtmlPanelGroup;
+
+/**
+ * @author Manfred Geiler (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+abstract class AbstractHtmlPanelLayout extends HtmlPanelGroup
+{
+    
+    private static final int DEFAULT_BORDER = Integer.MIN_VALUE;
+    private static final String DEFAULT_LAYOUT = "classic";
+
+    public String getLayout(){
+        String layout = super.getLayout();        
+        return layout == null ? DEFAULT_LAYOUT : layout;
+    }
+    
+    // typesafe facet getters
+
+    public UIComponent getHeader()
+    {
+        return (UIComponent)getFacet("header");
+    }
+
+    public UIComponent getNavigation()
+    {
+        return (UIComponent)getFacet("navigation");
+    }
+
+    public UIComponent getBody()
+    {
+        return (UIComponent)getFacet("body");
+    }
+
+    public UIComponent getFooter()
+    {
+        return (UIComponent)getFacet("footer");
+    }
+
+}

Propchange: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/layout/AbstractHtmlPanelLayout.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/layout/AbstractHtmlPanelLayout.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/navigation/AbstractHtmlCommandNavigation.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/navigation/AbstractHtmlCommandNavigation.java?rev=618842&view=auto
==============================================================================
--- myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/navigation/AbstractHtmlCommandNavigation.java (added)
+++ myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/navigation/AbstractHtmlCommandNavigation.java Tue Feb  5 16:45:49 2008
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.myfaces.custom.navigation;
+
+import java.util.Iterator;
+import java.util.List;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.ActionEvent;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.PhaseId;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.component.html.ext.HtmlCommandLink;
+import org.apache.myfaces.custom.navigation.HtmlCommandNavigation;
+import org.apache.myfaces.custom.navigation.HtmlPanelNavigation;
+
+/**
+ * Command, that represents a navigation item.
+ *
+ * @author Manfred Geiler (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+abstract class AbstractHtmlCommandNavigation extends HtmlCommandLink
+{
+    private static final Log log = LogFactory.getLog(HtmlCommandNavigation.class);
+    
+    public boolean isImmediate()
+    {
+        //always immediate
+        return true;
+    }
+
+    public void setImmediate(boolean immediate)
+    {
+        if (log.isWarnEnabled()) log.warn("Immediate property of HtmlCommandNavigation cannot be set --> ignored.");
+    }
+
+    public Boolean getOpenDirectly()
+    {
+        return isOpen();            
+    }
+    
+    public Boolean getActiveDirectly()
+    {
+        return isActive();            
+    }
+    
+    /**
+     * @return false, if this item is child of another HtmlCommandNavigation, which is closed
+     */
+    public boolean isRendered()
+    {
+        if (! super.isRendered()) {
+            return false;
+        }
+        UIComponent parent = getParent();
+        while (parent != null)
+        {
+            if (parent instanceof HtmlCommandNavigation)
+            {
+                if (!((HtmlCommandNavigation)parent).isOpen())
+                {
+                    return false;
+                }
+            }
+
+            if (parent instanceof HtmlPanelNavigation)
+            {
+                break;
+            }
+            else
+            {
+                parent = parent.getParent();
+            }
+        }
+
+        return true;
+    }
+
+    public abstract boolean isOpen();
+    
+    public abstract void setOpen(boolean open);
+
+    public abstract boolean isActive();
+    
+    public abstract void setActive(boolean active);
+        
+    public void toggleOpen()
+    {
+        if (isOpen())
+        {
+            if (getChildCount() > 0)
+            {
+                //item is a menu group --> close item
+                setOpen(false);
+            }
+        }
+        else
+        {
+            UIComponent parent = getParent();
+
+            //close all siblings
+            closeAllChildren(parent.getChildren().iterator());
+
+            //open all parents (to be sure) and search HtmlPanelNavigation
+            UIComponent p = parent;
+            while (p != null && !(p instanceof HtmlPanelNavigation))
+            {
+                if (p instanceof HtmlCommandNavigation)
+                {
+                    ((HtmlCommandNavigation)p).setOpen(true);
+                }
+                p = p.getParent();
+            }
+            // p is now the HtmlPanelNavigation
+
+            if (!hasCommandNavigationChildren())
+            {
+                //item is an end node --> deactivate all other nodes, and then...
+                if (!(p instanceof HtmlPanelNavigation))
+                {
+                    log.error("HtmlCommandNavigation without parent HtmlPanelNavigation ?!");
+                }
+                else
+                {
+                    //deactivate all other items
+                    deactivateAllChildren(p.getChildren().iterator());
+                }
+                //...activate this item
+                setActive(true);
+            }
+            else
+            {
+                //open item
+                setOpen(true);
+            }
+        }
+    }
+
+    private boolean hasCommandNavigationChildren()
+    {
+        if (getChildCount() == 0)
+        {
+            return false;
+        }
+        List list = getChildren();
+        for (int i = 0, sizei = list.size(); i < sizei; i++)
+        {
+            if (list.get(i) instanceof HtmlCommandNavigation)
+            {
+                return true;
+            }
+        }
+        return false;
+    }
+
+
+    private static void deactivateAllChildren(Iterator children)
+    {
+        while (children.hasNext())
+        {
+            UIComponent ni = (UIComponent)children.next();
+            if (ni instanceof HtmlCommandNavigation)
+            {
+                ((HtmlCommandNavigation)ni).setActive(false);
+                if (ni.getChildCount() > 0)
+                {
+                    deactivateAllChildren(ni.getChildren().iterator());
+                }
+            }
+        }
+    }
+
+    private static void closeAllChildren(Iterator children)
+    {
+        while (children.hasNext())
+        {
+            UIComponent ni = (UIComponent)children.next();
+            if (ni instanceof HtmlCommandNavigation)
+            {
+                ((HtmlCommandNavigation)ni).setOpen(false);
+                if (ni.getChildCount() > 0)
+                {
+                    closeAllChildren(ni.getChildren().iterator());
+                }
+            }
+        }
+    }
+
+
+    public void broadcast(FacesEvent event) throws AbortProcessingException
+    {
+        if (event instanceof ActionEvent)
+        {
+            ActionEvent actionEvent = (ActionEvent)event;
+            if (actionEvent.getPhaseId() == PhaseId.APPLY_REQUEST_VALUES)
+            {
+                HtmlCommandNavigation navItem = (HtmlCommandNavigation)actionEvent.getComponent();
+                navItem.toggleOpen();
+                FacesContext.getCurrentInstance().renderResponse();
+            }
+        }
+        super.broadcast(event);
+    }
+
+
+}

Propchange: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/navigation/AbstractHtmlCommandNavigation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tomahawk/branches/1_2_0/core/src/main/java/org/apache/myfaces/custom/navigation/AbstractHtmlCommandNavigation.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL