1 81 package com.ivata.groupware.web.tree.comment; 82 83 import java.util.Properties ; 84 85 import javax.servlet.http.HttpServletRequest ; 86 import javax.servlet.http.HttpSession ; 87 import javax.servlet.jsp.JspException ; 88 import javax.servlet.jsp.JspWriter ; 89 import javax.servlet.jsp.PageContext ; 90 91 import com.ivata.groupware.admin.security.server.SecuritySession; 92 import com.ivata.groupware.admin.setting.Settings; 93 import com.ivata.groupware.admin.setting.SettingsDataTypeException; 94 import com.ivata.groupware.business.library.comment.CommentDO; 95 import com.ivata.groupware.business.library.right.LibraryRights; 96 import com.ivata.groupware.util.SettingDateFormatter; 97 import com.ivata.groupware.web.tree.DefaultTreeNodeRenderer; 98 import com.ivata.groupware.web.tree.TreeNode; 99 import com.ivata.mask.util.SystemException; 100 import com.ivata.mask.web.format.CharacterEntityFormat; 101 import com.ivata.mask.web.format.DateFormatterException; 102 import com.ivata.mask.web.format.FormatConstants; 103 import com.ivata.mask.web.format.HTMLFormatter; 104 import com.ivata.mask.web.format.LineBreakFormat; 105 106 107 121 public class CommentTreeNodeRenderer extends DefaultTreeNodeRenderer { 122 123 126 private CharacterEntityFormat characterEntityFormat = new CharacterEntityFormat(); 127 128 131 private SettingDateFormatter dateFormatter; 132 133 138 private LibraryRights libraryRights; 139 140 143 private LineBreakFormat lineBreakFormat = new LineBreakFormat(); 144 145 148 private Settings settings; 149 156 int threadNumber = 0; 157 SecuritySession securitySession; 158 159 162 public CommentTreeNodeRenderer(SecuritySession securitySession, 163 SettingDateFormatter dateFormatter, LibraryRights 164 libraryRights, Settings settings) { 165 this.securitySession = securitySession; 166 this.dateFormatter = dateFormatter; 167 this.libraryRights = libraryRights; 168 this.settings = settings; 169 } 170 171 185 public void finalize(final HttpSession session, 186 final HttpServletRequest request, 187 final JspWriter out) throws JspException { 188 try { 189 out.print(getTreeTag().getTheme().parseSection("finalizeCommentTree", 190 new Properties ())); 191 } catch (java.io.IOException e) { 192 throw new JspException (e); 193 } 194 195 super.finalize(session, request, out); 196 } 197 198 207 public final SettingDateFormatter getDateFormatter() { 208 return dateFormatter; 209 } 210 211 228 public void initialize(final HttpSession session, 229 final HttpServletRequest request, 230 final JspWriter out, 231 final PageContext pageContext) throws JspException { 232 try { 233 out.print(getTreeTag().getTheme().parseSection("initializeCommentTree", 234 new Properties ())); 235 } catch (java.io.IOException e) { 236 throw new JspException (e); 237 } 238 239 super.initialize(session, request, out, pageContext); 240 241 lineBreakFormat.setConvertLineBreaks(true); 243 } 244 245 259 public Properties setAdditionalProperties(final TreeNode treeNode, 260 final int level, 261 final Properties properties) throws JspException { 262 HTMLFormatter formatter = new HTMLFormatter(); 264 CommentDO commentDO = (CommentDO) treeNode; 265 266 try { 268 if (libraryRights.canAmendComment(securitySession, commentDO)) { 269 properties.setProperty("canUserEdit", "true"); 270 } 271 } catch (SystemException e) { 272 throw new RuntimeException (e); 273 } 274 275 if (commentDO.getFormat() == FormatConstants.FORMAT_TEXT) { 278 formatter.add(characterEntityFormat); 279 formatter.add(lineBreakFormat); 280 } 281 282 properties.setProperty("commentSubject", 283 formatter.format(commentDO.getSubject())); 284 properties.setProperty("commentText", 285 formatter.format(commentDO.getText())); 286 properties.setProperty("commentUserName", commentDO.getCreatedBy().getName()); 287 288 try { 289 properties.setProperty("commentModified", 290 dateFormatter.format(commentDO.getModified())); 291 } catch (DateFormatterException e1) { 292 throw new RuntimeException (e1); 293 } 294 295 try { 297 properties.setProperty("spacer", 298 new Integer ( 299 level * settings.getIntegerSetting(securitySession, 300 "libraryCommentSpacer", 301 securitySession.getUser()).intValue()).toString()); 302 } catch (SettingsDataTypeException e) { 303 throw new JspException (e); 304 } catch (SystemException e) { 305 throw new JspException (e); 306 } 307 308 String threadClass; 312 313 if ((threadNumber % 2) == 0) { 314 if ((level % 2) == 0) { 315 threadClass = "commentEvenThreadEvenReply"; 316 } else { 317 threadClass = "commentEvenThreadOddReply"; 318 } 319 } else if ((level % 2) == 0) { 320 threadClass = "commentOddThreadEvenReply"; 321 } else { 322 threadClass = "commentOddThreadOddReply"; 323 } 324 325 properties.setProperty("threadClass", threadClass); 326 327 if (level == 0) { 329 ++threadNumber; 330 } 331 332 return properties; 333 } 334 } 335 | Popular Tags |