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
e90fdee2
Commit
e90fdee2
authored
Aug 14, 2013
by
Maxime Sinclair
Browse files
[TASK] Refactoring, decoding feature is now in a utility class
parent
9e90a366
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/net/sourceforge/plantuml/servlet/UmlDiagramService.java
View file @
e90fdee2
...
...
@@ -25,16 +25,13 @@ package net.sourceforge.plantuml.servlet;
import
java.io.IOException
;
import
javax.imageio.IIOException
;
import
java.net.URLDecoder
;
import
javax.servlet.ServletException
;
import
javax.servlet.http.HttpServlet
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
net.sourceforge.plantuml.FileFormat
;
import
net.sourceforge.plantuml.code.Transcoder
;
import
net.sourceforge.plantuml.code.TranscoderUtil
;
import
net.sourceforge.plantuml.servlet.utility.UmlExtractor
;
/**
* Common service servlet to produce diagram from compressed UML source contained in the end part of the requested URI.
...
...
@@ -46,24 +43,7 @@ public abstract class UmlDiagramService extends HttpServlet {
public
void
doGet
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
IOException
,
ServletException
{
// build the UML source from the compressed request parameter
String
text
=
URLDecoder
.
decode
(
getSource
(
request
.
getRequestURI
()),
"UTF-8"
);
Transcoder
transcoder
=
getTranscoder
();
text
=
transcoder
.
decode
(
text
);
// encapsulate the UML syntax if necessary
String
uml
;
if
(
text
.
startsWith
(
"@start"
))
{
uml
=
text
;
}
else
{
StringBuilder
plantUmlSource
=
new
StringBuilder
();
plantUmlSource
.
append
(
"@startuml\n"
);
plantUmlSource
.
append
(
text
);
if
(
text
.
endsWith
(
"\n"
)
==
false
)
{
plantUmlSource
.
append
(
"\n"
);
}
plantUmlSource
.
append
(
"@enduml"
);
uml
=
plantUmlSource
.
toString
();
}
String
uml
=
UmlExtractor
.
getUmlSource
(
getSource
(
request
.
getRequestURI
()));
// generate the response
DiagramResponse
dr
=
new
DiagramResponse
(
response
,
getOutputFormat
());
...
...
@@ -91,7 +71,4 @@ public abstract class UmlDiagramService extends HttpServlet {
*/
abstract
public
FileFormat
getOutputFormat
();
private
Transcoder
getTranscoder
()
{
return
TranscoderUtil
.
getDefaultTranscoder
();
}
}
src/main/java/net/sourceforge/plantuml/servlet/utility/UmlExtractor.java
0 → 100644
View file @
e90fdee2
/* ========================================================================
* 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.UnsupportedEncodingException
;
import
java.net.URLDecoder
;
import
net.sourceforge.plantuml.code.Transcoder
;
import
net.sourceforge.plantuml.code.TranscoderUtil
;
/**
* Utility class to extract the UML source from the compressed UML source contained in the end part of the requested URI.
*/
public
class
UmlExtractor
{
/**
* Build the complete UML source from the compressed source extracted from the HTTP URI.
*
* @param source
* the last part of the URI containing the compressed UML
* @return the textual UML source
*/
static
public
String
getUmlSource
(
String
source
)
{
// build the UML source from the compressed part of the URL
String
text
;
try
{
text
=
URLDecoder
.
decode
(
source
,
"UTF-8"
);
}
catch
(
UnsupportedEncodingException
uee
)
{
text
=
"' invalid encoded string"
;
}
Transcoder
transcoder
=
TranscoderUtil
.
getDefaultTranscoder
();
try
{
text
=
transcoder
.
decode
(
text
);
}
catch
(
IOException
ioe
)
{
text
=
"' unable to decode string"
;
}
// encapsulate the UML syntax if necessary
String
uml
;
if
(
text
.
startsWith
(
"@start"
))
{
uml
=
text
;
}
else
{
StringBuilder
plantUmlSource
=
new
StringBuilder
();
plantUmlSource
.
append
(
"@startuml\n"
);
plantUmlSource
.
append
(
text
);
if
(
text
.
endsWith
(
"\n"
)
==
false
)
{
plantUmlSource
.
append
(
"\n"
);
}
plantUmlSource
.
append
(
"@enduml"
);
uml
=
plantUmlSource
.
toString
();
}
return
uml
;
}
}
\ No newline at end of file
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