Author: manaRH
Date: 2010-09-30 04:27:00 -0400 (Thu, 30 Sep 2010)
New Revision: 13786
Modified:
branches/enterprise/JBPAPP_5_0/examples/ui/view/graphicImage.xhtml
branches/enterprise/JBPAPP_5_0/ui/src/main/config/component/graphicImage.xml
branches/enterprise/JBPAPP_5_0/ui/src/main/java/org/jboss/seam/ui/graphicImage/GraphicImageRendererBase.java
branches/enterprise/JBPAPP_5_0/ui/src/main/java/org/jboss/seam/ui/graphicImage/UIGraphicImage.java
Log:
JBPAPP-4771
Modified: branches/enterprise/JBPAPP_5_0/examples/ui/view/graphicImage.xhtml
===================================================================
--- branches/enterprise/JBPAPP_5_0/examples/ui/view/graphicImage.xhtml 2010-09-29 13:01:01
UTC (rev 13785)
+++ branches/enterprise/JBPAPP_5_0/examples/ui/view/graphicImage.xhtml 2010-09-30 08:27:00
UTC (rev 13786)
@@ -11,7 +11,7 @@
<p>Outputs an image</p>
<h:panelGrid>
<s:fragment>
- <s:graphicImage value="#{person.picture.data}">
+ <s:graphicImage value="#{person.picture.data}" cache="true"
cacheKey="id-0.5">
<s:transformImageSize factor="0.5" />
</s:graphicImage>
<h:outputText value="No image found (upload one)"
rendered="#{person.picture.contentType eq null}" />
Modified: branches/enterprise/JBPAPP_5_0/ui/src/main/config/component/graphicImage.xml
===================================================================
---
branches/enterprise/JBPAPP_5_0/ui/src/main/config/component/graphicImage.xml 2010-09-29
13:01:01 UTC (rev 13785)
+++
branches/enterprise/JBPAPP_5_0/ui/src/main/config/component/graphicImage.xml 2010-09-30
08:27:00 UTC (rev 13786)
@@ -29,5 +29,20 @@
<classname>java.lang.String</classname>
<description>File name for the generated URL - allows a stable file name and
thus browser caching</description>
</property>
+ <property>
+ <name>cache</name>
+ <classname>boolean</classname>
+ <description>True if this image should be cached</description>
+ </property>
+ <property>
+ <name>cacheKey</name>
+ <classname>java.lang.String</classname>
+ <description>Unique string for a cached image</description>
+ </property>
+ <property>
+ <name>invalidate</name>
+ <classname>boolean</classname>
+ <description>if property resolves to true, current cached key will be
removed</description>
+ </property>
</component>
</components>
Modified:
branches/enterprise/JBPAPP_5_0/ui/src/main/java/org/jboss/seam/ui/graphicImage/GraphicImageRendererBase.java
===================================================================
---
branches/enterprise/JBPAPP_5_0/ui/src/main/java/org/jboss/seam/ui/graphicImage/GraphicImageRendererBase.java 2010-09-29
13:01:01 UTC (rev 13785)
+++
branches/enterprise/JBPAPP_5_0/ui/src/main/java/org/jboss/seam/ui/graphicImage/GraphicImageRendererBase.java 2010-09-30
08:27:00 UTC (rev 13786)
@@ -6,43 +6,64 @@
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
+import org.jboss.seam.cache.CacheProvider;
import org.jboss.seam.ui.graphicImage.GraphicImageStore.ImageWrapper;
import org.jboss.seam.ui.util.HTML;
import org.jboss.seam.ui.util.cdk.RendererBase;
public class GraphicImageRendererBase extends RendererBase
{
-
+
@Override
protected Class getComponentClass()
{
return UIGraphicImage.class;
}
-
+
@Override
protected void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException
{
UIGraphicImage graphicImage = (UIGraphicImage) component;
-
+
+ CacheProvider cacheProvider = CacheProvider.instance();
+
String key = graphicImage.getFileName();
String extension = null;
+ ImageWrapper wrapper = null;
+
Image image = Image.instance();
- image.setInput(graphicImage.getValue());
-
- // Do transforms
-
- for (UIComponent cmp : graphicImage.getChildren())
+
+ if (graphicImage.isInvalidate())
+ cacheProvider.remove(graphicImage.getCacheKey());
+
+ if (graphicImage.isCache() && cacheProvider.get(graphicImage.getCacheKey())
!= null)
{
- if (cmp instanceof ImageTransform)
+ wrapper = (ImageWrapper) cacheProvider.get(graphicImage.getCacheKey());
+ }
+ else
+ {
+
+ image.setInput(graphicImage.getValue());
+
+ // Do transforms
+
+ for (UIComponent cmp : graphicImage.getChildren())
{
- ImageTransform imageTransform = (ImageTransform) cmp;
- imageTransform.applyTransform(image);
+ if (cmp instanceof ImageTransform)
+ {
+ ImageTransform imageTransform = (ImageTransform) cmp;
+ imageTransform.applyTransform(image);
+ }
}
+
+ wrapper = new ImageWrapper(image.getImage(), image.getContentType());
+
+ if(graphicImage.isCache())
+ cacheProvider.put(graphicImage.getCacheKey(), wrapper);
}
- key = GraphicImageStore.instance().put(new ImageWrapper(image.getImage(),
image.getContentType()),
- key);
+ key = GraphicImageStore.instance().put(wrapper, key);
extension = image.getContentType().getExtension();
writer.startElement(HTML.IMG_ELEM, graphicImage);
@@ -50,14 +71,13 @@
{
writer.writeAttribute(HTML.ID_ATTR, graphicImage.getClientId(context),
HTML.ID_ATTR);
}
-
- String url = context.getExternalContext().getRequestContextPath()
- + GraphicImageResource.GRAPHIC_IMAGE_RESOURCE_PATH + "/" + key +
extension;
+
+ String url = context.getExternalContext().getRequestContextPath() +
GraphicImageResource.GRAPHIC_IMAGE_RESOURCE_PATH + "/" + key + extension;
writer.writeAttribute(HTML.SRC_ATTR, url, HTML.SRC_ATTR);
HTML.renderHTMLAttributes(writer, component, HTML.IMG_PASSTHROUGH_ATTRIBUTES);
writer.endElement(HTML.IMG_ELEM);
}
-
+
@Override
public boolean getRendersChildren()
{
Modified:
branches/enterprise/JBPAPP_5_0/ui/src/main/java/org/jboss/seam/ui/graphicImage/UIGraphicImage.java
===================================================================
---
branches/enterprise/JBPAPP_5_0/ui/src/main/java/org/jboss/seam/ui/graphicImage/UIGraphicImage.java 2010-09-29
13:01:01 UTC (rev 13785)
+++
branches/enterprise/JBPAPP_5_0/ui/src/main/java/org/jboss/seam/ui/graphicImage/UIGraphicImage.java 2010-09-30
08:27:00 UTC (rev 13786)
@@ -2,15 +2,24 @@
import javax.faces.component.html.HtmlGraphicImage;
-public abstract class UIGraphicImage extends HtmlGraphicImage
-{
+public abstract class UIGraphicImage extends HtmlGraphicImage {
- public static final String FAMILY = "org.jboss.seam.ui.UIGraphicImage";
+ public static final String FAMILY = "org.jboss.seam.ui.UIGraphicImage";
- public abstract String getFileName();
+ public abstract String getFileName();
- public abstract void setFileName(String fileName);
-
-
+ public abstract void setFileName(String fileName);
+ public abstract boolean isCache();
+
+ public abstract void setCache(boolean cache);
+
+ public abstract String getCacheKey();
+
+ public abstract void setCacheKey(String cacheKey);
+
+ public abstract boolean isInvalidate();
+
+ public abstract void setInvalidate(boolean invalidate);
+
}
Show replies by date