myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From grantsm...@apache.org
Subject svn commit: r643044 - in /myfaces/tomahawk/trunk/sandbox: core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/ core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/util/ examples/src/main/java/org/apache/myfaces/examples/graphi...
Date Mon, 31 Mar 2008 16:15:45 GMT
Author: grantsmith
Date: Mon Mar 31 09:15:42 2008
New Revision: 643044

URL: http://svn.apache.org/viewvc?rev=643044&view=rev
Log:
https://issues.apache.org/jira/browse/TOMAHAWK-1220
Refactorings

Added:
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/util/
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/util/GraphicImageDynamicConstants.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/util/GraphicsImageDynamicHelper.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/util/ImageContext.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/util/ImageRenderer.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/util/ImageResponseStream.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/util/SimpleImageContext.java
Modified:
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/GraphicImageDynamic.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/GraphicImageDynamicRenderer.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/GraphicImageDynamicTag.java
    myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/graphicImageDynamic/GraphicImageDynamicTextBean.java
    myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/graphicImageDynamic/UploadedImageRenderer.java

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/GraphicImageDynamic.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/GraphicImageDynamic.java?rev=643044&r1=643043&r2=643044&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/GraphicImageDynamic.java
(original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/GraphicImageDynamic.java
Mon Mar 31 09:15:42 2008
@@ -16,9 +16,11 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.myfaces.custom.graphicimagedynamic;
 
 import org.apache.myfaces.component.html.ext.HtmlGraphicImage;
+import org.apache.myfaces.custom.graphicimagedynamic.util.ImageRenderer;
 import org.apache.myfaces.shared_tomahawk.util.ClassUtils;
 
 import javax.faces.context.FacesContext;
@@ -41,7 +43,12 @@
 {
     public static final String COMPONENT_TYPE = "org.apache.myfaces.GraphicImageDynamic";
     public static final String COMPONENT_FAMILY = "javax.faces.Graphic";
-    private static final String DEFAULT_RENDERER_TYPE = GraphicImageDynamicRenderer.RENDERER_TYPE;
+    public static final String RENDERER_PARAM = "_renderer";
+	public static final String VALUE_PARAM = "_value";
+	public static final String WIDTH_PARAM = "_width";
+	public static final String HEIGHT_PARAM = "_height";    
+    private static final String DEFAULT_RENDERER_TYPE = GraphicImageDynamicRenderer.RENDERER_TYPE;

+    
 
     public GraphicImageDynamic()
     {

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/GraphicImageDynamicRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/GraphicImageDynamicRenderer.java?rev=643044&r1=643043&r2=643044&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/GraphicImageDynamicRenderer.java
(original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/GraphicImageDynamicRenderer.java
Mon Mar 31 09:15:42 2008
@@ -19,23 +19,12 @@
 
 package org.apache.myfaces.custom.graphicimagedynamic;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.myfaces.component.html.util.ParameterResourceHandler;
-import org.apache.myfaces.renderkit.html.ext.HtmlImageRenderer;
-import org.apache.myfaces.renderkit.html.util.AddResource;
-import org.apache.myfaces.renderkit.html.util.AddResourceFactory;
-import org.apache.myfaces.renderkit.html.util.ResourceLoader;
-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;
-import org.apache.myfaces.shared_tomahawk.util.ClassUtils;
+import java.io.IOException;
+import java.util.Map;
 
 import javax.faces.FacesException;
 import javax.faces.FactoryFinder;
 import javax.faces.component.UIComponent;
-import javax.faces.component.UIParameter;
-import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
 import javax.faces.context.FacesContextFactory;
 import javax.faces.context.ResponseStream;
@@ -43,332 +32,183 @@
 import javax.faces.el.ValueBinding;
 import javax.faces.lifecycle.Lifecycle;
 import javax.faces.lifecycle.LifecycleFactory;
-import javax.faces.webapp.FacesServlet;
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.component.html.util.ParameterResourceHandler;
+import org.apache.myfaces.custom.graphicimagedynamic.util.GraphicImageDynamicConstants;
+import org.apache.myfaces.custom.graphicimagedynamic.util.GraphicsImageDynamicHelper;
+import org.apache.myfaces.custom.graphicimagedynamic.util.ImageContext;
+import org.apache.myfaces.custom.graphicimagedynamic.util.ImageRenderer;
+import org.apache.myfaces.custom.graphicimagedynamic.util.ImageResponseStream;
+import org.apache.myfaces.custom.util.ComponentUtils;
+import org.apache.myfaces.renderkit.html.ext.HtmlImageRenderer;
+import org.apache.myfaces.renderkit.html.util.AddResource;
+import org.apache.myfaces.renderkit.html.util.AddResourceFactory;
+import org.apache.myfaces.renderkit.html.util.ResourceLoader;
+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 Sylvain Vieujot
- * @version $Revision$ $Date: 2005-05-23 19:39:37 +0200 (Mon, 23 May 2005) $
  */
-public class GraphicImageDynamicRenderer extends HtmlImageRenderer implements ResourceLoader
-{
-    protected static class SimpleImageContext implements ImageContext
-    {
-        private final Map _params;
-        private final Integer _width;
-        private final Integer _height;
-
-        public SimpleImageContext(Map params, Integer width, Integer height)
-        {
-            _params = params;
-            _width = width;
-            _height = height;
-        }
-
-        public Map getParamters()
-        {
-            return _params;
-        }
-
-        public Integer getWidth()
-        {
-            return _width;
-        }
-
-        public Integer getHeight()
-        {
-            return _height;
-        }
-    }
-
-    private static final Log log = LogFactory.getLog(GraphicImageDynamicRenderer.class);
-
-    private static final class ImageResponseStream extends ResponseStream
-    {
-        private final OutputStream _out;
-
-        private ImageResponseStream(OutputStream out)
-        {
-            _out = out;
-        }
-
-        public void close() throws IOException
-        {
-            _out.flush();
-            _out.close();
-        }
-
-        public void flush() throws IOException
-        {
-            _out.flush();
-        }
-
-        public void write(byte[] b, int off, int len) throws IOException
-        {
-            _out.write(b, off, len);
-        }
-
-        public void write(byte[] b) throws IOException
-        {
-            _out.write(b);
-        }
-
-        public void write(int b) throws IOException
-        {
-            _out.write(b);
-        }
-    }
-
-    private static final String RENDERER_PARAM = "_renderer";
-	private static final String VALUE_PARAM = "_value";
-    private static final String WIDTH_PARAM = "_width";
-    private static final String HEIGHT_PARAM = "_height";
-
+public class GraphicImageDynamicRenderer extends HtmlImageRenderer implements
+		ResourceLoader {
+	
+	private static final Log log = LogFactory
+			.getLog(GraphicImageDynamicRenderer.class);
     public static final String RENDERER_TYPE = "org.apache.myfaces.GraphicImageDynamicRenderer";
 
-    public void encodeEnd(FacesContext context, UIComponent component) throws IOException
-    {
-        RendererUtils.checkParamValidity(context, component, GraphicImageDynamic.class);
-
-        GraphicImageDynamic graphicImageDynamic = (GraphicImageDynamic) component;
-        ResponseWriter writer = context.getResponseWriter();
-
-        writer.startElement(HTML.IMG_ELEM, graphicImageDynamic);
-        HtmlRendererUtils.writeIdIfNecessary(writer, graphicImageDynamic, context);
-        HtmlRendererUtils.renderHTMLAttributes(writer, graphicImageDynamic,
-                                               HTML.IMG_PASSTHROUGH_ATTRIBUTES);
-
-        Map params = getParameterMap(context, component);
-        String width = graphicImageDynamic.getWidth();
-        if (width != null)
-        {
-            params.put(WIDTH_PARAM, width);
-        }
-        String height = graphicImageDynamic.getHeight();
-        if (height != null)
-        {
-            params.put(HEIGHT_PARAM, height);
-        }
-
-        Class imageRendererClass = graphicImageDynamic.getImageRendererClass();
-        if (imageRendererClass != null)
-        {
-			params.put(RENDERER_PARAM, imageRendererClass.getName());
-        }
-
-		ValueBinding imageRendererValueBinding = graphicImageDynamic.getValueBinding("value");
-		if (imageRendererValueBinding != null)
-		{
-			params.put(VALUE_PARAM, imageRendererValueBinding.getExpressionString());
+    public void encodeEnd(FacesContext context, UIComponent component)
+			throws IOException {
+
+		GraphicImageDynamic graphicImageDynamic = (GraphicImageDynamic) component;
+		String width = graphicImageDynamic.getWidth();
+		String height = graphicImageDynamic.getHeight();
+		ResponseWriter writer = context.getResponseWriter();
+		Map params = ComponentUtils.getParameterMap(component);
+		Class imageRendererClass = graphicImageDynamic.getImageRendererClass();
+		ValueBinding imageRendererValueBinding = graphicImageDynamic
+				.getValueBinding("value");
+		AddResource addResource;
+		String url;
+
+		// render the img HTML element.
+		RendererUtils.checkParamValidity(context, component,
+				GraphicImageDynamic.class);
+
+		writer.startElement(HTML.IMG_ELEM, graphicImageDynamic);
+
+		HtmlRendererUtils.writeIdIfNecessary(writer, graphicImageDynamic,
+				context);
+		HtmlRendererUtils.renderHTMLAttributes(writer, graphicImageDynamic,
+				HTML.IMG_PASSTHROUGH_ATTRIBUTES);
+
+		if (width != null) {
+			params.put(GraphicImageDynamic.WIDTH_PARAM, width);
 		}
 
-		AddResource addResource = AddResourceFactory.getInstance(context);
-        String url =
-			context.getExternalContext().encodeResourceURL(
-				addResource.getResourceUri(context, new ParameterResourceHandler(this
-					.getClass(), params)));
-        writer.writeAttribute(HTML.SRC_ATTR, url, null);
-
-        writer.endElement(HTML.IMG_ELEM);
-    }
-
-    protected Map getParameterMap(FacesContext context, UIComponent component)
-    {
-        Map result = new HashMap();
-        for (Iterator iter = component.getChildren().iterator(); iter.hasNext();)
-        {
-            UIComponent child = (UIComponent) iter.next();
-            if (child instanceof UIParameter)
-            {
-                UIParameter uiparam = (UIParameter) child;
-                Object value = uiparam.getValue();
-                if (value != null)
-                {
-                    result.put(uiparam.getName(), value);
-                }
-            }
-        }
-        return result;
-    }
-
-    public void decode(FacesContext facesContext, UIComponent component)
-    {
-        super.decode(facesContext, component);
-    }
+		if (height != null) {
+			params.put(GraphicImageDynamic.HEIGHT_PARAM, height);
+		}
 
-    /**
-     * @throws IOException
-     * @see org.apache.myfaces.renderkit.html.util.ResourceLoader#serveResource(javax.servlet.ServletContext,
javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.String)
-     */
-    public void serveResource(ServletContext context, HttpServletRequest request,
-                              HttpServletResponse response, String resourceUri) throws IOException
-    {
-        FacesContextFactory facesContextFactory = (FacesContextFactory) FactoryFinder
-                .getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
-        LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder
-                .getFactory(FactoryFinder.LIFECYCLE_FACTORY);
-        Lifecycle lifecycle = lifecycleFactory.getLifecycle(getLifecycleId(context));
-        FacesContext facesContext = facesContextFactory.getFacesContext(context, request,
response,
-                                                                        lifecycle);
-        facesContext.setResponseStream(new ImageResponseStream(response.getOutputStream()));
-        try
-        {
-			ImageRenderer imageRenderer = null;
+		if (imageRendererClass != null) {
+			params.put(GraphicImageDynamic.RENDERER_PARAM, imageRendererClass
+					.getName());
+		}
 
-			Map requestMap = facesContext.getExternalContext().getRequestParameterMap();
-            Object rendererValue = requestMap.get(RENDERER_PARAM);
-			if (rendererValue != null)
-			{
-				imageRenderer = getImageRendererFromClassName(rendererValue.toString());
-			}
-			else
-			{
-				Object rendererValueBinding = requestMap.get(VALUE_PARAM);
-				if (rendererValueBinding != null)
-				{
-					imageRenderer = getImageRendererFromValueBinding(facesContext, rendererValueBinding.toString());
+		if (imageRendererValueBinding != null) {
+			params.put(GraphicImageDynamic.VALUE_PARAM,
+					imageRendererValueBinding.getExpressionString());
+		}
+
+		addResource = AddResourceFactory.getInstance(context);
+		url = context.getExternalContext().encodeResourceURL(
+				addResource.getResourceUri(context,
+						new ParameterResourceHandler(this.getClass(), params)));
+		writer.writeAttribute(HTML.SRC_ATTR, url, null);
+
+		writer.endElement(HTML.IMG_ELEM);
+	}
+
+    public void decode(FacesContext facesContext, UIComponent component) {
+		super.decode(facesContext, component);
+	}
+
+    public void serveResource(ServletContext servletContext,
+			HttpServletRequest request, HttpServletResponse response,
+			String resourceUri) throws IOException {
+
+		// get the facesContext from the servletContext.
+		FacesContextFactory facesContextFactory = (FacesContextFactory) FactoryFinder
+				.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
+		LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder
+				.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
+		Lifecycle lifecycle = lifecycleFactory.getLifecycle(ComponentUtils
+				.getLifecycleId(servletContext));
+		FacesContext facesContext = facesContextFactory.getFacesContext(
+				servletContext, request, response, lifecycle);
+
+		facesContext.setResponseStream(new ImageResponseStream(response
+				.getOutputStream()));
+
+		// render the image.
+		try {
+
+			ImageRenderer imageRenderer = null;
+			Map requestMap = facesContext.getExternalContext()
+					.getRequestParameterMap();
+			Object rendererValue = requestMap
+					.get(GraphicImageDynamic.RENDERER_PARAM);
+
+			if (rendererValue != null) {
+				imageRenderer = GraphicsImageDynamicHelper
+						.getImageRendererFromClassName(rendererValue.toString());
+			} else {
+				Object rendererValueBinding = requestMap
+						.get(GraphicImageDynamic.VALUE_PARAM);
+				
+				if (rendererValueBinding != null) {
+					imageRenderer = GraphicsImageDynamicHelper
+							.getImageRendererFromValueBinding(facesContext,
+									rendererValueBinding.toString());
 				}
 			}
 
-
-			if (imageRenderer == null)
-			{
-				throw new FacesException("no image renderer defined.");
+			if (imageRenderer == null) {
+				throw new FacesException(
+						GraphicImageDynamicConstants.NO_IMAGE_RENDERER_DEFINED);
 			}
 
-			try
-			{
+			try {
 				renderImage(imageRenderer, facesContext);
+			} catch (Exception e) {
+				throw new FacesException(
+						GraphicImageDynamicConstants.MSG_COULDNOT_RENDER_IMAGE
+								+ rendererValue + " : " + e.getMessage(), e);
 			}
-			catch (Exception e)
-			{
-				throw new FacesException("could not renderer image "
-										 + rendererValue + " : " + e.getMessage(), e);
-			}
+
 			facesContext.getResponseStream().close();
-        }
-        finally
-        {
-            facesContext.release();
-        }
-    }
-
-	protected ImageRenderer getImageRendererFromValueBinding(FacesContext facesContext, String
rendererValueBinding)
-	{
-		return (ImageRenderer) facesContext.getApplication().createValueBinding(rendererValueBinding.toString()).getValue(facesContext);
+		} finally {
+			facesContext.release();
+		}
 	}
 
-	protected ImageRenderer getImageRendererFromClassName(String imageRendererClassName)
-	{
-		ImageRenderer imageRenderer;
-		try
-				{
-					Class rendererClass = ClassUtils.classForName(imageRendererClassName.toString());
-			if (!ImageRenderer.class.isAssignableFrom(rendererClass))
-			{
-				throw new FacesException("Image renderer class [" + imageRendererClassName
-										 + "] does not implement " + ImageRenderer.class.getName());
-			}
-			try
-			{
-				imageRenderer = (ImageRenderer) rendererClass.newInstance();
-			}
-			catch (InstantiationException e)
-			{
-				throw new FacesException("could not instantiate image renderer class "
-										 + imageRendererClassName + " : " + e.getMessage(), e);
-			}
-			catch (IllegalAccessException e)
-			{
-				throw new FacesException("could not instantiate image renderer class "
-										 + imageRendererClassName + " : " + e.getMessage(), e);
-			}
+    /**
+     * This method is used for rendering the image.
+     * @param imageRenderer
+     * @param facesContext
+     * @throws Exception
+     */
+	protected void renderImage(ImageRenderer imageRenderer,
+			FacesContext facesContext) throws Exception {
+
+		ImageContext imageContext = GraphicsImageDynamicHelper
+				.createImageContext(facesContext, log);
+		imageRenderer.setContext(facesContext, imageContext);
+		HttpServletResponse response = (HttpServletResponse) facesContext
+				.getExternalContext().getResponse();
+		int contentLength = imageRenderer.getContentLength();
+		String contentType = imageRenderer.getContentType();
+		ResponseStream out = facesContext.getResponseStream();
+
+		if (contentLength > 0) {
+			response.setContentLength(contentLength);
 		}
-		catch (ClassNotFoundException e)
-		{
-			throw new FacesException("image renderer class not found: " + e.getMessage(), e);
+
+		if (contentType != null && contentType.length() > 0) {
+			response.setContentType(contentType);
 		}
-		return imageRenderer;
-	}
 
-	protected void renderImage(ImageRenderer imageRenderer, FacesContext facesContext)
-            throws Exception
-    {
-            ImageContext imageContext = createImageContext(facesContext);
-
-        imageRenderer.setContext(facesContext, imageContext);
-
-        HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext()
-                .getResponse();
-
-
-        int contentLength = imageRenderer.getContentLength();
-        if( contentLength >0 )
-        {
-            response.setContentLength(contentLength);
-        }
-
-        String contentType = imageRenderer.getContentType();
-        if (contentType != null && contentType.length() > 0 )
-        {
-            response.setContentType(contentType);
-        }
-
-        ResponseStream out = facesContext.getResponseStream();
-        try
-        {
-                imageRenderer.renderResource( out );
-        }
-        finally
-        {
-            out.close();
-            facesContext.responseComplete();
-        }
-    }
-
-    protected ImageContext createImageContext(FacesContext facesContext)
-    {
-        ExternalContext externalContext = facesContext.getExternalContext();
-        final Map requestMap = externalContext.getRequestParameterMap();
-        Object value = requestMap.get(WIDTH_PARAM);
-        Integer width = null;
-        if (value != null)
-        {
-            try
-            {
-                width = Integer.valueOf(value.toString());
-            }
-            catch (NumberFormatException e)
-            {
-                log.error("Invalid value for image width : " + value + ", " + e.getMessage(),
e);
-            }
-        }
-        Integer height = null;
-        value = requestMap.get(HEIGHT_PARAM);
-        if (value != null)
-        {
-            try
-            {
-                height = Integer.valueOf(value.toString());
-            }
-            catch (NumberFormatException e)
-            {
-                log.error("Invalid value for image height : " + value + ", " + e.getMessage(),
e);
-            }
-        }
-        return new SimpleImageContext(requestMap, width, height);
-    }
-
-    private String getLifecycleId(ServletContext context)
-    {
-        String lifecycleId = context.getInitParameter(FacesServlet.LIFECYCLE_ID_ATTR);
-        return lifecycleId != null ? lifecycleId : LifecycleFactory.DEFAULT_LIFECYCLE;
-    }
+		try {
+			imageRenderer.renderResource(out);
+		} finally {
+			out.close();
+			facesContext.responseComplete();
+		}
+	}
 }

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/GraphicImageDynamicTag.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/GraphicImageDynamicTag.java?rev=643044&r1=643043&r2=643044&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/GraphicImageDynamicTag.java
(original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/GraphicImageDynamicTag.java
Mon Mar 31 09:15:42 2008
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.myfaces.custom.graphicimagedynamic;
 
 import org.apache.myfaces.taglib.html.ext.HtmlGraphicImageTag;
@@ -58,4 +59,4 @@
     {
         _imageRendererClass = imageRendererClass;
     }
-}
\ No newline at end of file
+}

Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/util/GraphicImageDynamicConstants.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/util/GraphicImageDynamicConstants.java?rev=643044&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/util/GraphicImageDynamicConstants.java
(added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/util/GraphicImageDynamicConstants.java
Mon Mar 31 09:15:42 2008
@@ -0,0 +1,25 @@
+/*
+ * 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.graphicimagedynamic.util;
+
+public interface GraphicImageDynamicConstants {
+	String NO_IMAGE_RENDERER_DEFINED = "no image renderer defined.";
+	String MSG_COULDNOT_RENDER_IMAGE = "could not render image ";
+}

Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/util/GraphicsImageDynamicHelper.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/util/GraphicsImageDynamicHelper.java?rev=643044&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/util/GraphicsImageDynamicHelper.java
(added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/util/GraphicsImageDynamicHelper.java
Mon Mar 31 09:15:42 2008
@@ -0,0 +1,124 @@
+/*
+ * 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.graphicimagedynamic.util;
+
+import java.util.Map;
+
+import javax.faces.FacesException;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+
+import org.apache.commons.logging.Log;
+import org.apache.myfaces.custom.graphicimagedynamic.GraphicImageDynamic;
+import org.apache.myfaces.shared_tomahawk.util.ClassUtils;
+
+/**
+ * This class is a utility class used by the 
+ * GraphicsImageDynamic component.
+ */
+public class GraphicsImageDynamicHelper {
+	
+	/**
+	 * This method is used for getting the ImageRenderer
+	 * from the image render class.
+	 * @param imageRendererClassName
+	 * @return the image renderer
+	 */
+	public static ImageRenderer getImageRendererFromClassName(
+			String imageRendererClassName) {
+		ImageRenderer imageRenderer;
+		try {
+			Class rendererClass = ClassUtils
+					.classForName(imageRendererClassName);
+			if (!ImageRenderer.class.isAssignableFrom(rendererClass)) {
+				throw new FacesException("Image renderer class ["
+						+ imageRendererClassName + "] does not implement "
+						+ ImageRenderer.class.getName());
+			}
+			try {
+				imageRenderer = (ImageRenderer) rendererClass.newInstance();
+			} catch (InstantiationException e) {
+				throw new FacesException(
+						"could not instantiate image renderer class "
+								+ imageRendererClassName + " : "
+								+ e.getMessage(), e);
+			} catch (IllegalAccessException e) {
+				throw new FacesException(
+						"could not instantiate image renderer class "
+								+ imageRendererClassName + " : "
+								+ e.getMessage(), e);
+			}
+		} catch (ClassNotFoundException e) {
+			throw new FacesException("image renderer class not found: "
+					+ e.getMessage(), e);
+		}
+		return imageRenderer;
+	}
+
+	/**
+	 * This method gets the image renderer from the ValueBinding.
+	 * @param facesContext
+	 * @param rendererValueBinding
+	 * @return the ImageRenderer.
+	 */
+	public static ImageRenderer getImageRendererFromValueBinding(
+			FacesContext facesContext, String rendererValueBinding) {
+		return (ImageRenderer) facesContext.getApplication()
+				.createValueBinding(rendererValueBinding).getValue(
+						facesContext);
+	}	
+	
+	
+	/**
+	 * This method is used for creating the image context.
+	 * @param facesContext
+	 * @return the imageContext.
+	 */
+    public static ImageContext createImageContext(FacesContext facesContext,
+			Log log) {
+
+		ExternalContext externalContext = facesContext.getExternalContext();
+		final Map requestMap = externalContext.getRequestParameterMap();
+		Object value = requestMap.get(GraphicImageDynamic.WIDTH_PARAM);
+		Integer height = null;
+		Integer width = null;
+
+		if (value != null) {
+			try {
+				width = Integer.valueOf(value.toString());
+			} catch (NumberFormatException e) {
+				log.error("Invalid value for image width : " + value + ", "
+						+ e.getMessage(), e);
+			}
+		}
+
+		value = requestMap.get(GraphicImageDynamic.HEIGHT_PARAM);
+		if (value != null) {
+			try {
+				height = Integer.valueOf(value.toString());
+			} catch (NumberFormatException e) {
+				log.error("Invalid value for image height : " + value + ", "
+						+ e.getMessage(), e);
+			}
+		}
+
+		return new SimpleImageContext(requestMap, width, height);
+	}
+}

Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/util/ImageContext.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/util/ImageContext.java?rev=643044&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/util/ImageContext.java
(added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/util/ImageContext.java
Mon Mar 31 09:15:42 2008
@@ -0,0 +1,49 @@
+/*
+ * 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.graphicimagedynamic.util;
+
+import org.apache.myfaces.custom.dynamicResources.ResourceContext;
+
+
+/**
+ * The ImageContext class holds additional objects and values which can be used 
+ * to determine which or how an image should be rendered. 
+ * 
+ * @author Mathias Broekelmann
+ * @version $Revision: 472727 $ $Date: 2006-11-09 03:08:46 +0200 (Thu, 09 Nov 2006) $
+ *
+ */
+public interface ImageContext extends ResourceContext
+{
+    
+    /**
+     * Returns the desired width of the image
+     * 
+     * @return null if no width is defined
+     */
+    Integer getWidth();
+
+    /**
+     * Returns the desired height of the image
+     * 
+     * @return null if no height is defined
+     */
+    Integer getHeight();
+}

Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/util/ImageRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/util/ImageRenderer.java?rev=643044&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/util/ImageRenderer.java
(added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/util/ImageRenderer.java
Mon Mar 31 09:15:42 2008
@@ -0,0 +1,50 @@
+/*
+ * 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.graphicimagedynamic.util;
+
+import org.apache.myfaces.custom.dynamicResources.ResourceRenderer;
+
+/**
+ * The ImageRenderer is used to render the binary data for a html img tag
+ * Implementions must have a default constructor
+ * 
+ * @author Mathias Broekelmann
+ * @version $Revision: 472727 $ $Date: 2006-11-09 03:08:46 +0200 (Thu, 09 Nov 2006) $
+ */
+public interface ImageRenderer extends ResourceRenderer
+{
+	/**
+	 * This method will be called first, to set the contexts.
+	 * 
+     * @param facesContext the faces context
+     * @param imageContext the image context width aditional image parameters
+	 *
+	void setContext(FacesContext facesContext, ImageContext imageContext) throws Exception;
+	*/
+    /**
+     * Called to render the image to the given outputstream.
+     * 
+     * @param out the outputstream which is used to write the binary data of the image
+     *  
+     * @throws IOException
+     *
+    void renderImage(ResponseStream out) throws IOException;
+    */
+}

Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/util/ImageResponseStream.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/util/ImageResponseStream.java?rev=643044&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/util/ImageResponseStream.java
(added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/util/ImageResponseStream.java
Mon Mar 31 09:15:42 2008
@@ -0,0 +1,58 @@
+/*
+ * 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.graphicimagedynamic.util;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import javax.faces.context.ResponseStream;
+
+/**
+ * This class is responsible for wrapping the
+ * ImageResponseStream.
+ */
+public class ImageResponseStream extends ResponseStream {
+
+	private final OutputStream _out;
+
+	public ImageResponseStream(OutputStream out) {
+		_out = out;
+	}
+
+	public void close() throws IOException {
+		_out.flush();
+		_out.close();
+	}
+
+	public void flush() throws IOException {
+		_out.flush();
+	}
+
+	public void write(byte[] b, int off, int len) throws IOException {
+		_out.write(b, off, len);
+	}
+
+	public void write(byte[] b) throws IOException {
+		_out.write(b);
+	}
+
+	public void write(int b) throws IOException {
+		_out.write(b);
+	}
+}

Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/util/SimpleImageContext.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/util/SimpleImageContext.java?rev=643044&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/util/SimpleImageContext.java
(added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/util/SimpleImageContext.java
Mon Mar 31 09:15:42 2008
@@ -0,0 +1,48 @@
+/*
+ * 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.graphicimagedynamic.util;
+
+import java.util.Map;
+
+public class SimpleImageContext implements ImageContext {
+	
+	private final Map _params;
+	private final Integer _width;
+	private final Integer _height;
+
+	public SimpleImageContext(Map params, Integer width, Integer height) {
+		_params = params;
+		_width = width;
+		_height = height;
+	}
+
+	public Map getParamters() {
+		return _params;
+	}
+
+	public Integer getWidth() {
+		return _width;
+	}
+
+	public Integer getHeight() {
+		return _height;
+	}
+}
+

Modified: myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/graphicImageDynamic/GraphicImageDynamicTextBean.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/graphicImageDynamic/GraphicImageDynamicTextBean.java?rev=643044&r1=643043&r2=643044&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/graphicImageDynamic/GraphicImageDynamicTextBean.java
(original)
+++ myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/graphicImageDynamic/GraphicImageDynamicTextBean.java
Mon Mar 31 09:15:42 2008
@@ -28,8 +28,8 @@
 import javax.faces.context.ResponseStream;
 
 import org.apache.myfaces.custom.dynamicResources.ResourceContext;
-import org.apache.myfaces.custom.graphicimagedynamic.ImageContext;
-import org.apache.myfaces.custom.graphicimagedynamic.ImageRenderer;
+import org.apache.myfaces.custom.graphicimagedynamic.util.ImageContext;
+import org.apache.myfaces.custom.graphicimagedynamic.util.ImageRenderer;
 
 import com.sun.image.codec.jpeg.JPEGCodec;
 import com.sun.image.codec.jpeg.JPEGImageEncoder;
@@ -115,7 +115,7 @@
     }
 
     /**
-     * @see org.apache.myfaces.custom.graphicimagedynamic.ImageRenderer#renderImage(javax.faces.context.FacesContext,
org.apache.myfaces.custom.graphicimagedynamic.ImageContext, java.io.OutputStream)
+     * @see org.apache.myfaces.custom.graphicimagedynamic.ImageRenderer#renderResource(javax.faces.context.ResponseStream)

      */
     public void renderResource(ResponseStream out)
             throws IOException

Modified: myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/graphicImageDynamic/UploadedImageRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/graphicImageDynamic/UploadedImageRenderer.java?rev=643044&r1=643043&r2=643044&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/graphicImageDynamic/UploadedImageRenderer.java
(original)
+++ myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/graphicImageDynamic/UploadedImageRenderer.java
Mon Mar 31 09:15:42 2008
@@ -26,7 +26,7 @@
 import javax.faces.el.ValueBinding;
 
 import org.apache.myfaces.custom.dynamicResources.ResourceContext;
-import org.apache.myfaces.custom.graphicimagedynamic.ImageRenderer;
+import org.apache.myfaces.custom.graphicimagedynamic.util.ImageRenderer;
 
 /**
  * @author Mathias Broekelmann
@@ -65,7 +65,7 @@
     }
 
     /**
-     * @see org.apache.myfaces.custom.graphicimagedynamic.ImageRenderer#renderImage(javax.faces.context.FacesContext,
org.apache.myfaces.custom.graphicimagedynamic.ImageContext, java.io.OutputStream)
+     * @see org.apache.myfaces.custom.graphicimagedynamic.ImageRenderer#renderResource(javax.faces.context.ResponseStream)

      */
     public void renderResource(ResponseStream out)
             throws IOException



Mime
View raw message