KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > smile > stored > s_insertPublication


1 package smile.stored;
2
3 import java.util.*;
4 import java.sql.*;
5
6 /**
7  * s_insertPublication is an implements the ProcedureInterface and is a
8  * sub-class of StoredProcedure. This class inserts publications in the
9  * database. Copyright 2002 Smile Les motoristes Internet http://www.smile.fr/
10  * Contact cofax@smile.fr for further information
11  *
12  * @author Smile Les motoristes Internet
13  * @author Lee Bolding
14  * @created March 22, 2002
15  */

16 public class s_insertPublication extends StoredProcedure implements ProcedureInterface {
17
18     /**
19      * Description of the Field
20      */

21     protected String JavaDoc pubConfigAction;
22
23     String JavaDoc publication;
24
25     String JavaDoc pubName;
26
27     String JavaDoc pubDesc;
28
29     String JavaDoc tagLine;
30
31     String JavaDoc keywords;
32
33     String JavaDoc homePage;
34
35     String JavaDoc icon;
36
37     String JavaDoc iconWidth;
38
39     String JavaDoc iconHeight;
40
41     String JavaDoc javaScript;
42
43     String JavaDoc rolloverTime;
44
45     String JavaDoc defaultSection;
46
47     String JavaDoc defaultSectionWithDate;
48
49     String JavaDoc domainName;
50
51     String JavaDoc testFTPServer;
52
53     String JavaDoc testFTPLogin;
54
55     String JavaDoc testFTPPassword;
56
57     String JavaDoc testTemplateFolder;
58
59     String JavaDoc testImagesFolder;
60
61     String JavaDoc liveFTPServer;
62
63     String JavaDoc liveFTPLogin;
64
65     String JavaDoc liveFTPPassword;
66
67     String JavaDoc liveTemplateFolder;
68
69     String JavaDoc liveImagesFolder;
70
71     String JavaDoc liveImagesServer;
72
73     String JavaDoc importFTPServer;
74
75     String JavaDoc importFTPLogin;
76
77     String JavaDoc importFTPPassword;
78
79     String JavaDoc importFTPFilePath;
80
81     String JavaDoc importFTPFileContents;
82
83     String JavaDoc mainCofaxServer;
84
85     String JavaDoc imagesURLPrefix;
86
87     String JavaDoc cacheServers;
88
89     String JavaDoc pubID;
90
91     String JavaDoc P3PPolicyRef;
92
93     String JavaDoc P3PCompactHeader;
94
95     String JavaDoc errorHeaders;
96
97     String JavaDoc wmails;
98
99     String JavaDoc wlevels;
100
101     String JavaDoc wadminemail;
102
103     /**
104      * Constructor for the s_insertPublication object
105      */

106     public s_insertPublication() {
107     }
108
109     /**
110      * Description of the Method
111      *
112      * @param initData
113      * Description of the Parameter
114      * @param con
115      * Description of the Parameter
116      */

117     public void init(HashMap initData, Connection con) {
118         // on initialise le hashmap de donnees et la connection de l'objet
119
super.init(initData, con);
120         // on initialise les propprietes de l'objet
121
publication = utils.getString(data, "PUBLICATION", "");
122         pubName = utils.getString(data, "PUBNAME", "");
123         pubDesc = utils.getString(data, "PUBDESC", "");
124         tagLine = utils.getString(data, "TAGLINE", "");
125         keywords = utils.getString(data, "KEYWORDS", "");
126         homePage = utils.getString(data, "HOMEPAGE", "");
127         icon = utils.getString(data, "ICON", "");
128         iconWidth = utils.getString(data, "ICONWIDTH", "");
129         iconHeight = utils.getString(data, "ICONHEIGHT", "");
130         javaScript = utils.getString(data, "JAVASCRIPT", "");
131         rolloverTime = utils.getString(data, "ROLLOVERTIME", "4");
132         defaultSection = utils.getString(data, "DEFAULTSECTION", "");
133         defaultSectionWithDate = utils.getString(data, "DEFAULTSECTIONWITHDATE", "");
134         domainName = utils.getString(data, "DOMAINNAME", "");
135         testFTPServer = utils.getString(data, "TESTFTPSERVER", "");
136         testFTPLogin = utils.getString(data, "TESTFTPLOGIN", "");
137         testFTPPassword = utils.getString(data, "TESTFTPPASSWORD", "");
138         testTemplateFolder = utils.getString(data, "TESTTEMPLATEFOLDER", "");
139         testImagesFolder = utils.getString(data, "TESTIMAGESFOLDER", "");
140         liveFTPServer = utils.getString(data, "LIVEFTPSERVER", "");
141         liveFTPLogin = utils.getString(data, "LIVEFTPLOGIN", "");
142         liveFTPPassword = utils.getString(data, "LIVEFTPPASSWORD", "");
143         liveTemplateFolder = utils.getString(data, "LIVETEMPLATEFOLDER", "");
144         liveImagesFolder = utils.getString(data, "LIVEIMAGESFOLDER", "");
145         liveImagesServer = utils.getString(data, "LIVEIMAGESSERVER", "");
146         importFTPServer = utils.getString(data, "IMPORTFTPSERVER", "");
147         importFTPLogin = utils.getString(data, "IMPORTFTPLOGIN", "");
148         importFTPPassword = utils.getString(data, "IMPORTFTPPASSWORD", "");
149         importFTPFilePath = utils.getString(data, "IMPORTFTPFILEPATH", "");
150         importFTPFileContents = utils.getString(data, "IMPORTFTPFILECONTENTS", "");
151         mainCofaxServer = utils.getString(data, "MAINCOFAXSERVER", "");
152         imagesURLPrefix = utils.getString(data, "IMAGESURLPREFIX", "");
153         cacheServers = utils.getString(data, "CACHESERVERS", "");
154         pubID = utils.getString(data, "PUBID", "0");
155         P3PPolicyRef = utils.getString(data, "POLICYREF", "");
156         P3PCompactHeader = utils.getString(data, "COMPACTHEADER", "");
157         errorHeaders = utils.getString(data, "USEERROR", "");
158         wmails = utils.getString(data, "WORKFLOW_MAILS", "");
159         wlevels = utils.getString(data, "WORKFLOW_LEVELS", "");
160         wadminemail = utils.getString(data, "WORKFLOW_ADMINEMAIL", "");
161     }
162
163     /**
164      * Description of the Method
165      *
166      * @exception SQLException
167      * Description of the Exception
168      */

169     public void checkAction() throws SQLException {
170         // action
171
execStatementToRS("SELECT * FROM tblpublications WHERE pubID = " + pubID);
172         if (Integer.parseInt(pubID) > 0 && psResult.next()) {
173             action = "update";
174         } else if (Integer.parseInt(pubID) == 0) {
175             action = "insert";
176         } else {
177             throw new SQLException("ERROR: Publication DOES NOT EXIST.");
178         }
179         close();
180
181         // PubConfigAction
182
execStatementToRS("SELECT * FROM tbltoolspublicationconfig WHERE pubID = " + pubID);
183         if (Integer.parseInt(pubID) > 0 && psResult.next()) {
184             pubConfigAction = "update";
185         } else {
186             pubConfigAction = "insert";
187         }
188         close();
189
190     }
191
192     /**
193      * Description of the Method
194      *
195      * @exception SQLException
196      * Description of the Exception
197      */

198     public void checkParams() throws SQLException {
199         if (publication.equals("") || pubName.equals("") || pubDesc.equals("")) {
200             throw new SQLException("ERROR: REQUIRED FIELDS WERE NOT SENT.");
201         }
202     }
203
204     /**
205      * Description of the Method
206      *
207      * @exception SQLException
208      * Description of the Exception
209      */

210     public void executeAction() throws SQLException {
211         // Action on the table tblpublications
212
if (action.equals("update")) {
213             StringBuffer JavaDoc v_sb = new StringBuffer JavaDoc();
214             v_sb.append("UPDATE tblpublications").append(" SET publication = '" + publication + "',").append(" pubName = '" + pubName + "',").append(
215                     " pubDesc = '" + pubDesc + "',").append(" tagLine = '" + tagLine + "',").append(" keywords = '" + keywords + "',").append(
216                     " homePage = '" + homePage + "',").append(" icon = '" + icon + "',").append(" iconWidth = '" + iconWidth + "',").append(
217                     " iconHeight = '" + iconHeight + "',").append(" javaScript = '" + javaScript + "',").append(" rolloverTime = '" + rolloverTime + "',")
218                     .append(" defaultSection = '" + defaultSection + "',").append(" defaultSectionWithDate = '" + defaultSectionWithDate + "',").append(
219                             " pubUpdateDate = '" + sdf.format(new java.util.Date JavaDoc()) + "', ").append(" workflow_mails = '" + wmails + "',").append(
220                             " workflow_levels = '" + wlevels + "',").append(" workflow_adminEmail = '" + wadminemail + "' ").append(" WHERE pubID = " + pubID);
221
222             execStatement(v_sb.toString());
223         } else if (action.equals("insert")) {
224             StringBuffer JavaDoc v_sb = new StringBuffer JavaDoc();
225             v_sb.append("INSERT INTO tblpublications ").append("(publication,").append("pubName,").append("pubDesc,").append("tagLine,").append("keywords,")
226                     .append("homePage,").append("icon,").append("iconWidth,").append("iconHeight,").append("javaScript,").append("rolloverTime,").append(
227                             "defaultSection,").append("defaultSectionWithDate,").append("pubUpdateDate, ").append(
228                             "workflow_mails, workflow_levels, workflow_adminEmail) ").append(" VALUES ('" + publication + "',").append("'" + pubName + "',")
229                     .append("'" + pubDesc + "',").append("'" + tagLine + "',").append("'" + keywords + "',").append("'" + homePage + "',").append(
230                             "'" + icon + "',").append("'" + iconWidth + "',").append("'" + iconHeight + "',").append("'" + javaScript + "',").append(
231                             "'" + rolloverTime + "',").append("'" + defaultSection + "',").append("'" + defaultSectionWithDate + "',").append(
232                             "'" + sdf.format(new java.util.Date JavaDoc()) + "', ").append("'" + wmails + "','" + wlevels + "', '" + wadminemail + "')");
233
234             // we synchronize this code in order to get the good pubID
235
synchronized (this) {
236                 execStatement(v_sb.toString());
237                 // get back the pubID Max
238
pubID = getMax("tblpublications", "pubID");
239             }
240         }
241
242         // Action on the table tbltoolspublicationconfig
243
if (pubConfigAction.equals("update")) {
244             StringBuffer JavaDoc v_sb = new StringBuffer JavaDoc();
245             v_sb.append("UPDATE tbltoolspublicationconfig").append(" SET domainName = '" + domainName + "',").append(
246                     " testFTPServer = '" + testFTPServer + "',").append(" testFTPLogin = '" + testFTPLogin + "',").append(
247                     " testFTPPassword = '" + testFTPPassword + "',").append(" testTemplateFolder = '" + testTemplateFolder + "',").append(
248                     " testImagesFolder = '" + testImagesFolder + "',").append(" liveFTPServer = '" + liveFTPServer + "',").append(
249                     " liveFTPLogin = '" + liveFTPLogin + "',").append(" liveFTPPassword = '" + liveFTPPassword + "',").append(
250                     " liveTemplateFolder = '" + liveTemplateFolder + "',").append(" liveImagesFolder = '" + liveImagesFolder + "',").append(
251                     " liveImagesServer = '" + liveImagesServer + "',").append(" importFTPServer = '" + importFTPServer + "',").append(
252                     " importFTPLogin = '" + importFTPLogin + "',").append(" importFTPPassword = '" + importFTPPassword + "',").append(
253                     " importFTPFilePath = '" + importFTPFilePath + "',").append(" importFTPFileContents = '" + importFTPFileContents + "',").append(
254                     " mainCofaxServer = '" + mainCofaxServer + "',").append(" cacheServers = '" + cacheServers + "',").append(
255                     " imagesURLPrefix = '" + imagesURLPrefix + "', ").append(" errorHeaders = '" + errorHeaders + "', ").append(
256                     " P3PPolicyRef = '" + P3PPolicyRef + "', ").append(" P3PCompactHeader = '" + P3PCompactHeader + "' ").append(" WHERE pubID = " + pubID);
257             execStatement(v_sb.toString());
258         } else if (pubConfigAction.equals("insert")) {
259             StringBuffer JavaDoc v_sb = new StringBuffer JavaDoc();
260             v_sb.append(" INSERT INTO tbltoolspublicationconfig ").append(" VALUES (" + pubID + ",").append("'" + domainName + "',").append(
261                     "'" + testFTPServer + "',").append("'" + testFTPLogin + "',").append("'" + testFTPPassword + "',").append("'" + testTemplateFolder + "',")
262                     .append("'" + testImagesFolder + "',").append("'" + liveFTPServer + "',").append("'" + liveFTPLogin + "',").append(
263                             "'" + liveFTPPassword + "',").append("'" + liveTemplateFolder + "',").append("'" + liveImagesFolder + "',").append(
264                             "'" + liveImagesServer + "',").append("'" + importFTPServer + "',").append("'" + importFTPLogin + "',").append(
265                             "'" + importFTPPassword + "',").append("'" + importFTPFilePath + "',").append("'" + importFTPFileContents + "',").append(
266                             "'" + mainCofaxServer + "',").append("'" + imagesURLPrefix + "',").append("'" + cacheServers + "', ").append(
267                             "'" + errorHeaders + "', ").append("'" + P3PPolicyRef + "', ").append("'" + P3PCompactHeader + "')");
268             execStatement(v_sb.toString());
269         }
270         String JavaDoc v_select = "select " + pubID + " as pubID";
271         execStatementToRS(queryResultOk);
272     }
273 }
274
Popular Tags