KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > snapper > Snapper


1 /*
2  * snapper2
3  *
4  * Enhydra super-servlet
5  *
6  */

7
8 package org.enhydra.snapper;
9
10 import java.io.File JavaDoc;
11 import java.io.FileInputStream JavaDoc;
12 import java.io.InputStream JavaDoc;
13 import java.net.URL JavaDoc;
14 import java.net.URLConnection JavaDoc;
15 import java.util.Properties JavaDoc;
16 import java.util.Vector JavaDoc;
17 import com.lutris.appserver.server.*;
18 import com.lutris.appserver.server.httpPresentation.*;
19 import com.lutris.util.*;
20
21 import com.lutris.logging.Logger;
22 /**
23  * The application object.
24  *
25  * Application-wide data would go here.
26  */

27
28 public class Snapper extends StandardApplication {
29
30     protected static String JavaDoc indexDir;
31     protected static String JavaDoc searcherClassName;
32     protected static String JavaDoc xslDirectory;
33     protected static int maxRange = 50;
34     protected static String JavaDoc relativeIndexPath = "false";
35     protected static String JavaDoc fileSeparator = "system-dependent";
36     
37         
38         protected static String JavaDoc simpleSearchType = "Default";
39     
40     public Properties JavaDoc prop;
41     public SnapperManager snapperManager;
42     /*
43      * A few methods you might want to add to.
44      * See StandardApplication for more details.
45      */

46     public void startup(Config appConfig) throws ApplicationException {
47         super.startup(appConfig);
48         // Here is where you would read application-specific settings from
49
// your config file.
50
// configureFromJar();
51
Properties JavaDoc prop = new Properties JavaDoc();
52         try {
53             prop.put("SearcherFactoryClassName", appConfig.getString("Snapper.SearcherFactoryClassName"));
54             prop.put("LoggingManagerClassName", appConfig.getString("Snapper.LoggingManagerClassName"));
55             
56          } catch (ConfigException except) {
57             throw new ApplicationException(except);
58          }
59   
60          SnapperManager.getInstance().init(prop);
61  
62  
63         try{
64             indexDir = appConfig.getString("Snapper.IndexDir");
65         } catch (ConfigException e) {
66             if (logChannel != null) {
67                 logChannel.write(Logger.INFO, "Snapper.IndexDir application parameter isn't properly initialized!");
68                 
69             }
70         }
71       
72             
73                try{
74                 xslDirectory = appConfig.getString("Snapper.Xsl.Directory");
75                 File JavaDoc temp=new File JavaDoc(xslDirectory);
76                 
77                 if(!temp.isDirectory())
78                 {
79                     temp=new File JavaDoc(appConfig.getConfigFile().getFile().getParent()+File.separator+xslDirectory);
80                 
81                     if(!temp.isDirectory())
82                     {
83                         if (logChannel != null)
84                             logChannel.write(Logger.INFO, "Snapper.xsl.Directory application parameter isn't properly initialized!");
85                        
86                     }
87                    else
88                    {
89                    try{
90                     xslDirectory = temp.getCanonicalPath();
91                    }catch(Exception JavaDoc e){
92                     logChannel.write(Logger.INFO, "Snapper.xsl.Directory application parameter isn't properly initialized!");
93                      }
94                    }
95                 }
96             
97              } catch (ConfigException e) {
98                 if (logChannel != null) {
99                     logChannel.write(Logger.INFO, "Snapper.xsl.Directory application parameter isn't properly initialized!");
100                     
101                 }
102             }
103            
104         
105             
106           try{
107             maxRange = appConfig.getInt("Snapper.MaxRange");
108                 } catch (ConfigException e) {
109                     if (logChannel != null) {
110                         logChannel.write(Logger.INFO, "Snapper.IndexDir application parameter isn't properly initialized!");
111                         
112                     }
113                 }
114                 
115            try{
116             simpleSearchType = appConfig.getString("Snapper.SimpleSearch.Type");
117                 } catch (ConfigException e) {
118                     //if (logChannel != null) {
119
//logChannel.write(Logger.INFO, "Snapper.IndexDir application parameter isn't properly initialized!");
120

121                     }
122           try{
123             relativeIndexPath = appConfig.getString("Snapper.RelativeIndexPath");
124                 } catch (ConfigException e) {
125                     if (logChannel != null) {
126                         logChannel.write(Logger.DEBUG, "Snapper.RelativeIndexPath application parameter isn't properly initialized!");
127                         
128                     }
129                 }
130              
131
132           try{
133             fileSeparator = appConfig.getString("Snapper.FileSeparator");
134                 } catch (ConfigException e) {
135                     if (logChannel != null) {
136                         logChannel.write(Logger.DEBUG, "Snapper.FileSeparator application parameter isn't properly initialized! Default value is used!");
137                         
138                     }
139                 }
140         
141         
142         
143     }
144     public boolean requestPreprocessor(HttpPresentationComms comms)
145                    throws Exception JavaDoc {
146         return super.requestPreprocessor(comms);
147     }
148
149     /**
150      * This is an optional function, used only by the Multiserver's graphical
151      * administration. This bit of HTML appears in the status page for this
152      * application. You could add extra status info, for example
153      * a list of currently logged in users.
154      *
155      * @return HTML that is displayed in the status page of the Multiserver.
156      */

157     public String JavaDoc toHtml() {
158         return "This is <I>snapper</I>";
159     }
160     
161     public static String JavaDoc getIndexDir() {
162         return indexDir;
163     }
164     
165     public static String JavaDoc getSearcherClassName() {
166         return searcherClassName;
167     }
168    public static String JavaDoc getXslDirectory() {
169         return xslDirectory;
170     }
171    
172       public static String JavaDoc getSimpleSearchType() {
173         return simpleSearchType;
174     }
175     
176      public static int getMaxRange() {
177         return maxRange;
178     }
179    
180      public static String JavaDoc getRelativeIndexPath() {
181         return relativeIndexPath;
182     }
183
184      public static String JavaDoc getFileSeparatorConvention() {
185         return fileSeparator;
186     }
187     
188       private void configureFromJar () {
189         //String rootDirectoryPath=System.getProperty("user.dir");
190
try {
191           
192            InputStream JavaDoc is =Snapper.class.getClassLoader().getResourceAsStream("snapperConf.forJar");
193
194            prop=new Properties JavaDoc();
195            prop.load(is);
196
197         } catch (Exception JavaDoc ex) {
198            ex.printStackTrace();
199             System.out.println("Snapper needs to be configured properly - Can't read Snapper's default configuration from JAR!!!");
200         }
201      }
202      
203      
204      
205 }
206
207
Popular Tags