You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sv...@apache.org on 2006/02/17 03:08:15 UTC
svn commit: r378411 - in /myfaces/tomahawk/trunk/sandbox:
core/src/main/java/org/apache/myfaces/custom/dynamicResources/
core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/
core/src/main/java/org/apache/myfaces/custom/outputlinkdynamic/ c...
Author: svieujot
Date: Thu Feb 16 18:08:12 2006
New Revision: 378411
URL: http://svn.apache.org/viewcvs?rev=378411&view=rev
Log:
Add outputLinkDynamic component and refactor graphicImageDynamic to allow shared renderers.
Added:
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dynamicResources/
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dynamicResources/ResourceContext.java (with props)
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dynamicResources/ResourceRenderer.java (with props)
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dynamicResources/SimpleResourceContext.java (with props)
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/outputlinkdynamic/
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/outputlinkdynamic/OutputLinkDynamic.java (with props)
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/outputlinkdynamic/OutputLinkDynamicRenderer.java (with props)
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/outputlinkdynamic/OutputLinkDynamicTag.java (with props)
myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/outputLinkDynamic/
myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/outputLinkDynamic/OutputLinkDynamicBean.java (with props)
myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/outputLinkDynamic/UploadedFileRenderer.java (with props)
myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/outputLinkDynamic.jsp (with props)
Modified:
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/ImageContext.java
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/ImageRenderer.java
myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml
myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld
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
myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/WEB-INF/examples-config.xml
myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/home.jsp
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dynamicResources/ResourceContext.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dynamicResources/ResourceContext.java?rev=378411&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dynamicResources/ResourceContext.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dynamicResources/ResourceContext.java Thu Feb 16 18:08:12 2006
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.dynamicResources;
+
+import java.util.Map;
+
+
+/**
+ * The ResourceContext class holds additional objects and values which can be used
+ * to determine which or how a resource should be rendered.
+ *
+ * @author Sylvain Vieujot
+ * @version $Revision$ $Date$
+ *
+ */
+public interface ResourceContext
+{
+ /**
+ * Returns a map with the values of the used parameters
+ *
+ * @return not null, Map contains instances of String for keys and values
+ */
+ Map getParamters();
+}
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dynamicResources/ResourceContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dynamicResources/ResourceContext.java
------------------------------------------------------------------------------
svn:keywords = LastChangedDate LastChangedBy LastChangedRevision Author Id
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dynamicResources/ResourceContext.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dynamicResources/ResourceRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dynamicResources/ResourceRenderer.java?rev=378411&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dynamicResources/ResourceRenderer.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dynamicResources/ResourceRenderer.java Thu Feb 16 18:08:12 2006
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.dynamicResources;
+
+import java.io.IOException;
+
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseStream;
+
+/**
+ * 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$ $Date$
+ */
+public interface 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, ResourceContext resourceContext) throws Exception;
+
+ /**
+ * The content length of the image to render.
+ * Set to a negative value if you don't want to set the response content length.
+ *
+ * @return the content length of the rendered image
+ */
+ int getContentLength();
+
+ /**
+ * The MimeType of the image. This is usally a value of
+ * image/jpeg, image/gif, image/png or anything else which can be
+ * used as an image for html
+ *
+ * @return the Mime-Type, not null
+ */
+ String getContentType();
+
+ /**
+ * 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 renderResource(ResponseStream out) throws IOException;
+}
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dynamicResources/ResourceRenderer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dynamicResources/ResourceRenderer.java
------------------------------------------------------------------------------
svn:keywords = LastChangedDate LastChangedBy LastChangedRevision Author Id
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dynamicResources/ResourceRenderer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dynamicResources/SimpleResourceContext.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dynamicResources/SimpleResourceContext.java?rev=378411&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dynamicResources/SimpleResourceContext.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dynamicResources/SimpleResourceContext.java Thu Feb 16 18:08:12 2006
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.dynamicResources;
+
+import java.util.Map;
+
+
+/**
+ * @author Sylvain Vieujot
+ * @version $Revision$ $Date$
+ *
+ */
+public class SimpleResourceContext implements ResourceContext
+{
+
+ private final Map _params;
+
+ public SimpleResourceContext(Map params)
+ {
+ _params = params;
+ }
+
+ public Map getParamters()
+ {
+ return _params;
+ }
+}
\ No newline at end of file
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dynamicResources/SimpleResourceContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dynamicResources/SimpleResourceContext.java
------------------------------------------------------------------------------
svn:keywords = LastChangedDate LastChangedBy LastChangedRevision Author Id
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/dynamicResources/SimpleResourceContext.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/GraphicImageDynamicRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/GraphicImageDynamicRenderer.java?rev=378411&r1=378410&r2=378411&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 Thu Feb 16 18:08:12 2006
@@ -283,7 +283,7 @@
ResponseStream out = facesContext.getResponseStream();
try
{
- imageRenderer.renderImage( out );
+ imageRenderer.renderResource( out );
}
finally
{
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/ImageContext.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/ImageContext.java?rev=378411&r1=378410&r2=378411&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/ImageContext.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/ImageContext.java Thu Feb 16 18:08:12 2006
@@ -15,25 +15,19 @@
*/
package org.apache.myfaces.custom.graphicimagedynamic;
-import java.util.Map;
+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 rendererd.
+ * to determine which or how an image should be rendered.
*
* @author Mathias Broekelmann
* @version $Revision$ $Date$
*
*/
-public interface ImageContext
+public interface ImageContext extends ResourceContext
{
- /**
- * Returns a map with the values of the used parameters
- *
- * @return not null, Map contains instances of String for keys and values
- */
- Map getParamters();
/**
* Returns the desired width of the image
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/ImageRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/ImageRenderer.java?rev=378411&r1=378410&r2=378411&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/ImageRenderer.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/graphicimagedynamic/ImageRenderer.java Thu Feb 16 18:08:12 2006
@@ -20,6 +20,8 @@
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseStream;
+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
@@ -27,39 +29,23 @@
* @author Mathias Broekelmann
* @version $Revision$ $Date$
*/
-public interface ImageRenderer
+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;
-
- /**
- * The content length of the image to render.
- * Set to a negative value if you don't want to set the response content length.
- *
- * @return the content length of the rendered image
- */
- int getContentLength();
-
- /**
- * The MimeType of the image. This is usally a value of
- * image/jpeg, image/gif, image/png or anything else which can be
- * used as an image for html
- *
- * @return the Mime-Type, not null
- */
- String getContentType();
-
+ */
/**
* 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/outputlinkdynamic/OutputLinkDynamic.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/outputlinkdynamic/OutputLinkDynamic.java?rev=378411&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/outputlinkdynamic/OutputLinkDynamic.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/outputlinkdynamic/OutputLinkDynamic.java Thu Feb 16 18:08:12 2006
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.outputlinkdynamic;
+
+import javax.faces.component.html.HtmlOutputLink;
+import javax.faces.context.FacesContext;
+import javax.faces.el.EvaluationException;
+import javax.faces.el.ValueBinding;
+
+import org.apache.myfaces.custom.dynamicResources.ResourceRenderer;
+import org.apache.myfaces.util.ClassUtils;
+
+/**
+ * @author Sylvain Vieujot (latest modification by $Author$)
+ *
+ * @version $Revision$ $Date$
+ *
+ * Warning, this component is far from ready.
+ * It's more a proof of concept right now.
+ * TODO : Remove the need to include .get for the last part of the method expressions : getBytesMethod="#{graphicImageDynamicBean.upImage.getBytes}"
+ * TODO : Make a similar download component to download files
+ * TODO : Use shorter URLs
+ */
+
+public class OutputLinkDynamic extends HtmlOutputLink
+{
+ private static final String DEFAULT_RENDERER_TYPE = OutputLinkDynamicRenderer.RENDERER_TYPE;
+
+ public OutputLinkDynamic()
+ {
+ setRendererType(DEFAULT_RENDERER_TYPE);
+ }
+
+ private Class _resourceRendererClass;
+
+ public Object saveState(FacesContext context)
+ {
+ Object[] values = new Object[2];
+ values[0] = super.saveState(context);
+ values[1] = _resourceRendererClass;
+ return values;
+ }
+
+ public void restoreState(FacesContext context, Object state)
+ {
+ Object values[] = (Object[]) state;
+ super.restoreState(context, values[0]);
+ _resourceRendererClass = (Class) values[1];
+ }
+
+ public void setImageRendererClass(Class resourceRendererClass)
+ {
+ if (resourceRendererClass != null && !ResourceRenderer.class.isAssignableFrom(resourceRendererClass))
+ {
+ throw new IllegalArgumentException(
+ "resourceRendererClass must be null or a class which implements "
+ + ResourceRenderer.class.getName());
+ }
+ _resourceRendererClass = resourceRendererClass;
+ }
+
+ public Class getResourceRendererClass()
+ {
+ if (_resourceRendererClass != null)
+ {
+ return _resourceRendererClass;
+ }
+ ValueBinding vb = getValueBinding("resourceRendererClass");
+ if (vb != null)
+ {
+ Object value = vb.getValue(getFacesContext());
+ if (value == null)
+ {
+ return null;
+ }
+ Class clazz;
+ if (value instanceof Class)
+ {
+ clazz = (Class) value;
+ }
+ else
+ {
+ try
+ {
+ clazz = ClassUtils.classForName(value.toString());
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new EvaluationException("Could not load resourceRendererClass for "
+ + vb.getExpressionString(), e);
+ }
+ }
+ if (!ResourceRenderer.class.isAssignableFrom(clazz))
+ {
+ throw new EvaluationException("Expected value for " + vb.getExpressionString()
+ + " must be one of null, a fully qualified class name or "
+ + "an instance of a class which implements "
+ + ResourceRenderer.class.getName());
+ }
+ return clazz;
+ }
+ return null;
+ }
+}
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/outputlinkdynamic/OutputLinkDynamic.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/outputlinkdynamic/OutputLinkDynamic.java
------------------------------------------------------------------------------
svn:keywords = LastChangedDate LastChangedBy LastChangedRevision Author Id
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/outputlinkdynamic/OutputLinkDynamic.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/outputlinkdynamic/OutputLinkDynamicRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/outputlinkdynamic/OutputLinkDynamicRenderer.java?rev=378411&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/outputlinkdynamic/OutputLinkDynamicRenderer.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/outputlinkdynamic/OutputLinkDynamicRenderer.java Thu Feb 16 18:08:12 2006
@@ -0,0 +1,271 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.outputlinkdynamic;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.Iterator;
+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;
+import javax.faces.context.ResponseWriter;
+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 org.apache.myfaces.component.html.util.ParameterResourceHandler;
+import org.apache.myfaces.custom.dynamicResources.ResourceContext;
+import org.apache.myfaces.custom.dynamicResources.ResourceRenderer;
+import org.apache.myfaces.custom.dynamicResources.SimpleResourceContext;
+import org.apache.myfaces.renderkit.RendererUtils;
+import org.apache.myfaces.renderkit.html.HTML;
+import org.apache.myfaces.renderkit.html.HtmlRendererUtils;
+import org.apache.myfaces.renderkit.html.ext.HtmlLinkRenderer;
+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.util.ClassUtils;
+
+/**
+ * @author Sylvain Vieujot
+ * @version $Revision$ $Date$
+ */
+public class OutputLinkDynamicRenderer extends HtmlLinkRenderer implements ResourceLoader
+{
+ public static final String RENDERER_TYPE = "org.apache.myfaces.OutputLinkDynamicRenderer";
+
+ private static final class ResourceResponseStream extends ResponseStream
+ {
+ private final OutputStream _out;
+
+ private ResourceResponseStream(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";
+
+ public void encodeBegin(FacesContext context, UIComponent component) throws IOException
+ {
+ RendererUtils.checkParamValidity(context, component, OutputLinkDynamic.class);
+
+ OutputLinkDynamic outputLinkDynamic = (OutputLinkDynamic) component;
+ ResponseWriter writer = context.getResponseWriter();
+
+ writer.startElement(HTML.ANCHOR_ELEM, outputLinkDynamic);
+ HtmlRendererUtils.writeIdIfNecessary(writer, outputLinkDynamic, context);
+ HtmlRendererUtils.renderHTMLAttributes(writer, outputLinkDynamic,
+ HTML.ANCHOR_PASSTHROUGH_ATTRIBUTES);
+
+ Map params = getParameterMap(context, component);
+
+ Class resourceRendererClass = outputLinkDynamic.getResourceRendererClass();
+ if (resourceRendererClass == null)
+ {
+ throw new FacesException("No resourceRendererClass defined for component "
+ + component.getId());
+ }
+ params.put(RENDERER_PARAM, resourceRendererClass.getName());
+
+ AddResource addResource = AddResourceFactory.getInstance(context);
+ String url = addResource.getResourceUri(context, new ParameterResourceHandler(this
+ .getClass(), params));
+ writer.writeAttribute(HTML.HREF_ATTR, url, null);
+ }
+
+ public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException
+ {
+ ResponseWriter writer = facesContext.getResponseWriter();
+ // force separate end tag
+ writer.writeText("", null);
+ writer.endElement(HTML.ANCHOR_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);
+ }
+
+ /**
+ * @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 ResourceResponseStream(response.getOutputStream()));
+ try
+ {
+ Map requestMap = facesContext.getExternalContext().getRequestParameterMap();
+ Object rendererValue = requestMap.get(RENDERER_PARAM);
+ if (rendererValue == null)
+ {
+ throw new FacesException("no image renderer defined.");
+ }
+ try
+ {
+ Class rendererClass = ClassUtils.classForName(rendererValue.toString());
+ if (!ResourceRenderer.class.isAssignableFrom(rendererClass))
+ {
+ throw new FacesException("Resource renderer class [" + rendererValue
+ + "] does not implement " + ResourceRenderer.class.getName());
+ }
+ try
+ {
+ ResourceRenderer resourceRenderer = (ResourceRenderer) rendererClass.newInstance();
+ renderResource(resourceRenderer, facesContext);
+ }
+ catch (InstantiationException e)
+ {
+ throw new FacesException("could not instantiate resource renderer class "
+ + rendererValue + " : " + e.getMessage(), e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new FacesException("could not instantiate resource renderer class "
+ + rendererValue + " : " + e.getMessage(), e);
+ }
+ catch (Exception e)
+ {
+ throw new FacesException("could not renderer image "
+ + rendererValue + " : " + e.getMessage(), e);
+ }
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new FacesException("image renderer class not found: " + e.getMessage(), e);
+ }
+ facesContext.getResponseStream().close();
+ }
+ finally
+ {
+ facesContext.release();
+ }
+ }
+
+ protected void renderResource(ResourceRenderer resourceRenderer, FacesContext facesContext)
+ throws Exception
+ {
+ ResourceContext resourceContext = createResourceContext(facesContext);
+
+ resourceRenderer.setContext(facesContext, resourceContext);
+
+ HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext()
+ .getResponse();
+
+
+ int contentLength = resourceRenderer.getContentLength();
+ if( contentLength >0 )
+ {
+ response.setContentLength(contentLength);
+ }
+
+ String contentType = resourceRenderer.getContentType();
+ if (contentType != null && contentType.length() > 0 )
+ {
+ response.setContentType(contentType);
+ }
+
+ ResponseStream out = facesContext.getResponseStream();
+ try
+ {
+ resourceRenderer.renderResource( out );
+ }
+ finally
+ {
+ out.close();
+ facesContext.responseComplete();
+ }
+ }
+
+ protected ResourceContext createResourceContext(FacesContext facesContext)
+ {
+ ExternalContext externalContext = facesContext.getExternalContext();
+ final Map requestMap = externalContext.getRequestParameterMap();
+ return new SimpleResourceContext(requestMap);
+ }
+
+ private String getLifecycleId(ServletContext context)
+ {
+ String lifecycleId = context.getInitParameter(FacesServlet.LIFECYCLE_ID_ATTR);
+ return lifecycleId != null ? lifecycleId : LifecycleFactory.DEFAULT_LIFECYCLE;
+ }
+}
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/outputlinkdynamic/OutputLinkDynamicRenderer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/outputlinkdynamic/OutputLinkDynamicRenderer.java
------------------------------------------------------------------------------
svn:keywords = LastChangedDate LastChangedBy LastChangedRevision Author Id
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/outputlinkdynamic/OutputLinkDynamicRenderer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/outputlinkdynamic/OutputLinkDynamicTag.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/outputlinkdynamic/OutputLinkDynamicTag.java?rev=378411&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/outputlinkdynamic/OutputLinkDynamicTag.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/outputlinkdynamic/OutputLinkDynamicTag.java Thu Feb 16 18:08:12 2006
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.outputlinkdynamic;
+
+import javax.faces.component.UIComponent;
+
+import org.apache.myfaces.taglib.html.HtmlOutputLinkTag;
+
+/**
+ * @author Sylvain Vieujot, Mathias Brökelmann
+ * @version $Revision$ $Date$
+ */
+
+public class OutputLinkDynamicTag extends HtmlOutputLinkTag
+{
+ private String _resourceRendererClass;
+
+ public String getComponentType()
+ {
+ return "org.apache.myfaces.OutputLinkDynamic";
+ }
+
+ public String getRendererType()
+ {
+ return OutputLinkDynamicRenderer.RENDERER_TYPE;
+ }
+
+ public void release()
+ {
+ super.release();
+ _resourceRendererClass = null;
+ }
+
+ protected void setProperties(UIComponent component)
+ {
+ super.setProperties(component);
+
+ setStringProperty(component, "resourceRendererClass", _resourceRendererClass);
+ }
+
+ public void setResourceRendererClass(String resourceRendererClass)
+ {
+ _resourceRendererClass = resourceRendererClass;
+ }
+}
\ No newline at end of file
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/outputlinkdynamic/OutputLinkDynamicTag.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/outputlinkdynamic/OutputLinkDynamicTag.java
------------------------------------------------------------------------------
svn:keywords = LastChangedDate LastChangedBy LastChangedRevision Author Id
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/outputlinkdynamic/OutputLinkDynamicTag.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml?rev=378411&r1=378410&r2=378411&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml Thu Feb 16 18:08:12 2006
@@ -59,10 +59,10 @@
<component-class>org.apache.myfaces.custom.schedule.HtmlSchedule</component-class>
</component>
- <component>
- <component-type>org.apache.myfaces.Script</component-type>
- <component-class>org.apache.myfaces.custom.script.Script</component-class>
- </component>
+ <component>
+ <component-type>org.apache.myfaces.Script</component-type>
+ <component-class>org.apache.myfaces.custom.script.Script</component-class>
+ </component>
<component>
@@ -93,6 +93,11 @@
<component>
<component-type>org.apache.myfaces.GraphicImageDynamic</component-type>
<component-class>org.apache.myfaces.custom.graphicimagedynamic.GraphicImageDynamic</component-class>
+ </component>
+
+ <component>
+ <component-type>org.apache.myfaces.OutputLinkDynamic</component-type>
+ <component-class>org.apache.myfaces.custom.outputlinkdynamic.OutputLinkDynamic</component-class>
</component>
<component>
@@ -250,6 +255,12 @@
<component-family>javax.faces.Graphic</component-family>
<renderer-type>org.apache.myfaces.GraphicImageDynamicRenderer</renderer-type>
<renderer-class>org.apache.myfaces.custom.graphicimagedynamic.GraphicImageDynamicRenderer</renderer-class>
+ </renderer>
+
+ <renderer>
+ <component-family>javax.faces.Output</component-family>
+ <renderer-type>org.apache.myfaces.OutputLinkDynamicRenderer</renderer-type>
+ <renderer-class>org.apache.myfaces.custom.outputlinkdynamic.OutputLinkDynamicRenderer</renderer-class>
</renderer>
<renderer>
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld?rev=378411&r1=378410&r2=378411&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld Thu Feb 16 18:08:12 2006
@@ -561,7 +561,7 @@
</attribute>
</tag>
- <!-- graphicImage -->
+ <!-- graphicImageDynamic -->
<tag>
<name>graphicImageDynamic</name>
<tag-class>org.apache.myfaces.custom.graphicimagedynamic.GraphicImageDynamicTag</tag-class>
@@ -582,7 +582,38 @@
<type>java.lang.String</type>
<description>
The class which implements org.apache.myfaces.custom.graphicimagedynamic.ImageRenderer. The image renderer is responsible for loading the image. The class must have a default constructor. Any request scoped attribute or managed bean is not
- available when this image renderer is instantiated and used. The image renderer must render the binary data for the image by using the parameters passed by nested f:param elements and/or using session or application scoped beans
+ available when this image renderer is instantiated and used. The image renderer must render the binary data for the image by using the parameters passed by nested f:param elements and/or using session or application scoped beans.
+ </description>
+ </attribute>
+
+ </tag>
+
+ <!-- outputLinkDynamic -->
+ <tag>
+ <name>outputLinkDynamic</name>
+ <tag-class>org.apache.myfaces.custom.outputlinkdynamic.OutputLinkDynamicTag</tag-class>
+ <body-content>JSP</body-content>
+ <description>Extends standard outputLink but links to a dynamically rendered resource (image, file, ...).</description>
+ &ui_output_attributes;
+ &html_universal_attributes;
+ &html_event_handler_attributes;
+ &html_anchor_attributes;
+ &user_role_attributes;
+ &ext_forceId_attribute;
+
+ <attribute>
+ <name>resourceRendererClass</name>
+ <required>true</required>
+ <rtexprvalue>false</rtexprvalue>
+ <type>java.lang.String</type>
+ <description>
+ The class which implements org.apache.myfaces.custom.dynamicResources.ResourceRenderer.
+ The resource renderer is responsible for resource the image.
+ The class must have a default constructor.
+ Any request scoped attribute or managed bean is not available when this resource renderer
+ is instantiated and used.
+ The resource renderer must render the binary data for the resource by using the parameters
+ passed by nested f:param elements and/or using session or application scoped beans.
</description>
</attribute>
Modified: myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/graphicImageDynamic/GraphicImageDynamicTextBean.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/graphicImageDynamic/GraphicImageDynamicTextBean.java?rev=378411&r1=378410&r2=378411&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 Thu Feb 16 18:08:12 2006
@@ -24,6 +24,7 @@
import javax.faces.context.FacesContext;
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;
@@ -48,8 +49,9 @@
this._text = text;
}
- public void setContext(FacesContext facesContext, ImageContext imageContext) throws IOException
+ public void setContext(FacesContext facesContext, ResourceContext resourceContext) throws IOException
{
+ ImageContext imageContext = (ImageContext) resourceContext;
Object text = imageContext.getParamters().get("text");
if (text == null)
{
@@ -112,7 +114,7 @@
/**
* @see org.apache.myfaces.custom.graphicimagedynamic.ImageRenderer#renderImage(javax.faces.context.FacesContext, org.apache.myfaces.custom.graphicimagedynamic.ImageContext, java.io.OutputStream)
*/
- public void renderImage(ResponseStream out)
+ public void renderResource(ResponseStream out)
throws IOException
{
out.write( bytes );
Modified: myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/graphicImageDynamic/UploadedImageRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/graphicImageDynamic/UploadedImageRenderer.java?rev=378411&r1=378410&r2=378411&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 Thu Feb 16 18:08:12 2006
@@ -22,7 +22,7 @@
import javax.faces.context.ResponseStream;
import javax.faces.el.ValueBinding;
-import org.apache.myfaces.custom.graphicimagedynamic.ImageContext;
+import org.apache.myfaces.custom.dynamicResources.ResourceContext;
import org.apache.myfaces.custom.graphicimagedynamic.ImageRenderer;
/**
@@ -33,7 +33,7 @@
{
private GraphicImageDynamicBean _graphicImageDynamicBean;
- public void setContext(FacesContext facesContext, ImageContext imageContext) throws IOException
+ public void setContext(FacesContext facesContext, ResourceContext imageContext) throws IOException
{
ValueBinding vb = facesContext.getApplication().createValueBinding(
"#{graphicImageDynamicBean}");
@@ -64,7 +64,7 @@
/**
* @see org.apache.myfaces.custom.graphicimagedynamic.ImageRenderer#renderImage(javax.faces.context.FacesContext, org.apache.myfaces.custom.graphicimagedynamic.ImageContext, java.io.OutputStream)
*/
- public void renderImage(ResponseStream out)
+ public void renderResource(ResponseStream out)
throws IOException
{
if (_graphicImageDynamicBean.isUploaded())
Added: myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/outputLinkDynamic/OutputLinkDynamicBean.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/outputLinkDynamic/OutputLinkDynamicBean.java?rev=378411&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/outputLinkDynamic/OutputLinkDynamicBean.java (added)
+++ myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/outputLinkDynamic/OutputLinkDynamicBean.java Thu Feb 16 18:08:12 2006
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.examples.outputLinkDynamic;
+
+import org.apache.myfaces.custom.fileupload.UploadedFile;
+
+/**
+ * @author Sylvain Vieujot (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class OutputLinkDynamicBean
+{
+ private UploadedFile _upFile;
+
+
+ public UploadedFile getUpFile()
+ {
+ return _upFile;
+ }
+
+ public void setUpFile(UploadedFile upFile)
+ {
+ this._upFile = upFile;
+ }
+
+ public boolean isUploaded()
+ {
+ return _upFile != null;
+ }
+
+ public Class getResourceRenderer()
+ {
+ return UploadedFileRenderer.class;
+ }
+}
\ No newline at end of file
Propchange: myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/outputLinkDynamic/OutputLinkDynamicBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/outputLinkDynamic/OutputLinkDynamicBean.java
------------------------------------------------------------------------------
svn:keywords = LastChangedDate LastChangedBy LastChangedRevision Author Id
Propchange: myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/outputLinkDynamic/OutputLinkDynamicBean.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/outputLinkDynamic/UploadedFileRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/outputLinkDynamic/UploadedFileRenderer.java?rev=378411&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/outputLinkDynamic/UploadedFileRenderer.java (added)
+++ myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/outputLinkDynamic/UploadedFileRenderer.java Thu Feb 16 18:08:12 2006
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.examples.outputLinkDynamic;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseStream;
+import javax.faces.el.ValueBinding;
+
+import org.apache.myfaces.custom.dynamicResources.ResourceContext;
+import org.apache.myfaces.custom.dynamicResources.ResourceRenderer;
+
+/**
+ * @author Mathias Broekelmann, Sylvain Vieujot
+ *
+ */
+public class UploadedFileRenderer implements ResourceRenderer
+{
+ private OutputLinkDynamicBean _outputLinkDynamicBean;
+
+ public void setContext(FacesContext facesContext, ResourceContext resourceContext)
+ {
+ ValueBinding vb = facesContext.getApplication().createValueBinding(
+ "#{outputLinkDynamicBean}");
+ OutputLinkDynamicBean value = (OutputLinkDynamicBean) vb.getValue(facesContext);
+ if (value == null)
+ {
+ throw new IllegalStateException("managed bean outputLinkDynamicBean not found");
+ }
+ _outputLinkDynamicBean = value;
+ }
+
+ /**
+ * @see org.apache.myfaces.custom.graphicimagedynamic.ImageRenderer#getContentLength()
+ */
+ public int getContentLength() {
+ return _outputLinkDynamicBean.isUploaded() ? (int)_outputLinkDynamicBean.getUpFile().getSize() : -1;
+ }
+
+ /**
+ * @see org.apache.myfaces.custom.graphicimagedynamic.ImageRenderer#getContentType()
+ */
+ public String getContentType()
+ {
+ return _outputLinkDynamicBean.isUploaded() ? _outputLinkDynamicBean.getUpFile()
+ .getContentType() : null;
+ }
+
+ /**
+ * @see org.apache.myfaces.custom.graphicimagedynamic.ImageRenderer#renderImage(javax.faces.context.FacesContext, org.apache.myfaces.custom.graphicimagedynamic.ImageContext, java.io.OutputStream)
+ */
+ public void renderResource(ResponseStream out)
+ throws IOException
+ {
+ if (_outputLinkDynamicBean.isUploaded())
+ {
+ InputStream is = _outputLinkDynamicBean.getUpFile().getInputStream();
+ try
+ {
+ byte[] buffer = new byte[1024];
+ int len = is.read(buffer);
+ while (len != -1)
+ {
+ out.write(buffer, 0, len);
+ len = is.read(buffer);
+ }
+ }
+ finally
+ {
+ is.close();
+ }
+ }
+ }
+}
Propchange: myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/outputLinkDynamic/UploadedFileRenderer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/outputLinkDynamic/UploadedFileRenderer.java
------------------------------------------------------------------------------
svn:keywords = LastChangedDate LastChangedBy LastChangedRevision Author Id
Propchange: myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/outputLinkDynamic/UploadedFileRenderer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/WEB-INF/examples-config.xml
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/WEB-INF/examples-config.xml?rev=378411&r1=378410&r2=378411&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/WEB-INF/examples-config.xml (original)
+++ myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/WEB-INF/examples-config.xml Thu Feb 16 18:08:12 2006
@@ -415,18 +415,26 @@
</managed-bean>
-<!-- managed bean for graphicImageAjax-->
-
- <managed-bean>
- <managed-bean-name>graphicImageDynamicBean</managed-bean-name>
- <managed-bean-class>org.apache.myfaces.examples.graphicImageDynamic.GraphicImageDynamicBean</managed-bean-class>
- <managed-bean-scope>application</managed-bean-scope>
- </managed-bean>
+ <!-- managed bean for graphicImageDynamic -->
<managed-bean>
+ <managed-bean-name>graphicImageDynamicBean</managed-bean-name>
+ <managed-bean-class>org.apache.myfaces.examples.graphicImageDynamic.GraphicImageDynamicBean</managed-bean-class>
+ <managed-bean-scope>application</managed-bean-scope>
+ </managed-bean>
+
+ <managed-bean>
<managed-bean-name>graphicImageDynamicTextBean</managed-bean-name>
<managed-bean-class>org.apache.myfaces.examples.graphicImageDynamic.GraphicImageDynamicTextBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
+ </managed-bean>
+
+ <!-- managed bean for outputLinkDynamic -->
+
+ <managed-bean>
+ <managed-bean-name>outputLinkDynamicBean</managed-bean-name>
+ <managed-bean-class>org.apache.myfaces.examples.outputLinkDynamic.OutputLinkDynamicBean</managed-bean-class>
+ <managed-bean-scope>application</managed-bean-scope>
</managed-bean>
<!-- manage bean for the selectManyPicklist component -->
Modified: myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/home.jsp
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/home.jsp?rev=378411&r1=378410&r2=378411&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/home.jsp (original)
+++ myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/home.jsp Thu Feb 16 18:08:12 2006
@@ -32,7 +32,8 @@
<h:outputLink value="accordionPanel.jsf" ><f:verbatim>AccordionPanel</f:verbatim></h:outputLink>
<h:outputLink value="validateUrl.jsf" ><f:verbatim>Validation example 2 - including URL validator</f:verbatim></h:outputLink>
<h:outputLink value="graphicImageDynamic.jsf" ><f:verbatim>GraphicImageDynamic - graphic image without a dedicated servlet</f:verbatim></h:outputLink>
- <h:outputLink value="graphicImageDynamicText.jsf" ><f:verbatim>GraphicImageDynamic - text rendered as graphic image</f:verbatim></h:outputLink>
+ <h:outputLink value="graphicImageDynamicText.jsf" ><f:verbatim>GraphicImageDynamic - text rendered as graphic image</f:verbatim></h:outputLink>
+ <h:outputLink value="outputLinkDynamic.jsf" ><f:verbatim>OutputLinkDynamic - resource serving from a link without a dedicated servlet</f:verbatim></h:outputLink>
<h:outputLink value="effect.jsf" ><f:verbatim>Effect - FAT and script.aculo.us effects</f:verbatim></h:outputLink>
<h:commandLink action="go_scope_shop"><f:verbatim>Scope - saveState without serialisation</f:verbatim></h:commandLink>
<h:outputLink value="picklist.jsf"><f:verbatim>selectManyPicklist - a picklist</f:verbatim></h:outputLink>
Added: myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/outputLinkDynamic.jsp
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/outputLinkDynamic.jsp?rev=378411&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/outputLinkDynamic.jsp (added)
+++ myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/outputLinkDynamic.jsp Thu Feb 16 18:08:12 2006
@@ -0,0 +1,52 @@
+<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
+<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
+<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
+<%@ taglib uri="http://myfaces.apache.org/sandbox" prefix="s"%>
+
+<!--
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+//-->
+<html>
+
+ <%@include file="inc/head.inc" %>
+
+<body>
+ <f:view>
+ <h:form enctype="multipart/form-data">
+ <br/>
+ Upload a file :
+ <t:inputFileUpload id="fileupload"
+ value="#{outputLinkDynamicBean.upFile}"/>
+
+ <br/>
+
+ <s:outputLinkDynamic
+ rendered="#{outputLinkDynamicBean.uploaded}"
+ resourceRendererClass="#{outputLinkDynamicBean.resourceRenderer}">
+ <h:outputText value="Click here to get it ..."/>
+ </s:outputLinkDynamic>
+
+ <br/>
+ <t:messages showDetail="true"/>
+ <h:commandButton value="Update"/>
+ </h:form>
+ </f:view>
+</body>
+
+<%@include file="inc/page_footer.jsp" %>
+
+</html>
\ No newline at end of file
Propchange: myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/outputLinkDynamic.jsp
------------------------------------------------------------------------------
svn:keywords = LastChangedDate LastChangedBy LastChangedRevision Author Id
Propchange: myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/outputLinkDynamic.jsp
------------------------------------------------------------------------------
svn:mime-type = text/plain