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