KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > tools > ScarabGlobalTool


1 package org.tigris.scarab.tools;
2
3 /* ================================================================
4  * Copyright (c) 2000-2002 CollabNet. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  *
17  * 3. The end-user documentation included with the redistribution, if
18  * any, must include the following acknowlegement: "This product includes
19  * software developed by Collab.Net <http://www.Collab.Net/>."
20  * Alternately, this acknowlegement may appear in the software itself, if
21  * and wherever such third-party acknowlegements normally appear.
22  *
23  * 4. The hosted project names must not be used to endorse or promote
24  * products derived from this software without prior written
25  * permission. For written permission, please contact info@collab.net.
26  *
27  * 5. Products derived from this software may not use the "Tigris" or
28  * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
29  * prior written permission of Collab.Net.
30  *
31  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
32  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
33  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
34  * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
35  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
37  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
39  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42  *
43  * ====================================================================
44  *
45  * This software consists of voluntary contributions made by many
46  * individuals on behalf of Collab.Net.
47  */

48
49 import java.util.Date JavaDoc;
50 import java.util.Calendar JavaDoc;
51 import java.util.List JavaDoc;
52 import java.util.ArrayList JavaDoc;
53 import java.util.StringTokenizer JavaDoc;
54 import java.util.Enumeration JavaDoc;
55
56 import org.apache.commons.lang.StringUtils;
57 import org.apache.log4j.Logger;
58 import org.apache.fulcrum.TurbineServices;
59 import org.apache.fulcrum.security.TurbineSecurity;
60 import org.apache.fulcrum.security.entity.User;
61 import org.apache.fulcrum.velocity.TurbineVelocityService;
62 import org.apache.fulcrum.velocity.VelocityService;
63 import org.apache.turbine.services.pull.ApplicationTool;
64
65 import org.apache.velocity.app.FieldMethodizer;
66
67 import org.tigris.scarab.om.AttributePeer;
68 import org.tigris.scarab.om.IssueTypePeer;
69
70 import org.tigris.scarab.om.GlobalParameter;
71 import org.tigris.scarab.om.ScarabUser;
72 import org.tigris.scarab.om.ScarabUserImplPeer;
73 import org.tigris.scarab.om.GlobalParameterManager;
74 import org.tigris.scarab.om.ModuleManager;
75 import org.tigris.scarab.om.Module;
76 import org.tigris.scarab.om.MITListManager;
77 import org.tigris.scarab.services.security.ScarabSecurity;
78 import org.tigris.scarab.workflow.Workflow;
79 import org.tigris.scarab.workflow.WorkflowFactory;
80 import org.tigris.scarab.util.IssueIdParser;
81 import org.tigris.scarab.util.Log;
82 import org.tigris.scarab.util.SkipFiltering;
83 import org.tigris.scarab.util.SimpleSkipFiltering;
84 import org.tigris.scarab.util.ScarabLink;
85 import org.tigris.scarab.util.ScarabUtil;
86
87 import org.apache.torque.util.Criteria;
88 import org.apache.torque.TorqueException;
89
90 import org.apache.turbine.Turbine;
91
92 /**
93  * This scope is an object that is made available as a global
94  * object within the system.
95  * This object must be thread safe as multiple
96  * requests may access it at the same time. The object is made
97  * available in the context as: $scarabG
98  * <p>
99  * The design goals of the Scarab*API is to enable a <a
100  * HREF="http://jakarta.apache.org/turbine/pullmodel.html">pull based
101  * methodology</a> to be implemented.
102  *
103  * @author <a HREF="mailto:jon@collab.net">Jon S. Stevens</a>
104  * @author <a HREF="mailto:dr@bitonic.com">Douglas B. Robertson</a>
105  * @version $Id: ScarabGlobalTool.java 9576 2005-04-10 10:53:51Z dabbous $
106  */

