1 6 7 package org.contineo.actions.setup; 8 9 import java.io.File ; 10 import java.io.IOException ; 11 import java.util.Iterator ; 12 import java.util.List ; 13 import javax.servlet.http.HttpServletRequest ; 14 import javax.servlet.http.HttpServletResponse ; 15 import org.apache.commons.beanutils.BeanUtils; 16 import org.apache.log4j.Level; 17 import org.apache.log4j.Logger; 18 import org.apache.lucene.analysis.de.GermanAnalyzer; 19 import org.apache.lucene.analysis.fr.FrenchAnalyzer; 20 import org.apache.lucene.analysis.standard.StandardAnalyzer; 21 import org.apache.lucene.index.IndexWriter; 22 import org.apache.struts.action.Action; 23 import org.apache.struts.action.ActionForm; 24 import org.apache.struts.action.ActionForward; 25 import org.apache.struts.action.ActionMapping; 26 import org.contineo.core.FileBean; 27 import org.contineo.core.LoggingManager; 28 import org.contineo.core.XMLBean; 29 import org.contineo.core.config.SettingConfigurator; 30 import org.jdom.Element; 31 36 public class SavePathAction extends Action { 37 38 42 private Logger logger; 43 44 45 46 public SavePathAction() { 47 logger = LoggingManager.getLogger(this.getClass()); 48 } 49 50 public ActionForward execute(ActionMapping mapping, 51 ActionForm form, HttpServletRequest request, 52 HttpServletResponse response) { 53 ActionForward actionForward = new ActionForward(); 54 try { 55 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 56 XMLBean xml = new XMLBean(loader.getResource("settings.xml")); 57 List list = xml.getAllChild("setting", "category", "directory"); 58 Iterator iter = list.iterator(); 59 while (iter.hasNext()) { 60 Element elem = (Element)iter.next(); 61 String value = BeanUtils.getSimpleProperty(form, elem.getAttributeValue("name")); 62 if (!value.endsWith("/") && !value.endsWith("\\")) 63 value += "/"; 64 xml.setText(elem, value); 65 FileBean.createDir(value); 66 } 67 xml.writeXMLDoc(); 68 SettingConfigurator conf = new SettingConfigurator(); 69 String path = conf.getValue("indexdir"); 70 if (!path.endsWith(File.pathSeparator)) 71 path += "/"; 72 try { 73 new IndexWriter(path + "english/" ,new StandardAnalyzer(), true); 74 new IndexWriter(path + "french/" ,new FrenchAnalyzer(), true); 75 new IndexWriter(path + "german/" ,new GermanAnalyzer(), true); 76 } catch (IOException ioe) { 77 if (logger.isEnabledFor(Level.ERROR)) 78 logger.error(ioe.getMessage()); 79 } 80 actionForward.setPath("/InitBackup.do"); 81 } catch (Exception e) { 82 if (logger.isEnabledFor(Level.ERROR)) 83 logger.error(e.getMessage()); 84 actionForward = mapping.findForward("error"); 85 } 86 return actionForward; 87 } 88 } 89 | Popular Tags |