mirror of
https://github.com/octoleo/plantuml-server.git
synced 2025-01-03 05:00:14 +00:00
[FEATURE] Map service totally implemented
This commit is contained in:
parent
bedc5b49ce
commit
13ac55e09e
@ -28,12 +28,14 @@ import java.util.Collections;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.servlet.ServletOutputStream;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import net.sourceforge.plantuml.FileFormat;
|
import net.sourceforge.plantuml.FileFormat;
|
||||||
import net.sourceforge.plantuml.FileFormatOption;
|
import net.sourceforge.plantuml.FileFormatOption;
|
||||||
import net.sourceforge.plantuml.SourceStringReader;
|
import net.sourceforge.plantuml.SourceStringReader;
|
||||||
import net.sourceforge.plantuml.StringUtils;
|
import net.sourceforge.plantuml.StringUtils;
|
||||||
|
import net.sourceforge.plantuml.servlet.utility.NullOutputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delegates the diagram generation from the UML source and the filling of the HTTP response with the diagram in the
|
* Delegates the diagram generation from the UML source and the filling of the HTTP response with the diagram in the
|
||||||
@ -47,7 +49,7 @@ class DiagramResponse {
|
|||||||
Map<FileFormat, String> map = new HashMap<FileFormat, String>();
|
Map<FileFormat, String> map = new HashMap<FileFormat, String>();
|
||||||
map.put(FileFormat.PNG, "image/png");
|
map.put(FileFormat.PNG, "image/png");
|
||||||
map.put(FileFormat.SVG, "image/svg+xml");
|
map.put(FileFormat.SVG, "image/svg+xml");
|
||||||
map.put(FileFormat.ATXT, "text/plain");
|
map.put(FileFormat.ATXT, "text/plain;charset=ISO-8859-1");
|
||||||
contentType = Collections.unmodifiableMap(map);
|
contentType = Collections.unmodifiableMap(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,14 +69,18 @@ class DiagramResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void sendMap(String uml) throws IOException {
|
void sendMap(String uml) throws IOException {
|
||||||
/* SourceStringReader reader = new SourceStringReader(uml);
|
if (StringUtils.isDiagramCacheable(uml)) {
|
||||||
String map = reader.generateImage(response.getOutputStream(), new FileFormatOption(FileFormat.PNG));
|
addHeaderForCache();
|
||||||
response.flushBuffer();
|
}
|
||||||
System.out.println( "map !!!" + map + "!!!");
|
response.setContentType(getContentType());
|
||||||
|
SourceStringReader reader = new SourceStringReader(uml);
|
||||||
|
String map = reader.generateImage(new NullOutputStream(), new FileFormatOption(FileFormat.PNG));
|
||||||
String[] mapLines = map.split("[\\r\\n]");
|
String[] mapLines = map.split("[\\r\\n]");
|
||||||
for (int i=2; (i+1)<mapLines.length; i++)
|
ServletOutputStream httpOut = response.getOutputStream();
|
||||||
System.out.println("map"+i+" !!!"+mapLines[i]+"!!!");
|
for (int i=2; (i+1)<mapLines.length; i++) {
|
||||||
*/
|
httpOut.print(mapLines[i]);
|
||||||
|
}
|
||||||
|
response.flushBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addHeaderForCache() {
|
private void addHeaderForCache() {
|
||||||
|
@ -7,30 +7,37 @@ hide empty methods
|
|||||||
hide empty fields
|
hide empty fields
|
||||||
abstract class UmlDiagramService {
|
abstract class UmlDiagramService {
|
||||||
public void doGet(HttpServletRequest rq, HttpServletResponse rsp)
|
public void doGet(HttpServletRequest rq, HttpServletResponse rsp)
|
||||||
abstract public ResponseSender getSender()
|
|
||||||
abstract public String getSource( String uri)
|
abstract public String getSource( String uri)
|
||||||
abstract public FileFormat getOutputFormat()
|
abstract FileFormat getOutputFormat()
|
||||||
}
|
}
|
||||||
interface ResponseSender {
|
class DiagramResponse {
|
||||||
ResponseSender( HttpServletResponse r, FileFormat f)
|
DiagramResponse( HttpServletResponse r, FileFormat f)
|
||||||
void sendDiagram( String uml, int n)
|
void sendDiagram( String uml)
|
||||||
|
void sendMap( String uml)
|
||||||
}
|
}
|
||||||
abstract HttpServlet <|-- UmlDiagramService
|
abstract HttpServlet <|-- UmlDiagramService
|
||||||
|
abstract HttpServlet <|-- MapServlet
|
||||||
abstract HttpServlet <|-- ProxyServlet
|
abstract HttpServlet <|-- ProxyServlet
|
||||||
UmlDiagramService <|-- PngServlet
|
UmlDiagramService <|-- PngServlet
|
||||||
UmlDiagramService <|-- SvgServlet
|
UmlDiagramService <|-- SvgServlet
|
||||||
UmlDiagramService <|-- AsciiServlet
|
UmlDiagramService <|-- AsciiServlet
|
||||||
UmlDiagramService <|-- MapServlet
|
UmlDiagramService o- DiagramResponse
|
||||||
UmlDiagramService o- ResponseSender
|
MapServlet o- DiagramResponse
|
||||||
ResponseSender <|-- DiagramResponse
|
|
||||||
ResponseSender <|-- MapResponse
|
|
||||||
ResponseSender <|-- ProxyResponse
|
|
||||||
ProxyResponse -o ProxyServlet
|
|
||||||
@enduml
|
@enduml
|
||||||
|
|
||||||
## Sequence diagram ##
|
## Sequence diagram ##
|
||||||
######################
|
######################
|
||||||
|
|
||||||
@startuml
|
@startuml
|
||||||
TODO
|
title Generation of a PNG image illustrated
|
||||||
|
PngServlet -> PngServlet : getSource()
|
||||||
|
PngServlet -> UmlExtractor : getUmlSource()
|
||||||
|
UmlExtractor --> PngServlet
|
||||||
|
PngServlet -> PngServlet : getOutputFormat()
|
||||||
|
PngServlet -> DiagramResponse : <<create>>
|
||||||
|
PngServlet -> DiagramResponse : sendDiagram()
|
||||||
|
participant "PlantUML library" as Lib #99FF99
|
||||||
|
DiagramResponse -> Lib : generateImage()
|
||||||
|
Lib --> DiagramResponse
|
||||||
|
DiagramResponse --> PngServlet
|
||||||
@enduml
|
@enduml
|
@ -8,5 +8,8 @@
|
|||||||
Structure of the service part of the PlantUmlServer: <br>
|
Structure of the service part of the PlantUmlServer: <br>
|
||||||
<img src="http://www.plantuml.com/plantuml/img/XP51ReCm44Ntd6AMH0etwAPIbNPJjIhg0OoPm4WsTiPZrAZDtGk514ZIP3b_dlx_7jTK8g3riWUBja0EIJsNf7RbGjeIcavHHH1MMa0R5G9yMlD4gc9bS-IMDC9t0k1ZOKX3wwY4qZsZf2yYlYSCoWVk8WO1tgrX8GVlce30mQywZrFGQ9OBKrD1XPAxo1hJenAP5lo636uSMoKz_1R5HndcT9KSag7tMFeKshS-qzBhxTRpW6sV_FVCW4qv6apDh5diNvLVxWxJEMTPyF2JPPUNlS5snkDy0tfdzxK_OfV_DZ1DTOV8stl4Oz14_pCkEpzqCjM_ilq5" />
|
<img src="http://www.plantuml.com/plantuml/img/XP51ReCm44Ntd6AMH0etwAPIbNPJjIhg0OoPm4WsTiPZrAZDtGk514ZIP3b_dlx_7jTK8g3riWUBja0EIJsNf7RbGjeIcavHHH1MMa0R5G9yMlD4gc9bS-IMDC9t0k1ZOKX3wwY4qZsZf2yYlYSCoWVk8WO1tgrX8GVlce30mQywZrFGQ9OBKrD1XPAxo1hJenAP5lo636uSMoKz_1R5HndcT9KSag7tMFeKshS-qzBhxTRpW6sV_FVCW4qv6apDh5diNvLVxWxJEMTPyF2JPPUNlS5snkDy0tfdzxK_OfV_DZ1DTOV8stl4Oz14_pCkEpzqCjM_ilq5" />
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
<img src="http://www.plantuml.com/plantuml/img/XP1DZi8m38NtdCA23RFe0OfGLr24n4y5uW2cU2fBQL8vBeBRup8ZHEc2LPJtNhuNMraTmOey2Ie73-4N48hT2hZ6Ye2TQwEQHvTHuQiZoTMHGfB1ssq65Uanj5BIzESZTghTycQ0KeFy1KrvPNjkqgD-gTktshIQ1wbH1wKBnagmFb1iWezaB-RpKiYcoBAlqKZ-ygyQk45HBhb1hp0kd1sdxGOSdmNbFWQCiE4pJD8qpzDqz4cpWixkVlpSCAsxhHgsKvDX_H3G6_q1" />
|
||||||
|
</p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -0,0 +1,54 @@
|
|||||||
|
/* ========================================================================
|
||||||
|
* 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.OutputStream;
|
||||||
|
|
||||||
|
public class NullOutputStream extends OutputStream {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes to nowhere
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void write(int b) throws IOException {
|
||||||
|
// Do nothing silently
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overridden for performance reason
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void write(byte b[]) throws IOException {
|
||||||
|
// Do nothing silently
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overridden for performance reason
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void write(byte b[], int off, int len) throws IOException {
|
||||||
|
// Do nothing silently
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<p>This package contains utility classes of the JEE PlantUml Server.</p>
|
||||||
|
<ul>
|
||||||
|
<li>NullOutputStream is used by the Map feature.</li>
|
||||||
|
<li>UmlExtractor encapsulates the PlantUML library to decode the UML compressed source.</li>
|
||||||
|
</ul>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -13,6 +13,7 @@ public class AllTests extends TestSuite {
|
|||||||
suite.addTestSuite(TestAsciiArt.class);
|
suite.addTestSuite(TestAsciiArt.class);
|
||||||
suite.addTestSuite(TestSVG.class);
|
suite.addTestSuite(TestSVG.class);
|
||||||
suite.addTestSuite(TestProxy.class);
|
suite.addTestSuite(TestProxy.class);
|
||||||
|
suite.addTestSuite(TestMap.class);
|
||||||
// $JUnit-END$
|
// $JUnit-END$
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,8 @@ public class TestMap extends WebappTestCase {
|
|||||||
WebResponse response = conversation.getResource(request);
|
WebResponse response = conversation.getResource(request);
|
||||||
// Analyze response
|
// Analyze response
|
||||||
// Verifies the Content-Type header
|
// Verifies the Content-Type header
|
||||||
assertEquals("Response content type is not TEXT PLAIN", "text/plain", response.getContentType());
|
assertEquals("Response content type is not TEXT PLAIN", "text/plain", response.getContentType());
|
||||||
|
assertEquals("Response character set is not ISO-8859-1", "ISO-8859-1", response.getCharacterSet());
|
||||||
// Get the content, check its first characters and verify its size
|
// Get the content, check its first characters and verify its size
|
||||||
String diagram = response.getText();
|
String diagram = response.getText();
|
||||||
assertTrue("Response content is not starting with <area", diagram.startsWith("<area"));
|
assertTrue("Response content is not starting with <area", diagram.startsWith("<area"));
|
||||||
@ -38,8 +39,8 @@ public class TestMap extends WebappTestCase {
|
|||||||
// Analyze response
|
// Analyze response
|
||||||
// Get the data contained in the XML
|
// Get the data contained in the XML
|
||||||
String map = response.getText();
|
String map = response.getText();
|
||||||
assertTrue(map.matches("(<([^<>]+)>)+")); // list of tags
|
assertTrue("Response is not a list of tags", map.matches("(<([^<>]+)>)+"));
|
||||||
assertTrue(map.matches(".*(area shape=\".+\" id=\".+\" href=\".+\").*")); // area structure
|
assertTrue("Response doesn't contain the area structure", map.matches(".*(area shape=\".+\" id=\".+\" href=\".+\").*"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user