Commit 13ac55e0 authored by Maxime Sinclair's avatar Maxime Sinclair
Browse files

[FEATURE] Map service totally implemented

parent bedc5b49
......@@ -28,12 +28,14 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.SourceStringReader;
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
......@@ -47,7 +49,7 @@ class DiagramResponse {
Map<FileFormat, String> map = new HashMap<FileFormat, String>();
map.put(FileFormat.PNG, "image/png");
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);
}
......@@ -67,14 +69,18 @@ class DiagramResponse {
}
void sendMap(String uml) throws IOException {
/* SourceStringReader reader = new SourceStringReader(uml);
String map = reader.generateImage(response.getOutputStream(), new FileFormatOption(FileFormat.PNG));
response.flushBuffer();
System.out.println( "map !!!" + map + "!!!");
if (StringUtils.isDiagramCacheable(uml)) {
addHeaderForCache();
}
response.setContentType(getContentType());
SourceStringReader reader = new SourceStringReader(uml);
String map = reader.generateImage(new NullOutputStream(), new FileFormatOption(FileFormat.PNG));
String[] mapLines = map.split("[\\r\\n]");
for (int i=2; (i+1)<mapLines.length; i++)
System.out.println("map"+i+" !!!"+mapLines[i]+"!!!");
*/
ServletOutputStream httpOut = response.getOutputStream();
for (int i=2; (i+1)<mapLines.length; i++) {
httpOut.print(mapLines[i]);
}
response.flushBuffer();
}
private void addHeaderForCache() {
......
......@@ -7,30 +7,37 @@ hide empty methods
hide empty fields
abstract class UmlDiagramService {
public void doGet(HttpServletRequest rq, HttpServletResponse rsp)
abstract public ResponseSender getSender()
abstract public String getSource( String uri)
abstract public FileFormat getOutputFormat()
abstract FileFormat getOutputFormat()
}
interface ResponseSender {
ResponseSender( HttpServletResponse r, FileFormat f)
void sendDiagram( String uml, int n)
class DiagramResponse {
DiagramResponse( HttpServletResponse r, FileFormat f)
void sendDiagram( String uml)
void sendMap( String uml)
}
abstract HttpServlet <|-- UmlDiagramService
abstract HttpServlet <|-- MapServlet
abstract HttpServlet <|-- ProxyServlet
UmlDiagramService <|-- PngServlet
UmlDiagramService <|-- SvgServlet
UmlDiagramService <|-- AsciiServlet
UmlDiagramService <|-- MapServlet
UmlDiagramService o- ResponseSender
ResponseSender <|-- DiagramResponse
ResponseSender <|-- MapResponse
ResponseSender <|-- ProxyResponse
ProxyResponse -o ProxyServlet
UmlDiagramService o- DiagramResponse
MapServlet o- DiagramResponse
@enduml
## Sequence diagram ##
######################
@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
\ No newline at end of file
......@@ -8,5 +8,8 @@
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" />
</p>
<p>
<img src="http://www.plantuml.com/plantuml/img/XP1DZi8m38NtdCA23RFe0OfGLr24n4y5uW2cU2fBQL8vBeBRup8ZHEc2LPJtNhuNMraTmOey2Ie73-4N48hT2hZ6Ye2TQwEQHvTHuQiZoTMHGfB1ssq65Uanj5BIzESZTghTycQ0KeFy1KrvPNjkqgD-gTktshIQ1wbH1wKBnagmFb1iWezaB-RpKiYcoBAlqKZ-ygyQk45HBhb1hp0kd1sdxGOSdmNbFWQCiE4pJD8qpzDqz4cpWixkVlpSCAsxhHgsKvDX_H3G6_q1" />
</p>
</body>
</html>
\ No newline at end of file
/* ========================================================================
* 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
}
}
<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>
\ No newline at end of file
......@@ -13,6 +13,7 @@ public class AllTests extends TestSuite {
suite.addTestSuite(TestAsciiArt.class);
suite.addTestSuite(TestSVG.class);
suite.addTestSuite(TestProxy.class);
suite.addTestSuite(TestMap.class);
// $JUnit-END$
return suite;
}
......
......@@ -18,7 +18,8 @@ public class TestMap extends WebappTestCase {
WebResponse response = conversation.getResource(request);
// Analyze response
// 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
String diagram = response.getText();
assertTrue("Response content is not starting with <area", diagram.startsWith("<area"));
......@@ -38,8 +39,8 @@ public class TestMap extends WebappTestCase {
// Analyze response
// Get the data contained in the XML
String map = response.getText();
assertTrue(map.matches("(<([^<>]+)>)+")); // list of tags
assertTrue(map.matches(".*(area shape=\".+\" id=\".+\" href=\".+\").*")); // area structure
assertTrue("Response is not a list of tags", map.matches("(<([^<>]+)>)+"));
assertTrue("Response doesn't contain the area structure", map.matches(".*(area shape=\".+\" id=\".+\" href=\".+\").*"));
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment