KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mvnforum > admin > RankXML


1 /*
2  * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/RankXML.java,v 1.8 2006/04/14 17:36:29 minhnn Exp $
3  * $Author: minhnn $
4  * $Revision: 1.8 $
5  * $Date: 2006/04/14 17:36:29 $
6  *
7  * ====================================================================
8  *
9  * Copyright (C) 2002-2006 by MyVietnam.net
10  *
11  * All copyright notices regarding mvnForum MUST remain
12  * intact in the scripts and in the outputted HTML.
13  * The "powered by" text/logo with a link back to
14  * http://www.mvnForum.com and http://www.MyVietnam.net in
15  * the footer of the pages MUST remain visible when the pages
16  * are viewed on the internet or intranet.
17  *
18  * This program is free software; you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation; either version 2 of the License, or
21  * any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program; if not, write to the Free Software
30  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31  *
32  * Support can be obtained from support forums at:
33  * http://www.mvnForum.com/mvnforum/index
34  *
35  * Correspondence and Marketing Questions can be sent to:
36  * info at MyVietnam net
37  *
38  * @author: Igor Manic
39  */

40 package com.mvnforum.admin;
41
42 import java.io.IOException JavaDoc;
43 import java.util.*;
44
45 import com.mvnforum.admin.importexport.XMLUtil;
46 import com.mvnforum.admin.importexport.XMLWriter;
47 import com.mvnforum.db.DAOFactory;
48 import com.mvnforum.db.RankDAO;
49 import net.myvietnam.mvncore.exception.*;
50 import net.myvietnam.mvncore.filter.DisableHtmlTagFilter;
51 import net.myvietnam.mvncore.filter.EnableHtmlTagFilter;
52
53 /**
54  * @author Igor Manic
55  * @version $Revision: 1.8 $, $Date: 2006/04/14 17:36:29 $
56  * <br/>
57  * <code>RankXML</code> todo Igor: enter description
58  *
59  */

60 public class RankXML {
61
62     private int rankID;
63     /** Returns <code>RankID</code> of this rank or
64       * <code>-1</code> if rank is not created yet. */

65     public int getRankID() { return rankID; }
66
67     public RankXML() {
68         super();
69         rankID=-1;
70     }
71
72     public void setRankID(String JavaDoc id) {
73         rankID=XMLUtil.stringToIntDef(id, -1);
74     }
75
76     /**
77      * Creates a rank. All argument values (<code>int</code>s, <code>Timestamp</code>s, ...)
78      * are represented as <code>String</code>s, because of more convenient using
79      * of this method for XML parsing.
80      *
81      * @param rankMinPosts Minimal number of posts needed to achieve this rank.
82      * @param rankLevel Can be null.
83      * @param rankTitle Title of this rank ("Stranger", "Newbie", ...).
84      * @param rankImage Can be null.
85      * @param rankType Can be null.
86      * @param rankOption Can be null.
87      *
88      * @throws CreateException
89      * @throws DuplicateKeyException
90      * @throws ObjectNotFoundException
91      * @throws DatabaseException
92      * @throws ForeignKeyNotFoundException
93      *
94      */

95     public void addRank(String JavaDoc rankMinPosts, String JavaDoc rankLevel,
96                         String JavaDoc rankTitle, String JavaDoc rankImage,
97                         String JavaDoc rankType, String JavaDoc rankOption)
98         throws CreateException, DuplicateKeyException,
99         ObjectNotFoundException, DatabaseException {
100
101         if ((rankMinPosts==null) || (rankMinPosts.length()<=0) ||
102             (rankTitle==null) || (rankTitle.length()<=0)) {
103             throw new CreateException("Not enough data to create a rank.");
104         } else {
105             int rankMinPosts1;
106             int rankLevel1;
107             int rankType1;
108             int rankOption1;
109             try {
110                 rankMinPosts1= XMLUtil.stringToIntDef(rankMinPosts, 0);
111                 rankLevel1= XMLUtil.stringToIntDef(rankLevel, 0);
112                 if (rankImage==null) rankImage="";
113                 rankType1= XMLUtil.stringToIntDef(rankType, 0);
114                 rankOption1= XMLUtil.stringToIntDef(rankOption, 0);
115             } catch (NumberFormatException JavaDoc e) {
116                 throw new CreateException("Invalid data for a rank. Expected a number.");
117             }
118
119             rankTitle=EnableHtmlTagFilter.filter(rankTitle);
120             rankImage=EnableHtmlTagFilter.filter(rankImage);
121             DAOFactory.getRankDAO().create(rankMinPosts1, rankLevel1,
122                                      rankTitle, rankImage,
123                                      rankType1, rankOption1);
124
125             this.rankID=DAOFactory.getRankDAO().getRankIDFromRankTitle(rankTitle);
126         }
127     }
128
129
130 // ===============================================================
131
// ==================== STATIC EXPORT METHODS ====================
132
// ===============================================================
133
public static void exportRankList(XMLWriter xmlWriter)
134         throws IOException JavaDoc, ExportException, DatabaseException {
135
136         Collection ranks=ExportWebHelper.execSqlQuery(
137                    "SELECT RankMinPosts, RankLevel, RankTitle, RankImage, RankType, RankOption"+
138                    " FROM "+RankDAO.TABLE_NAME);
139         Iterator iter=ranks.iterator();
140         String JavaDoc[] rank=null;
141         //try {
142
xmlWriter.startElement("RankList");
143             try {
144                 while ( (rank=(String JavaDoc[])iter.next()) !=null) {
145                     if (rank.length!=6) {
146                         throw new ExportException("Error while retrieving list of ranks.");
147                     }
148                     xmlWriter.startElement("Rank");
149                     xmlWriter.startElement("RankMinPosts");
150                     xmlWriter.writeData(rank[0]);
151                     xmlWriter.endElement("RankMinPosts");
152                     xmlWriter.startElement("RankLevel");
153                     xmlWriter.writeData(rank[1]);
154                     xmlWriter.endElement("RankLevel");
155                     xmlWriter.startElement("RankTitle");
156                     xmlWriter.writeData(DisableHtmlTagFilter.filter(rank[2]));
157                     xmlWriter.endElement("RankTitle");
158                     xmlWriter.startElement("RankImage");
159                     xmlWriter.writeData(DisableHtmlTagFilter.filter(rank[3]));
160                     xmlWriter.endElement("RankImage");
161                     xmlWriter.startElement("RankType");
162                     xmlWriter.writeData(rank[4]);
163                     xmlWriter.endElement("RankType");
164                     xmlWriter.startElement("RankOption");
165                     xmlWriter.writeData(rank[5]);
166                     xmlWriter.endElement("RankOption");
167                     xmlWriter.endElement("Rank");
168                 }
169             } catch (NoSuchElementException e) {
170                 //no more database records
171
}
172             xmlWriter.endElement("RankList");
173          //} catch throw exportexception
174
}
175 }
176
Popular Tags