summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/WeblogServlet.java
blob: 4baf05569bfd216b3d779a0719e48ff7db871c35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package org.madore.damlengine;

import java.util.Properties;
import java.util.Enumeration;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Paths;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/* Thinkos about the mess that is tomcat:

 * - Make sure that /usr/share/java/postgresql-jdbc3.jar (or whatever
 *   contains the class org.postgresql.Driver) is symlinked from
 *   /var/lib/tomcat7/common (or some path listed in the common.loader
 *   property of the catalina.properties file).  Similarly,
 *   xercesImpl.jar and probably xml-resolver.jar need to be linked.

 * - The following parameters need to be defined in <init-param> tags
 *   inside the <servlet> block: base_path, template_path, pghost,
 *   pgport, dbname, pguser and pgpass or pgpassfile.

 */

public class WeblogServlet extends HttpServlet {

    private static final long serialVersionUID = 2014100701L;

    @Override
    public void init(ServletConfig cfg)
	throws ServletException
    {
	super.init(cfg);  // Important!
	synchronized ( DamlEngine.class ) { if ( DamlEngine.appProps == null ) {
	    DamlEngine.runAsServlet = true;
	    DamlEngine.appProps = new Properties();
	    for (Enumeration<String> e = cfg.getInitParameterNames() ; e.hasMoreElements() ; ) {
		String k = e.nextElement();
		DamlEngine.appProps.setProperty(k, cfg.getInitParameter(k));
	    }
	    if ( DamlEngine.appProps.getProperty("base_path") != null )
		DamlEngine.basePath = Paths.get(DamlEngine.appProps.getProperty("base_path"));
	    if ( DamlEngine.basePath == null )
		DamlEngine.basePath = Paths.get(getServletContext().getRealPath("/"));
	    if ( DamlEngine.appProps.getProperty("template_path") != null )
		DamlEngine.templatePath = Paths.get(DamlEngine.appProps.getProperty("template_path"));
	    if ( DamlEngine.templatePath == null )
		DamlEngine.templatePath = DamlEngine.basePath.resolve("templates");
	}  }
    }

    @Override
    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {
        response.setContentType("text/html; charset=utf-8");
	response.setCharacterEncoding("UTF-8");
        OutputStream out = response.getOutputStream();
	final int number = 1729;
	try {
	    WeblogSelect.fullProcess(new Context.WeblogSingleSelectionContext(number),
				     out);
	} catch (Exception e) {
	    throw new ServletException("exception during WeblogSelect.fullProcess()", e);
	}

    }
}