107 public class ScarabGlobalTool
108     implements ApplicationTool
109 {
110     private static int moduleCodeLength = 0;
111
112     private static final Logger LOG =
113         Logger.getLogger("org.tigris.scarab");
114
115     /**
116      * holds the Scarab constants
117      */

118     private FieldMethodizer constant = null;
119     
120     /**
121      * holds the Scarab security permission constants
122      */

123     private FieldMethodizer security = null;
124
125     /**
126      * holds the Scarab parameter name constants
127      */

128     private FieldMethodizer parameterName = null;
129
130     private static final String JavaDoc BUILD_VERSION =
131         Turbine.getConfiguration().getString("scarab.build.version", "");
132
133
134     
135     public void init(Object JavaDoc data)
136     {
137     }
138     
139     public void refresh()
140     {
141     }
142     
143     /**
144      * Constructor does initialization stuff
145      */

146     public ScarabGlobalTool()
147     {
148         constant = new FieldMethodizer(
149             "org.tigris.scarab.util.ScarabConstants");
150         security = new FieldMethodizer(
151             "org.tigris.scarab.services.security.ScarabSecurity");
152         parameterName = new FieldMethodizer(
153             "org.tigris.scarab.om.GlobalParameter");
154     }
155
156     /**
157      * returns Scarab's build version.
158      */

159     public String JavaDoc getBuildVersion()
160     {
161         return BUILD_VERSION;
162     }
163     
164     /**
165      * holds the Scarab constants. it will be available to the template system
166      * as $scarabG.Constant.CONSTANT_NAME.
167      */

168     public FieldMethodizer getConstant()
169     {
170         return constant;
171     }
172     
173     /**
174      * holds the Scarab permission constants. It will be available to
175      * the template system as $scarabG.PERMISSION_NAME.
176      */

177     public FieldMethodizer getPermission()
178     {
179         return security;
180     }
181
182     /**
183      * holds the names of parameters that are configurable through the ui.
184      */

185     public FieldMethodizer getParameterName()
186     {
187         return parameterName;
188     }
189
190     public String JavaDoc replace(String JavaDoc text, String JavaDoc a, String JavaDoc b)
191     {
192         return StringUtils.replace(text, a, b);
193     }
194
195     public GlobalParameterManager getParameter()
196     {
197         return GlobalParameterManager.getManager();
198     }
199
200     /**
201      * Returns a list of all the permissions in use by scarab.
202      *
203      * @return a <code>List</code> of <code>String</code>s
204      */

205     public List JavaDoc getAllPermissions()
206     {
207         return ScarabSecurity.getAllPermissions();
208     }
209     
210     /**
211      * Gets a List of all of the data (non-user) Attribute objects.
212      */

213     public List JavaDoc getAllAttributes()
214         throws Exception JavaDoc
215     {
216         return AttributePeer.getAttributes();
217     }
218     
219     /**
220      * Gets a List of all of the Attribute objects by type.
221      */

222     public List JavaDoc getAttributes(String JavaDoc attributeType)
223         throws Exception JavaDoc
224     {
225         return AttributePeer.getAttributes(attributeType, false);
226     }
227
228     /**
229      * Gets a List of all of the data (non-user) Attribute objects.
230      * Passes in sort criteria.
231      */

232     public List JavaDoc getAllAttributes(String JavaDoc attributeType, boolean includeDeleted,
233                                  String JavaDoc sortColumn, String JavaDoc sortPolarity)
234         throws Exception JavaDoc
235     {
236         return AttributePeer.getAttributes(attributeType, includeDeleted,
237                                            sortColumn, sortPolarity);
238     }
239
240     /**
241      * Gets a List of all of the data (non-user) Attribute objects.
242      * Passes in sort criteria.
243      */

244     public List JavaDoc getAllAttributes(String JavaDoc sortColumn, String JavaDoc sortPolarity)
245         throws Exception JavaDoc
246     {
247         return AttributePeer.getAttributes(sortColumn, sortPolarity);
248     }
249     
250     /**
251      * Gets a List of all of user Attributes.
252      */

253     public List JavaDoc getUserAttributes()
254         throws Exception JavaDoc
255     {
256         return AttributePeer.getAttributes("user");
257     }
258
259
260     /**
261      * Gets a List of all of the Attribute objects.
262      */

263     public List JavaDoc getUserAttributes(String JavaDoc sortColumn, String JavaDoc sortPolarity)
264         throws Exception JavaDoc
265     {
266         return AttributePeer.getAttributes("user", false, sortColumn, sortPolarity);
267     }
268     
269     /**
270      * Gets a List of all of the Attribute objects.
271      */

272     public List JavaDoc getUserAttributes(boolean includeDeleted, String JavaDoc sortColumn,
273                                   String JavaDoc sortPolarity)
274         throws Exception JavaDoc
275     {
276         return AttributePeer.getAttributes("user", includeDeleted, sortColumn, sortPolarity);
277     }
278
279     /**
280      * Gets a List of all of user Attribute objects.
281      */

282     public List JavaDoc getAttributes(String JavaDoc attributeType, boolean includeDeleted,
283                               String JavaDoc sortColumn, String JavaDoc sortPolarity)
284         throws Exception JavaDoc
285     {
286         return AttributePeer.getAttributes(attributeType, includeDeleted,
287                                            sortColumn, sortPolarity);
288     }
289
290     public List JavaDoc getAllIssueTypes()
291         throws Exception JavaDoc
292     {
293         return IssueTypePeer.getAllIssueTypes(false, "name", "asc");
294     }
295
296     /**
297      * gets a list of all Issue Types
298      */

299     public List JavaDoc getAllIssueTypes(boolean deleted)
300         throws Exception JavaDoc
301     {
302         return IssueTypePeer.getAllIssueTypes(deleted, "name", "asc");
303     }
304     
305     /**
306      * Gets a List of all of the Attribute objects.
307      */

308     public List JavaDoc getAllIssueTypes(boolean deleted, String JavaDoc sortColumn,
309                                  String JavaDoc sortPolarity)
310         throws Exception JavaDoc
311     {
312         return IssueTypePeer.getAllIssueTypes(deleted, sortColumn, sortPolarity);
313     }
314     
315     /**
316      * Makes the workflow tool accessible.
317      */

318     public Workflow getWorkflow()
319         throws Exception JavaDoc
320     {
321         return WorkflowFactory.getInstance();
322     }
323     
324     /**
325      * Returns a List of users based on the given search criteria. This method
326      * is an overloaded function which returns an unsorted list of users.
327      *
328      * @param searchField the name of the database attribute to search on
329      * @param searchCriteria the search criteria to use within the LIKE command
330      * @return a List of users matching the specifed criteria
331      *
332      */

333     public List JavaDoc getSearchUsers(String JavaDoc searchField, String JavaDoc searchCriteria)
334         throws Exception JavaDoc
335     {
336         return (getSearchUsers(searchField, searchCriteria, null, null));
337     }
338     
339     /**
340      * Returns a List of users based on the given search criteria and orders
341      * the list by the specified field. The method will use the LIKE
342      * SQL command and perform a search as such (assuming 'doug' is
343      * specified as the search criteria:
344      * <code>WHERE some_field LIKE '%doug%'</code>
345      *
346      * @param searchField the name of the database attribute to search on
347      * @param searchCriteria the search criteria to use within the LIKE command
348      * @param orderByField the name of the database attribute to order the list by
349      * @param ascOrDesc either "ASC" of "DESC" specifying the order to sort in
350      * @return a List of users matching the specifed criteria
351      */

352     /**
353      * Describe <code>getSearchUsers</code> method here.
354      *
355      * @param searchField a <code>String</code> value
356      * @param searchCriteria a <code>String</code> value
357      * @param orderByField a <code>String</code> value
358      * @param ascOrDesc a <code>String</code> value
359      * @return a <code>List</code> value
360      * @exception Exception if an error occurs
361      */

362     public List JavaDoc getSearchUsers(String JavaDoc searchField, String JavaDoc searchCriteria,
363                                String JavaDoc orderByField, String JavaDoc ascOrDesc)
364         throws Exception JavaDoc
365     {
366         ArrayList JavaDoc userSearchList = new ArrayList JavaDoc();
367         String JavaDoc lSearchField = "";
368         String JavaDoc lOrderByField = "";
369         
370         Criteria criteria = new Criteria();
371         
372         // add the input from the user
373
if (searchCriteria != null && searchCriteria.length() > 0)
374         {
375             if (searchField.equals("FIRST_NAME"))
376             {
377                 lSearchField = ScarabUser.FIRST_NAME;
378             }
379             else if (searchField.equals("LAST_NAME"))
380             {
381                 lSearchField = ScarabUser.LAST_NAME;
382             }
383             else if (searchField.equals("LOGIN_NAME"))
384             {
385                 lSearchField = ScarabUser.USERNAME;
386             }
387             else
388             {
389                 lSearchField = ScarabUser.EMAIL;
390             }
391             
392             // FIXME: Probably shouldn't be using ScarabUserPeerImpl here
393
// What should we do to get the right table name?
394
lSearchField = ScarabUserImplPeer.getTableName() + '.' + lSearchField;
395             
396             criteria = criteria.add(lSearchField,
397                                         (Object JavaDoc)('%' + searchCriteria.trim() + '%'),Criteria.LIKE);
398         }
399         
400         // sort the results
401
if (orderByField != null && orderByField.length() > 0)
402         {
403             if (orderByField.equals("FIRST_NAME"))
404             {
405                 lOrderByField = ScarabUser.FIRST_NAME;
406             }
407             else if (orderByField.equals("LAST_NAME"))
408             {
409                 lOrderByField = ScarabUser.LAST_NAME;
410             }
411             else if (orderByField.equals("LOGIN_NAME"))
412             {
413                 lOrderByField = ScarabUser.USERNAME;
414             }
415             else
416             {
417                 lOrderByField = ScarabUser.EMAIL;
418             }
419             
420             // FIXME: Probably shouldn't be using ScarabUserPeerImpl here
421
// What should we do to get the right table name?
422
lOrderByField = ScarabUserImplPeer.getTableName() + '.' + lOrderByField;
423             
424             if (ascOrDesc != null && ascOrDesc.equalsIgnoreCase("DESC"))
425             {
426                 criteria = criteria.addDescendingOrderByColumn(lOrderByField);
427             }
428             else
429             {
430                 criteria = criteria.addAscendingOrderByColumn(lOrderByField);
431             }
432         }
433         
434         User[] tempUsers = TurbineSecurity.getUsers(criteria);
435         for (int i=0; i < tempUsers.length; i++)
436         {
437             userSearchList.add(i, tempUsers[i]);
438         }
439         return (userSearchList);
440     }
441
442     /**
443      * Create a list of Modules from the given list of issues. Each
444      * Module in the list of issues will only occur once in the list of
445      * Modules.
446      */

447     public List JavaDoc getModulesFromIssueList(List JavaDoc issues)
448         throws TorqueException
449     {
450         return ModuleManager.getInstancesFromIssueList(issues);
451     }
452
453     public MITListManager getMITListManager()
454     {
455         return MITListManager.getManager();
456     }
457
458     /**
459      * Get a new Date object initialized to the current time.
460      * @return a <code>Date</code> value
461      */

462     public Date JavaDoc getNow()
463     {
464         return new Date JavaDoc();
465     }
466
467     /**
468      * Creates a new array with elements reversed from the given array.
469      *
470      * @param a the orginal <code>Object[]</code>
471      * @return a new <code>Object[]</code> with values reversed from the
472      * original
473      */

474     public Object JavaDoc[] reverse(Object JavaDoc[] a)
475     {
476         Object JavaDoc[] b = new Object JavaDoc[a.length];
477         for (int i=a.length-1; i>=0; i--)
478         {
479             b[a.length-1-i] = a[i];
480         }
481         return b;
482     }
483
484     /**
485      * Creates a new <code>List</code> with elements reversed from the
486      * given <code>List</code>.
487      *
488      * @param a the orginal <code>List</code>
489      * @return a new <code>List</code> with values reversed from the
490      * original
491      */

492     public List JavaDoc reverse(List JavaDoc a)
493     {
494         int size = a.size();
495         List JavaDoc b = new ArrayList JavaDoc(size);
496         for (int i=size-1; i>=0; i--)
497         {
498             b.add(a.get(i));
499         }
500         return b;
501     }
502
503     /**
504      * Creates a view of the portion of the given
505      * <code>List</code> between the specified <code>fromIndex</code>, inclusive, and
506      * <code>toIndex</code>, exclusive.
507      * The list returned by this method is backed by the original, so changes
508      * to either affect the other.
509      *
510      * @param a the orginal <code>List</code>
511      * @param fromIndex the start index of the returned subset
512      * @param toIndex the end index of the returned subset
513      * @return a derived <code>List</code> with a view of the original
514      */

515     public List JavaDoc subset(List JavaDoc a, Integer JavaDoc fromIndex, Integer JavaDoc toIndex)
516     {
517         int from = Math.min(fromIndex.intValue(), a.size());
518         from = Math.max(from, 0);
519         int to = Math.min(toIndex.intValue(), a.size());
520         to = Math.max(to, from);
521         return a.subList(from, to);
522     }
523
524     /**
525      * Creates a new array with a view of the portion of the given array
526      * between the specified fromIndex, inclusive, and toIndex, exclusive
527      *
528      * @param a the orginal <code>Object[]</code>
529      * @param fromIndex the start index of the returned subset
530      * @param toIndex the end index of the returned subset
531      * @return a new <code>Object[]</code> with a view of the original
532      */

533     public Object JavaDoc[] subset(Object JavaDoc[] a, Integer JavaDoc fromIndex, Integer JavaDoc toIndex)
534     {
535         int from = Math.min(fromIndex.intValue(), a.length);
536         from = Math.max(from, 0);
537         int to = Math.min(toIndex.intValue(), a.length);
538         to = Math.max(to, from);
539         Object JavaDoc[] b = new Object JavaDoc[from-to];
540         for (int i=from-1; i>=to; i--)
541         {
542             b[i-to] = a[i];
543         }
544         return b;
545     }
546
547     /**
548      * Velocity has no way of getting the size of an <code>Object[]</code>
549      * easily. Usually this would be done by calling obj.length
550      * but this doesn't work in Velocity.
551      * @param obj the <code>Object[]</code>
552      * @return the number of objects in the <code>Object[]</code> or -1 if obj is null
553      */

554     public int sizeOfArray(Object JavaDoc[] obj)
555     {
556         return (obj == null) ? -1 : obj.length;
557     }
558
559     public boolean isString(Object JavaDoc obj)
560     {
561         return obj instanceof String JavaDoc;
562     }
563
564     /**
565      * Breaks text into a list of Strings. Text is separated into tokens
566      * at characters given in delimiters. The delimiters are not part
567      * of the resulting tokens. if delimiters is empty or null, "\n" is used.
568      *
569      * @param text a <code>String</code> value
570      * @param delimiters a <code>String</code> value
571      * @return a <code>List</code> value
572      */

573     public Enumeration JavaDoc tokenize(String JavaDoc text, String JavaDoc delimiters)
574     {
575         if (delimiters == null || delimiters.length() == 0)
576         {
577             delimiters = "\n";
578         }
579
580         if (text == null)
581         {
582             text = "";
583         }
584         
585         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(text, delimiters);
586         return st;
587     }
588
589     public List JavaDoc linkIssueIds(Module module, String JavaDoc text)
590     {
591         List JavaDoc result = null;
592         try
593         {
594             result = IssueIdParser.tokenizeText(module, text);
595         }
596         catch (Exception JavaDoc e)
597         {
598             // return the text as is and log the error
599
result = new ArrayList JavaDoc(1);
600             result.add(text);
601             Log.get().warn("Could not linkify text: " + text, e);
602         }
603         return result;
604     }
605     
606     public SkipFiltering getCommentText(String JavaDoc text, ScarabLink link, Module currentModule)
607     {
608         return this.textToHTML(text, link, currentModule);
609     }
610     
611     /**
612      * <p>Converts a text string to HTML by:</p>
613      * <ul>
614      * <li>replacing reserved characters with equivalent HTML entities</li>
615      * <li>adding hyperlinks for URLs</li>
616      * <li>adding hyperlinks for issue references</li>
617      * </ul>
618      * @param text The text string to convert.
619      * @param link
620      * @param currentModule The active module.
621      * @return A SkipFiltering object which contains the generated HTML.
622      */

623     public SkipFiltering textToHTML(String JavaDoc text,
624                                     ScarabLink link,
625                                     Module currentModule)
626     {
627         SkipFiltering sf = null;
628         try
629         {
630             sf = new SimpleSkipFiltering(ScarabUtil.linkifyText(text,
631                                                                 link,
632                                                                 currentModule));
633         }
634         catch (Exception JavaDoc e)
635         {
636             sf = new SimpleSkipFiltering(text);
637         }
638         return sf;
639     }
640
641     /**
642      * Logs a message at the debug level. Useful for "I am here" type
643      * messages. The category is "org.tigris.scarab".
644      *
645      * @param s message to log
646      */

647     public void log(String JavaDoc s)
648     {
649         LOG.debug(s);
650     }
651
652     /**
653      * Logs a message at the debug level. Useful for "I am here" type
654      * messages. The category in which to log is also specified.
655      *
656      * @param category log4j Category
657      * @param s message to log
658      */

659     public void log(String JavaDoc category, String JavaDoc s)
660     {
661         Logger.getLogger(category).debug(s);
662     }
663
664     /**
665      * Prints a message to standard out. Useful for "I am here" type
666      * messages.
667      *
668      * @param s message to log
669      */

670     public void print(String JavaDoc s)
671     {
672         System.out.println(s);
673     }
674
675     /**
676      * Provides the site name for the top banner.
677      *
678      * @return the configured site name
679      */

680     public String JavaDoc getSiteName()
681     {
682         String JavaDoc siteName =
683             Turbine.getConfiguration().getString("scarab.site.name","");
684
685         if (siteName == null)
686         {
687             siteName = "";
688         }
689         return siteName;
690     }
691
692     /**
693      * Provides the site logo for the top banner.
694      *
695      * @return the configured site logo
696      */

697     public String JavaDoc getSiteLogo()
698     {
699         String JavaDoc siteLogo =
700             Turbine.getConfiguration().getString("scarab.site.logo","");
701
702         if (siteLogo == null)
703         {
704             siteLogo = "";
705         }
706         return siteLogo;
707     }
708
709     /**
710      * Provides the maximum number of public modules to be shown on the
711      * login screen. the number is stored in the property
712      * scarab.public.modules.display.count
713      * If no number is specified, this method returns -1
714      *
715      * @return the number specified in scarab.public.modules.display.count
716      */

717     public int getPublicModulesDisplayCount()
718     {
719         String JavaDoc publicModulesDisplayCount =
720             Turbine.getConfiguration().getString("scarab.public.modules.display.count","-1");
721         return Integer.parseInt(publicModulesDisplayCount);
722     }
723
724     /**
725      * Provides the flag, wether issue store needs valid reason.
726      * Note: This method returns true, when the global variable
727      * was not defined. This may be the case when you migrate from an
728      * older version of scarab to a20++ where this parameter was not
729      * used. Thus per default Scarab makes the field required.
730      *
731      * @return true: yes, valid reason field needed; false: reason field may stay empty.
732      */

733     public boolean isIssueReasonRequired(Module module)
734     {
735         String JavaDoc key = GlobalParameter.ISSUE_REASON_REQUIRED;
736         boolean result = GlobalParameterManager.
737                              getBooleanFromHierarchy(key, module, true);
738         return result;
739     }
740
741     
742     /**
743      * Returns an <code>int</code> representation of the given
744      * <code>Object</code> whose toString method should be a valid integer.
745      * If the <code>String</code> cannot be parsed <code>0</code> is returned.
746      * @param obj the object
747      * @return the <code>int</code> representation of the <code>Object</code>
748      * if possible or <code>0</code>.
749      */

750     public int getInt(Object JavaDoc obj)
751     {
752         int result = 0;
753         if (obj != null)
754         {
755             try
756             {
757                 result = Integer.parseInt(obj.toString());
758             }
759             catch (Exception JavaDoc e)
760             {
761                 Log.get().error(obj + " cannot convert to an integer.", e);
762             }
763         }
764         return result;
765     }
766
767     public int getCALENDAR_YEAR_FIELD()
768     {
769         return Calendar.YEAR;
770     }
771
772     public int getCALENDAR_MONTH_FIELD()
773     {
774         return Calendar.MONTH;
775     }
776
777     public int getCALENDAR_DAY_FIELD()
778     {
779         return Calendar.DAY_OF_MONTH;
780     }
781
782     public int getCALENDAR_HOUR_FIELD()
783     {
784         return Calendar.HOUR_OF_DAY;
785     }
786
787     public Date JavaDoc addApproxOneHour(Date JavaDoc date)
788     {
789         date.setTime(date.getTime() + 3599999);
790         return date;
791     }
792
793     /**
794      * Delegates to Velocity's <code>templateExists()</code> method.
795      */

796     public boolean templateExists(String JavaDoc template)
797     {
798         return ((TurbineVelocityService) TurbineServices
799                 .getInstance().getService(VelocityService.SERVICE_NAME))
800             .templateExists(template);
801     }
802
803     /**
804      * @return
805      */

806     public synchronized static int getModuleCodeLength() {
807         if (moduleCodeLength == 0)
808         {
809             try
810             {
811                 moduleCodeLength = Integer.parseInt(Turbine.getConfiguration().
812                                    getString("scarab.module.code.length", "4"));
813             }
814             catch (Exception JavaDoc e)
815             {
816                 e.printStackTrace();
817                 moduleCodeLength = 4;
818             }
819         }
820         return moduleCodeLength;
821     }
822
823     /**
824      * @return
825      */

826     public static int getModuleCodeLengthPadded() {
827         return getModuleCodeLength() + 6;
828     }
829
830     /**
831      * @return Return the current turbine configuration with all keys included
832      */

833     public org.apache.commons.configuration.Configuration getTurbineConfiguration()
834     {
835         return Turbine.getConfiguration();
836     }
837
838 }
839
Popular Tags