KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

29
30
31 public class SnapperAdmin extends StandardApplication {
32
33     protected static String JavaDoc indexDir;
34     protected static String JavaDoc searcherClassName;
35     protected static String JavaDoc indexerClassName;
36     protected static String JavaDoc xslDirectory;
37     protected static String JavaDoc downloadParameter;
38
39     protected static int maxFieldLength;
40     protected static long maxIndexLength;
41     public static Vector JavaDoc sitesUpdated;
42     public static Vector JavaDoc sitesIndexed;
43     public static Vector JavaDoc sitesLocked;
44     public SnapperManager snapperManager;
45     public Properties JavaDoc prop;
46     FileInputStream JavaDoc fis;
47     private String JavaDoc relm = "SnapperManager";
48     
49     //private String username, password;
50

51     /*
52      * A few methods you might want to add to.
53      * See StandardApplication for more details.
54      */

55     public void startup(Config appConfig) throws ApplicationException {
56           Properties JavaDoc prop = new Properties JavaDoc();
57         try {
58             prop.put("IndexerFactoryClassName", appConfig.getString("Snapper.IndexerFactoryClassName","org.enhydra.snapper.wrapper.lucene.LuceneIndexerFactory"));
59             indexerClassName = appConfig.getString("Snapper.IndexerFactoryClassName","org.enhydra.snapper.wrapper.lucene.LuceneIndexerFactory");
60             prop.put("LoggingManagerClassName", appConfig.getString("Snapper.LoggingManagerClassName","org.enhydra.snapper.logging.StandardLoggingManager"));
61             //username = appConfig.getString("Snapper.Username");
62
//password = appConfig.getString("Snapper.Password");
63
prop.put("LogicalNameFromDatabase", appConfig.getString("Snapper.LogicalNameFromDatabase","0"));
64             prop.put("DocumentLogicalName", appConfig.getString("Snapper.DocumentLogicalName",""));
65             prop.put("DBFetchSize", appConfig.getString("Snapper.DBFetchSize","0"));
66 // if (appConfig.getString("Snapper.TempDir",) != null)
67
prop.put("RelativeIndexPath", appConfig.getString("Snapper.RelativeIndexPath", "false"));
68             prop.put("FileSeparator", appConfig.getString("Snapper.FileSeparator", "system-dependent"));
69             prop.put("TempDir", appConfig.getString("Snapper.TempDir", System.getProperty("user.home")+File.separator+".snapperTemp"));
70 // System.out.println(System.getProperty("user.home")+File.separator+"snapperTemp");
71

72          } catch (ConfigException except) {
73             throw new ApplicationException(except);
74          }
75          
76         //configureFromJar();
77
SnapperManager.getInstance().init(prop);
78
79
80         super.startup(appConfig);
81         // Here is where you would read application-specific settings from
82
// your config file.
83

84         sitesUpdated = new Vector JavaDoc();
85         sitesIndexed = new Vector JavaDoc();
86         sitesLocked = new Vector JavaDoc();
87         
88         try{
89             maxIndexLength = Long.parseLong(appConfig.getString("Snapper.MaxIndexLength"));
90         } catch (ConfigException e) {
91             if (logChannel != null) {
92                 logChannel.write(Logger.INFO, "Snapper.MaxIndexLength application parameter isn't properly initialized!");
93                 
94             }
95         }
96         
97         
98         try{
99             maxFieldLength = Integer.parseInt(appConfig.getString("Snapper.Lucene.MaxFieldLength"));
100         } catch (ConfigException e) {
101             if (logChannel != null) {
102                 logChannel.write(Logger.INFO, "Snapper.Lucene.MaxFieldLength application parameter isn't properly initialized!");
103                 
104             }
105         }
106
107         
108         try{
109             indexDir = appConfig.getString("Snapper.IndexDir");
110         } catch (ConfigException e) {
111             if (logChannel != null) {
112                 logChannel.write(Logger.INFO, "Snapper.IndexDir application parameter isn't properly initialized!");
113                 
114             }
115         }
116                     
117             /*try{
118                 //indexerClassName = appConfig.getString("Snapper.IndexerFactoryClassName");
119             } catch (ConfigException e) {
120                 if (logChannel != null) {
121                     logChannel.write(Logger.INFO, "Snapper.IndexerFactoryClassName application parameter isn't properly initialized!");
122                     
123                 }
124         }*/

125             
126         try{
127             maxIndexLength = Long.parseLong(appConfig.getString("Snapper.MaxIndexLength"));
128         } catch (ConfigException e) {
129             if (logChannel != null) {
130                 logChannel.write(Logger.INFO, "Snapper.MaxIndexLength application parameter isn't properly initialized!");
131                 
132             }
133         }
134         
135                         
136         
137     }
138    
139     public boolean requestPreprocessor(HttpPresentationComms comms)
140                    throws Exception JavaDoc {
141         super.requestPreprocessor(comms);
142       
143        if (comms.session == null) {
144             // Session not setup; so its not a presentation object.
145
return false;
146          }
147    
148          /*
149          * Ensure that the username/password are being sent.
150          * If both the username and password are empty strings, then
151          * do not require a login.
152          */

153      
154 // BasicAuthResult auth = BasicAuth.getAuthentication(comms.request);
155
// if (((username.length() != 0) || (password.length() != 0)) &&
156
// ((auth == null) ||
157
// !username.equals(auth.username) ||
158
// !password.equals(auth.password))) {
159
/*
160              * If they click cancel on the username/password dialog box,
161              * then the browser will show the HTML sent along with the
162              * unauthorized response code. Normally, the user will enter
163              * a username and password, the browser will re-issue the request,
164              * and the user will never see this.
165              */

166 // throw new PageUnauthorizedException(relm);
167
// }
168

169           /*
170            * Since they sent the correct username and password, we know they
171            * are logged in. If there is no user set in the session, then
172            * set it now.
173            */

174         
175         String JavaDoc user = comms.request.getRemoteUser();
176      
177         if(user!=null)
178          {
179          if (comms.session.getUser() == null)
180           {
181             SnapperUser snapperUser = new SnapperUser(user);
182             comms.session.setUser(snapperUser);
183      
184           }
185          }
186           // Proceed normally.
187

188    
189         return false;
190         
191   }
192
193     /**
194      * This is an optional function, used only by the Multiserver's graphical
195      * administration. This bit of HTML appears in the status page for this
196      * application. You could add extra status info, for example
197      * a list of currently logged in users.
198      *
199      * @return HTML that is displayed in the status page of the Multiserver.
200      */

201     public String JavaDoc toHtml() {
202         return "This is <I>Snapper</I>";
203     }
204     
205     public static String JavaDoc getIndexDir() {
206         return indexDir;
207     }
208     
209     public static String JavaDoc getSearcherClassName() {
210         return searcherClassName;
211     }
212     public static String JavaDoc getIdexerClassName() {
213         return indexerClassName;
214     }
215     public static String JavaDoc getXslDirectory() {
216         return xslDirectory;
217     }
218     
219     public static int getmaxFieldLength() {
220         return maxFieldLength;
221     }
222      public static String JavaDoc getDownloadParameter() {
223         return downloadParameter;
224     }
225      
226      public static long getmaxIndexLength() {
227         return maxIndexLength;
228     }
229      
230      public static Vector JavaDoc getSitesLocked() {
231         return sitesLocked;
232     }
233      
234      public static void setSiteLocked(String JavaDoc name) {
235          sitesLocked.add(name);
236          
237     }
238      
239      public static void removeSiteLocked(String JavaDoc name) {
240         sitesLocked.remove(name);
241    }
242      
243      public static void removeAllLocked(){
244         sitesLocked.removeAllElements();
245      }
246      
247      private void configureFromJar () {
248          //String rootDirectoryPath=System.getProperty("user.dir");
249
try {
250            
251             InputStream JavaDoc is =SnapperAdmin.class.getClassLoader().getResourceAsStream("snapperConf.forJar");
252
253             prop=new Properties JavaDoc();
254             prop.load(is);
255
256          } catch (Exception JavaDoc ex) {
257             ex.printStackTrace();
258              System.out.println("Snapper needs to be configured properly - Can't read Snapper's default configuration from JAR!!!");
259          }
260       }
261 }
262
263
Popular Tags