001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/RankXML.java,v 1.10 2007/10/09 11:09:14 lexuanttkhtn Exp $
003: * $Author: lexuanttkhtn $
004: * $Revision: 1.10 $
005: * $Date: 2007/10/09 11:09:14 $
006: *
007: * ====================================================================
008: *
009: * Copyright (C) 2002-2007 by MyVietnam.net
010: *
011: * All copyright notices regarding mvnForum MUST remain
012: * intact in the scripts and in the outputted HTML.
013: * The "powered by" text/logo with a link back to
014: * http://www.mvnForum.com and http://www.MyVietnam.net in
015: * the footer of the pages MUST remain visible when the pages
016: * are viewed on the internet or intranet.
017: *
018: * This program is free software; you can redistribute it and/or modify
019: * it under the terms of the GNU General Public License as published by
020: * the Free Software Foundation; either version 2 of the License, or
021: * any later version.
022: *
023: * This program is distributed in the hope that it will be useful,
024: * but WITHOUT ANY WARRANTY; without even the implied warranty of
025: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
026: * GNU General Public License for more details.
027: *
028: * You should have received a copy of the GNU General Public License
029: * along with this program; if not, write to the Free Software
030: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
031: *
032: * Support can be obtained from support forums at:
033: * http://www.mvnForum.com/mvnforum/index
034: *
035: * Correspondence and Marketing Questions can be sent to:
036: * info at MyVietnam net
037: *
038: * @author: Igor Manic
039: */
040: package com.mvnforum.admin;
041:
042: import java.io.IOException;
043: import java.util.*;
044:
045: import com.mvnforum.admin.importexport.XMLUtil;
046: import com.mvnforum.admin.importexport.XMLWriter;
047: import com.mvnforum.db.DAOFactory;
048: import com.mvnforum.db.RankDAO;
049: import net.myvietnam.mvncore.exception.*;
050: import net.myvietnam.mvncore.filter.DisableHtmlTagFilter;
051: import net.myvietnam.mvncore.filter.EnableHtmlTagFilter;
052:
053: /**
054: * @author Igor Manic
055: * @version $Revision: 1.10 $, $Date: 2007/10/09 11:09:14 $
056: * <br/>
057: * <code>RankXML</code> todo Igor: enter description
058: *
059: */
060: public class RankXML {
061:
062: private int rankID;
063:
064: /** Returns <code>RankID</code> of this rank or
065: * <code>-1</code> if rank is not created yet. */
066: public int getRankID() {
067: return rankID;
068: }
069:
070: public RankXML() {
071: super ();
072: rankID = -1;
073: }
074:
075: public void setRankID(String id) {
076: rankID = XMLUtil.stringToIntDef(id, -1);
077: }
078:
079: /**
080: * Creates a rank. All argument values (<code>int</code>s, <code>Timestamp</code>s, ...)
081: * are represented as <code>String</code>s, because of more convenient using
082: * of this method for XML parsing.
083: *
084: * @param rankMinPosts Minimal number of posts needed to achieve this rank.
085: * @param rankLevel Can be null.
086: * @param rankTitle Title of this rank ("Stranger", "Newbie", ...).
087: * @param rankImage Can be null.
088: * @param rankType Can be null.
089: * @param rankOption Can be null.
090: *
091: * @throws CreateException
092: * @throws DuplicateKeyException
093: * @throws ObjectNotFoundException
094: * @throws DatabaseException
095: * @throws ForeignKeyNotFoundException
096: *
097: */
098: public void addRank(String rankMinPosts, String rankLevel,
099: String rankTitle, String rankImage, String rankType,
100: String rankOption) throws CreateException,
101: DuplicateKeyException, ObjectNotFoundException,
102: DatabaseException {
103:
104: if ((rankMinPosts == null) || (rankMinPosts.length() <= 0)
105: || (rankTitle == null) || (rankTitle.length() <= 0)) {
106: throw new CreateException(
107: "Not enough data to create a rank.");
108: } else {
109: int rankMinPosts1;
110: int rankLevel1;
111: int rankType1;
112: int rankOption1;
113: try {
114: rankMinPosts1 = XMLUtil.stringToIntDef(rankMinPosts, 0);
115: rankLevel1 = XMLUtil.stringToIntDef(rankLevel, 0);
116: if (rankImage == null)
117: rankImage = "";
118: rankType1 = XMLUtil.stringToIntDef(rankType, 0);
119: rankOption1 = XMLUtil.stringToIntDef(rankOption, 0);
120: } catch (NumberFormatException e) {
121: throw new CreateException(
122: "Invalid data for a rank. Expected a number.");
123: }
124:
125: rankTitle = EnableHtmlTagFilter.filter(rankTitle);
126: rankImage = EnableHtmlTagFilter.filter(rankImage);
127: DAOFactory.getRankDAO().create(rankMinPosts1, rankLevel1,
128: rankTitle, rankImage, rankType1, rankOption1);
129:
130: this .rankID = DAOFactory.getRankDAO()
131: .getRankIDFromRankTitle(rankTitle);
132: }
133: }
134:
135: // ===============================================================
136: // ==================== STATIC EXPORT METHODS ====================
137: // ===============================================================
138: public static void exportRankList(XMLWriter xmlWriter)
139: throws IOException, ExportException, DatabaseException {
140:
141: Collection ranks = ExportWebHelper
142: .execSqlQuery("SELECT RankMinPosts, RankLevel, RankTitle, RankImage, RankType, RankOption"
143: + " FROM " + RankDAO.TABLE_NAME);
144: Iterator iter = ranks.iterator();
145: String[] rank = null;
146: //try {
147: xmlWriter.startElement("RankList");
148: try {
149: while ((rank = (String[]) iter.next()) != null) {
150: if (rank.length != 6) {
151: throw new ExportException(
152: "Error while retrieving list of ranks.");
153: }
154: xmlWriter.startElement("Rank");
155: xmlWriter.startElement("RankMinPosts");
156: xmlWriter.writeData(rank[0]);
157: xmlWriter.endElement("RankMinPosts");
158: xmlWriter.startElement("RankLevel");
159: xmlWriter.writeData(rank[1]);
160: xmlWriter.endElement("RankLevel");
161: xmlWriter.startElement("RankTitle");
162: xmlWriter.writeData(DisableHtmlTagFilter
163: .filter(rank[2]));
164: xmlWriter.endElement("RankTitle");
165: xmlWriter.startElement("RankImage");
166: xmlWriter.writeData(DisableHtmlTagFilter
167: .filter(rank[3]));
168: xmlWriter.endElement("RankImage");
169: xmlWriter.startElement("RankType");
170: xmlWriter.writeData(rank[4]);
171: xmlWriter.endElement("RankType");
172: xmlWriter.startElement("RankOption");
173: xmlWriter.writeData(rank[5]);
174: xmlWriter.endElement("RankOption");
175: xmlWriter.endElement("Rank");
176: }
177: } catch (NoSuchElementException e) {
178: //no more database records
179: }
180: xmlWriter.endElement("RankList");
181: //} catch throw exportexception
182: }
183: }
|