myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r1130178 - in /myfaces/tomahawk/trunk/sandbox/core20/src/main: conf/META-INF/ java/org/apache/myfaces/custom/roundedPanel/
Date Wed, 01 Jun 2011 15:07:23 GMT
Author: lu4242
Date: Wed Jun  1 15:07:23 2011
New Revision: 1130178

URL: http://svn.apache.org/viewvc?rev=1130178&view=rev
Log:
TOMAHAWK-1594 Add s:roundedPanel component

Added:
    myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/
    myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/AbstractHtmlRoundedPanel.java
    myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/HtmlColorUtils.java
    myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/HtmlRoundedPanelRenderer.java
    myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/RoundedPanelProperties.java
    myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/RoundedPanelPropertiesBuilder.java
    myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/RoundedPanelResouceHandlerSupport.java
    myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/RoundedPanelResource.java
    myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/RoundedPanelResourceHandlerWrapper.java
    myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/RoundedPanelResourceLoader.java
Modified:
    myfaces/tomahawk/trunk/sandbox/core20/src/main/conf/META-INF/faces-config-base.xml

Modified: myfaces/tomahawk/trunk/sandbox/core20/src/main/conf/META-INF/faces-config-base.xml
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core20/src/main/conf/META-INF/faces-config-base.xml?rev=1130178&r1=1130177&r2=1130178&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core20/src/main/conf/META-INF/faces-config-base.xml (original)
+++ myfaces/tomahawk/trunk/sandbox/core20/src/main/conf/META-INF/faces-config-base.xml Wed Jun  1 15:07:23 2011
@@ -24,4 +24,8 @@
               xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd" 
               version="2.0">
 
+    <application>
+        <resource-handler>org.apache.myfaces.custom.roundedPanel.RoundedPanelResourceHandlerWrapper</resource-handler>
+    </application>
+
 </faces-config>

Added: myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/AbstractHtmlRoundedPanel.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/AbstractHtmlRoundedPanel.java?rev=1130178&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/AbstractHtmlRoundedPanel.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/AbstractHtmlRoundedPanel.java Wed Jun  1 15:07:23 2011
@@ -0,0 +1,121 @@
+/*
+ * 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.roundedPanel;
+
+import javax.faces.component.UIPanel;
+
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent;
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty;
+
+/**
+ * 
+ * @author Leonardo Uribe (parts taken from sandbox 1.1 s:roundedDiv by Andrew Robinson) 
+ *
+ */
+@JSFComponent(name="s:roundedPanel",
+    clazz = "org.apache.myfaces.custom.roundedPanel.HtmlRoundedPanel")
+public abstract class AbstractHtmlRoundedPanel extends UIPanel
+{
+    public static final String COMPONENT_FAMILY = "org.apache.myfaces.custom.roundedPanel.HtmlRoundedPanel";
+    public static final String COMPONENT_TYPE = "org.apache.myfaces.custom.roundedPanel.HtmlRoundedPanel";
+    public static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.custom.roundedPanel.HtmlRoundedPanel";
+    
+    @Override
+    public String getFamily()
+    {
+        return COMPONENT_FAMILY;
+    }
+
+    /**
+     * The radius of the corners in pixels. (Default: 8)
+     * 
+     * @JSFProperty
+     *   defaultValue = "Integer.valueOf(8)"
+     * @return the radius
+     */
+    public abstract Integer getRadius();
+    
+    /**
+     * Background color to give the corners. Leave blank (null) to have a transparent 
+     * background. If the user is using IE6, this has to be set, or the corners 
+     * will not look good due to IE6's lack of PNG support.
+     * 
+     * @JSFProperty
+     * @return the backgroundColor
+     */
+    public abstract String getBackgroundColor(); 
+    
+    /**
+     * The foreground color of the DIV
+     * 
+     * @JSFProperty
+     * @return the color
+     */
+    public abstract String getColor();
+    
+    /**
+     * Either "table" or "div". Specifies how the output should be rendered. 
+     * Size must be null if using "table" (if it is not, a div will be rendered). 
+     * (Default: div)
+     * 
+     * @JSFProperty
+     *   defaultValue = "div"
+     * @return
+     */
+    public abstract String getLayout();
+    
+    /**
+     * HTML: CSS styling instructions.
+     * 
+     */
+    @JSFProperty
+    public abstract String getStyle();
+
+    /**
+     * The CSS class for this element.  Corresponds to the HTML 'class' attribute.
+     * 
+     */
+    @JSFProperty
+    public abstract String getStyleClass();
+    
+    /**
+     * HTML: CSS styling instructions.
+     * 
+     */
+    @JSFProperty
+    public abstract String getContentStyle();
+
+    /**
+     * The CSS class for this element.  Corresponds to the HTML 'class' attribute.
+     * 
+     */
+    @JSFProperty
+    public abstract String getContentStyleClass();
+    
+    /**
+     * Defines an optional library to load already generated images to be used by this component.
+     * The idea is just save the images with the same names on a library folder, so the component
+     * can use it without trigger image generation. 
+     * 
+     * @return
+     */
+    @JSFProperty
+    public abstract String getLibrary();
+
+}

