KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/importexport/mvnforum/MvnForumGroupXML.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.MVNForumConstant;
43 import com.mvnforum.admin.GroupXML;
44 import net.myvietnam.mvncore.exception.*;
45
46 /**
47  * @author Igor Manic
48  * @version $Revision: 1.6 $, $Date: 2006/04/14 17:36:29 $
49  * <br/>
50  * <code>MvnForumGroupXML</code> class encapsulates processing of
51  * groups' definitions found in the backup XML file. It implements
52  * methods to be called from XML parsing routine, adds some additional
53  * processing and checking, and calls corresponding methods of
54  * <code>GroupXML</code> and other neccessary classes in order to perform
55  * the actual creation of a group, as well as other related items (like
56  * group members and group permissions). It also ensures that default
57  * virtual <code>"Registered Members"</code> group is created, even if it
58  * wasn't found in the XML.
59  */

60 public class MvnForumGroupXML {
61
62     private GroupXML groupXML=null;
63     private boolean groupCreated=false;
64     private boolean isRegisteredMembersGroup = false;
65
66     String JavaDoc groupOwnerName = null;
67     String JavaDoc groupName = null;
68     String JavaDoc groupDesc = null;
69     String JavaDoc groupOption = null;
70     String JavaDoc groupCreationDate = null;
71     String JavaDoc groupModifiedDate = null;
72
73     public MvnForumGroupXML() {
74         super();
75         groupXML=new GroupXML();
76         groupCreated=false;
77         isRegisteredMembersGroup=false;
78     }
79
80     public int getGroupID() {
81         return groupXML.getGroupID();
82     }
83
84     public void setGroupID(String JavaDoc id) {
85         groupXML.setGroupID(id);
86     }
87
88     /**
89      * This method simply calls <code>setGroupID()</code>.
90      * It's defined only to avoid property-setter problems with digester
91      * (since it doesn't seem to recognize <code>setGroupID()</code> as a setter
92      * method for <code>groupID</code> property).
93      */

94     public void setGroupId(String JavaDoc id) {
95         setGroupID(id);
96     }
97
98     public void setGroupClass(String JavaDoc groupClass) {
99         if (groupClass!=null) {
100             if (groupClass.equalsIgnoreCase("RegisteredMembers")) {
101                 groupXML.setGroupID(Integer.toString(MVNForumConstant.GROUP_ID_OF_REGISTERED_MEMBERS));
102                 isRegisteredMembersGroup=true;
103             }
104         }
105     }
106
107     public void setGroupOwnerName(String JavaDoc value) {
108         groupOwnerName=value;
109     }
110
111     public void setGroupName(String JavaDoc value) {
112         groupName=value;
113     }
114
115     public void setGroupDesc(String JavaDoc value) {
116         groupDesc=value;
117     }
118
119     public void setGroupOption(String JavaDoc value) {
120         groupOption=value;
121     }
122
123     public void setGroupCreationDate(String JavaDoc value) {
124         groupCreationDate=value;
125     }
126
127     public void setGroupModifiedDate(String JavaDoc value) {
128         groupModifiedDate=value;
129     }
130
131     public void addGroup() throws CreateException, DuplicateKeyException,
132     ObjectNotFoundException, DatabaseException, ForeignKeyNotFoundException, BadInputException {
133         /* First, check if the digester already called this method.
134          * It will happen even under normal circumstances, if this group has
135          * subelements that need it already be defined, so they first call
136          * this method to create group before creating data that refer him.
137          */

138         if (groupCreated) return;
139         /* Then, check if "Registered Members" group is created.
140          * It must be the first one to be created, otherwise, DBMS might have
141          * added some other (non-reserved) group with this ID
142          * that is supposed to be reserved for "Registered Members".
143          */

144         if (!isRegisteredMembersGroup) MvnForumXML.checkRegisteredMembersGroup();
145
146         ImportMvnForum.addMessage("Adding group \""+groupName+"\".");
147         groupXML.addGroup(groupOwnerName, groupName, groupDesc,
148                           groupOption, groupCreationDate, groupModifiedDate);
149         groupCreated=true;
150         if (isRegisteredMembersGroup) MvnForumXML.addedRegisteredMembersGroup=true;
151     }
152
153     public void addGroupPermission(String JavaDoc permission) throws CreateException,
154     DuplicateKeyException, ObjectNotFoundException, DatabaseException, ForeignKeyNotFoundException, BadInputException {
155         if ( (!groupCreated) || (groupXML.getGroupID()<0) ) {
156             addGroup();
157         }
158         ImportMvnForum.addMessage("Adding group permission \""+permission+"\".");
159         groupXML.addGroupPermission(permission);
160     }
161
162     public void addGroupMember(String JavaDoc memberName, String JavaDoc privilege,
163                                String JavaDoc creationDate, String JavaDoc modifiedDate)
164     throws CreateException, DuplicateKeyException, ObjectNotFoundException,
165     DatabaseException, ForeignKeyNotFoundException, BadInputException {
166         if ( (!groupCreated) || (groupXML.getGroupID()<0) ) {
167             addGroup();
168         }
169         ImportMvnForum.addMessage("Adding group member \""+memberName+"\".");
170         groupXML.addMemberGroup(memberName, privilege, creationDate, modifiedDate);
171     }
172
173
174 }
175
Popular Tags