KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * CofaxToolsUtil 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/CofaxToolsUtil.java,v 1.57.2.1 2006/12/11 16:28:24 fxrobin Exp $
21  */

22
23 package org.cofax.cms;
24
25 import java.io.BufferedReader JavaDoc;
26 import java.io.File JavaDoc;
27 import java.io.FileReader JavaDoc;
28 import java.io.FileWriter JavaDoc;
29 import java.io.IOException JavaDoc;
30 import java.io.PrintWriter JavaDoc;
31 import java.text.Collator JavaDoc;
32 import java.util.ArrayList JavaDoc;
33 import java.util.Calendar JavaDoc;
34 import java.util.Enumeration JavaDoc;
35 import java.util.HashMap JavaDoc;
36 import java.util.Iterator JavaDoc;
37 import java.util.List JavaDoc;
38 import java.util.Locale JavaDoc;
39 import java.util.ResourceBundle JavaDoc;
40 import java.util.Set JavaDoc;
41 import java.util.SortedMap JavaDoc;
42 import java.util.TreeMap JavaDoc;
43 import java.util.Vector JavaDoc;
44
45 import javax.servlet.http.HttpServletRequest JavaDoc;
46 import javax.servlet.http.HttpSession JavaDoc;
47
48 import org.cofax.CofaxUtil;
49 import org.cofax.DataStore;
50
51
52 /**
53  * CofaxToolsUtil: Collection of shared utilities for Cofax Tools. 
54  *
55  *@author Charles Harvey
56  *@created April 29, 2002
57  */

