KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > cofax > cms > CofaxToolsDbUtils


1 /*
2  * CofaxToolsDbUtils is part of the Cofax content management system library.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Please see http://www.cofax.org for contact information and other related informaion.
19  *
20  * $Header: /cvsroot/cofax/cofax/src/org/cofax/cms/CofaxToolsDbUtils.java,v 1.43.2.1 2006/12/11 16:28:23 fxrobin Exp $
21  */

22  
23 package org.cofax.cms;
24
25 import org.cofax.*;
26 import javax.servlet.http.*;
27 import java.io.*;
28 import java.util.*;
29
30
31 /**
32  * CofaxDbUtils: Collection of database results formatting utilities for Cofax
33  * Tools. All calls function through getPackageData, but return results
34  * fornatted in different collection objects.
35  *
36  *@author Charles Harvey
37  *@author Karl Martino
38  *@author Badr Chentouf
39  *@created May 1, 2002
40  */

41 public class CofaxToolsDbUtils {
42     
43         /**
44      * Description of the Field
45      */

46     public static String JavaDoc st_selectPackagetags;
47     /**
48      * Description of the Field
49      */

50     public static String JavaDoc st_selectPackagetagsCache;
51     
52     /**
53      * Updates or inserts an article, attached MultiMedia, and related links
54      *
55      *@param db The new article value
56      *@param req The new article value
57      *@param session The new article value
58      *@return Description of the Return Value
59      */

60     public static String JavaDoc setArticle(DataStore db, HttpServletRequest req, HttpSession session, String JavaDoc toValidOrPublish) {
61
62         HashMap ht = new HashMap();
63         Enumeration en = req.getAttributeNames();
64         while (en.hasMoreElements()) {
65             String JavaDoc key = (String JavaDoc) en.nextElement();
66             ht.put(key, req.getAttribute(key));
67         }
68         String JavaDoc fileName = (String JavaDoc) req.getAttribute("FILENAME");
69         String JavaDoc toolsPath = CofaxToolsServlet.toolsPath;
70         
71         if (fileName.equals("")) {
72             return (CofaxToolsUtil.getI18NMessage(req.getLocale(), "cofdbutil_nofilename"));
73         }
74
75         if (fileName.indexOf(" ") > -1) {
76             return (CofaxToolsUtil.getI18NMessage(req.getLocale(), "cofdbutil_nospacesslug"));
77         }
78
79         String JavaDoc headlineCheck = (String JavaDoc) req.getAttribute("HEADLINE");
80         if ((headlineCheck == null) || (headlineCheck.equals(""))) {
81             return (CofaxToolsUtil.getI18NMessage(req.getLocale(), "cofdbutil_noheadline"));
82         }
83
84         String JavaDoc itemID = (String JavaDoc) req.getAttribute("ITEMID");
85
86         String JavaDoc rankTest = (String JavaDoc) req.getAttribute("RANK");
87         if ((rankTest == null) || (rankTest.equals(""))) {
88             ht.put("RANK", "999");
89         }
90
91         String JavaDoc month = (String JavaDoc) req.getAttribute("selectDatemonth");
92         String JavaDoc day = (String JavaDoc) req.getAttribute("selectDateday");
93         String JavaDoc year = (String JavaDoc) req.getAttribute("selectDateyear");
94         if (year.length() < 4) year = "20" + year;
95         if (day.length() < 2) day = "0" + day;
96         if (month.length() < 2) month = "0" + month;
97         String JavaDoc pubDate = (year + "-" + month + "-" + day);
98         ht.put("PUBDATE", pubDate);
99
100         String JavaDoc lifeCycle = (String JavaDoc) req.getAttribute("LIFECYCLE");
101         lifeCycle = CofaxToolsUtil.convertCheckedToBoolean(lifeCycle);
102         if (lifeCycle.equals("1"))
103         {
104             String JavaDoc startmonth = (String JavaDoc) req.getAttribute("selectStartDatemonth");
105             String JavaDoc startday = (String JavaDoc) req.getAttribute("selectStartDateday");
106             String JavaDoc startyear = (String JavaDoc) req.getAttribute("selectStartDateyear");
107             if (startyear.length() < 4) startyear = "20" + startyear;
108             if (startday.length() < 2) startday = "0" + startday;
109             if (startmonth.length() < 2) startmonth = "0" + startmonth;
110             String JavaDoc startDate = (startyear + "-" + startmonth + "-" + startday);
111             ht.put("STARTDATE", startDate);
112
113             String JavaDoc endmonth = (String JavaDoc) req.getAttribute("selectEndDatemonth");
114             String JavaDoc endday = (String JavaDoc) req.getAttribute("selectEndDateday");
115             String JavaDoc endyear = (String JavaDoc) req.getAttribute("selectEndDateyear");
116             if (endyear.length() < 4) endyear = "20" + endyear;
117             if (endday.length() < 2) endday = "0" + endday;
118             if (endmonth.length() < 2) endmonth = "0" + endmonth;
119             String JavaDoc endDate = (endyear + "-" + endmonth + "-" + endday);
120             ht.put("ENDDATE", endDate);
121             
122         }
123
124         CofaxToolsUser user = (CofaxToolsUser) session.getAttribute("user");
125         //approved field
126
String JavaDoc approved = (String JavaDoc)req.getAttribute("APPROVED");
127         if ((approved==null) || (approved.equals("")))
128         {
129             approved = (String JavaDoc) user.userInfoHash.get("USERNAME");
130         }
131         ht.put("APPROVED", approved);
132
133         String JavaDoc oldSection = (String JavaDoc)req.getAttribute("OLDSECTION");
134         ht.put("OLDSECTION", oldSection);
135         String JavaDoc oldState = (String JavaDoc)req.getAttribute("OLDSTATE");
136         ht.put("OLDSTATE", oldState);
137
138         String JavaDoc disableArticle = (String JavaDoc) req.getAttribute("DISABLEARTICLE");
139         String JavaDoc disableIndex = (String JavaDoc) req.getAttribute("DISABLEINDEX");
140         disableArticle = CofaxToolsUtil.convertCheckedToBoolean(disableArticle);
141         disableIndex = CofaxToolsUtil.convertCheckedToBoolean(disableIndex);
142         ht.put("DISABLEARTICLE", disableArticle);
143         ht.put("DISABLEINDEX", disableIndex);
144
145         //if the article is in process of validation, it must stay when you 'save' it
146
if (toValidOrPublish.equals("0") && oldState.equals("1")) toValidOrPublish="1";
147
148         ht.put("TOVALIDORPUBLISH", toValidOrPublish);
149         
150         // to delete completly an article from database
151
String JavaDoc deleteArticle = (String JavaDoc)req.getAttribute("DELETEARTICLE");
152         if (deleteArticle != null && deleteArticle.equals("on")) {
153             String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "deleteArticle");
154             HashMap hto = CofaxToolsDbUtils.getNameValuePackageHash(db, ht, tag);
155             return(CofaxToolsUtil.getI18NMessage(req.getLocale(), "article") + " " + fileName + " " + CofaxToolsUtil.getI18NMessage(req.getLocale(), "deleted") + ".");
156         }
157         
158                 
159         String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "insertArticle");
160         HashMap hto = CofaxToolsDbUtils.getNameValuePackageHash(db, ht, tag);
161             
162
163         itemID = (String JavaDoc) hto.get("ITEMID");
164         req.setAttribute("itemID",itemID);
165         int test = Integer.parseInt(itemID);
166         try {
167             if (test <= 0) {
168                 return (CofaxToolsUtil.getI18NMessage(req.getLocale(), "cofdbutil_changesto") + " " + fileName + " " +
169                         CofaxToolsUtil.getI18NMessage(req.getLocale(), "cofdbutil_notimplemented"));
170             }
171         } catch (Exception JavaDoc e) {
172             CofaxToolsUtil.log("CofaxToolsUtil setArticle ERROR: " + e);
173             e.printStackTrace(System.err);
174         }
175
176         if (!user.userPreviousArticlesHash.containsKey(itemID) && (!fileName.equals(""))) {
177             user.userPreviousArticlesHash.put(fileName, toolsPath +
178                     "?mode=article_edit_article_by_itemID&ITEMID=" +
179                     itemID + "&hl=article_create_article");
180         }
181         // insert or delete mappings associated with story
182
try {
183             int numMappings = Integer.parseInt((String JavaDoc) req.getAttribute("numMappings"));
184             for (int i = 1; i < numMappings; i++) {
185                 String JavaDoc mappingCode = (String JavaDoc) req.getAttribute("MAPPINGCODE" + i);
186                 String JavaDoc rank = (String JavaDoc) req.getAttribute("RANK" + i);
187                 if ((rank == null) || (rank.equals(""))) {
188                     rank = "999";
189                 }
190                 if ((mappingCode != null) && (rank != null)
191                          && (!mappingCode.equals("")) && (!rank.equals(""))) {
192                     HashMap htTemp = new HashMap();
193                     htTemp.put("ITEMID", itemID);
194                     htTemp.put("RANK", rank);
195                     htTemp.put("MAPPINGCODE", mappingCode);
196
197                     if (req.getAttribute("mappingDelete" + i) != null) {
198                         tag = ("deleteMap");
199                     } else {
200
201                         tag = ("insertMap");
202                     }
203                     tag = CofaxToolsDbUtils.fillTag(db, tag);
204                     List list = CofaxToolsDbUtils.getPackageData(db, htTemp, tag);
205                 }
206             }
207         } catch (Exception JavaDoc e) {
208             CofaxToolsUtil.log("CofaxToolsUtil setArticle ERROR: " + e);
209             e.printStackTrace(System.err);
210         }
211
212         // insert or delete links associated with story
213
try {
214             int numLinks = Integer.parseInt((String JavaDoc) req.getAttribute("numLinks"));
215             for (int iii = 0; iii < numLinks; iii++) {
216                 String JavaDoc relatedLink = (String JavaDoc) req.getAttribute("relatedLink" + iii);
217                 String JavaDoc relatedLinkText = (String JavaDoc) req.getAttribute("relatedLinkText" + iii);
218                 String JavaDoc relatedLinkRank = (String JavaDoc) req.getAttribute("relatedLinkRank" + iii);
219                 if ((!relatedLinkText.equals("")) && (!relatedLink.equals(""))) {
220                     HashMap htTempTwo = new HashMap();
221                     htTempTwo.put("ITEMID", itemID);
222                     htTempTwo.put("LINK", relatedLink);
223                     htTempTwo.put("RANK", relatedLinkRank);
224                     htTempTwo.put("TEXT", relatedLinkText);
225
226                     tag = ("deleteRelatedLinkByItemID");
227                     tag = CofaxToolsDbUtils.fillTag(db, tag);
228                     List listThree = CofaxToolsDbUtils.getPackageData(db, htTempTwo, tag);
229
230                     if (req.getAttribute("deleteRelatedLink" + iii) != null) {
231                     } else {
232                         tag = ("insertRelatedLinkByItemID");
233                         tag = CofaxToolsDbUtils.fillTag(db, tag);
234                         List listFour = CofaxToolsDbUtils.getPackageData(db, htTempTwo, tag);
235                     }
236                 }
237             }
238         } catch (Exception JavaDoc e) {
239             CofaxToolsUtil.log("CofaxToolsUtil setArticle ERROR: " + e);
240             e.printStackTrace(System.err);
241         }
242
243         // insert or delete MultiMedia items associated with the story
244
int numMultiMediaItems = Integer.parseInt((String JavaDoc) req.getAttribute("numMultiMediaItems"));
245
246         for (int i = 0; i < numMultiMediaItems; i++) {
247             String JavaDoc multiMediaCaption = (String JavaDoc) req.getAttribute("multiMediaCaption" + i);
248             String JavaDoc deleteMultiMedia = (String JavaDoc) req.getAttribute("deleteMultiMedia" + i);
249             String JavaDoc uploadImage = (String JavaDoc) req.getAttribute("uploadImage" + i);
250             
251             CofaxToolsUtil.log("upLoadImage : " + uploadImage);
252             
253             if (uploadImage==null) uploadImage="";
254             String JavaDoc multiMediaType = (String JavaDoc) req.getAttribute("multiMediaType" + i);
255             String JavaDoc multiMediaID = (String JavaDoc) req.getAttribute("MULTIMEDIAID" + i);
256             String JavaDoc itemName = (String JavaDoc) req.getAttribute("itemName" + i);
257             String JavaDoc size = (String JavaDoc) req.getAttribute("SIZE" + i);
258             String JavaDoc newUpload = (String JavaDoc) req.getAttribute("newUpload"+i);
259             
260             String JavaDoc articleImageName = "";
261             String JavaDoc tagtwo = "";
262             HashMap htTempTwo = new HashMap();
263             htTempTwo.put("ITEMID", itemID);
264             // added by fx for storing the original file name
265
htTempTwo.put("FILENAME", CofaxToolsFTP.stripPath(uploadImage));
266             CofaxToolsUtil.log("récupération du nom de fichier pur : " + uploadImage);
267            
268             if (deleteMultiMedia != null) {
269                 htTempTwo.put("MULTIMEDIAID", multiMediaID);
270                 tagtwo = ("deleteMultiMedia");
271                 /* LTN Lacomblez - 2006/06/22 : delete multimedia file */
272                 String JavaDoc filename = CofaxToolsServlet.staticFolder;
273                 int positionOfLastSlash = filename.lastIndexOf(File.separatorChar);
274                 if (positionOfLastSlash != -1) filename += File.separator;
275                 filename += user.workingPubName + File.separator;
276                 filename += CofaxToolsServlet.articleRessourceFolder + File.separator + itemName;
277                 File myFile = new File(filename);
278                 myFile.delete();
279                 CofaxToolsUtil.log("File deleted : " + myFile.toString());
280                 
281                 /* --------------------------------------------------- */
282             } else {
283                 if (newUpload != null && newUpload.equals("yes")) {
284                     String JavaDoc fileExtension = CofaxToolsUtil.getFileExtension(uploadImage);
285                     if (multiMediaType.equals("sectionImage")) {
286                         fileExtension = ".I" + fileExtension;
287                     }
288                     if (multiMediaType.equals("other")) {
289                         fileExtension = "." + numMultiMediaItems + fileExtension;
290                     }
291                     articleImageName = itemID + fileExtension;
292                 } else {
293                     CofaxToolsUtil.log("ItemName : " + itemName);
294                     if ((itemName != null) && (!itemName.equals(""))) {
295                         
296                         articleImageName = itemName;
297                         CofaxToolsUtil.log("ArticleImageName is becoming itemName: " + articleImageName);
298                     }
299                     htTempTwo.put("SIZE", size);
300                     
301                 }
302                 htTempTwo.put("articleImageName", articleImageName);
303                 
304                 CofaxToolsUtil.log("Article image Name : " + articleImageName);
305                 
306                 // FX : Changinf IF test case
307

308                 if ((articleImageName!=null) && !(articleImageName.equals(""))
309                     && articleImageName.indexOf(".")>0
310                         )
311                     htTempTwo.put("ICON", "" + CofaxToolsServlet.aliasPath + "/static/images/" + articleImageName.substring(articleImageName.length()-3) + ".gif");
312                 
313                 if ((multiMediaID != null) && (!multiMediaID.equals(""))) {
314                     htTempTwo.put("MULTIMEDIAID", multiMediaID);
315                 }
316                 if ((multiMediaType != null) && (!multiMediaType.equals(""))) {
317                     htTempTwo.put("multiMediaType", multiMediaType);
318                 }
319                 if ((multiMediaCaption != null) && (!multiMediaCaption.equals(""))) {
320                     htTempTwo.put("multiMediaCaption", multiMediaCaption);
321                 }
322                 tagtwo = ("insertMultimedia");
323
324
325                 if ( newUpload != null
326                     && newUpload.equals("yes")
327                     && uploadImage != null
328                     && !uploadImage.equals("")
329                     )
330                     
331                     {
332                     String JavaDoc newFilePath = CofaxToolsServlet.staticFolder;
333                     int positionOfLastSlash = newFilePath.lastIndexOf(File.separatorChar);
334                     if (positionOfLastSlash != -1) {
335                         newFilePath += File.separator;
336                     }
337                     newFilePath += user.workingPubName + File.separator;
338                     
339                     // FX :
340
/*
341                     newFilePath += CofaxToolsServlet.articleRessourceFolder + File.separator ;
342                     //newFilePath += year + File.separator + month + File.separator + day;
343                     newFilePath += itemID;
344                     */

345                     // LTN Lacomblez
346
newFilePath += CofaxToolsServlet.articleRessourceFolder;
347                     
348                     // FX :
349
CofaxToolsUtil.log("CofaxToolsUtil: storing ... " + newFilePath);
350                     
351                     File createPath = new File(newFilePath);
352                     if (!createPath.exists()) {
353                         CofaxToolsUtil.log("CofaxToolsUtil: creating directory " + newFilePath);
354                         boolean createdDir = false;
355                         try {
356                             createdDir = createPath.mkdirs();
357                         } catch (Exception JavaDoc e) {
358                             CofaxToolsUtil.log("CofaxToolsUtil.setArticle creating " +
359                                     newFilePath +
360                                     "threw an exception: " + e);
361                         }
362                         if (createdDir) {
363                             CofaxToolsUtil.log("CofaxToolsUtil.setArticle created dir: " +
364                                     newFilePath);
365                         } else {
366                             CofaxToolsUtil.log("CofaxToolsUtil.setArticle ERROR creating dir:" +
367                                     newFilePath);
368                         }
369                     }
370                     String JavaDoc orgFilePath = CofaxToolsServlet.fileTransferFolder;
371                     positionOfLastSlash = orgFilePath.lastIndexOf(File.separatorChar);
372                     if (positionOfLastSlash != -1) {
373                         orgFilePath += File.separator;
374                     }
375                     orgFilePath += CofaxToolsFTP.stripPath(uploadImage);
376                     File orgFile = new File(orgFilePath);
377
378                     //get the file size
379
try {
380                         double sizeFile = (double)orgFile.length() / 1000;
381                         long sizeFileLong = java.lang.Math.round(sizeFile);
382                         htTempTwo.put("SIZE",sizeFileLong + " Ko");
383                     } catch (Exception JavaDoc e) { System.out.println("Error while retrieving file size : " + e); }
384                     
385                     File newFile = new File(newFilePath + File.separator + articleImageName);
386                     if (newFile.exists()) {
387                         newFile.delete();
388                     }
389                     CofaxToolsUtil.log("CofaxToolsDbUtils: Renaming " + orgFilePath + " to " +
390                         newFile);
391                     boolean uploaded = false;
392                     try {
393                         uploaded = orgFile.renameTo(newFile);
394                     } catch(Exception JavaDoc e) {
395                         CofaxToolsUtil.log("CofaxToolsDbUtils: failed remaning fileName." + e.toString());
396                     }
397                     CofaxToolsUtil.log("CofaxToolsDbUtils: Uploading " + articleImageName + " " +
398                                 uploadImage + " ");
399                     
400
401                     // If supplied servers to FTP to... then upstream this image
402
// TODO: THIS IS BROKEN
403
String JavaDoc liveFTPServer =
404                             (String JavaDoc) user.workingPubConfigElementsHash.get("LIVEFTPSERVER") + "";
405                     liveFTPServer = liveFTPServer.trim();
406                     if ((liveFTPServer != null) && (!liveFTPServer.equals("null")) &&
407                             (!liveFTPServer.equals(""))) {
408                         CofaxToolsUtil.log("CofaxToolsUtil setArticle uploading media: " +
409                                 uploadImage);
410                         String JavaDoc s = CofaxToolsFTP.uploadArticleMedia(newFilePath, articleImageName,
411                                     year, month, day, db, session);
412                         CofaxToolsUtil.log("CofaxToolsUtil setArticle upload results: " + s);
413                     }
414
415                 }
416             }
417
418             if ((multiMediaType != null) && (!multiMediaType.equals(""))) {
419                 tagtwo = CofaxToolsDbUtils.fillTag(db, tagtwo);
420                 List list = CofaxToolsDbUtils.getPackageData(db, htTempTwo, tagtwo);
421             }
422         }
423
424         // Clear the cache associated with the article
425
HashMap fillReq = new HashMap();
426         fillReq.put("ITEMID", itemID);
427         tag = CofaxToolsDbUtils.fillTag(db, "getVirtualFolderFromViewAllByItemID");
428         HashMap htTemp = CofaxToolsDbUtils.getNameValuePackageHash(db, fillReq, tag);
429
430         String JavaDoc virtualFolder = (String JavaDoc) htTemp.get("VIRTUALFOLDER");
431         String JavaDoc URLToClear = CofaxToolsServlet.removePageCache + "/" +
432                 virtualFolder + "/" + fileName + ".htm";
433         //clear also the cache of the parent section
434
String JavaDoc URLToClear2 = CofaxToolsServlet.removePageCache + "/" +
435                 virtualFolder + "/";
436         String JavaDoc sServers = (String JavaDoc) user.workingPubConfigElementsHash.get("CACHESERVERS");
437
438         ArrayList servers = new ArrayList();
439         if (sServers.indexOf(",") > -1) {
440             servers = CofaxToolsFTP.splitServers(sServers);
441         } else {
442             servers.add(sServers);
443         }
444
445         for (int i = 0; i < servers.size(); i++) {
446             CofaxToolsClearCache clear = new CofaxToolsClearCache("HTTP://" +
447                     servers.get(i) + URLToClear);
448             clear.start();
449             CofaxToolsClearCache clear2 = new CofaxToolsClearCache("HTTP://" +
450                     servers.get(i) + URLToClear2);
451             clear2.start();
452         }
453
454         return ("'" + fileName + "' : " + CofaxToolsUtil.getI18NMessage(req.getLocale(),"tools_articlesaved"));
455     }
456
457
458
459     /**
460      * Updates security info into the securities table table.
461      *
462      *@param db The new security value
463      *@param req The new security value
464      *@return Description of the Return Value
465      */

