1 package org.javabb.transaction; 2 3 import java.io.File ; 4 import java.io.FileInputStream ; 5 import java.io.FileOutputStream ; 6 import java.io.IOException ; 7 import java.util.ArrayList ; 8 import java.util.LinkedList ; 9 import java.util.List ; 10 import java.util.Properties ; 11 12 import org.javabb.dao.entity.ICategoryDAO; 13 import org.javabb.dao.entity.IForumDAO; 14 import org.javabb.dao.entity.IPostDAO; 15 import org.javabb.dao.entity.IRefreshStatsDAO; 16 import org.javabb.dao.entity.ITopicDAO; 17 import org.javabb.dao.entity.IUserRankDAO; 18 import org.javabb.infra.Configuration; 19 import org.javabb.infra.ConfigurationFactory; 20 import org.javabb.vh.ForumConfigView; 21 import org.javabb.vo.Category; 22 import org.javabb.vo.Forum; 23 import org.javabb.vo.Post; 24 import org.javabb.vo.Topic; 25 26 41 42 48 public class ForumTransaction extends Transaction { 49 50 private IForumDAO _forumDAO; 51 52 private ICategoryDAO _categoryDAO; 53 54 private UserTransaction _userTransaction; 55 56 private IRefreshStatsDAO _refreshStatsDAO; 57 58 private IUserRankDAO _userRankDAO; 59 60 private ITopicDAO _topicDAO; 61 62 private IPostDAO _postDAO; 63 64 public void setForumDAO(IForumDAO forumDAO) { 65 this._forumDAO = forumDAO; 66 } 67 68 public void setCategoryDAO(ICategoryDAO categoryDAO) { 69 this._categoryDAO = categoryDAO; 70 } 71 72 public void setUserTransaction(UserTransaction userTransaction) { 73 _userTransaction = userTransaction; 74 } 75 76 public void setUserRankDAO(IUserRankDAO rankDAO) { 77 _userRankDAO = rankDAO; 78 } 79 80 83 public void setRefreshStatsDAO(IRefreshStatsDAO refreshStatsDAO) { 84 _refreshStatsDAO = refreshStatsDAO; 85 } 86 87 public void setTopicDAO(ITopicDAO topicDAO) { 88 this._topicDAO = topicDAO; 89 } 90 91 public void setPostDAO(IPostDAO postDAO) { 92 this._postDAO = postDAO; 93 } 94 95 99 public Forum loadForum(Long id) { 100 return _forumDAO.load(id); 101 } 102 103 109 public List findAll() throws Exception { 110 return _forumDAO.findAll(); 111 } 112 113 121 public List findAll(Category category) throws Exception { 122 return _forumDAO.findByCategory(category.getId()); 123 } 124 125 129 public Long findNroTotalForuns() throws Exception { 130 return new Long (_forumDAO.countAllForums()); 131 } 132 133 139 public void deleteForum(Forum forum) throws Exception { 140 _forumDAO.deleteForum(forum); 141 } 142 143 148 public void transferForum(Forum forum, int forumTo) throws Exception { 149 _forumDAO.transferForum(forum, forumTo); 150 } 151 152 157 public void refreshForum(Long forumId) { 158 if(forumId != null){ 159 _refreshStatsDAO.refreshForum(forumId); 160 } 161 } 162 163 168 public void refreshTopic(Long topicId) { 169 if (topicId != null) { 170 _refreshStatsDAO.refreshTopic(topicId); 171 172 } 173 } 174 175 180 public void refreshPost(Long postId) { 181 if (postId != null) { 182 _refreshStatsDAO.refreshPost(postId); 183 } 184 } 185 186 189 public void update(Long forumId, Forum forum) { 190 Forum forumToUpdate = this.loadForum(forumId); 191 forumToUpdate.setDescricao(forum.getDescricao()); 192 forumToUpdate.setCategory(forum.getCategory()); 193 forumToUpdate.setNome(forum.getNome()); 194 } 195 196 202 public Forum insertForum(Forum forum) { 203 Integer orderForum = new Integer (_forumDAO.countAllForums() + 1); 204 forum.setForumOrder(orderForum); 205 forum.setForumStatus(new Integer (0)); 206 forum = _forumDAO.insertForum(forum); 207 208 return forum; 209 } 210 211 216 public List listButtons() { 217 List languages = new ArrayList (); 218 219 String btnPath = Configuration.realPath + File.separator + "forum" 220 + File.separator + "images" + File.separator + "buttons"; 221 222 File [] btnDir = new File (btnPath).listFiles(); 223 for (int i = 0; i < btnDir.length; i++) { 224 String btnDirName = btnDir[i].getName(); 225 if (!"CVS".equalsIgnoreCase(btnDirName)) { 226 languages.add(btnDirName); 227 } 228 } 229 230 return languages; 231 } 232 233 238 public void saveConfigForum(ForumConfigView forum) { 239 try { 240 Properties properties = new Properties (); 241 242 String javabbProperties = Configuration.realPath + File.separator 243 + "WEB-INF" + File.separator + "appconf" + File.separator 244 + "javabb.properties"; 245 246 properties.load(new FileInputStream (javabbProperties)); 247 FileOutputStream out = new FileOutputStream (javabbProperties); 248 249 251 String url = forum.getDomain(); 252 if ("/".equals(url.substring(url.length() - 1, url.length()))) { 253 properties.put("config.forum.domain", forum.getDomain()); 254 } else { 255 properties.put("config.forum.domain", forum.getDomain() + "/"); 256 } 257 properties.put("config.forum.forum.name", forum.getForumName()); 258 properties.put("config.forum.date.format", forum.getDateFormat()); 259 properties.put("config.forum.time.format", forum.getTimeFormat()); 260 properties.put("config.forum.topics.page", forum.getTopicsPage()); 261 properties.put("config.forum.posts.page", forum.getPostsPage()); 262 properties.put("config.forum.button.lang", forum.getButtonLang()); 263 264 properties.put("config.forum.admin.mail", forum.getAdminMail()); 265 properties.put("config.email.notify.topic", forum.getNotifyTopic()); 266 properties.put("config.forum.smtp.server.host", forum.getSmtpHost()); 267 properties.put("config.forum.smtp.server.user", forum.getSmtpUser()); 268 properties.put("config.forum.smtp.server.senha", forum.getSmtpPassword()); 269 properties.put("config.forum.flood_control", forum.getFloodControl()); 270 properties.put("config.forum.posts.announce.text", forum.getForumAnnounceText()); 271 272 properties.store(out, "JavaBB Property File"); 273 out.close(); 274 275 ConfigurationFactory.refreshConfig(); 277 278 } catch (IOException e) { 279 e.printStackTrace(); 280 } 281 } 282 283 294 public void sortForuns(Long idCategory, Integer destOrder, Integer position) 295 throws Exception { 296 297 List foruns = _forumDAO.findByCategoryOrderAsc(idCategory); 298 LinkedList sortForum = new LinkedList (); 299 for (int i = 0; i < foruns.size(); i++) { 300 Forum forumAdd = (Forum) foruns.get(i); 301 forumAdd.setForumOrder(new Integer (i)); 302 sortForum.add(forumAdd); 303 } 304 305 foruns.clear(); 307 foruns = null; 308 309 Forum t = (Forum) sortForum.get(position.intValue()); 310 311 sortForum.remove(position.intValue()); 312 sortForum.add(destOrder.intValue(), t); 313 314 Forum forumUpd = null; 315 for (int i = 0; i < sortForum.size(); i++) { 316 Forum forum = (Forum) sortForum.get(i); 317 forumUpd = new Forum(); 320 forumUpd = _forumDAO.load(forum.getIdForum()); 321 forumUpd.setForumOrder(new Integer (i)); 322 } 323 324 sortForum.clear(); 326 sortForum = null; 327 } 328 329 332 public void setUnreadForumIds() throws Exception { 333 344 } 345 346 347 351 public void refreshForumUserRank() throws Exception { 352 _userRankDAO.cleanAllUserRank(); 353 List forums = findAll(); 354 for(int i=0; i<forums.size(); i++){ 355 Forum forum = (Forum) forums.get(i); 356 _userRankDAO.refreshUserRankByForum(forum.getId()); 357 } 358 } 359 360 }
| Popular Tags
|