58
59 public class CofaxToolsUtil {
60
61
62     /**
63      * Reads a local file given the complete filepath and returns the body as a
64      * String.
65      *
66      *@param fileLocation Description of the Parameter
67      *@return Description of the Return Value
68      */

69     public static String JavaDoc readFile(String JavaDoc fileLocation) {
70         return readFile(fileLocation, false);
71     }
72
73
74     /**
75      * Reads a local file given the complete filepath and returns the body as a
76      * String.  If parameter delete is set to true file will be deleted
77      * after it is read.
78      *
79      *@param fileLocation Description of the Parameter
80      *@param delete Description of the Parameter
81      *@return Description of the Return Value
82      */

83     public static String JavaDoc readFile(String JavaDoc fileLocation, boolean delete) {
84         StringBuffer JavaDoc s = new StringBuffer JavaDoc();
85         String JavaDoc thisLine;
86         try {
87             FileReader JavaDoc fr = new FileReader JavaDoc(fileLocation);
88             BufferedReader JavaDoc br = new BufferedReader JavaDoc(fr);
89
90             while ((thisLine = br.readLine()) != null) {
91                 s.append(thisLine + "\n");
92             }
93             File JavaDoc file = new File JavaDoc(fileLocation);
94             if (delete == true) {
95                 if (!file.delete()) {
96                     log("CofaxToolsUtil readFile ERROR: Cannot delete file on local drive: " + fileLocation + ".");
97                 }
98             }
99         } catch (IOException JavaDoc e) {
100             log("CofaxToolsUtil readFile ERROR: " + e.toString());
101         }
102         String JavaDoc nb = s.toString();
103         return (nb);
104     }
105
106
107     /**
108      * Takes a HashMap of items, text, and a name and returns an HTML table
109      * populated with checkboxes.
110      *
111      *@param nameValue Description of the Parameter
112      *@param name Description of the Parameter
113      *@return Description of the Return Value
114      */

115     public static String JavaDoc createCheckBoxTable(HashMap JavaDoc nameValue, String JavaDoc name) {
116         Vector JavaDoc v = new Vector JavaDoc();
117         return (createCheckBoxTable(nameValue, v, name));
118     }
119
120
121
122     /**
123      * Takes a HashMap of items, text, and a name and a vector of checked items
124      * returns an HTML table populated with checkboxes checked where
125      * applicable.
126      *
127      *@param nameValueIn Description of the Parameter
128      *@param checked Description of the Parameter
129      *@param name Description of the Parameter
130      *@return Description of the Return Value
131      */

132     public static String JavaDoc createCheckBoxTable(HashMap JavaDoc nameValueIn, Vector JavaDoc checked, String JavaDoc name) {
133         HashMap JavaDoc nameValueReverse = new HashMap JavaDoc();
134         Iterator JavaDoc it = nameValueIn.keySet().iterator();
135         while (it.hasNext()) {
136             String JavaDoc keyName = (String JavaDoc) it.next();
137             String JavaDoc keyVal = (String JavaDoc) nameValueIn.get(keyName);
138             nameValueReverse.put(keyVal, keyName);
139         }
140         StringBuffer JavaDoc s = new StringBuffer JavaDoc();
141         s.append("\n\n<TABLE BORDER=0>\n");
142         SortedMap JavaDoc nameValue = new TreeMap JavaDoc();
143
144         // can't put all here because of oracle inserting nulls into the key space
145
Iterator JavaDoc nameValIt = nameValueReverse.keySet().iterator();
146         while (nameValIt.hasNext()) {
147             try {
148                 String JavaDoc key = (String JavaDoc) nameValIt.next();
149                 String JavaDoc val = (String JavaDoc) nameValueReverse.get(key);
150                 if ((key != null) && (val != null)) {
151                     nameValue.put(key, val);
152                 }
153             } catch (Exception JavaDoc e) {
154                 log("Null key in HashMap nameValueReverse sub createCheckBoxTable class CofaxToolsUtil - likely Oracle error " + e);
155             }
156         }
157
158         Set JavaDoc set = nameValue.keySet();
159         Iterator JavaDoc keys = set.iterator();
160
161         String JavaDoc isChecked;
162         int i = 0;
163         while (keys.hasNext()) {
164             String JavaDoc key = (String JavaDoc) keys.next();
165             String JavaDoc checkCheck = (String JavaDoc) nameValue.get(key);
166             if (checked.contains(checkCheck)) {
167                 isChecked = "checked";
168             } else {
169                 isChecked = "";
170             }
171
172             s.append("<TD><INPUT TYPE=CHECKBOX " + isChecked + " NAME=\"" + i + "\" VALUE=\"" + nameValue.get(key) + "\"><INPUT TYPE=HIDDEN NAME=PARAMNAME" + i + " VALUE=" + nameValue.get(key) + "></TD><TD>" + key + "</TD><TR>\n");
173             i++;
174         }
175         s.append("<INPUT TYPE=HIDDEN NAME=checkBoxTableLength VALUE=" + (i) + ">");
176         s.append("</TABLE>\n\n");
177         return (s.toString());
178     }
179
180
181     /**
182      * Returns an html select bar given a name and a HashMap of values.
183      *
184      *@param selectName Description of the Parameter
185      *@param nameValue Description of the Parameter
186      *@return Description of the Return Value
187      */

188     public static String JavaDoc createSelect(String JavaDoc selectName, HashMap JavaDoc nameValue) {
189         String JavaDoc sb = createSelect(selectName, nameValue, "");
190         return (sb);
191     }
192
193
194     /**
195      * Returns an html select bar given a name and a HashMap of values.&nbsp;
196      * Parameter selected will be marked as selected in the bar.
197      *
198      *@param selectName Description of the Parameter
199      *@param nameValue Description of the Parameter
200      *@param selected Description of the Parameter
201      *@return Description of the Return Value
202      */

203     public static String JavaDoc createSelect(String JavaDoc selectName, HashMap JavaDoc nameValue, String JavaDoc selected) {
204         String JavaDoc sb = createSelect(selectName, nameValue, selected, "");
205         return (sb);
206     }
207
208
209     /**
210      * Returns an html select bar given a name and a HashMap of values.&nbsp;
211      * Parameter selected will be marked as selected in the bar.&nbsp;
212      * Parameter javascript will be placed in the SELECT tag for onChange, etc.
213      *
214      *@param selectName Description of the Parameter
215      *@param nameValue Description of the Parameter
216      *@param selected Description of the Parameter
217      *@param javaScript Description of the Parameter
218      *@return Description of the Return Value
219      */

220     public static String JavaDoc createSelect(String JavaDoc selectName, HashMap JavaDoc nameValue, String JavaDoc selected, String JavaDoc javaScript) {
221
222         // put the hash into a sorted map for ordering
223
SortedMap JavaDoc sortedMap = new TreeMap JavaDoc();
224         sortedMap.putAll(nameValue);
225         Set JavaDoc set = sortedMap.keySet();
226         Iterator JavaDoc iterator = set.iterator();
227         StringBuffer JavaDoc s = new StringBuffer JavaDoc();
228
229         // add the values to an html select statement
230
try {
231             String JavaDoc[] a = new String JavaDoc[nameValue.size()];
232             s.append("\n\n<SELECT NAME =\"" + selectName + "\" " + javaScript + ">\n");
233             String JavaDoc i;
234             int ii = 0;
235             while (iterator.hasNext()) {
236                 String JavaDoc key = (String JavaDoc) iterator.next();
237                 String JavaDoc value = (String JavaDoc) sortedMap.get(key);
238                 if (value == selected || value.equals(selected)) {
239                     i = " selected";
240                 } else {
241                     i = "";
242                 }
243                 a[ii] = ("<OPTION VALUE=\"" + value + "\"" + i + ">" + key + "\n");
244                 ii++;
245             }
246             StringBuffer JavaDoc sb = arrayToStringBuffer(a);
247             s.append(sb.toString());
248             s.append("\n</SELECT>\n\n");
249         } catch (ArrayIndexOutOfBoundsException JavaDoc e) {
250             log("CofaxToolsUtil createSelect ERROR: " + e.toString());
251         } finally {
252           
253         }
254         return (s.toString());
255     }
256
257
258     /**
259      * Returns an html multiple select field given a name, a HashMap of names
260      * and values, and a size for the amount of fields to show.
261      *
262      *@param selectName Description of the Parameter
263      *@param nameValue Description of the Parameter
264      *@param size Description of the Parameter
265      *@return Description of the Return Value
266      */

267     public static String JavaDoc createMultipleSelect(String JavaDoc selectName, HashMap JavaDoc nameValue, int size) {
268         Vector JavaDoc selected = new Vector JavaDoc();
269         return createMultipleSelect(selectName, nameValue, size, selected);
270     }
271
272
273     /**
274      * Returns an html multiple select field given a name, a HashMap of names
275      * and values, and a size for the amount of fields to show. Sets values in
276      * Vector selected to selected.
277      *
278      *@param selectName Description of the Parameter
279      *@param nameValue Description of the Parameter
280      *@param size Description of the Parameter
281      *@param selected Description of the Parameter
282      *@return Description of the Return Value
283      */

284     public static String JavaDoc createMultipleSelect(String JavaDoc selectName, HashMap JavaDoc nameValue, int size, Vector JavaDoc selected) {
285
286         Iterator JavaDoc en = nameValue.keySet().iterator();
287         StringBuffer JavaDoc s = new StringBuffer JavaDoc();
288         s.append("\n\n<SELECT NAME =\"" + selectName + "\" MULTIPLE SIZE=" + size + ">\n");
289
290         while (en.hasNext()) {
291             String JavaDoc key = (String JavaDoc) en.next();
292             String JavaDoc value = (String JavaDoc) nameValue.get(key);
293             if (selected.contains(value)) {
294                 s.append("<OPTION VALUE=\"" + value + "\" SELECTED>" + key + "\n");
295             } else {
296                 s.append("<OPTION VALUE=\"" + value + "\">" + key + "\n");
297             }
298
299         }
300         s.append("</SELECT>");
301         return (s.toString());
302     }
303
304     /**
305      * Sorts a String array by value and returns sorted value.
306      *
307      *@param toBeSorted Description of the Parameter
308      *@return Description of the Return Value
309      */

310     public static String JavaDoc[] bubbleSort(String JavaDoc[] toBeSorted) {
311
312         boolean sorted = false;
313         // sort the array
314
while (!sorted) {
315             sorted = true;
316             for (int i = 0; i < toBeSorted.length - 1; i++) {
317                 Collator JavaDoc myCollator = Collator.getInstance();
318                 int iPlus = i + 1;
319
320                 if (myCollator.compare((String JavaDoc) toBeSorted[i], (String JavaDoc) toBeSorted[iPlus]) > 0) {
321                     String JavaDoc temp = toBeSorted[i];
322                     toBeSorted[i] = toBeSorted[iPlus];
323                     toBeSorted[iPlus] = temp;
324                     sorted = false;
325                 }
326             }
327         }
328
329         return (toBeSorted);
330     }
331
332
333
334     /**
335      * Ports Array elements into a StringBuffer in their natural order.
336      *
337      *@param input Description of the Parameter
338      *@return Description of the Return Value
339      */

340     public static StringBuffer JavaDoc arrayToStringBuffer(String JavaDoc[] input) {
341         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
342         for (int i = 0; i < input.length; i++) {
343             sb.append(input[i]);
344         }
345
346         return (sb);
347     }
348
349
350
351     /**
352      * Produces an html select of all Group Types.
353      *
354      *@param db Description of the Parameter
355      *@return The groupTypesSelectID value
356      */

357     public static String JavaDoc getGroupTypesSelectID(DataStore db) {
358         String JavaDoc s = getGroupTypesSelectID(db, "noPub");
359         return (s);
360     }
361
362
363
364     /**
365      * Produces an html select of all Group Types with parameter selected as
366      * the selected value.
367      *
368      *@param db Description of the Parameter
369      *@param selected Description of the Parameter
370      *@return The groupTypesSelectID value
371      */

372     public static String JavaDoc getGroupTypesSelectID(DataStore db, String JavaDoc selected) {
373         HashMap JavaDoc htGroupTypes = getGroupTypes(db);
374         String JavaDoc s = createSelect("GROUPTYPE", htGroupTypes, selected);
375         return (s);
376     }
377
378
379     /**
380      * Produces an html select of all Groups.
381      *
382      *@param db Description of the Parameter
383      *@param session Description of the Parameter
384      *@return The groupsSelectID value
385      */

386     public static String JavaDoc getGroupsSelectID(DataStore db, HttpSession JavaDoc session) {
387         String JavaDoc s = getGroupsSelectID(db, "noPub", session);
388         return (s);
389     }
390
391
392
393     /**
394      * Produces an html select of all Groups with parameter selected as the
395      * selected value.
396      *
397      *@param db Description of the Parameter
398      *@param selected Description of the Parameter
399      *@param session Description of the Parameter
400      *@return The groupsSelectID value
401      */

402     public static String JavaDoc getGroupsSelectID(DataStore db, String JavaDoc selected, HttpSession JavaDoc session) {
403         HashMap JavaDoc htGroups = new HashMap JavaDoc();
404         CofaxToolsUser user = (CofaxToolsUser) session.getAttribute("user");
405         htGroups = getGroupsConverse(db);
406         String JavaDoc s = createSelect("selectGroup", htGroups, selected);
407         return (s);
408     }
409
410
411
412     /**
413      * Produces an html select of all publications. Produces only the
414      * publications a user is grouped to unless the user is a national admin,
415      * in which case produces all publications.
416      *
417      *@param db Description of the Parameter
418      *@param session Description of the Parameter
419      *@param name Description of the Parameter
420      *@return The publicationSelectID value
421      */

422     public static String JavaDoc getPublicationSelectID(DataStore db, HttpSession JavaDoc session, String JavaDoc name) {
423         String JavaDoc s = getPublicationSelectID(db, session, name, "PUBLICATION");
424         return (s);
425     }
426
427
428
429     /**
430      * Produces an html select of all publications with parameter selected as
431      * the selected value.&nbsp; Produces only the publications a user is
432      * grouped to unless the user is a national admin, in which case produces
433      * all publications.
434      *
435      *@param db Description of the Parameter
436      *@param session Description of the Parameter
437      *@param selected Description of the Parameter
438      *@param name Description of the Parameter
439      *@return The publicationSelectID value
440      */

441     public static String JavaDoc getPublicationSelectID(DataStore db, HttpSession JavaDoc session, String JavaDoc selected, String JavaDoc name) {
442         CofaxToolsUser user = (CofaxToolsUser) session.getAttribute("user");
443         HashMap JavaDoc results = new HashMap JavaDoc();
444         boolean nationalAdmin = false;
445
446         // check if the admin is national and allow them to see all pubs if so
447
Iterator JavaDoc groupTypeIt = user.userPubsVectorOHash.iterator();
448         while (groupTypeIt.hasNext()) {
449             HashMap JavaDoc pubIdGroupType = (HashMap JavaDoc) groupTypeIt.next();
450             if (pubIdGroupType.containsValue(CofaxToolsServlet.adminGroupID)) {
451                 nationalAdmin = true;
452             }
453         }
454
455         if (nationalAdmin == true) {
456             String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getPubDescPubIDFromTblPubs");
457             results = CofaxToolsDbUtils.getValueValuePackageHash(db, tag, "PUBDESC", "PUBID");
458         } else {
459             results = user.userPubDescPubIDHash;
460         }
461         String JavaDoc s = createSelect(name, results, selected);
462         return (s);
463     }
464
465
466
467     /**
468      * Returns a HashMap of pubDesc and pubName given a pubID.
469      *
470      *@param db Description of the Parameter
471      *@param pubID Description of the Parameter
472      *@return The pubNamePubDescFromID value
473      */

474     public static HashMap JavaDoc getPubNamePubDescFromID(DataStore db, String JavaDoc pubID) {
475         HashMap JavaDoc fillReq = new HashMap JavaDoc();
476         fillReq.put("PUBID", pubID);
477         String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getPubDescPubNameFromTblPubsByPubID");
478         HashMap JavaDoc results = CofaxToolsDbUtils.getNameValuePackageHash(db, fillReq, tag);
479         return (results);
480     }
481
482
483
484     /**
485      * Produces an html select of all users.
486      *
487      *@param db Description of the Parameter
488      *@param session Description of the Parameter
489      *@return The usersSelect value
490      */

491     public static String JavaDoc getUsersSelect(DataStore db, HttpSession JavaDoc session) {
492         String JavaDoc s = getUsersSelect(db, session, "");
493         return (s);
494     }
495
496
497     /**
498      * Produces an html select of all users with parameter selected
499      * selected.&nbsp;Produces only users that belong to the same group(s) as
500      * the current user, unless the current user is a national admin, in which
501      * case produces all users.
502      *
503      *@param db Description of the Parameter
504      *@param session Description of the Parameter
505      *@param selected Description of the Parameter
506      *@return The usersSelect value
507      */

508     public static String JavaDoc getUsersSelect(DataStore db, HttpSession JavaDoc session, String JavaDoc selected) {
509         CofaxToolsUser user = (CofaxToolsUser) session.getAttribute("user");
510
511         // get a HashMap of all userName / userID from the database
512
String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getUserNameUserIdFromPermUsers");
513         HashMap JavaDoc userIDUserName = CofaxToolsDbUtils.getValueValuePackageHash(db, tag, "USERNAME", "USERID");
514         Iterator JavaDoc enu = userIDUserName.keySet().iterator();
515
516         // get an arraylist of tblpermusergroup (userID, userGroup)
517
tag = CofaxToolsDbUtils.fillTag(db, "getAllFromPermUserToGroup");
518         ArrayList JavaDoc users = (ArrayList JavaDoc) CofaxToolsDbUtils.getPackageData(db, tag);
519
520         // create a hash for putting the correct users into
521
HashMap JavaDoc userIDUserNameTwo = new HashMap JavaDoc();
522         //userIDUserNameTwo.put("", "** Select User Below or Create New **");
523

524         // iterate through the username/ userID table
525
while (enu.hasNext()) {
526             // get the user id
527
String JavaDoc checkUserIDKey = (String JavaDoc) enu.next();
528             String JavaDoc checkUserID = (String JavaDoc) userIDUserName.get(checkUserIDKey);
529             for (int i = 0; i < users.size(); i++) {
530                 HashMap JavaDoc hm = (HashMap JavaDoc) users.get(i);
531                 String JavaDoc checkUserTwo = (String JavaDoc) hm.get("USERID");
532                 if (checkUserTwo.equals(checkUserID)) {
533                     boolean delete = true;
534                     Iterator JavaDoc it = hm.keySet().iterator();
535                     while (it.hasNext()) {
536                         String JavaDoc userGroupKey = (String JavaDoc) it.next();
537                         if (userGroupKey.indexOf("USERID") < 0) {
538                             String JavaDoc userGroup = (String JavaDoc) hm.get(userGroupKey);
539                             if (!userGroup.equals("")) {
540                                 if (user.userGroupNameGroupIDHash.containsKey(userGroup)) {
541                                     delete = false;
542                                 }
543                             }
544                         }
545                     }
546                     if (delete == false) {
547                         userIDUserNameTwo.put(checkUserIDKey, checkUserID);
548                     }
549                 }
550             }
551         }
552         boolean nationalAdmin = false;
553         // check if the admin is national and allow them to see all users if so
554
if (user.userGroupVector.contains((String JavaDoc)CofaxToolsServlet.adminGroupID)) {
555             nationalAdmin = true;
556         }
557         
558         if (nationalAdmin == true) {
559             userIDUserNameTwo = userIDUserName;
560         }
561
562         String JavaDoc s = createSelect("selectUser", userIDUserNameTwo, selected);
563         return (s);
564     }
565
566
567     /**
568      * Return contents of tblpermusers for a specific user in a HashMap.
569      *
570      *@param db Description of the Parameter
571      *@param userID Description of the Parameter
572      *@return The userInfo value
573      */

574     public static HashMap JavaDoc getUserInfo(DataStore db, String JavaDoc userID) {
575         HashMap JavaDoc fillReq = new HashMap JavaDoc();
576         fillReq.put("USERID", userID);
577         String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getUserInfoByUserID");
578         HashMap JavaDoc results = CofaxToolsDbUtils.getNameValuePackageHash(db, fillReq, tag);
579         return (results);
580     }
581
582
583     /**
584      * Return all groups that a given user belongs to in a Vector.
585      *
586      *@param db Description of the Parameter
587      *@param userID Description of the Parameter
588      *@return The userGroups value
589      */

590     public static Vector JavaDoc getUserGroups(DataStore db, String JavaDoc userID) {
591         HashMap JavaDoc fillReq = new HashMap JavaDoc();
592         fillReq.put("USERID", userID);
593         String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getVectorOfGroupsByUserID");
594         Vector JavaDoc results = CofaxToolsDbUtils.getPackageVector(db, fillReq, tag);
595         return (results);
596     }
597
598
599     /**
600      * Returns groupID & GroupName for all groups.
601      *
602      *@param db Description of the Parameter
603      *@param session Description of the Parameter
604      *@return The groups value
605      */

606     public static HashMap JavaDoc getGroups(DataStore db, HttpSession JavaDoc session) {
607         CofaxToolsUser user = (CofaxToolsUser) session.getAttribute("user");
608         HashMap JavaDoc results = new HashMap JavaDoc();
609         boolean nationalAdmin = false;
610
611         // check if the admin is national and allow them to see all groups if so
612
if (user.userGroupVector.contains((String JavaDoc)CofaxToolsServlet.adminGroupID)) {
613             nationalAdmin = true;
614         }
615
616         if (nationalAdmin != true) {
617             results = user.userGroupNameGroupIDHash;
618         } else {
619             String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getGroupNameGroupIDFromPermGroups");
620             results = CofaxToolsDbUtils.getValueValuePackageHash(db, tag, "GROUPID", "GROUPNAME");
621         }
622         return (results);
623     }
624
625
626     /**
627      * Return GroupName & groupID for all groups.
628      *
629      *@param db Description of the Parameter
630      *@return The groupsConverse value
631      */

632     public static HashMap JavaDoc getGroupsConverse(DataStore db) {
633         String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getGroupNameGroupIDFromPermGroups");
634         HashMap JavaDoc results = CofaxToolsDbUtils.getValueValuePackageHash(db, tag, "GROUPNAME", "GROUPID");
635         return (results);
636     }
637
638
639     /**
640      * Return all group types in a HashMap.
641      *
642      *@param db Description of the Parameter
643      *@return The groupTypes value
644      */

645     public static HashMap JavaDoc getGroupTypes(DataStore db) {
646         String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getGroupNameGroupIDFromPermGroupType");
647         HashMap JavaDoc results = CofaxToolsDbUtils.getValueValuePackageHash(db, tag, "GROUPTYPENAME", "GROUPTYPEID");
648         return (results);
649     }
650
651
652
653     /**
654      * Return group info for a specific group.
655      *
656      *@param db Description of the Parameter
657      *@param groupID Description of the Parameter
658      *@return The groupInfo value
659      */

660     public static HashMap JavaDoc getGroupInfo(DataStore db, String JavaDoc groupID) {
661         HashMap JavaDoc fillReq = new HashMap JavaDoc();
662         fillReq.put("pubNameKey", groupID);
663         String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getAllFromPermGroupsByGroupID");
664         HashMap JavaDoc results = CofaxToolsDbUtils.getNameValuePackageHash(db, fillReq, tag);
665         return (results);
666     }
667
668
669
670     /**
671      * Logs to a file or to System.out - basic function is to concentrate error
672      * checking.
673      *
674      *@param input Description of the Parameter
675      */

676     public static void log(String JavaDoc input) {
677         input = new java.util.Date JavaDoc().toString()+" - "+input;
678         if (CofaxToolsServlet.log.equals("1")) {
679             if (!CofaxToolsServlet.logLocation.equals("")) {
680                 try {
681                     if (CofaxToolsServlet.logMaxSize > 0) {
682                         File JavaDoc file = new File JavaDoc(CofaxToolsServlet.logLocation);
683                         long fileSize = file.length();
684                         if (fileSize > CofaxToolsServlet.logMaxSize) {
685                             file.delete();
686                         }
687                     }
688                     PrintWriter JavaDoc fileOutputStream = new PrintWriter JavaDoc(new FileWriter JavaDoc(CofaxToolsServlet.logLocation, true));
689                     fileOutputStream.println(input);
690                     fileOutputStream.close();
691                 } catch (IOException JavaDoc e) {
692                     System.err.println("CofaxToolsUtil log ERROR: " + e.toString());
693                 }
694             } else {
695                 System.out.println("CT log: " + input);
696             }
697         }
698     }
699
700
701     /**
702      * Returns pub Desc / pub ID for all Publications.
703      *
704      *@param db Description of the Parameter
705      *@return The publications value
706      */

707     public static HashMap JavaDoc getPublications(DataStore db) {
708         String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getPubDescPubIDFromTblPubs");
709         HashMap JavaDoc results = CofaxToolsDbUtils.getValueValuePackageHash(db, tag, "PUBDESC", "PUBID");
710         return (results);
711     }
712
713
714     /**
715      * Returns the publications associated with a group.
716      *
717      *@param db Description of the Parameter
718      *@param groupID Description of the Parameter
719      *@return The groupsPublications value
720      */

721     public static HashMap JavaDoc getGroupsPublications(DataStore db, String JavaDoc groupID) {
722         HashMap JavaDoc fillReq = new HashMap JavaDoc();
723         fillReq.put("pubNameKey", groupID);
724         String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getAllFromGroupToPubByGroupID");
725         //HashMap results = CofaxToolsDbUtils.getNameValuePackageHash(db, fillReq, tag);
726
ArrayList JavaDoc results = (ArrayList JavaDoc) CofaxToolsDbUtils.getPackageData(db, fillReq, tag);
727
728         tag = CofaxToolsDbUtils.fillTag(db, "getPubDescPubIDFromTblPubs");
729         HashMap JavaDoc pubNames = CofaxToolsDbUtils.getValueValuePackageHash(db, tag, "PUBID", "PUBDESC");
730         HashMap JavaDoc newHash = new HashMap JavaDoc();
731         //Iterator en = results.keySet().iterator();
732
Iterator JavaDoc en = results.iterator();
733         while (en.hasNext()) {
734             HashMap JavaDoc groupIDpubID = (HashMap JavaDoc) en.next();
735             String JavaDoc resultValue = (String JavaDoc) groupIDpubID.get("PUBID");
736             newHash.put(pubNames.get(resultValue), resultValue);
737         }
738         return (newHash);
739     }
740
741
742
743     /**
744      * Returns the publications not associated with a group.
745      *
746      *@param db Description of the Parameter
747      *@param groupID Description of the Parameter
748      *@return The groupsNonPublications value
749      */

750     public static HashMap JavaDoc getGroupsNonPublications(DataStore db, String JavaDoc groupID) {
751         HashMap JavaDoc fillReq = new HashMap JavaDoc();
752         fillReq.put("pubNameKey", groupID);
753         String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getAllFromGroupToPubByGroupID");
754         //HashMap results = CofaxToolsDbUtils.getNameValuePackageHash(db, fillReq, tag);
755
ArrayList JavaDoc results = (ArrayList JavaDoc) CofaxToolsDbUtils.getPackageData(db, fillReq, tag);
756         //Iterator enu = results.keySet().iterator();
757
Iterator JavaDoc enu = results.iterator();
758         Vector JavaDoc vec = new Vector JavaDoc();
759         while (enu.hasNext()) {
760             //String resultKey = (String)enu.next();
761
HashMap JavaDoc groupIDpubID = (HashMap JavaDoc) enu.next();
762             String JavaDoc resultValue = (String JavaDoc) groupIDpubID.get("PUBID");
763             vec.add(resultValue);
764         }
765
766         tag = CofaxToolsDbUtils.fillTag(db, "getPubDescPubIDFromTblPubs");
767         HashMap JavaDoc pubNames = CofaxToolsDbUtils.getValueValuePackageHash(db, tag, "PUBID", "PUBDESC");
768         HashMap JavaDoc newHash = new HashMap JavaDoc();
769         Iterator JavaDoc en = pubNames.keySet().iterator();
770         while (en.hasNext()) {
771             String JavaDoc pubNamesKey = (String JavaDoc) en.next();
772             String JavaDoc pubNamesValue = (String JavaDoc) pubNames.get(pubNamesKey);
773
774             if (vec.indexOf(pubNamesKey) == -1) {
775                 newHash.put(pubNamesValue, pubNamesKey);
776             }
777         }
778         return (newHash);
779     }
780
781
782
783     /**
784      * Returns pubDesc given pubID.
785      *
786      *@param db Description of the Parameter
787      *@param pubID Description of the Parameter
788      *@return The pubDescFromID value
789      */

790     public static String JavaDoc getPubDescFromID(DataStore db, String JavaDoc pubID) {
791         HashMap JavaDoc fillReq = new HashMap JavaDoc();
792         fillReq.put("PUBID", pubID);
793         String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getPubDescFromPublicationsByPubID");
794         HashMap JavaDoc pubNames = CofaxToolsDbUtils.getNameValuePackageHash(db, fillReq, tag);
795         return ((String JavaDoc) pubNames.get("PUBDESC"));
796     }
797
798
799     /**
800      * Returns pubName given pubID.
801      *
802      *@param db Description of the Parameter
803      *@param pubID Description of the Parameter
804      *@return The pubNameFromID value
805      */

806
807     public static String JavaDoc getPubNameFromID(DataStore db, String JavaDoc pubID) {
808         HashMap JavaDoc fillReq = new HashMap JavaDoc();
809         fillReq.put("PUBID", pubID);
810         String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getPubNameFromPublicationsByPubID");
811         HashMap JavaDoc pubNames = CofaxToolsDbUtils.getNameValuePackageHash(db, fillReq, tag);
812         return ((String JavaDoc) pubNames.get("PUBNAME"));
813     }
814
815
816     /**
817      * Returns pubID given pubName.
818      *
819      *@param db Description of the Parameter
820      *@param pubName Description of the Parameter
821      *@return The pubIDFromName value
822      */

823
824     public static String JavaDoc getPubIDFromName(DataStore db, String JavaDoc pubName) {
825         HashMap JavaDoc fillReq = new HashMap JavaDoc();
826         fillReq.put("PUBNAME", pubName);
827         String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getPubIDByPubName");
828         HashMap JavaDoc pubNames = CofaxToolsDbUtils.getNameValuePackageHash(db, fillReq, tag);
829         return ((String JavaDoc) pubNames.get("PUBID"));
830     }
831
832
833
834     /**
835      * Prints a HashMap to System.out in name/ value pairs for reporting/
836      * debugging.
837      *
838      *@param name Description of the Parameter
839      *@param vec Description of the Parameter
840      */

841     public static void showVector(String JavaDoc name, Vector JavaDoc vec) {
842         String JavaDoc key = "";
843         String JavaDoc value = "";
844         Iterator JavaDoc it = vec.iterator();
845         while (it.hasNext()) {
846             log(name + " contents: -" + it.next());
847         }
848     }
849
850
851     /**
852      * Prints a HashMap to System.out in name/ value pairs for reporting/
853      * debugging.
854      *
855      *@param name Description of the Parameter
856      *@param hm Description of the Parameter
857      */

858     public static void showHash(String JavaDoc name, HashMap JavaDoc hm) {
859         String JavaDoc key = "";
860         String JavaDoc value = "";
861         Iterator JavaDoc it = hm.keySet().iterator();
862         while (it.hasNext()) {
863             try {
864                 key = (String JavaDoc) it.next();
865                 value = (String JavaDoc) hm.get(key);
866                 log(name + " name/ value: -" + key + "-" + value + "-");
867             } catch (java.lang.ClassCastException JavaDoc e) {
868                 log("name/ " + key + " cannot be cast to a string, sorry!");
869             }
870         }
871     }
872
873
874     /**
875      * Prints a List of HashMaps to System.out in name/ value pairs for
876      * reporting/ debugging.
877      *
878      *@param name Description of the Parameter
879      *@param list Description of the Parameter
880      */

881     public static void showListOfHashes(String JavaDoc name, List JavaDoc list) {
882         Iterator JavaDoc it = list.iterator();
883
884         while (it.hasNext()) {
885             Object JavaDoc o = it.next();
886             HashMap JavaDoc hm = (HashMap JavaDoc) o;
887             Iterator JavaDoc ite = hm.keySet().iterator();
888
889             while (ite.hasNext()) {
890                 String JavaDoc key = (String JavaDoc) ite.next();
891                 String JavaDoc s = (String JavaDoc) hm.get(key);
892                 log(name + " name/ value : " + key + " " + s + "");
893             }
894         }
895     }
896
897
898     /**
899      * Return groupTypeID in a Vector.
900      *
901      *@param db Description of the Parameter
902      *@return The groupTypeIDs value
903      */

904     public static Vector JavaDoc getGroupTypeIDs(DataStore db) {
905         String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getGroupTypeIDFromGroupType");
906         Vector JavaDoc v = CofaxToolsDbUtils.getPackageVector(db, tag);
907         return (v);
908     }
909
910
911     /**
912      * Return groupTypeName in a Vector.
913      *
914      *@param db Description of the Parameter
915      *@return The groupTypeNames value
916      */

917     public static Vector JavaDoc getGroupTypeNames(DataStore db) {
918         String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getGroupTypeNameFromGroupType");
919         Vector JavaDoc v = CofaxToolsDbUtils.getPackageVector(db, tag);
920         return (v);
921     }
922
923
924     /**
925      * Return modes/ group types in a Vector of Hashes.
926      *
927      *@param db Description of the Parameter
928      *@return The modes value
929      */

930     public static ArrayList JavaDoc getModes(DataStore db) {
931         String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getModeAndTypeFromPermModes");
932         ArrayList JavaDoc l = (ArrayList JavaDoc) CofaxToolsDbUtils.getPackageData(db, tag);
933         return (l);
934     }
935
936
937
938     /**
939      * Prints out info regarding a vector full of hashes.
940      *
941      *@param s Description of the Parameter
942      *@param v Description of the Parameter
943      */

944
945     public static void showVectorOfHashes(String JavaDoc s, Vector JavaDoc v) {
946         Iterator JavaDoc it = v.iterator();
947         int i = 0;
948         while (it.hasNext()) {
949             i++;
950             Object JavaDoc o = it.next();
951             HashMap JavaDoc ht = (HashMap JavaDoc) o;
952             Iterator JavaDoc en = ht.keySet().iterator();
953             while (en.hasNext()) {
954                 String JavaDoc key = (String JavaDoc) en.next();
955                 String JavaDoc value = (String JavaDoc) ht.get(key);
956                 log(s + " table " + i + " : " + key + " \\ " + value + "");
957
958             }
959         }
960     }
961
962
963     /**
964      * Returns a hash of all publication info by pub id.
965      *
966      *@param db Description of the Parameter
967      *@param pubID Description of the Parameter
968      *@return The publicationInfo value
969      */

970
971     public static HashMap JavaDoc getPublicationInfo(DataStore db, String JavaDoc pubID) {
972         HashMap JavaDoc fillReq = new HashMap JavaDoc();
973         fillReq.put("PUBID", pubID);
974         String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getAllFromConfigByPubID");
975         HashMap JavaDoc pubInfo = CofaxToolsDbUtils.getNameValuePackageHash(db, fillReq, tag);
976         tag = CofaxToolsDbUtils.fillTag(db, "getAllFromPublicationsByPubID");
977         HashMap JavaDoc pubInfo2 = CofaxToolsDbUtils.getNameValuePackageHash(db, fillReq, tag);
978         pubInfo.putAll(pubInfo2);
979         return (pubInfo);
980     }
981
982
983     /**
984      * Returns a select of all group types with a group selected
985      *
986      *@param db Description of the Parameter
987      *@return The selectGroupType value
988      */

989     public static String JavaDoc getSelectGroupType(DataStore db) {
990         String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getGroupNameGroupIDFromPermGroupType");
991         HashMap JavaDoc typeInfo = CofaxToolsDbUtils.getValueValuePackageHash(db, tag, "GROUPTYPENAME", "GROUPTYPEID");
992         String JavaDoc select = createSelect("selectGroupType", typeInfo, "");
993         return (select);
994     }
995
996
997     /**
998      * Returns a select of all group types.
999      *
1000     *@param db Description of the Parameter
1001     *@param groupID Description of the Parameter
1002     *@return The selectGroupType value
1003     */

1004    public static String JavaDoc getSelectGroupType(DataStore db, String JavaDoc groupID) {
1005        String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getGroupNameGroupIDFromPermGroupType");
1006        HashMap JavaDoc typeInfo = CofaxToolsDbUtils.getValueValuePackageHash(db, tag, "GROUPTYPENAME", "GROUPTYPEID");
1007        String JavaDoc select = createSelect("selectGroupType", typeInfo, groupID);
1008        return (select);
1009    }
1010
1011
1012    /**
1013     * Returns a select of all group types.
1014     *
1015     *@param db Description of the Parameter
1016     *@param groupTypeID Description of the Parameter
1017     *@return The groupTypeInfo value
1018     */

1019    public static HashMap JavaDoc getGroupTypeInfo(DataStore db, String JavaDoc groupTypeID) {
1020        HashMap JavaDoc fillReq = new HashMap JavaDoc();
1021        fillReq.put("GROUPTYPEID", groupTypeID);
1022        String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getAlltblpermgrouptypeByGroupTypeID");
1023        HashMap JavaDoc typeInfo = CofaxToolsDbUtils.getNameValuePackageHash(db, fillReq, tag);
1024        return (typeInfo);
1025    }
1026
1027
1028    /**
1029     * Replaces all occurances of the specified sub-string to find with the
1030     * specified sub-string to replace with.
1031     *
1032     *@param originalText Description of the Parameter
1033     *@param subStringToFind Description of the Parameter
1034     *@param subStringToReplaceWith Description of the Parameter
1035     *@return Description of the Return Value
1036     */

1037    public static String JavaDoc replace(String JavaDoc originalText, String JavaDoc subStringToFind, String JavaDoc subStringToReplaceWith) {
1038        int s = 0;
1039        int e = 0;
1040        StringBuffer JavaDoc newText = new StringBuffer JavaDoc();
1041        while ((e = originalText.indexOf(subStringToFind, s)) >= 0) {
1042            newText.append(originalText.substring(s, e));
1043            newText.append(subStringToReplaceWith);
1044            s = e + subStringToFind.length();
1045        }
1046
1047        newText.append(originalText.substring(s));
1048        return newText.toString();
1049    }
1050
1051
1052
1053    /**
1054     * Returns a select of dates (mm/dd/yyyy).
1055     *
1056     *@param label Description of the Parameter
1057     *@return The selectDate value
1058     */

1059
1060    public static String JavaDoc getSelectDate(String JavaDoc label) {
1061        String JavaDoc sb = getSelectDate(label, 0, 0, 0);
1062        return (sb);
1063    }
1064
1065
1066    /**
1067     * Returns a select of dates with given dates selected (mm/dd/yyyy).
1068     *
1069     *@param label Description of the Parameter
1070     *@param year Description of the Parameter
1071     *@param month Description of the Parameter
1072     *@param day Description of the Parameter
1073     *@return The selectDate value
1074     */

1075
1076    public static String JavaDoc getSelectDate(String JavaDoc label, int year, int month, int day) {
1077        StringBuffer JavaDoc select = new StringBuffer JavaDoc();
1078        StringBuffer JavaDoc select1 = new StringBuffer JavaDoc();
1079        StringBuffer JavaDoc select2 = new StringBuffer JavaDoc();
1080        StringBuffer JavaDoc select3 = new StringBuffer JavaDoc();
1081        String JavaDoc selected;
1082        select1.append("<SELECT name=" + label + "month>\n");
1083        for (int i = 1; i <= 12; i++) {
1084            if (month == i) {
1085                selected = "selected";
1086            } else {
1087                selected = "";
1088            }
1089            select1.append("<OPTION VALUE=" + i + " " + selected + ">" + i + "\n");
1090        }
1091        select1.append("</SELECT>\n");
1092
1093        select2.append("<SELECT name=" + label + "day>\n");
1094        for (int i = 1; i <= 31; i++) {
1095            if (day == i) {
1096                selected = "selected";
1097            } else {
1098                selected = "";
1099            }
1100            select2.append("<OPTION VALUE=" + i + " " + selected + ">" + i + "\n");
1101        }
1102        select2.append("</SELECT>\n");
1103
1104        select3.append("<SELECT name=" + label + "year>\n");
1105        for (int i = 1990; i <= 2010; i++) {
1106            if (year == i) {
1107                selected = "selected";
1108            } else {
1109                selected = "";
1110            }
1111            select3.append("<OPTION VALUE=" + i + " " + selected + ">" + i + "\n");
1112        }
1113        select3.append("</SELECT>\n");
1114        
1115        //inverse dates for french
1116
if (CofaxToolsServlet.lcl.toString().equals("fr")) {
1117            select.append(select2.toString());
1118            select.append(select1.toString());
1119            select.append(select3.toString());
1120        } else {
1121            select.append(select1.toString());
1122            select.append(select2.toString());
1123            select.append(select3.toString());
1124        }
1125        return select.toString();
1126    }
1127
1128
1129
1130    /**
1131     * Returns a select of all article sections for a given publication with no
1132     * selected value.
1133     *
1134     *@param db Description of the Parameter
1135     *@param currentPubName Description of the Parameter
1136     *@param name Description of the Parameter
1137     *@return The selectArticleSection value
1138     */

1139    public static String JavaDoc getSelectArticleSection(DataStore db, String JavaDoc currentPubName, String JavaDoc name, String JavaDoc userID) {
1140        String JavaDoc select = getSelectArticleSection(db, currentPubName, name, userID, "" );
1141        return (select);
1142    }
1143    
1144
1145    /**
1146     * Returns a select of all article sections for a given publication with a
1147     * selected value.
1148     *
1149     *@param db Description of the Parameter
1150     *@param currentPubName Description of the Parameter
1151     *@param name Description of the Parameter
1152     *@param selected Description of the Parameter
1153     *@return The selectArticleSection value
1154     */

1155
1156    public static String JavaDoc getSelectArticleSection(DataStore db, String JavaDoc currentPubName, String JavaDoc name, String JavaDoc userID, String JavaDoc selected) {
1157        HashMap JavaDoc fillReq = new HashMap JavaDoc();
1158        fillReq.put("currentPubName", currentPubName);
1159        fillReq.put("currentUserID", userID);
1160        String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getSectionDescAndSectionFromSectionsByPubNameUser");
1161        HashMap JavaDoc nameValue = CofaxToolsDbUtils.getValueValuePackageHash(db, fillReq, tag, "SECTIONDESC", "SECTION");
1162        String JavaDoc select = createSelect(name, nameValue, selected);
1163        return (select);
1164    }
1165
1166
1167    /**
1168     * Returns a combo box allowing user to set or delete mappings, sets
1169     * selected values and mappings.
1170     *
1171     *@param db Description of the Parameter
1172     *@param howManyRows Description of the Parameter
1173     *@param session Description of the Parameter
1174     *@return The mappingCodesRankComboTable value
1175     */

1176
1177    public static String JavaDoc getMappingCodesRankComboTable(DataStore db, int howManyRows, HttpSession JavaDoc session) {
1178        HashMap JavaDoc ht = new HashMap JavaDoc();
1179        String JavaDoc combo = getMappingCodesRankComboTable(db, howManyRows, session, ht);
1180        return (combo);
1181    }
1182
1183
1184    /**
1185     * Returns a combo box allowing user to set or delete mappings, sets
1186     * selected values and mappings.
1187     *
1188     *@param db Description of the Parameter
1189     *@param howManyRows Description of the Parameter
1190     *@param session Description of the Parameter
1191     *@param sectionSelectRank Description of the Parameter
1192     *@return The mappingCodesRankComboTable value
1193     */

1194
1195    public static String JavaDoc getMappingCodesRankComboTable(DataStore db, int howManyRows, HttpSession JavaDoc session, HashMap JavaDoc sectionSelectRank) {
1196
1197        StringBuffer JavaDoc combo = new StringBuffer JavaDoc();
1198        combo.append("<TABLE>");
1199        combo.append("<TR><TD><B>" + CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"createarticle_map") + "</B></TD>\n");
1200        combo.append("<TD><B>" + CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"createarticle_rank") + "</B></TD>\n");
1201        combo.append("<TD><B>" + CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"createarticle_removefrommap") + "</B></TD></TR>\n");
1202        combo.append("<TR>");
1203
1204        ArrayList JavaDoc tempSelectStatement = (ArrayList JavaDoc) getSelectMappingsMultiplePublicationsArrayList(db, CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"mapping_code"), session);
1205
1206        Iterator JavaDoc en = sectionSelectRank.keySet().iterator();
1207        int i = 1;
1208        while (en.hasNext()) {
1209            String JavaDoc selectedSection = (String JavaDoc) en.next();
1210            String JavaDoc rank = (String JavaDoc) sectionSelectRank.get(selectedSection);
1211            String JavaDoc selectStatement = createSelect("MAPPINGCODE" + i, tempSelectStatement, selectedSection);
1212            combo.append("<TD>" + selectStatement + "</TD>\n");
1213            combo.append("<TD><input name=RANK" + i + " value=\"" + rank + "\" size=4></TD>\n");
1214            combo.append("<TD><input type=checkbox name=mappingDelete" + i + "></TD>\n");
1215            combo.append("<TR>\n");
1216            i++;
1217        }
1218        for (int in = 0; in < howManyRows; in++) {
1219            String JavaDoc selectStatement = createSelect("MAPPINGCODE" + i, tempSelectStatement);
1220            combo.append("<TD>" + selectStatement + "</TD>\n");
1221            combo.append("<TD><input name=RANK" + i + " value=\"\" size=4></TD>\n");
1222            combo.append("<TD>&nbsp;</TD>\n");
1223            combo.append("<TR>\n");
1224            i++;
1225        }
1226
1227        combo.append("<INPUT TYPE=HIDDEN NAME=numMappings VALUE = " + i + "></TABLE>\n");
1228        return (combo.toString());
1229    }
1230
1231
1232    /**
1233     * Returns a multiple select of all publications that user is grouped to.
1234     *
1235     *@param session Description of the Parameter
1236     *@param size Description of the Parameter
1237     *@param req Description of the Parameter
1238     *@return The selectMultipleMultiplePublication value
1239     */

