KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/importexport/mvnforum/MvnForumAttachmentXML.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.AttachmentXML;
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>MvnForumAttachmentXML</code> class encapsulates processing of
50  * attachments' 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>AttachmentXML</code> and other neccessary classes in order to perform
54  * the actual creation of an attachment.
55  */

56 public class MvnForumAttachmentXML {
57
58     private AttachmentXML attachmentXML=null;
59     private boolean attachmentCreated=false;
60     private MvnForumPostXML parentPost =null;
61
62     String JavaDoc attachMemberName =null;
63     String JavaDoc attachFilename =null;
64     String JavaDoc attachFileSize =null;
65     String JavaDoc attachMimeType =null;
66     String JavaDoc attachDesc =null;
67     String JavaDoc attachCreationIP =null;
68     String JavaDoc attachCreationDate =null;
69     String JavaDoc attachModifiedDate =null;
70     String JavaDoc attachDownloadCount =null;
71     String JavaDoc attachOption =null;
72     String JavaDoc attachStatus =null;
73
74     public MvnForumAttachmentXML() {
75         super();
76         attachmentXML=new AttachmentXML();
77         attachmentCreated=false;
78         parentPost=null;
79     }
80
81     public int getAttachmentID() {
82         return attachmentXML.getAttachmentID();
83     }
84
85     public void setAttachmentID(String JavaDoc id) {
86         if (id!=null) attachmentXML.setAttachmentID(id);
87     }
88
89     /**
90      * This method simply calls <code>setAttachmentID()</code>.
91      * It's defined only to avoid property-setter problems with digester
92      * (since it doesn't seem to recognize <code>setAttachmentID()</code> as a setter
93      * method for <code>attachmentID</code> property).
94      */

95     public void setAttachmentId(String JavaDoc id) {
96         setAttachmentID(id);
97     }
98
99     public int getParentCategoryID() {
100         return attachmentXML.getParentCategoryID(); //==parentPost.getParentCategoryID();
101
}
102
103     public int getParentForumID() {
104         return attachmentXML.getParentForumID(); //==parentPost.getParentForumID();
105
}
106
107     public int getParentThreadID() {
108         return attachmentXML.getParentThreadID(); //==parentPost.getParentThreadID();
109
}
110
111     public int getParentPostID() {
112         return attachmentXML.getParentPostID(); //==parentPost.getPostID();
113
}
114
115     public void setParentPost(Object JavaDoc o)
116     throws ForeignKeyNotFoundException {
117         if (o instanceof MvnForumPostXML) {
118             parentPost=(MvnForumPostXML)o;
119             //warning: parent post might be not added to database yet
120
} else {
121             throw new ForeignKeyNotFoundException("Can't find parent post.");
122         }
123     }
124
125     public void setAttachMemberName(String JavaDoc value) {
126         attachMemberName=value;
127     }
128
129     public void setAttachFilename(String JavaDoc value) {
130         attachFilename=value;
131     }
132
133     public void setAttachFileSize(String JavaDoc value) {
134         attachFileSize=value;
135     }
136
137     public void setAttachMimeType(String JavaDoc value) {
138         attachMimeType=value;
139     }
140
141     public void setAttachDesc(String JavaDoc value) {
142         attachDesc=value;
143     }
144
145     public void setAttachCreationIP(String JavaDoc value) {
146         attachCreationIP=value;
147     }
148
149     public void setAttachCreationDate(String JavaDoc value) {
150         attachCreationDate=value;
151     }
152
153     public void setAttachModifiedDate(String JavaDoc value) {
154         attachModifiedDate=value;
155     }
156
157     public void setAttachDownloadCount(String JavaDoc value) {
158         attachDownloadCount=value;
159     }
160
161     public void setAttachOption(String JavaDoc value) {
162         attachOption=value;
163     }
164
165     public void setAttachStatus(String JavaDoc value) {
166         attachStatus=value;
167     }
168
169     public void addAttachment() throws CreateException, DuplicateKeyException,
170     ObjectNotFoundException, DatabaseException, ForeignKeyNotFoundException, BadInputException {
171         /* First, check if the digester already called this method.
172          * It will happen even under normal circumstances, if this attachment has
173          * subelements that need it already be defined, so they first call
174          * this method to create attachment before creating data that refer him.
175          */

176         if (attachmentCreated) return;
177         /* Second, create parent post if it's not yet created. */
178         if (parentPost!=null) {
179             parentPost.addPost();
180             attachmentXML.setParentPostID(parentPost.getPostID());
181             attachmentXML.setParentThreadID(parentPost.getParentThreadID());
182             attachmentXML.setParentForumID(parentPost.getParentForumID());
183             attachmentXML.setParentCategoryID(parentPost.getParentCategoryID());
184         }
185
186         ImportMvnForum.addMessage("Adding attachment \""+attachFilename+"\".");
187         //AttachmentXML.addAttachment() will check itself if the ID is assigned, as it should be
188
attachmentXML.addAttachment(attachMemberName, attachFilename,
189                       attachFileSize, attachMimeType, attachDesc,
190                       attachCreationIP, attachCreationDate, attachModifiedDate,
191                       attachDownloadCount, attachOption, attachStatus);
192         attachmentCreated=true;
193
194         if (parentPost!=null) {
195             parentPost.updateAddedAttachment(this);
196         }
197     }
198
199
200 }
201
Popular Tags