KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > smile > stored > s_updateArticlePreload


1 package smile.stored;
2
3 import java.util.*;
4 import java.sql.*;
5
6 /**
7  * s_updateArticlePreload is an implements the ProcedureInterface and is a
8  * sub-class of StoredProcedure. This class inserts articles into the prelaod
9  * articles database. Copyright 2002 Smile Les motoristes Internet
10  * http://www.smile.fr/ Contact cofax@smile.fr for further information
11  *
12  * @author Badr Chentouf - Smile Les motoristes Internet
13  * @author FX Robin
14  * @created July 11, 2002
15  * @version 2.3
16  */

17 public class s_updateArticlePreload extends StoredProcedure implements ProcedureInterface {
18
19     String JavaDoc itemID;
20
21     /**
22      * Constructor for the s_updateArticlePreload object
23      */

24     public s_updateArticlePreload() {
25     }
26
27     /**
28      * Description of the Method
29      *
30      * @param initData
31      * Description of the Parameter
32      * @param con
33      * Description of the Parameter
34      */

35     public void init(HashMap initData, Connection con) {
36         // on initialise le hashmap de donnees et la connection de l'objet
37
super.init(initData, con);
38     }
39
40     /**
41      * Sets the itemID attribute of the s_updateArticlePreload object
42      *
43      * @param pItemID
44      * The new itemID value
45      */

46     public void setItemID(String JavaDoc pItemID) {
47         itemID = pItemID;
48     }
49
50     /**
51      * Description of the Method
52      *
53      * @exception SQLException
54      * Description of the Exception
55      */

56     public void checkParams() throws SQLException {
57         itemID = utils.getString(data, "ITEMID", "");
58     }
59
60     /**
61      * Description of the Method
62      *
63      * @exception SQLException
64      * Description of the Exception
65      */

66     public void checkAction() throws SQLException {
67     }
68
69     /**
70      * Description of the Method
71      *
72      * @exception SQLException
73      * Description of the Exception
74      */

75     public void executeAction() throws SQLException {
76
77         // boolean to know if we have to execute the insert query
78
// because of the life cycle
79
boolean toExecute = true;
80
81         // Gets the useDate flag
82
String JavaDoc useDate;
83         StringBuffer JavaDoc v_useDate = new StringBuffer JavaDoc();
84         v_useDate.append("SELECT tblpublications.defaultSectionWithDate ").append("from tblarticles, tblpublications ").append(
85                 "where tblpublications.pubName = tblarticles.pubName ").append("and tblarticles.itemID='" + itemID + "'");
86
87         try {
88             useDate = execStatementToValue(v_useDate.toString());
89         } catch (SQLException e) {
90             useDate = "1";
91         }
92
93         // getting values
94
String JavaDoc virtualFolder = "";
95         String JavaDoc pubSectionDesc = "";
96         String JavaDoc fullLink = "";
97         String JavaDoc lifeCycle = "";
98         String JavaDoc startDate = "";
99         String JavaDoc endDate = "";
100         String JavaDoc workflow_state = "";
101         StringBuffer JavaDoc v_sb1 = new StringBuffer JavaDoc();
102         v_sb1.append("SELECT ");
103         if (useDate == "1") {
104             v_sb1.append("CONCAT(a.pubName, '/', s.sectionName) as virtualFolder, ");
105             v_sb1.append("s.sectionDesc as pubSectionDesc, ");
106             v_sb1.append("a.customURL as fullLink, ");
107         } else {
108             v_sb1.append("CONCAT(a.pubName, '/', s.sectionName) as virtualFolder, ");
109             v_sb1.append("s.sectionDesc as pubSectionDesc, ");
110             v_sb1.append("a.customURL as fullLink, ");
111         }
112         v_sb1.append("a.lifeCycle, ");
113         v_sb1.append("a.PubStart, ");
114         v_sb1.append("a.PubEnd, ");
115         v_sb1.append("a.workflow_state ");
116         v_sb1.append(" FROM ").append(" tblarticles as a, tblpublications as p, tblsections as s ").append(" WHERE a.pubName = p.pubName ").append(
117                 " and a.pubName=s.pubName ").append(" and a.section=s.section ").append(" and a.itemID=" + itemID);
118
119         execStatementToRS(v_sb1.toString());
120         if (psResult.next()) {
121             virtualFolder = psResult.getString(1);
122             pubSectionDesc = psResult.getString(2);
123
124             // Check for ' or \ in the section description
125
if (pubSectionDesc != null) {
126                 pubSectionDesc = utils.replaceString(pubSectionDesc, "'", "''");
127                 pubSectionDesc = utils.replaceString(pubSectionDesc, "\\", "\\\\");
128             }
129
130             fullLink = psResult.getString(3);
131             lifeCycle = psResult.getString(4);
132             startDate = psResult.getString(5);
133             endDate = psResult.getString(6);
134             workflow_state = psResult.getString(7);
135         }
136         psResult.close();
137
138         // set into tblarticleproload only article with workflow_state=2
139
if (!(workflow_state.equals("2")))
140             toExecute = false;
141
142         // Test the lifeCycle to publish or not the article
143
if (lifeCycle.equals("1")) {
144             int startDateInt = Integer.parseInt(startDate.substring(0, 4) + startDate.substring(5, 7) + startDate.substring(8, 10));
145             int endDateInt = Integer.parseInt(endDate.substring(0, 4) + endDate.substring(5, 7) + endDate.substring(8, 10));
146
147             String JavaDoc todayString = "" + (String JavaDoc) sdf.format(new java.util.Date JavaDoc()).toString();
148             int todayDateInt = Integer.parseInt(todayString.substring(0, 4) + todayString.substring(5, 7) + todayString.substring(8, 10));
149             if ((startDateInt > todayDateInt) || (endDateInt < todayDateInt)) {
150                 // the article is unpublished
151
toExecute = false;
152                 System.out.println("s_updateArticlePreload : the article " + itemID + " is unpublished because of life cycle");
153             }
154
155         }
156
157         // deleting previous active articles
158
execStatement("DELETE from tblarticlepreload WHERE itemID='" + itemID + "'");
159
160         // getting image values
161
if (toExecute) {
162
163             StringBuffer JavaDoc v_listImage = new StringBuffer JavaDoc();
164             StringBuffer JavaDoc v_listImageCaption = new StringBuffer JavaDoc();
165             StringBuffer JavaDoc v_articleImage = new StringBuffer JavaDoc();
166             StringBuffer JavaDoc v_articleImageCaption = new StringBuffer JavaDoc();
167             v_listImage.append("SELECT COALESCE(itemName, '') from tblmultimedia where itemID = '" + itemID + "' AND type='sectionImage'");
168             v_listImageCaption.append("SELECT COALESCE(caption, '') from tblmultimedia where itemID = '" + itemID + "' AND type='sectionImage'");
169             v_articleImage.append("SELECT COALESCE(itemName, '') from tblmultimedia where itemID = '" + itemID + "' AND type='articleImage'");
170             v_articleImageCaption.append("SELECT COALESCE(caption, '') from tblmultimedia where itemID = '" + itemID + "' AND type='articleImage'");
171             String JavaDoc listImage;
172             String JavaDoc listImageCaption;
173             String JavaDoc articleImage;
174             String JavaDoc articleImageCaption;
175             try {
176                 listImage = utils.replaceString(execStatementToValue(v_listImage.toString()), "'", "''");
177             } catch (SQLException e) {
178                 listImage = "";
179             }
180
181             try {
182                 listImageCaption = utils.replaceString(execStatementToValue(v_listImageCaption.toString()), "'", "''");
183             } catch (SQLException e) {
184                 listImageCaption = "";
185             }
186
187             try {
188                 articleImage = utils.replaceString(execStatementToValue(v_articleImage.toString()), "'", "''");
189             } catch (SQLException e) {
190                 articleImage = "";
191             }
192
193             try {
194                 articleImageCaption = utils.replaceString(execStatementToValue(v_articleImageCaption.toString()), "'", "''");
195             } catch (SQLException e) {
196                 articleImageCaption = "";
197             }
198
199             // update tblarticlepreload with those fields
200
StringBuffer JavaDoc v_Update1 = new StringBuffer JavaDoc();
201             v_Update1.append("INSERT INTO tblarticlepreload (itemID, mappingCode, ").append(" shortTime, dayOfWeek, virtualFolder, pubSectionDesc, pubYear, ")
202                     .append(" pubMonth, pubDay, dateFolder, pubDateLong, fullLink, articleLeadIn, ").append(
203                             " sigImage, sigImageCaption, sectionName, sectionDesc, sigDir, ").append(" sectionImage, sectionType, orderingRank, hostname, ")
204                     .append(" listImage, listImageCaption, articleImage, articleImageCaption, relatedLinksCount, pubDesc) ").append("SELECT ").append(
205                             " a.itemId, o.mappingCode, ").append(" DATE_FORMAT(a.pubDate, '%h:%i %p'),").append(" DATE_FORMAT(a.pubDate, '%W'), ").append(
206                             " '" + virtualFolder + "', ").append(" '" + pubSectionDesc + "', ").append(" DATE_FORMAT(a.pubDate, '%Y'), ").append(
207                             " DATE_FORMAT(a.pubDate, '%m'), ").append(" DATE_FORMAT(a.pubDate, '%d'), ").append(" DATE_FORMAT(a.pubDate, '%Y/%m/%d'), ")
208                     .append(" DATE_FORMAT(a.pubDate, '%W, %M %e, %Y'), ");
209             
210             String JavaDoc _contextPath = org.cofax.cms.CofaxToolsServlet.contextUrl;
211             
212             if (fullLink == null || fullLink.equals(""))
213                 v_Update1.append(" CONCAT(p.hostName,'"+_contextPath+"/',a.pubName,'/',s.sectionName,'/',fileName,'.htm'), ");
214             else
215                 v_Update1.append(" '" + fullLink + "', ");
216             v_Update1.append(" at.articleTypeLeadIn, ").append(" at.articleTypeImage, ").append(" at.articleTypeName, ").append(" s.sectionName, ").append(
217                     " s.sectionDesc, ").append(" s.sigDir, ").append(" s.Image, ").append(" s.sectionType, ").append(" o.rank, ").append(" p.hostname, ")
218                     .append(" '" + listImage + "' as listImage, ").append(" '" + listImageCaption + "' as listImageCaption, ").append(
219                             " '" + articleImage + "' as articleImage, ").append(" '" + articleImageCaption + "' as articleImageCaption, ").append(
220                             " 0 as relatedLinksCount, ").append(" p.pubDesc as pubDesc ").append("FROM ").append(
221                             " tblarticleorder as o, tblarticles as a LEFT JOIN tblarticletypes as at ON a.articleTypeID=at.articleTypeID, ").append(
222                             "tblpublications as p, tblsections as s ").append("WHERE a.pubName = p.pubName ").append("AND a.disableArticle = 0 ").append(
223                             "AND (at.disableArticleType = 0 or at.disableArticleType is null) ").append("AND a.pubName = s.pubName ").append(
224                             "AND o.mappingCode = s.mappingCode ").append("AND o.itemID = a.itemID ").append("AND a.itemID = '" + itemID + "'");
225
226             execStatement(v_Update1.toString());
227         }
228         execStatementToRS(queryResultOk);
229
230     }
231
232 }
233
Popular Tags