Stephan Richter
3 years ago
6 changed files with 125 additions and 43 deletions
@ -0,0 +1,19 @@
@@ -0,0 +1,19 @@
|
||||
package de.srsoftware.widerhall.web; |
||||
|
||||
import javax.servlet.ServletException; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.IOException; |
||||
import java.util.Map; |
||||
|
||||
public class Front extends TemplateServlet { |
||||
|
||||
private static final String FRONT = "frontpage"; |
||||
|
||||
@Override |
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { |
||||
loadTemplates(); |
||||
String error = loadTemplate(FRONT, Map.of(),resp); |
||||
if (error != null) resp.sendError(400,error); |
||||
} |
||||
} |
@ -0,0 +1,57 @@
@@ -0,0 +1,57 @@
|
||||
package de.srsoftware.widerhall.web; |
||||
|
||||
import de.srsoftware.widerhall.Configuration; |
||||
import org.stringtemplate.v4.STGroup; |
||||
import org.stringtemplate.v4.STRawGroupDir; |
||||
|
||||
import javax.servlet.http.HttpServlet; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
import java.nio.file.Files; |
||||
import java.util.Map; |
||||
|
||||
import static de.srsoftware.widerhall.Util.t; |
||||
|
||||
public abstract class TemplateServlet extends HttpServlet { |
||||
private STGroup templates; |
||||
private final String baseDir; |
||||
|
||||
public TemplateServlet(){ |
||||
var config = Configuration.instance(); |
||||
baseDir = config.baseDir(); |
||||
loadTemplates(); |
||||
} |
||||
|
||||
protected String loadFile(String filename, HttpServletResponse resp) { |
||||
var path = String.join(File.separator,baseDir,"static",filename); |
||||
var file = new File(path); |
||||
if (!file.exists()) return t("File {} does not exist!",filename); |
||||
try { |
||||
var content = Files.readString(file.toPath()); |
||||
resp.getWriter().println(content); |
||||
} catch (IOException e) { |
||||
return t("Failed to load file '{}'!",filename); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
protected String loadTemplate(String path, Map<String, ? extends Object> data, HttpServletResponse resp) { |
||||
var template = templates.getInstanceOf(path); |
||||
if (template != null){ |
||||
try { |
||||
template.add("data",data); |
||||
resp.getWriter().println(template.render()); |
||||
return null; |
||||
} catch (IOException e) { |
||||
return t("Failed to load template '{}'",path); |
||||
} |
||||
} |
||||
return t("No template for path '{}'!",path); |
||||
} |
||||
|
||||
protected void loadTemplates() { |
||||
var templateDir = String.join(File.separator,baseDir,"static","templates"); |
||||
templates = new STRawGroupDir(templateDir,'«','»'); |
||||
} |
||||
} |
@ -0,0 +1,40 @@
@@ -0,0 +1,40 @@
|
||||
<!DOCTYPE html> |
||||
<html> |
||||
<head> |
||||
<meta charset="utf-8" /> |
||||
<link rel="stylesheet" href="css" /> |
||||
</head> |
||||
<body id="login"> |
||||
<h1>Widerhall front page</h1> |
||||
If you are looking for you mailing lists, <a href="web/index">Go to the /web page</a>... |
||||
<fieldset> |
||||
<legend>What is <em>Widerhall</em>?</legend> |
||||
<p> |
||||
Widerhall is a mailing list system written in Java. |
||||
It allows to maintain a set of mailing lists with the option to make (some of) them publicy subscribable. |
||||
</p> |
||||
<p> |
||||
<em>Widerhall</em> is very lightweight, as does not include a full email server stack. |
||||
</p> |
||||
</fieldset> |
||||
<fieldset> |
||||
<legend>Why should I use <em>Widerhall</em>?</legend> |
||||
<p> |
||||
Compared to other mailing list systems, widerhall is very lightweight: |
||||
<p> |
||||
It contains not mailserver stack. It does not even require you to set up a mailserver! |
||||
</p> |
||||
</fieldset> |
||||
<fieldset> |
||||
<legend>How does it work?</legend> |
||||
<p> |
||||
Widerhall works by just letting you set up any IMAP/SMTP enabled email address with a provider of your choice. |
||||
It then connects to the inbox of you selected email address and watches for incoming messages. |
||||
Upon message reception, it forwards the message to all subscribers of the mailing list. |
||||
</p> |
||||
<p> |
||||
That's it. |
||||
</p> |
||||
</fieldset> |
||||
</body> |
||||
</html> |
Loading…
Reference in new issue