1240
1241    public static String JavaDoc getSelectMultipleMultiplePublication(HttpSession JavaDoc session, int size, HttpServletRequest JavaDoc req) {
1242        String JavaDoc from = req.getParameter("from");
1243        Vector JavaDoc selected = new Vector JavaDoc();
1244
1245        if ((from != null) && (from.equals("savedSearch"))) {
1246            String JavaDoc publications[] = req.getParameterValues("publications");
1247            for (int i = 0; i < publications.length; i++) {
1248                selected.add(publications[i]);
1249            }
1250        } else {
1251            CofaxToolsUser user = (CofaxToolsUser) (session.getAttribute("user"));
1252            String JavaDoc workingPubName = user.workingPubName;
1253            selected.add(workingPubName);
1254        }
1255
1256
1257        CofaxToolsUser user = (CofaxToolsUser) session.getAttribute("user");
1258        HashMap JavaDoc userPubNamePubDescHash = user.userPubNamePubDescHash;
1259        String JavaDoc select = createMultipleSelect("publications", userPubNamePubDescHash, size, selected);
1260        return (select);
1261    }
1262
1263
1264
1265    /**
1266     * Returns a select of all sections from all publications a user is grouped
1267     * to.
1268     *
1269     *@param db Description of the Parameter
1270     *@param session Description of the Parameter
1271     *@param req Description of the Parameter
1272     *@return The selectCategoriesMultiplePublications value
1273     */

1274    public static String JavaDoc getSelectCategoriesMultiplePublications(DataStore db, HttpSession JavaDoc session, HttpServletRequest JavaDoc req) {
1275        CofaxToolsUser user = (CofaxToolsUser) session.getAttribute("user");
1276        String JavaDoc sectionPref = "";
1277        String JavaDoc from = req.getParameter("from");
1278        if ((from != null) && (from.equals("savedSearch"))) {
1279            sectionPref = req.getParameter("SECTION");
1280        }
1281
1282        List JavaDoc al = new ArrayList JavaDoc();
1283        // put the label into the arraylist
1284
HashMap JavaDoc tempLabel = new HashMap JavaDoc();
1285        tempLabel.put("** " + CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"tools_allsections") + " **", "");
1286        al.add(tempLabel);
1287
1288        String JavaDoc wkPub = user.workingPubName;
1289        HashMap JavaDoc userPubNamePubIDHash = new HashMap JavaDoc();
1290        userPubNamePubIDHash.putAll(user.userPubNamePubIDHash);
1291
1292        userPubNamePubIDHash.remove(wkPub);
1293        HashMap JavaDoc wkFillReq = new HashMap JavaDoc();
1294        wkFillReq.put("PUBNAME", wkPub);
1295
1296        StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
1297
1298        // get the sections for the working pub and put them into an arraylist
1299
String JavaDoc wkTag = CofaxToolsDbUtils.fillTag(db, "getSectionDescAndSectionFromSectionsByPubName");
1300        wkFillReq.put("currentUserID", (String JavaDoc)user.userInfoHash.get("USERID"));
1301        HashMap JavaDoc wkHt = CofaxToolsDbUtils.getValueValuePackageHash(db, wkFillReq, wkTag, "SECTIONDESC", "SECTION");
1302        SortedMap JavaDoc wkSortedMap = new TreeMap JavaDoc();
1303        wkSortedMap.putAll(wkHt);
1304        Set JavaDoc wkset = wkSortedMap.keySet();
1305        Iterator JavaDoc wkIterator = wkset.iterator();
1306        while (wkIterator.hasNext()) {
1307            String JavaDoc wkName = (String JavaDoc) wkIterator.next();
1308            String JavaDoc wkID = (String JavaDoc) wkSortedMap.get(wkName);
1309            HashMap JavaDoc wkTemp = new HashMap JavaDoc();
1310            wkTemp.put(wkName, wkID);
1311            al.add(wkTemp);
1312        }
1313
1314        // get the sections for the non working pub and put them into an arraylist
1315
Iterator JavaDoc en = userPubNamePubIDHash.keySet().iterator();
1316        HashMap JavaDoc htSelect = new HashMap JavaDoc();
1317        while (en.hasNext()) {
1318            String JavaDoc pubName = (String JavaDoc) en.next();
1319            HashMap JavaDoc fillReq = new HashMap JavaDoc();
1320            fillReq.put("PUBNAME", pubName);
1321            fillReq.put("currentUserID", (String JavaDoc)user.userInfoHash.get("USERID"));
1322            String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getSectionDescAndSectionFromSectionsByPubName");
1323            HashMap JavaDoc ht = CofaxToolsDbUtils.getValueValuePackageHash(db, fillReq, tag, "SECTIONDESC", "SECTION");
1324            Iterator JavaDoc enSel = ht.keySet().iterator();
1325            while (enSel.hasNext()) {
1326                String JavaDoc section = (String JavaDoc) enSel.next();
1327                String JavaDoc sectionDesc = (String JavaDoc) ht.get(section);
1328                htSelect.put(pubName + ": " + section, sectionDesc);
1329            }
1330        }
1331        SortedMap JavaDoc sortedMap = new TreeMap JavaDoc();
1332        sortedMap.putAll(htSelect);
1333        Set JavaDoc set = sortedMap.keySet();
1334        Iterator JavaDoc iterator = set.iterator();
1335        while (iterator.hasNext()) {
1336            String JavaDoc name = (String JavaDoc) iterator.next();
1337            String JavaDoc ID = (String JavaDoc) sortedMap.get(name);
1338            HashMap JavaDoc temp = new HashMap JavaDoc();
1339            temp.put(name, ID);
1340            al.add(temp);
1341        }
1342
1343        String JavaDoc select = createSelect("SECTION", (ArrayList JavaDoc) al, sectionPref);
1344        return (select);
1345    }
1346
1347
1348
1349    /**
1350     * Returns a hash of all mappings from all publications a user is grouped
1351     * to.
1352     *
1353     *@param db Description of the Parameter
1354     *@param label Description of the Parameter
1355     *@param session Description of the Parameter
1356     *@return The selectMappingsMultiplePublications value
1357     */

1358    public static HashMap JavaDoc getSelectMappingsMultiplePublications(DataStore db, String JavaDoc label, HttpSession JavaDoc session) {
1359
1360        CofaxToolsUser user = (CofaxToolsUser) session.getAttribute("user");
1361        HashMap JavaDoc userPubNamePubIDHash = user.userPubNamePubIDHash;
1362        Iterator JavaDoc en = userPubNamePubIDHash.keySet().iterator();
1363        StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
1364        HashMap JavaDoc htSelect = new HashMap JavaDoc();
1365
1366        while (en.hasNext()) {
1367            String JavaDoc pubName = (String JavaDoc) en.next();
1368            HashMap JavaDoc fillReq = new HashMap JavaDoc();
1369            fillReq.put("PUBNAME", pubName);
1370            String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getSectionDescAndMapCodeFromSectionsByPubName");
1371            HashMap JavaDoc ht = CofaxToolsDbUtils.getValueValuePackageHash(db, fillReq, tag, "SECTIONDESC", "MAPPINGCODE");
1372            Iterator JavaDoc enSel = ht.keySet().iterator();
1373
1374            while (enSel.hasNext()) {
1375                String JavaDoc section = (String JavaDoc) enSel.next();
1376                String JavaDoc sectionDesc = (String JavaDoc) ht.get(section);
1377                htSelect.put(pubName + ": " + section, sectionDesc);
1378            }
1379        }
1380        htSelect.put(label, "");
1381
1382        return (htSelect);
1383    }
1384
1385
1386
1387    /**
1388     * Splits an http query, returns a hash.&nbsp;For GET only..If multiple
1389     * values exists, returns a vector inside the hash for particluar value.
1390     *
1391     *@param req Description of the Parameter
1392     *@return Description of the Return Value
1393     */

1394    public static HashMap JavaDoc splitGetQuery(HttpServletRequest JavaDoc req) {
1395
1396        String JavaDoc info = req.getQueryString();
1397        //info = URLDecoder.decode(info);
1398
String JavaDoc leftOver = "";
1399        String JavaDoc pair;
1400        HashMap JavaDoc ht = new HashMap JavaDoc();
1401
1402        while (info.indexOf("=") >= 0) {
1403
1404            int firstAnd = info.indexOf("&");
1405
1406            // get pair value name = value if string still contains a &
1407
if (firstAnd >= 0) {
1408                pair = info.substring(0, firstAnd);
1409                leftOver = info.substring(firstAnd + 1);
1410            }
1411            // else there is only one pair remaining
1412
else {
1413                pair = info;
1414                leftOver = "";
1415            }
1416
1417            // split pair value
1418
int firstEquals = pair.indexOf("=");
1419            String JavaDoc name = pair.substring(0, firstEquals);
1420            String JavaDoc value = pair.substring(firstEquals + 1);
1421
1422            if ((value.equals(null)) || (value.equals(""))) {
1423                value = "";
1424            }
1425
1426            // check to see if we have a duplicate value, if not, add to hash
1427
if (!ht.containsKey(name)) {
1428                ht.put(name, value);
1429            }
1430            // if so, cast hash name to a vector and add our value
1431
else if (ht.containsKey(name)) {
1432
1433                try {
1434                    // if this value is already a vector we can add our new value
1435
Vector JavaDoc vec = (Vector JavaDoc) ht.get(name);
1436                    vec.add(value);
1437                } catch (java.lang.ClassCastException JavaDoc e) {
1438                    // if it is not we need to turn the old string into a vector and add our new value
1439
String JavaDoc oldValue = (String JavaDoc) ht.get(name);
1440                    Vector JavaDoc newVec = new Vector JavaDoc();
1441                    newVec.add(oldValue);
1442                    newVec.add(value);
1443                    ht.remove(name);
1444                    ht.put(name, newVec);
1445                }
1446            }
1447
1448            info = leftOver;
1449        }
1450        return (ht);
1451    }
1452
1453
1454    /**
1455     * Splits an http query, returns a hash.&nbsp;For POST only..If multiple
1456     * values exists, returns a string[] inside the hash for particluar value.
1457     *
1458     *@param req Description of the Parameter
1459     *@return Description of the Return Value
1460     */

1461    public static HashMap JavaDoc splitPostQuery(HttpServletRequest JavaDoc req) {
1462        Enumeration JavaDoc _enum = req.getParameterNames();
1463        HashMap JavaDoc ht = new HashMap JavaDoc();
1464        while (_enum.hasMoreElements()) {
1465            String JavaDoc va = (String JavaDoc) _enum.nextElement();
1466            String JavaDoc s = req.getParameter(va);
1467            ht.put(va, s);
1468        }
1469        return (ht);
1470    }
1471
1472
1473    /**
1474     * Displays the elements of an http header.
1475     *
1476     *@param req Description of the Parameter
1477     */

1478    public static void showHeader(HttpServletRequest JavaDoc req) {
1479
1480        Enumeration JavaDoc en = req.getHeaderNames();
1481        while (en.hasMoreElements()) {
1482            String JavaDoc val = (String JavaDoc) en.nextElement();
1483            log("header: " + val);
1484            Enumeration JavaDoc enu = req.getHeaders(val);
1485            while (enu.hasMoreElements()) {
1486                log("" + val + ":" + enu.nextElement());
1487            }
1488        }
1489
1490        Enumeration JavaDoc _enum = req.getParameterNames();
1491        while (_enum.hasMoreElements()) {
1492            String JavaDoc va = (String JavaDoc) _enum.nextElement();
1493            String JavaDoc[] s = req.getParameterValues(va);
1494
1495            for (int in = 0; in < s.length; in++) {
1496                log(va + ":" + s[in] + "");
1497            }
1498        }
1499
1500    }
1501
1502
1503    /**
1504     * Returns a list of article name, mapping, etc after compiling DB request
1505     * on fly.
1506     *
1507     *@param db Description of the Parameter
1508     *@param req Description of the Parameter
1509     *@return Description of the Return Value
1510     */

1511
1512    public static String JavaDoc searchArticles(DataStore db, HttpServletRequest JavaDoc req) {
1513        HttpSession JavaDoc session = req.getSession();
1514        CofaxToolsUser user = (CofaxToolsUser) session.getAttribute("user");
1515        String JavaDoc HttpPrefix = (String JavaDoc) user.workingPubConfigElementsHash.get("MAINCOFAXSERVER");
1516        if (!(HttpPrefix.endsWith("/"))) HttpPrefix += "/";
1517        String JavaDoc useDate;
1518
1519        String JavaDoc toolsPath = CofaxToolsServlet.toolsPath;
1520
1521        //HashMap ht = splitQuery(req);
1522
String JavaDoc startDate = (req.getParameter("startDatemonth") + "/" + req.getParameter("startDateday") + "/" + req.getParameter("startDateyear"));
1523        String JavaDoc stopDate = (req.getParameter("stopDatemonth") + "/" + req.getParameter("stopDateday") + "/" + req.getParameter("stopDateyear"));
1524        String JavaDoc section = req.getParameter("SECTION");
1525        String JavaDoc mapping = req.getParameter("mapping");
1526        String JavaDoc field1 = req.getParameter("field1");
1527        String JavaDoc condition1 = req.getParameter("condition1");
1528        String JavaDoc fieldtwo1 = req.getParameter("fieldtwo1");
1529        String JavaDoc field2 = req.getParameter("field2");
1530        String JavaDoc condition2 = req.getParameter("condition2");
1531        String JavaDoc fieldtwo2 = req.getParameter("fieldtwo2");
1532        String JavaDoc field3 = req.getParameter("field3");
1533        String JavaDoc condition3 = req.getParameter("condition3");
1534        String JavaDoc fieldtwo3 = req.getParameter("fieldtwo3");
1535        String JavaDoc results = req.getParameter("results");
1536        String JavaDoc orderBy = req.getParameter("orderBy");
1537        String JavaDoc startDatemonth = req.getParameter("startDatemonth");
1538        String JavaDoc startDateday = req.getParameter("startDateday");
1539        String JavaDoc startDateyear = req.getParameter("startDateyear");
1540        String JavaDoc stopDatemonth = req.getParameter("stopDatemonth");
1541        String JavaDoc stopDateday = req.getParameter("stopDateday");
1542        String JavaDoc stopDateyear = req.getParameter("stopDateyear");
1543
1544        HashMap JavaDoc fillReq = new HashMap JavaDoc();
1545        fillReq.put("PUBNAME", (String JavaDoc) user.workingPubName);
1546        String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getUseDateFromPublicationsByPubName");
1547        HashMap JavaDoc useDates = CofaxToolsDbUtils.getNameValuePackageHash(db, fillReq, tag);
1548        useDate = (String JavaDoc) useDates.get("USEDATE");
1549        useDate = "1";
1550
1551        String JavaDoc publications[] = req.getParameterValues("publications");
1552        if (publications == null) {
1553            return ("You must select at least one publication to search. Please click back on your browser and try again<BR>");
1554        }
1555
1556        if (publications.length < 1) {
1557            return ("You must select at least one publication to search. Please click back on your browser and try again<BR>");
1558        }
1559
1560        // call the search function from the specific datastore
1561
HashMap JavaDoc htParams = new HashMap JavaDoc();
1562        htParams.put("startDate",startDate);
1563        htParams.put("stopDate",stopDate);
1564        htParams.put("section",section);
1565        htParams.put("mapping",mapping);
1566        htParams.put("field1",field1);
1567        htParams.put("condition1",condition1);
1568        htParams.put("fieldtwo1",fieldtwo1);
1569        htParams.put("field2",field2);
1570        htParams.put("condition2",condition2);
1571        htParams.put("fieldtwo2",fieldtwo2);
1572        htParams.put("field3",field3);
1573        htParams.put("condition3",condition3);
1574        htParams.put("fieldtwo3",fieldtwo3);
1575        htParams.put("results",results);
1576        htParams.put("orderBy",orderBy);
1577        htParams.put("startDatemonth",startDatemonth);
1578        htParams.put("startDateday",startDateday);
1579        htParams.put("startDateyear",startDateyear);
1580        htParams.put("stopDatemonth",stopDatemonth);
1581        htParams.put("stopDateday",stopDateday);
1582        htParams.put("stopDateyear",stopDateyear);
1583        htParams.put("publications",publications);
1584        HashMap JavaDoc newHt = db.searchArticles(htParams);
1585                
1586        StringBuffer JavaDoc thisSearch = (StringBuffer JavaDoc) newHt.get("thisSearch");
1587        StringBuffer JavaDoc SQLState = (StringBuffer JavaDoc) newHt.get("SQLState");
1588
1589        List JavaDoc resultsL = CofaxToolsDbUtils.getPackageData(db, SQLState.toString());
1590        StringBuffer JavaDoc sbu = new StringBuffer JavaDoc();
1591        sbu.append("<TABLE WIDTH=750 CELLSPACING=0 CELLPADDING=0 BORDER=0>");
1592        sbu.append("<TD COLSPAN=3><INPUT TYPE=BUTTON VALUE=\"" + CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"searcharticle_savesearchas") + "\" onClick=\"saveSearch(\'" + thisSearch + "\')\">&nbsp;<INPUT TYPE=TEXT NAME=SEARCHNAME SIZE=20 MAXLENGTH=50><HR></TD><TR>\n");
1593
1594        if (resultsL.size() <= 0) {
1595            sbu.append(CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"tools_searchnoresult"));
1596        }
1597
1598        while (resultsL.size() > 0) {
1599            StringBuffer JavaDoc sbTemp = new StringBuffer JavaDoc();
1600            HashMap JavaDoc hashInfo = (HashMap JavaDoc) resultsL.get(0);
1601            sbTemp.append("" + (String JavaDoc) hashInfo.get("SECTIONDESC") + "");
1602            String JavaDoc lead = (String JavaDoc) hashInfo.get("LEAD");
1603            String JavaDoc sectionUrlName = (String JavaDoc) hashInfo.get("SECTION");
1604            String JavaDoc pubDate = (String JavaDoc) hashInfo.get("PUBDATE");
1605            String JavaDoc disableArticle = (String JavaDoc) hashInfo.get("DISABLEARTICLE");
1606            String JavaDoc disableIndex = (String JavaDoc) hashInfo.get("DISABLEINDEX");
1607            String JavaDoc workflow_state = (String JavaDoc) hashInfo.get("WORKFLOW_STATE");
1608            resultsL.remove(0);
1609            for (int ii = 0; ii < resultsL.size(); ii++) {
1610                HashMap JavaDoc tempH = (HashMap JavaDoc) resultsL.get(ii);
1611                String JavaDoc tempItemID = (String JavaDoc) tempH.get("ITEMID");
1612                if (tempItemID.equals((String JavaDoc) hashInfo.get("ITEMID"))) {
1613                    String JavaDoc tempSectionDesc = (String JavaDoc) tempH.get("SECTIONDESC");
1614                    sbTemp.append("<BR>" + tempSectionDesc + "");
1615                    resultsL.remove(ii);
1616                    ii--;
1617                }
1618            }
1619            String JavaDoc linkFunction = req.getParameter("linkFunction");
1620            if (linkFunction == null) {
1621                linkFunction = "";
1622            }
1623            String JavaDoc fontColor = "RED";
1624            if ((disableArticle.equals("1")) || (disableIndex.equals("1"))) {
1625                fontColor = "666666";
1626            }
1627            if (workflow_state.equals("1")) fontColor="#C1C307";
1628            else if (workflow_state.equals("2")) fontColor="#0066CC";
1629            else if (workflow_state.equals("0")) fontColor="silver";
1630
1631            sbu.append("<TD VALIGN=top><B><FONT SIZE=2 COLOR=" + fontColor + ">" + (String JavaDoc) hashInfo.get("FILENAME") + "</FONT></B></TD>\n");
1632            sbu.append("<TD VALIGN=top><B>");
1633            String JavaDoc viewArticleLink="<A HREF=\"javascript:oL('" + HttpPrefix + (String JavaDoc) hashInfo.get("VIRTUALFOLDER") + "/" + (String JavaDoc) hashInfo.get("FILENAME") + ".htm')\";>";
1634            if (workflow_state.equals("2")) sbu.append(viewArticleLink);
1635            sbu.append((String JavaDoc) hashInfo.get("HEADLINE"));
1636            if (workflow_state.equals("2")) sbu.append("</A>");
1637            sbu.append("</TD>\n");
1638            sbu.append("<TD VALIGN=top><B><FONT SIZE=1>V:" + (String JavaDoc) hashInfo.get("VERSIONNUM") + "</B></FONT></TD><TR>\n");
1639
1640            if (linkFunction.equals("relate")) {
1641                String JavaDoc callingFormPortion = req.getParameter("callingFormPortion");
1642                sbu.append("<TD VALIGN=TOP><FONT SIZE=1><B>" + (String JavaDoc) hashInfo.get("ITEMID"));
1643                
1644                sbu.append("<BR>" + (String JavaDoc) hashInfo.get("PUBNAME") + "<BR><A HREF=\"javascript: returnLink(\'" + HttpPrefix + (String JavaDoc) hashInfo.get("VIRTUALFOLDER") + "/" + (String JavaDoc) hashInfo.get("FILENAME") + ".htm\',\'" + (String JavaDoc) hashInfo.get("HEADLINE") + "\')\">" + getI18NMessage(CofaxToolsServlet.lcl,"searcharticle_linkarticle") + "</A>\n");
1645                sbu.append("<BR>" + sbTemp + "</B></FONT></TD>\n");
1646            } else {
1647                sbu.append("<TD VALIGN=TOP><FONT SIZE=1><B>" + (String JavaDoc) hashInfo.get("ITEMID"));
1648                sbu.append("<BR>" + (String JavaDoc) hashInfo.get("PUBNAME"));
1649                //show the 'edit' link only if the current user is allowed to edit this article
1650
boolean hp = CofaxToolsSecurity.checkArticleEdition(db, session, (String JavaDoc) hashInfo.get("ITEMID"));
1651                if (hp) {
1652                    sbu.append("<BR><A HREF=" + toolsPath + "?mode=article_edit_article_by_itemID&ITEMID=" + (String JavaDoc) hashInfo.get("ITEMID") + "&hl=article_create_article>" + CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"createarticle_edit") + "</A>\n");
1653                    if (!(workflow_state.equals("2")))
1654                    {
1655                            String JavaDoc url="'?mode=article_preview_article&ITEMID=" + (String JavaDoc) hashInfo.get("ITEMID") + "'";
1656                            String JavaDoc script= "window.open(" + url + ",'preview','WIDTH=700, HEIGHT=500 TOOLBAR=no TITLE=no MENUBAR=no STATUS=yes SCROLLBARS=no RESIZABLE=yes');";
1657                            sbu.append("&nbsp;" + "<A HREF=\"#\" onClick=\"" + script + "\">" + CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"createarticle_saveandpreview") + "</A>");
1658                    } else
1659                    {
1660                            sbu.append("&nbsp;" + viewArticleLink + CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"createarticle_viewonwebsite") + "</A>");
1661                    }
1662                }
1663                sbu.append("<BR>" + sbTemp + "</B></FONT></TD>\n");
1664            }
1665
1666            String JavaDoc byL = (String JavaDoc) hashInfo.get("BYLINE");
1667            if ((byL != null) && (!byL.equals(""))) {
1668                sbu.append("<TD VALIGN=TOP><FONT SIZE=1>" + (String JavaDoc) hashInfo.get("BYLINE") + "</FONT><BR>");
1669            } else {
1670                sbu.append("<TD VALIGN=TOP>");
1671            }
1672            sbu.append("<FONT SIZE=1>" + (String JavaDoc) hashInfo.get("LEAD") + "</FONT></TD>\n");
1673            sbu.append("<TD VALIGN=bottom>");
1674            if (workflow_state.equals("1")) sbu.append("<FONT COLOR=#C1C307 SIZE=1><B>" + getI18NMessage(CofaxToolsServlet.lcl,"createarticle_inprocessofvalidation") + "</B></FONT><BR>\n");
1675            else if (workflow_state.equals("2")) sbu.append("<FONT COLOR=#0066CC SIZE=1><B>" + getI18NMessage(CofaxToolsServlet.lcl,"createarticle_published") + "</B></FONT><BR>\n");
1676            else if (workflow_state.equals("0")) sbu.append("<FONT COLOR='silver' SIZE=1><B>" + getI18NMessage(CofaxToolsServlet.lcl,"createarticle_draft") + "</B></FONT><BR>\n");
1677
1678            sbu.append("<FONT SIZE=1><B>" + pubDate.substring(0, 10) + "</B></FONT></TD><TR>\n");
1679            sbu.append("<TD COLSPAN=3><HR></TD><TR>\n");
1680            sbTemp = null;
1681        }
1682        sbu.append("</TABLE>");
1683        return (sbu.toString());
1684    }
1685
1686
1687
1688
1689    /**
1690     * Returns info about the current date in a hash.
1691     *
1692     *@return The dateInfo value
1693     */

