Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
runcon
Plantuml Server
Commits
ae955806
Commit
ae955806
authored
Jan 07, 2014
by
maximesinclair
Browse files
[FEATURE] First implementation of the configuration
parent
f0493c58
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/main/java/net/sourceforge/plantuml/servlet/PlantUmlServlet.java
View file @
ae955806
...
...
@@ -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
();
}
...
...
src/main/java/net/sourceforge/plantuml/servlet/utility/Configuration.java
0 → 100644
View file @
ae955806
/* ========================================================================
* 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"
);
}
}
src/main/resources/config.properties
0 → 100644
View file @
ae955806
#PlantUML configuration file
#
#
USE_GOOGLE_TRACKER
=
on
\ No newline at end of file
src/main/webapp/index.jsp
View file @
ae955806
<%@ 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 --%>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment