diff --git a/src/main/java/net/sourceforge/plantuml/servlet/PlantUmlServlet.java b/src/main/java/net/sourceforge/plantuml/servlet/PlantUmlServlet.java index 65d49ee..ffdf059 100644 --- a/src/main/java/net/sourceforge/plantuml/servlet/PlantUmlServlet.java +++ b/src/main/java/net/sourceforge/plantuml/servlet/PlantUmlServlet.java @@ -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(); } diff --git a/src/main/java/net/sourceforge/plantuml/servlet/utility/Configuration.java b/src/main/java/net/sourceforge/plantuml/servlet/utility/Configuration.java new file mode 100644 index 0000000..e29d5a9 --- /dev/null +++ b/src/main/java/net/sourceforge/plantuml/servlet/utility/Configuration.java @@ -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"); + } + +} diff --git a/src/main/resources/config.properties b/src/main/resources/config.properties new file mode 100644 index 0000000..5b1521f --- /dev/null +++ b/src/main/resources/config.properties @@ -0,0 +1,3 @@ +#PlantUML configuration file +# +#USE_GOOGLE_TRACKER=on \ No newline at end of file diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp index 0680eab..4385869 100644 --- a/src/main/webapp/index.jsp +++ b/src/main/webapp/index.jsp @@ -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" %> + @@ -32,6 +33,9 @@ <%-- PAGE TITLE --%>

PlantUML Server

This application provides a servlet which serves images created by PlantUML.

+ +

SOCIAL BUTTONS

+
<%-- CONTENT --%>