1694    public static HashMap JavaDoc getDateInfo() {
1695        java.util.Date JavaDoc date = new java.util.Date JavaDoc();
1696        Calendar JavaDoc today = Calendar.getInstance();
1697        today.setTime(date);
1698
1699        int monthTemp = today.get(Calendar.MONTH);
1700        monthTemp++;
1701        String JavaDoc month = String.valueOf(monthTemp);
1702        String JavaDoc year = String.valueOf(today.get(Calendar.YEAR));
1703        String JavaDoc day = String.valueOf(today.get(Calendar.DAY_OF_MONTH));
1704        String JavaDoc hour = String.valueOf(today.get(Calendar.HOUR));
1705        if (hour.equals("0")) {
1706            hour = "12";
1707        }
1708        String JavaDoc minute = String.valueOf(today.get(Calendar.MINUTE));
1709        String JavaDoc second = String.valueOf(today.get(Calendar.SECOND));
1710        String JavaDoc amPm = String.valueOf(today.get(Calendar.AM_PM));
1711        if (amPm.equals("1")) {
1712            amPm = "PM";
1713        } else {
1714            amPm = "AM";
1715        }
1716
1717        // pad the times
1718
if (hour.length() == 1) {
1719            hour = "0" + hour;
1720        }
1721        if (minute.length() == 1) {
1722            minute = "0" + minute;
1723        }
1724        if (second.length() == 1) {
1725            second = "0" + second;
1726        }
1727
1728        HashMap JavaDoc ht = new HashMap JavaDoc();
1729        ht.put("year", year);
1730        ht.put("month", month);
1731        ht.put("day", day);
1732        ht.put("hour", hour);
1733        ht.put("minute", minute);
1734        ht.put("second", second);
1735        ht.put("amPm", amPm);
1736        return (ht);
1737    }
1738
1739
1740    /**
1741     * Returns info needed to edit an article by itemID.
1742     *
1743     *@param db Description of the Parameter
1744     *@param itemID Description of the Parameter
1745     *@param session Description of the Parameter
1746     *@return The articleInfoByItemID value
1747     */

1748    public static HashMap JavaDoc getArticleInfoByItemID(DataStore db, String JavaDoc itemID, HttpSession JavaDoc session) {
1749        HashMap JavaDoc fillReq = new HashMap JavaDoc();
1750        fillReq.put("ITEMID", itemID);
1751        String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getAllFromArticlesbyItemID");
1752        HashMap JavaDoc ht = CofaxToolsDbUtils.getNameValuePackageHash(db, fillReq, tag);
1753        try
1754        {
1755            HashMap JavaDoc tmpper = new HashMap JavaDoc();
1756            tmpper.put("request:articleTypeID", (String JavaDoc)ht.get("ARTICLETYPEID"));
1757            String JavaDoc tagDefinition = db.getPackageTag("getArticleTypeByID", tmpper, "", "" );
1758            List JavaDoc packageData = db.getPackageData( "getArticleTypeByID", tagDefinition, "", "");
1759            
1760            if (packageData == null || (packageData.size() == 0) ){
1761                ht.put("ARTICLETYPE", "");
1762            } else {
1763                Iterator JavaDoc rows = packageData.iterator();
1764                HashMap JavaDoc rowData = (HashMap JavaDoc) rows.next();
1765                ht.put("ARTICLETYPE", (String JavaDoc)rowData.get("getArticleTypeByID:articleType"));
1766            }
1767        } catch (Exception JavaDoc e)
1768        {
1769            log("CofaxToolsUtil getArticleInfoByItemID: ERROR : " + e);
1770        }
1771        return (ht);
1772    }
1773
1774
1775    /**
1776     * Escapes >,<,",' to ascii characters and returns the HashMap
1777     *
1778     *@param hm Description of the Parameter
1779     *@return Description of the Return Value
1780     */

1781    public static HashMap JavaDoc escapeHTML(HashMap JavaDoc hm) {
1782        Iterator JavaDoc it = hm.keySet().iterator();
1783        while (it.hasNext()) {
1784            String JavaDoc key = (String JavaDoc) it.next();
1785            String JavaDoc val = (String JavaDoc) hm.get(key);
1786            if ((val != null) && (!val.equals(""))) {
1787                val = CofaxUtil.replace(val, "&", "&amp;");
1788                val = CofaxUtil.replace(val, "\"", "&quot;");
1789                val = CofaxUtil.replace(val, "<", "&lt;");
1790                val = CofaxUtil.replace(val, ">", "&gt;");
1791                val = CofaxUtil.replace(val, "\'", "&#039;");
1792                val = CofaxUtil.replace(val, "&amp;#0039;", "&#039;");
1793            }
1794            if ((key != null) && (!key.equals(""))) {
1795                hm.put(key, val);
1796            }
1797        }
1798        return (hm);
1799    }
1800
1801
1802
1803    /**
1804     * Returns mappings/ ranks associated with an article by itemID - Omits
1805     * original rank!
1806     *
1807     *@param db Description of the Parameter
1808     *@param itemID Description of the Parameter
1809     *@param section Description of the Parameter
1810     *@param pubName Description of the Parameter
1811     *@return The articleMappingsAndRankByItemID value
1812     */

1813    public static HashMap JavaDoc getArticleMappingsAndRankByItemID(DataStore db, String JavaDoc itemID, String JavaDoc section, String JavaDoc pubName) {
1814        HashMap JavaDoc fillReq = new HashMap JavaDoc();
1815        fillReq.put("SECTION", section);
1816        fillReq.put("PUBNAME", pubName);
1817        String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getMapCodeFromtblsectionsBySectionAndPubName");
1818        HashMap JavaDoc htTemp = CofaxToolsDbUtils.getNameValuePackageHash(db, fillReq, tag);
1819
1820        String JavaDoc mappingCode = (String JavaDoc) htTemp.get("MAPPINGCODE");
1821        HashMap JavaDoc fillReqTwo = new HashMap JavaDoc();
1822        fillReqTwo.put("ITEMID", itemID);
1823        tag = CofaxToolsDbUtils.fillTag(db, "getMapCodeRankFromViewAllArticlesByItemID");
1824        HashMap JavaDoc ht = CofaxToolsDbUtils.getValueValuePackageHash(db, fillReqTwo, tag, "MAPPINGCODE", "ORDERINGRANK");
1825
1826        try {
1827            ht.remove(mappingCode);
1828        } catch (Exception JavaDoc e) {
1829            // Your mother gave me an ear infection over the phone
1830
}
1831
1832        Iterator JavaDoc en = ht.keySet().iterator();
1833        while (en.hasNext()) {
1834            String JavaDoc mappingCodeTwo = (String JavaDoc) en.next();
1835        }
1836        return (ht);
1837    }
1838
1839
1840    /**
1841     * Returns all MultiMedia info associated with an article by itemID.
1842     *
1843     *@param db Description of the Parameter
1844     *@param itemID Description of the Parameter
1845     *@return The relatedMultiMediaByItemID value
1846     */

1847    public static List JavaDoc getRelatedMultiMediaByItemID(DataStore db, String JavaDoc itemID) {
1848        HashMap JavaDoc fillReq = new HashMap JavaDoc();
1849        fillReq.put("ITEMID", itemID);
1850        String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getAllFromMultimediaByItemID");
1851        List JavaDoc results = CofaxToolsDbUtils.getPackageData(db, fillReq, tag);
1852        return (results);
1853    }
1854
1855
1856    /**
1857     * Returns all MultiMedia info associated with a MultiMedia item by
1858     * multiMediaID.
1859     *
1860     *@param db Description of the Parameter
1861     *@param itemID Description of the Parameter
1862     *@return The relatedMultiMediaByMultiMediaID value
1863     */

1864    public static List JavaDoc getRelatedMultiMediaByMultiMediaID(DataStore db, String JavaDoc itemID) {
1865        HashMap JavaDoc fillReq = new HashMap JavaDoc();
1866        fillReq.put("ITEMID", itemID);
1867        String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getAllFromMultimediaByItemID");
1868        List JavaDoc results = CofaxToolsDbUtils.getPackageData(db, fillReq, tag);
1869        return (results);
1870    }
1871
1872
1873    /**
1874     * Returns all MultiMedia types.
1875     *
1876     *@param db Description of the Parameter
1877     *@return The multiMediaTypes value
1878     */

1879    public static HashMap JavaDoc getMultiMediaTypes(DataStore db) {
1880        String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getDistinctTypeFromMultimedia");
1881        Vector JavaDoc vec = CofaxToolsDbUtils.getPackageVector(db, tag);
1882        HashMap JavaDoc ht = new HashMap JavaDoc();
1883        Iterator JavaDoc it = vec.iterator();
1884        while (it.hasNext()) {
1885            String JavaDoc type = (String JavaDoc) it.next();
1886            ht.put(type, type);
1887        }
1888        return (ht);
1889    }
1890
1891
1892    /**
1893     * Formats a sql date into a Cofax usable date
1894     *
1895     *@param date Description of the Parameter
1896     *@return Description of the Return Value
1897     */

1898    public static String JavaDoc sqlDateToCofaxDate(String JavaDoc date) {
1899        if (date.length() > 0) {
1900            date = date.substring(0, 10);
1901            date = date.replace('-', '/');
1902        }
1903        return (date);
1904    }
1905
1906
1907    /**
1908     * Formats the current date into String yyyy/mm/dd.
1909     *
1910     *@return The dateString value
1911     */

1912    public static String JavaDoc getDateString() {
1913        HashMap JavaDoc ht = getDateInfo();
1914        String JavaDoc year = (String JavaDoc) ht.get("year");
1915        String JavaDoc month = (String JavaDoc) ht.get("month");
1916        String JavaDoc day = (String JavaDoc) ht.get("day");
1917        if (month.length() == 1) {
1918            month = "0" + month;
1919        }
1920        if (day.length() == 1) {
1921            day = "0" + day;
1922        }
1923        return (year + "/" + month + "/" + day);
1924    }
1925
1926
1927
1928    /**
1929     * Returns a select of article types for a given publication with no
1930     * selected value.
1931     *
1932     *@param db Description of the Parameter
1933     *@param currentPubName Description of the Parameter
1934     *@param label Description of the Parameter
1935     *@return The selectArticleType value
1936     */

1937     
1938    public static String JavaDoc getSelectArticleType(DataStore db, String JavaDoc currentPubName, String JavaDoc label) {
1939        String JavaDoc select = getSelectArticleType(db, currentPubName, label, "");
1940        return (select);
1941    }
1942
1943
1944        /**
1945     * Returns a select of article types for a given publication with no
1946     * selected value.
1947     *
1948     *@param db Description of the Parameter
1949     *@param currentPubName Description of the Parameter
1950     *@param label Description of the Parameter
1951     *@return The selectArticleType value
1952     */

1953     
1954    public static String JavaDoc getSelectArticleTypeNew(DataStore db, String JavaDoc currentPubName, String JavaDoc label) {
1955        String JavaDoc select = getSelectArticleTypeNew(db, currentPubName, label, "");
1956        return (select);
1957    }
1958
1959
1960    /**
1961     * Returns a select of article types for a given publication with a
1962     * selected value.
1963     *
1964     *@param db Description of the Parameter
1965     *@param currentPubName Description of the Parameter
1966     *@param label Description of the Parameter
1967     *@param selected Description of the Parameter
1968     *@return The selectArticleType value
1969     */

1970     
1971    public static String JavaDoc getSelectArticleType(DataStore db, String JavaDoc currentPubName, String JavaDoc label, String JavaDoc selected) {
1972        HashMap JavaDoc fillReq = new HashMap JavaDoc();
1973        fillReq.put("currentPubName", currentPubName);
1974        String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getArticleTypeDescAndTypeFromArticleTypesByPubName");
1975        HashMap JavaDoc ht = CofaxToolsDbUtils.getValueValuePackageHash(db, fillReq, tag, "ARTICLETYPEDESC", "ARTICLETYPEID");
1976        ht.put("** Select Articletype **", "");
1977        String JavaDoc select = createSelect(label, ht, selected);
1978        return (select);
1979    }
1980    
1981    
1982     /**
1983     * Returns a select of article types for a given publication with a
1984     * selected value.
1985     *
1986     *@param db Description of the Parameter
1987     *@param currentPubName Description of the Parameter
1988     *@param label Description of the Parameter
1989     *@param selected Description of the Parameter
1990     *@return The selectArticleType value
1991     */

1992    public static String JavaDoc getSelectArticleTypeNew(DataStore db, String JavaDoc currentPubName, String JavaDoc label, String JavaDoc selected) {
1993        HashMap JavaDoc fillReq = new HashMap JavaDoc();
1994        fillReq.put("currentPubName", currentPubName);
1995        String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getArticleTypeDescAndTypeFromArticleTypeByPubName");
1996        HashMap JavaDoc ht = CofaxToolsDbUtils.getValueValuePackageHash(db, fillReq, tag, "ARTICLETYPEDESC", "ARTICLETYPE");
1997        ht.put("** Select Articletype **", "");
1998        String JavaDoc select = createSelect(label, ht, selected);
1999        return (select);
2000    }
2001    
2002
2003
2004
2005
2006    /**
2007     * Returns a select of section types for a given publication with no
2008     * selected value.
2009     *
2010     *@param db Description of the Parameter
2011     *@param currentPubName Description of the Parameter
2012     *@param label Description of the Parameter
2013     *@return The selectSection value
2014     */

2015    public static String JavaDoc getSelectSection(DataStore db, String JavaDoc currentPubName, String JavaDoc label) {
2016        String JavaDoc select = getSelectSection(db, currentPubName, label, "");
2017        return (select);
2018    }
2019
2020
2021
2022    /**
2023     * Returns a select of section types for a given publication with a
2024     * selected value.
2025     *
2026     *@param db Description of the Parameter
2027     *@param pubName Description of the Parameter
2028     *@param label Description of the Parameter
2029     *@param selected Description of the Parameter
2030     *@return The selectSection value
2031     */

2032    public static String JavaDoc getSelectSection(DataStore db, String JavaDoc pubName, String JavaDoc label, String JavaDoc selected) {
2033        HashMap JavaDoc fillReq = new HashMap JavaDoc();
2034        fillReq.put("PUBNAME", pubName);
2035        String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getSectionDescAndMapCodeFromSectionsByPubName");
2036        HashMap JavaDoc ht = CofaxToolsDbUtils.getValueValuePackageHash(db, fillReq, tag, "SECTIONDESC", "MAPPINGCODE");
2037        ht.put("** " + CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"tools_selectmappingsection") + " **", "");
2038        String JavaDoc select = createSelect(label, ht, selected);
2039        return (select);
2040    }
2041
2042    /**
2043     * Converts a given boolean in a hashmap to "checked" or "" accordingly for
2044     * placement on an html page.
2045     *
2046     *@param ht Description of the Parameter
2047     *@param itemToBeConverted Description of the Parameter
2048     *@return Description of the Return Value
2049     */

2050    public static HashMap JavaDoc convertBooleanToChecked(HashMap JavaDoc ht, String JavaDoc itemToBeConverted) {
2051        if (ht.size() > 0) {
2052
2053            String JavaDoc checked = (String JavaDoc) ht.get(itemToBeConverted);
2054            if ((checked != null) && (!checked.equals("0"))) {
2055                checked = "checked";
2056            } else {
2057                checked = "";
2058            }
2059            ht.put(itemToBeConverted, checked);
2060        }
2061        return (ht);
2062    }
2063
2064
2065    /**
2066     * Converts a given checkbox String to a boolean according to its status.
2067     *
2068     *@param checked Description of the Parameter
2069     *@return Description of the Return Value
2070     */

2071    public static String JavaDoc convertCheckedToBoolean(String JavaDoc checked) {
2072        if (checked != null) {
2073            checked = "1";
2074        } else {
2075            checked = "0";
2076        }
2077        return (checked);
2078    }
2079
2080
2081
2082    /**
2083     * Returns info associated with an article type by articletypeID.
2084     *
2085     *@param db Description of the Parameter
2086     *@param articleTypeID Description of the Parameter
2087     *@return The articletypeInfoByID value
2088     */

2089     /*
2090    public static HashMap getArticletypeInfoByID(DataStore db, String articleTypeID) {
2091        HashMap fillReq = new HashMap();
2092        fillReq.put("ARTICLETYPEID", articleTypeID);
2093        String tag = CofaxToolsDbUtils.fillTag(db, "getAllFromTblArticleTypeByArticleTypeID");
2094        HashMap ht = CofaxToolsDbUtils.getNameValuePackageHash(db, fillReq, tag);
2095        return (ht);
2096    }
2097    */

2098
2099
2100
2101    /**
2102     * Returns a comboBox to order sections by.
2103     *
2104     *@param db Description of the Parameter
2105     *@param publication Description of the Parameter
2106     *@param session Description of the Parameter
2107     *@param req Description of the Parameter
2108     *@param numPreOrders Description of the Parameter
2109     *@return The orderSectionComboBox value
2110     */

2111    public static String JavaDoc getOrderSectionComboBox(DataStore db, String JavaDoc publication, HttpSession JavaDoc session, HttpServletRequest JavaDoc req, String JavaDoc numPreOrders) {
2112        HashMap JavaDoc ht = new HashMap JavaDoc();
2113        return (getOrderSectionComboBox(db, publication, session, req, ht, numPreOrders));
2114    }
2115
2116
2117    /**
2118     * Returns a comboBox to order sections by.
2119     *
2120     *@param db Description of the Parameter
2121     *@param publication Description of the Parameter
2122     *@param session Description of the Parameter
2123     *@param req Description of the Parameter
2124     *@param temp Description of the Parameter
2125     *@param numPreOrders Description of the Parameter
2126     *@return The orderSectionComboBox value
2127     */

