KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/importexport/jive/JiveMessageXML.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.jive;
41
42 import com.mvnforum.admin.PostXML;
43 import com.mvnforum.admin.importexport.XMLUtil;
44 import com.mvnforum.db.DAOFactory;
45 import net.myvietnam.mvncore.exception.*;
46
47 /**
48  * @author Igor Manic
49  * @version $Revision: 1.6 $, $Date: 2006/04/14 17:36:29 $
50  * <br/>
51  * <code>JiveMessageXML</code> class encapsulates processing of
52  * messages' 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>PostXML</code> and other neccessary classes in order to perform
56  * the actual creation of a post.
57  */

58 public class JiveMessageXML {
59
60     private PostXML postXML=null;
61     private boolean postCreated=false;
62     //only one of parentJiveMessage and parentJiveThread will be defined (later), and the other will be null
63
private JiveThreadXML parentJiveThread =null;
64     private JiveMessageXML parentJiveMessage =null;
65
66     public JiveMessageXML() {
67         super();
68         postXML=new PostXML();
69         postCreated=false;
70         parentJiveThread=null;
71         parentJiveMessage=null;
72     }
73
74     public void setPostID(String JavaDoc id) {
75         postXML.setPostID(id);
76     }
77
78     /**
79      * This method simply calls <code>setPostID()</code>.
80      * It's defined only to avoid property-setter problems with digester
81      * (since it doesn't seem to recognize <code>setPostID()</code> as a setter
82      * method for <code>postID</code> property).
83      */

84     public void setPostId(String JavaDoc id) {
85         setPostID(id);
86     }
87
88     public int getPostID() {
89         return postXML.getPostID();
90     }
91
92     public int getParentCategoryID() {
93         return postXML.getParentCategoryID();
94     }
95
96     public int getParentForumID() {
97         return postXML.getParentForumID();
98     }
99
100     public int getParentThreadID() {
101         return postXML.getParentThreadID();
102     }
103
104     public int getParentPostID() {
105         return postXML.getParentPostID();
106     }
107
108     public void setParentThreadOrPost(Object JavaDoc o)
109     throws ForeignKeyNotFoundException {
110         if (o instanceof JiveThreadXML) {
111             parentJiveThread=(JiveThreadXML)o;
112             //warning: parent thread might not be added to database yet
113
parentJiveMessage=null;
114         } else if (o instanceof JiveMessageXML) {
115             parentJiveMessage=(JiveMessageXML)o;
116             //warning: parent post might be not added to database yet
117
parentJiveThread=null;
118         } else {
119             throw new ForeignKeyNotFoundException("Can't find neither parent thread nor message.");
120         }
121     }
122
123     private String JavaDoc postSubject=null;
124     public void setPostSubject(String JavaDoc value) throws CreateException {
125         if ( (value==null) || (value.equals("")) ) {
126             throw new CreateException("Cannot create a post with an empty PostSubject.");
127         } else this.postSubject=value;
128     }
129
130     private String JavaDoc postBody=null;
131     public void setPostBody(String JavaDoc value) throws CreateException {
132         if ( (value==null) || (value.equals("")) ) {
133             throw new CreateException("Cannot create a post with an empty PostBody.");
134         } else this.postBody=value;
135     }
136
137     private String JavaDoc postUsername=null;
138     public void setPostUsername(String JavaDoc value) throws CreateException {
139         this.postUsername=value;
140     }
141
142     private String JavaDoc postCreationDate=null;
143     public void setPostCreationDate(String JavaDoc value) throws CreateException {
144         this.postCreationDate=value;
145     }
146
147     private String JavaDoc postModifiedDate=null;
148     public void setPostModifiedDate(String JavaDoc value) throws CreateException {
149         this.postModifiedDate=value;
150     }
151
152     public void addJiveMessage() throws CreateException, DuplicateKeyException,
153     ObjectNotFoundException, DatabaseException, ForeignKeyNotFoundException, BadInputException {
154         /* First, check if the digester already called this method.
155          * It will happen even under normal circumstances, if this message has
156          * subelements that need it already be defined, so they first call
157          * this method to create message before creating data that refer him.
158          */

159         if (postCreated) return;
160         /* Second, create parent message or thread if it's not yet created. */
161         if (parentJiveMessage!=null) {
162             parentJiveMessage.addJiveMessage();
163             postXML.setParentPostID(parentJiveMessage.getPostID());
164             postXML.setParentThreadID(parentJiveMessage.getParentThreadID());
165             postXML.setParentForumID(parentJiveMessage.getParentForumID());
166             postXML.setParentCategoryID(parentJiveMessage.getParentCategoryID());
167         } else if (parentJiveThread!=null) {
168             parentJiveThread.addJiveThread(postUsername, postSubject, postBody);
169             //postXML.setParentPostID(0) is not neccessary
170
postXML.setParentThreadID(parentJiveThread.getThreadID());
171             postXML.setParentForumID(parentJiveThread.getParentForumID());
172             postXML.setParentCategoryID(parentJiveThread.getParentCategoryID());
173         }
174
175         ImportJive.addMessage("Adding Jive message \""+postSubject+"\".");
176         postXML.addPost(postUsername/*memberName*/, postUsername/*lastEditMemberName*/,
177                         postSubject/*postTopic*/, postBody,
178                         postCreationDate, postModifiedDate/*postLastEditDate*/,
179                         null/*postCreationIP*/, null/*postLastEditIP*/,
180                         null/*postEditCount*/, null/*postFormatOption*/,
181                         null/*postOption*/, null/*postStatus*/,
182                         null/*postIcon*/, null/*postAttachCount*/);
183         postCreated=true;
184
185         if ((postUsername!=null) && (postUsername.length()>0)) {
186             DAOFactory.getMemberDAO().increasePostCount(
187                    DAOFactory.getMemberDAO().getMemberIDFromMemberName(postUsername));
188         }
189         if (parentJiveMessage!=null) {
190             parentJiveMessage.updateAddedReplyPost(postXML, postUsername, postCreationDate);
191         } else if (parentJiveThread!=null) {
192             parentJiveThread.updateAddedPost(postXML, postUsername, XMLUtil.stringToSqlTimestampDefNull(postCreationDate));
193         }
194     }
195
196     public void updateAddedReplyPost(PostXML subPost, String JavaDoc postUsername, String JavaDoc postCreationDate)
197     throws ObjectNotFoundException, DatabaseException, ForeignKeyNotFoundException {
198         if ((!postCreated) || (postXML.getPostID()<0)) return; //todo Igor: process this error
199
//nothing to update in this post data
200
if (parentJiveMessage!=null) {
201             parentJiveMessage.updateAddedReplyPost(subPost, postUsername, postCreationDate);
202         } else if (parentJiveThread!=null) {
203             parentJiveThread.updateAddedPost(subPost, postUsername, XMLUtil.stringToSqlTimestampDefNull(postCreationDate));
204         }
205     }
206
207
208 }
209
210
211
Popular Tags