View Javadoc
1 //============================================================================== 2 // file : ClassCMD.java 3 // project: East Networks News System 4 // 5 // last change: date: $Date: 2003/09/10 09:28:37 $ 6 // by: $Author: bitiboy $ 7 // revision: $Revision: 1.1 $ 8 //------------------------------------------------------------------------------ 9 // copyright: GNU GPL Software License (see class documentation) 10 //============================================================================== 11 package net.eastol.news.command; 12 13 14 /* 15 * $Id: ClassCMD.java,v 1.1 2003/09/10 09:28:37 bitiboy Exp $ 16 * 17 * Copyright 2003 Acai Software All Rights Reserved. 18 * 19 * This file ClassCMD.java is part of the East Networks News System. 20 21 * The East Networks News System is free software; you can redistribute it and/or modify 22 * it under the terms of the GNU General Public License as published by 23 * the Free Software Foundation; either version 2 of the License, or 24 * (at your option) any later version. 25 26 * East Networks News System is distributed in the hope that it will be useful, 27 * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 * GNU General Public License for more details. 30 31 * You should have received a copy of the GNU General Public License 32 * along with the East Networks News System; if not, write to the Free Software 33 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 34 35 * http://www.justhis.com http://ejb.cn 36 * CONTACT: email = webmaster@justhis.com superaxis@sohu.com 37 */ 38 import com.justhis.jdo.JDOUtil; 39 40 import com.justhis.util.exception.LogicException; 41 import com.justhis.util.exception.UtilException; 42 43 import net.eastol.news.common.CommonCommand; 44 import net.eastol.news.jdo.bean.NewsClass; 45 import net.eastol.news.jdo.bean.NewsSys; 46 import net.eastol.news.jibx.bean.NewsCommonXML; 47 48 import java.sql.SQLException; 49 50 import java.util.Date; 51 52 import javax.jdo.Transaction; 53 54 import javax.servlet.ServletException; 55 56 57 /*** 58 * TODO DOCUMENT ME! 59 * 60 * @author <a href="http://blog.ejb.cn">acai</a> 61 * @version $Revision $ 62 */ 63 public class ClassCMD extends CommonCommand { 64 //~ Methods ---------------------------------------------------------------- 65 66 /*** 67 * TODO DOCUMENT ME! 68 * 69 * @return TODO 70 */ 71 public String getName() { 72 return null; 73 } 74 75 /*** 76 * TODO DOCUMENT ME! 77 * 78 * @return TODO 79 * 80 * @throws LogicException TODO 81 * @throws SQLException TODO 82 * @throws ServletException TODO 83 * @throws UtilException TODO 84 */ 85 public String execute() 86 throws LogicException, SQLException, ServletException, 87 UtilException { 88 if ("AddClass".equals(action)) { 89 this.AddClass(); 90 } else if ("AdminClass".equals(action)) { 91 this.showClassList(); 92 } else if ("DeleteClass".equals(action)) { 93 this.deleteClass(); 94 } else if ("ModifyClass".equals(action)) { 95 this.modifyClass(); 96 } else if ("UpdateClass".equals(action)) { 97 this.updateClass(); 98 } else if ("UpOrderClass".equals(action)) { 99 this.upOrder(); 100 } else if ("DownOrderClass".equals(action)) { 101 this.downOrder(); 102 } else if ("AddNClass".equals(action)) { 103 this.addNClass(); 104 } else if ("AddNClassForm".equals(action)) { 105 this.showAddNClassForm(); 106 } else if ("AdminChildren".equals(action)) { 107 this.adminChildren(); 108 } 109 110 return null; 111 } 112 113 /*** 114 * TODO DOCUMENT ME! 115 * 116 * @throws ServletException TODO 117 * @throws UtilException TODO 118 * @throws SQLException TODO 119 * @throws LogicException TODO 120 */ 121 private void AddClass() 122 throws ServletException, UtilException, SQLException, 123 LogicException { 124 NewsClass nc = new NewsClass(); 125 System.out.println("Now add News class"); 126 nc.setClassName(xp.getProperty("className")); 127 nc.setNewsClassId(this.getDBSequence()); 128 nc.setListStyle(xp.getIntProperty("listStyle")); 129 nc.setStyleId(xp.getIntProperty("styleId")); 130 nc.setLogo(xp.getProperty("logo")); 131 nc.setNewsAd(xp.getProperty("newsAd")); 132 nc.setHeadAd(xp.getProperty("headAd")); 133 nc.setLastUpdate(new Date()); 134 135 /* try { 136 JibxUtil.marshallDocument(nc, "asdf.xslt", "asdf.xml"); 137 } catch (FileNotFoundException e) { 138 139 e.printStackTrace(); 140 } catch (JiBXException e) { 141 throw new LogicException(e); 142 }*/ 143 Transaction trans = getTransaction(); 144 trans.begin(); 145 146 NewsSys ns = (NewsSys) JDOUtil.findObjectById(trans, NewsSys.class, 147 systemOID 148 ); 149 ns.addClass(nc); 150 trans.commit(); 151 System.out.println("????????class:"); 152 153 this.printClassList(ns); 154 155 NewsCommonXML ncx = new NewsCommonXML(); 156 ncx.setMsg("Succsessful!"); 157 158 this.go(ncx, this.getXsltFileFromUrl()); 159 } 160 161 /*** 162 * TODO DOCUMENT ME! 163 * 164 * @throws UtilException TODO 165 * @throws SQLException TODO 166 * @throws LogicException TODO 167 * @throws ServletException TODO 168 */ 169 private void addNClass() 170 throws UtilException, SQLException, LogicException, 171 ServletException { 172 NewsClass nc = new NewsClass(); 173 System.out.println("Now add News class"); 174 nc.setClassName(xp.getProperty("className")); 175 nc.setNewsClassId(this.getDBSequence()); 176 nc.setListStyle(xp.getIntProperty("listStyle")); 177 nc.setStyleId(xp.getIntProperty("styleId")); 178 nc.setLogo(xp.getProperty("logo")); 179 nc.setNewsAd(xp.getProperty("newsAd")); 180 nc.setHeadAd(xp.getProperty("headAd")); 181 nc.setLastUpdate(new Date()); 182 183 //nc.setParentClassId(xp.getLongProperty("parentClassId")); 184 String classId = xp.getProperty("parentClassId"); 185 Transaction trans = getTransaction(); 186 trans.begin(); 187 188 NewsClass parent = (NewsClass) JDOUtil.findObjectById(trans, 189 NewsClass.class, 190 classId 191 ); 192 parent.addChild(nc); 193 194 trans.commit(); 195 196 this.printClassList(); 197 198 this.showSuccessAddNClassForm(); 199 } 200 201 /*** 202 * TODO DOCUMENT ME! 203 * 204 * @throws UtilException TODO 205 * @throws SQLException TODO 206 * @throws LogicException TODO 207 * @throws ServletException TODO 208 */ 209 private void adminChildren() 210 throws UtilException, SQLException, LogicException, 211 ServletException { 212 NewsClass nc = (NewsClass) JDOUtil.findObjectById(getPM(), 213 NewsClass.class, 214 xp.getProperty("objId") 215 ); 216 NewsCommonXML ncx = new NewsCommonXML(); 217 ncx.setClassCollection(nc.getChildList()); 218 this.go(nc); 219 } 220 221 /*** 222 * TODO DOCUMENT ME! 223 * 224 * @throws UtilException TODO 225 * @throws SQLException TODO 226 * @throws LogicException TODO 227 * @throws ServletException TODO 228 */ 229 private void deleteClass() 230 throws UtilException, SQLException, LogicException, 231 ServletException { 232 Transaction trans = getTransaction(); 233 234 trans.begin(); 235 236 NewsSys ns = (NewsSys) JDOUtil.findObjectById(trans, NewsSys.class, 237 systemOID 238 ); 239 240 NewsClass nc = (NewsClass) JDOUtil.findObjectById(trans, 241 NewsClass.class, 242 xp.getProperty("objId") 243 ); 244 ns.deleteClass(nc); 245 246 /*trans.getPersistenceManager().refresh(nc); 247 JDOUtil.deleteObject(trans, NewsClass.class,xp.getProperty("objId"));*/ 248 trans.commit(); 249 250 this.printClassList(); 251 252 showClassList(); 253 } 254 255 /*** 256 * TODO DOCUMENT ME! 257 * 258 * @throws UtilException TODO 259 * @throws SQLException TODO 260 * @throws LogicException TODO 261 * @throws ServletException TODO 262 */ 263 private void downOrder() 264 throws UtilException, SQLException, LogicException, 265 ServletException { 266 Transaction trans = getTransaction(); 267 268 try { 269 trans.begin(); 270 271 NewsClass nc; 272 nc = (NewsClass) JDOUtil.findObjectById(trans, NewsClass.class, 273 xp.getProperty("objId") 274 ); 275 nc.setOrderId(nc.getOrderId() - 1); 276 277 trans.commit(); 278 } catch (UtilException e) { 279 try { 280 trans.rollback(); 281 } catch (Exception ex) { 282 } 283 284 throw e; 285 } catch (Exception e) { 286 throw new LogicException("happen unkown Exception from transaction", 287 e 288 ); 289 } 290 291 this.printClassList(); 292 293 showClassList(); 294 } 295 296 /*** 297 * TODO DOCUMENT ME! 298 * 299 * @throws ServletException TODO 300 * @throws UtilException TODO 301 * @throws SQLException TODO 302 * @throws LogicException TODO 303 */ 304 private void modifyClass() 305 throws ServletException, UtilException, SQLException, 306 LogicException { 307 this.go(JDOUtil.findObjectById(getPM(), NewsClass.class, 308 xp.getProperty("objId") 309 ), "AdminClassAdd.xsl" 310 ); 311 } 312 313 /*** 314 * TODO DOCUMENT ME! 315 * 316 * @throws UtilException TODO 317 * @throws SQLException TODO 318 * @throws LogicException TODO 319 * @throws ServletException TODO 320 */ 321 private void showAddNClassForm() 322 throws UtilException, SQLException, LogicException, 323 ServletException { 324 NewsSys ns = (NewsSys) JDOUtil.findObjectById(this.getPM(), 325 NewsSys.class, systemOID 326 ); 327 this.getPM().refresh(ns); 328 329 NewsCommonXML ncx = new NewsCommonXML(); 330 331 ncx.setClassCollection(ns.getClassList()); 332 this.go(ncx, "AdminNclassAdd.xsl"); 333 } 334 335 /*** 336 * TODO DOCUMENT ME! 337 * 338 * @throws UtilException TODO 339 * @throws SQLException TODO 340 * @throws LogicException TODO 341 * @throws ServletException TODO 342 */ 343 private void showClassList() 344 throws UtilException, SQLException, LogicException, 345 ServletException { 346 NewsSys ns = (NewsSys) JDOUtil.findObjectById(this.getPM(), 347 NewsSys.class, systemOID 348 ); 349 NewsCommonXML ncx = new NewsCommonXML(); 350 351 ncx.setClassCollection(ns.getClassList()); 352 this.go(ncx, this.getXsltFileFromUrl()); 353 354 /* NewsCommonXML ncx = new NewsCommonXML(); 355 356 ncx.setClassCollection(JDOUtil.findObjList(getPM(), NewsClass.class, 357 "orderId descending")); 358 this.go(ncx, this.getXsltFileFromUrl());*/ 359 } 360 361 /*** 362 * TODO DOCUMENT ME! 363 * 364 * @throws UtilException TODO 365 * @throws SQLException TODO 366 * @throws LogicException TODO 367 * @throws ServletException TODO 368 */ 369 private void showSuccessAddNClassForm() 370 throws UtilException, SQLException, 371 LogicException, ServletException { 372 NewsSys ns = (NewsSys) JDOUtil.findObjectById(this.getPM(), 373 NewsSys.class, systemOID 374 ); 375 NewsCommonXML ncx = new NewsCommonXML(); 376 ncx.setMsg("Successful!"); 377 ncx.setClassCollection(ns.getClassList()); 378 this.go(ncx, "AdminNclassAdd.xsl"); 379 } 380 381 /*** 382 * TODO DOCUMENT ME! 383 * 384 * @throws UtilException TODO 385 * @throws SQLException TODO 386 * @throws LogicException TODO 387 * @throws ServletException TODO 388 */ 389 private void upOrder() 390 throws UtilException, SQLException, LogicException, 391 ServletException { 392 Transaction trans = getTransaction(); 393 394 try { 395 trans.begin(); 396 397 NewsClass nc; 398 nc = (NewsClass) JDOUtil.findObjectById(trans, NewsClass.class, 399 xp.getProperty("objId") 400 ); 401 nc.setOrderId(nc.getOrderId() + 1); 402 403 trans.commit(); 404 } catch (UtilException e) { 405 try { 406 trans.rollback(); 407 } catch (Exception ex) { 408 } 409 410 throw e; 411 } catch (Exception e) { 412 throw new LogicException("happen unkown Exception from transaction", 413 e 414 ); 415 } 416 417 this.printClassList(); 418 419 showClassList(); 420 } 421 422 /*** 423 * TODO DOCUMENT ME! 424 * 425 * @throws UtilException TODO 426 * @throws SQLException TODO 427 * @throws LogicException TODO 428 * @throws ServletException TODO 429 */ 430 private void updateClass() 431 throws UtilException, SQLException, LogicException, 432 ServletException { 433 Transaction trans = getTransaction(); 434 435 trans.begin(); 436 437 NewsClass nc; 438 nc = (NewsClass) JDOUtil.findObjectById(trans.getPersistenceManager(), 439 NewsClass.class, 440 xp.getProperty("objId") 441 ); 442 443 // findObjectById(trans, xp.getProperty("objId")); 444 nc.setClassName(xp.getProperty("className")); 445 nc.setNewsClassId(this.getDBSequence()); 446 nc.setListStyle(xp.getIntProperty("listStyle")); 447 nc.setStyleId(xp.getIntProperty("styleId")); 448 nc.setLogo(xp.getProperty("logo")); 449 nc.setNewsAd(xp.getProperty("newsAd")); 450 nc.setHeadAd(xp.getProperty("headAd")); 451 452 trans.commit(); 453 454 this.printClassList(); 455 showClassList(); 456 } 457 } 458 459 460 /* 461 * $Log: ClassCMD.java,v $ 462 * Revision 1.1 2003/09/10 09:28:37 bitiboy 463 * *** empty log message *** 464 * 465 * 466 */

This page was automatically generated by Maven