Author: manaRH
Date: 2013-06-03 09:20:28 -0400 (Mon, 03 Jun 2013)
New Revision: 15513
Modified:
branches/enterprise/WFK-2_1/examples/ui/ui-web/src/main/webapp/graphicImage.xhtml
branches/enterprise/WFK-2_1/jboss-seam-ui/src/main/java/org/jboss/seam/ui/graphicImage/GraphicImageRendererBase.java
branches/enterprise/WFK-2_1/jboss-seam-ui/src/main/java/org/jboss/seam/ui/graphicImage/UIGraphicImage.java
branches/enterprise/WFK-2_1/seam-reference-guide/src/docbook/en-US/Controls.xml
Log:
JBSEAM-3033 added cacheble s:graphicImage
Modified:
branches/enterprise/WFK-2_1/examples/ui/ui-web/src/main/webapp/graphicImage.xhtml
===================================================================
---
branches/enterprise/WFK-2_1/examples/ui/ui-web/src/main/webapp/graphicImage.xhtml 2013-06-03
13:20:12 UTC (rev 15512)
+++
branches/enterprise/WFK-2_1/examples/ui/ui-web/src/main/webapp/graphicImage.xhtml 2013-06-03
13:20:28 UTC (rev 15513)
@@ -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/WFK-2_1/jboss-seam-ui/src/main/java/org/jboss/seam/ui/graphicImage/GraphicImageRendererBase.java
===================================================================
---
branches/enterprise/WFK-2_1/jboss-seam-ui/src/main/java/org/jboss/seam/ui/graphicImage/GraphicImageRendererBase.java 2013-06-03
13:20:12 UTC (rev 15512)
+++
branches/enterprise/WFK-2_1/jboss-seam-ui/src/main/java/org/jboss/seam/ui/graphicImage/GraphicImageRendererBase.java 2013-06-03
13:20:28 UTC (rev 15513)
@@ -6,6 +6,7 @@
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;
@@ -31,26 +32,46 @@
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);
@@ -58,9 +79,8 @@
{
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);
Modified:
branches/enterprise/WFK-2_1/jboss-seam-ui/src/main/java/org/jboss/seam/ui/graphicImage/UIGraphicImage.java
===================================================================
---
branches/enterprise/WFK-2_1/jboss-seam-ui/src/main/java/org/jboss/seam/ui/graphicImage/UIGraphicImage.java 2013-06-03
13:20:12 UTC (rev 15512)
+++
branches/enterprise/WFK-2_1/jboss-seam-ui/src/main/java/org/jboss/seam/ui/graphicImage/UIGraphicImage.java 2013-06-03
13:20:28 UTC (rev 15513)
@@ -31,4 +31,13 @@
@Attribute
public abstract Object getValue();
+
+ @Attribute(description = @Description("True if this image should be
cached"))
+ public abstract boolean isCache();
+
+ @Attribute(description = @Description("Unique string for a cached image"))
+ public abstract String getCacheKey();
+
+ @Attribute(description = @Description("if property resolves to true, current
cached key will be removed"))
+ public abstract boolean isInvalidate();
}
Modified: branches/enterprise/WFK-2_1/seam-reference-guide/src/docbook/en-US/Controls.xml
===================================================================
---
branches/enterprise/WFK-2_1/seam-reference-guide/src/docbook/en-US/Controls.xml 2013-06-03
13:20:12 UTC (rev 15512)
+++
branches/enterprise/WFK-2_1/seam-reference-guide/src/docbook/en-US/Controls.xml 2013-06-03
13:20:28 UTC (rev 15513)
@@ -1346,6 +1346,21 @@
should be unique
</para>
</listitem>
+ <listitem>
+ <para>
+ <literal>cache</literal> — specify if this
image should be cached. Boolean value.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ <literal>invalidate</literal> — specify if
this image cache should be invalidated. Boolean value.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ <literal>cacheKey</literal> — specify unique
string for a cached image.
+ </para>
+ </listitem>
</itemizedlist>
<para><emphasis>Transformations</emphasis></para>
Show replies by date