/* * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * "The contents of this file are subject to the Mozilla Public License * Version 1.1 (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.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations under * the License. * * The Original Code is ICEfaces 1.5 open source software code, released * November 5, 2006. The Initial Developer of the Original Code is ICEsoft * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C) * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved. * * Contributor(s): _____________________. * * Alternatively, the contents of this file may be used under the terms of * the GNU Lesser General Public License Version 2.1 or later (the "LGPL" * License), in which case the provisions of the LGPL License are * applicable instead of those above. If you wish to allow use of your * version of this file only under the terms of the LGPL License and not to * allow others to use your version of this file under the MPL, indicate * your decision by deleting the provisions above and replace them with * the notice and other provisions required by the LGPL License. If you do * not delete the provisions above, a recipient may use your version of * this file under either the MPL or the LGPL License." * */ package com.icesoft.faces.component.ext; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.Serializable; import java.net.URI; import java.util.Date; import com.icesoft.faces.component.CSS_DEFAULT; import com.icesoft.faces.component.ext.taglib.Util; import com.icesoft.faces.context.Resource; import com.icesoft.faces.context.ResourceRegistry; import com.icesoft.faces.context.effects.CurrentStyle; import com.icesoft.faces.context.effects.Effect; import com.icesoft.faces.context.effects.JavascriptContext; import com.icesoft.util.pooling.ClientIdPool; import javax.faces.context.FacesContext; import javax.faces.el.ValueBinding; /** * This is an extension of javax.faces.component.html.HtmlGraphicImage, which * provides some additional behavior to this component such as:
Set the value of the effect property.
Return the value of the effect property.
Set the value of the visible property.
Return the value of the visible property.
Set the value of the renderedOnUserRole property.
Return the value of the renderedOnUserRole property.
Return the value of the rendered property.
Return the value of the onclickeffect property.
Set the value of the onclickeffect property.
Return the value of the ondblclickeffect property.
Set the value of the ondblclickeffect property.
Return the value of the onmousedowneffect property.
Set the value of the onmousedowneffect property.
Return the value of the onmouseupeffect property.
Set the value of the onmouseupeffect property.
Return the value of the onmousemoveeffect property.
Set the value of the onmousemoveeffect property.
Return the value of the onmouseovereffect property.
Set the value of the onmouseovereffect property.
Return the value of the onmouseouteffect property.
Set the value of the onmouseouteffect property.
Return the value of the onkeypresseffect property.
Set the value of the onkeypresseffect property.
Return the value of the onkeydowneffect property.
Set the value of the onkeydowneffect property.
Return the value of the onkeyupeffect property.
Set the value of the onkeyupeffect property.
Return the value of the currentStyle property.
Set the value of the currentStyle property.
Set the value of the styleClass property.
Return the value of the styleClass property.
Gets the state of the instance as a Serializable
* Object.
Perform any processing required to restore the state from the entries * in the state Object.
*/ public void restoreState(FacesContext context, Object state) { Object values[] = (Object[]) state; super.restoreState(context, values[0]); renderedOnUserRole = (String) values[1]; effect = (Effect) values[2]; onclickeffect = (Effect) values[4]; ondblclickeffect = (Effect) values[5]; onmousedowneffect = (Effect) values[6]; onmouseupeffect = (Effect) values[7]; onmousemoveeffect = (Effect) values[8]; onmouseovereffect = (Effect) values[9]; onmouseouteffect = (Effect) values[10]; onkeypresseffect = (Effect) values[14]; onkeydowneffect = (Effect) values[15]; onkeyupeffect = (Effect) values[16]; currentStyle = (CurrentStyle) values[17]; visible = (Boolean)values[18]; mimeType = (String)values[19]; styleClass = (String)values[20]; } public String getByteArrayImagePath(FacesContext context) { return getImageByteArrayResource(context).getPath(); } private ImageByteArrayResource getImageByteArrayResource(FacesContext context) { if(!getAttributes().containsKey(ClientIdPool.get(getClientId(context)+"ImgBytArrRes"))) { ImageByteArrayResource imageByteArrayResource = new ImageByteArrayResource(context,this); getAttributes().put(ClientIdPool.get(getClientId(context)+"ImgBytArrRes"), imageByteArrayResource); } return (ImageByteArrayResource)getAttributes().get(ClientIdPool.get(getClientId(context)+"ImgBytArrRes")); } } class ImageByteArrayResource implements Resource, Serializable { private Date lastModified; private byte[] content; private String mimetype; private URI uri; public ImageByteArrayResource(FacesContext context, HtmlGraphicImage component) { this.lastModified = new Date(System.currentTimeMillis()); this.mimetype = component.getMimeType(); uri = ((ResourceRegistry) context).registerResource(this); } public String calculateDigest() { return String.valueOf(this.hashCode()); } public Date lastModified() { return lastModified; } public InputStream open() throws IOException { return new ByteArrayInputStream(content); } public void withOptions(Options options) throws IOException { Date now = new Date(); options.setExpiresBy(now); options.setLastModified(now); options.setMimeType(mimetype); } public void setContent(byte[] content) { this.content = content; } public String getPath() { return uri.getPath()+ "?"+ content.hashCode(); } }