KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > workflow > designer > ResourceManager


1 package com.opensymphony.workflow.designer;
2
3 import java.io.*;
4 import java.util.ResourceBundle JavaDoc;
5 import javax.swing.*;
6
7 import com.opensymphony.workflow.designer.swing.EnhancedResourceBundle;
8
9 public final class ResourceManager
10 {
11   private static final ResourceManager INSTANCE = new ResourceManager();
12
13   private EnhancedResourceBundle bundle;
14
15   private ResourceManager()
16   {
17     bundle = new EnhancedResourceBundle("com.opensymphony.workflow.designer.resources");
18   }
19
20   public static ResourceBundle JavaDoc getBundle()
21   {
22     return INSTANCE.bundle.getBundle();
23   }
24
25   public static String JavaDoc getString(String JavaDoc key)
26   {
27       return getString(key, key);
28   }
29
30     public static String JavaDoc getString(String JavaDoc key, String JavaDoc defaultValue)
31     {
32         return INSTANCE.bundle.getString(key, defaultValue);
33     }
34
35   public static String JavaDoc getString(String JavaDoc key, Object JavaDoc args)
36   {
37       return INSTANCE.bundle.getString(key, args);
38   }
39
40   public static ImageIcon getIcon(String JavaDoc key)
41   {
42       return INSTANCE.bundle.getIcon(key);
43   }
44
45   public static InputStream getInputStream(String JavaDoc path)
46   {
47     return INSTANCE.bundle.getInputStream(path);
48   }
49
50   public static ImageIcon readImageIcon(String JavaDoc path)
51   {
52       return INSTANCE.bundle.readImageIcon(path);
53   }
54
55   public static String JavaDoc readTextFromFile(String JavaDoc path)
56   {
57     InputStream in = getInputStream(path);
58     if(null == in)
59       return null;
60     BufferedReader reader = new BufferedReader(new InputStreamReader(in));
61     StringBuffer JavaDoc result = new StringBuffer JavaDoc();
62     try
63     {
64       String JavaDoc line = reader.readLine();
65       while(line != null)
66       {
67         result.append(line);
68         line = reader.readLine();
69         if(line != null)
70           result.append('\n');
71       }
72       return result.toString();
73     }
74     catch(IOException e)
75     {
76       return null;
77     }
78     finally
79     {
80       try
81       {
82         reader.close();
83       }
84       catch(IOException e)
85       {
86       }
87     }
88   }
89 }
Popular Tags