2128    public static String JavaDoc getOrderSectionComboBox(DataStore db, String JavaDoc publication, HttpSession JavaDoc session, HttpServletRequest JavaDoc req, HashMap JavaDoc temp, String JavaDoc numPreOrders) {
2129        List JavaDoc list;
2130        String JavaDoc mappingCode;
2131        String JavaDoc results;
2132        String JavaDoc startDate;
2133        String JavaDoc endDate;
2134
2135        if (temp.size() <= 0) {
2136            mappingCode = req.getParameter("mapping");
2137            results = req.getParameter("results");
2138
2139            String JavaDoc startYear = req.getParameter("selectStartDateyear");
2140            String JavaDoc startMonth = req.getParameter("selectStartDatemonth");
2141            String JavaDoc startDay = req.getParameter("selectStartDateday");
2142            String JavaDoc stopYear = req.getParameter("selectEndDateyear");
2143            String JavaDoc stopMonth = req.getParameter("selectEndDatemonth");
2144            String JavaDoc stopDay = req.getParameter("selectEndDateday");
2145
2146            if (startMonth.length() == 1) {
2147                startMonth = "0" + startMonth;
2148            }
2149            if (startDay.length() == 1) {
2150                startDay = "0" + startDay;
2151            }
2152            if (stopMonth.length() == 1) {
2153                stopMonth = "0" + stopMonth;
2154            }
2155            if (stopDay.length() == 1) {
2156                stopDay = "0" + stopDay;
2157            }
2158
2159            startDate = (startYear + "-" + startMonth + "-" + startDay);
2160            endDate = (stopYear + "-" + stopMonth + "-" + stopDay);
2161        } else {
2162            mappingCode = (String JavaDoc) temp.get("mapping");
2163            results = ("100");
2164            startDate = (String JavaDoc) temp.get("PUBDATE");
2165            endDate = (String JavaDoc) temp.get("PUBDATE");
2166        }
2167
2168        if (mappingCode.equals("insertPublication")) {
2169            return ("You must select a section to order before submitting the form");
2170        }
2171
2172        CofaxToolsUser user = (CofaxToolsUser) session.getAttribute("user");
2173        String JavaDoc HttpPrefix = (String JavaDoc) user.workingPubConfigElementsHash.get("MAINCOFAXSERVER");
2174        HashMap JavaDoc fillRequest = new HashMap JavaDoc();
2175        fillRequest.put("results", results);
2176        fillRequest.put("MAPPINGCODE", mappingCode);
2177        fillRequest.put("startDate", startDate);
2178        fillRequest.put("endDate", endDate);
2179
2180        if (startDate.equals(endDate)) {
2181            String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getAllfromtblarticlesTblOrderByMapAndDate");
2182            list = CofaxToolsDbUtils.getPackageData(db, fillRequest, tag);
2183        } else {
2184            String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getAllfromtblarticlesTblOrderByMapAndDates");
2185            list = CofaxToolsDbUtils.getPackageData(db, fillRequest, tag);
2186        }
2187
2188        HashMap JavaDoc fillReq = new HashMap JavaDoc();
2189        fillReq.put("MAPPINGCODE", mappingCode);
2190        String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getSectionNameDescFromtblsectionsByMappingCode");
2191        HashMap JavaDoc htTemp = CofaxToolsDbUtils.getNameValuePackageHash(db, fillReq, tag);
2192
2193        String JavaDoc sectionName = (String JavaDoc) htTemp.get("SECTIONNAME");
2194        String JavaDoc section = (String JavaDoc) htTemp.get("SECTION");
2195        String JavaDoc sectionDesc = (String JavaDoc) htTemp.get("SECTIONDESC");
2196
2197        String JavaDoc toolsPath = CofaxToolsServlet.toolsPath;
2198
2199        ArrayList JavaDoc tempSelectMappingsMultiplePublications = (ArrayList JavaDoc) getSelectMappingsMultiplePublicationsArrayList(db, "** Mapping Section **", session);
2200
2201        int mappingSize = list.size();
2202
2203        HashMap JavaDoc ht = new HashMap JavaDoc();
2204        for (int i = 0; i < (list.size() + 30); i++) {
2205            String JavaDoc tempNum = String.valueOf(i + 1);
2206            if (tempNum.length() == 1) {
2207                tempNum = "0" + tempNum;
2208            }
2209            ht.put(tempNum, tempNum);
2210        }
2211
2212        StringBuffer JavaDoc s = new StringBuffer JavaDoc();
2213        s.append("<TABLE WIDTH=750>");
2214        s.append("<INPUT TYPE=HIDDEN NAME=mapTo VALUE=\'" + mappingCode + "\'>");
2215
2216        for (int i = 1; i <= list.size(); i++) {
2217            HashMap JavaDoc map = (HashMap JavaDoc) list.get(i - 1);
2218            String JavaDoc headline = (String JavaDoc) map.get("HEADLINE");
2219            map = escapeHTML(map);
2220
2221            String JavaDoc itemID = (String JavaDoc) map.get("ITEMID");
2222            String JavaDoc docID = (String JavaDoc) map.get("DOCID");
2223            String JavaDoc pubName = (String JavaDoc) map.get("PUBNAME");
2224            String JavaDoc pubDate = sqlDateToCofaxDate((String JavaDoc) map.get("PUBDATE"));
2225            String JavaDoc rank = (String JavaDoc) map.get("RANK");
2226            String JavaDoc disableArticle = (String JavaDoc) map.get("DISABLEARTICLE");
2227            String JavaDoc disableIndex = (String JavaDoc) map.get("DISABLEINDEX");
2228            String JavaDoc fileName = (String JavaDoc) map.get("FILENAME");
2229            if (disableIndex.equals("1")) {
2230                disableIndex = "checked";
2231            } else {
2232                disableIndex = "";
2233            }
2234            if (disableArticle.equals("1")) {
2235                disableArticle = "checked";
2236            } else {
2237                disableArticle = "";
2238            }
2239            String JavaDoc tempNum = String.valueOf(i);
2240            if (tempNum.length() == 1) {
2241                tempNum = "0" + tempNum;
2242            }
2243            String JavaDoc selectRank = createSelect("RANK" + i, ht, tempNum);
2244            
2245            String JavaDoc headline2=headline;
2246            String JavaDoc validated = (String JavaDoc) map.get("WORKFLOW_STATE");
2247            if (validated.equals("0")) headline2="<font color='silver'><i>" + headline + "</i></font>";
2248            else if (validated.equals("1")) headline2="<font color='#C1C307'><i>" + headline + "</i></font>";
2249            else if (validated.equals("2")) headline2="<font color='#0066CC'>" + headline + "</font>";
2250            
2251            s.append("\n<INPUT TYPE=HIDDEN NAME=ITEMID" + i + " VALUE=" + itemID + ">\n");
2252            s.append("<INPUT TYPE=HIDDEN NAME=SECTION" + i + " VALUE=\'" + section + "\'>\n");
2253            s.append("<INPUT TYPE=HIDDEN NAME=MAPPINGCODE" + i + " VALUE=" + mappingCode + ">\n");
2254            s.append("<INPUT TYPE=HIDDEN NAME=FILENAME" + i + " VALUE=" + fileName + ">\n");
2255            s.append("<INPUT TYPE=HIDDEN NAME=PUBNAME" + i + " VALUE=" + pubName + ">\n");
2256            s.append("<INPUT TYPE=HIDDEN NAME=PUBDATE" + i + " VALUE=" + pubDate + ">\n");
2257            s.append("<TD>" + selectRank + "</TD><TD><B> " + fileName + "<B></TD><TD><B>" + headline2 + "</TD><TD><INPUT TYPE=CHECKBOX NAME=remove" + i + ">Delete from map</TD><TR>\n");
2258            s.append("<TD><A HREF=" + toolsPath + "?mode=article_edit_article_by_itemID&ITEMID=" + itemID + ">Edit</A></TD><TD> " + sectionName + "</TD><TD>" + pubDate + "</TD><TD><INPUT TYPE=CHECKBOX NAME=DISABLEINDEX" + i + " " + disableIndex + " >" + CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"createarticle_disableonsectionfront") + "</TD><TR>\n");
2259            s.append("<TD>" + pubName + "</TD><TD></TD><TD></TD><TD><INPUT TYPE=CHECKBOX NAME=DISABLEARTICLE" + i + " " + disableArticle + " >" + CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"createarticle_disablearticle") + "</TD><TR>\n");
2260            s.append("<TD COLSPAN=4>&nbsp;</TD><TR>");
2261
2262        }
2263        if (mappingSize == 0) {
2264            s.append("<TD><FONT COLOR=RED>No Stories have been found for this section.</FONT>\n");
2265        }
2266        s.append("<TD><INPUT TYPE=HIDDEN NAME=listFilledSize VALUE=" + String.valueOf(list.size()) + ">\n");
2267        s.append("</TABLE><TABLE WIDTH=750>\n");
2268        if (Integer.parseInt(numPreOrders) > 0) {
2269            s.append("<TD COLSPAN=4><HR><CENTER><B>Pre-Order Non-Existent Stories</B></TD><TR>\n");
2270        } else {
2271            s.append("<TD COLSPAN=4><HR></TD><TR>\n");
2272        }
2273
2274        HashMap JavaDoc htTime = getDateInfo();
2275        int year = Integer.parseInt((String JavaDoc) htTime.get("year"));
2276        int month = Integer.parseInt((String JavaDoc) htTime.get("month"));
2277        int day = Integer.parseInt((String JavaDoc) htTime.get("day"));
2278
2279        for (int i = list.size() + 1; i <= (list.size() + Integer.parseInt(numPreOrders)); i++) {
2280            String JavaDoc tempNum = String.valueOf(i);
2281            if (tempNum.length() == 1) {
2282                tempNum = "0" + tempNum;
2283            }
2284            String JavaDoc selectDate = getSelectDate("date" + i, year, month, day);
2285            String JavaDoc selectRank = createSelect("RANK" + i, ht, tempNum);
2286            String JavaDoc selectMappingsMultiplePublications = createSelect("MAPPINGCODE" + i, tempSelectMappingsMultiplePublications);
2287            s.append("<TD COLSPAN=2><INPUT TYPE=HIDDEN NAME=ITEMID" + i + " VALUE=\"\">\n");
2288            s.append("<INPUT TYPE=HIDDEN NAME=SECTION" + i + " VALUE=\'" + section + "\'>\n");
2289            s.append("" + selectRank + "&nbsp; Slug:<INPUT TYPE=TEXT NAME=FILENAME" + i + "></TD><TR>\n");
2290            s.append("<TD>From Section: " + selectMappingsMultiplePublications + "</TD><TD> Pub Date: " + selectDate + "</TD><TR>\n");
2291            s.append("<TD COLSPAN=2>&nbsp;</TD><TR>\n");
2292
2293        }
2294
2295        s.append("<INPUT TYPE=HIDDEN NAME=listSize VALUE=" + (list.size() + Integer.parseInt(numPreOrders)) + ">\n");
2296        s.append("</TABLE>\n");
2297        return (s.toString());
2298    }
2299
2300
2301
2302    /**
2303     * returns a MultiMedia comboBox associated with an article by itemID.
2304     *
2305     *@param db Description of the Parameter
2306     *@param l Description of the Parameter
2307     *@param pubDate Description of the Parameter
2308     *@param session Description of the Parameter
2309     *@param storyItemID Description of the Parameter
2310     *@return The multiMediaComboBox value
2311     */

2312    // pubDate can be removed as soon as testing is done - all images will be living in one place at that point
2313
public static String JavaDoc getMultiMediaComboBox(DataStore db, List JavaDoc l, String JavaDoc pubDate,
2314            HttpSession JavaDoc session, String JavaDoc storyItemID) {
2315        CofaxToolsUser user = (CofaxToolsUser) session.getAttribute("user");
2316        String JavaDoc imagesURLPrefix = (String JavaDoc) user.workingPubConfigElementsHash.get("IMAGESURLPREFIX");
2317
2318        if (!imagesURLPrefix.endsWith("/")) {
2319            imagesURLPrefix = imagesURLPrefix + "/";
2320        }
2321        
2322        String JavaDoc pubName = user.workingPubName;
2323        String JavaDoc pubID = (String JavaDoc) user.workingPub;
2324        StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
2325        String JavaDoc useDate = "0" ; // don't use date anymore
2326

2327        pubDate = sqlDateToCofaxDate(pubDate);
2328        int finalCount = 0;
2329
2330        HashMap JavaDoc ht = new HashMap JavaDoc ();// getMultiMediaTypes(db);
2331
// FX : moving to i18n
2332
ht.put("** " + CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"tools_selecttype") + " **", "");
2333        ht.put(CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"article_image"), "articleImage");
2334        ht.put(CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"article_attachments"), "other");
2335        // ht.put(CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"section_image"), "sectionImage");
2336

2337
2338        sb.append("<input type=\"hidden\" name=\"ITEMID\" value=\"" + storyItemID + "\" />");
2339        sb.append("<div class=\"multimediabox\">"); // FX : changing to DIV
2340

2341        // if the article has MultiMedia info attached to it, grab the info.
2342
for (int i = 0; i < l.size(); i++) {
2343            HashMap JavaDoc hashInfo = (HashMap JavaDoc) l.get(i);
2344            String JavaDoc multiMediaID = (String JavaDoc) hashInfo.get("MULTIMEDIAID");
2345            String JavaDoc type = (String JavaDoc) hashInfo.get("TYPE");
2346            String JavaDoc itemID = (String JavaDoc) hashInfo.get("ITEMID");
2347            String JavaDoc caption = (String JavaDoc) hashInfo.get("CAPTION");
2348            String JavaDoc itemName = (String JavaDoc) hashInfo.get("ITEMNAME");
2349            String JavaDoc size = (String JavaDoc) hashInfo.get("SIZE");
2350            String JavaDoc filename = (String JavaDoc) hashInfo.get("FILENAME");
2351            
2352            //remove already used types for this article
2353
if (type.equals("articleImage")) ht.remove("article image");
2354            if (type.equals("sectionImage")) ht.remove("section image");
2355                    
2356            //check if it's a pdf
2357
String JavaDoc imagesURLPrefix2 = imagesURLPrefix;
2358            if (useDate.equals("1")) imagesURLPrefix2=imagesURLPrefix2+pubDate + "/";
2359            imagesURLPrefix2=imagesURLPrefix2+itemName;
2360            if (imagesURLPrefix2.toLowerCase().endsWith("pdf")) imagesURLPrefix2="" + CofaxToolsServlet.aliasPath + "/static/images/pdf.gif";
2361            if (imagesURLPrefix2.toLowerCase().endsWith("doc")) imagesURLPrefix2="" + CofaxToolsServlet.aliasPath + "/static/images/doc.gif";
2362            if (imagesURLPrefix2.toLowerCase().endsWith("ppt")) imagesURLPrefix2="" + CofaxToolsServlet.aliasPath + "/static/images/ppt.gif";
2363            if (imagesURLPrefix2.toLowerCase().endsWith("mdb")) imagesURLPrefix2="" + CofaxToolsServlet.aliasPath + "/static/images/mdb.gif";
2364            if (imagesURLPrefix2.toLowerCase().endsWith("xls")) imagesURLPrefix2="" + CofaxToolsServlet.aliasPath + "/static/images/xls.gif";
2365            if (imagesURLPrefix2.toLowerCase().endsWith("csv")) imagesURLPrefix2="" + CofaxToolsServlet.aliasPath + "/static/images/xls.gif";
2366            if (imagesURLPrefix2.toLowerCase().endsWith("zip")) imagesURLPrefix2="" + CofaxToolsServlet.aliasPath + "/static/images/zip.gif";
2367            
2368            // FX : changing formatting
2369
sb.append("<table>");
2370            sb.append("<input type=\"hidden\" name=\"multiMediaType" + i + "\" value=\"" + type + "\" />");
2371            sb.append("<input type=\"hidden\" name=\"uploadImage" + i + "\" value=\"" + filename + "\" />"); // added by fx : 29/03/06
2372
sb.append("<input type=\"hidden\" name=\"MULTIMEDIAID" + i + "\" value=\"" + multiMediaID + "\" />" + "\n");
2373            sb.append("<tr><th>Type</th><td>" + CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,type) +"&nbsp;<input type=\"checkbox\" name=\"deleteMultiMedia" + i + "\" />" + CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"createarticle_delete")+ "</td></tr>");
2374            sb.append("<tr><th>"+CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"article_file")+"</th><td><a HREF=\"javascript:openNewWindow(\'" + imagesURLPrefix);
2375                    // IF useDate
2376
if (useDate.equals("1")) sb.append(pubDate + "/");
2377                    sb.append(itemName + "\',\'this\',\'WIDTH=300, HEIGHT=400 MENUBAR=yes SCROLLBARS=yes RESIZABLE=yes\')\">\n");
2378                    sb.append("&nbsp;"+itemName+"</a>");
2379                    // IF useDate
2380
// if (useDate.equals("1")) sb.append(pubDate + "/");
2381
sb.append("</td></tr>");
2382                    sb.append("<tr><th>" + CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"createarticle_caption") + "</th>\n");
2383                    sb.append("<td><input type=\"text\" name=\"multiMediaCaption" + i + "\" size=\"20\" value=\"" + caption + "\" />"+ size+"</td></tr>\n");
2384                    sb.append("<input type=\"hidden\" name=\"itemName" + i + "\" value=\"" + itemName + "\" />");
2385                    sb.append("<input type=\"hidden\" name=\"SIZE" + i + "\" value=\"" + size + "\" />");
2386                
2387                sb.append("</table>\n");
2388            sb.append("");
2389            finalCount++;
2390        }
2391
2392        //for (int ii = 0; ii < incr; ii++) {
2393
int i = finalCount;
2394            String JavaDoc selectMultiMediaType = createSelect("multiMediaType" + i, ht);
2395            sb.append("<hr />");
2396            sb.append("<table>");
2397            sb.append("<tr><th>" + CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"createarticle_addmultimedia") + "</th>");
2398            sb.append("<td>"+ selectMultiMediaType + "</td></tr>");
2399            sb.append("<th>"+CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"article_file")+"</th>");
2400            sb.append("<td><input type=\"file\" name=\"uploadImage" + i + "\" size=\"5\" value=\"Upload New\" /></td></tr>\n");
2401            sb.append("<input type=\"hidden\" name=\"numMultiMediaItems\" value=\"" + finalCount + "\" />\n");
2402            sb.append("<input type=\"hidden\" name=\"newUpload" + i + "\" value=\"yes\" />\n");
2403            sb.append("<tr><th>" + CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"createarticle_caption") + "</th>\n");
2404            sb.append("<td><input type=\"text\" name=\"multiMediaCaption" + i + "\" size=\"20\" /></textarea></td></tr>\n");
2405            sb.append("</table>");
2406            sb.append("\n");
2407            finalCount++;
2408        //}
2409
sb.append("<input type=\"hidden\" name=\"numMultiMediaItems\" value=\"" + finalCount + "\" />");
2410        sb.append("</div>");
2411        
2412        return (sb.toString());
2413    }
2414
2415
2416    /**
2417     * Strips a file extension from a path and returns it
2418     *
2419     *@param path Description of the Parameter
2420     *@return The fileExtension value
2421     */

2422    public static String JavaDoc getFileExtension(String JavaDoc path) {
2423        if ((path != null) && (!path.equals(""))) {
2424            int lastOccur = path.lastIndexOf(".");
2425            if (lastOccur > 0) {
2426                path = path.substring(lastOccur);
2427            }
2428        }
2429        return (path);
2430    }
2431
2432
2433    /**
2434     * Return comboBox of related links
2435     *
2436     *@param db Description of the Parameter
2437     *@return The relatedLinksComboBox value
2438     */

2439    public static String JavaDoc getRelatedLinksComboBox(DataStore db) {
2440        return (getRelatedLinksComboBox(db, ""));
2441    }
2442
2443
2444    /**
2445     * Return comboBox of related links by an itemID
2446     *
2447     *@param db Description of the Parameter
2448     *@param itemID Description of the Parameter
2449     *@return The relatedLinksComboBox value
2450     */

2451
2452    public static String JavaDoc getRelatedLinksComboBox(DataStore db, String JavaDoc itemID) {
2453        HashMap JavaDoc fillReq = new HashMap JavaDoc();
2454        fillReq.put("ITEMID", itemID);
2455        String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getAllRelatedLinksByItemIDOrderByRank");
2456        String JavaDoc toolsPath = CofaxToolsServlet.toolsPath;
2457        List JavaDoc l = new ArrayList JavaDoc();
2458        if ((itemID != null) && (!itemID.equals(""))) {
2459            l = CofaxToolsDbUtils.getPackageData(db, fillReq, tag);
2460        }
2461
2462        StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
2463
2464        int selectSize = l.size() + 1;
2465        HashMap JavaDoc ht = new HashMap JavaDoc();
2466        for (int in = 0; in < selectSize; in++) {
2467            ht.put(String.valueOf(in), String.valueOf(in));
2468        }
2469        int i = 0;
2470        int ii = 0;
2471
2472        for (i = 0; i < l.size(); i++) {
2473            HashMap JavaDoc hm = (HashMap JavaDoc) l.get(i);
2474            String JavaDoc link = (String JavaDoc) hm.get("LINK");
2475            String JavaDoc rank = (String JavaDoc) hm.get("RANK");
2476            String JavaDoc text = (String JavaDoc) hm.get("TEXT");
2477            sb.append("<table class='relatedLinks'>"); //FX : reformatting
2478
sb.append("<tr><th>" + CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"createarticle_link") + "</th><td><INPUT TYPE=TEXT SIZE=20 NAME=\"relatedLink" + i + "\" VALUE=\"" + link + "\"></td></tr>\n");
2479            sb.append("<tr><th>Action</th><td><a target='_blank' HREF='"+link+"'>"+CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"createarticle_link")+"</a>&nbsp;&nbsp;<INPUT TYPE=CHECKBOX NAME=\"deleteRelatedLink" + i + "\" />" + CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"createarticle_delete") + "</td>");
2480            sb.append("<tr><th>" + CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"createarticle_text") + "</th><td><INPUT TYPE=TEXT SIZE=20 NAME=\"relatedLinkText" + i + "\" VALUE=\"" + text + "\"></td></tr>\n");
2481            String JavaDoc select = createSelect("relatedLinkRank" + i, ht, rank);
2482            sb.append("<tr><th>" + CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"createarticle_rank") + "</th><td>" + select + "</td>");
2483            sb.append("</tr></table>\n<hr />\n");
2484        }
2485
2486        for (ii = i; ii < l.size() + 1; ii++) {
2487            sb.append("<table class='createRelatedLinks'>"); //FX : reformatting
2488
sb.append("<tr><th colspan='2'>" + CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"createarticle_addlink") + "</th></tr>");
2489            sb.append("<tr><th>" + CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"createarticle_link") + "</th><td><INPUT TYPE=TEXT SIZE=15 NAME=\"relatedLink" + ii + "\" VALUE=\"\">&nbsp; <a HREF=\"#\" onClick=\"openNewWindow(\'" + toolsPath + "?mode=article_search_article&linkFunction=relate&callingFormPortion=" + ii + "\',\'window2\',\'WIDTH=760, HEIGHT=500 MENUBAR=yes SCROLLBARS=yes RESIZABLE=yes\')\"><IMG border=0 SRC=\"" + CofaxToolsServlet.aliasPath + "/static/images/im_loupe.gif\"></a></td></tr>\n");
2490            sb.append("<tr><th>" + CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"createarticle_text") + "</th><td><INPUT TYPE=TEXT SIZE=15 NAME=\"relatedLinkText" + ii + "\" VALUE=\"\"></td>\n");
2491            String JavaDoc select = createSelect("relatedLinkRank" + ii, ht, String.valueOf(ii));
2492            sb.append("<tr><th>" + CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"createarticle_rank") + "</th><td>" + select + "</td>");
2493            sb.append("</tr></table>\n");
2494        }
2495
2496        sb.append("<INPUT TYPE=HIDDEN NAME=numLinks VALUE=" + ii + ">");
2497        return (sb.toString());
2498    }
2499
2500
2501    /**
2502     * Unpacks a serialized search and returns the correctly selected elements
2503     * to the user.
2504     *
2505     *@param req Description of the Parameter
2506     *@return The searchSelectCombo value
2507     */