Added: myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/HtmlColorUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/HtmlColorUtils.java?rev=1130178&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/HtmlColorUtils.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/HtmlColorUtils.java Wed Jun  1 15:07:23 2011
@@ -0,0 +1,234 @@
+/*
+ * 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.roundedPanel;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 
+ * @author Leonardo Uribe
+ *
+ */
+public class HtmlColorUtils
+{
+    private static final Map<String, String> COLOR_NAMES_CODE = new HashMap<String, String>();
+    
+    static
+    {
+        COLOR_NAMES_CODE.put("aliceblue","#F0F8FF");
+        COLOR_NAMES_CODE.put("antiquewhite","#FAEBD7");
+        COLOR_NAMES_CODE.put("aqua","#00FFFF");
+        COLOR_NAMES_CODE.put("aquamarine","#7FFFD4");
+        COLOR_NAMES_CODE.put("azure","#F0FFFF");
+        COLOR_NAMES_CODE.put("beige","#F5F5DC");
+        COLOR_NAMES_CODE.put("bisque","#FFE4C4");
+        COLOR_NAMES_CODE.put("black","#000000");
+        COLOR_NAMES_CODE.put("blanchedalmond","#FFEBCD");
+        COLOR_NAMES_CODE.put("blue","#0000FF");
+        COLOR_NAMES_CODE.put("blueviolet","#8A2BE2");
+        COLOR_NAMES_CODE.put("brown","#A52A2A");
+        COLOR_NAMES_CODE.put("burlywood","#DEB887");
+        COLOR_NAMES_CODE.put("cadetblue","#5F9EA0");
+        COLOR_NAMES_CODE.put("chartreuse","#7FFF00");
+        COLOR_NAMES_CODE.put("chocolate","#D2691E");
+        COLOR_NAMES_CODE.put("coral","#FF7F50");
+        COLOR_NAMES_CODE.put("cornflowerblue","#6495ED");
+        COLOR_NAMES_CODE.put("cornsilk","#FFF8DC");
+        COLOR_NAMES_CODE.put("crimson","#DC143C");
+        COLOR_NAMES_CODE.put("cyan","#00FFFF");
+        COLOR_NAMES_CODE.put("darkblue","#00008B");
+        COLOR_NAMES_CODE.put("darkcyan","#008B8B");
+        COLOR_NAMES_CODE.put("darkgoldenrod","#B8860B");
+        COLOR_NAMES_CODE.put("darkgray","#A9A9A9");
+        COLOR_NAMES_CODE.put("darkgrey","#A9A9A9");
+        COLOR_NAMES_CODE.put("darkgreen","#006400");
+        COLOR_NAMES_CODE.put("darkkhaki","#BDB76B");
+        COLOR_NAMES_CODE.put("darkmagenta","#8B008B");
+        COLOR_NAMES_CODE.put("darkolivegreen","#556B2F");
+        COLOR_NAMES_CODE.put("darkorange","#FF8C00");
+        COLOR_NAMES_CODE.put("darkorchid","#9932CC");
+        COLOR_NAMES_CODE.put("darkred","#8B0000");
+        COLOR_NAMES_CODE.put("darksalmon","#E9967A");
+        COLOR_NAMES_CODE.put("darkseagreen","#8FBC8F");
+        COLOR_NAMES_CODE.put("darkslateblue","#483D8B");
+        COLOR_NAMES_CODE.put("darkslategray","#2F4F4F");
+        COLOR_NAMES_CODE.put("darkstategrey","#2F4F4F");
+        COLOR_NAMES_CODE.put("darkturquoise","#00CED1");
+        COLOR_NAMES_CODE.put("darkviolet","#9400D3");
+        COLOR_NAMES_CODE.put("deeppink","#FF1493");
+        COLOR_NAMES_CODE.put("deepskyblue","#00BFFF");
+        COLOR_NAMES_CODE.put("dimgray","#696969");
+        COLOR_NAMES_CODE.put("dimgrey","#696969");
+        COLOR_NAMES_CODE.put("dodgerblue","#1E90FF");
+        COLOR_NAMES_CODE.put("firebrick","#B22222");
+        COLOR_NAMES_CODE.put("floralwhite","#FFFAF0");
+        COLOR_NAMES_CODE.put("forestgreen","#228B22");
+        COLOR_NAMES_CODE.put("fuchsia","#FF00FF");
+        COLOR_NAMES_CODE.put("gainsboro","#DCDCDC");
+        COLOR_NAMES_CODE.put("ghostwhite","#F8F8FF");
+        COLOR_NAMES_CODE.put("gold","#FFD700");
+        COLOR_NAMES_CODE.put("goldenrod","#DAA520");
+        COLOR_NAMES_CODE.put("gray","#808080");
+        COLOR_NAMES_CODE.put("grey","#808080");
+        COLOR_NAMES_CODE.put("green","#008000");
+        COLOR_NAMES_CODE.put("greenyellow","#ADFF2F");
+        COLOR_NAMES_CODE.put("honeydew","#F0FFF0");
+        COLOR_NAMES_CODE.put("hotpink","#FF69B4");
+        COLOR_NAMES_CODE.put("indianred","#CD5C5C");
+        COLOR_NAMES_CODE.put("indigo","#4B0082");
+        COLOR_NAMES_CODE.put("ivory","#FFFFF0");
+        COLOR_NAMES_CODE.put("khaki","#F0E68C");
+        COLOR_NAMES_CODE.put("lavender","#E6E6FA");
+        COLOR_NAMES_CODE.put("lavenderblush","#FFF0F5");
+        COLOR_NAMES_CODE.put("lawngreen","#7CFC00");
+        COLOR_NAMES_CODE.put("lemonchiffon","#FFFACD");
+        COLOR_NAMES_CODE.put("lightblue","#ADD8E6");
+        COLOR_NAMES_CODE.put("lightcoral","#F08080");
+        COLOR_NAMES_CODE.put("lightcyan","#E0FFFF");
+        COLOR_NAMES_CODE.put("lightgoldenrodyellow","#FAFAD2");
+        COLOR_NAMES_CODE.put("lightgreen","#90EE90");
+        COLOR_NAMES_CODE.put("lightgray","#D3D3D3");
+        COLOR_NAMES_CODE.put("lightgrey","#D3D3D3");
+        COLOR_NAMES_CODE.put("lightpink","#FFB6C1");
+        COLOR_NAMES_CODE.put("lightsalmon","#FFA07A");
+        COLOR_NAMES_CODE.put("lightseagreen","#20B2AA");
+        COLOR_NAMES_CODE.put("lightskyblue","#87CEFA");
+        COLOR_NAMES_CODE.put("lightslategray","#778899");
+        COLOR_NAMES_CODE.put("lightslategrey","#778899");
+        COLOR_NAMES_CODE.put("lightsteelblue","#B0C4DE");
+        COLOR_NAMES_CODE.put("lightyellow","#FFFFE0");
+        COLOR_NAMES_CODE.put("lime","#00FF00");
+        COLOR_NAMES_CODE.put("limegreen","#32CD32");
+        COLOR_NAMES_CODE.put("linen","#FAF0E6");
+        COLOR_NAMES_CODE.put("magenta","#FF00FF");
+        COLOR_NAMES_CODE.put("maroon","#800000");
+        COLOR_NAMES_CODE.put("mediumaquamarine","#66CDAA");
+        COLOR_NAMES_CODE.put("mediumblue","#0000CD");
+        COLOR_NAMES_CODE.put("mediumorchid","#BA55D3");
+        COLOR_NAMES_CODE.put("mediumpurple","#9370DB");
+        COLOR_NAMES_CODE.put("mediumseagreen","#3CB371");
+        COLOR_NAMES_CODE.put("mediumslateblue","#7B68EE");
+        COLOR_NAMES_CODE.put("mediumspringgreen","#00FA9A");
+        COLOR_NAMES_CODE.put("mediumturquoise","#48D1CC");
+        COLOR_NAMES_CODE.put("mediumvioletred","#C71585");
+        COLOR_NAMES_CODE.put("midnightblue","#191970");
+        COLOR_NAMES_CODE.put("mintcream","#F5FFFA");
+        COLOR_NAMES_CODE.put("mistyrose","#FFE4E1");
+        COLOR_NAMES_CODE.put("moccasin","#FFE4B5");
+        COLOR_NAMES_CODE.put("navajowhite","#FFDEAD");
+        COLOR_NAMES_CODE.put("navy","#000080");
+        COLOR_NAMES_CODE.put("oldlace","#FDF5E6");
+        COLOR_NAMES_CODE.put("olive","#808000");
+        COLOR_NAMES_CODE.put("olivedrab","#6B8E23");
+        COLOR_NAMES_CODE.put("orange","#FFA500");
+        COLOR_NAMES_CODE.put("orangered","#FF4500");
+        COLOR_NAMES_CODE.put("orchid","#DA70D6");
+        COLOR_NAMES_CODE.put("palegoldenrod","#EEE8AA");
+        COLOR_NAMES_CODE.put("palegreen","#98FB98");
+        COLOR_NAMES_CODE.put("paleturquoise","#AFEEEE");
+        COLOR_NAMES_CODE.put("palevioletred","#DB7093");
+        COLOR_NAMES_CODE.put("papayawhip","#FFEFD5");
+        COLOR_NAMES_CODE.put("peachpuff","#FFDAB9");
+        COLOR_NAMES_CODE.put("peru","#CD853F");
+        COLOR_NAMES_CODE.put("pink","#FFC0CB");
+        COLOR_NAMES_CODE.put("plum","#DDA0DD");
+        COLOR_NAMES_CODE.put("powderblue","#B0E0E6");
+        COLOR_NAMES_CODE.put("purple","#800080");
+        COLOR_NAMES_CODE.put("red","#FF0000");
+        COLOR_NAMES_CODE.put("rosybrown","#BC8F8F");
+        COLOR_NAMES_CODE.put("royalblue","#4169E1");
+        COLOR_NAMES_CODE.put("saddlebrown","#8B4513");
+        COLOR_NAMES_CODE.put("salmon","#FA8072");
+        COLOR_NAMES_CODE.put("sandybrown","#FAA460");
+        COLOR_NAMES_CODE.put("seagreen","#2E8B57");
+        COLOR_NAMES_CODE.put("seashell","#FFF5EE");
+        COLOR_NAMES_CODE.put("sienna","#A0522D");
+        COLOR_NAMES_CODE.put("silver","#C0C0C0");
+        COLOR_NAMES_CODE.put("skyblue","#87CEEB");
+        COLOR_NAMES_CODE.put("slateblue","#6A5ACD");
+        COLOR_NAMES_CODE.put("slategray","#708090");
+        COLOR_NAMES_CODE.put("slategrey","#708090");
+        COLOR_NAMES_CODE.put("snow","#FFFAFA");
+        COLOR_NAMES_CODE.put("springgreen","#00FF7F");
+        COLOR_NAMES_CODE.put("steelblue","#4682B4");
+        COLOR_NAMES_CODE.put("tan","#D2B48C");
+        COLOR_NAMES_CODE.put("teal","#008080");
+        COLOR_NAMES_CODE.put("thistle","#D8BFD8");
+        COLOR_NAMES_CODE.put("tomato","#FF6347");
+        COLOR_NAMES_CODE.put("turquoise","#40E0D0");
+        COLOR_NAMES_CODE.put("violet","#EE82EE");
+        COLOR_NAMES_CODE.put("wheat","#F5DEB3");
+        COLOR_NAMES_CODE.put("white","#FFFFFF");
+        COLOR_NAMES_CODE.put("whitesmoke","#F5F5F5");
+        COLOR_NAMES_CODE.put("yellow","#FFFF00");
+        COLOR_NAMES_CODE.put("yellowgreen","#9ACD32");
+    }
+
+    /**
+     * Takes a color property and return a rgb color using the notation #RRGGBB.
+     * If the entry is invalid o no valid chars are included returns null.
+     * 
+     * @param color
+     * @return
+     */
+    public static String encodeColorProperty(String color)
+    {
+        if (color == null)
+        {
+            return null;
+        }
+        String encodedColor = color.trim();
+        if (encodedColor.length() <= 0)
+        {
+            return null;
+        }
+        if (encodedColor.charAt(0) == '#')
+        {
+            //Check if valid digits are used.
+            if (encodedColor.length() == 7)
+            {
+                for (int i = 1; i < encodedColor.length(); i++)
+                {
+                    char c = encodedColor.charAt(i);
+                    if (( '0' <= c && c <= '9' )||
+                        ( 'a' <= c && c <= 'f' )||
+                        ( 'A' <= c && c <= 'F' ))
+                    {
+                    }
+                    else
+                    {
+                        encodedColor = null;
+                        break;
+                    }
+                }
+            }
+            else
+            {
+                encodedColor = null;
+            }
+        }
+        else
+        {
+            encodedColor = COLOR_NAMES_CODE.get(encodedColor); 
+        }
+        return encodedColor;
+    }
+
+}
\ No newline at end of file

