1 7 8 package org.enhydra.snapper; 9 10 import java.io.FileInputStream ; 11 import java.io.File ; 12 import java.io.InputStream ; 13 import java.util.Properties ; 14 import java.util.Vector ; 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 29 30 31 public class SnapperAdmin extends StandardApplication { 32 33 protected static String indexDir; 34 protected static String searcherClassName; 35 protected static String indexerClassName; 36 protected static String xslDirectory; 37 protected static String downloadParameter; 38 39 protected static int maxFieldLength; 40 protected static long maxIndexLength; 41 public static Vector sitesUpdated; 42 public static Vector sitesIndexed; 43 public static Vector sitesLocked; 44 public SnapperManager snapperManager; 45 public Properties prop; 46 FileInputStream fis; 47 private String relm = "SnapperManager"; 48 49 51 55 public void startup(Config appConfig) throws ApplicationException { 56 Properties prop = new Properties (); 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 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 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 72 } catch (ConfigException except) { 73 throw new ApplicationException(except); 74 } 75 76 SnapperManager.getInstance().init(prop); 78 79 80 super.startup(appConfig); 81 84 sitesUpdated = new Vector (); 85 sitesIndexed = new Vector (); 86 sitesLocked = new Vector (); 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 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 { 141 super.requestPreprocessor(comms); 142 143 if (comms.session == null) { 144 return false; 146 } 147 148 153 154 166 169 174 175 String 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 188 189 return false; 190 191 } 192 193 201 public String toHtml() { 202 return "This is <I>Snapper</I>"; 203 } 204 205 public static String getIndexDir() { 206 return indexDir; 207 } 208 209 public static String getSearcherClassName() { 210 return searcherClassName; 211 } 212 public static String getIdexerClassName() { 213 return indexerClassName; 214 } 215 public static String getXslDirectory() { 216 return xslDirectory; 217 } 218 219 public static int getmaxFieldLength() { 220 return maxFieldLength; 221 } 222 public static String getDownloadParameter() { 223 return downloadParameter; 224 } 225 226 public static long getmaxIndexLength() { 227 return maxIndexLength; 228 } 229 230 public static Vector getSitesLocked() { 231 return sitesLocked; 232 } 233 234 public static void setSiteLocked(String name) { 235 sitesLocked.add(name); 236 237 } 238 239 public static void removeSiteLocked(String name) { 240 sitesLocked.remove(name); 241 } 242 243 public static void removeAllLocked(){ 244 sitesLocked.removeAllElements(); 245 } 246 247 private void configureFromJar () { 248 try { 250 251 InputStream is =SnapperAdmin.class.getClassLoader().getResourceAsStream("snapperConf.forJar"); 252 253 prop=new Properties (); 254 prop.load(is); 255 256 } catch (Exception 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 |