2508
2509    public static String JavaDoc getSearchSelectCombo(HttpServletRequest JavaDoc req) {
2510
2511        String JavaDoc from = req.getParameter("from");
2512        String JavaDoc startDatemonthPref = "";
2513        String JavaDoc startDatedayPref = "";
2514        String JavaDoc startDateyearPref = "";
2515        String JavaDoc stopDatemonthPref = "";
2516        String JavaDoc stopDatedayPref = "";
2517        String JavaDoc stopDateyearPref = "";
2518        String JavaDoc publicationsPref = "";
2519        String JavaDoc sectionPref = "";
2520        String JavaDoc mappingPref = "";
2521        String JavaDoc orderByPref = "";
2522        String JavaDoc resultsPref = "";
2523        String JavaDoc field1Pref = "";
2524        String JavaDoc field2Pref = "";
2525        String JavaDoc field3Pref = "";
2526        String JavaDoc condition1Pref = "";
2527        String JavaDoc condition2Pref = "";
2528        String JavaDoc condition3Pref = "";
2529        String JavaDoc fieldtwo1Pref = "";
2530        String JavaDoc fieldtwo2Pref = "";
2531        String JavaDoc fieldtwo3Pref = "";
2532
2533        if ((from != null) && (from.equals("savedSearch"))) {
2534            startDatemonthPref = req.getParameter("startDatemonth");
2535            startDatedayPref = req.getParameter("startDatemday");
2536            startDateyearPref = req.getParameter("startDateyear");
2537            stopDatemonthPref = req.getParameter("stopDatemonth");
2538            stopDatedayPref = req.getParameter("stopDateday");
2539            stopDateyearPref = req.getParameter("stopDateyear");
2540            publicationsPref = req.getParameter("publications");
2541            sectionPref = req.getParameter("SECTION");
2542            mappingPref = req.getParameter("mapping");
2543            orderByPref = req.getParameter("orderBy");
2544            resultsPref = req.getParameter("results");
2545            field1Pref = req.getParameter("field1");
2546            field2Pref = req.getParameter("field2");
2547            field3Pref = req.getParameter("field3");
2548            condition1Pref = req.getParameter("condition1");
2549            condition2Pref = req.getParameter("condition2");
2550            condition3Pref = req.getParameter("condition3");
2551            fieldtwo1Pref = req.getParameter("fieldtwo1");
2552            fieldtwo2Pref = req.getParameter("fieldtwo2");
2553            fieldtwo3Pref = req.getParameter("fieldtwo3");
2554        }
2555
2556        HashMap JavaDoc field = new HashMap JavaDoc();
2557        field.put(getI18NMessage(CofaxToolsServlet.lcl,"search_makeselection"), "");
2558        field.put(getI18NMessage(CofaxToolsServlet.lcl,"createarticle_title"), "HEADLINE");
2559        field.put(getI18NMessage(CofaxToolsServlet.lcl,"createarticle_byline"), "BYLINE");
2560        field.put(getI18NMessage(CofaxToolsServlet.lcl,"createarticle_body"), "BODY");
2561        field.put(getI18NMessage(CofaxToolsServlet.lcl,"createarticle_lead"), "LEAD");
2562        field.put(getI18NMessage(CofaxToolsServlet.lcl,"section"), "SECTIONDESC");
2563        field.put(getI18NMessage(CofaxToolsServlet.lcl,"createarticle_mapping"), "MAPPINGCODE");
2564        field.put("Item ID", "ITEMID");
2565        field.put(getI18NMessage(CofaxToolsServlet.lcl,"createarticle_code"), "FILENAME");
2566
2567        HashMap JavaDoc condition = new HashMap JavaDoc();
2568        condition.put(getI18NMessage(CofaxToolsServlet.lcl,"search_contains"), "LIKE");
2569        condition.put(getI18NMessage(CofaxToolsServlet.lcl,"search_doesnotcontain"), "NOT LIKE");
2570        condition.put(getI18NMessage(CofaxToolsServlet.lcl,"search_is"), "=");
2571        condition.put(getI18NMessage(CofaxToolsServlet.lcl,"search_isnot"), "!=");
2572
2573        HashMap JavaDoc orderBy = new HashMap JavaDoc();
2574        orderBy.put(getI18NMessage(CofaxToolsServlet.lcl,"createarticle_title"), "HEADLINE");
2575        orderBy.put("Pubdate", "PUBDATE");
2576        orderBy.put(getI18NMessage(CofaxToolsServlet.lcl,"publication"), "PUBNAME");
2577        orderBy.put(getI18NMessage(CofaxToolsServlet.lcl,"createarticle_byline"), "BYLINE");
2578        orderBy.put(getI18NMessage(CofaxToolsServlet.lcl,"createarticle_code"), "FILENAME");
2579
2580        HashMap JavaDoc results = new HashMap JavaDoc();
2581        results.put("10", "10");
2582        results.put("25", "25");
2583        results.put("50", "50");
2584        results.put("75", "75");
2585        results.put("100", "100");
2586
2587        String JavaDoc selectOrderBy = "";
2588        if (!orderByPref.equals("")) {
2589            selectOrderBy = createSelect("orderBy", orderBy, orderByPref);
2590        } else {
2591            selectOrderBy = createSelect("orderBy", orderBy, "PUBNAME");
2592        }
2593
2594        String JavaDoc selectResults = "";
2595        if (!resultsPref.equals("")) {
2596            selectResults = createSelect("results", results, resultsPref);
2597        } else {
2598            selectResults = createSelect("results", results, "50");
2599        }
2600
2601        StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
2602        sb.append("<TABLE>");
2603
2604        String JavaDoc conditionSelect1 = "";
2605        if (!condition1Pref.equals("")) {
2606            conditionSelect1 = createSelect("condition1", condition, condition1Pref);
2607        } else {
2608            conditionSelect1 = createSelect("condition1", condition, "LIKE");
2609        }
2610        String JavaDoc fieldSelect1 = "";
2611        if (!field1Pref.equals("")) {
2612            fieldSelect1 = createSelect("field1", field, field1Pref, "onChange = \"bodySearchCheck(\'field1\');\"");
2613        } else {
2614            fieldSelect1 = createSelect("field1", field, "", "onChange = \"bodySearchCheck(\'field1\');\"");
2615        }
2616        sb.append("<TD>" + fieldSelect1 + "</TD>\n");
2617        sb.append("<TD>" + conditionSelect1 + "</TD>\n");
2618
2619        if (!fieldtwo1Pref.equals("")) {
2620            sb.append("<TD><INPUT TYPE=TEXT SIZE=30 MAXLENGTH=50 NAME=fieldtwo1 VALUE=\"" + fieldtwo1Pref + "\">\n");
2621        } else {
2622            sb.append("<TD><INPUT TYPE=TEXT SIZE=30 MAXLENGTH=50 NAME=fieldtwo1>\n");
2623        }
2624        sb.append("<TR>\n");
2625
2626        String JavaDoc conditionSelect2 = "";
2627        if (!condition2Pref.equals("")) {
2628            conditionSelect2 = createSelect("condition2", condition, condition2Pref);
2629        } else {
2630            conditionSelect2 = createSelect("condition2", condition, "LIKE");
2631        }
2632        String JavaDoc fieldSelect2 = "";
2633        if (!field2Pref.equals("")) {
2634            fieldSelect2 = createSelect("field2", field, field2Pref, "onChange = \"bodySearchCheck(\'field2\');\"");
2635        } else {
2636            fieldSelect2 = createSelect("field2", field, "", "onChange = \"bodySearchCheck(\'field2\');\"");
2637        }
2638        sb.append("<TD>" + fieldSelect2 + "</TD>\n");
2639        sb.append("<TD>" + conditionSelect2 + "</TD>\n");
2640
2641        if (!fieldtwo2Pref.equals("")) {
2642            sb.append("<TD><INPUT TYPE=TEXT SIZE=30 MAXLENGTH=50 NAME=fieldtwo2 VALUE=\"" + fieldtwo2Pref + "\">\n");
2643        } else {
2644            sb.append("<TD><INPUT TYPE=TEXT SIZE=30 MAXLENGTH=50 NAME=fieldtwo2>\n");
2645        }
2646        sb.append("<TR>\n");
2647
2648        String JavaDoc conditionSelect3 = "";
2649        if (!condition3Pref.equals("")) {
2650            conditionSelect3 = createSelect("condition3", condition, condition3Pref);
2651        } else {
2652            conditionSelect3 = createSelect("condition3", condition, "LIKE");
2653        }
2654        String JavaDoc fieldSelect3 = "";
2655        if (!(field3Pref).equals("")) {
2656            fieldSelect3 = createSelect("field3", field, field3Pref, "onChange = \"bodySearchCheck(\'field3\');\"");
2657        } else {
2658            fieldSelect3 = createSelect("field3", field, "", "onChange = \"bodySearchCheck(\'field3\');\"");
2659        }
2660        sb.append("<TD>" + fieldSelect3 + "</TD>\n");
2661        sb.append("<TD>" + conditionSelect3 + "</TD>\n");
2662
2663        if (!fieldtwo3Pref.equals("")) {
2664            sb.append("<TD><INPUT TYPE=TEXT SIZE=30 MAXLENGTH=50 NAME=fieldtwo3 VALUE=\"" + fieldtwo3Pref + "\">\n");
2665        } else {
2666            sb.append("<TD><INPUT TYPE=TEXT SIZE=30 MAXLENGTH=50 NAME=fieldtwo3>\n");
2667        }
2668        sb.append("<TR>\n");
2669        
2670        /*
2671        //add the choice of the workflow_state of articles
2672        sb.append("<TR><TD colspan=3>\n");
2673        sb.append("<SELECT NAME=workflow_state>");
2674        sb.append("<OPTION VALUE=3 SELECTED>" + getI18NMessage(CofaxToolsServlet.lcl,"search_makeselection"));
2675        sb.append("<OPTION VALUE=0>" + getI18NMessage(CofaxToolsServlet.lcl,"createarticle_draft"));
2676        sb.append("<OPTION VALUE=1>" + getI18NMessage(CofaxToolsServlet.lcl,"createarticle_inprocessofvalidation"));
2677        sb.append("<OPTION VALUE=2>" + getI18NMessage(CofaxToolsServlet.lcl,"createarticle_published"));
2678        sb.append("</TD></TR>\n");
2679        */

2680        sb.append("<TR>\n");
2681        sb.append("<TD colspan=2><B>" + getI18NMessage(CofaxToolsServlet.lcl,"search_orderby") + ": " + selectOrderBy + "</TD>\n");
2682        sb.append("<TD><B>" + getI18NMessage(CofaxToolsServlet.lcl,"search_show") + ": " + selectResults + "</TD>\n");
2683        sb.append("</TABLE>");
2684
2685        return (sb.toString());
2686    }
2687
2688
2689    /**
2690     * Saves a search for articles (URL string) to the database for later
2691     * access
2692     *
2693     *@param db Description of the Parameter
2694     *@param session Description of the Parameter
2695     *@param req Description of the Parameter
2696     *@return Description of the Return Value
2697     */

2698    public static String JavaDoc saveSearch(DataStore db, HttpSession JavaDoc session, HttpServletRequest JavaDoc req) {
2699        HashMap JavaDoc htTemp = splitPostQuery(req);
2700        CofaxToolsUser user = (CofaxToolsUser) session.getAttribute("user");
2701        String JavaDoc toolsPath = CofaxToolsServlet.toolsPath;
2702        HashMap JavaDoc ht = new HashMap JavaDoc();
2703        String JavaDoc searchName = (String JavaDoc) req.getParameter("SEARCHNAME");
2704        ht.put("SEARCHNAME", searchName);
2705        String JavaDoc userID = (String JavaDoc) user.userInfoHash.get("USERID");
2706        ht.put("USERID", userID);
2707        String JavaDoc search = (String JavaDoc) req.getQueryString();
2708        search = replace(search, "search_save_search", "article_search_for_articles");
2709        search = toolsPath + "?from=savedSearch&" + search;
2710        ht.put("SEARCH", search);
2711        String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "updateSavedSearches");
2712        List JavaDoc list = CofaxToolsDbUtils.getPackageData(db, ht, tag);
2713        return ("Search " + searchName + " saved.");
2714    }
2715
2716
2717    /**
2718     * Returns a user's saved searches from the database
2719     *
2720     *@param db Description of the Parameter
2721     *@param session Description of the Parameter
2722     *@return The selectSavedSearches value
2723     */

2724
2725    public static String JavaDoc getSelectSavedSearches(DataStore db, HttpSession JavaDoc session) {
2726        CofaxToolsUser user = (CofaxToolsUser) session.getAttribute("user");
2727        String JavaDoc userID = (String JavaDoc) user.userInfoHash.get("USERID");
2728        HashMap JavaDoc fillReq = new HashMap JavaDoc();
2729        fillReq.put("USERID", userID);
2730        String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getSavedSearchesByUserID");
2731        HashMap JavaDoc ht = CofaxToolsDbUtils.getValueValuePackageHash(db, fillReq, tag, "SEARCHNAME", "SEARCH");
2732        ht.put(CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"search_savedsearches"), "");
2733        String JavaDoc select = createSelect("savedSearches", ht, "", "onChange=\"skipTo();\"");
2734        return (select);
2735    }
2736
2737
2738    /**
2739     * Replicates CofaxToolsServlet init function so server does not have to be
2740     * restarted on change of config file.
2741     *
2742     *@param db Description of the Parameter
2743     *@return Description of the Return Value
2744     */

2745    public static boolean resetServlet(DataStore db) {
2746
2747        CofaxToolsServlet.dataStore.clearCache(DataStore.PACKAGE_TAG_RESULTS);
2748        CofaxToolsServlet.dataStore.setCache(CofaxToolsDbUtils.getValueValuePackageHash(db, "select tag_name, tag_value from cofax.tbltoolspackagetags", "TAG_NAME", "TAG_VALUE", true), DataStore.PACKAGE_TAG_PROCESSED);
2749        CofaxToolsServlet.dataStore.setCache(CofaxToolsDbUtils.getValueValuePackageHash(db, "select tag_value, cache from cofax.tbltoolspackagetags", "TAG_VALUE", "CACHE", true), DataStore.PACKAGE_TAG_CACHE_COMMAND);
2750
2751        return (true);
2752    }
2753
2754
2755    /**
2756     * Splits an url into section, date, publication, fileName and returns a
2757     * HashMap of values.
2758     *
2759     *@param url Description of the Parameter
2760     *@return The cofaxUrlParameters value
2761     */

2762    public static HashMap JavaDoc getCofaxUrlParameters(String JavaDoc url) {
2763        String JavaDoc pub = "";
2764        String JavaDoc date = "";
2765        String JavaDoc section = "";
2766        String JavaDoc fileNameWithExtension = "";
2767        String JavaDoc fileName = "";
2768        boolean gotDate = false;
2769        int datePartCount = 0;
2770        String JavaDoc fileNameExtension = "";
2771        HashMap JavaDoc ht = new HashMap JavaDoc();
2772        ht.put("SECTION", "");
2773        ht.put("PUBNAME", "");
2774        ht.put("FILENAME", "");
2775        ht.put("PUBDATE", "");
2776
2777        int pos = url.indexOf("" + CofaxToolsServlet.aliasPath + "/");
2778        url = url.substring(pos + 1);
2779
2780        // Split pathInfo by '/' to parse variables from it.
2781
int count = 0;
2782
2783        Iterator JavaDoc paths = CofaxUtil.split("/", url).iterator();
2784        while (paths.hasNext()) {
2785            // Get the piece of the path to parse
2786
String JavaDoc path = (String JavaDoc) paths.next();
2787            count++;
2788            // If in position 2, get the publication name
2789
if (count == 2) {
2790                if ((path.indexOf('.') > -1)) {
2791                    // If we find a '.' then we have a file name
2792
fileNameWithExtension = path;
2793                } else {
2794                    pub = path;
2795                }
2796            }
2797
2798            if (CofaxUtil.isDigits(path)) {
2799                datePartCount++;
2800                if (datePartCount == 1) {
2801                    date = path;
2802                } else {
2803                    date = date + "/" + path;
2804                }
2805                if (datePartCount == 3) {
2806                    gotDate = true;
2807                }
2808                continue;
2809            }
2810            datePartCount = 0;
2811
2812            // If the path piece is in a position higher than two, and
2813
// we have passed or escaped the date parse,
2814
// get a filename or a section.
2815
// TODO: Test for forwarding codes....
2816
if (count >= 3) {
2817                if ((path.indexOf('.') > -1)) {
2818                    // If we find a '.' then we have a file name
2819
fileNameWithExtension = path;
2820                } else {
2821                    // If we don't find a '.' then we have a section
2822
if (section.equals("")) {
2823                        section = path;
2824                    } else {
2825                        section = section + "/" + path;
2826                    }
2827                }
2828            }
2829        }
2830
2831        // If the path parsing assembled a section, then add this
2832

2833        ht.put("SECTION", section);
2834        ht.put("PUBNAME", pub);
2835
2836        // Removing the .htm extension from the fileName.
2837
// This is used extensively as a SLUG.
2838
int dotLoc = fileNameWithExtension.lastIndexOf('.');
2839        if (dotLoc > -1) {
2840            fileName = fileNameWithExtension.substring(0, dotLoc);
2841        }
2842        ht.put("FILENAME", fileName);
2843        ht.put("PUBDATE", date);
2844        return (ht);
2845    }
2846
2847
2848    /**
2849     * Returns a mapping code when given a hash of section name and pubname.
2850     *
2851     *@param db Description of the Parameter
2852     *@param ht Description of the Parameter
2853     *@return The mappingCodeBySectionPublication value
2854     */

2855    public static String JavaDoc getMappingCodeBySectionPublication(DataStore db, HashMap JavaDoc ht) {
2856
2857        String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getMapCodeFromtblsectionsBySectionNameAndPubName");
2858        HashMap JavaDoc results = CofaxToolsDbUtils.getNameValuePackageHash(db, ht, tag);
2859        String JavaDoc mappingCode = (String JavaDoc) results.get("MAPPINGCODE");
2860        return (mappingCode);
2861    }
2862
2863
2864    /**
2865     * Returns an itemid when given a hash of section name and section date.
2866     *
2867     *@param db Description of the Parameter
2868     *@param ht Description of the Parameter
2869     *@return The itemIDFromNameSectionDate value
2870     */

2871    public static String JavaDoc getItemIDFromNameSectionDate(DataStore db, HashMap JavaDoc ht) {
2872        String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getSectionFromtblsectionsByPublicationSectionName");
2873        HashMap JavaDoc htTemp = CofaxToolsDbUtils.getNameValuePackageHash(db, ht, tag);
2874        String JavaDoc section = (String JavaDoc) htTemp.get("SECTION");
2875        ht.put("SECTION", section);
2876
2877        tag = CofaxToolsDbUtils.fillTag(db, "getItemIDFromNameSectionDate");
2878        HashMap JavaDoc results = CofaxToolsDbUtils.getNameValuePackageHash(db, ht, tag);
2879        String JavaDoc itemID = (String JavaDoc) results.get("ITEMID");
2880        return (itemID);
2881    }
2882
2883
2884    /**
2885     * Duplicates String indexOf() functionality but is case insensitive.
2886     *
2887     *@param mainText Description of the Parameter
2888     *@param index Description of the Parameter
2889     *@return Description of the Return Value
2890     */

2891    public static int caseInsensitiveIndexOf(String JavaDoc mainText, String JavaDoc index) {
2892        int stLen = index.length();
2893        int stLenTest = 0;
2894        int indexIterator = 0;
2895        char indexChar[] = index.toCharArray();
2896        char mainTextChar[] = mainText.toCharArray();
2897        for (int i = 0; i < mainTextChar.length; i++) {
2898            char mainTextTest = mainTextChar[i];
2899            char indexTest = indexChar[indexIterator];
2900            String JavaDoc s1 = String.valueOf(mainTextTest).toLowerCase();
2901            String JavaDoc s2 = String.valueOf(indexTest).toLowerCase();
2902            if (s1.equals(s2)) {
2903                stLenTest++;
2904                indexIterator++;
2905                if (stLenTest == stLen) {
2906                    return (i - stLen + 1);
2907                }
2908            } else {
2909                stLenTest = 0;
2910                indexIterator = 0;
2911            }
2912        }
2913        return (-1);
2914    }
2915
2916
2917    /**
2918     * Check to see that the file transfer folder is set correctly
2919     *
2920     *@param path Description of the Parameter
2921     *@return Description of the Return Value
2922     */

2923    public static boolean checkFileTransferFolder(String JavaDoc path) {
2924        boolean check = false;
2925        File JavaDoc file = new File JavaDoc(path);
2926        if (file.isDirectory()) {
2927            check = true;
2928        }
2929        return (check);
2930    }
2931
2932
2933    /**
2934     * Returns a select with params for how many results a user desires to see.
2935     *
2936     *@param selected Description of the Parameter
2937     *@return The selectOrderSectionResults value
2938     */

2939
2940    public static String JavaDoc getSelectOrderSectionResults(String JavaDoc selected) {
2941        HashMap JavaDoc hp = new HashMap JavaDoc();
2942        hp.put("10", "10");
2943        hp.put("25", "25");
2944        hp.put("50", "50");
2945        hp.put("75", "75");
2946        return (createSelect("results", hp, selected));
2947    }
2948
2949
2950    /*
2951     * Returns a select combo of hour, minute, second, am/pm with params selected
2952     *
2953     */

2954    /**
2955     * Gets the selectTime attribute of the CofaxToolsUtil class
2956     *
2957     *@param name Description of the Parameter
2958     *@param hour Description of the Parameter
2959     *@param minute Description of the Parameter
2960     *@param second Description of the Parameter
2961     *@param amPm Description of the Parameter
2962     *@return The selectTime value
2963     */

2964    public static String JavaDoc getSelectTime(String JavaDoc name, int hour, int minute, int second, String JavaDoc amPm) {
2965        StringBuffer JavaDoc results = new StringBuffer JavaDoc();
2966        HashMap JavaDoc hp = new HashMap JavaDoc();
2967
2968        // make the hour select
2969
for (int i = 1; i <= 12; i++) {
2970            String JavaDoc min = String.valueOf(i);
2971            if (min.length() == 1) {
2972                min = "0" + min;
2973            }
2974            hp.put(min, min);
2975        }
2976        results.append(createSelect(name + "Hour", hp, String.valueOf(hour)));
2977        hp.clear();
2978
2979        // make the minute select
2980
for (int i = 1; i <= 60; i++) {
2981            String JavaDoc min = String.valueOf(i);
2982            if (min.length() == 1) {
2983                min = "0" + min;
2984            }
2985            hp.put(min, min);
2986        }
2987        results.append(createSelect(name + "Minute", hp, String.valueOf(minute)));
2988        hp.clear();
2989
2990        // make the seconds select
2991
for (int i = 1; i <= 60; i++) {
2992            String JavaDoc min = String.valueOf(i);
2993            if (min.length() == 1) {
2994                min = "0" + min;
2995            }
2996            hp.put(min, min);
2997        }
2998        results.append(createSelect(name + "Second", hp, String.valueOf(second)));
2999        hp.clear();
3000
3001        // make the AM/ PM select
3002
hp.put("AM", "AM");
3003        hp.put("PM", "PM");
3004        results.append(createSelect(name + "AmPm", hp, (String JavaDoc) amPm));
3005        hp.clear();
3006
3007        return (results.toString());
3008    }
3009
3010
3011
3012    /**
3013     * Returns a hash of all mappings from all publications a user is grouped
3014     * to.
3015     *
3016     *@param db Description of the Parameter
3017     *@param label Description of the Parameter
3018     *@param session Description of the Parameter
3019     *@return The selectMappingsMultiplePublicationsArrayList value
3020     */

3021    public static List JavaDoc getSelectMappingsMultiplePublicationsArrayList(DataStore db, String JavaDoc label, HttpSession JavaDoc session) {
3022
3023        CofaxToolsUser user = (CofaxToolsUser) session.getAttribute("user");
3024        HashMap JavaDoc userPubNamePubIDHash = new HashMap JavaDoc();
3025        userPubNamePubIDHash.putAll(user.userPubNamePubIDHash);
3026
3027        String JavaDoc wkPub = user.workingPubName;
3028        List JavaDoc al = new ArrayList JavaDoc();
3029        // put the label into the arraylist
3030
HashMap JavaDoc tempLabel = new HashMap JavaDoc();
3031        tempLabel.put(label, "");
3032        al.add(tempLabel);
3033
3034        // remove the working pub from the hash
3035
userPubNamePubIDHash.remove(wkPub);
3036        HashMap JavaDoc wkFillReq = new HashMap JavaDoc();
3037        wkFillReq.put("PUBNAME", wkPub);
3038        wkFillReq.put("currentUserID", (String JavaDoc) user.userInfoHash.get("USERID"));
3039        // get the sections for the working pub and put them into an arraylist
3040
String JavaDoc wkTag = CofaxToolsDbUtils.fillTag(db, "getSectionDescAndMapCodeFromSectionsByPubName");
3041        HashMap JavaDoc wkHt = CofaxToolsDbUtils.getValueValuePackageHash(db, wkFillReq, wkTag, "SECTIONDESC", "MAPPINGCODE");
3042        SortedMap JavaDoc wkSortedMap = new TreeMap JavaDoc();
3043        wkSortedMap.putAll(wkHt);
3044        Set JavaDoc wkset = wkSortedMap.keySet();
3045        Iterator JavaDoc wkIterator = wkset.iterator();
3046        while (wkIterator.hasNext()) {
3047            String JavaDoc wkName = (String JavaDoc) wkIterator.next();
3048            String JavaDoc wkID = (String JavaDoc) wkSortedMap.get(wkName);
3049            HashMap JavaDoc wkTemp = new HashMap JavaDoc();
3050            wkTemp.put(wkName, wkID);
3051            al.add(wkTemp);
3052        }
3053
3054        // get the sections for the non working pub and put them into an arraylist
3055
Iterator JavaDoc en = userPubNamePubIDHash.keySet().iterator();
3056        HashMap JavaDoc htSelect = new HashMap JavaDoc();
3057        while (en.hasNext()) {
3058            String JavaDoc pubName = (String JavaDoc) en.next();
3059            HashMap JavaDoc fillReq = new HashMap JavaDoc();
3060            fillReq.put("PUBNAME", pubName);
3061            fillReq.put("currentUserID", (String JavaDoc) user.userInfoHash.get("USERID"));
3062            String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getSectionDescAndMapCodeFromSectionsByPubName");
3063            HashMap JavaDoc ht = CofaxToolsDbUtils.getValueValuePackageHash(db, fillReq, tag, "SECTIONDESC", "MAPPINGCODE");
3064            Iterator JavaDoc enSel = ht.keySet().iterator();
3065            while (enSel.hasNext()) {
3066                String JavaDoc section = (String JavaDoc) enSel.next();
3067                String JavaDoc sectionDesc = (String JavaDoc) ht.get(section);
3068                htSelect.put(pubName + ": " + section, sectionDesc);
3069            }
3070        }
3071        SortedMap JavaDoc sortedMap = new TreeMap JavaDoc();
3072        sortedMap.putAll(htSelect);
3073        Set JavaDoc set = sortedMap.keySet();
3074        Iterator JavaDoc iterator = set.iterator();
3075        while (iterator.hasNext()) {
3076            String JavaDoc name = (String JavaDoc) iterator.next();
3077            String JavaDoc ID = (String JavaDoc) sortedMap.get(name);
3078            HashMap JavaDoc temp = new HashMap JavaDoc();
3079            temp.put(name, ID);
3080            al.add(temp);
3081        }
3082        return (al);
3083    }
3084
3085
3086    /**
3087     * Returns an html select bar given a name and a HashMap of values.
3088     *
3089     *@param selectName Description of the Parameter
3090     *@param nameValue Description of the Parameter
3091     *@return Description of the Return Value
3092     */

