1 23 24 package org.infoglue.deliver.taglib.content; 25 26 import java.util.Map ; 27 28 import javax.servlet.jsp.JspException ; 29 30 import org.infoglue.cms.entities.management.LanguageVO; 31 import org.infoglue.deliver.controllers.kernel.impl.simple.LanguageDeliveryController; 32 import org.infoglue.deliver.taglib.component.ComponentLogicTag; 33 import org.infoglue.deliver.util.Support; 34 35 49 50 public class ContentAttributeTag extends ComponentLogicTag 51 { 52 private static final long serialVersionUID = 3257850991142318897L; 53 54 private Integer contentId; 55 private String propertyName; 56 private String attributeName; 57 private Integer languageId; 58 private String mapKeyName; 59 private boolean disableEditOnSight = false; 60 private boolean useInheritance = true; 61 private boolean useAttributeLanguageFallback = false; 62 private boolean parse = false; 63 private boolean fullBaseUrl = false; 64 65 public ContentAttributeTag() 66 { 67 super(); 68 } 69 70 76 public int doStartTag() throws JspException 77 { 78 return EVAL_BODY_INCLUDE; 79 } 80 81 private String getContentAttributeValue(Integer languageId) throws JspException 82 { 83 String result = null; 84 85 if(contentId != null) 86 { 87 if(!parse) 88 { 89 result = getController().getContentAttribute(contentId, languageId, attributeName, disableEditOnSight); 90 } 91 else 92 { 93 result = getController().getParsedContentAttribute(contentId, languageId, attributeName, disableEditOnSight); 94 } 95 } 96 else if(propertyName != null) 97 { 98 if(!parse) 99 { 100 result = getComponentLogic().getContentAttribute(propertyName, languageId, attributeName, disableEditOnSight, useInheritance); 101 } 102 else 103 { 104 result = getComponentLogic().getParsedContentAttribute(propertyName, languageId, attributeName, disableEditOnSight, useInheritance); 105 } 106 } 107 else 108 { 109 throw new JspException ("You must specify either contentId or propertyName"); 110 } 111 112 return result; 113 } 114 115 public int doEndTag() throws JspException 116 { 117 if(this.languageId == null) 118 this.languageId = getController().getLanguageId(); 119 120 boolean previousSetting = getController().getDeliveryContext().getUseFullUrl(); 121 String result = null; 122 if(previousSetting != fullBaseUrl) 123 { 124 getController().getDeliveryContext().setUseFullUrl(fullBaseUrl); 125 } 126 if ( mapKeyName != null ) 130 { 131 disableEditOnSight = true; 132 } 133 134 result = getContentAttributeValue(this.languageId); 135 136 if((result == null || result.trim().equals("")) && useAttributeLanguageFallback) 137 { 138 try 139 { 140 LanguageVO masteLanguageVO = LanguageDeliveryController.getLanguageDeliveryController().getMasterLanguageForSiteNode(this.getController().getDatabase(), this.getController().getSiteNodeId()); 141 result = getContentAttributeValue(masteLanguageVO.getLanguageId()); 142 } 143 catch(Exception e) 144 { 145 throw new JspException ("Error getting the master language for this sitenode:" + this.getController().getSiteNodeId()); 146 } 147 } 148 149 if ( mapKeyName != null && result != null ) 150 { 151 Map map = Support.convertTextToProperties( result.toString() ); 152 if ( map != null && !map.isEmpty() ) 153 { 154 result = (String )map.get( mapKeyName ); 155 } 156 } 157 produceResult( result ); 158 getController().getDeliveryContext().setUseFullUrl(previousSetting); 160 161 contentId = null; 162 propertyName = null; 163 attributeName = null;; 164 mapKeyName = null;; 165 disableEditOnSight = false; 166 useInheritance = true; 167 useAttributeLanguageFallback = true; 168 parse = false; 169 fullBaseUrl = false; 170 languageId = null; 171 172 return EVAL_PAGE; 173 } 174 175 public void setPropertyName(String propertyName) throws JspException 176 { 177 this.propertyName = evaluateString("contentAttribute", "propertyName", propertyName); 178 } 179 180 public void setAttributeName(String attributeName) throws JspException 181 { 182 this.attributeName = evaluateString("contentAttribute", "attributeName", attributeName); 183 } 184 185 public void setDisableEditOnSight(boolean disableEditOnSight) 186 { 187 this.disableEditOnSight = disableEditOnSight; 188 } 189 190 public void setUseInheritance(boolean useInheritance) 191 { 192 this.useInheritance = useInheritance; 193 } 194 195 public void setParse(boolean parse) 196 { 197 this.parse = parse; 198 } 199 200 public void setContentId(final String contentId) throws JspException 201 { 202 this.contentId = evaluateInteger("contentAttribute", "contentId", contentId); 203 } 204 205 public void setLanguageId(final String languageId) throws JspException 206 { 207 this.languageId = evaluateInteger("contentAttribute", "languageId", languageId); 208 } 209 210 public void setFullBaseUrl(boolean fullBaseUrl) 211 { 212 this.fullBaseUrl = fullBaseUrl; 213 } 214 215 public void setMapKeyName( String mapKeyName ) 216 { 217 this.mapKeyName = mapKeyName; 218 } 219 220 public void setUseAttributeLanguageFallback(boolean useAttributeLanguageFallback) 221 { 222 this.useAttributeLanguageFallback = useAttributeLanguageFallback; 223 } 224 } | Popular Tags |