Added: myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/HtmlRoundedPanelRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/HtmlRoundedPanelRenderer.java?rev=1130178&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/HtmlRoundedPanelRenderer.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/HtmlRoundedPanelRenderer.java Wed Jun  1 15:07:23 2011
@@ -0,0 +1,265 @@
+/*
+ * 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.roundedPanel;
+
+import java.io.IOException;
+
+import javax.faces.application.Resource;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.render.Renderer;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFRenderer;
+import org.apache.myfaces.shared_tomahawk.util.WebConfigParamUtils;
+import org.apache.myfaces.shared_tomahawk.renderkit.JSFAttr;
+import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
+
+/**
+ * 
+ * @author Leonardo Uribe
+ *
+ */
+@JSFRenderer(renderKitId="HTML_BASIC", 
+        family="org.apache.myfaces.custom.roundedPanel.HtmlRoundedPanel",
+        type="org.apache.myfaces.custom.roundedPanel.HtmlRoundedPanel")
+public class HtmlRoundedPanelRenderer extends Renderer
+{
+    private static final Log log = LogFactory.getLog(HtmlRoundedPanelRenderer.class);
+    
+    public static final String INIT_PARAM_ROUNDED_PANEL_MAX_RADIUS = "org.apache.myfaces.ROUNDED_PANEL_MAX_RADIUS";
+    public static final int INIT_PARAM_ROUNDED_PANEL_MAX_RADIUS_DEFAULT = 30;
+    
+    public boolean getRendersChildren()
+    {
+        return true;
+    }
+    
+    public void encodeBegin(FacesContext context, UIComponent component)
+    throws IOException
+    {
+    }
+    
+    public void encodeChildren(FacesContext context, UIComponent component)
+    throws IOException
+    {
+    }
+    
+    @Override
+    public void encodeEnd(FacesContext context, UIComponent component)
+            throws IOException
+    {
+        super.encodeEnd(context, component);
+        
+        AbstractHtmlRoundedPanel roundedPanel = (AbstractHtmlRoundedPanel) component;
+        
+        Integer maxRadius = WebConfigParamUtils.getIntegerInitParameter(context.getExternalContext(), 
+                INIT_PARAM_ROUNDED_PANEL_MAX_RADIUS, INIT_PARAM_ROUNDED_PANEL_MAX_RADIUS_DEFAULT);
+        
+        if (roundedPanel.getRadius().intValue() > maxRadius.intValue())
+        {
+            log.error("Radius used for rounded panel is bigger than max allowed."
+                    +maxRadius.toString()+
+                    " Increase the value of "+INIT_PARAM_ROUNDED_PANEL_MAX_RADIUS+
+                    " web config param or reduce the value in your component");
+            return;
+        }
+        
+        
+        //Create properties from component properties
+        RoundedPanelProperties roundedPanelProperties = new RoundedPanelProperties(roundedPanel.getRadius());
+        
+        roundedPanelProperties.setBackgroundColor(encodeColorProperty(roundedPanel.getBackgroundColor()));
+        roundedPanelProperties.setColor(encodeColorProperty(roundedPanel.getColor()));
+        
+        if ("table".equals(roundedPanel.getLayout()))
+        {
+            encodeTableRoundedPanel(context, roundedPanel, roundedPanelProperties);
+        }
+        else
+        {
+            encodeDivRoundedPanel(context, roundedPanel, roundedPanelProperties);
+        }
+    }
+    
+    public void encodeDivRoundedPanel(FacesContext context, AbstractHtmlRoundedPanel roundedPanel,
+            RoundedPanelProperties roundedPanelProperties) throws IOException
+    {
+        ResponseWriter writer = context.getResponseWriter();
+        
+        writer.startElement(HTML.DIV_ELEM, null);
+        writer.writeAttribute(HTML.STYLE_ATTR, "background:"+roundedPanel.getColor()+";"+roundedPanel.getStyle(), null);
+        HtmlRendererUtils.renderHTMLAttribute(writer, roundedPanel, JSFAttr.STYLE_CLASS_ATTR, HTML.CLASS_ATTR);
+        
+        String cornerHeightCss = "height: "+roundedPanel.getRadius().toString()+"px; font-size: 1px;";
+        
+        writer.startElement(HTML.DIV_ELEM, null);
+        Resource tr = getImageResource(context, roundedPanel, roundedPanelProperties,  
+                        RoundedPanelPropertiesBuilder.ROUNDED_PANEL_PATTERN_BASIC, RoundedPanelPropertiesBuilder.SECTION_TOP_RIGHT);
+        writer.writeAttribute(HTML.STYLE_ATTR, "background: url("+tr.getRequestPath()+") no-repeat top right;"+cornerHeightCss, null);
+        
+        writer.startElement(HTML.DIV_ELEM, null);
+        Resource tl = getImageResource(context, roundedPanel, roundedPanelProperties,  
+                        RoundedPanelPropertiesBuilder.ROUNDED_PANEL_PATTERN_BASIC, RoundedPanelPropertiesBuilder.SECTION_TOP_LEFT);
+        writer.writeAttribute(HTML.STYLE_ATTR, "background: url("+tl.getRequestPath()+") no-repeat top left;"+cornerHeightCss, null);
+        
+        writer.endElement(HTML.DIV_ELEM);
+        writer.endElement(HTML.DIV_ELEM);
+        
+        writer.startElement(HTML.DIV_ELEM, null);
+        HtmlRendererUtils.renderHTMLAttribute(writer, roundedPanel, "contentStyle", HTML.STYLE_ATTR);
+        HtmlRendererUtils.renderHTMLAttribute(writer, roundedPanel, "contentStyleClass", HTML.CLASS_ATTR);
+        RendererUtils.renderChildren(context, roundedPanel);
+        writer.endElement(HTML.DIV_ELEM);
+        
+        writer.startElement(HTML.DIV_ELEM, null);
+        Resource br = getImageResource(context, roundedPanel, roundedPanelProperties,  
+                        RoundedPanelPropertiesBuilder.ROUNDED_PANEL_PATTERN_BASIC, RoundedPanelPropertiesBuilder.SECTION_BOTTOM_RIGHT);
+        writer.writeAttribute(HTML.STYLE_ATTR, "background: url("+br.getRequestPath()+") no-repeat bottom right;"+cornerHeightCss, null);
+        
+        writer.startElement(HTML.DIV_ELEM, null);
+        Resource bl = getImageResource(context, roundedPanel, roundedPanelProperties,  
+                        RoundedPanelPropertiesBuilder.ROUNDED_PANEL_PATTERN_BASIC, RoundedPanelPropertiesBuilder.SECTION_BOTTOM_LEFT);
+        writer.writeAttribute(HTML.STYLE_ATTR, "background: url("+bl.getRequestPath()+") no-repeat bottom left;"+cornerHeightCss, null);
+        
+        writer.endElement(HTML.DIV_ELEM);
+        writer.endElement(HTML.DIV_ELEM);
+        
+        writer.endElement(HTML.DIV_ELEM);
+    }
+
+    public void encodeTableRoundedPanel(FacesContext context, AbstractHtmlRoundedPanel roundedPanel,
+            RoundedPanelProperties roundedPanelProperties) throws IOException
+    {
+        ResponseWriter writer = context.getResponseWriter();
+        
+        writer.startElement(HTML.TABLE_ELEM, null);
+        writer.writeAttribute(HTML.CELLPADDING_ATTR, "0", null);
+        writer.writeAttribute(HTML.CELLSPACING_ATTR, "0", null);
+        writer.writeAttribute(HTML.BORDER_ATTR, "0", null);
+        writer.writeAttribute(HTML.STYLE_ATTR, "background-color: "+roundedPanel.getColor()+";"+roundedPanel.getStyle(), null);
+        HtmlRendererUtils.renderHTMLAttribute(writer, roundedPanel, JSFAttr.STYLE_CLASS_ATTR, HTML.CLASS_ATTR);
+        
+        writer.startElement(HTML.TBODY_ELEM, null);
+        
+        writer.startElement(HTML.TR_ELEM, null);
+        
+        String cornerHeightCss = "height: "+roundedPanel.getRadius().toString()+"px; width:"+roundedPanel.getRadius().toString()+"; font-size: 1px;";
+        writer.startElement(HTML.TD_ELEM, null);
+        Resource tl = getImageResource(context, roundedPanel, roundedPanelProperties,  
+                        RoundedPanelPropertiesBuilder.ROUNDED_PANEL_PATTERN_BASIC, RoundedPanelPropertiesBuilder.SECTION_TOP_LEFT);
+        writer.writeAttribute(HTML.STYLE_ATTR, "background: url("+tl.getRequestPath()+") no-repeat top left;"+cornerHeightCss, null);
+        writer.endElement(HTML.TD_ELEM);
+        writer.startElement(HTML.TD_ELEM, null);
+        writer.endElement(HTML.TD_ELEM);
+        writer.startElement(HTML.TD_ELEM, null);
+        Resource tr = getImageResource(context, roundedPanel, roundedPanelProperties, 
+                        RoundedPanelPropertiesBuilder.ROUNDED_PANEL_PATTERN_BASIC, RoundedPanelPropertiesBuilder.SECTION_TOP_RIGHT);
+        writer.writeAttribute(HTML.STYLE_ATTR, "background: url("+tr.getRequestPath()+") no-repeat top right;"+cornerHeightCss, null);
+        writer.endElement(HTML.TD_ELEM);
+        
+        writer.endElement(HTML.TR_ELEM);
+
+        writer.startElement(HTML.TR_ELEM, null);
+        writer.startElement(HTML.TD_ELEM, null);
+        writer.writeAttribute(HTML.COLSPAN_ATTR, "3", null);
+        HtmlRendererUtils.renderHTMLAttribute(writer, roundedPanel, "contentStyle", HTML.STYLE_ATTR);
+        HtmlRendererUtils.renderHTMLAttribute(writer, roundedPanel, "contentStyleClass", HTML.CLASS_ATTR);
+        RendererUtils.renderChildren(context, roundedPanel);
+        writer.endElement(HTML.TD_ELEM);
+        writer.endElement(HTML.TR_ELEM);
+        
+        writer.startElement(HTML.TR_ELEM, null);
+        
+        writer.startElement(HTML.TD_ELEM, null);
+        Resource bl = getImageResource(context, roundedPanel, roundedPanelProperties, 
+                        RoundedPanelPropertiesBuilder.ROUNDED_PANEL_PATTERN_BASIC, RoundedPanelPropertiesBuilder.SECTION_BOTTOM_LEFT);
+        writer.writeAttribute(HTML.STYLE_ATTR, "background: url("+bl.getRequestPath()+") no-repeat bottom left;"+cornerHeightCss, null);
+        writer.endElement(HTML.TD_ELEM);
+        writer.startElement(HTML.TD_ELEM, null);
+        writer.endElement(HTML.TD_ELEM);
+        writer.startElement(HTML.TD_ELEM, null);
+        Resource br = getImageResource(context, roundedPanel, roundedPanelProperties, 
+                RoundedPanelPropertiesBuilder.ROUNDED_PANEL_PATTERN_BASIC, RoundedPanelPropertiesBuilder.SECTION_BOTTOM_RIGHT);
+        writer.writeAttribute(HTML.STYLE_ATTR, "background: url("+br.getRequestPath()+") no-repeat bottom right;"+cornerHeightCss, null);
+        writer.endElement(HTML.TD_ELEM);
+        
+        writer.endElement(HTML.TR_ELEM);
+        
+        writer.endElement(HTML.BODY_ELEM);
+        writer.endElement(HTML.TABLE_ELEM);
+    }
+    
+    protected Resource getImageResource(FacesContext context, AbstractHtmlRoundedPanel roundedPanel, 
+            RoundedPanelProperties roundedPanelProperties, String roundedPanelPattern, String imagePart)
+    {
+        Resource r = null;
+        String resourceName = generateResourceName(roundedPanelProperties, 
+                roundedPanelPattern, imagePart); 
+        if (roundedPanel.getLibrary() != null)
+        {
+            r = context.getApplication().getResourceHandler().createResource(resourceName, roundedPanel.getLibrary());
+        }
+        if (r == null)
+        {
+            r = context.getApplication().getResourceHandler().createResource(resourceName, RoundedPanelResourceHandlerWrapper.ROUNDED_PANEL_LIBRARY);
+        }
+        return r;
+    }
+    
+    public String generateResourceName(RoundedPanelProperties roundedPanelProperties,
+            String roundedPanelPattern, String imagePart)
+    {
+        return roundedPanelPattern +"_"+ (imagePart == null ? "all" : imagePart) + encodeRoundedPanelProperties(roundedPanelProperties) + ".png";
+    }
+
+    private String encodeRoundedPanelProperties(RoundedPanelProperties roundedPanelProperties)
+    {
+        return roundedPanelProperties.getEncodedRoundedPanelProperties();
+    }
+
+    protected String encodeColorProperty(String color)
+    {
+        if (color == null)
+        {
+            return null;
+        }
+        if (color.length() > 0)
+        {
+            String returnedColor = HtmlColorUtils.encodeColorProperty(color);
+            if (returnedColor == null)
+            {
+                if (log.isWarnEnabled())
+                {
+                    log.warn("Cannot encode color:"+color);
+                }
+            }
+            return returnedColor;
+        }
+        else
+        {
+            return null;
+        }
+    }
+    
+}

