View Javadoc

1   package org.rcfaces.core.internal.taglib;
2   
3   import javax.faces.application.Application;
4   import javax.faces.component.UIComponent;
5   import org.rcfaces.core.internal.component.Properties;
6   import javax.el.ValueExpression;
7   import javax.faces.component.UIViewRoot;
8   import org.apache.commons.logging.Log;
9   import javax.servlet.jsp.tagext.Tag;
10  import org.apache.commons.logging.LogFactory;
11  import org.rcfaces.core.component.ImageComponent;
12  import org.rcfaces.core.internal.tools.ListenersTools1_2;
13  import org.rcfaces.core.internal.tools.ListenersTools;
14  import javax.faces.context.FacesContext;
15  
16  public class ImageTag extends AbstractOutputTag implements Tag {
17  
18  
19  	private static final Log LOG=LogFactory.getLog(ImageTag.class);
20  
21  	private ValueExpression imageURL;
22  	private ValueExpression imageHeight;
23  	private ValueExpression imageWidth;
24  	private ValueExpression alternateText;
25  	private ValueExpression filterProperties;
26  	public String getComponentType() {
27  		return ImageComponent.COMPONENT_TYPE;
28  	}
29  
30  	public final void setImageURL(ValueExpression imageURL) {
31  		this.imageURL = imageURL;
32  	}
33  
34  	public final void setImageHeight(ValueExpression imageHeight) {
35  		this.imageHeight = imageHeight;
36  	}
37  
38  	public final void setImageWidth(ValueExpression imageWidth) {
39  		this.imageWidth = imageWidth;
40  	}
41  
42  	public final void setAlternateText(ValueExpression alternateText) {
43  		this.alternateText = alternateText;
44  	}
45  
46  	public final void setFilterProperties(ValueExpression filterProperties) {
47  		this.filterProperties = filterProperties;
48  	}
49  
50  	protected void setProperties(UIComponent uiComponent) {
51  		if (LOG.isDebugEnabled()) {
52  			if (ImageComponent.COMPONENT_TYPE==getComponentType()) {
53  				LOG.debug("Component id='"+getId()+"' type='"+getComponentType()+"'.");
54  			}
55  			LOG.debug("  imageURL='"+imageURL+"'");
56  			LOG.debug("  imageHeight='"+imageHeight+"'");
57  			LOG.debug("  imageWidth='"+imageWidth+"'");
58  			LOG.debug("  alternateText='"+alternateText+"'");
59  			LOG.debug("  filterProperties='"+filterProperties+"'");
60  		}
61  		if ((uiComponent instanceof ImageComponent)==false) {
62  			if (uiComponent instanceof UIViewRoot) {
63  				throw new IllegalStateException("The first component of the page must be a UIViewRoot component !");
64  			}
65  			throw new IllegalStateException("Component specified by tag is not instanceof of 'ImageComponent'.");
66  		}
67  
68  		super.setProperties(uiComponent);
69  
70  		ImageComponent component = (ImageComponent) uiComponent;
71  		FacesContext facesContext = getFacesContext();
72  
73  		if (imageURL != null) {
74  			if (imageURL.isLiteralText()==false) {
75  				component.setValueExpression(Properties.IMAGE_URL, imageURL);
76  
77  			} else {
78  				component.setImageURL(imageURL.getExpressionString());
79  			}
80  		}
81  
82  		if (imageHeight != null) {
83  			if (imageHeight.isLiteralText()==false) {
84  				component.setValueExpression(Properties.IMAGE_HEIGHT, imageHeight);
85  
86  			} else {
87  				component.setImageHeight(getInt(imageHeight.getExpressionString()));
88  			}
89  		}
90  
91  		if (imageWidth != null) {
92  			if (imageWidth.isLiteralText()==false) {
93  				component.setValueExpression(Properties.IMAGE_WIDTH, imageWidth);
94  
95  			} else {
96  				component.setImageWidth(getInt(imageWidth.getExpressionString()));
97  			}
98  		}
99  
100 		if (alternateText != null) {
101 			if (alternateText.isLiteralText()==false) {
102 				component.setValueExpression(Properties.ALTERNATE_TEXT, alternateText);
103 
104 			} else {
105 				component.setAlternateText(alternateText.getExpressionString());
106 			}
107 		}
108 
109 		if (filterProperties != null) {
110 			if (filterProperties.isLiteralText()==false) {
111 				component.setValueExpression(Properties.FILTER_PROPERTIES, filterProperties);
112 
113 			} else {
114 				component.setFilterProperties(filterProperties.getExpressionString());
115 			}
116 		}
117 	}
118 
119 	public void release() {
120 		imageURL = null;
121 		imageHeight = null;
122 		imageWidth = null;
123 		alternateText = null;
124 		filterProperties = null;
125 
126 		super.release();
127 	}
128 
129 }