1
0
mirror of https://github.com/octoleo/plantuml-server.git synced 2024-06-07 10:50:52 +00:00

[FEATURE] First implementation of the configuration

This commit is contained in:
maximesinclair 2014-01-07 00:06:14 +01:00
parent f0493c581c
commit ae9558062f
4 changed files with 98 additions and 1 deletions

View File

@ -30,6 +30,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
@ -41,6 +42,7 @@ import net.sourceforge.plantuml.SourceStringReader;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.code.Transcoder;
import net.sourceforge.plantuml.code.TranscoderUtil;
import net.sourceforge.plantuml.servlet.utility.Configuration;
import net.sourceforge.plantuml.api.PlantumlUtils;
/*
@ -121,7 +123,11 @@ public class PlantUmlServlet extends HttpServlet {
dispatcher.forward(request, response);
return;
}
public void init(ServletConfig config) throws ServletException {
config.getServletContext().setAttribute("cfg", Configuration.get());
}
private Transcoder getTranscoder() {
return TranscoderUtil.getDefaultTranscoder();
}

View File

@ -0,0 +1,84 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*/
package net.sourceforge.plantuml.servlet.utility;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class Configuration {
private static Configuration instance;
private Properties config;
/**
* Singleton constructor
*/
private Configuration() {
Properties config = new Properties();
// Default values
config.setProperty("SHOW_SOCIAL_BUTTONS", "off");
config.setProperty("USE_GOOGLE_TRACKER", "off");
// End of default values
try {
InputStream is = Thread.currentThread().getContextClassLoader().
getResourceAsStream("config.properties");
if (is != null) {
config.load(is);
is.close();
}
} catch (IOException e) {
// Just log a warning
e.printStackTrace();
}
}
/**
* Get the configuration
*
* @return the complete configuration
*/
public static Properties get() {
if (instance == null) {
instance = new Configuration();
}
return instance.config;
}
/**
* Get a boolean configuration value
*
* @return true if the value is "on"
*/
public static boolean get(String key) {
if (instance.config.getProperty(key) == null) {
return false;
}
return instance.config.getProperty(key).startsWith("on");
}
}

View File

@ -0,0 +1,3 @@
#PlantUML configuration file
#
#USE_GOOGLE_TRACKER=on

View File

@ -1,6 +1,7 @@
<%@ page info="index" contentType="text/html; charset=utf-8" pageEncoding="utf-8" session="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="cfg" value="${applicationScope['cfg']}" />
<c:set var="contextroot" value="${pageContext.request.contextPath}" />
<c:set var="hostpath" value="http://${pageContext.request.serverName}:${pageContext.request.serverPort}${contextroot}" />
<c:if test="${pageContext.request.serverPort == 80 }">
@ -32,6 +33,9 @@
<%-- PAGE TITLE --%>
<h1>PlantUML Server</h1>
<p>This application provides a servlet which serves images created by <a href="http://plantuml.sourceforge.net">PlantUML</a>.</p>
<c:if test="${cfg['SHOW_SOCIAL_BUTTONS'] == 'on' }">
<p>SOCIAL BUTTONS</p>
</c:if>
</div>
<div id="content">
<%-- CONTENT --%>