466     public static String JavaDoc setSecurity(DataStore db, HttpServletRequest req) {
467
468         List modesAndTypes = (ArrayList) CofaxToolsUtil.getModes(db);
469         Vector groupTypeIDs = CofaxToolsUtil.getGroupTypeIDs(db);
470         Vector modes = new Vector();
471
472         Iterator miti = modesAndTypes.iterator();
473
474         while (miti.hasNext()) {
475             Object JavaDoc key = miti.next();
476             HashMap ht = (HashMap) key;
477             String JavaDoc modeName = (String JavaDoc) ht.get("MODES");
478             if (!modes.contains(modeName)) {
479                 modes.add(modeName);
480             }
481         }
482
483         int i = 0;
484
485         Iterator mit = modes.iterator();
486         while (mit.hasNext()) {
487             String JavaDoc mode = (String JavaDoc) mit.next();
488             Iterator git = groupTypeIDs.iterator();
489             while (git.hasNext()) {
490                 String JavaDoc type = (String JavaDoc) git.next();
491                 String JavaDoc checked = mode + "." + type;
492                 String JavaDoc value = req.getParameter(checked);
493                 String JavaDoc tag = "";
494                 HashMap fillReq = new HashMap();
495                 String JavaDoc delete = "0";
496                 if (value != null) {
497                     delete = "0";
498                 } else {
499                     delete = "1";
500                 }
501
502                 fillReq.put("DELETE", delete);
503                 fillReq.put("MODES", mode);
504                 fillReq.put("TYPE", type);
505
506                 tag = CofaxToolsDbUtils.fillTag(db, "updateModes");
507                 List list = CofaxToolsDbUtils.getPackageData(db, fillReq, tag);
508             }
509         }
510
511         return (CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_securitychange"));
512     }
513
514
515     /**
516      * Updates article types into the article types table.
517      *
518      *@param db The new articleType value
519      *@param req The new articleType value
520      *@return Description of the Return Value
521      */

522     public static String JavaDoc setArticleType(DataStore db, HttpServletRequest req) {
523
524         String JavaDoc articleTypeMappingCode = req.getParameter("ARTICLETYPEMAPPINGCODE");
525         String JavaDoc articleTypeCategory = req.getParameter("ARTICLETYPECATEGORY");
526         String JavaDoc articleTypeCode = req.getParameter("ARTICLETYPE");
527         String JavaDoc articleTypeDesc = req.getParameter("ARTICLETYPEDESC");
528         String JavaDoc articleTypeName = req.getParameter("ARTICLETYPENAME");
529
530         if ((articleTypeCode == null) || (articleTypeCode.equals("")) ||
531                 (articleTypeMappingCode == null) || (articleTypeMappingCode.equals("")) ||
532                 (articleTypeCategory == null) || (articleTypeCategory.equals("")) ||
533                 (articleTypeDesc == null) || (articleTypeDesc.equals("")) ||
534                 (articleTypeName == null) || (articleTypeName.equals(""))
535                 ) {
536             return (CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_badarticletype"));
537         }
538
539         HashMap ht = CofaxToolsUtil.splitPostQuery(req);
540         String JavaDoc disableArticleType = req.getParameter("DISABLEARTICLETYPE");
541         String JavaDoc articleTypeDisplayOnIndex = req.getParameter("ARTICLETYPEDISPLAYONINDEX");
542         disableArticleType = CofaxToolsUtil.convertCheckedToBoolean(disableArticleType);
543         articleTypeDisplayOnIndex =
544                 CofaxToolsUtil.convertCheckedToBoolean(articleTypeDisplayOnIndex);
545         ht.put("DISABLEARTICLETYPE", disableArticleType);
546         ht.put("ARTICLETYPEDISPLAYONINDEX", articleTypeDisplayOnIndex);
547
548         String JavaDoc articleTypeID = req.getParameter("ARTICLETYPEID");
549         if ((articleTypeID == null) || (articleTypeID.equals(""))) {
550             articleTypeID = "0";
551             ht.put("ARTICLETYPEID", articleTypeID);
552
553         }
554       
555
556         String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "insertArticleType");
557         List list = CofaxToolsDbUtils.getPackageData(db, ht, tag);
558         return (CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_changesto") + " " + req.getParameter("ARTICLETYPEDESC") +
559                 " " + CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_implemented"));
560     }
561
562
563     /**
564      * Updates sections into the section table.
565      *
566      *@param db The new section value
567      *@param req The new section value
568      *@return Description of the Return Value
569      */

570     public static String JavaDoc setSection(DataStore db, HttpServletRequest req, HttpSession session, String JavaDoc userID) {
571         HashMap ht = CofaxToolsUtil.splitPostQuery(req);
572         String JavaDoc displayOnIndex = req.getParameter("DISPLAYONINDEX");
573         displayOnIndex = CofaxToolsUtil.convertCheckedToBoolean(displayOnIndex);
574         ht.put("DISPLAYONINDEX", displayOnIndex);
575
576         String JavaDoc section = req.getParameter("SECTION");
577         String JavaDoc sectionName = req.getParameter("SECTIONNAME");
578         String JavaDoc sectionDesc = req.getParameter("SECTIONDESC");
579         String JavaDoc subMapOf = req.getParameter("SUBMAPOF");
580         String JavaDoc keywords = req.getParameter("KEYWORDS");
581         String JavaDoc rank = req.getParameter("RANK");
582         if (rank.equals("") || (rank == null)) {
583             rank = "999";
584         }
585         if (subMapOf.equals("") || (subMapOf == null)) {
586             ht.put("SUBMAPOF", "0");
587         }
588         ht.put("RANK", rank);
589         ht.put("USERID",userID);
590         ht.put("KEYWORDS",keywords);
591         //delete an empty section
592
String JavaDoc deleteSection = req.getParameter("DELETESECTION");
593         if (deleteSection != null && deleteSection.equals("on")) {
594             Vector u_sections = null;
595             StringBuffer JavaDoc v = new StringBuffer JavaDoc();
596             v.append("SELECT mappingCode FROM tblsections WHERE subMapOf = 'req:MAPPINGCODE' ");
597             u_sections = CofaxToolsDbUtils.getPackageVector(db,ht,v.toString());
598             if (u_sections.size() > 0 && u_sections != null) {
599                 return(CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_cantdeletesubsections"));
600             }
601             else {
602                 String JavaDoc pubName = (String JavaDoc)req.getParameter("PUBNAME");
603                 String JavaDoc mappingCode = (String JavaDoc)req.getParameter("MAPPINGCODE");
604                 StringBuffer JavaDoc v_s = new StringBuffer JavaDoc();
605                 v_s.append("SELECT tblarticles.itemID FROM tblarticles ")
606                    .append("WHERE tblarticles.section='" + section + "' AND tblarticles.pubname='" + pubName + "' ");
607                 List articles = CofaxToolsDbUtils.getPackageData(db, ht, v_s.toString());
608                 
609                 Iterator it = articles.iterator();
610                 if (it.hasNext()) {
611                     return(CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbtuil_sectionhasarticles"));
612                 }
613                 else {
614                     StringBuffer JavaDoc v_delete2 = new StringBuffer JavaDoc();
615                     v_delete2.append("DELETE FROM tblpermusersection WHERE mappingCode = '" + mappingCode + "' ");
616                     List del2 = CofaxToolsDbUtils.getPackageData(db, ht, v_delete2.toString());
617
618                     StringBuffer JavaDoc v_delete = new StringBuffer JavaDoc();
619                     v_delete.append("DELETE FROM tblsections WHERE mappingCode = '" + mappingCode + "' ");
620                     List del = CofaxToolsDbUtils.getPackageData(db, ht, v_delete.toString());
621             
622                     return(CofaxToolsUtil.getI18NMessage(req.getLocale(),"section") + " " + sectionName + " " + CofaxToolsUtil.getI18NMessage(req.getLocale(),"deleted"));
623                 }
624             }
625         }
626
627         // check if there's already the same codes in the base
628
String JavaDoc pubName = (String JavaDoc)req.getParameter("PUBNAME");
629         String JavaDoc mappingCode = (String JavaDoc)req.getParameter("MAPPINGCODE");
630         if ((mappingCode.equals("")) || (mappingCode.equals("0"))) {
631             StringBuffer JavaDoc v_s = new StringBuffer JavaDoc();
632             v_s.append("SELECT mappingCode FROM tblsections ")
633                .append("WHERE section='" + section + "' AND pubname='" + pubName + "' ");
634                //.append("AND subMapOf='" + subMapOf +"' ");
635
List sections = CofaxToolsDbUtils.getPackageData(db, ht, v_s.toString());
636             
637             Iterator it = sections.iterator();
638             if (it.hasNext()) {
639                 return(CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_doublesectioncode"));
640             }
641         }
642
643         if ((section.equals("")) || (sectionName.equals("")) || (sectionDesc.equals(""))) {
644             return (CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_changesto") + " " + req.getParameter("SECTIONDESC") +
645                     CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_badsection"));
646         }
647
648         //check if the parent section is not a sub section or the same section
649
if (!(subMapOf.equals("0"))) {
650             if (subMapOf.equals(mappingCode)) return (CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_subsectionnosame"));
651             
652             String JavaDoc subMapOf2 = subMapOf;
653             while ( !(subMapOf2.equals("0")) && !(subMapOf2.equals("")) )
654             {
655                 if (subMapOf2.equals(mappingCode)) return (CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_subsectionnoparent"));
656                 StringBuffer JavaDoc v1 = new StringBuffer JavaDoc();
657                 String JavaDoc tag= "SELECT subMapOf FROM tblsections WHERE mappingCode='" + subMapOf2 +"'";
658                 HashMap ht2 = new HashMap();
659                 HashMap htTemp = CofaxToolsDbUtils.getNameValuePackageHash(db, ht2, tag);
660                 subMapOf2 = (String JavaDoc) htTemp.get("SUBMAPOF");
661                 if (subMapOf2==null) subMapOf2="0";
662             }
663         }
664
665         
666         String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "insertMappingCode");
667         List list = CofaxToolsDbUtils.getPackageData(db, ht, tag);
668         if (!db.getError()) {
669             // Clear the cache associated with the updated section
670
String JavaDoc virtualFolder = pubName + "/" + sectionName;
671             String JavaDoc URLToClear = CofaxToolsServlet.removePageCache+"/"+virtualFolder+"/";
672             CofaxToolsUser user = (CofaxToolsUser) session.getAttribute("user");
673             String JavaDoc sServers = (String JavaDoc)user.workingPubConfigElementsHash.get("CACHESERVERS");
674     
675             ArrayList servers = new ArrayList();
676             if (sServers.indexOf(",") > -1) { servers = CofaxToolsFTP.splitServers(sServers);}
677             else { servers.add(sServers); }
678     
679             for (int i =0; i < servers.size(); i ++){
680                 CofaxToolsClearCache clear = new CofaxToolsClearCache("HTTP://"+servers.get(i)+URLToClear);
681                 clear.start();
682             }
683                     
684         
685             return (CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_changesto") + " " + req.getParameter("SECTIONDESC") + " " +
686                     CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_implemented"));
687         } else {
688             CofaxToolsUtil.log("CofaxToolsUtil setSection ERROR: " + db.getLastError());
689             return (CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_changesto") + " " + req.getParameter("SECTIONDESC") +
690                       " " + CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_notimplemented"));
691         }
692     }
693
694
695
696     /**
697      * Updates or inserts info into the articleOrder and creates new stories if
698      * needed.
699      *
700      *@param db The new orderSection value
701      *@param req The new orderSection value
702      *@return Description of the Return Value
703      */

704     public static String JavaDoc setOrderSection(DataStore db, HttpServletRequest req) {
705
706         HashMap ht = new HashMap();
707         int listSize = Integer.parseInt(req.getParameter("listSize"));
708         int listFilledSize = Integer.parseInt(req.getParameter("listFilledSize"));
709         String JavaDoc tag = "";
710         String JavaDoc mapTo = req.getParameter("mapTo");
711         for (int i = 1; i <= listFilledSize; i++) {
712
713             String JavaDoc rank = req.getParameter("RANK" + i);
714             String JavaDoc itemID = req.getParameter("ITEMID" + i);
715             String JavaDoc mappingCode = req.getParameter("MAPPINGCODE" + i);
716             String JavaDoc section = req.getParameter("SECTION" + i);
717             String JavaDoc fileName = req.getParameter("FILENAME" + i);
718             String JavaDoc pubName = req.getParameter("PUBNAME" + i);
719             String JavaDoc pubDate = req.getParameter("PUBDATE" + i);
720             String JavaDoc disableArticle = req.getParameter("DISABLEARTICLE" + i);
721             String JavaDoc disableIndex = req.getParameter("DISABLEINDEX" + i);
722
723             ht.put("ITEMID", itemID);
724             ht.put("MAPPINGCODE", mappingCode);
725             ht.put("RANK", rank);
726             if (req.getParameter("remove" + i) != null) {
727                 tag = ("deleteMap");
728             } else {
729                 tag = ("insertMap");
730             }
731             tag = CofaxToolsDbUtils.fillTag(db, tag);
732             List temp = CofaxToolsDbUtils.getPackageData(db, ht, tag);
733
734             if (req.getParameter("remove" + i) == null) {
735                 // disable on section front or index if user desires
736
if (req.getParameter("DISABLEARTICLE" + i) != null) {
737                     disableArticle = "1";
738                 } else {
739                     disableArticle = "0";
740                 }
741                 if (req.getParameter("DISABLEINDEX" + i) != null) {
742                     disableIndex = "1";
743                 } else {
744                     disableIndex = "0";
745                 }
746
747                 HashMap disable = new HashMap();
748                 disable.put("DISABLEARTICLE", disableArticle);
749                 disable.put("DISABLEINDEX", disableIndex);
750                 disable.put("ITEMID", itemID);
751                 String JavaDoc tagTemp = CofaxToolsDbUtils.fillTag(db, "updateArticleDisableIndex");
752                 List list = CofaxToolsDbUtils.getPackageData(db, disable, tagTemp);
753             }
754         }
755
756         for (int i = listFilledSize + 1; i <= listSize; i++) {
757             String JavaDoc year = req.getParameter("date" + i + "year");
758             String JavaDoc month = req.getParameter("date" + i + "month");
759             String JavaDoc day = req.getParameter("date" + i + "day");
760
761             if (month.length() == 1) {
762                 month = "0" + month;
763             }
764             if (day.length() == 1) {
765                 day = "0" + day;
766             }
767
768             String JavaDoc pubDate = (year + "-" + month + "-" + day);
769             String JavaDoc fileName = req.getParameter("FILENAME" + i);
770             String JavaDoc mappingCode = req.getParameter("MAPPINGCODE" + i);
771             String JavaDoc rank = req.getParameter("RANK" + i);
772             String JavaDoc section = req.getParameter("SECTION" + i);
773
774             ht.put("FILENAME", fileName);
775             ht.put("PUBDATE", pubDate);
776             ht.put("SECTION", section);
777             ht.put("MAPPINGCODE", mappingCode);
778
779             if ((fileName != null) && (!fileName.equals(""))) {
780
781                 tag = ("getItemIDByFileNameMapCodePubDate");
782                 tag = CofaxToolsDbUtils.fillTag(db, tag);
783                 HashMap htTemp = CofaxToolsDbUtils.getNameValuePackageHash(db, ht, tag);
784
785                 String JavaDoc itemID = "";
786
787                 Iterator en = htTemp.keySet().iterator();
788                 while (en.hasNext()) {
789                     String JavaDoc key = (String JavaDoc) en.next();
790                     itemID = (String JavaDoc) htTemp.get(key);
791                 }
792
793                 HashMap fillReq = new HashMap();
794                 fillReq.put("MAPPINGCODE", mappingCode);
795                 tag = CofaxToolsDbUtils.fillTag(db, "selectPubNameAndSectionByMappingCode");
796                 HashMap htTempo = CofaxToolsDbUtils.getNameValuePackageHash(db, fillReq, tag);
797                 String JavaDoc pubName = (String JavaDoc) htTempo.get("PUBNAME");
798                 section = (String JavaDoc) htTempo.get("SECTION");
799                 ht.put("PUBNAME", pubName);
800                 ht.put("SECTION", section);
801
802                 if ((itemID.equals("")) || (itemID == null)) {
803                     // get a new item id here
804
System.err.println("GOT INTO INSERTARTICLEWIZARD");
805                     tag = ("insertArticleWizard");
806                     tag = CofaxToolsDbUtils.fillTag(db, tag);
807                     HashMap hta = CofaxToolsDbUtils.getNameValuePackageHash(db, ht, tag);
808                     itemID = (String JavaDoc) hta.get("ITEMID");
809                 }
810                 // change the pub to the pub this article was mapped to in
811
// order to insert the mapping
812

813                 ht.put("ITEMID", itemID);
814                 ht.put("mapTo", mapTo);
815                 ht.put("MAPPINGCODE", mapTo);
816                 ht.put("RANK", rank);
817                 tag = CofaxToolsDbUtils.fillTag(db, "insertMap");
818                 List listtt = CofaxToolsDbUtils.getPackageData(db, ht, tag);
819             }
820         }
821         return (CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_sectionordered"));
822     }
823
824
825
826
827
828     /**
829      * Updates or inserts info into the group table.
830      *
831      *@param db The new groupInfo value
832      *@param req The new groupInfo value
833      *@return Description of the Return Value
834      */

835     public static String JavaDoc setGroupInfo(DataStore db, HttpServletRequest req) {
836         HashMap ht = CofaxToolsUtil.splitPostQuery(req);
837         String JavaDoc tag = "";
838
839         String JavaDoc delete = (String JavaDoc) ht.get("delete");
840         String JavaDoc groupID = (String JavaDoc) ht.get("GROUPID");
841         String JavaDoc groupName = (String JavaDoc) ht.get("GROUPNAME");
842         if ((groupID == null) || (groupID.equals(""))) {
843             groupID = "0";
844         }
845         ht.put("GROUPID", groupID);
846
847         if ((groupID.equals("0")) && (delete != null) && (!delete.equals(""))) {
848             return (CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_deletebadgroup"));
849         }
850
851         // if the group needs to be deleted, first determine that there are no
852
// users atached to it. If there are,
853
// force the admin to remove those groups from the users.
854
if ((delete != null) && (!delete.equals(""))) {
855             HashMap deleteTemp = new HashMap();
856             deleteTemp.put("GROUPID", groupID);
857             tag = CofaxToolsDbUtils.fillTag(db, "getGroupedUsers");
858             HashMap groupedUsers =
859                     CofaxToolsDbUtils.getValueValuePackageHash(db, deleteTemp,
860                     tag, "USERNAME", "USERID");
861
862             StringBuffer JavaDoc results = new StringBuffer JavaDoc();
863             results.append(CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_deletegroupwithusers"));
864             if (groupedUsers.size() > 0) {
865                 Iterator i = groupedUsers.keySet().iterator();
866                 while (i.hasNext()) {
867                     String JavaDoc key = (String JavaDoc) i.next();
868                     String JavaDoc val = (String JavaDoc) groupedUsers.get(key);
869                     results.append("<BR>" + val + ": " + key);
870                 }
871                 return (results.toString());
872             } else {
873                 tag = CofaxToolsDbUtils.fillTag(db, "deleteGroups");
874                 List deletedGroup = CofaxToolsDbUtils.getPackageData(db, deleteTemp, tag);
875                 return (CofaxToolsUtil.getI18NMessage(req.getLocale(),"group") + " " + groupID + " (" + groupName + ")" + " " + CofaxToolsUtil.getI18NMessage(req.getLocale(),"deleted"));
876             }
877
878         }
879
880         boolean nonSelectedDelete = true;
881         String JavaDoc[] selectedPublications = (String JavaDoc[]) req.getParameterValues("selectedPublications");
882         String JavaDoc[] nonSelectedPublications = (String JavaDoc[]) req.getParameterValues("nonSelectPubs");
883         if (nonSelectedPublications == null) {
884             nonSelectedDelete = false;
885         }
886
887         if (selectedPublications == null) {
888             return (CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_groupselectpub"));
889         }
890         if (groupName.equals("")) {
891             return (CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_nogroupname"));
892         }
893
894         // check to see that at least one publication and not more than 50 have been added to the group
895

896         if (selectedPublications.length == 0) {
897             return (CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_groupnojoinpub"));
898         }
899
900         tag = CofaxToolsDbUtils.fillTag(db, "updateGroups");
901         List list = CofaxToolsDbUtils.getPackageData(db, ht, tag);
902
903         // get the user new id back
904
HashMap hm = (HashMap) list.get(0);
905         groupID = (String JavaDoc) hm.get("GROUPID");
906
907         // add currently chosen pubs
908
HashMap htTempo = new HashMap();
909         for (int i = 0; i < selectedPublications.length; i++) {
910             htTempo.put("GROUPID", groupID);
911             htTempo.put("PUBID", selectedPublications[i]);
912             htTempo.put("DELETE", "0");
913             tag = CofaxToolsDbUtils.fillTag(db, "updateGroupToPublication");
914             List temp = CofaxToolsDbUtils.getPackageData(db, htTempo, tag);
915         }
916
917         // delete currently non chosen pubs
918
if (nonSelectedDelete == true) {
919             for (int i = 0; i < nonSelectedPublications.length; i++) {
920                 htTempo.put("GROUPID", groupID);
921                 htTempo.put("PUBID", nonSelectedPublications[i]);
922                 htTempo.put("DELETE", "1");
923                 tag = CofaxToolsDbUtils.fillTag(db, "updateGroupToPublication");
924                 List tempTwo = CofaxToolsDbUtils.getPackageData(db, htTempo, tag);
925             }
926         }
927
928         return (CofaxToolsUtil.getI18NMessage(req.getLocale(),"group") + " " + req.getParameter("GROUPNAME") + " " + CofaxToolsUtil.getI18NMessage(req.getLocale(),"implemented"));
929     }
930
931
932
933     /**
934      * Updates or inserts info into the group type table.
935      *
936      *@param db The new groupTypeInfo value
937      *@param req The new groupTypeInfo value
938      *@return Description of the Return Value
939      */

940     public static String JavaDoc setGroupTypeInfo(DataStore db, HttpServletRequest req) {
941         HashMap ht = CofaxToolsUtil.splitPostQuery(req);
942         String JavaDoc tag = "";
943         String JavaDoc groupTypeName = (String JavaDoc) req.getParameter("GROUPTYPENAME");
944         String JavaDoc groupTypeID = (String JavaDoc) req.getParameter("GROUPTYPEID");
945         String JavaDoc delete = (String JavaDoc) req.getParameter("delete");
946
947         // Make sure that the user cannot create a duplicate group
948
String JavaDoc tempTag = CofaxToolsDbUtils.fillTag(db, "getGroupNameGroupIDFromPermGroupType");
949         HashMap typeInfoCheck = CofaxToolsDbUtils.getValueValuePackageHash(db, tempTag, "GROUPTYPENAME", "GROUPTYPEID");
950
951         if ((groupTypeID == null) || (groupTypeID.equals(""))) {
952             Iterator ite = typeInfoCheck.keySet().iterator();
953             while (ite.hasNext()) {
954                 String JavaDoc gName = (String JavaDoc) ite.next();
955                 gName = gName.toUpperCase();
956                 String JavaDoc gNametest = groupTypeName.toUpperCase();
957                 if (gNametest.equals(gName)) {
958                     return (groupTypeName + CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_duplicategroupname"));
959                 }
960             }
961         }
962
963         // if the end user wants to delete the group type, make sure that they have changed any groups which might have this type
964
if ((delete != null) && (!delete.equals(""))) {
965             StringBuffer JavaDoc results = new StringBuffer JavaDoc();
966             HashMap hp = new HashMap();
967             hp.put("GROUPTYPEID", groupTypeID);
968             hp.put("GROUPTYPE", groupTypeID);
969
970             tag = CofaxToolsDbUtils.fillTag(db, "getGroupNameIDByGroupType");
971             HashMap relatedGroups = CofaxToolsDbUtils.getValueValuePackageHash(db, hp, tag, "GROUPNAME", "GROUPID");
972
973             if (relatedGroups.size() > 0) {
974                 results.append(CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_deleteinusegrouptype"));
975                 Iterator i = relatedGroups.keySet().iterator();
976                 while (i.hasNext()) {
977                     String JavaDoc key = (String JavaDoc) i.next();
978                     String JavaDoc val = (String JavaDoc) relatedGroups.get(key);
979                     results.append("<BR>" + val + ": " + key);
980                 }
981                 return (results.toString());
982             } else {
983                 tag = CofaxToolsDbUtils.fillTag(db, "deleteGroupTypes");
984                 List del = CofaxToolsDbUtils.getPackageData(db, hp, tag);
985                 return (CofaxToolsUtil.getI18NMessage(req.getLocale(),"groupType") + " " + groupTypeID + "(" + groupTypeName + ")" + " " + CofaxToolsUtil.getI18NMessage(req.getLocale(),"deleted"));
986             }
987         }
988
989         if ((groupTypeID == null) || (groupTypeID.equals(""))) {
990             groupTypeID = "0";
991         }
992
993         if (groupTypeName.equals("")) {
994             return (CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_groupneedsname"));
995         }
996
997         ht.put("GROUPTYPEID", groupTypeID);
998
999         tag = CofaxToolsDbUtils.fillTag(db, "updateGroupType");
1000        List list = CofaxToolsDbUtils.getPackageData(db, ht, tag);
1001        return (CofaxToolsUtil.getI18NMessage(req.getLocale(),"groupType") + " " + req.getParameter("GROUPTYPENAME") + " " + CofaxToolsUtil.getI18NMessage(req.getLocale(),"implemented"));
1002    }
1003
1004
1005
1006    /**
1007     * Updates or inserts info into the publication and publication config
1008     * tables.
1009     *
1010     *@param db The new publicationInfo value
1011     *@param req The new publicationInfo value
1012     *@return Description of the Return Value
1013     */

1014    public static String JavaDoc setPublicationInfo(DataStore db, HttpServletRequest req) {
1015        HashMap ht = CofaxToolsUtil.splitPostQuery(req);
1016        String JavaDoc pubID = (String JavaDoc) ht.get("PUBID");
1017        if ((pubID == null) || (pubID.equals(""))) {
1018            pubID = "0";
1019        }
1020        // sanity checks
1021

1022        String JavaDoc PUBDESC = (String JavaDoc) ht.get("PUBDESC");
1023        String JavaDoc TAGLINE = (String JavaDoc) ht.get("TAGLINE");
1024        String JavaDoc PUBNAME = (String JavaDoc) ht.get("PUBNAME");
1025        String JavaDoc ROLLOVERTIME = (String JavaDoc) ht.get("ROLLOVERTIME");
1026        String JavaDoc DEFAULTSECTION = (String JavaDoc) ht.get("DEFAULTSECTION");
1027        String JavaDoc DEFAULTSECTIONWITHDATE = (String JavaDoc) ht.get("DEFAULTSECTIONWITHDATE");
1028        String JavaDoc HOMEPAGE = (String JavaDoc) ht.get("HOMEPAGE");
1029        String JavaDoc DOMAINNAME = (String JavaDoc) ht.get("DOMAINNAME");
1030        String JavaDoc TESTFTPSERVER = (String JavaDoc) ht.get("TESTFTPSERVER");
1031        String JavaDoc TESTFTPLOGIN = (String JavaDoc) ht.get("TESTFTPLOGIN");
1032        String JavaDoc TESTFTPPASSWORD = (String JavaDoc) ht.get("TESTFTPPASSWORD");
1033        String JavaDoc TESTTEMPLATEFOLDER = (String JavaDoc) ht.get("TESTTEMPLATEFOLDER");
1034        String JavaDoc TESTIMAGESFOLDER = (String JavaDoc) ht.get("TESTIMAGESFOLDER");
1035        String JavaDoc LIVEFTPSERVER = (String JavaDoc) ht.get("LIVEFTPSERVER");
1036        String JavaDoc LIVEFTPLOGIN = (String JavaDoc) ht.get("LIVEFTPLOGIN");
1037        String JavaDoc LIVEFTPPASSWORD = (String JavaDoc) ht.get("LIVEFTPPASSWORD");
1038        String JavaDoc LIVETEMPLATEFOLDER = (String JavaDoc) ht.get("LIVETEMPLATEFOLDER");
1039        String JavaDoc LIVEIMAGESSERVER = (String JavaDoc) ht.get("LIVEIMAGESSERVER");
1040        String JavaDoc LIVEIMAGESFOLDER = (String JavaDoc) ht.get("LIVEIMAGESFOLDER");
1041        String JavaDoc IMPORTFTPSERVER = (String JavaDoc) ht.get("IMPORTFTPSERVER");
1042        String JavaDoc IMPORTFTPLOGIN = (String JavaDoc) ht.get("IMPORTFTPLOGIN");
1043        String JavaDoc IMPORTFTPPASSWORD = (String JavaDoc) ht.get("IMPORTFTPPASSWORD");
1044        String JavaDoc IMPORTFTPFILEPATH = (String JavaDoc) ht.get("IMPORTFTPFILEPATH");
1045        String JavaDoc IMPORTFTPFILECONTENTS = (String JavaDoc) ht.get("IMPORTFTPFILECONTENTS");
1046        String JavaDoc MAINCOFAXSERVER = (String JavaDoc) ht.get("MAINCOFAXSERVER");
1047        String JavaDoc IMAGESURLPREFIX = (String JavaDoc) ht.get("IMAGESURLPREFIX");
1048        String JavaDoc CACHESERVERS = (String JavaDoc) ht.get("CACHESERVERS");
1049        String JavaDoc PUBLICATION = (String JavaDoc) ht.get("PUBLICATION");
1050
1051        if ((PUBDESC == null) || (PUBDESC.equals("")) ||
1052                (PUBNAME == null) || (PUBNAME.equals("")) ||
1053                (PUBLICATION == null) || (PUBLICATION.equals("")) ||
1054                (ROLLOVERTIME == null) || (ROLLOVERTIME.equals("")) ||
1055                (DEFAULTSECTION == null) ||
1056                (DEFAULTSECTIONWITHDATE == null) || (DEFAULTSECTIONWITHDATE.equals("")) ||
1057                (DOMAINNAME == null) || (DOMAINNAME.equals("")) ||
1058                (TESTFTPSERVER == null) ||
1059                (TESTFTPLOGIN == null) ||
1060                (TESTFTPPASSWORD == null) ||
1061                (TESTTEMPLATEFOLDER == null) ||
1062                (TESTIMAGESFOLDER == null) ||
1063                (LIVEFTPSERVER == null) ||
1064                (LIVEFTPLOGIN == null) ||
1065                (LIVEFTPPASSWORD == null) ||
1066                (LIVETEMPLATEFOLDER == null) ||
1067                (LIVEIMAGESSERVER == null) ||
1068                (LIVEIMAGESFOLDER == null) ||
1069                (IMPORTFTPSERVER == null) ||
1070                (IMPORTFTPLOGIN == null) ||
1071                (IMPORTFTPPASSWORD == null) ||
1072                (IMPORTFTPFILEPATH == null) ||
1073                (IMPORTFTPFILECONTENTS == null) ||
1074                (MAINCOFAXSERVER == null) || (MAINCOFAXSERVER.equals("")) ||
1075                (IMAGESURLPREFIX == null) || (IMAGESURLPREFIX.equals("")) ||
1076                (CACHESERVERS == null) || (CACHESERVERS.equals(""))) {
1077            return (CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_badpub"));
1078        }
1079        if (DEFAULTSECTION.equals("")) {
1080            ht.put("DEFAULTSECTIONWITHDATE", "0");
1081        }
1082        ht.put("PUBID", pubID);
1083        
1084
1085        //delete an empty publication
1086
String JavaDoc deletePublication = req.getParameter("delete");
1087        if (deletePublication != null && deletePublication.equals("on")) {
1088            Vector u_sections = null;
1089            StringBuffer JavaDoc v = new StringBuffer JavaDoc();
1090            v.append("SELECT mappingCode FROM tblsections WHERE pubName = '" + PUBNAME + "' ");
1091            u_sections = CofaxToolsDbUtils.getPackageVector(db,ht,v.toString());
1092            if (u_sections.size() > 0 && u_sections != null) {
1093                return(CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_pubhassections"));
1094            }
1095            else {
1096                StringBuffer JavaDoc v_delete2 = new StringBuffer JavaDoc();
1097                v_delete2.append("DELETE FROM tblpermgrouppublication WHERE pubID = '" + pubID + "' ");
1098                List del2 = CofaxToolsDbUtils.getPackageData(db, ht, v_delete2.toString());
1099
1100                StringBuffer JavaDoc v_delete = new StringBuffer JavaDoc();
1101                v_delete.append("DELETE FROM tbltoolspublicationconfig WHERE pubID = '" + pubID + "' ");
1102                List del = CofaxToolsDbUtils.getPackageData(db, ht, v_delete.toString());
1103            
1104                StringBuffer JavaDoc v_delete3 = new StringBuffer JavaDoc();
1105                v_delete3.append("DELETE FROM tblpublications WHERE pubID = '" + pubID + "' ");
1106                List del3 = CofaxToolsDbUtils.getPackageData(db, ht, v_delete3.toString());
1107
1108                return(CofaxToolsUtil.getI18NMessage(req.getLocale(),"publication") + " " + PUBNAME + " " + CofaxToolsUtil.getI18NMessage(req.getLocale(),"deleted"));
1109            }
1110        }
1111
1112        String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "insertPublication");
1113        List temp = CofaxToolsDbUtils.getPackageData(db, ht, tag);
1114        return (CofaxToolsUtil.getI18NMessage(req.getLocale(),"publication") + " " + req.getParameter("PUBDESC") + " " + CofaxToolsUtil.getI18NMessage(req.getLocale(),"implemented"));
1115    }
1116
1117
1118
1119    /**
1120     * Returns an ArrayList of HashMap results from SQL query. Used to keep
1121     * consistant flow of data through this class so manipulation can be done
1122     * through one funnel. Duplex method exists to implement calls to the
1123     * database where package tags exist that need variables fulfilled. Init
1124     * needs to be called the first time the cache of package tags is fulfilled
1125     * so java does not try to check the cache at the same time it is
1126     * fulfilling it.
1127     *
1128     *@param db Description of the Parameter
1129     *@param ht Description of the Parameter
1130     *@param tagStatement Description of the Parameter
1131     *@param init Description of the Parameter
1132     *@return The packageData value
1133     */

1134    public static List getPackageData(DataStore db, HashMap ht,
1135            String JavaDoc tagStatement, boolean init) {
1136        //CofaxToolsUtil.showHash("packageDataHash", ht);
1137
//CofaxToolsUtil.CofaxToolsUtil.log("getPackageData: " + tagStatement);
1138
ArrayList list = new ArrayList();
1139        try {
1140            list = (ArrayList) db.getPackageData(ht, "", tagStatement, init);
1141        } catch (java.lang.NullPointerException JavaDoc e) {
1142            CofaxToolsUtil.log("CofaxToolsDbUtils getPackageData " +
1143                    "ERROR executing package tag against " +
1144                    "database: " + e);
1145        }
1146        if (db.getError() == true) {
1147            CofaxToolsUtil.log("CofaxToolsDbUtils getPackageData SQl Error: " +
1148                    db.getLastError());
1149        }
1150        //CofaxToolsUtil.showListOfHashes("results:", list);
1151
return (list);
1152    }
1153
1154
1155
1156    /**
1157     * Returns an ArrayList of HashMap results from SQL query. Used to keep
1158     * consistant flow of data through this class so manipulation can be done
1159     * through one funnel.
1160     *
1161     *@param db Description of the Parameter
1162     *@param ht Description of the Parameter
1163     *@param tagStatement Description of the Parameter
1164     *@return The packageData value
1165     */

1166    public static List getPackageData(DataStore db, HashMap ht, String JavaDoc tagStatement) {
1167        return (getPackageData(db, ht, tagStatement, false));
1168    }
1169
1170
1171    /**
1172     * Returns an ArrayList of HashMap results from SQL query. Used to keep
1173     * consistant flow of data through this class so manipulation can be done
1174     * through one funnel. Simplex method exists to implement calls to the
1175     * database where package tags exist that do not need variables fulfilled.
1176     *
1177     *@param db Description of the Parameter
1178     *@param tagStatement Description of the Parameter
1179     *@return The packageData value
1180     */

1181    public static List getPackageData(DataStore db, String JavaDoc tagStatement) {
1182        HashMap ht = new HashMap();
1183        return (getPackageData(db, ht, tagStatement, false));
1184    }
1185
1186
1187    /**
1188     * Returns a HashMap formatted name / value by one column wide SQl query by
1189     * arrangment of getPackageData ArrayList results. Returns results
1190     * formatted Name:Value. Package tags using this call may ask for any
1191     * amount of parameters, but only data from one set or keys will be
1192     * overwritten. Simplex method exists for package tags that do not need
1193     * parameters fulfilled.
1194     *
1195     *@param db Description of the Parameter
1196     *@param tagStatement Description of the Parameter
1197     *@return The nameValuePackageHash value
1198     */

1199    public static HashMap getNameValuePackageHash(DataStore db, String JavaDoc tagStatement) {
1200        HashMap ht = new HashMap();
1201        return (getNameValuePackageHash(db, ht, tagStatement));
1202    }
1203
1204
1205    /**
1206     * Returns a HashMap formatted name / value by one column wide SQl query by
1207     * arrangment of getPackageData ArrayList results. Returns results
1208     * formatted Name:Value. Package tags using this call may ask for any
1209     * amount of parameters, but only data from one set or keys will be
1210     * overwritten. Duplex method exists for package tags that need parameters
1211     * fulfilled.
1212     *
1213     *@param db Description of the Parameter
1214     *@param ht Description of the Parameter
1215     *@param tagStatement Description of the Parameter
1216     *@return The nameValuePackageHash value
1217     */

1218    public static HashMap getNameValuePackageHash(DataStore db, HashMap ht, String JavaDoc tagStatement) {
1219
1220        HashMap nameValue = new HashMap();
1221        
1222        CofaxToolsUtil.log("tagStatement= " + tagStatement);
1223
1224
1225        if (tagStatement != null && !tagStatement.equals("")) {
1226            ArrayList packageRows = (ArrayList) getPackageData(db, ht, tagStatement);
1227            if (packageRows.size() > 0) {
1228                Iterator rows = packageRows.iterator();
1229                while (rows.hasNext()) {
1230                    HashMap glossaryRow;
1231                    glossaryRow = (HashMap) rows.next();
1232                    for (Iterator cols = glossaryRow.keySet().iterator(); cols.hasNext(); ) {
1233                        String JavaDoc colName = cols.next().toString();
1234                        String JavaDoc value = glossaryRow.get(colName).toString();
1235                                                
1236                        if ((value != null) && (colName != null) && (!value.equals("")) && (!colName.equals(""))) {
1237                            nameValue.put(colName, value + "");
1238                        }
1239                    }
1240                }
1241            } else {
1242                CofaxToolsUtil.log("CofaxToolsDbUtils getNameValuePackageHash query produced no results for tag: " + tagStatement + ". Check ODS log for errors - this is a common error that may happen when sections do not exist for a beta publication that a user is grouped to, for example.");
1243            }
1244            if (db.getError()) {
1245                CofaxToolsUtil.log(db.getLastError());
1246            }
1247        } else {
1248            CofaxToolsUtil.log("CofaxToolsDbUtils getNameValuePackageHash did not receive a packageTag to act upon.");
1249        }
1250
1251        return nameValue;
1252    }
1253
1254
1255    /**
1256     * Returns a HashMap formatted value / value by two column wide SQl query
1257     * through arrangement of ArrayList returned by getPackageData. SQL calls
1258     * using this method should ask for two values only, though they may ask
1259     * for any amount of those values. Field1 and field2 determine the column
1260     * order of the HashMap that is returned. Simplex mehhod for package tags
1261     * that do not need to have parameters fulfilled. init is passed so tools
1262     * don't try to access the package tag cache at the same time they are
1263     * trying to create it.
1264     *
1265     *@param db Description of the Parameter
1266     *@param tagStatement Description of the Parameter
1267     *@param field1 Description of the Parameter
1268     *@param field2 Description of the Parameter
1269     *@param init Description of the Parameter
1270     *@return The valueValuePackageHash value
1271     */

1272    public static HashMap getValueValuePackageHash(DataStore db, String JavaDoc tagStatement, String JavaDoc field1, String JavaDoc field2, boolean init) {
1273        HashMap ht = new HashMap();
1274        return (getValueValuePackageHash(db, ht, tagStatement, field1, field2, init));
1275    }
1276
1277
1278    /**
1279     * Returns a HashMap formatted value / value by two column wide SQl query
1280     * through arrangement of ArrayList returned by getPackageData. SQL calls
1281     * using this method should ask for two values only, though they may ask
1282     * for any amount of those values. Field1 and field2 determine the column
1283     * order of the HashMap that is returned. Simplex mehhod for package tags
1284     * that do not need to have parameters fulfilled
1285     *
1286     *@param db Description of the Parameter
1287     *@param tagStatement Description of the Parameter
1288     *@param field1 Description of the Parameter
1289     *@param field2 Description of the Parameter
1290     *@return The valueValuePackageHash value
1291     */

1292    public static HashMap getValueValuePackageHash(DataStore db, String JavaDoc tagStatement, String JavaDoc field1, String JavaDoc field2) {
1293        HashMap ht = new HashMap();
1294        return (getValueValuePackageHash(db, ht, tagStatement, field1, field2, false));
1295    }
1296
1297
1298    /**
1299     * Returns a HashMap formatted value / value by two column wide SQl query
1300     * through arrangement of ArrayList returned by getPackageData. SQL calls
1301     * using this method should ask for two values only, though they may ask
1302     * for any amount of those values. Field1 and field2 determine the column
1303     * order of the HashMap that is returned.
1304     *
1305     *@param db Description of the Parameter
1306     *@param ht Description of the Parameter
1307     *@param tagStatement Description of the Parameter
1308     *@param field1 Description of the Parameter
1309     *@param field2 Description of the Parameter
1310     *@return The valueValuePackageHash value
1311     */

1312    public static HashMap getValueValuePackageHash(DataStore db, HashMap ht, String JavaDoc tagStatement, String JavaDoc field1, String JavaDoc field2) {
1313        return (getValueValuePackageHash(db, ht, tagStatement, field1, field2, false));
1314    }
1315
1316
1317    /**
1318     * Returns a HashMap formatted value / value by two column wide SQl query
1319     * through arrangement of ArrayList returned by getPackageData. SQL calls
1320     * using this method should ask for two values only, though they may ask
1321     * for any amount of those values. Field1 and field2 determine the column
1322     * order of the HashMap that is returned. Init is passed so that
1323     * CofaxToolsServlet does not attempt to operate on HashMaps that contain
1324     * cached package tags at the same time they are being instantiaited and
1325     * fulfilled, which would create 503 errors.
1326     *
1327     *@param db Description of the Parameter
1328     *@param ht Description of the Parameter
1329     *@param tagStatement Description of the Parameter
1330     *@param field1 Description of the Parameter
1331     *@param field2 Description of the Parameter
1332     *@param init Description of the Parameter
1333     *@return The valueValuePackageHash value
1334     */

1335    public static HashMap getValueValuePackageHash(DataStore db, HashMap ht, String JavaDoc tagStatement, String JavaDoc field1, String JavaDoc field2, boolean init) {
1336
1337        HashMap nameValue = new HashMap();
1338        if (tagStatement != null && !tagStatement.equals("")) {
1339            ArrayList packageRows = (ArrayList) getPackageData(db, ht, tagStatement, init);
1340            if (packageRows.size() > 0) {
1341                Iterator rows = packageRows.iterator();
1342                while (rows.hasNext()) {
1343                    HashMap glossaryRow;
1344                    glossaryRow = (HashMap) rows.next();
1345                    //CofaxToolsUtil.showHash("PACKAGE DATA FULFILLED HASH",glossaryRow);
1346
String JavaDoc val1 = "";
1347                    String JavaDoc val2 = "";
1348                    try {
1349                        val1 = glossaryRow.get(field1).toString();
1350                        val2 = glossaryRow.get(field2).toString();
1351                        nameValue.put(val1, val2);
1352                    } catch (Exception JavaDoc e) {
1353                        CofaxToolsUtil.log("CofaxToolsDbUtils getValueValuePackageHash ERROR in getValueValuePackageHash getting glossary rows:" + e);
1354                    }
1355                }
1356
1357            } else {
1358                CofaxToolsUtil.log("CofaxToolsDbUtils getValueValuePackageHash query produced no results for tag: " + tagStatement + ". Check ODS log for errors - this is a common error that may happen when sections do not exist for a beta publication that a user is grouped to, for example.");
1359            }
1360
1361            if (db.getError()) {
1362                CofaxToolsUtil.log(db.getLastError());
1363            }
1364        } else {
1365            CofaxToolsUtil.log("CofaxToolsDbUtils getValueValuePackageHash did not receive a tagStatement to act upon.");
1366        }
1367
1368        return nameValue;
1369    }
1370
1371
1372    /**
1373     * Returns a Vector formatted one column wide SQl query through ArrayList
1374     * results by getPackageData. SQl calls using this routine should be asking
1375     * for an indeterminate amount of information from one column only.
1376     *
1377     *@param db Description of the Parameter
1378     *@param tagStatement Description of the Parameter
1379     *@return The packageVector value
1380     */

1381    public static Vector getPackageVector(DataStore db, String JavaDoc tagStatement) {
1382        HashMap ht = new HashMap();
1383        return (getPackageVector(db, ht, tagStatement));
1384    }
1385
1386
1387    /**
1388     * Returns a Vector formatted one column wide SQl query through ArrayList
1389     * results by getPackageData. SQl calls using this routine should be asking
1390     * for an indeterminate amount of information from one column only.
1391     *
1392     *@param db Description of the Parameter
1393     *@param ht Description of the Parameter
1394     *@param tagStatement Description of the Parameter
1395     *@return The packageVector value
1396     */

1397    public static Vector getPackageVector(DataStore db, HashMap ht, String JavaDoc tagStatement) {
1398
1399        Vector value = new Vector();
1400        if (tagStatement != null && !tagStatement.equals("")) {
1401
1402            ArrayList packageRows = (ArrayList) getPackageData(db, ht, tagStatement);
1403            if (packageRows.size() > 0) {
1404                Iterator rows = packageRows.iterator();
1405                while (rows.hasNext()) {
1406                    HashMap glossaryRow;
1407                    glossaryRow = (HashMap) rows.next();
1408
1409                    for (Iterator cols = glossaryRow.keySet().iterator(); cols.hasNext(); ) {
1410                        String JavaDoc colName = cols.next().toString();
1411                        String JavaDoc val = glossaryRow.get(colName).toString();
1412                        if (value != null) {
1413                            value.add(val);
1414                        }
1415                    }
1416                }
1417            } else {
1418                CofaxToolsUtil.log("CofaxToolsDbUtils getPackageVector query produced no results for tag: " + tagStatement + ". Check ODS log for errors - this is a common error that may happen when sections do not exist for a beta publication that a user is grouped to, for example.");
1419            }
1420
1421            if (db.getError()) {
1422                CofaxToolsUtil.log(db.getLastError());
1423            }
1424        } else {
1425            CofaxToolsUtil.log("CofaxToolsDbUtils getpackageVector did not receive a tagStatement to act upon.");
1426        }
1427
1428        return value;
1429    }
1430
1431
1432
1433    /**
1434     * Returns a package tag unfulfilled from memory
1435     *
1436     *@param db Description of the Parameter
1437     *@param tag Description of the Parameter
1438     *@return Description of the Return Value
1439     */

1440    public static String JavaDoc fillTag(DataStore db, String JavaDoc tag) {
1441        CofaxToolsUtil.log("fillTag : " + tag );
1442        String JavaDoc retour = (String JavaDoc) CofaxToolsServlet.dataStore.getCacheValue(tag, DataStore.PACKAGE_TAG_PROCESSED);
1443        CofaxToolsUtil.log("retour : " + retour );
1444        return retour;
1445    }
1446
1447    /**
1448     * Generate a new password and send it by mail
1449     *
1450     *@param db
1451     *@param req
1452     *@param login
1453     *@return
1454     */

1455    public static String JavaDoc setNewPassword(DataStore db, HttpServletRequest req, String JavaDoc login, String JavaDoc email) {
1456        String JavaDoc requestedUrl = req.getScheme() + "://" + req.getHeader("host");
1457        String JavaDoc message="";
1458        String JavaDoc mailTo ="";
1459        String JavaDoc mailFrom = "";
1460        String JavaDoc newPassword = "";
1461        boolean blnContinue= false;
1462        HashMap ht = new HashMap();
1463        
1464        if ((login!=null) && !(login.equals(""))) {
1465            blnContinue = true;
1466            // set the new password
1467
newPassword = login;
1468            ht.put("login",login);
1469            ht.put("password",newPassword + java.lang.Math.round(java.lang.Math.random()*10000));
1470            newPassword = (String JavaDoc)ht.get("password");
1471            ht.put("password",login + ":" + newPassword);
1472
1473            //get the mailTo and mailFrom
1474
String JavaDoc tag1 = CofaxToolsDbUtils.fillTag(db, "getEmailFromLogin");
1475            HashMap htTemp = CofaxToolsDbUtils.getNameValuePackageHash(db, ht, tag1);
1476            mailTo = (String JavaDoc) htTemp.get("EMAIL");
1477            if (mailTo==null) {
1478                message = login + " " + CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_notfound");
1479                return (message);
1480            }
1481            mailFrom = CofaxToolsServlet.adminEmail;
1482        } else {
1483            if ((email!=null) && !(email.equals(""))) {
1484                blnContinue = true;
1485                //get the login and mailFrom
1486
ht.put("email",email);
1487                String JavaDoc tag1 = CofaxToolsDbUtils.fillTag(db, "getLoginFromEmail");
1488                HashMap htTemp = CofaxToolsDbUtils.getNameValuePackageHash(db, ht, tag1);
1489                login = (String JavaDoc) htTemp.get("USERNAME");
1490                if (login==null) {
1491                    message = email + " " + CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_notfound");
1492                    return (message);
1493                }
1494                mailFrom = CofaxToolsServlet.adminEmail;
1495                mailTo = email;
1496
1497                // set the new password
1498
newPassword = login;
1499                ht.put("login",login);
1500                ht.put("password",newPassword + java.lang.Math.round(java.lang.Math.random()*10000));
1501                newPassword = (String JavaDoc)ht.get("password");
1502                ht.put("password",login + ":" + newPassword);
1503
1504            }
1505        }
1506        
1507        if (!blnContinue) {
1508            message = CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_fillinfield");
1509            return (message);
1510        }
1511        
1512        
1513        //set the message body and subject
1514
String JavaDoc messageBody = "<br>" + CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_newpasswordis") + " ";
1515        messageBody +=newPassword +"<br>";
1516        messageBody += CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_youcanlogin") + "<a HREF='" + requestedUrl + "" + CofaxToolsServlet.aliasPath + "/tools/'>Cofax</a>";
1517        messageBody += "<br><br>" + CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_webmaster");
1518        String JavaDoc subject = CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_newpasswordsubject");
1519
1520        System.out.println(messageBody);
1521
1522        //update the password for this login
1523
String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "setNewRamdomPassword");
1524        List list = CofaxToolsDbUtils.getPackageData(db, ht, tag);
1525    
1526        //send the mail
1527
boolean bln = CofaxToolsWorkflow.sendMail(mailTo, mailFrom, subject, messageBody);
1528        if (bln) message = CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_newpasswordsuccess") + " " + mailTo;
1529        else message = CofaxToolsUtil.getI18NMessage(req.getLocale(),"cofdbutil_newpasswordfail") + " " + mailTo;
1530        
1531        return (message);
1532    }
1533
1534
1535}
1536
1537
Popular Tags