1 package org.jahia.webapps.addressbook; 2 3 import javax.servlet.http.HttpServlet ; 4 import java.io.*; 5 import java.sql.*; 6 import javax.servlet.*; 7 import javax.servlet.http.*; 8 9 10 import org.jdom.input.*; 11 import org.jdom.*; 12 13 import java.security.Security ; 14 import java.net.URLEncoder ; 15 import java.net.URLDecoder ; 16 17 import java.util.*; 18 import org.apache.log4j.PropertyConfigurator; 19 import org.apache.log4j.xml.DOMConfigurator; 20 21 import org.jdom.output.*; 22 import org.jahia.tools.Tools; 23 24 public class InitServlet extends HttpServlet { 25 26 static private String servletDiskPath = null; 27 28 private static org.apache.log4j.Logger logger = 29 org.apache.log4j.Logger.getLogger(InitServlet.class); 30 31 private String dbURL; 32 33 public void init() { 34 35 String prefix = getServletContext().getRealPath("/"); 36 String xmlFile = getInitParameter("log4j-xml-init-file"); 37 if (xmlFile != null) { 39 DOMConfigurator.configure(prefix+xmlFile); 40 } 41 42 logger.debug("Log4j configured, initializing the rest of the WebRaptor..."); 43 44 System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol"); 48 51 String webInfPath = getServletContext().getRealPath("WEB-INF"); 52 53 servletDiskPath = this.getServletContext().getRealPath(File.separator); 54 File repositoryConfigFile = new File(servletDiskPath + "WEB-INF" + File.separator + "classes" + File.separator + "repository.xml"); 55 if (repositoryConfigFile.exists()) { 56 SAXBuilder builder = new SAXBuilder(); 57 try { 58 Document document = builder.build(repositoryConfigFile); 59 if (document != null) { 60 Element rootElement = document.getRootElement(); 61 Element connElement = rootElement.getChild("jdbc-connection-descriptor"); 62 if (connElement != null) { 63 logger.debug("Found <jdbc-connection-descriptor> tag."); 64 String dbAlias = connElement.getAttributeValue("dbalias"); 65 logger.debug("Read dbalias=[" + dbAlias + "]"); 66 if (dbAlias.startsWith("$context/")) { 67 String withoutMarker = dbAlias.substring("$context/".length()); 68 withoutMarker = Tools.replace(withoutMarker, "/", File.separator); 71 logger.debug("Setting OJB dbalis to [" + servletDiskPath + withoutMarker + "]"); 72 connElement.setAttribute("dbalias", servletDiskPath + withoutMarker); 73 } 74 } 75 XMLOutputter serializer = new XMLOutputter(); 76 FileOutputStream repositoryOutput = new FileOutputStream(repositoryConfigFile); 77 serializer.output(document, repositoryOutput); 78 } 79 } catch (org.jdom.JDOMException jdome) { 80 logger.error("Error loading repository configuration file " + repositoryConfigFile.toString(), jdome); 81 } catch (java.io.FileNotFoundException fnfe) { 82 logger.error("Error modifying repository config file " + repositoryConfigFile.toString(), fnfe); 83 } catch (java.io.IOException ioe) { 84 logger.error("Error modifying repository config file " + repositoryConfigFile.toString(), ioe); 85 } 86 } 87 88 } 89 90 public void service(HttpServletRequest request, 91 HttpServletResponse response) 92 throws ServletException, IOException { 93 } 94 95 } | Popular Tags |