1 64 65 package com.jcorporate.expresso.ext.taglib; 66 67 import com.jcorporate.expresso.core.i18n.Messages; 68 import com.jcorporate.expresso.core.misc.ConfigManager; 69 import com.jcorporate.expresso.core.misc.ConfigurationException; 70 import com.jcorporate.expresso.core.misc.StringUtil; 71 import com.jcorporate.expresso.ext.struts.taglib.bean.ExMessageTag; 72 import com.jcorporate.expresso.kernel.util.FastStringBuffer; 73 74 import javax.servlet.http.HttpServletRequest ; 75 import javax.servlet.jsp.JspTagException ; 76 import javax.servlet.jsp.JspWriter ; 77 import javax.servlet.jsp.PageContext ; 78 import java.io.IOException ; 79 import java.util.Locale ; 80 81 82 88 public class Back 89 extends ExpressoTagSupport { 90 private String page = null; 91 92 95 private String image = "/expresso/expresso/images/FingerLeft.gif"; 96 97 100 private String title = "Back to original page..."; 101 102 105 private String key = null; 106 107 110 public static String BACK_KEY = "com.jcorporate.expresso.ext.taglib.Back."; 111 112 public Back() { 113 super(); 114 } 115 116 public int doStartTag() throws javax.servlet.jsp.JspException { 117 return SKIP_BODY; 118 } 119 120 121 public int doEndTag() 122 throws JspTagException { 123 FastStringBuffer image = new FastStringBuffer(32); 124 try { 125 126 130 image.append(ConfigManager.getContext("default").getImages()); 131 image.append("/FingerLeft.gif"); 132 } catch (ConfigurationException ce) { 133 System.out.println(ce.getMessage()); 134 System.out.println("Using default image value"); 135 } 136 137 String backUrl = null; 138 139 if (page == null) { 140 141 142 Object o = pageContext.getAttribute(BACK_KEY + ".URL", 143 PageContext.SESSION_SCOPE); 144 Object ot = pageContext.getAttribute(BACK_KEY + ".TITLE", 145 PageContext.SESSION_SCOPE); 146 147 if (o != null) { 148 backUrl = (String ) o; 149 150 JspWriter writer = pageContext.getOut(); 151 title = (String ) ot; 152 153 if (backUrl.equals("")) { 154 backUrl = "NONE"; 155 } 156 if (!backUrl.equals("NONE")) { 157 try { 158 FastStringBuffer fsb = new FastStringBuffer(56); 159 fsb.append("<a HREF=\""); 160 fsb.append(backUrl); 161 fsb.append("\" title=\""); 162 fsb.append(StringUtil.notNull(title)); 163 fsb.append("\"><img SRC=\""); 164 fsb.append(image.toString()); 165 fsb.append("\" border=\"0\"></a>"); 166 writer.print(fsb.toString()); 167 } catch (IOException ie) { 172 throw new JspTagException ("Cant write output"); 173 } 174 } 175 } 176 } else { 177 if (page.equals("current")) { 178 HttpServletRequest req = (HttpServletRequest ) pageContext.getRequest(); 179 backUrl = req.getRequestURI(); 180 181 if (req.getQueryString() != null) { 182 String queryString = req.getQueryString(); 183 185 FastStringBuffer fsb = new FastStringBuffer(queryString.length() 186 + backUrl.length() 187 + 4); 188 fsb.append(backUrl); 189 fsb.append("?"); 190 fsb.append(req.getQueryString()); 191 backUrl = fsb.toString(); 192 } 194 } else { 195 backUrl = page; 196 } 197 198 pageContext.setAttribute(BACK_KEY + ".URL", backUrl, 199 PageContext.SESSION_SCOPE); 200 201 if (title != null) { 202 pageContext.setAttribute(BACK_KEY + ".TITLE", title, 203 PageContext.SESSION_SCOPE); 204 } 205 if (key != null) { 206 pageContext.setAttribute(BACK_KEY + ".TITLE", getString(key), 207 PageContext.SESSION_SCOPE); 208 } 209 } 210 211 return EVAL_PAGE; 212 } 213 214 public String getKey() { 215 return key; 216 } 217 218 public void setKey(String newKey) { 219 key = newKey; 220 } 221 222 public String getPage() { 223 return page; 224 } 225 226 229 public String getTitle() { 230 return title; 231 } 232 233 public String getImage() { 234 return image; 235 } 236 237 public void setPage(String newName) { 238 page = newName; 239 } 240 241 public void setImage(String newName) { 242 image = newName; 243 } 244 245 public void setTitle(String newName) { 246 title = newName; 247 } 248 249 255 private String getString(String key) { 256 StringUtil.assertNotBlank(key, 257 "You must specify a key for the string."); 258 259 Locale l = (Locale ) pageContext.getAttribute(Messages.LOCALE_KEY, 260 PageContext.SESSION_SCOPE); 261 String schemaClass = (String ) pageContext.getAttribute(ExMessageTag.SCHEMA_KEY, 262 PageContext.PAGE_SCOPE); 263 264 if (schemaClass != null) { 265 Object [] args = {}; 266 267 return Messages.getString(schemaClass, l, key, args); 268 } else { 269 return Messages.getString(l, key); 270 } 271 } 272 } 273 274 | Popular Tags |