KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > admingui > util > Util


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.tools.admingui.util;
25
26 import com.iplanet.jato.*;
27 import com.iplanet.jato.view.*;
28 import com.iplanet.jato.view.event.*;
29 import com.iplanet.jato.view.html.*;
30 import com.iplanet.jato.model.*;
31 import com.sun.web.ui.common.CCI18N;
32
33 import com.sun.enterprise.tools.admingui.AdminGUIConstants;
34 import com.sun.enterprise.tools.admingui.tree.IndexTreeNode;
35 import com.sun.enterprise.tools.admingui.tree.IndexTreeModelImpl;
36 import com.sun.enterprise.tools.admingui.tree.MonitorTreeModelImpl;
37 import com.sun.enterprise.tools.admingui.tree.IndexTreeModel;
38 import com.sun.enterprise.tools.guiframework.exception.FrameworkException;
39
40 import java.io.File JavaDoc;
41 import java.io.IOException JavaDoc;
42 import java.io.FileNotFoundException JavaDoc;
43 import java.io.StringWriter JavaDoc;
44 import java.io.FileReader JavaDoc;
45 import java.io.EOFException JavaDoc;
46
47 import java.util.Locale JavaDoc;
48 import java.util.List JavaDoc;
49 import java.util.Vector JavaDoc;
50 import java.util.HashMap JavaDoc;
51 import java.util.StringTokenizer JavaDoc;
52 import java.util.logging.Level JavaDoc;
53 import java.util.logging.Logger JavaDoc;
54 import java.util.ResourceBundle JavaDoc;
55 import java.util.MissingResourceException JavaDoc;
56 import java.util.Date JavaDoc;
57
58 import java.net.URLEncoder JavaDoc;
59 import java.text.MessageFormat JavaDoc;
60 import java.text.DateFormat JavaDoc;
61
62 import javax.servlet.ServletContext JavaDoc;
63 import javax.servlet.http.HttpServletRequest JavaDoc;
64
65 // For now o.k. Ask backend support when we move to common console.
66
import com.sun.enterprise.util.SystemPropertyConstants;
67
68 public class Util {
69     
70     public static String JavaDoc getMessage(String JavaDoc key) {
71        CCI18N i18n = null;
72        RequestContext ctx = RequestManager.getRequestContext();
73        i18n = (CCI18N)ctx.getRequest().getAttribute("__i18nObject");
74        if (i18n == null) {
75            i18n = new CCI18N(ctx, "com.sun.enterprise.tools.admingui.resources.Resources");
76            ctx.getRequest().setAttribute("__i18nObject", i18n);
77        }
78        return i18n.getMessage(key);
79     }
80     
81     public static String JavaDoc getMessage(String JavaDoc key, Object JavaDoc args[]) {
82        CCI18N i18n = null;
83        RequestContext ctx = RequestManager.getRequestContext();
84        i18n = (CCI18N)ctx.getRequest().getAttribute("__i18nObject");
85        if (i18n == null) {
86            i18n = new CCI18N(ctx, "com.sun.enterprise.tools.admingui.resources.Resources");
87            ctx.getRequest().setAttribute("__i18nObject", i18n);
88             
89         }
90         return i18n.getMessage(key, args);
91    }
92
93     public static void setCurrentTreeModelType(RequestContext rc, String JavaDoc modelType) {
94         rc.getRequest().getSession().setAttribute(TREE_MODEL_TYPE, modelType);
95     }
96     
97     public static String JavaDoc getCurrentTreeModelType(RequestContext rc) {
98         String JavaDoc modelType = (String JavaDoc) rc.getRequest().getSession().getAttribute(TREE_MODEL_TYPE);
99         if (modelType == null)
100             modelType = DEFAULT_TREE_MODEL_TYPE;
101         return modelType;
102     }
103     
104     public static IndexTreeModel getCurrentTreeModel() {
105         RequestContext rc = RequestManager.getRequestContext();
106         String JavaDoc modelType = getCurrentTreeModelType(rc);
107         
108         if (modelType.equals("index")) {
109             return IndexTreeModelImpl.getIndexTreeModel(rc);
110         } else if (modelType.equals("monitor")) {
111             return MonitorTreeModelImpl.getIndexTreeModel(rc);
112         }
113         throw new RuntimeException JavaDoc("Invalid model type specified.");
114     }
115     
116     // these methods set and get the right-side view for returning to when switching treees.
117
public static void setCurrentViewURL(String JavaDoc viewName) {
118         RequestContext rc = RequestManager.getRequestContext();
119         rc.getRequest().getSession().setAttribute(
120             getCurrentTreeModelType(rc), viewName);
121     }
122     
123     public static String JavaDoc getCurrentViewURL(RequestContext rc) {
124         if (rc == null)
125             rc = RequestManager.getRequestContext();
126         String JavaDoc view = (String JavaDoc) rc.getRequest().getSession().getAttribute(
127             getCurrentTreeModelType(rc));
128         return (view == null)?(""):(view);
129     }
130     
131     public static final IndexTreeNode getSelectedNode() {
132         RequestContext rc = RequestManager.getRequestContext();
133     IndexTreeNode selectedNode = (IndexTreeNode)
134             rc.getRequest().getSession().getAttribute(
135                 getCurrentTreeModelType(rc)+SELECTEDNODE);
136         
137         // if not in session, try the model.
138
if (selectedNode == null) {
139             IndexTreeModel model = getCurrentTreeModel();
140             selectedNode = ((IndexTreeNode)model.getCurrentNode());
141             if (selectedNode == null) {
142                 // avoid returning null, so return the root.
143
selectedNode = model.getRoot();
144             }
145         }
146         return selectedNode;
147     }
148     
149     public static void setSelectedNode(IndexTreeNode selectedNode) {
150         RequestContext rc = RequestManager.getRequestContext();
151     rc.getRequest().getSession().setAttribute(
152             getCurrentTreeModelType(rc)+SELECTEDNODE, selectedNode);
153     }
154     
155     public static String JavaDoc URLencode(RequestContext ctx, String JavaDoc str) {
156         String JavaDoc encoding = ctx.getResponse().getCharacterEncoding() != null ?
157             ctx.getResponse().getCharacterEncoding() : CCI18N.ISO_ENCODING;
158         try {
159             str = URLEncoder.encode(str, encoding);
160         } catch (java.io.UnsupportedEncodingException JavaDoc ex) {
161         }
162         return str;
163     }
164     
165     /**
166      * This method concatenates the delimiter char to the end of each string
167      * in the array, and returns a single string with the concatenated string.
168      */

169     
170     public static String JavaDoc concatDelimiter(String JavaDoc[] str, String JavaDoc delimiter){
171     StringBuffer JavaDoc retStr = new StringBuffer JavaDoc();
172     
173     if(str != null) {
174         for (int i=0; i < str.length; i++) {
175         String JavaDoc element = str[i];
176         
177         if (element == null || element.length() == 0) {
178             throw new IllegalArgumentException JavaDoc();
179         }
180         retStr.append(element);
181         
182         if (i < str.length - 1) {
183             retStr.append(delimiter);
184         }
185         }
186     }
187     
188     return retStr.toString();
189     
190     }
191     
192     /**
193      * This method converts a string into stringarray, uses the delimeter as the
194      * separator character. If the delimiter is null, uses space as default.
195      */

196     
197     public static String JavaDoc[] stringToArray(String JavaDoc str, String JavaDoc delimiter) {
198     String JavaDoc[] retString = new String JavaDoc[0];
199     
200     if (str != null) {
201         if(delimiter == null) {
202         delimiter = " ";
203         }
204         StringTokenizer JavaDoc tokens = new StringTokenizer JavaDoc(str, delimiter);
205         retString = new String JavaDoc[tokens.countTokens()];
206         int i = 0;
207         while(tokens.hasMoreTokens()) {
208         retString[i++] = tokens.nextToken();
209         }
210     }
211     return retString;
212     }
213     
214     /**
215      * This method converts String array into HashMap, uses the elements in the array as key.
216      */

217     
218     public static HashMap JavaDoc stringArrayToHashMap(String JavaDoc[] str) {
219     HashMap JavaDoc h = new HashMap JavaDoc();
220     
221     for (int i=0; str != null && i < str.length; i++) {
222         h.put(str[i], str[i]);
223     }
224     return h;
225     }
226     
227     public static String JavaDoc getDefaultDisplayURL(String JavaDoc url) {
228     if (isLoggableFINER()) {
229         logFINER("URL = "+AdminGUIConstants.DEFAULT_DISPLAY_URL_DIR+url);
230     }
231     return AdminGUIConstants.DEFAULT_DISPLAY_URL_DIR+url;
232     }
233
234     public static String JavaDoc getLocalizedURL(RequestContext rc, String JavaDoc fileName) {
235         return getLocalizedURL(rc, fileName, null);
236     }
237     
238     public static String JavaDoc getLocalizedURL(RequestContext rc, String JavaDoc fileName, Locale JavaDoc locale) {
239     if(locale == null) {
240         locale = getLocale();
241     }
242     if (locale.equals(Locale.ENGLISH) || locale.getLanguage().equals("en"))
243         return fileName;
244     
245     int lastdot = fileName.lastIndexOf(".");
246     String JavaDoc newName = fileName.substring(0,lastdot)+"_"+locale.getLanguage() +
247     fileName.substring(lastdot,fileName.length());
248     
249     try {
250         verifyClassExists(rc.getServletContext(), newName);
251     } catch (ClassNotFoundException JavaDoc ex) {
252         // don't return a localized version, use the given version
253
return fileName;
254     }
255     return newName;
256     }
257     
258     public static String JavaDoc getLocalizedString(String JavaDoc key) {
259     return key;
260     }
261     
262     private static void verifyClassExists(ServletContext JavaDoc sc, String JavaDoc fileName) throws ClassNotFoundException JavaDoc {
263     String JavaDoc className = null;
264     if (fileName.endsWith(".jsp")) {
265         className = fileName.substring(0,fileName.lastIndexOf(".jsp"))+"_jsp";
266         className = className.replaceAll("/", "._");
267         className = "_jasper"+className;
268         
269         try {
270         Class JavaDoc clazz = Class.forName(className);
271         return;
272         } catch (ClassNotFoundException JavaDoc ex) {
273         } catch (Exception JavaDoc ex) {
274         }
275     }
276     if (sc != null) {
277         // look for the file itself
278
String JavaDoc path = sc.getRealPath(fileName);
279         File JavaDoc f = new File JavaDoc(path);
280         if (f.exists() == false) {
281         String JavaDoc msg = "";
282         if (className != null) {
283             msg = "Class \""+className+"\" not found, and";
284         }
285         msg += "File \""+path+"\" not found!";
286         throw new ClassNotFoundException JavaDoc(msg);
287         }
288     } else {
289         throw new FrameworkException("sc null");
290     }
291     }
292
293
294     //
295
// The following are helper methods for sending messages to the log file.
296
// Here is a description of how the variouis log levels should be used:
297
//
298
// SEVERE -- When an unrecoverable GUI error occurs. This does NOT
299
// include errors thrown from the backend. This should only
300
// be thrown if something unexpected in our GUI code occurs.
301
// These errors should NOT be thrown if the AdminGUI itself
302
// does not have a problem. The administrator should react to
303
// these messages to fix the problem or file a bug against the
304
// AdminGUI.
305
//
306
// WARNING -- A less severe GUI error. This does NOT include errors
307
// thrown from the backend. These errors may be generated
308
// from edge cases that we don't support or may be bugs or
309
// admin GUI configuration problems. The administrator may
310
// want to look into these, but most likely this error is
311
// something that was preventable by the user.
312
//
313
// INFO -- This level is appropriate if a requested business action
314
// cannot be completed due to an error. If the backend fails,
315
// expected business information does not exist, or invalid
316
// data is passed in, this would be the appropriate Log level.
317
// This level is visible by default, yet it does not indicate a
318
// problem with the system (NOTE: if the backend fails for a
319
// more severe reason, the backend is responsible for logging
320
// the problem). Business logic exceptions and messages should
321
// mostly be logged at this level.
322
//
323
// CONFIG -- This log level should be used to display high-level success
324
// or informational messages. For example, when invoking an
325
// MBean, you might want to log some information about the
326
// result at this level. This should be business-logic
327
// oriented and not meant to be useful for tracing the flow of
328
// the application.
329
//
330
// FINE -- This log level should be used to trace course information.
331
// For example, a page or model has been loaded.
332
//
333
// FINER -- This log level should be used to trace more detailed
334
// information such as a field-level tracing, or method level
335
// tracing.
336
//
337
// FINEST -- This log level should be used for very detailed log
338
// information, this level should be used whenever you log
339
// specific information to assist debugging exactly what is
340
// going on. This information should be developer oriented and
341
// is not intended to be useful to the end user.
342
//
343

344     // SEVERE helper log methods
345
public static boolean isLoggableSEVERE() {
346     return sLogger.isLoggable(Level.SEVERE);
347     }
348
349     public static void logSEVERE(String JavaDoc msg) {
350     sLogger.log(Level.SEVERE, msg);
351     }
352
353     public static void logSEVERE(Throwable JavaDoc ex) {
354     logSEVERE("", ex);
355     }
356
357     public static void logSEVERE(String JavaDoc msg, Throwable JavaDoc ex) {
358     sLogger.log(Level.SEVERE, msg, ex);
359     }
360
361     // WARNING helper log methods
362
public static boolean isLoggableWARNING() {
363     return sLogger.isLoggable(Level.WARNING);
364     }
365
366     public static void logWARNING(String JavaDoc msg) {
367     sLogger.log(Level.WARNING, msg);
368     }
369
370     public static void logWARNING(Throwable JavaDoc ex) {
371     logWARNING("", ex);
372     }
373
374     public static void logWARNING(String JavaDoc msg, Throwable JavaDoc ex) {
375     sLogger.log(Level.WARNING, msg, ex);
376     }
377
378     // INFO helper log methods
379
public static boolean isLoggableINFO() {
380     return sLogger.isLoggable(Level.INFO);
381     }
382
383     public static void logINFO(String JavaDoc msg) {
384     sLogger.log(Level.INFO, msg);
385     }
386
387     public static void logINFO(Throwable JavaDoc ex) {
388     logINFO("", ex);
389     }
390
391     public static void logINFO(String JavaDoc msg, Throwable JavaDoc ex) {
392     sLogger.log(Level.INFO, msg, ex);
393     }
394
395     // CONFIG helper log methods
396
public static boolean isLoggableCONFIG() {
397     return sLogger.isLoggable(Level.CONFIG);
398     }
399
400     public static void logCONFIG(String JavaDoc msg) {
401     sLogger.log(Level.CONFIG, msg);
402     }
403
404     public static void logCONFIG(Throwable JavaDoc ex) {
405     logCONFIG("", ex);
406     }
407
408     public static void logCONFIG(String JavaDoc msg, Throwable JavaDoc ex) {
409     sLogger.log(Level.CONFIG, msg, ex);
410     }
411
412     // FINE helper log methods
413
public static boolean isLoggableFINE() {
414     return sLogger.isLoggable(Level.FINE);
415     }
416
417     public static void logFINE(String JavaDoc msg) {
418     sLogger.log(Level.FINE, msg);
419     }
420
421     public static void logFINE(Throwable JavaDoc ex) {
422     logFINE("", ex);
423     }
424
425     public static void logFINE(String JavaDoc msg, Throwable JavaDoc ex) {
426     sLogger.log(Level.FINE, msg, ex);
427     }
428
429     // FINER helper log methods
430
public static boolean isLoggableFINER() {
431     return sLogger.isLoggable(Level.FINER);
432     }
433
434     public static void logFINER(String JavaDoc msg) {
435     sLogger.log(Level.FINER, msg);
436     }
437
438     public static void logFINER(Throwable JavaDoc ex) {
439     logFINER("", ex);
440     }
441
442     public static void logFINER(String JavaDoc msg, Throwable JavaDoc ex) {
443     sLogger.log(Level.FINER, msg, ex);
444     }
445
446     // FINEST helper log methods
447
public static boolean isLoggableFINEST() {
448     return sLogger.isLoggable(Level.FINEST);
449     }
450
451     public static void logFINEST(String JavaDoc msg) {
452     sLogger.log(Level.FINEST, msg);
453     }
454
455     public static void logFINEST(Throwable JavaDoc ex) {
456     logFINEST("", ex);
457     }
458
459     public static void logFINEST(String JavaDoc msg, Throwable JavaDoc ex) {
460     sLogger.log(Level.FINEST, msg, ex);
461     }
462
463     public static String JavaDoc getLocalizedHTML(RequestContext rc, String JavaDoc fileName) {
464         return getLocalizedHTML(rc, fileName, null);
465     }
466     public static String JavaDoc getLocalizedHTML(RequestContext rc, String JavaDoc fileName, Locale JavaDoc locale) {
467     if (locale == null) {
468         locale = getLocale();
469     }
470     if (locale.equals(Locale.ENGLISH) ||
471             locale.getLanguage() == null ||
472             locale.getLanguage().equalsIgnoreCase("null") ||
473             locale.getLanguage().equals("en")) {
474                 return fileName;
475     }
476         
477     int lastdot = fileName.lastIndexOf(".html");
478     String JavaDoc newName = fileName.substring(0,lastdot)+"_"+locale.getLanguage()+".html";
479
480     String JavaDoc path = rc.getServletContext().getRealPath(newName);
481     File JavaDoc f = new File JavaDoc(path);
482
483     if (!(f.exists())) {
484         if (isLoggableWARNING()) {
485         logWARNING("AdminGUI: "+path+" File Not Found");
486         }
487         return fileName;
488     }
489     return newName;
490     }
491     
492     //Use this API if you can't use the CI18N provided by lockhart. Most of our localization
493
//can be done using CI18N, using this just for deployment screens.
494
public static String JavaDoc getMessage(String JavaDoc baseName, String JavaDoc key, Object JavaDoc[] args) {
495     return getMessage(baseName, key, args, null);
496     }
497     
498
499     public static String JavaDoc getMessage(String JavaDoc baseName, String JavaDoc key, Object JavaDoc[] args, Locale JavaDoc locale) {
500     if (key == null) {
501         return null;
502     }
503     if(locale == null) {
504         locale = getLocale();
505     }
506     ResourceBundle JavaDoc bundle = getResourceBundle(baseName, locale);
507
508     if(args == null) {
509         return getMessageFromBundle(key, bundle);
510     }
511     String JavaDoc pattern = getMessageFromBundle(key, bundle);
512     MessageFormat JavaDoc mf = new MessageFormat JavaDoc(pattern);
513     
514     Object JavaDoc[] mfArgs = new Object JavaDoc[args.length];
515     for(int i = 0; i < args.length; i++) {
516         mfArgs[i] = getMessageFromBundle(args[i].toString(), bundle);
517     }
518     
519     key = mf.format(mfArgs);
520     return key;
521     }
522
523     // Once the bugid: 6192814 is fixed in lockhart CCI18N, change
524
// the below getLocale() method to use CCI18N. This is just a
525
// temporary fix for bugid: 6191081
526

527     private static Locale JavaDoc getLocale() {
528         RequestContext ctx = RequestManager.getRequestContext();
529         Locale JavaDoc locale = null;
530         if(ctx != null) {
531             HttpServletRequest JavaDoc request = ctx.getRequest();
532                         //FIXME: temporary workaround. jato context is lost
533
//in new redeploy.jsp when a non-jato RedeployServlet is
534
//called. Catch java.lang.IllegalStateException: Null request object
535
//from org.apache.coyote.tomcat5.CoyoteRequestFacade.getLocale.
536
//Use the Locale.getDefault() instead.
537
try {
538                             locale = request.getLocale();
539                         } catch (Exception JavaDoc ex) {
540                             locale = Locale.getDefault();
541                         }
542         }
543         return (locale == null ? Locale.getDefault() : locale);
544     }
545
546      public static String JavaDoc fileReader(String JavaDoc fileName) throws FileNotFoundException JavaDoc, IOException JavaDoc {
547     StringWriter JavaDoc sr = new StringWriter JavaDoc();
548     try {
549         FileReader JavaDoc fr = new FileReader JavaDoc(fileName);
550         
551         char[] buf = new char[1024];
552         int len = 0;
553         while (len != -1) {
554             try {
555                 len = fr.read(buf, 0, buf.length);
556             } catch (EOFException JavaDoc eof) {
557                 break;
558             }
559             if (len != -1) {
560                 sr.write(buf, 0, len);
561             }
562         }
563
564         fr.close();
565         sr.close();
566
567     } catch (FileNotFoundException JavaDoc fnfe) {
568         //We may never reach here, it's better to get this from the properties file.
569
throw fnfe;
570         //logWARNING("Please check whether the file "+fileName +" exists, and is readable");
571
//sr.write("Please check whether the file "+fileName +" exists, and is readable");
572
//System.out.println("FileNotFoundException ...");
573
}
574     catch (IOException JavaDoc ioe) {
575         throw ioe;
576         //We may never reach here, it's better to get this from the properties file.
577
//logWARNING("IOException in Util.fileReader:"+fileName);
578
}
579     return sr.toString();
580     }
581      
582     public static boolean isEmpty(String JavaDoc str) {
583         if (str == null)
584             return true;
585         if (str.trim().length() == 0)
586             return true;
587         return false;
588     }
589      
590     private static String JavaDoc getMessageFromBundle(String JavaDoc key, ResourceBundle JavaDoc bundle) {
591     try {
592         key = bundle.getString(key);
593     }
594     catch (MissingResourceException JavaDoc ex) {
595     }
596     return key;
597     }
598     private static ResourceBundle JavaDoc getResourceBundle(String JavaDoc baseName, Locale JavaDoc locale) {
599     ResourceBundle JavaDoc bundle = null;
600     try {
601         bundle = ResourceBundle.getBundle(baseName, locale);
602     }
603     catch(MissingResourceException JavaDoc ex) {
604         try {
605         bundle = ResourceBundle.getBundle(baseName);
606         }
607         catch(MissingResourceException JavaDoc ex1) {
608         //returns the default ResourceBundle
609
bundle = ResourceBundle.getBundle("com.sun.enterprise.tools.admingui.resources.Resources");
610         }
611     }
612     return bundle;
613     }
614
615     // three methods to manipulate a HTML string generated for a tag.
616
public static String JavaDoc addHtmlProp(String JavaDoc tag, String JavaDoc addText) {
617         int i = tag.indexOf(' ');
618         if (i<0)
619             return tag;
620         return tag.substring(0,i) + " " + addText + tag.substring(i,tag.length());
621     }
622     
623     
624     public static String JavaDoc removeHtmlProp(String JavaDoc tag, String JavaDoc prop) {
625         int i = tag.indexOf(prop);
626         if (i<0) return tag;
627         int j = tag.indexOf('\"', i+2+prop.length());
628         if (j<0) return tag;
629         
630         
631         
632         //At this point, j is pointing to the end quote. doing the substring(j+1, tag.length()) should
633
//be enough to remove that property. We shouldn't remove one extra char.
634
//bug# 6315465, the tag is of the form <a HREF="../admingui/links?links.childPageLink=_VALUE_&amp;jato.pageSession=" name="links.childPageLink">__0__</a>
635
//removing one extra char means removing the ending '>', causing a missing end tag and the links doesn't appear.
636

637         /*
638         if(j+2 == tag.length()) {
639             return tag.substring(0,i) + tag.substring(j+1, tag.length());
640         } else {
641             return tag.substring(0,i) + tag.substring(j+2, tag.length());
642         }
643          */

644         
645         return tag.substring(0,i) + tag.substring(j+1, tag.length());
646         
647         
648     }
649     
650     public static String JavaDoc extractHtmlProp(String JavaDoc tag, String JavaDoc prop) {
651          int i = tag.indexOf(prop);
652          if (i<0) return "";
653          int j = tag.indexOf('\"', i+2+prop.length());
654          if (j<0) return "";
655          return tag.substring(i+2+prop.length(), j);
656     }
657     
658     /**
659      * Parses a string containing substrings separated from
660      * each other by the standard separator characters and returns
661      * a list of strings.
662      *
663      * Splits the string <code>line</code> into individual string elements
664      * separated by the field separators, and returns these individual
665      * strings as a list of strings. The individual string elements are
666      * trimmed of leading and trailing whitespace. Only non-empty strings
667      * are returned in the list.
668      *
669      * @param line The string to split
670      * @return Returns the list containing the individual strings that
671      * the input string was split into.
672      */

673     public static List JavaDoc parseStringList(String JavaDoc line)
674     {
675         return parseStringList(line, null);
676     }
677
678     /**
679      * Parses a string containing substrings separated from
680      * each other by the specified set of separator characters and returns
681      * a list of strings.
682      *
683      * Splits the string <code>line</code> into individual string elements
684      * separated by the field separators specified in <code>sep</code>,
685      * and returns these individual strings as a list of strings. The
686      * individual string elements are trimmed of leading and trailing
687      * whitespace. Only non-empty strings are returned in the list.
688      *
689      * @param line The string to split
690      * @param sep The list of separators to use for determining where the
691      * string should be split. If null, then the standard
692      * separators (see StringTokenizer javadocs) are used.
693      * @return Returns the list containing the individual strings that
694      * the input string was split into.
695      */

696     public static List JavaDoc parseStringList(String JavaDoc line, String JavaDoc sep)
697     {
698         if (line == null)
699             return null;
700
701         StringTokenizer JavaDoc st;
702         if (sep == null)
703             st = new StringTokenizer JavaDoc(line);
704         else
705             st = new StringTokenizer JavaDoc(line, sep);
706
707         String JavaDoc token;
708
709         List JavaDoc tokens = new Vector JavaDoc();
710         while (st.hasMoreTokens())
711         {
712             token = st.nextToken().trim();
713             if (token.length() > 0)
714                 tokens.add(token);
715         }
716
717         return tokens;
718     }
719
720     public static String JavaDoc getFormattedDate(long time, int dateStyle) {
721     DateFormat JavaDoc df = DateFormat.getDateTimeInstance(dateStyle, DateFormat.MEDIUM, getLocale());
722     String JavaDoc formattedDate = df.format(new Date JavaDoc(time));
723     return formattedDate;
724     }
725
726     public static String JavaDoc getDomainRoot() {
727         String JavaDoc domainRoot = System.getProperty(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY);
728         return domainRoot;
729     }
730
731     private static final String JavaDoc SELECTEDNODE = "selectedNode";
732     private static final String JavaDoc TREE_MODEL_TYPE = "treeModelType";
733     public static final String JavaDoc DEFAULT_TREE_MODEL_TYPE = "index";
734     public static final Logger JavaDoc sLogger = Logger.getLogger(AdminGUIConstants.LOGGER_NAME);
735 }
736
Popular Tags