KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mvnforum > admin > importexport > jive > JiveForumXML


1 /*
2  * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/importexport/jive/JiveForumXML.java,v 1.7 2006/04/14 17:36:29 minhnn Exp $
3  * $Author: minhnn $
4  * $Revision: 1.7 $
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.jive;
41
42 import java.sql.Timestamp JavaDoc;
43
44 import com.mvnforum.admin.*;
45 import net.myvietnam.mvncore.exception.*;
46
47 /**
48  * @author Igor Manic
49  * @version $Revision: 1.7 $, $Date: 2006/04/14 17:36:29 $
50  * <br/>
51  * <code>JiveForumXML</code> class encapsulates processing of
52  * forums' definitions found in the Jive XML file. It implements
53  * methods to be called from XML parsing routine, adds some additional
54  * processing and checking, and calls corresponding methods of
55  * <code>ForumXML</code> and other neccessary classes in order to perform
56  * the actual creation of a forum, as well as assigning forum-specific
57  * premissions to members and groups.
58  */

59 public class JiveForumXML {
60
61     private ForumXML forumXML=null;
62     private boolean forumCreated=false;
63
64     public JiveForumXML() {
65         super();
66         forumXML=new ForumXML();
67         forumCreated=false;
68     }
69
70     public void setForumID(String JavaDoc id) {
71         forumXML.setForumID(id);
72     }
73
74     /**
75      * This method simply calls <code>setForumID()</code>.
76      * It's defined only to avoid property-setter problems with digester
77      * (since it doesn't seem to recognize <code>setForumID()</code> as a setter
78      * method for <code>forumID</code> property).
79      */

80     public void setForumId(String JavaDoc id) {
81         setForumID(id);
82     }
83
84     public int getForumID() { return forumXML.getForumID(); }
85
86     public int getParentCategoryID() {
87         return forumXML.getParentCategoryID();
88     }
89
90     private String JavaDoc forumName=null;
91     public void setForumName(String JavaDoc value) throws CreateException {
92         if ( (value==null) || (value.equals("")) ) {
93             throw new CreateException("Cannot create a forum with an empty ForumName.");
94         }
95         this.forumName=value;
96     }
97
98     private String JavaDoc forumDesc=null;
99     public void setForumDescription(String JavaDoc value) throws CreateException {
100         this.forumDesc=value;
101     }
102
103     private String JavaDoc forumCreationDate=null;
104     public void setForumCreationDate(String JavaDoc value) throws CreateException {
105         this.forumCreationDate=value;
106     }
107
108     private String JavaDoc forumModifiedDate=null;
109     public void setForumModifiedDate(String JavaDoc value) throws CreateException {
110         this.forumModifiedDate=value;
111     }
112
113     public void addJiveForum()
114     throws CreateException, DuplicateKeyException, ObjectNotFoundException,
115     DatabaseException, ForeignKeyNotFoundException {
116         /* First check if the digester already called this method.
117          * It will happen even under normal circumstances, if this forum has
118          * subelements that need it already be defined, so they first call
119          * this method to create forum before creating data that refer him.
120          */

121         if (forumCreated) return;
122         //todo Igor: add checking of JiveXML.rootCategoryID to know whether the root category is created or not
123
if ( (forumName==null) || (forumName.equals("")) ) {
124             throw new CreateException("Cannot create a forum with an empty ForumName.");
125         } else {
126             forumXML.setParentCategoryID(JiveXML.rootCategoryID);
127             String JavaDoc forumPassword=JiveXML.allForumsPassword;
128
129             ImportJive.addMessage("Adding forum \""+forumName+"\".");
130             forumXML.addForum(null/*lastPostMemberName*/, forumName, forumDesc,
131                               forumCreationDate, forumModifiedDate, null/*forumLastPostDate*/,
132                               null/*forumOrder*/, null/*forumType*/, null/*forumFormatOption*/,
133                               null/*forumOption*/, null/*forumStatus*/,
134                               null/*forumModerationMode*/, forumPassword,
135                               null/*forumThreadCount*/, null/*forumPostCount*/);
136             forumCreated=true;
137
138             JiveXML.addedForum(forumXML); //update parents
139
}
140     }
141
142     public void updateAddedThread(ThreadXML threadXML) throws ObjectNotFoundException,
143     DatabaseException {
144         if ((!forumCreated) || (forumXML.getForumID()<0)) return; //todo Igor: process this error
145
forumXML.increaseThreadCount();
146         JiveXML.addedThread(threadXML); //update parent category
147
}
148
149     public void updateAddedPost(PostXML postXML, String JavaDoc postUsername, Timestamp JavaDoc postCreationDate)
150     throws ObjectNotFoundException, DatabaseException, ForeignKeyNotFoundException {
151         if ((!forumCreated) || (forumXML.getForumID()<0)) return; //todo Igor: process this error
152
forumXML.increasePostCount();
153         forumXML.updateLastPostMemberName(postUsername);
154         forumXML.updateLastPostDate(postCreationDate);
155         JiveXML.addedPost(postXML); //update parent category
156
}
157
158     public void addJiveForumUser(String JavaDoc usertype, String JavaDoc username, String JavaDoc jivePermission)
159     throws CreateException, DuplicateKeyException, ObjectNotFoundException,
160     DatabaseException, ForeignKeyNotFoundException {
161         if ( (!forumCreated) || (forumXML.getForumID()<0) ) {
162             addJiveForum();
163         }
164         if (usertype==null) {
165             throw new CreateException("Not enough data to create a member forum-specific permission.");
166
167         } else if (usertype.equalsIgnoreCase("ANONYMOUS")) {
168             int[] perms = JiveXML.convertMemberForumPermission(jivePermission);
169             ImportJive.addMessage("Adding forum-specific permissions for guests.");
170             for (int j=0; j<perms.length; j++) {
171                 try {
172                     forumXML.addGuestMemberForumPermission(Integer.toString(perms[j]));
173                 } catch (DuplicateKeyException e) {
174                     /* Ignore if we doubled some permissions.
175                      * Because we convert each Jive permission into the list of
176                      * MVN Forum permissions (can be more than one), some permissions
177                      * could be generated twice, or more times.
178                      */

179                 }
180             }
181
182         } else if (usertype.equalsIgnoreCase("REGISTERED_USERS")) {
183             int[] perms = JiveXML.convertGroupForumPermission(jivePermission);
184             ImportJive.addMessage("Adding forum-specific permissions for registered members.");
185             for (int j=0; j<perms.length; j++) {
186                 try {
187                     forumXML.addRegisteredMembersGroupForumPermission(Integer.toString(perms[j]));
188                 } catch (DuplicateKeyException e) {
189                     /* Ignore if we doubled some permissions.
190                      * Because we convert each Jive permission into the list of
191                      * MVN Forum permissions (can be more than one), some permissions
192                      * could be generated twice, or more times.
193                      */

194                 }
195             }
196
197         } else if (usertype.equalsIgnoreCase("USER")) {
198             int[] perms = JiveXML.convertMemberForumPermission(jivePermission);
199             ImportJive.addMessage("Adding forum-specific permissions for member \""+username+"\".");
200             for (int j=0; j<perms.length; j++) {
201                 try {
202                     forumXML.addMemberForumPermission(username, Integer.toString(perms[j]));
203                 } catch (DuplicateKeyException e) {
204                     /* Ignore if we doubled some permissions.
205                      * Because we convert each Jive permission into the list of
206                      * MVN Forum permissions (can be more than one), some permissions
207                      * could be generated twice, or more times.
208                      */

209                 }
210             }
211         } else {
212             throw new CreateException("Invalid usertype. This Jive user forum-specific permission is ignored.");
213         }
214     }
215
216     public void addJiveForumGroup(String JavaDoc groupname, String JavaDoc jivePermission)
217     throws CreateException, DuplicateKeyException, ObjectNotFoundException,
218     DatabaseException, ForeignKeyNotFoundException {
219         if ( (!forumCreated) || (forumXML.getForumID()<0) ) {
220             addJiveForum();
221         }
222         if ( (groupname==null) || (groupname.equals("")) ) {
223             throw new CreateException("Not enough data to create a group permission.");
224         } else {
225             int[] perms = JiveXML.convertGroupForumPermission(jivePermission);
226             ImportJive.addMessage("Adding forum-specific permissions for group \""+groupname+"\".");
227             for (int j=0; j<perms.length; j++) {
228                 try {
229                     forumXML.addGroupForumPermission(groupname, Integer.toString(perms[j]));
230                 } catch (DuplicateKeyException e) {
231                     /* Ignore if we doubled some permissions.
232                      * Because we convert each Jive permission into the list of
233                      * MVN Forum permissions (can be more than one), some permissions
234                      * could be generated twice, or more times.
235                      */

236                 }
237             }
238         }
239     }
240
241
242 }
243
244
245
Popular Tags