Added: myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/RoundedPanelProperties.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/RoundedPanelProperties.java?rev=1130178&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/RoundedPanelProperties.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/RoundedPanelProperties.java Wed Jun  1 15:07:23 2011
@@ -0,0 +1,116 @@
+/*
+ * 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.roundedPanel;
+
+import org.apache.myfaces.shared_tomahawk.util.StringUtils;
+
+/**
+ * 
+ * @author Leonardo Uribe
+ *
+ */
+public class RoundedPanelProperties
+{
+
+    private int radius;
+    private String backgroundColor;
+    private String color;
+    
+    public RoundedPanelProperties(String encodedRoundedPanelProperties)
+    {
+        String[] array = StringUtils.splitLongString(encodedRoundedPanelProperties, '_');
+        
+        for (int i = 0; i < array.length; i++)
+        {
+            if (array[i].startsWith("r"))
+            {
+                radius = Integer.parseInt(array[i].substring(1));
+            }
+            else if (array[i].startsWith("c"))
+            {
+                color = "#"+array[i].substring(1);
+            }
+            else if (array[i].startsWith("b"))
+            {
+                backgroundColor = "#"+array[i].substring(1);
+            }
+            else
+            {
+                throw new IllegalStateException("Invalid encodedRoundedPanelProperties");
+            }
+        }
+    }
+
+    public RoundedPanelProperties(int radius)
+    {
+        this.radius = radius;
+    }
+
+    public int getRadius()
+    {
+        return radius;
+    }
+
+    public void setRadius(int radius)
+    {
+        this.radius = radius;
+    }
+    
+    public String getBackgroundColor()
+    {
+        return backgroundColor;
+    }
+
+    public String getColor()
+    {
+        return color;
+    }
+
+    public void setBackgroundColor(String backgroundColor)
+    {
+        this.backgroundColor = backgroundColor;
+    }
+
+    public void setColor(String color)
+    {
+        this.color = color;
+    }
+
+    public String getEncodedRoundedPanelProperties()
+    {
+        return ("_r"+Integer.toString(radius))+
+            (this.backgroundColor == null ? "" : "_b" + encodeColor(this.backgroundColor.trim()))+
+            (this.color == null ? "" : "_c" + encodeColor(this.color.trim()));
+    }
+    
+    private String encodeColor(String color)
+    {
+        if (color.charAt(0) == '#')
+        {
+            return color.substring(1);
+        }
+        return color;
+    }
+
+    @Override
+    public String toString()
+    {
+        return "["+Integer.toString(radius)+"]";
+    }
+}

