[FEATURE] First implementation of the configuration
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user