1 package org.jahia.taglibs.url; 2 3 import javax.servlet.jsp.JspException ; 4 5 import org.jahia.data.beans.FieldBean; 6 import org.jahia.data.fields.JahiaField; 7 import org.jahia.exceptions.JahiaException; 8 9 public class UpdateFieldURLTag extends AbstractURLTag { 10 11 private static org.apache.log4j.Logger logger = 12 org.apache.log4j.Logger.getLogger(UpdateFieldURLTag.class); 13 14 private String fieldName = null; 15 private JahiaField field = null; 16 17 public void setFieldName (String fieldName) { 18 this.fieldName = fieldName; 19 } 20 21 protected void init () { 22 if (getName() == null) { 23 if (fieldName != null) { 24 try { 25 this.field = getJahiaData().fields().getField(this. 26 fieldName); 27 } catch (JahiaException je) { 28 logger.error("Error while retrieving field " + fieldName + 29 ":", je); 30 } 31 } 32 } else { 33 FieldBean fieldBean = (FieldBean) pageContext.findAttribute(getName()); 34 if (fieldBean != null) { 35 this.field = fieldBean.getJahiaField(); 36 } 37 } 38 } 39 40 protected Object getIdObject () { 41 String resultURL = null; 42 if (isWithJSPopup()) { 43 resultURL = getJSPopupURL(); 44 } else { 45 resultURL = getURL(); 46 } 47 if ( (resultURL != null) && 48 (resultURL.length() > 0)) { 49 return resultURL; 50 } 51 return null; 52 } 53 54 protected String getURL () { 55 if (field != null) { 56 try { 57 return getJahiaData().gui().drawUpdateFieldUrl(field); 58 } catch (JahiaException je) { 59 logger.error("Error during URL generation:", je); 60 } 61 } 62 return null; 63 } 64 65 protected String getJSPopupURL () { 66 if (field != null) { 67 try { 68 String popupURL = getJahiaData().gui().html(). 69 drawUpdateFieldLauncher(field); 70 if ( (popupURL != null) && (!"".equals(popupURL))) { 71 return "javascript:" + popupURL; 72 } else { 73 return null; 74 } 75 } catch (JahiaException je) { 76 logger.error("Error while generating URL : ", je); 77 } 78 } 79 return null; 80 } 81 82 public int doEndTag () 83 throws JspException { 84 super.doEndTag(); 87 field = null; 88 fieldName = null; 89 return EVAL_PAGE; 90 } 91 92 } | Popular Tags |