1 package org.jahia.taglibs.button; 2 3 import javax.servlet.http.HttpServletRequest ; 4 import javax.servlet.jsp.JspException ; 5 6 import org.jahia.data.JahiaData; 7 import org.jahia.exceptions.JahiaException; 8 import org.jahia.registries.ServicesRegistry; 9 import org.jahia.services.usermanager.JahiaUser; 10 import org.jahia.services.usermanager.JahiaUserManagerService; 11 12 13 19 public class SwitchModeRolloverTag extends AbstractRolloverTag { 20 21 private String imgdir = "images"; 22 private String viewOn = ""; 23 private String viewOff = ""; 24 private String editOn = ""; 25 private String editOff = ""; 26 private String previewOn = ""; 27 private String previewOff = ""; 28 private String width = ""; 29 private String height = ""; 30 private String separator; 31 32 public void setImgdir(String imgdir) { 33 this.imgdir = imgdir; 34 } 35 36 public String getImgDir() { 37 return this.imgdir; 38 } 39 40 public void setViewOn(String viewOn) { 41 this.viewOn = viewOn; 42 } 43 44 public void setViewOff(String viewOff) { 45 this.viewOff = viewOff; 46 } 47 48 public void setEditOn(String editOn) { 49 this.editOn = editOn; 50 } 51 52 public void setEditOff(String editOff) { 53 this.editOff = editOff; 54 } 55 56 public void setWidth(String width) { 57 this.width = width; 58 } 59 60 public String getWidth() { 61 return this.width; 62 } 63 64 public void setHeight(String height) { 65 this.height = height; 66 } 67 68 public String getHeight() { 69 return this.height; 70 } 71 72 73 74 75 76 public String buildButton (JahiaData jData, HttpServletRequest request) { 78 79 String url1 = null; 80 String url2 = null; 81 82 String inImage1 = null; 83 String outImage1 = null; 84 String inImage2 = null; 85 String outImage2 = null; 86 87 boolean isFirstAllowed = false; 88 boolean isSecondAllowed = false; 89 90 boolean stagingActivated = jData.params().getSite().isStagingEnabled(); 91 92 try { 93 if (jData.gui().isEditMode()) { 94 url1 = jData.gui().drawNormalModeLink(); 95 inImage1 = this.viewOn; 96 outImage1 = this.viewOff; 97 98 if (stagingActivated) { 99 url2 = jData.gui().drawPreviewModeLink(); 100 inImage2 = this.previewOn; 101 outImage2 = this.previewOff; 102 } 103 104 } else if (jData.gui().isPreviewMode()) { 105 url1 = jData.gui().drawNormalModeLink(); 106 inImage1 = this.viewOn; 107 outImage1 = this.viewOff; 108 109 url2 = jData.gui().drawEditModeLink(); 110 inImage2 = this.editOn; 111 outImage2 = this.editOff; 112 } else { 113 if (stagingActivated) { 115 url1 = jData.gui().drawPreviewModeLink(); 116 inImage1 = this.previewOn; 117 outImage1 = this.previewOff; 118 } else { 119 url1 = jData.gui().drawEditModeLink(); 120 inImage1 = this.editOn; 121 inImage1 = this.editOff; 122 } 123 } 124 } catch (JahiaException je) { 125 return ""; 126 } 127 128 if ( url1 == null || url1.trim().equals("")) { 129 isFirstAllowed = false; 130 } else { 131 isFirstAllowed = true; 132 } 133 134 if ( url2 == null || url2.trim().equals("")) { 135 isSecondAllowed = false; 136 } else { 137 isSecondAllowed = true; 138 } 139 140 String imgDir = getImgDir(); 142 String width = getWidth(); 143 String height = getHeight(); 144 String align = getAlign(); 145 String imgName = getClassName() + "Img_"; 146 String context = jData.gui().drawHttpJspContext(request); 147 String outImage = null; 148 String overImage = null; 149 String launcher = null; 150 151 StringBuffer text = new StringBuffer ( ); 152 if (isFirstAllowed) { 153 overImage = inImage1; 154 outImage = outImage1; 155 156 text.append( "<a HREF=\"" ); 157 text.append( launcher ); 158 text.append( "\" onMouseOut=\"document." ); 159 text.append( imgName ); 160 text.append( getCounter() ); 161 text.append( ".src='" ); 162 text.append( context ); 163 text.append( "/" ); 164 text.append( imgDir ); 165 text.append( "/" ); 166 text.append( outImage ); 167 text.append( "';\" onMouseOver=\"document." ); 168 text.append( imgName ); 169 text.append( getCounter() ); 170 text.append( ".src='" ); 171 text.append( context ); 172 text.append( "/" ); 173 text.append( imgDir ); 174 text.append( "/" ); 175 text.append( overImage ); 176 text.append( "';\"><img name=\"" ); 177 text.append( imgName ); 178 text.append( getCounter().intValue() ); 179 text.append( "\" SRC=\"" ); 180 text.append( context ); 181 text.append( "/" ); 182 text.append( imgDir ); 183 text.append( "/" ); 184 text.append( outImage ); 185 text.append( "\"" ); 186 if ( !width.equals("" ) ) { 187 text.append( " width=\"" ); 188 text.append( width ); 189 text.append( "\"" ); 190 } 191 if ( !height.equals("") ) { 192 text.append( " height=\"" ); 193 text.append( height ); 194 text.append( "\"" ); 195 } 196 if ( !align.equals("") ) { 197 text.append( " align=\"" ); 198 text.append( align ); 199 text.append( "\"" ); 200 } 201 202 text.append( " border=\"0\" alt=\"\">" ); 203 text.append( getTitle() ); 204 text.append( "</a>" ); 205 } 206 207 if (isFirstAllowed && isSecondAllowed) { 208 text.append(separator); 209 } 210 211 if (isSecondAllowed) { 212 overImage = inImage2; 213 outImage = outImage2; 214 215 text.append( "<a HREF=\"" ); 216 text.append( launcher ); 217 text.append( "\" onMouseOut=\"document." ); 218 text.append( imgName ); 219 text.append( getCounter() ); 220 text.append( ".src='" ); 221 text.append( context ); 222 text.append( "/" ); 223 text.append( imgDir ); 224 text.append( "/" ); 225 text.append( outImage ); 226 text.append( "';\" onMouseOver=\"document." ); 227 text.append( imgName ); 228 text.append( getCounter() ); 229 text.append( ".src='" ); 230 text.append( context ); 231 text.append( "/" ); 232 text.append( imgDir ); 233 text.append( "/" ); 234 text.append( overImage ); 235 text.append( "';\"><img name=\"" ); 236 text.append( imgName ); 237 text.append( getCounter().intValue() ); 238 text.append( "\" SRC=\"" ); 239 text.append( context ); 240 text.append( "/" ); 241 text.append( imgDir ); 242 text.append( "/" ); 243 text.append( outImage ); 244 text.append( "\"" ); 245 if ( !width.equals("" ) ) { 246 text.append( " width=\"" ); 247 text.append( width ); 248 text.append( "\"" ); 249 } 250 if ( !height.equals("") ) { 251 text.append( " height=\"" ); 252 text.append( height ); 253 text.append( "\"" ); 254 } 255 if ( !align.equals("") ) { 256 text.append( " align=\"" ); 257 text.append( align ); 258 text.append( "\"" ); 259 } 260 261 text.append( " border=\"0\" alt=\"\">" ); 262 text.append( getTitle() ); 263 text.append( "</a>" ); 264 } 265 266 return text.toString(); 267 } 268 269 public boolean testRights(JahiaData jData) { 271 if (this.editOn.equals("") || this.editOff.equals("")) { 273 this.editOn = this.viewOn; 274 this.editOff = this.viewOff; 275 } 276 JahiaUserManagerService userService = ServicesRegistry.getInstance().getJahiaUserManagerService(); 279 JahiaUser theUser = userService.lookupUser( jData.page().getJahiaID(), JahiaUserManagerService.GUEST_USERNAME ); 280 return jData.gui().isLogged() || jData.page().checkWriteAccess(theUser); 281 } 282 283 public String getLauncher (JahiaData jData) 284 throws JahiaException { 285 return jData.gui().drawSwitchModeLink(); 286 } 287 288 public String getMouseOutImage(JahiaData jData) 290 throws JahiaException { 291 return ""; 292 } 293 294 public String getMouseOverImage(JahiaData jData) 295 throws JahiaException { 296 return ""; 297 } 298 public void setSeparator(String separator) { 299 this.separator = separator; 300 } 301 public String getSeparator() { 302 return separator; 303 } 304 305 public int doEndTag() throws JspException { 306 imgdir = "images"; 309 viewOn = ""; 310 viewOff = ""; 311 editOn = ""; 312 editOff = ""; 313 previewOn = ""; 314 previewOff = ""; 315 width = ""; 316 height = ""; 317 separator = null; 318 return EVAL_PAGE; 319 } 320 321 322 } 323 | Popular Tags |