| 1 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 58 public class JiveMessageXML { 59 60 private PostXML postXML=null; 61 private boolean postCreated=false; 62 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 id) { 75 postXML.setPostID(id); 76 } 77 78 84 public void setPostId(String 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 o) 109 throws ForeignKeyNotFoundException { 110 if (o instanceof JiveThreadXML) { 111 parentJiveThread=(JiveThreadXML)o; 112 parentJiveMessage=null; 114 } else if (o instanceof JiveMessageXML) { 115 parentJiveMessage=(JiveMessageXML)o; 116 parentJiveThread=null; 118 } else { 119 throw new ForeignKeyNotFoundException("Can't find neither parent thread nor message."); 120 } 121 } 122 123 private String postSubject=null; 124 public void setPostSubject(String 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 postBody=null; 131 public void setPostBody(String 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 postUsername=null; 138 public void setPostUsername(String value) throws CreateException { 139 this.postUsername=value; 140 } 141 142 private String postCreationDate=null; 143 public void setPostCreationDate(String value) throws CreateException { 144 this.postCreationDate=value; 145 } 146 147 private String postModifiedDate=null; 148 public void setPostModifiedDate(String value) throws CreateException { 149 this.postModifiedDate=value; 150 } 151 152 public void addJiveMessage() throws CreateException, DuplicateKeyException, 153 ObjectNotFoundException, DatabaseException, ForeignKeyNotFoundException, BadInputException { 154 159 if (postCreated) return; 160 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.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, postUsername, 177 postSubject, postBody, 178 postCreationDate, postModifiedDate, 179 null, null, 180 null, null, 181 null, null, 182 null, null); 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 postUsername, String postCreationDate) 197 throws ObjectNotFoundException, DatabaseException, ForeignKeyNotFoundException { 198 if ((!postCreated) || (postXML.getPostID()<0)) return; 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 |