3093    public static String JavaDoc createSelect(String JavaDoc selectName, ArrayList JavaDoc nameValue) {
3094        String JavaDoc sb = createSelect(selectName, nameValue, "");
3095        return (sb);
3096    }
3097
3098
3099    /**
3100     * Returns an html select bar given a name and a HashMap of values.&nbsp;
3101     * Parameter selected will be marked as selected in the bar.
3102     *
3103     *@param selectName Description of the Parameter
3104     *@param nameValue Description of the Parameter
3105     *@param selected Description of the Parameter
3106     *@return Description of the Return Value
3107     */

3108    public static String JavaDoc createSelect(String JavaDoc selectName, ArrayList JavaDoc nameValue, String JavaDoc selected) {
3109        String JavaDoc sb = createSelect(selectName, nameValue, selected, "");
3110        return (sb);
3111    }
3112
3113
3114    /**
3115     * Returns an html select bar given a name and a HashMap of values.&nbsp;
3116     * Parameter selected will be marked as selected in the bar.&nbsp;
3117     * Parameter javascript will be placed in the SELECT tag for onChange, etc.
3118     *
3119     *@param selectName Description of the Parameter
3120     *@param nameValue Description of the Parameter
3121     *@param selected Description of the Parameter
3122     *@param javaScript Description of the Parameter
3123     *@return Description of the Return Value
3124     */

3125    public static String JavaDoc createSelect(String JavaDoc selectName, ArrayList JavaDoc nameValue, String JavaDoc selected, String JavaDoc javaScript) {
3126
3127        StringBuffer JavaDoc s = new StringBuffer JavaDoc();
3128        // add the values to an html select statement
3129
try {
3130            Iterator JavaDoc iterator = nameValue.iterator();
3131            s.append("\n\n<SELECT NAME =\"" + selectName + "\" " + javaScript + ">\n");
3132            String JavaDoc i = "";
3133
3134            while (iterator.hasNext()) {
3135                HashMap JavaDoc h = (HashMap JavaDoc) iterator.next();
3136                Iterator JavaDoc it = h.keySet().iterator();
3137                while (it.hasNext()) {
3138                    String JavaDoc key = (String JavaDoc) it.next();
3139                    String JavaDoc value = (String JavaDoc) h.get(key);
3140                    if (value == selected || value.equals(selected)) {
3141                        i = " selected";
3142                    } else {
3143                        i = "";
3144                    }
3145                    s.append("<OPTION VALUE=\"" + value + "\"" + i + ">" + key + "\n");
3146                }
3147            }
3148            s.append("\n</SELECT>\n\n");
3149        } catch (ArrayIndexOutOfBoundsException JavaDoc e) {
3150            log("CofaxToolsUtil createSelect ERROR: " + e.toString());
3151        } finally {
3152            
3153        }
3154        return (s.toString());
3155    }
3156
3157
3158    /*
3159     * Returns a select with parameters to show how many preorders a customer wants to use on order section.
3160     *
3161     */

3162    /**
3163     * Description of the Method
3164     *
3165     *@param label Description of the Parameter
3166     *@param selected Description of the Parameter
3167     *@return Description of the Return Value
3168     */

3169    public static String JavaDoc createShowPreOrderSelect(String JavaDoc label, String JavaDoc selected) {
3170        HashMap JavaDoc ht = new HashMap JavaDoc();
3171        ht.put("00", "00");
3172        ht.put("05", "05");
3173        ht.put("10", "10");
3174        ht.put("15", "15");
3175        ht.put("20", "20");
3176        ht.put("25", "25");
3177        String JavaDoc select = createSelect(label, ht, selected);
3178        return (select);
3179    }
3180
3181
3182   /**
3183     * Returns a select for sections allowed.
3184     *
3185     *@return The select sections
3186     */

3187
3188    public static String JavaDoc getSelectSections(DataStore db, String JavaDoc userID, String JavaDoc pubName, String JavaDoc sectionMappingCode) {
3189        StringBuffer JavaDoc selectSections = new StringBuffer JavaDoc("");
3190        try {
3191            if ((userID!=null) && !(userID.equals(""))) {
3192                selectSections.append("<SELECT NAME='sectionMappingCode'>");
3193                selectSections.append("<OPTION VALUE='' selected>** " + CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"tools_selectmappingsection") + " **");
3194                String JavaDoc tag = "select S.*, manager from tblsections AS S LEFT JOIN tblpermusersection AS PUS ";
3195                tag = tag + "on (S.mappingCode=PUS.mappingCode and PUS.userID=" + userID + ") ";
3196                tag = tag + "where S.pubName='" + pubName + "' and S.subMapOf=0 ";
3197                tag = tag + "order by rank ";
3198                HashMap JavaDoc htTmp = new HashMap JavaDoc();
3199                List JavaDoc lstSections = CofaxToolsDbUtils.getPackageData(db, htTmp, tag);
3200                if (lstSections.size() <= 0) {
3201                    selectSections.append("<OPTION value=''>" + CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"tools_nosection"));
3202                }
3203                while (lstSections.size() > 0) {
3204                    StringBuffer JavaDoc sbTemp = new StringBuffer JavaDoc();
3205                    HashMap JavaDoc hashInfo = (HashMap JavaDoc) lstSections.get(0);
3206                    String JavaDoc mappingCode = (String JavaDoc) hashInfo.get("MAPPINGCODE");
3207                    String JavaDoc sectionDesc = (String JavaDoc) hashInfo.get("SECTIONDESC");
3208                    String JavaDoc manager = (String JavaDoc) hashInfo.get("MANAGER");
3209                    if (manager==null) manager="0";
3210                    if (manager.equals("1")) {
3211                        if (mappingCode.equals(sectionMappingCode)) {
3212                            selectSections.append("<OPTION SELECTED VALUE='" + mappingCode + "'>" + sectionDesc + "\n");
3213                        } else {
3214                            selectSections.append("<OPTION VALUE='" + mappingCode + "'>" + sectionDesc + "\n");
3215                        }
3216                    }
3217                    String JavaDoc blanks = "+--";
3218                    selectSections.append(getSelectSubSections(db, userID, pubName, mappingCode, blanks, sectionMappingCode));
3219                    lstSections.remove(0);
3220                }
3221                selectSections.append("</SECTION>");
3222            }
3223        } catch (Exception JavaDoc e) {return "";}
3224        return (selectSections.toString());
3225    }
3226
3227    public static String JavaDoc getSelectSubSections(DataStore db, String JavaDoc userID, String JavaDoc pubName, String JavaDoc sectionMappingCode, String JavaDoc blanks, String JavaDoc selected) {
3228        StringBuffer JavaDoc selectSubSections = new StringBuffer JavaDoc("");
3229        try {
3230            String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getListSubSection");
3231            HashMap JavaDoc htTmp = new HashMap JavaDoc();
3232            htTmp.put("userID",userID);
3233            htTmp.put("sectionMappingCode",sectionMappingCode);
3234            htTmp.put("pubName",pubName);
3235            List JavaDoc lstUsers = CofaxToolsDbUtils.getPackageData(db, htTmp, tag);
3236            List JavaDoc lstSections2 = CofaxToolsDbUtils.getPackageData(db, htTmp, tag);
3237            while (lstSections2.size() > 0) {
3238                StringBuffer JavaDoc sbTemp2 = new StringBuffer JavaDoc();
3239                HashMap JavaDoc hashInfo2 = (HashMap JavaDoc) lstSections2.get(0);
3240                String JavaDoc mappingCode2 = (String JavaDoc) hashInfo2.get("MAPPINGCODE");
3241                String JavaDoc sectionDesc2 = (String JavaDoc) hashInfo2.get("SECTIONDESC");
3242                String JavaDoc manager2 = (String JavaDoc) hashInfo2.get("MANAGER");
3243                if (manager2==null) manager2="0";
3244                if (manager2.equals("1")) {
3245                    if (mappingCode2.equals(selected)) {
3246                        selectSubSections.append("<OPTION SELECTED VALUE='" + mappingCode2 + "'>" + blanks + sectionDesc2 + "\n");
3247                    } else {
3248                        selectSubSections.append("<OPTION VALUE='" + mappingCode2 + "'>" + blanks + sectionDesc2 + "\n");
3249                    }
3250                }
3251                //check if there are sub sections
3252
String JavaDoc tag3 = CofaxToolsDbUtils.fillTag(db, "getListSubSection");
3253                HashMap JavaDoc htTmp3 = new HashMap JavaDoc();
3254                htTmp3.put("userID",userID);
3255                htTmp3.put("sectionMappingCode",mappingCode2);
3256                htTmp3.put("pubName",pubName);
3257                List JavaDoc lstSections3 = CofaxToolsDbUtils.getPackageData(db, htTmp3, tag3);
3258                if (lstSections3.size() > 0) {
3259                    String JavaDoc blanks2 = "&nbsp;&nbsp;&nbsp;" + blanks;
3260                    selectSubSections.append(getSelectSubSections(db, userID, pubName, mappingCode2, blanks2, selected));
3261                }
3262                lstSections2.remove(0);
3263            }
3264        } catch (Exception JavaDoc e) {return "";}
3265        return (selectSubSections.toString());
3266    }
3267
3268
3269
3270    /**
3271     * Returns the list of managers or redactors of the section.
3272     *
3273     */

3274
3275    public static String JavaDoc getsectionManagerTable(DataStore db, int manager, String JavaDoc sectionMappingCode, boolean isAdministrator, String JavaDoc limit) {
3276        StringBuffer JavaDoc sectionManagerTable = new StringBuffer JavaDoc("");
3277        try {
3278            if ((sectionMappingCode!=null) && !(sectionMappingCode.equals(""))) {
3279                String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getListManagerSection");
3280                HashMap JavaDoc htTmp = new HashMap JavaDoc();
3281                htTmp.put("sectionMappingCode",sectionMappingCode);
3282                htTmp.put("manager",manager + "");
3283                List JavaDoc lstUsers = CofaxToolsDbUtils.getPackageData(db, htTmp, tag);
3284                if (lstUsers.size() <= 0) {
3285                    if (manager==1) sectionManagerTable.append(CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"tools_nomanager") + "<br>\n");
3286                    else sectionManagerTable.append(CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"tools_noredactor") + "<br>\n");
3287                }
3288                int i=0;
3289                int numrows = CofaxToolsServlet.numrows;
3290                if (limit.equals("no")) numrows=0;
3291                while ((lstUsers.size() > 0) && ((i<numrows)||(numrows==0))) {
3292                    StringBuffer JavaDoc sbTemp = new StringBuffer JavaDoc();
3293                    HashMap JavaDoc hashInfo = (HashMap JavaDoc) lstUsers.get(0);
3294                    String JavaDoc userID = (String JavaDoc) hashInfo.get("USERID");
3295                    String JavaDoc userName = (String JavaDoc) hashInfo.get("USERNAME");
3296                    if (isAdministrator) {
3297                        sectionManagerTable.append("&gt;&nbsp;<a HREF='?mode=admin_get_user_info&selectUser=" + userID + "'>" + userName + "</a>");
3298                        sectionManagerTable.append("&nbsp;(<a HREF='?mode=section_add_user&USERS=" + userID + "&sectionMappingCode=" + sectionMappingCode + "&DIRECTOR=" + manager + "&DELETE=1' alt='Delete'>x</a>)<br>\n");
3299                    } else {
3300                        sectionManagerTable.append("&gt;&nbsp;" + userName + "<br>\n");
3301                    }
3302                    lstUsers.remove(0);
3303                    i++;
3304                }
3305                if ((i>=numrows) && (numrows==CofaxToolsServlet.numrows)) {
3306                    sectionManagerTable.append("&gt;&gt;&nbsp;<a HREF='?mode=section_get_section&sectionMappingCode=" + sectionMappingCode + "&ht=section_edit_section&limitUser=no'>" + CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"createsection_moreusers")+"</a>");
3307                }
3308            }
3309        } catch (Exception JavaDoc e) {return("");}
3310
3311        return (sectionManagerTable.toString());
3312    }
3313
3314
3315    /**
3316     * Returns the list of users that are not redactors of the section.
3317     *
3318     */

3319
3320    public static String JavaDoc getSectionOtherUsersTable(DataStore db, int manager, String JavaDoc sectionMappingCode, String JavaDoc limit) {
3321        StringBuffer JavaDoc sectionOtherUsersTable = new StringBuffer JavaDoc("");
3322        try {
3323            if ((sectionMappingCode!=null) && !(sectionMappingCode.equals(""))) {
3324                String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getOtherUsersOnSection");
3325                HashMap JavaDoc htTmp = new HashMap JavaDoc();
3326                htTmp.put("sectionMappingCode",sectionMappingCode);
3327                htTmp.put("manager",manager + "");
3328                List JavaDoc lstUsers = CofaxToolsDbUtils.getPackageData(db, htTmp, tag);
3329                if (lstUsers.size() <= 0) {
3330                    sectionOtherUsersTable.append(CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"tools_nootheruser") + "<br>\n");
3331                } else {
3332                    int i=0;
3333                    int numrows = CofaxToolsServlet.numrows;
3334                    if (limit.equals("no")) numrows=0;
3335                    sectionOtherUsersTable.append("<SELECT NAME=USERS>\n");
3336                    while ((lstUsers.size() > 0) && ((i<numrows)||(numrows==0))) {
3337                        StringBuffer JavaDoc sbTemp = new StringBuffer JavaDoc();
3338                        HashMap JavaDoc hashInfo = (HashMap JavaDoc) lstUsers.get(0);
3339                        String JavaDoc userID = (String JavaDoc) hashInfo.get("USERID");
3340                        String JavaDoc userName = (String JavaDoc) hashInfo.get("USERNAME");
3341                        String JavaDoc director = (String JavaDoc) hashInfo.get("MANAGER");
3342                        if ((director==null) || ((director.equals("")))) {
3343                            sectionOtherUsersTable.append("<OPTION VALUE='" + userID + "'>" + userName + "\n");
3344                            i++;
3345                        }
3346                        lstUsers.remove(0);
3347                    }
3348                    sectionOtherUsersTable.append("</SELECT>\n");
3349                    if ((i>=numrows) && (numrows==CofaxToolsServlet.numrows)) {
3350                        sectionOtherUsersTable.append("&nbsp;(<a alt='" + CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"createsection_moreusers") + "' HREF='?mode=section_get_section&sectionMappingCode=" + sectionMappingCode + "&ht=section_edit_section&limitUser=no'>+</a>)");
3351                    }
3352                }
3353            }
3354        } catch (Exception JavaDoc e) {
3355            return(CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"tools_anerroroccured"));
3356        }
3357        return (sectionOtherUsersTable.toString());
3358    }
3359
3360
3361
3362
3363
3364    /**
3365     * Returns the list of last modified articles by the current user
3366     *
3367     */

3368
3369    public static String JavaDoc getMyLastArticles(DataStore db, String JavaDoc pubname, String JavaDoc userID) {
3370        StringBuffer JavaDoc listMyLastArticles = new StringBuffer JavaDoc("");
3371        try {
3372            if ((userID!=null) && !(userID.equals(""))) {
3373                String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getMyLastArticles");
3374                HashMap JavaDoc htTmp = new HashMap JavaDoc();
3375                htTmp.put("pubname",pubname);
3376                htTmp.put("userID",userID);
3377                List JavaDoc lstUsers = CofaxToolsDbUtils.getPackageData(db, htTmp, tag);
3378                if (lstUsers.size() <= 0) {
3379                    listMyLastArticles.append(CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"myaccount_noarticle") + "<br>\n");
3380                }
3381                listMyLastArticles.append("<table class='mylastarticles'>"); // fx : reformatting
3382
while (lstUsers.size() > 0) {
3383                    StringBuffer JavaDoc sbTemp = new StringBuffer JavaDoc();
3384                    HashMap JavaDoc hashInfo = (HashMap JavaDoc) lstUsers.get(0);
3385                    String JavaDoc itemID = (String JavaDoc) hashInfo.get("ITEMID");
3386                    String JavaDoc headline = (String JavaDoc) hashInfo.get("HEADLINE");
3387                    String JavaDoc updateDate = (String JavaDoc) hashInfo.get("UPDATEDATE");
3388                    String JavaDoc validated = (String JavaDoc) hashInfo.get("WORKFLOW_STATE");
3389                    String JavaDoc state="";
3390                    
3391                    
3392                    listMyLastArticles.append("<tr>");
3393                    
3394                    // fx : reformatting
3395
if (validated.equals("0")) state="<span class='draft'>" + getI18NMessage(CofaxToolsServlet.lcl,"createarticle_draft") + "</span>";
3396                    else if (validated.equals("1")) state="<span class='in_validation'>" + getI18NMessage(CofaxToolsServlet.lcl,"createarticle_inprocessofvalidation") + "</span>";
3397                    else if (validated.equals("2")) state="<span class='published'>" + getI18NMessage(CofaxToolsServlet.lcl,"createarticle_published") + "</span>";
3398                    listMyLastArticles.append("<td><a HREF='?mode=article_edit_article_by_itemID&ITEMID=" + itemID + "&hl=article_create_article'>" + headline + "</a></td><td>" + updateDate + "</td><td>" + state + "</td>");
3399                    lstUsers.remove(0);
3400                    sbTemp.append("</tr>");
3401                }
3402                listMyLastArticles.append("</table>");
3403            }
3404        } catch (Exception JavaDoc e) {listMyLastArticles.append(CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"tools_anerroroccured"));}
3405        return (listMyLastArticles.toString());
3406    }
3407
3408    /**
3409     * Returns the list of last modified articles by the current user
3410     *
3411     */

3412
3413    public static String JavaDoc getMySavedSearches(DataStore db, String JavaDoc userID) {
3414        StringBuffer JavaDoc listMySavedSearches = new StringBuffer JavaDoc("");
3415        try {
3416            if ((userID!=null) && !(userID.equals(""))) {
3417                String JavaDoc tag = "select * from tblpermsavedsearches ";
3418                tag = tag + "where userID=" + userID + " ";
3419                tag = tag + "order by searchName";
3420                HashMap JavaDoc htTmp = new HashMap JavaDoc();
3421                List JavaDoc lstUsers = CofaxToolsDbUtils.getPackageData(db, htTmp, tag);
3422                if (lstUsers.size() <= 0) {
3423                    listMySavedSearches.append(CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"no_recorded_searches"));
3424                }
3425                while (lstUsers.size() > 0) {
3426                    StringBuffer JavaDoc sbTemp = new StringBuffer JavaDoc();
3427                    HashMap JavaDoc hashInfo = (HashMap JavaDoc) lstUsers.get(0);
3428                    String JavaDoc search = (String JavaDoc) hashInfo.get("SEARCH");
3429                    String JavaDoc searchName = (String JavaDoc) hashInfo.get("SEARCHNAME");
3430                    listMySavedSearches.append("&gt;&nbsp;");
3431                    listMySavedSearches.append("<a alt='delete' HREF='?mode=article_search_delete&SEARCHNAME=" + searchName + "&USERID="+ userID + "'>(x)</a>&nbsp;");
3432                    listMySavedSearches.append("<a HREF='" + search + "'>" + searchName + "</a>&nbsp;");
3433                    listMySavedSearches.append("<br>");
3434                    lstUsers.remove(0);
3435                }
3436            }
3437        } catch (Exception JavaDoc e) {listMySavedSearches.append(CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"tools_anerroroccured"));}
3438        return (listMySavedSearches.toString());
3439    }
3440
3441
3442    /**
3443     * Returns the list of last modified articles by the current user
3444     *
3445     */

3446
3447    public static String JavaDoc getArticlesToPublish(DataStore db, String JavaDoc pubName, String JavaDoc userID) {
3448        StringBuffer JavaDoc listArticlesToPublish = new StringBuffer JavaDoc("");
3449        try {
3450            if ((userID!=null) && !(userID.equals(""))) {
3451                String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getArticlesToPublish");
3452                HashMap JavaDoc htTmp = new HashMap JavaDoc();
3453                htTmp.put("pubName",pubName);
3454                htTmp.put("userID",userID);
3455                List JavaDoc lstUsers = CofaxToolsDbUtils.getPackageData(db, htTmp, tag);
3456            
3457                if (lstUsers.size() <= 0) {
3458                    listArticlesToPublish.append(CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"myaccount_noarticle") + "<br>\n");
3459                }
3460                while (lstUsers.size() > 0) {
3461                    StringBuffer JavaDoc sbTemp = new StringBuffer JavaDoc();
3462                    HashMap JavaDoc hashInfo = (HashMap JavaDoc) lstUsers.get(0);
3463                    String JavaDoc headline = (String JavaDoc) hashInfo.get("HEADLINE");
3464                    String JavaDoc filename = (String JavaDoc) hashInfo.get("FILENAME");
3465                    String JavaDoc itemID = (String JavaDoc) hashInfo.get("ITEMID");
3466                    listArticlesToPublish.append("&gt;&nbsp;");
3467                    listArticlesToPublish.append("<a HREF='?mode=article_edit_article_by_itemID&ITEMID=" + itemID + "&hl=article_create_article'>" + filename + "</a>&nbsp;<i><font color='#C1C307'>" + getI18NMessage(CofaxToolsServlet.lcl,"createarticle_inprocessofvalidation") + ".</i></font>");
3468                    listArticlesToPublish.append("<br>");
3469                    lstUsers.remove(0);
3470                }
3471            }
3472        } catch (Exception JavaDoc e) {listArticlesToPublish.append(CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"tools_anerroroccured"));}
3473        return (listArticlesToPublish.toString());
3474    }
3475
3476
3477
3478
3479    /**
3480     * Returns a checkbox table for security access to sections.
3481     *
3482     *@param db Description of the Parameter
3483     *@return The right sections checkbox table value
3484     */

