1 7 8 package org.enhydra.snapper; 9 10 import java.io.File ; 11 import java.io.FileInputStream ; 12 import java.io.InputStream ; 13 import java.net.URL ; 14 import java.net.URLConnection ; 15 import java.util.Properties ; 16 import java.util.Vector ; 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 27 28 public class Snapper extends StandardApplication { 29 30 protected static String indexDir; 31 protected static String searcherClassName; 32 protected static String xslDirectory; 33 protected static int maxRange = 50; 34 protected static String relativeIndexPath = "false"; 35 protected static String fileSeparator = "system-dependent"; 36 37 38 protected static String simpleSearchType = "Default"; 39 40 public Properties prop; 41 public SnapperManager snapperManager; 42 46 public void startup(Config appConfig) throws ApplicationException { 47 super.startup(appConfig); 48 Properties prop = new Properties (); 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 temp=new File (xslDirectory); 76 77 if(!temp.isDirectory()) 78 { 79 temp=new File (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 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 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 { 146 return super.requestPreprocessor(comms); 147 } 148 149 157 public String toHtml() { 158 return "This is <I>snapper</I>"; 159 } 160 161 public static String getIndexDir() { 162 return indexDir; 163 } 164 165 public static String getSearcherClassName() { 166 return searcherClassName; 167 } 168 public static String getXslDirectory() { 169 return xslDirectory; 170 } 171 172 public static String getSimpleSearchType() { 173 return simpleSearchType; 174 } 175 176 public static int getMaxRange() { 177 return maxRange; 178 } 179 180 public static String getRelativeIndexPath() { 181 return relativeIndexPath; 182 } 183 184 public static String getFileSeparatorConvention() { 185 return fileSeparator; 186 } 187 188 private void configureFromJar () { 189 try { 191 192 InputStream is =Snapper.class.getClassLoader().getResourceAsStream("snapperConf.forJar"); 193 194 prop=new Properties (); 195 prop.load(is); 196 197 } catch (Exception 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 |