Added: myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/RoundedPanelPropertiesBuilder.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/RoundedPanelPropertiesBuilder.java?rev=1130178&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/RoundedPanelPropertiesBuilder.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/RoundedPanelPropertiesBuilder.java Wed Jun  1 15:07:23 2011
@@ -0,0 +1,311 @@
+/*
+ * 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.roundedPanel;
+
+import java.awt.AlphaComposite;
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.Shape;
+import java.awt.Transparency;
+import java.awt.geom.Ellipse2D;
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import javax.faces.context.FacesContext;
+import javax.imageio.ImageIO;
+
+import org.apache.myfaces.shared_tomahawk.util.WebConfigParamUtils;
+
+/**
+ * 
+ * @author Leonardo Uribe
+ *
+ */
+public class RoundedPanelPropertiesBuilder
+{
+    public static final String ROUNDED_PANEL_PATTERN_BASIC = "b";
+    
+    public static final String SECTION_TOP_LEFT = "tl";
+    public static final String SECTION_TOP_RIGHT = "tr";
+    public static final String SECTION_BOTTOM_LEFT = "bl";
+    public static final String SECTION_BOTTOM_RIGHT = "br";
+    
+    public boolean isValidResourceName(FacesContext context, String resourceName)
+    {
+        String roundedPanelPattern = null;
+        String imagePart = null;
+        String roundedPanelPropertiesText = null;
+        int index = resourceName.indexOf('_');
+        if (index < 0)
+        {
+            return false;
+        }
+        if (!resourceName.endsWith(".png"))
+        {
+            return false;
+        }
+        roundedPanelPattern = resourceName.substring(0,index);
+        
+        //Check valid rounded panel pattern
+        if (!ROUNDED_PANEL_PATTERN_BASIC.equals(roundedPanelPattern))
+        {
+            return false;
+        }
+        
+        int index2 = resourceName.indexOf('_',index+1);
+        if (index2 < 0)
+        {
+            return false;
+        }
+        imagePart = resourceName.substring(index+1, index2);
+        
+        //Check valid image part
+        if (ROUNDED_PANEL_PATTERN_BASIC.equals(roundedPanelPattern))
+        {
+            if (!SECTION_TOP_RIGHT.equals(imagePart) &&
+                !SECTION_TOP_LEFT.equals(imagePart) &&
+                !SECTION_BOTTOM_RIGHT.equals(imagePart) &&
+                !SECTION_BOTTOM_LEFT.equals(imagePart))
+            {
+                return false;
+            }
+        }
+        
+        int index3 = resourceName.indexOf('.', index2+1);
+        if (index3 < 0)
+        {
+            return false;
+        }
+        roundedPanelPropertiesText = resourceName.substring(index2+1,index3);
+        
+        try
+        {
+            RoundedPanelProperties properties = new RoundedPanelProperties(roundedPanelPropertiesText);
+            
+            Integer maxRadius = WebConfigParamUtils.getIntegerInitParameter(context.getExternalContext(), 
+                    HtmlRoundedPanelRenderer.INIT_PARAM_ROUNDED_PANEL_MAX_RADIUS, 
+                    HtmlRoundedPanelRenderer.INIT_PARAM_ROUNDED_PANEL_MAX_RADIUS_DEFAULT);
+            
+            if (properties.getRadius() > maxRadius )
+            {
+                return false;
+            }
+            
+            if (properties.getBackgroundColor() != null &&
+                HtmlColorUtils.encodeColorProperty(properties.getBackgroundColor()) == null)
+            {
+                return false;
+            }
+
+            if (properties.getColor() != null &&
+                HtmlColorUtils.encodeColorProperty(properties.getColor()) == null)
+            {
+                return false;
+            }
+
+            return true;
+        }
+        catch(Exception e)
+        {
+            return false;
+        }
+    }
+    
+    public String decodeRoundedPanelPattern(String resourceName)
+    {
+        return resourceName.substring(0, resourceName.indexOf('_'));
+    }
+    
+    public String decodeImagePart(String resourceName)
+    {
+        int index = resourceName.indexOf('_');
+        int index2 = resourceName.indexOf('_',index+1);
+        return resourceName.substring(index+1, index2);
+    }
+    
+    public RoundedPanelProperties decodeRoundedPanelProperties(FacesContext context, String resourceName)
+    {
+        if (isValidResourceName(context, resourceName))
+        {
+            String roundedPanelPattern = null;
+            String imagePart = null;
+            String roundedPanelPropertiesText = null;
+            int index = resourceName.indexOf('_');
+            roundedPanelPattern = resourceName.substring(0,index);
+            int index2 = resourceName.indexOf('_',index+1);
+            imagePart = resourceName.substring(index+1, index2);
+            int index3 = resourceName.indexOf('.', index2+1);
+            roundedPanelPropertiesText = resourceName.substring(index2+1,index3);
+            return new RoundedPanelProperties(roundedPanelPropertiesText);
+        }
+        return null;
+    }
+    
+    public void generateRoundedPanelImage(FacesContext facesContext,
+                                          OutputStream out,
+                                          String resourceName) throws IOException
+    {
+        generateRoundedPanelImage(facesContext, out, 
+                decodeRoundedPanelProperties(facesContext, resourceName), 
+                decodeRoundedPanelPattern(resourceName),
+                decodeImagePart(resourceName));
+    }
+    
+    public void generateRoundedPanelImage(FacesContext facesContext,
+                                          OutputStream out,
+                                          RoundedPanelProperties roundedPanelProperties, 
+                                          String pattern, 
+                                          String imagePart)
+        throws IOException
+    {
+        if (ROUNDED_PANEL_PATTERN_BASIC.equals(pattern))
+        {
+            ImageIO.write(
+                    generateBasicRoundedPanelImage(facesContext, 
+                                                   roundedPanelProperties, 
+                                                   pattern, 
+                                                   imagePart), "png", out);
+        }
+    }
+    
+    public BufferedImage generateBasicRoundedPanelImage(
+            FacesContext facesContext, 
+            RoundedPanelProperties roundedPanelProperties,
+            String pattern, 
+            String imagePart)
+    {
+        // create the canvas image
+        int w, h;
+        
+        w = roundedPanelProperties.getRadius();
+        h = roundedPanelProperties.getRadius();
+        
+        BufferedImage canvas = new BufferedImage(w, h,
+                BufferedImage.TYPE_INT_ARGB);
+        Graphics2D g = canvas.createGraphics();
+        Graphics2D g2 = null;
+
+        try
+        {
+            // either paint the background of the image, or set it to transparent
+            Color backgroundColor = null;
+            if (roundedPanelProperties.getBackgroundColor() != null)
+            {
+                backgroundColor = Color.decode(roundedPanelProperties.getBackgroundColor());
+            }
+            
+            paintBackground(g, w, h, backgroundColor);
+   
+            g2 = (Graphics2D) g;
+            // TODO: Apply rendering hints with a property
+            RenderingHints renderHints =
+                new RenderingHints(RenderingHints.KEY_ANTIALIASING,
+                                   RenderingHints.VALUE_ANTIALIAS_ON);
+              renderHints.put(RenderingHints.KEY_RENDERING,
+                              RenderingHints.VALUE_RENDER_QUALITY);
+            g2.setRenderingHints(renderHints);
+
+            g.setStroke(new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
+            
+            if (roundedPanelProperties.getColor() != null)
+            {
+                g.setColor(Color.decode(roundedPanelProperties.getColor()));
+                g.setPaint(Color.decode(roundedPanelProperties.getColor()));
+            }
+            else
+            {
+                g.setColor(Color.BLACK);
+                g.setColor(Color.BLACK);
+            }
+            
+            int x=0;
+            int y=0;
+            
+            if (SECTION_TOP_LEFT.equals(imagePart))
+            {
+                x=0;
+                y=0;
+            }
+            else if (SECTION_TOP_RIGHT.equals(imagePart))
+            {
+                x=-roundedPanelProperties.getRadius()-2;
+                y=0;
+            }
+            else if (SECTION_BOTTOM_LEFT.equals(imagePart))
+            {
+                x=0;
+                y=-roundedPanelProperties.getRadius()-2;
+            }
+            else if (SECTION_BOTTOM_RIGHT.equals(imagePart))
+            {
+                x=-roundedPanelProperties.getRadius()-2;
+                y=-roundedPanelProperties.getRadius()-2;
+            }      
+
+            Shape circle = new Ellipse2D.Float(x,y, (roundedPanelProperties.getRadius()*2)+1, (roundedPanelProperties.getRadius()*2)+1);
+            
+            //Shape circle = new RoundRectangle2D.Float(x, y,
+            //        (float) (roundedPanelProperties.getRadius()*2)+1, (roundedPanelProperties.getRadius()*2)+1,
+            //        (roundedPanelProperties.getRadius()*2)+1, (roundedPanelProperties.getRadius()*2)+1);
+            
+            g2.fill(circle);
+            g2.draw(circle);
+            
+            return canvas;
+        }
+        finally
+        {
+            if (g2 != null)
+                try
+                {
+                    g2.dispose();
+                }
+                catch (Exception ex)
+                {
+                }
+            g.dispose();
+        }
+    }
+    
+    private void paintBackground(Graphics2D g, int width, int height, Color background)
+    {
+        // treat a null background as fully transparent
+        if (background == null)
+        {
+            BufferedImage img = g.getDeviceConfiguration()
+                    .createCompatibleImage(width, height,
+                            Transparency.TRANSLUCENT);
+            Graphics2D g2 = img.createGraphics();
+
+            // Clear the image so all pixels have zero alpha
+            g2.setComposite(AlphaComposite.Clear);
+            g2.fillRect(0, 0, width, height);
+
+            g2.dispose();
+        }
+        else
+        {
+            g.setColor(background);
+            g.fillRect(0, 0, width, height);
+        }
+    }
+}

Added: myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/RoundedPanelResouceHandlerSupport.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/RoundedPanelResouceHandlerSupport.java?rev=1130178&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/RoundedPanelResouceHandlerSupport.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/RoundedPanelResouceHandlerSupport.java Wed Jun  1 15:07:23 2011
@@ -0,0 +1,71 @@
+/*
+ * 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.roundedPanel;
+
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFWebConfigParam;
+import org.apache.myfaces.shared_tomahawk.util.WebConfigParamUtils;
+import org.apache.myfaces.shared_tomahawk.resource.BaseResourceHandlerSupport;
+import org.apache.myfaces.shared_tomahawk.resource.ResourceLoader;
+
+/**
+ * 
+ * @author Leonardo Uribe
+ *
+ */
+public class RoundedPanelResouceHandlerSupport extends BaseResourceHandlerSupport
+{
+    /**
+     * 
+     */
+    @JSFWebConfigParam
+    public final static String INIT_PARAM_CACHE_DISK_ROUNDED_IMAGES = "org.apache.myfaces.tomahawk.INIT_PARAM_CACHE_DISK_ROUNDED_IMAGES";
+    
+    private ResourceLoader[] _resourceLoaders;
+    
+    private RoundedPanelPropertiesBuilder _roundedPanelPropertiesBuilder;
+    
+    private boolean _cacheDiskRoundedImages;
+    
+    public RoundedPanelResouceHandlerSupport()
+    {
+        this._roundedPanelPropertiesBuilder = new RoundedPanelPropertiesBuilder();
+        _cacheDiskRoundedImages = WebConfigParamUtils.getBooleanInitParameter(
+                FacesContext.getCurrentInstance().getExternalContext(), 
+                INIT_PARAM_CACHE_DISK_ROUNDED_IMAGES);
+        this._resourceLoaders = new ResourceLoader[] {new RoundedPanelResourceLoader("oamRoundedPanel", this._roundedPanelPropertiesBuilder, this._cacheDiskRoundedImages)};
+    }
+
+    @Override
+    public ResourceLoader[] getResourceLoaders()
+    {
+        return _resourceLoaders;
+    }
+    
+    public RoundedPanelPropertiesBuilder getRoundedPanelPropertiesBuilder()
+    {
+        return _roundedPanelPropertiesBuilder;
+    }
+
+    public boolean isCacheDiskRoundedImages()
+    {
+        return _cacheDiskRoundedImages;
+    }
+}

Added: myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/RoundedPanelResource.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/RoundedPanelResource.java?rev=1130178&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/RoundedPanelResource.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/RoundedPanelResource.java Wed Jun  1 15:07:23 2011
@@ -0,0 +1,234 @@
+/*
+ * 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.roundedPanel;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.faces.application.ProjectStage;
+import javax.faces.application.Resource;
+import javax.faces.application.ResourceHandler;
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.shared_tomahawk.resource.ResourceLoader;
+import org.apache.myfaces.shared_tomahawk.resource.ResourceHandlerSupport;
+import org.apache.myfaces.shared_tomahawk.resource.ResourceLoaderUtils;
+import org.apache.myfaces.shared_tomahawk.resource.ResourceMeta;
+
+/**
+ * 
+ * @author Leonardo Uribe
+ *
+ */
+public class RoundedPanelResource extends Resource
+{
+    private ResourceMeta _resourceMeta;
+    private ResourceHandlerSupport _resourceHandlerSupport;
+    private ResourceLoader _resourceLoader;
+
+    public RoundedPanelResource(ResourceMeta resourceMeta,
+            ResourceLoader resourceLoader, ResourceHandlerSupport support)
+    {
+        _resourceMeta = resourceMeta;
+        _resourceLoader = resourceLoader;
+        _resourceHandlerSupport = support;
+        setLibraryName(resourceMeta.getLibraryName());
+        setResourceName(resourceMeta.getResourceName());
+        setContentType("image/png");
+    }
+    
+    @Override
+    public InputStream getInputStream() throws IOException
+    {
+        return getResourceLoader().getResourceInputStream(_resourceMeta);
+    }
+
+    @Override
+    public URL getURL()
+    {
+        return getResourceLoader().getResourceURL(_resourceMeta);
+    }
+    
+    public ResourceLoader getResourceLoader()
+    {
+        return _resourceLoader;
+    }  
+
+    @Override
+    public String getRequestPath()
+    {
+        String path;
+        if (_resourceHandlerSupport.isExtensionMapping())
+        {
+            path = ResourceHandler.RESOURCE_IDENTIFIER + '/' + 
+                getResourceName() + _resourceHandlerSupport.getMapping();
+        }
+        else
+        {
+            String mapping = _resourceHandlerSupport.getMapping(); 
+            path = ResourceHandler.RESOURCE_IDENTIFIER + '/' + getResourceName();
+            path = (mapping == null) ? path : mapping + path;
+        }
+ 
+        FacesContext facesContext = FacesContext.getCurrentInstance();
+        String metadata = null;
+        if (getLibraryName() != null)
+        {
+            metadata = "?ln=" + getLibraryName();
+            path = path + metadata;
+        }
+        
+        return facesContext.getApplication().getViewHandler().getResourceURL(facesContext, path);
+    }
+    
+    @Override
+    public Map<String, String> getResponseHeaders()
+    {
+        FacesContext facesContext = FacesContext.getCurrentInstance();
+        
+        if (facesContext.getApplication().getResourceHandler().isResourceRequest(facesContext))
+        {
+            Map<String, String> headers = new HashMap<String, String>();
+            
+            long lastModified;
+            try
+            {
+                URL url = this.getURL();
+                
+                if (url != null)
+                {
+                    lastModified = ResourceLoaderUtils.getResourceLastModified(url);
+                }
+                else
+                {
+                    lastModified = -1L;
+                }
+            }
+            catch (IOException e)
+            {
+                lastModified = -1L;
+            }
+            
+            if (lastModified < _resourceHandlerSupport.getStartupTime())
+            {
+                lastModified = _resourceHandlerSupport.getStartupTime();
+            }            
+
+            if (lastModified >= 0L)
+            {
+                headers.put("Last-Modified", ResourceLoaderUtils.formatDateHeader(lastModified));
+                
+                long expires;
+                if (facesContext.isProjectStage(ProjectStage.Development))
+                {
+                    // Force to expire now to prevent caching on development time.
+                    expires = System.currentTimeMillis();
+                }
+                else
+                {
+                    expires = System.currentTimeMillis() + _resourceHandlerSupport.getMaxTimeExpires();
+                }
+                headers.put("Expires", ResourceLoaderUtils.formatDateHeader(expires));
+            }
+            
+            return headers;
+        }
+        else
+        {
+            //No need to return headers 
+            return Collections.emptyMap();
+        }
+    }
+
+    @Override
+    public boolean userAgentNeedsUpdate(FacesContext context)
+    {
+        // RFC2616 says related to If-Modified-Since header the following:
+        //
+        // "... The If-Modified-Since request-header field is used with a method to 
+        // make it conditional: if the requested variant has not been modified since 
+        // the time specified in this field, an entity will not be returned from 
+        // the server; instead, a 304 (not modified) response will be returned 
+        // without any message-body..."
+        // 
+        // This method is called from ResourceHandlerImpl.handleResourceRequest and if
+        // returns false send a 304 Not Modified response.
+        
+        String ifModifiedSinceString = context.getExternalContext().getRequestHeaderMap().get("If-Modified-Since");
+        
+        if (ifModifiedSinceString == null)
+        {
+            return true;
+        }
+        
+        Long ifModifiedSince = ResourceLoaderUtils.parseDateHeader(ifModifiedSinceString);
+        
+        if (ifModifiedSince == null)
+        {
+            return true;
+        }
+        
+        Long lastModified;
+        try
+        {
+            URL url = this.getURL();
+            if (url != null)
+            {
+                lastModified = ResourceLoaderUtils.getResourceLastModified(url);
+            }
+            else
+            {
+                //If url is null, set the lastModified time to the startup time.
+                lastModified = _resourceHandlerSupport.getStartupTime();
+            }
+        }
+        catch (IOException exception)
+        {
+            lastModified = -1L;
+        }
+        
+        if (lastModified >= 0L)
+        {
+            // this.couldResourceContainValueExpressions() &&
+            // Note this resource should be recreated each time the application is started
+            if (lastModified < _resourceHandlerSupport.getStartupTime())
+            {
+                lastModified = _resourceHandlerSupport.getStartupTime();
+            }
+            
+            // If the lastModified date is lower or equal than ifModifiedSince,
+            // the agent does not need to update.
+            // Note the lastModified time is set at milisecond precision, but when 
+            // the date is parsed and sent on ifModifiedSince, the exceding miliseconds
+            // are trimmed. So, we have to compare trimming this from the calculated
+            // lastModified time.
+            if ( (lastModified-(lastModified % 1000)) <= ifModifiedSince)
+            {
+                return false;
+            }
+        }
+        
+        return true;
+    }
+
+}

Added: myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/RoundedPanelResourceHandlerWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/RoundedPanelResourceHandlerWrapper.java?rev=1130178&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/RoundedPanelResourceHandlerWrapper.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/RoundedPanelResourceHandlerWrapper.java Wed Jun  1 15:07:23 2011
@@ -0,0 +1,338 @@
+/*
+ * 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.roundedPanel;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.faces.application.Resource;
+import javax.faces.application.ResourceHandler;
+import javax.faces.application.ResourceHandlerWrapper;
+import javax.faces.application.ResourceWrapper;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.myfaces.shared_tomahawk.resource.ResourceHandlerSupport;
+import org.apache.myfaces.shared_tomahawk.resource.ResourceLoader;
+import org.apache.myfaces.shared_tomahawk.resource.ResourceMeta;
+import org.apache.myfaces.shared_tomahawk.util.ExternalContextUtils;
+import org.apache.myfaces.shared_tomahawk.util.StringUtils;
+
+/**
+ * 
+ * @author Leonardo Uribe
+ *
+ */
+public class RoundedPanelResourceHandlerWrapper extends ResourceHandlerWrapper
+{
+    public final static String ROUNDED_PANEL_LIBRARY = "oam.custom.roundedPanel";
+
+    private RoundedPanelResouceHandlerSupport _resourceHandlerSupport;
+
+    private ResourceHandler delegate;
+
+    public RoundedPanelResourceHandlerWrapper(ResourceHandler delegate)
+    {
+        super();
+        this.delegate = delegate;
+        this._resourceHandlerSupport = new RoundedPanelResouceHandlerSupport();
+    }
+
+    @Override
+    public ResourceHandler getWrapped()
+    {
+        return delegate;
+    }
+    
+    @Override
+    public Resource createResource(String resourceName, String libraryName)
+    {
+        if (libraryName != null && ROUNDED_PANEL_LIBRARY.equals(libraryName))
+        {
+            return internalCreateResource(resourceName, libraryName);
+        }
+        else
+        {
+            return super.createResource(resourceName, libraryName);
+        }
+    }
+
+    @Override
+    public Resource createResource(String resourceName, String libraryName, String contentType)
+    {
+        if (libraryName != null && ROUNDED_PANEL_LIBRARY.equals(libraryName))
+        {
+            return internalCreateResource(resourceName, libraryName);
+        }
+        else
+        {
+            return super.createResource(resourceName, libraryName, contentType);
+        }
+    }
+    
+    private Resource internalCreateResource(String resourceName, String libraryName)
+    {
+        FacesContext facesContext = FacesContext.getCurrentInstance();
+        Resource resource = null;
+        
+        //ResourceMeta resourceMeta = new ResourceMetaImpl(null, libraryName, null, resourceName, null);
+        
+        for (ResourceLoader loader : getResourceHandlerSupport().getResourceLoaders())
+        {
+            ResourceMeta resourceMeta = deriveResourceMeta(loader, resourceName, libraryName, null);
+            
+            if (resourceMeta != null)
+            {
+                resource = new RoundedPanelResource(resourceMeta, loader, getResourceHandlerSupport());
+                
+                break;
+            }
+        }
+        
+        //return new RoundedPanelResource(resourceMeta, support, properties, part)
+        
+        //TODO: Implement me
+        return resource;
+        /*
+        if (isResourceRequest(facesContext))
+        {
+            //TODO: Implement me
+            return null;
+        }
+        else
+        {
+            //TODO: Implement me
+            return null;
+        }*/
+    }
+    
+    protected ResourceMeta deriveResourceMeta(ResourceLoader resourceLoader,
+            String resourceName, String libraryName, String localePrefix)
+    {
+        ResourceMeta resourceId = resourceLoader.createResourceMeta(null, libraryName, null, resourceName, null);
+        
+        return resourceId;
+    }
+    
+    @Override
+    public void handleResourceRequest(FacesContext facesContext) throws IOException
+    {
+        final Map<String, String> requestMap = facesContext.getExternalContext().getRequestParameterMap();
+        final String libraryName = requestMap.get("ln");
+        
+        if (libraryName != null && ROUNDED_PANEL_LIBRARY.equals(libraryName) && !_resourceHandlerSupport.isCacheDiskRoundedImages())
+        {
+            String resourceBasePath = getResourceHandlerSupport()
+                .calculateResourceBasePath(facesContext);
+
+            if (resourceBasePath == null)
+            {
+                // No base name could be calculated, so no further
+                //advance could be done here. HttpServletResponse.SC_NOT_FOUND
+                //cannot be returned since we cannot extract the 
+                //resource base name
+                return;
+            }
+        
+            // We neet to get an instance of HttpServletResponse, but sometimes
+            // the response object is wrapped by several instances of 
+            // ServletResponseWrapper (like ResponseSwitch).
+            // Since we are handling a resource, we can expect to get an 
+            // HttpServletResponse.
+            Object response = facesContext.getExternalContext().getResponse();
+            HttpServletResponse httpServletResponse = ExternalContextUtils.getHttpServletResponse(response);
+            if (httpServletResponse == null)
+            {
+                throw new IllegalStateException("Could not obtain an instance of HttpServletResponse.");
+            }
+        
+            if (isResourceIdentifierExcluded(facesContext, resourceBasePath))
+            {
+                httpServletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND);
+                return;
+            }
+        
+            String resourceName = null;
+            if (resourceBasePath.startsWith(ResourceHandler.RESOURCE_IDENTIFIER))
+            {
+                resourceName = resourceBasePath
+                        .substring(ResourceHandler.RESOURCE_IDENTIFIER.length() + 1);
+            }
+            else
+            {
+                //Does not have the conditions for be a resource call
+                httpServletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND);
+                return;
+            }
+        
+            Resource resource = facesContext.getApplication().getResourceHandler().createResource(resourceName, libraryName);
+        
+            if (resource == null)
+            {
+                httpServletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND);
+                return;
+            }
+        
+            if (!resource.userAgentNeedsUpdate(facesContext))
+            {
+                httpServletResponse.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
+                return;
+            }
+        
+            httpServletResponse.setContentType(_getContentType(resource, facesContext.getExternalContext()));
+        
+            Map<String, String> headers = resource.getResponseHeaders();
+        
+            for (Map.Entry<String, String> entry : headers.entrySet())
+            {
+                httpServletResponse.setHeader(entry.getKey(), entry.getValue());
+            }
+
+            RoundedPanelPropertiesBuilder roundedPanelPropertiesBuilder = 
+                _resourceHandlerSupport.getRoundedPanelPropertiesBuilder();
+            
+            if (!roundedPanelPropertiesBuilder.isValidResourceName(facesContext, resourceName))
+            {
+                httpServletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND);
+                return;
+            }
+            
+            //serve up the bytes (taken from trinidad ResourceServlet)
+            try
+            {
+                OutputStream out = httpServletResponse.getOutputStream();
+                try
+                {
+                    roundedPanelPropertiesBuilder.generateRoundedPanelImage(facesContext, out, resourceName); 
+                    
+                    //set the content lenght
+                    //httpServletResponse.setContentLength(count);
+                }
+                finally
+                {
+                    out.close();
+                }
+            }
+            catch (IOException e)
+            {
+                Logger log = Logger.getLogger(RoundedPanelResourceHandlerWrapper.class.getName());
+                if (log.isLoggable(Level.SEVERE))
+                    log.severe("Error trying to load resource " + resourceName
+                            + " with library " + libraryName + " :"
+                            + e.getMessage());
+                httpServletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND);
+            }
+        }
+        else
+        {
+            super.handleResourceRequest(facesContext);
+        }
+    }
+    
+    protected boolean isResourceIdentifierExcluded(FacesContext context,
+            String resourceIdentifier)
+    {
+        String value = context.getExternalContext().getInitParameter(
+                RESOURCE_EXCLUDES_PARAM_NAME);
+        if (value == null)
+        {
+            value = RESOURCE_EXCLUDES_DEFAULT_VALUE;
+        }
+        //TODO: optimize this code
+        String[] extensions = StringUtils.splitShortString(value, ' ');
+        for (int i = 0; i < extensions.length; i++)
+        {
+            if (resourceIdentifier.endsWith(extensions[i]))
+            {
+                return true;
+            }
+        }
+        return false;
+    }
+    
+    private String _getContentType(Resource resource, ExternalContext externalContext)
+    {
+        String contentType = resource.getContentType();
+
+        // the resource does not provide a content-type --> determine it via mime-type
+        if (contentType == null || contentType.length() == 0)
+        {
+            String resourceName = getWrappedResourceName(resource);
+
+            if (resourceName != null)
+            {
+                contentType = externalContext.getMimeType(resourceName);
+            }
+        }
+
+        return contentType;
+    }
+
+    /**
+     * Recursively unwarp the resource until we find the real resourceName
+     * This is needed because the JSF2 specced ResourceWrapper doesn't override
+     * the getResourceName() method :(
+     * @param resource
+     * @return the first non-null resourceName or <code>null</code> if none set
+     */
+    private String getWrappedResourceName(Resource resource)
+    {
+        String resourceName = resource.getResourceName();
+        if (resourceName != null)
+        {
+            return resourceName;
+        }
+
+        if (resource instanceof ResourceWrapper)
+        {
+            return getWrappedResourceName(((ResourceWrapper) resource).getWrapped());
+        }
+
+        return null;
+    }
+
+
+    @Override
+    public boolean libraryExists(String libraryName)
+    {
+        if (libraryName != null && ROUNDED_PANEL_LIBRARY.equals(libraryName))
+        {
+            return true;
+        }
+        else
+        {
+            return super.libraryExists(libraryName);
+        }
+    }
+    
+    
+    
+    /**
+     * @return the resourceHandlerSupport
+     */
+    protected ResourceHandlerSupport getResourceHandlerSupport()
+    {
+        return _resourceHandlerSupport;
+    }
+    
+}

