1 17 package org.alfresco.web.ui.repo.component; 18 19 import java.io.IOException ; 20 21 import javax.faces.context.FacesContext; 22 import javax.faces.context.ResponseWriter; 23 import javax.faces.el.ValueBinding; 24 25 import org.alfresco.model.ContentModel; 26 import org.alfresco.service.cmr.lock.LockService; 27 import org.alfresco.service.cmr.lock.LockStatus; 28 import org.alfresco.service.cmr.repository.NodeRef; 29 import org.alfresco.service.cmr.repository.NodeService; 30 import org.alfresco.web.app.Application; 31 import org.alfresco.web.bean.repository.Repository; 32 import org.alfresco.web.ui.common.Utils; 33 import org.alfresco.web.ui.common.component.SelfRenderingComponent; 34 import org.alfresco.web.ui.repo.WebResources; 35 36 39 public class UILockIcon extends SelfRenderingComponent 40 { 41 private static final String MSG_LOCKED_YOU = "locked_you"; 42 private static final String MSG_LOCKED_USER = "locked_user"; 43 44 47 50 public String getFamily() 51 { 52 return "org.alfresco.faces.LockIcon"; 53 } 54 55 58 public void restoreState(FacesContext context, Object state) 59 { 60 Object values[] = (Object [])state; 61 super.restoreState(context, values[0]); 63 this.lockImage = (String )values[1]; 64 this.lockOwnerImage = (String )values[2]; 65 this.align = (String )values[3]; 66 this.width = ((Integer )values[4]).intValue(); 67 this.height = ((Integer )values[5]).intValue(); 68 this.value = values[6]; 69 } 70 71 74 public Object saveState(FacesContext context) 75 { 76 Object values[] = new Object [7]; 77 values[0] = super.saveState(context); 79 values[1] = this.lockImage; 80 values[2] = this.lockOwnerImage; 81 values[3] = this.align; 82 values[4] = this.width; 83 values[5] = this.height; 84 values[6] = this.value; 85 return (values); 86 } 87 88 91 public void encodeBegin(FacesContext context) throws IOException 92 { 93 if (isRendered() == false) 94 { 95 return; 96 } 97 98 ResponseWriter out = context.getResponseWriter(); 99 100 NodeService nodeService = getNodeService(context); 102 boolean locked = false; 103 boolean lockedOwner = false; 104 105 Object val = getValue(); 106 NodeRef ref = null; 107 if (val instanceof NodeRef) 108 { 109 ref = (NodeRef)val; 110 if (nodeService.exists(ref) && nodeService.hasAspect(ref, ContentModel.ASPECT_LOCKABLE) == true) 111 { 112 LockStatus lockStatus = getLockService(context).getLockStatus(ref); 113 locked = (lockStatus == LockStatus.LOCKED || lockStatus == LockStatus.LOCK_OWNER); 114 lockedOwner = (lockStatus == LockStatus.LOCK_OWNER); 115 } 116 } 117 118 String msg = null; 119 120 if (locked == true) 121 { 122 out.write(" <img"); 123 124 outputAttribute(out, getAttributes().get("style"), "style"); 125 outputAttribute(out, getAttributes().get("styleClass"), "class"); 126 127 outputAttribute(out, getAlign(), "align"); 128 outputAttribute(out, getWidth(), "width"); 129 outputAttribute(out, getHeight(), "height"); 130 131 out.write("src=\""); 132 out.write(context.getExternalContext().getRequestContextPath()); 133 String lockImage = getLockImage(); 134 if (lockedOwner == true && getLockOwnerImage() != null) 135 { 136 lockImage = getLockOwnerImage(); 137 } 138 out.write(lockImage); 139 out.write("\" border=0"); 140 141 if (lockedOwner == true) 142 { 143 msg = Application.getMessage(context, MSG_LOCKED_YOU); 144 if (getLockedOwnerTooltip() != null) 145 { 146 msg = getLockedOwnerTooltip(); 147 } 148 } 149 else 150 { 151 String lockingUser = (String )nodeService.getProperty(ref, ContentModel.PROP_LOCK_OWNER); 152 msg = Application.getMessage(context, MSG_LOCKED_USER); 153 if (getLockedUserTooltip() != null) 154 { 155 msg = getLockedUserTooltip(); 156 } 157 StringBuilder buf = new StringBuilder (32); 158 msg = buf.append(msg).append(" '") 159 .append(lockingUser) 160 .append("'").toString(); 161 } 162 163 msg = Utils.encode(msg); 164 out.write(" alt=\""); 165 out.write(msg); 166 out.write("\" title=\""); 167 out.write(msg); 168 out.write("\">"); 169 } 170 } 171 172 179 private static NodeService getNodeService(FacesContext context) 180 { 181 NodeService service = Repository.getServiceRegistry(context).getNodeService(); 182 if (service == null) 183 { 184 throw new IllegalStateException ("Unable to obtain NodeService bean reference."); 185 } 186 187 return service; 188 } 189 190 197 private static LockService getLockService(FacesContext context) 198 { 199 LockService service = Repository.getServiceRegistry(context).getLockService(); 200 if (service == null) 201 { 202 throw new IllegalStateException ("Unable to obtain LockService bean reference."); 203 } 204 205 return service; 206 } 207 208 209 212 215 public String getLockImage() 216 { 217 ValueBinding vb = getValueBinding("lockImage"); 218 if (vb != null) 219 { 220 this.lockImage = (String )vb.getValue(getFacesContext()); 221 } 222 223 return this.lockImage; 224 } 225 226 229 public void setLockImage(String lockImage) 230 { 231 this.lockImage = lockImage; 232 } 233 234 237 public String getLockOwnerImage() 238 { 239 ValueBinding vb = getValueBinding("lockOwnerImage"); 240 if (vb != null) 241 { 242 this.lockOwnerImage = (String )vb.getValue(getFacesContext()); 243 } 244 245 return this.lockOwnerImage; 246 } 247 248 251 public void setLockOwnerImage(String lockOwnerImage) 252 { 253 this.lockOwnerImage = lockOwnerImage; 254 } 255 256 259 public String getAlign() 260 { 261 ValueBinding vb = getValueBinding("align"); 262 if (vb != null) 263 { 264 this.align = (String )vb.getValue(getFacesContext()); 265 } 266 267 return this.align; 268 } 269 270 273 public void setAlign(String align) 274 { 275 this.align = align; 276 } 277 278 281 public int getHeight() 282 { 283 ValueBinding vb = getValueBinding("height"); 284 if (vb != null) 285 { 286 Integer value = (Integer )vb.getValue(getFacesContext()); 287 if (value != null) 288 { 289 this.height = value.intValue(); 290 } 291 } 292 293 return this.height; 294 } 295 296 299 public void setHeight(int height) 300 { 301 this.height = height; 302 } 303 304 307 public int getWidth() 308 { 309 ValueBinding vb = getValueBinding("width"); 310 if (vb != null) 311 { 312 Integer value = (Integer )vb.getValue(getFacesContext()); 313 if (value != null) 314 { 315 this.width = value.intValue(); 316 } 317 } 318 319 return this.width; 320 } 321 322 325 public void setWidth(int width) 326 { 327 this.width = width; 328 } 329 330 333 public String getLockedOwnerTooltip() 334 { 335 ValueBinding vb = getValueBinding("lockedOwnerTooltip"); 336 if (vb != null) 337 { 338 this.lockedOwnerTooltip = (String )vb.getValue(getFacesContext()); 339 } 340 341 return this.lockedOwnerTooltip; 342 } 343 344 347 public void setLockedOwnerTooltip(String lockedOwnerTooltip) 348 { 349 this.lockedOwnerTooltip = lockedOwnerTooltip; 350 } 351 352 355 public String getLockedUserTooltip() 356 { 357 ValueBinding vb = getValueBinding("lockedUserTooltip"); 358 if (vb != null) 359 { 360 this.lockedUserTooltip = (String )vb.getValue(getFacesContext()); 361 } 362 363 return this.lockedUserTooltip; 364 } 365 366 369 public void setLockedUserTooltip(String lockedUserTooltip) 370 { 371 this.lockedUserTooltip = lockedUserTooltip; 372 } 373 374 377 public Object getValue() 378 { 379 ValueBinding vb = getValueBinding("value"); 380 if (vb != null) 381 { 382 this.value = vb.getValue(getFacesContext()); 383 } 384 385 return this.value; 386 } 387 388 391 public void setValue(Object value) 392 { 393 this.value = value; 394 } 395 396 397 private String lockImage = WebResources.IMAGE_LOCK; 398 private String lockOwnerImage = WebResources.IMAGE_LOCK_OWNER; 399 private String align = null; 400 private int width = 16; 401 private int height = 16; 402 private String lockedOwnerTooltip = null; 403 private String lockedUserTooltip = null; 404 private Object value = null; 405 } 406 | Popular Tags |