1 19 20 package com.sslexplorer.input.tags; 21 22 import javax.servlet.http.HttpServletRequest ; 23 import javax.servlet.jsp.JspException ; 24 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 import org.apache.struts.taglib.TagUtils; 28 import org.apache.struts.taglib.html.BaseFieldTag; 29 import org.apache.struts.util.MessageResources; 30 31 import com.sslexplorer.core.CoreUtil; 32 import com.sslexplorer.properties.Property; 33 import com.sslexplorer.properties.impl.profile.ProfilePropertyKey; 34 import com.sslexplorer.security.LogonControllerFactory; 35 36 42 public class DateTimePickerTag extends BaseFieldTag { 43 44 final static Log log = LogFactory.getLog(DateTimePickerTag.class); 45 46 48 protected String dateTimeId; 49 protected String pattern; 50 protected boolean twentyFourHour; 51 protected boolean showTime; 52 protected boolean disabled; 53 protected String fragment; 54 protected String dateSeparator; 55 protected boolean showDate; 56 protected boolean showMonthYear; 57 protected boolean showLongMonth; 58 protected boolean showMonthYearPicker; 59 protected boolean showSeconds; 60 61 64 protected static MessageResources messages = MessageResources.getMessageResources("org.apache.struts.taglib.bean.LocalStrings"); 65 66 69 public DateTimePickerTag() { 70 release(); 71 } 72 73 78 public int doEndTag() throws JspException { 79 if(fragment != null) { 80 TagUtils.getInstance().write(pageContext, fragment); 81 } 82 pattern = null; 83 return (EVAL_PAGE); 84 } 85 86 91 public void release() { 92 super.release(); 93 disabled = false; 94 twentyFourHour = true; 95 showTime = true; 96 pattern = null; 97 dateTimeId = null; 98 showDate = true; 99 showLongMonth = true; 100 showMonthYear = false; 101 showMonthYearPicker = true; 102 showSeconds = true; 103 dateSeparator = "/"; 104 fragment = null; 105 } 106 107 112 public int doStartTag() throws JspException { 113 if (disabled) 114 return SKIP_PAGE; 115 116 if(getBundle() == null || getBundle().equals("")) { 117 setBundle("navigation"); 118 } 119 fragment = generateFragment(); 120 return (EVAL_BODY_AGAIN); 121 } 122 123 String generateFragment() throws JspException { 124 StringBuffer buf = new StringBuffer (); 125 buf.append("<a HREF=\"#\" onclick=\"toggleCalendar('"); 132 buf.append("dateTimePicker_" + dateTimeId); 133 buf.append("','"); 134 buf.append(dateTimeId); 135 buf.append("','"); 136 String datePattern = pattern; 137 if(datePattern == null) { 138 datePattern = Property.getProperty( 139 new ProfilePropertyKey("ui.dateFormat", 140 LogonControllerFactory.getInstance().getSessionInfo( 141 (HttpServletRequest )pageContext.getRequest()))); 142 if(datePattern.contains("-")) { 143 dateSeparator = "-"; 144 } 145 else if(datePattern.contains("/")) { 146 dateSeparator = "/"; 147 } 148 datePattern = datePattern.replace(dateSeparator, "").toUpperCase(); 149 } 150 buf.append(datePattern); 151 buf.append("',"); 152 buf.append(showTime); 153 buf.append(","); 154 buf.append(twentyFourHour ? "24" : "12"); 155 buf.append(","); 156 buf.append(showDate); 157 buf.append(","); 158 buf.append(showMonthYear); 159 buf.append(","); 160 buf.append(showLongMonth); 161 buf.append(","); 162 buf.append(showMonthYearPicker); 163 buf.append(","); 164 buf.append(showSeconds); 165 buf.append(",'"); 166 buf.append(dateSeparator); 167 buf.append("','"); 168 buf.append(CoreUtil.getThemePath(pageContext.getSession())); 169 buf.append("/images/year-up.gif','"); 170 buf.append(CoreUtil.getThemePath(pageContext.getSession())); 171 buf.append("/images/year-down.gif','"); 172 buf.append(CoreUtil.getThemePath(pageContext.getSession())); 173 buf.append("/images/close.gif');\"><img SRC=\""); 174 buf.append(CoreUtil.getThemePath(pageContext.getSession())); 175 buf.append("/images/cal.gif\" border=\"0\"></a><div style=\"position: "); 176 buf.append("absolute;display:none;overflow:visible;top:4px;width:220px;left:4px;z-index:900\""); 177 buf.append(" id=\""); 178 buf.append("dateTimePicker_" + dateTimeId); 179 buf.append("\"><div/></div>"); 180 return buf.toString(); 181 } 182 183 186 public void setDisabled(boolean disabled) { 187 this.disabled = disabled; 188 } 189 190 196 public void setDateTimeId(String dateTimeId) { 197 this.dateTimeId = dateTimeId; 198 } 199 200 207 public void setPattern(String pattern) { 208 this.pattern = pattern; 209 } 210 211 216 public void setShowTime(String showTime) { 217 this.showTime = Boolean.parseBoolean(showTime); 218 } 219 220 227 public void setTwentyFourHour(String twentyFourHour) { 228 this.twentyFourHour = Boolean.parseBoolean(twentyFourHour); 229 } 230 231 236 public void setShowDate(boolean showDate) { 237 this.showDate = showDate; 238 } 239 240 245 public void setShowLongMonth(boolean showLongMonth) { 246 this.showLongMonth = showLongMonth; 247 } 248 249 254 public void setShowMonthYear(boolean showMonthYear) { 255 this.showMonthYear = showMonthYear; 256 } 257 258 263 public void setShowMonthYearPicker(boolean showMonthYearPicker) { 264 this.showMonthYearPicker = showMonthYearPicker; 265 } 266 267 272 public void setShowSeconds(boolean showSeconds) { 273 this.showSeconds = showSeconds; 274 } 275 276 281 public void setDateSeparator(String dateSeparator) { 282 this.dateSeparator = dateSeparator; 283 } 284 } 285 | Popular Tags |