3485     public static String JavaDoc getRightSectionCheckboxTable(DataStore db, String JavaDoc userID, String JavaDoc pubName, String JavaDoc limit) {
3486        StringBuffer JavaDoc checkboxTable = new StringBuffer JavaDoc("");
3487        try
3488        {
3489            if ((userID!=null) && !(userID.equals(""))) {
3490                checkboxTable.append("<TABLE BORDER=0>");
3491                checkboxTable.append("<TR><TD><i>dir.</i></TD><TD><i>acc.</i></TD></TR>");
3492                String JavaDoc tag = "select S.mappingCode, PUS.Manager, S.sectionDesc from tblsections AS S LEFT JOIN tblpermusersection AS PUS ";
3493                tag = tag + "on S.mappingCode=PUS.mappingCode and PUS.userID=" + userID + " ";
3494                tag = tag + "where S.pubName='" + pubName + "' and S.subMapOf=0 order by rank";
3495                HashMap JavaDoc htTmp = new HashMap JavaDoc();
3496                List JavaDoc lstSections = CofaxToolsDbUtils.getPackageData(db, htTmp, tag);
3497                if (lstSections.size() <= 0) {
3498                    checkboxTable.append("<TR><TD>" + CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"tools_nosectionallowed") + "</TD></TR>");
3499                }
3500                int checkBoxTableRightLength = 0;
3501                while (lstSections.size() > 0) {
3502                    HashMap JavaDoc hashInfo = (HashMap JavaDoc) lstSections.get(0);
3503                    String JavaDoc mappingCode = (String JavaDoc) hashInfo.get("MAPPINGCODE");
3504                    String JavaDoc sectionDesc = (String JavaDoc) hashInfo.get("SECTIONDESC");
3505                    String JavaDoc userPerm = (String JavaDoc) hashInfo.get("MANAGER");
3506
3507                    String JavaDoc managerChecked = "";
3508                    String JavaDoc redactorChecked = "";
3509                    if ("0".equals(userPerm))
3510                        redactorChecked = "checked";
3511                    else if ("1".equals(userPerm)) {
3512                        redactorChecked = "checked";
3513                        managerChecked = "checked";
3514                    }
3515
3516                    checkboxTable.append("<TR>");
3517                    checkboxTable.append("<TD><INPUT TYPE=CHECKBOX " + managerChecked + " NAME='d" + checkBoxTableRightLength + "' VALUE='1'></TD>");
3518                    checkboxTable.append("<TD><INPUT TYPE=CHECKBOX " + redactorChecked + " NAME='s" + checkBoxTableRightLength + "' VALUE='" + mappingCode + "'>");
3519                    checkboxTable.append(
3520                        "<INPUT TYPE=HIDDEN NAME='PARAM" + checkBoxTableRightLength + "' VALUE='" + mappingCode + "'></TD><TD nowrap><b>" + sectionDesc + "</b></TD></TR>\n");
3521                    lstSections.remove(0);
3522                    checkBoxTableRightLength++;
3523                    if (limit.equals("no")) {
3524                        String JavaDoc blanks = "&nbsp;&nbsp;&nbsp;";
3525                        HashMap JavaDoc ht3 = getRightSubSectionCheckboxTable(db, userID, pubName, mappingCode, blanks, checkBoxTableRightLength);
3526                        checkboxTable.append(ht3.get("tabSubSection"));
3527                        checkBoxTableRightLength = Integer.parseInt((String JavaDoc) ht3.get("checkBoxTableRightLength"));
3528                    }
3529                }
3530                checkboxTable.append("</TABLE>\n");
3531                checkboxTable.append("<INPUT TYPE=HIDDEN NAME='checkBoxTableRightLength' VALUE='" + checkBoxTableRightLength + "'>\n");
3532                if (!(limit.equals("no"))) {
3533                    checkboxTable.append("&gt;&nbsp;<a HREF='?mode=admin_get_user_info&selectUser=" + userID + "&limit=no'>" + CofaxToolsUtil.getI18NMessage(CofaxToolsServlet.lcl,"tools_allsections") + "</a>");
3534                }
3535            }
3536        } catch (Exception JavaDoc e) {CofaxToolsUtil.log(e.toString()); return "";}
3537        return (checkboxTable.toString());
3538    }
3539    
3540   public static HashMap JavaDoc getRightSubSectionCheckboxTable(DataStore db, String JavaDoc userID, String JavaDoc pubName, String JavaDoc sectionMappingCode, String JavaDoc blanks, int checkBoxTableRightLength) {
3541        HashMap JavaDoc returnHt = new HashMap JavaDoc();
3542        StringBuffer JavaDoc tabSubSections = new StringBuffer JavaDoc("");
3543        int sectionCnt = 0;
3544        try {
3545            String JavaDoc tag2 = "select S.mappingCode, PUS.Manager, S.sectionDesc from tblsections AS S LEFT JOIN tblpermusersection AS PUS ";
3546            tag2 = tag2 + "on S.mappingCode=PUS.mappingCode and PUS.userID=" + userID + " ";
3547            tag2 = tag2 + "where S.submapOf='" + sectionMappingCode + "' order by rank";
3548            HashMap JavaDoc htTmp2 = new HashMap JavaDoc();
3549            List JavaDoc lstSections2 = CofaxToolsDbUtils.getPackageData(db, htTmp2, tag2);
3550            while (lstSections2.size() > 0) {
3551                HashMap JavaDoc hashInfo2 = (HashMap JavaDoc) lstSections2.get(0);
3552                String JavaDoc mappingCode2 = (String JavaDoc) hashInfo2.get("MAPPINGCODE");
3553                String JavaDoc sectionDesc2 = (String JavaDoc) hashInfo2.get("SECTIONDESC");
3554                String JavaDoc userPerm = (String JavaDoc) hashInfo2.get("MANAGER");
3555
3556                String JavaDoc managerChecked = "";
3557                String JavaDoc redactorChecked = "";
3558                if ("0".equals(userPerm))
3559                    redactorChecked = "checked";
3560                else if ("1".equals(userPerm)) {
3561                    redactorChecked = "checked";
3562                    managerChecked = "checked";
3563                }
3564
3565                tabSubSections.append("<TR>");
3566                tabSubSections.append("<TD><INPUT TYPE=CHECKBOX " + managerChecked + " NAME='d" + checkBoxTableRightLength + "' VALUE='1'></TD>");
3567                tabSubSections.append("<TD><INPUT TYPE=CHECKBOX " + redactorChecked + " NAME='s" + checkBoxTableRightLength + "' VALUE='" + mappingCode2 + "'>");
3568                tabSubSections.append("<INPUT TYPE=HIDDEN NAME='PARAM" + checkBoxTableRightLength + "' VALUE='" + mappingCode2 + "'></TD><TD nowrap>" + blanks + sectionDesc2 + "</TD></TR>\n");
3569                
3570                checkBoxTableRightLength++;
3571                                
3572                //check if there are sub sections
3573
String JavaDoc tag3 = CofaxToolsDbUtils.fillTag(db, "getTabSubSections");
3574                HashMap JavaDoc htTmp3 = new HashMap JavaDoc();
3575                htTmp3.put("pubName",pubName);
3576                htTmp3.put("userID",userID);
3577                htTmp3.put("sectionMappingCode",mappingCode2);
3578                List JavaDoc lstSections3 = CofaxToolsDbUtils.getPackageData(db, htTmp3, tag3);
3579                if (lstSections3.size() > 0) {
3580                    String JavaDoc blanks2 = blanks + "&nbsp;&nbsp;&nbsp;";
3581                    HashMap JavaDoc ht3 = getRightSubSectionCheckboxTable(db, userID, pubName, mappingCode2, blanks2, checkBoxTableRightLength);
3582                    tabSubSections.append(ht3.get("tabSubSection"));
3583                    checkBoxTableRightLength=Integer.parseInt((String JavaDoc)ht3.get("checkBoxTableRightLength"));
3584                }
3585                lstSections2.remove(0);
3586            }
3587            
3588        } catch (Exception JavaDoc e) {return returnHt;}
3589        returnHt.put("tabSubSection",tabSubSections.toString());
3590        returnHt.put("checkBoxTableRightLength",checkBoxTableRightLength+"");
3591        return (returnHt);
3592    }
3593
3594    /**
3595     * Returns a checkbox table for security settings.
3596     *
3597     *@param db Description of the Parameter
3598     *@return The securityCheckboxTable value
3599     */

3600
3601    public static String JavaDoc getSecurityCheckboxTable(DataStore db) {
3602        StringBuffer JavaDoc selectComp = new StringBuffer JavaDoc("\n\n<TABLE BORDER=1>\n");
3603        selectComp.append("<TD><B>Action</B></TD>");
3604        String JavaDoc modeHashType = "";
3605
3606        HashMap JavaDoc preSortHash = new HashMap JavaDoc();
3607        StringBuffer JavaDoc preSortText = new StringBuffer JavaDoc();
3608
3609        Vector JavaDoc groupTypeNames = CofaxToolsUtil.getGroupTypeNames(db);
3610        Iterator JavaDoc gtnIter = groupTypeNames.iterator();
3611
3612        while (gtnIter.hasNext()) {
3613            String JavaDoc groupTypeNamesLabel = (String JavaDoc) gtnIter.next();
3614            selectComp.append("<TD><B>" + groupTypeNamesLabel + "</B></TD>\n");
3615        }
3616
3617        selectComp.append("<TR>\n");
3618        Vector JavaDoc groupTypeIDs = CofaxToolsUtil.getGroupTypeIDs(db);
3619
3620        HashMap JavaDoc htChecks = new HashMap JavaDoc();
3621        List JavaDoc modes = (ArrayList JavaDoc) CofaxToolsUtil.getModes(db);
3622
3623        Iterator JavaDoc modesIter = modes.iterator();
3624        while (modesIter.hasNext()) {
3625            Object JavaDoc modesO = modesIter.next();
3626            HashMap JavaDoc modeType = new HashMap JavaDoc();
3627            modeType = (HashMap JavaDoc) modesO;
3628            Iterator JavaDoc en = modeType.keySet().iterator();
3629            String JavaDoc modeE = (String JavaDoc) modeType.get("MODES");
3630            if (!htChecks.containsKey(modeE)) {
3631                htChecks.put(modeE, "");
3632            }
3633        }
3634
3635        Iterator JavaDoc enu = htChecks.keySet().iterator();
3636        while (enu.hasNext()) {
3637            String JavaDoc modeName = (String JavaDoc) enu.next();
3638            String JavaDoc tempModeName = modeName;
3639            tempModeName = tempModeName.replace('_', ' ');
3640            preSortText.append("<TD><B>" + tempModeName + "</TD>");
3641            Iterator JavaDoc groupTypeIDsIter = groupTypeIDs.iterator();
3642            while (groupTypeIDsIter.hasNext()) {
3643                String JavaDoc modeTypeS = (String JavaDoc) groupTypeIDsIter.next();
3644                boolean checked = false;
3645                Iterator JavaDoc modesItera = modes.iterator();
3646                while (modesItera.hasNext()) {
3647                    Object JavaDoc o = modesItera.next();
3648                    HashMap JavaDoc modeTypeH = new HashMap JavaDoc();
3649                    modeTypeH = (HashMap JavaDoc) o;
3650                    String JavaDoc modeHashName = (String JavaDoc) modeTypeH.get("MODES");
3651                    modeHashType = (String JavaDoc) modeTypeH.get("TYPE");
3652                    if (modeHashName.equals(modeName) && modeHashType.equals(modeTypeS)) {
3653                        preSortText.append("<TD><INPUT TYPE=CHECKBOX NAME=" + modeName + "." + modeTypeS + " CHECKED></TD>\n");
3654                        checked = true;
3655                    }
3656                }
3657                if (checked == false) {
3658                    preSortText.append("<TD><INPUT TYPE=CHECKBOX NAME=" + modeName + "." + modeTypeS + "></TD>\n");
3659                }
3660            }
3661            preSortText.append("<TR>\n");
3662            preSortHash.put(modeName, preSortText.toString());
3663            preSortText.setLength(0);
3664        }
3665
3666        SortedMap JavaDoc sortedMap = new TreeMap JavaDoc();
3667        sortedMap.putAll(preSortHash);
3668        Set JavaDoc set = sortedMap.keySet();
3669        Iterator JavaDoc iterator = set.iterator();
3670        StringBuffer JavaDoc s = new StringBuffer JavaDoc();
3671        while (iterator.hasNext()) {
3672            s.append(sortedMap.get(iterator.next()));
3673        }
3674        selectComp.append(s);
3675        selectComp.append("</TABLE>\n\n");
3676        return (selectComp.toString());
3677    }
3678
3679
3680    /**
3681    * Add rights to an user for a section
3682    *
3683    **/

3684    public static String JavaDoc addUserSection(DataStore db, HttpServletRequest JavaDoc req){
3685        HashMap JavaDoc ht = splitPostQuery(req);
3686        
3687        String JavaDoc director = req.getParameter("DIRECTOR");
3688        String JavaDoc userID = req.getParameter("USERS");
3689        String JavaDoc mappingCode = req.getParameter("sectionMappingCode");
3690        String JavaDoc delete = req.getParameter("DELETE");
3691        ht.put("MAPPINGCODE",mappingCode);
3692        
3693        if ( ((userID!=null) && (!(userID.equals("")))) &&
3694            ((mappingCode!=null) && (!(mappingCode.equals("")))) &&
3695            ((director!=null) && (!(director.equals("")))) ) {
3696
3697            if ( ((delete!=null) && (!(delete.equals(""))))) {
3698                //drop this user for this section
3699
StringBuffer JavaDoc v_del = new StringBuffer JavaDoc();
3700                if (director.equals("0")) v_del.append("delete from tblpermusersection WHERE userID = " + userID + " and mappingCode=" + mappingCode + " ");
3701                if (director.equals("1")) v_del.append("update tblpermusersection set manager=0 WHERE userID = " + userID + " and mappingCode=" + mappingCode + " ");
3702                List JavaDoc del = CofaxToolsDbUtils.getPackageData(db, ht, v_del.toString());
3703                return("User " + userID + " deleted from section " + mappingCode + ".");
3704            } else {
3705                Vector JavaDoc u_users = null;
3706                StringBuffer JavaDoc v = new StringBuffer JavaDoc();
3707                v.append("SELECT * FROM tblpermusersection WHERE userID = " + userID + " and mappingCode=" + mappingCode + " ");
3708                u_users = CofaxToolsDbUtils.getPackageVector(db,ht,v.toString());
3709                if (u_users.size() > 0 && u_users != null) {
3710                    StringBuffer JavaDoc v_ins = new StringBuffer JavaDoc();
3711                    v_ins.append("UPDATE tblpermusersection set manager=1 WHERE userID = " + userID + " and mappingCode=" + mappingCode + " ");
3712                    List JavaDoc del2 = CofaxToolsDbUtils.getPackageData(db, ht, v_ins.toString());
3713                } else
3714                {
3715                    StringBuffer JavaDoc v_ins = new StringBuffer JavaDoc();
3716                    v_ins.append("INSERT INTO tblpermusersection (mappingCode, userID, manager) Values(" + mappingCode + "," + userID + "," + director + ")");
3717                    List JavaDoc del2 = CofaxToolsDbUtils.getPackageData(db, ht, v_ins.toString());
3718                }
3719                return("User " + userID + " added to section " + mappingCode + ".");
3720            }
3721        }
3722        else
3723        {
3724            return("You must select a user");
3725        }
3726    }
3727
3728
3729   /**
3730     * Returns a tab list for sections allowed.
3731     *
3732     *@return The tab list sections
3733     */

3734
3735    public static String JavaDoc getTabSections(DataStore db, String JavaDoc userID, String JavaDoc pubName, int pubCnt) {
3736        StringBuffer JavaDoc tabSections = new StringBuffer JavaDoc("");
3737        int sectionCnt = 0;
3738        try {
3739            if ((userID!=null) && !(userID.equals(""))) {
3740
3741                String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getTabSections");
3742                HashMap JavaDoc htTmp = new HashMap JavaDoc();
3743                htTmp.put("pubName",pubName);
3744                htTmp.put("userID",userID);
3745                List JavaDoc lstSections = CofaxToolsDbUtils.getPackageData(db, htTmp, tag);
3746                while (lstSections.size() > 0) {
3747                    StringBuffer JavaDoc sbTemp = new StringBuffer JavaDoc();
3748                    HashMap JavaDoc hashInfo = (HashMap JavaDoc) lstSections.get(0);
3749                    String JavaDoc mappingCode = (String JavaDoc) hashInfo.get("MAPPINGCODE");
3750                    String JavaDoc sectionDesc = (String JavaDoc) hashInfo.get("SECTIONDESC");
3751                    String JavaDoc manager = (String JavaDoc) hashInfo.get("MANAGER");
3752                    sectionCnt ++;
3753                    
3754                    // FX : pure HTML
3755
tabSections.append("<li class='nav_section'><a HREF='"+ CofaxToolsServlet.aliasPath + "/tools/?mode=section_get_section&sectionMappingCode=" + mappingCode + "&ht=section_edit_section'>" + sectionDesc + "</a>");
3756                    tabSections.append("</li>\n");
3757                    
3758                    String JavaDoc blanks = pubCnt + "." + sectionCnt;
3759                    tabSections.append(getTabSubSections(db, userID, pubName, mappingCode, blanks));
3760                    //tabSections.append(getTabArticles(db, userID, mappingCode, blanks));
3761
lstSections.remove(0);
3762                }
3763            }
3764        } catch (Exception JavaDoc e) {return "";}
3765        return (tabSections.toString());
3766    }
3767
3768    public static String JavaDoc getTabSubSections(DataStore db, String JavaDoc userID, String JavaDoc pubName, String JavaDoc sectionMappingCode, String JavaDoc blanks) {
3769        StringBuffer JavaDoc tabSubSections = new StringBuffer JavaDoc("");
3770        int sectionCnt = 0;
3771        try {
3772            String JavaDoc tag2 = CofaxToolsDbUtils.fillTag(db, "getTabSubSections");
3773            HashMap JavaDoc htTmp2 = new HashMap JavaDoc();
3774            htTmp2.put("pubName",pubName);
3775            htTmp2.put("userID",userID);
3776            htTmp2.put("sectionMappingCode",sectionMappingCode);
3777            List JavaDoc lstSections2 = CofaxToolsDbUtils.getPackageData(db, htTmp2, tag2);
3778            // FX : changing to raw HTML : no JAVASCRIPT
3779
if (lstSections2.size()>0)
3780            {
3781                tabSubSections.append("<ul>\n");
3782                while (lstSections2.size() > 0) {
3783                    StringBuffer JavaDoc sbTemp2 = new StringBuffer JavaDoc();
3784                    HashMap JavaDoc hashInfo2 = (HashMap JavaDoc) lstSections2.get(0);
3785                    String JavaDoc mappingCode2 = (String JavaDoc) hashInfo2.get("MAPPINGCODE");
3786                    String JavaDoc sectionDesc2 = (String JavaDoc) hashInfo2.get("SECTIONDESC");
3787                    String JavaDoc manager2 = (String JavaDoc) hashInfo2.get("MANAGER");
3788                    sectionCnt ++;
3789                    
3790                    tabSubSections.append("<li class='nav_section'>");
3791                    tabSubSections.append("<a HREF='"+ CofaxToolsServlet.aliasPath + "/tools/?mode=section_get_section&sectionMappingCode=" + mappingCode2 + "&ht=section_edit_section\'>"+sectionDesc2+"</a>");
3792                    tabSubSections.append("</li>\n");
3793                    
3794                    
3795                    //check if there are sub sections
3796
String JavaDoc tag3 = CofaxToolsDbUtils.fillTag(db, "getTabSubSections");
3797                    HashMap JavaDoc htTmp3 = new HashMap JavaDoc();
3798                    htTmp3.put("pubName",pubName);
3799                    htTmp3.put("userID",userID);
3800                    htTmp3.put("sectionMappingCode",mappingCode2);
3801                    List JavaDoc lstSections3 = CofaxToolsDbUtils.getPackageData(db, htTmp3, tag3);
3802                    if (lstSections3.size() > 0) {
3803                        String JavaDoc blanks2 = blanks + "." + sectionCnt;
3804                        tabSubSections.append(getTabSubSections(db, userID, pubName, mappingCode2, blanks2));
3805                    } else
3806                    {
3807                        tabSubSections.append(getTabArticles(db, userID, mappingCode2, blanks + "." + sectionCnt, 0));
3808                    }
3809                    lstSections2.remove(0);
3810                }
3811             tabSubSections.append("</ul>\n");
3812            }
3813            tabSubSections.append(getTabArticles(db, userID, sectionMappingCode, blanks, sectionCnt));
3814            
3815            
3816        } catch (Exception JavaDoc e) {return "";}
3817        return (tabSubSections.toString());
3818    }
3819
3820    public static String JavaDoc getTabPublications(DataStore db, String JavaDoc userID, String JavaDoc currentPubID) {
3821        StringBuffer JavaDoc tabPublications = new StringBuffer JavaDoc("");
3822        int pubCnt = 0;
3823        try {
3824            if ((userID!=null) && !(userID.equals(""))) {
3825                String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getTabPublications");
3826                HashMap JavaDoc htTmp = new HashMap JavaDoc();
3827                htTmp.put("userID",userID);
3828                htTmp.put("currentPubID",currentPubID);
3829                List JavaDoc lstSections = CofaxToolsDbUtils.getPackageData(db, htTmp, tag);
3830                while (lstSections.size() > 0) {
3831                    StringBuffer JavaDoc sbTemp = new StringBuffer JavaDoc();
3832                    HashMap JavaDoc hashInfo = (HashMap JavaDoc) lstSections.get(0);
3833                    String JavaDoc pubID = (String JavaDoc) hashInfo.get("PUBID");
3834                    String JavaDoc pubDesc = (String JavaDoc) hashInfo.get("PUBDESC");
3835                    String JavaDoc pubName = (String JavaDoc) hashInfo.get("PUBNAME");
3836                    pubCnt ++;
3837                    tabPublications.append("<div class='nav_publication_name'>");
3838                    tabPublications.append("<a HREF='"+ CofaxToolsServlet.aliasPath + "/tools/?mode=admin_get_publication_info&PUBLICATION=" + pubID + "&hl=admin'>" + pubDesc + "</a></div>");
3839                    tabPublications.append("<div class='nav_publication'>");
3840                    tabPublications.append(getTabSections(db, userID, pubName, pubCnt));
3841                    tabPublications.append("\n</div>");
3842                    lstSections.remove(0);
3843                }
3844            }
3845        } catch (Exception JavaDoc e) {return "";}
3846        return (tabPublications.toString());
3847    }
3848
3849    public static String JavaDoc getTabArticles(DataStore db, String JavaDoc userID, String JavaDoc mappingCode, String JavaDoc blanks, int cnt) {
3850        StringBuffer JavaDoc tabArticles = new StringBuffer JavaDoc("");
3851        int articlesCnt = cnt;
3852        try {
3853            if ((userID!=null) && !(userID.equals(""))) {
3854                String JavaDoc tag = CofaxToolsDbUtils.fillTag(db, "getTabArticles");
3855                HashMap JavaDoc htTmp = new HashMap JavaDoc();
3856                htTmp.put("mappingCode",mappingCode);
3857                List JavaDoc lstSections = CofaxToolsDbUtils.getPackageData(db, htTmp, tag);
3858                // FX : adding a list
3859
if (lstSections.size() > 0)
3860                {
3861                 tabArticles.append("<ul>");
3862                while (lstSections.size() > 0)
3863                {
3864                    StringBuffer JavaDoc sbTemp = new StringBuffer JavaDoc();
3865                    HashMap JavaDoc hashInfo = (HashMap JavaDoc) lstSections.get(0);
3866                
3867                    String JavaDoc itemID = (String JavaDoc) hashInfo.get("ITEMID");
3868                    String JavaDoc fileName = (String JavaDoc) hashInfo.get("FILENAME");
3869                    String JavaDoc fullLink = (String JavaDoc) hashInfo.get("FULLLINK");
3870                    String JavaDoc wstate = (String JavaDoc) hashInfo.get("WORKFLOW_STATE");
3871                    articlesCnt ++;
3872                    // FX : reformatting pure HTML
3873
tabArticles.append("<li class='article_state_"+wstate+"'><a HREF='"+CofaxToolsServlet.aliasPath + "/tools/?mode=article_edit_article_by_itemID&ITEMID=" + itemID + "&hl=article_create_article'>"+ fileName + "</a></li>\n");
3874                    lstSections.remove(0);
3875                }
3876                tabArticles.append("</ul>");
3877                }
3878            }
3879        } catch (Exception JavaDoc e) {return "";}
3880        return (tabArticles.toString());
3881    }
3882
3883    static public String JavaDoc getI18NMessage(Locale JavaDoc lcl, String JavaDoc message) {
3884        ResourceBundle JavaDoc messages;
3885        String JavaDoc returnMessage="";
3886        try
3887        {
3888            messages = ResourceBundle.getBundle("org.cofax.i18n.cmsTools", lcl);
3889            returnMessage = messages.getString(message);
3890        } catch (Exception JavaDoc e) {
3891            CofaxToolsUtil.log("CofaxToolsUtil : getI18NMessage : error while reading " + message);
3892        }
3893        return (returnMessage);
3894    }
3895}
3896
3897
3898
Popular Tags