KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mvnforum > admin > importexport > mvnforum > MvnForumCategoryXML


1 /*
2  * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/importexport/mvnforum/MvnForumCategoryXML.java,v 1.6 2006/04/14 17:36:29 minhnn Exp $
3  * $Author: minhnn $
4  * $Revision: 1.6 $
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.importexport.mvnforum;
41
42 import com.mvnforum.admin.CategoryXML;
43 import net.myvietnam.mvncore.exception.*;
44
45 /**
46  * @author Igor Manic
47  * @version $Revision: 1.6 $, $Date: 2006/04/14 17:36:29 $
48  * <br/>
49  * <code>MvnForumCategoryXML</code> class encapsulates processing of
50  * categories' definitions found in the backup XML file. It implements
51  * methods to be called from XML parsing routine, adds some additional
52  * processing and checking, and calls corresponding methods of
53  * <code>CategoryXML</code> and other neccessary classes in order to perform
54  * the actual creation of a category, as well as other related items (like
55  * category watches).
56  */

57 public class MvnForumCategoryXML {
58
59     private CategoryXML categoryXML=null;
60     private boolean categoryCreated=false;
61     private MvnForumCategoryXML parentCategory=null;
62
63     String JavaDoc categoryName =null;
64     String JavaDoc categoryDesc =null;
65     String JavaDoc categoryCreationDate =null;
66     String JavaDoc categoryModifiedDate =null;
67     String JavaDoc categoryOrder =null;
68     String JavaDoc categoryOption =null;
69     String JavaDoc categoryStatus =null;
70
71     public MvnForumCategoryXML() {
72         super();
73         categoryXML=new CategoryXML();
74         categoryCreated=false;
75         parentCategory=null;
76     }
77
78     public int getCategoryID() {
79         return categoryXML.getCategoryID();
80     }
81
82     public void setCategoryID(String JavaDoc id) {
83         categoryXML.setCategoryID(id);
84     }
85
86     /**
87      * This method simply calls <code>setCategoryID()</code>.
88      * It's defined only to avoid property-setter problems with digester
89      * (since it doesn't seem to recognize <code>setCategoryID()</code> as a setter
90      * method for <code>categoryID</code> property).
91      */

92     public void setCategoryId(String JavaDoc id) {
93         setCategoryID(id);
94     }
95
96     public int getParentCategoryID() {
97         return categoryXML.getParentCategoryID(); //==parentCategory.getCategoryID();
98
}
99
100     public void setParentCategoryIfHave(Object JavaDoc o)
101     throws ForeignKeyNotFoundException {
102         if (o instanceof MvnForumCategoryXML) {
103             parentCategory=(MvnForumCategoryXML)o;
104             /* warning: parent category might not be added to database yet, so
105              * we don't have parentCategoryID now, and can't do this here:
106              * categoryXML.setParentCategoryID(parentCategory.getCategoryID());
107              */

108         } else {
109             //Ignore. Don't have parent category.
110
//throw new ForeignKeyNotFoundException("Can't find parent category.");
111
}
112     }
113
114     public void setCategoryName(String JavaDoc value) {
115         categoryName=value;
116     }
117
118     public void setCategoryDesc(String JavaDoc value) {
119         categoryDesc=value;
120     }
121
122     public void setCategoryCreationDate(String JavaDoc value) {
123         categoryCreationDate=value;
124     }
125
126     public void setCategoryModifiedDate(String JavaDoc value) {
127         categoryModifiedDate=value;
128     }
129
130     public void setCategoryOrder(String JavaDoc value) {
131         categoryOrder=value;
132     }
133
134     public void setCategoryOption(String JavaDoc value) {
135         categoryOption=value;
136     }
137
138     public void setCategoryStatus(String JavaDoc value) {
139         categoryStatus=value;
140     }
141
142     public void addCategory() throws CreateException, DuplicateKeyException,
143     ObjectNotFoundException, DatabaseException, ForeignKeyNotFoundException, BadInputException {
144         /* First, check if the digester already called this method.
145          * It will happen even under normal circumstances, if this category has
146          * subelements that need it already be defined, so they first call
147          * this method to create category before creating data that refer him.
148          */

149         if (categoryCreated) return;
150         /* Second, create parent category if it's not yet created. */
151         if (parentCategory!=null) {
152             parentCategory.addCategory();
153             categoryXML.setParentCategoryID(parentCategory.getCategoryID());
154         }
155
156         ImportMvnForum.addMessage("Adding category \""+categoryName+"\".");
157         categoryXML.addCategory(categoryName, categoryDesc,
158                                 categoryCreationDate, categoryModifiedDate,
159                                 categoryOrder, categoryOption, categoryStatus);
160         categoryCreated=true;
161
162         if (parentCategory!=null) {
163             parentCategory.updateAddedCategory(this);
164         }
165     }
166
167     public void addCategoryWatch(String JavaDoc memberName,
168                 String JavaDoc watchType, String JavaDoc watchOption,
169                 String JavaDoc watchStatus, String JavaDoc watchCreationDate,
170                 String JavaDoc watchLastSentDate, String JavaDoc watchEndDate)
171     throws CreateException, DuplicateKeyException, ObjectNotFoundException,
172     DatabaseException, ForeignKeyNotFoundException, BadInputException {
173         if ( (!categoryCreated) || (categoryXML.getCategoryID()<0) ) {
174             addCategory();
175         }
176         ImportMvnForum.addMessage("Adding category watch for member \""+memberName+"\".");
177         categoryXML.addCategoryWatch(memberName,
178                     watchType, watchOption, watchStatus,
179                     watchCreationDate, watchLastSentDate, watchEndDate);
180     }
181
182     public void updateAddedCategory(MvnForumCategoryXML subCategory) {
183         //do nothing
184
if (parentCategory!=null) {
185             parentCategory.updateAddedCategory(subCategory);
186         }
187     }
188
189     public void updateAddedForum(MvnForumForumXML subForum) {
190         //do nothing
191
if (parentCategory!=null) {
192             parentCategory.updateAddedForum(subForum);
193         }
194     }
195
196     public void updateAddedThread(MvnForumThreadXML subThread) {
197         //do nothing
198
if (parentCategory!=null) {
199             parentCategory.updateAddedThread(subThread);
200         }
201     }
202
203     public void updateAddedPost(MvnForumPostXML subPost) {
204         //do nothing
205
if (parentCategory!=null) {
206             parentCategory.updateAddedPost(subPost);
207         }
208     }
209
210     public void updateAddedAttachment(MvnForumAttachmentXML subAttachment) {
211         //do nothing
212
if (parentCategory!=null) {
213             parentCategory.updateAddedAttachment(subAttachment);
214         }
215     }
216
217
218 }
219
Popular Tags