1 17 18 19 20 package org.apache.lenya.lucene; 21 22 import java.io.File ; 23 24 import org.apache.avalon.excalibur.io.FileUtil; 25 import org.apache.lenya.xml.DOMUtil; 26 import org.apache.lenya.xml.DocumentHelper; 27 import org.apache.lenya.xml.XPath; 28 import org.apache.log4j.Category; 29 import org.w3c.dom.Document ; 30 import org.w3c.dom.Element ; 31 32 33 public class IndexConfiguration { 34 static Category log = Category.getInstance(IndexConfiguration.class); 35 private String configurationFilePath; 36 private String update_index_type; 37 private String index_dir; 38 private String htdocs_dump_dir; 39 private Class indexerClass; 40 41 46 public IndexConfiguration(String configurationFilePath) { 47 this.configurationFilePath = configurationFilePath; 48 49 try { 50 File configFile = new File (configurationFilePath); 51 Document document = DocumentHelper.readDocument(configFile); 52 configure(document.getDocumentElement()); 53 } catch (Exception e) { 54 log.error("Cannot load publishing configuration! ", e); 55 System.err.println("Cannot load publishing configuration! " + e); 56 } 57 } 58 59 64 public static void main(String [] args) { 65 if (args.length != 1) { 66 System.err.println("Usage: org.apache.lenya.lucene.IndexConfiguration lucene.xconf"); 67 68 return; 69 } 70 71 IndexConfiguration ic = new IndexConfiguration(args[0]); 72 String parameter; 73 74 parameter = ic.getUpdateIndexType(); 75 System.out.println("Index type: " + parameter); 76 77 parameter = ic.getIndexDir(); 78 System.out.println("Index dir: " + parameter); 79 System.out.println("Index dir (resolved): " + ic.resolvePath(parameter)); 80 81 parameter = ic.getHTDocsDumpDir(); 82 System.out.println("htdocs_dump: " + parameter); 83 System.out.println("htdocs_dump (resolved): " + ic.resolvePath(parameter)); 84 85 System.out.println("Indexer class: " + ic.getIndexerClass()); 86 } 87 88 95 public void configure(Element root) throws Exception { 96 DOMUtil du = new DOMUtil(); 97 update_index_type = du.getAttributeValue(root, new XPath("update-index/@type")); 98 index_dir = du.getAttributeValue(root, new XPath("index-dir/@src")); 99 htdocs_dump_dir = du.getAttributeValue(root, new XPath("htdocs-dump-dir/@src")); 100 101 String indexerClassName = du.getAttributeValue(root, new XPath("indexer/@class")); 102 indexerClass = Class.forName(indexerClassName); 103 } 104 105 110 public String getUpdateIndexType() { 111 log.debug(".getUpdateIndexType(): " + update_index_type); 112 113 return update_index_type; 114 } 115 116 121 public String getIndexDir() { 122 log.debug(".getIndexDir(): " + index_dir); 123 124 return index_dir; 125 } 126 127 132 public String getHTDocsDumpDir() { 133 log.debug(".getHTDocsDumpDir(): " + htdocs_dump_dir); 134 135 return htdocs_dump_dir; 136 } 137 138 143 public Class getIndexerClass() { 144 log.debug(".getIndexerClass(): " + indexerClass); 145 146 return indexerClass; 147 } 148 149 156 public String resolvePath(String path) { 157 158 if ( new File (path) .isAbsolute() ) { 160 return path; 161 } 162 163 try { 166 String configDir = new File (configurationFilePath) .getAbsoluteFile() .getParent(); 167 return new File (configDir, path) .getCanonicalPath(); 168 169 } catch (java.io.IOException e) { 170 e.printStackTrace(); 172 return null; 173 } 174 175 } 176 } 177 | Popular Tags |