1 38 39 package org.apache.cocoon.faces.samples.components.renderkit; 40 41 42 import org.apache.cocoon.faces.samples.components.components.AreaComponent; 43 import org.apache.cocoon.faces.samples.components.components.MapComponent; 44 import org.apache.cocoon.faces.samples.components.model.ImageArea; 45 46 import javax.faces.component.UIComponent; 47 import javax.faces.context.FacesContext; 48 import javax.faces.context.ResponseWriter; 49 50 import java.io.IOException ; 51 52 53 58 59 public class AreaRenderer extends BaseRenderer { 60 61 62 64 65 71 public void decode(FacesContext context, UIComponent component) { 72 73 if ((context == null) || (component == null)) { 74 throw new NullPointerException (); 75 } 76 77 } 78 79 80 86 public void encodeBegin(FacesContext context, UIComponent component) 87 throws IOException { 88 89 if ((context == null) || (component == null)) { 90 throw new NullPointerException (); 91 } 92 93 } 94 95 96 102 public void encodeChildren(FacesContext context, UIComponent component) 103 throws IOException { 104 105 if ((context == null) || (component == null)) { 106 throw new NullPointerException (); 107 } 108 109 } 110 111 112 118 public void encodeEnd(FacesContext context, UIComponent component) 119 throws IOException { 120 121 if ((context == null) || (component == null)) { 122 throw new NullPointerException (); 123 } 124 AreaComponent area = (AreaComponent) component; 125 String targetImageId = 126 area.findComponent(area.getTargetImage()).getClientId(context); 127 ImageArea iarea = (ImageArea) area.getValue(); 128 ResponseWriter writer = context.getResponseWriter(); 129 StringBuffer sb = null; 130 131 writer.startElement("area", area); 132 writer.writeAttribute("alt", iarea.getAlt(), "alt"); 133 writer.writeAttribute("coords", iarea.getCoords(), "coords"); 134 writer.writeAttribute("shape", iarea.getShape(), "shape"); 135 sb = 137 new StringBuffer ("document.forms[0]['").append(targetImageId) 138 .append("'].src='"); 139 sb.append( 140 getURI(context, (String ) area.getAttributes().get("onmouseout"))); 141 sb.append("'"); 142 writer.writeAttribute("onmouseout", sb.toString(), "onmouseout"); 143 sb = 145 new StringBuffer ("document.forms[0]['").append(targetImageId) 146 .append("'].src='"); 147 sb.append( 148 getURI(context, (String ) area.getAttributes().get("onmouseover"))); 149 sb.append("'"); 150 writer.writeAttribute("onmouseover", sb.toString(), "onmouseover"); 151 sb = new StringBuffer ("document.forms[0]['"); 153 sb.append(getName(context, area)); 154 sb.append("'].value='"); 155 sb.append(iarea.getAlt()); 156 sb.append("'; document.forms[0].submit()"); 157 writer.writeAttribute("onclick", sb.toString(), "value"); 158 writer.endElement("area"); 159 160 } 161 162 163 165 166 172 private String getName(FacesContext context, UIComponent component) { 173 while (component != null) { 174 if (component instanceof MapComponent) { 175 return (component.getId() + "_current"); 176 } 177 component = component.getParent(); 178 } 179 throw new IllegalArgumentException (); 180 } 181 182 183 190 private String getURI(FacesContext context, String value) { 191 if (value.startsWith("/")) { 192 return (context.getExternalContext().getRequestContextPath() + 193 value); 194 } else { 195 return (value); 196 } 197 } 198 199 200 } 201
| Popular Tags
|