Added: myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/RoundedPanelResourceLoader.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/RoundedPanelResourceLoader.java?rev=1130178&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/RoundedPanelResourceLoader.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core20/src/main/java/org/apache/myfaces/custom/roundedPanel/RoundedPanelResourceLoader.java Wed Jun  1 15:07:23 2011
@@ -0,0 +1,324 @@
+/*
+ * 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.roundedPanel;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.faces.FacesException;
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.shared_tomahawk.resource.ResourceLoader;
+import org.apache.myfaces.shared_tomahawk.resource.ResourceMeta;
+import org.apache.myfaces.shared_tomahawk.resource.ResourceMetaImpl;
+
+/**
+ * 
+ * @author Leonardo Uribe
+ *
+ */
+public class RoundedPanelResourceLoader extends ResourceLoader
+{
+    public final static String ROUNDED_PANEL_MAP = "oam.tomahawk.ROUNDED_PANEL_MAP";
+    
+    private volatile File _imagesDir;
+    
+    private RoundedPanelPropertiesBuilder _builder;
+    
+    private boolean _cacheDiskRoundedImages;
+    
+    public RoundedPanelResourceLoader(String prefix, RoundedPanelPropertiesBuilder builder, boolean cacheDiskRoundedImages)
+    {
+        super(prefix);
+
+        // This is the best place for initialization. 
+        // This class is created eagerly by RoundedPanelResouceHandlerSupport,
+        // that is created too by RounderPanelResourceHandlerWrapper, so we
+        // can be sure in this place we are on init time (no request has been sent).
+        initialize(builder, cacheDiskRoundedImages);
+    }
+    
+    protected void initialize(RoundedPanelPropertiesBuilder builder, boolean cacheDiskRoundedImages)
+    {
+        //Get startup FacesContext
+        FacesContext facesContext = FacesContext.getCurrentInstance();
+        
+        _cacheDiskRoundedImages = cacheDiskRoundedImages;
+        
+        if (_cacheDiskRoundedImages)
+        {
+            //1. Create temporal directory for images
+            Map<String, Object> applicationMap = facesContext.getExternalContext().getApplicationMap();
+            File tempdir = (File) applicationMap.get("javax.servlet.context.tempdir");
+            File imagesDir = new File(tempdir, getPrefix());
+            if (!imagesDir.exists())
+            {
+                imagesDir.mkdirs();
+            }
+            _imagesDir = imagesDir;
+        }
+        
+        _builder = builder;
+        
+        //2. Create map for register rendered rounded panel images
+        Map<String, RoundedPanelProperties> roundedPanelMap = new ConcurrentHashMap<String, RoundedPanelProperties>();
+        facesContext.getExternalContext().getApplicationMap().put(RoundedPanelResourceLoader.ROUNDED_PANEL_MAP, roundedPanelMap);
+    }
+    
+    /*
+    @SuppressWarnings("unchecked")
+    public static final void registerImage(FacesContext facesContext, String name, RoundedPanelProperties properties)
+    {
+        Map<String, ImageCreator> map = (Map<String, ImageCreator>) 
+            facesContext.getExternalContext().getApplicationMap().get(RoundedPanelResourceLoader.ROUNDED_PANEL_MAP);
+        map.put(name, new ImageCreator(properties));
+    }*/
+    
+    /*
+    @SuppressWarnings("unchecked")
+    public static final RoundedPanelProperties getPanelProperties(FacesContext facesContext, String imageName)
+    {
+        Map<String, ImageCreator> map = (Map<String, ImageCreator>) 
+            facesContext.getExternalContext().getApplicationMap().get(RoundedPanelResourceLoader.ROUNDED_PANEL_MAP);
+        
+        ImageCreator creator = (ImageCreator) map.get(imageName);
+        if (creator != null)
+        {
+            return (RoundedPanelProperties) creator.getProperties();
+        }
+        return null;
+    }*/
+    
+    @Override
+    public String getResourceVersion(String path)
+    {
+        return null;
+    }
+
+    @Override
+    public String getLibraryVersion(String path)
+    {
+        return null;
+    }
+    
+    private File getImagesDir(FacesContext facesContext)
+    {
+        return _imagesDir;
+    }
+
+    @Override
+    public URL getResourceURL(ResourceMeta resourceMeta)
+    {
+        FacesContext facesContext = FacesContext.getCurrentInstance();
+        
+        if (_cacheDiskRoundedImages)
+        {
+            if (imageExists(facesContext, resourceMeta))
+            {
+                File file = createOrGetImage(facesContext, resourceMeta);
+                
+                try
+                {
+                    return file.toURL();
+                }
+                catch (MalformedURLException e)
+                {
+                    throw new FacesException(e);
+                }
+            }
+            else
+            {
+                return null;
+            }
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+    @Override
+    public InputStream getResourceInputStream(ResourceMeta resourceMeta)
+    {
+        FacesContext facesContext = FacesContext.getCurrentInstance();
+        if (_cacheDiskRoundedImages)
+        {
+            if (imageExists(facesContext, resourceMeta))
+            {
+                File file = createOrGetImage(facesContext, resourceMeta);
+                
+                try
+                {
+                    return new BufferedInputStream(new FileInputStream(file));
+                }
+                catch (FileNotFoundException e)
+                {
+                    throw new FacesException(e);
+                }
+            }
+            else
+            {
+                return null;
+            }
+        }
+        else
+        {
+            if (imageExists(facesContext, resourceMeta))
+            {
+                //TODO: Implement me
+                return null;
+            }
+            else
+            {
+                return null;
+            }
+        }
+    }
+    
+    private File createOrGetImage(FacesContext facesContext, ResourceMeta resourceMeta)
+    {
+        File imagesDir = getImagesDir(facesContext);
+        String name = resourceMeta.getResourceName();
+        File file = new File(imagesDir, name);
+        if (!file.exists())
+        {
+            Map<String, ImageFileProducer> map = (Map<String, ImageFileProducer>) 
+                facesContext.getExternalContext().getApplicationMap().get(RoundedPanelResourceLoader.ROUNDED_PANEL_MAP);
+
+            ImageFileProducer creator = map.get(name);
+            
+            if (creator == null)
+            {
+                synchronized(this)
+                {
+                    creator = map.get(name);
+                    
+                    if (creator == null)
+                    {
+                        creator = new ImageFileProducer();
+                        map.put(name, creator);
+                    }
+                }
+            }
+            
+            if (!creator.isCreated())
+            {
+                creator.createImage(facesContext, resourceMeta, file, this);
+            }
+        }
+        return file;
+    }
+    
+    protected void innerCreateImage(FacesContext facesContext, ResourceMeta resourceMeta, File file)
+    {
+        FileOutputStream fos = null;
+        
+        try
+        {
+            boolean success = file.createNewFile();
+        }
+        catch(IOException e)
+        {
+            throw new FacesException(e);
+        }
+
+        try
+        {
+            fos = new FileOutputStream(file);
+            
+            _builder.generateRoundedPanelImage(facesContext, fos, resourceMeta.getResourceName());
+        }
+        catch (Exception ex)
+        {
+            ex.printStackTrace();
+            throw new FacesException(ex);
+        }
+        finally
+        {
+            if (fos != null)
+            {
+                try
+                {
+                    fos.close();
+                }
+                catch (Exception ex)
+                {
+                }
+            }
+        }        
+    }
+    
+    private boolean imageExists(FacesContext facesContext, ResourceMeta resourceMeta)
+    {
+        return _builder.isValidResourceName(facesContext, resourceMeta.getResourceName());
+    }
+    
+    @Override
+    public ResourceMeta createResourceMeta(String prefix, String libraryName,
+            String libraryVersion, String resourceName, String resourceVersion)
+    {
+        ResourceMeta resourceMeta =  new ResourceMetaImpl(prefix, libraryName, libraryVersion, resourceName, resourceVersion);
+        
+        if (imageExists(FacesContext.getCurrentInstance(), resourceMeta))
+        {
+            return resourceMeta;
+        }
+        return null;
+    }
+
+    @Override
+    public boolean libraryExists(String libraryName)
+    {
+        return RoundedPanelResourceHandlerWrapper.ROUNDED_PANEL_LIBRARY.equals(libraryName);
+    }
+    
+    public static class ImageFileProducer {
+        
+        public volatile boolean created = false;
+        
+        public ImageFileProducer()
+        {
+            super();
+        }
+
+        public boolean isCreated()
+        {
+            return created;
+        }
+
+        public synchronized void createImage(FacesContext facesContext, ResourceMeta resourceMeta, File file, RoundedPanelResourceLoader loader)
+        {
+            if (!created)
+            {
+                loader.innerCreateImage(facesContext, resourceMeta, file);
+                created = true;
+            }
+        }
+    }
+
+}



Mime
View raw message