Commit 7d7bdca9 authored by Maxime Sinclair's avatar Maxime Sinclair
Browse files

[FEATURE] Map usage integrated in the interactive servlet

JSTL (without EL) added
parent 13ac55e0
......@@ -75,6 +75,11 @@
<artifactId>plantuml</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>HTTPClient</groupId>
<artifactId>HTTPClient</artifactId>
......
......@@ -42,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.SourceInformation;
import HTTPClient.CookieModule;
import HTTPClient.HTTPConnection;
import HTTPClient.HTTPResponse;
......@@ -141,6 +142,11 @@ public class PlantUmlServlet extends HttpServlet {
request.setAttribute("net.sourceforge.plantuml.servlet.decoded", text);
request.setAttribute("net.sourceforge.plantuml.servlet.encoded", encoded);
// check if an image map is necessary
if (text != null && SourceInformation.containsLink(text)) {
request.setAttribute("net.sourceforge.plantuml.servlet.mapneeded", Boolean.TRUE);
}
// forward to index.jsp
RequestDispatcher dispatcher = request.getRequestDispatcher("/index.jsp");
......
/* ========================================================================
* 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;
/**
* Utility class giving information about a diagram based on its source description.
*/
public class SourceInformation {
/*
* Check if there is a link ([[url]]) in the source of the diagram.
* @param source the full textual representation of a diagram
* @return true if there is at least one link
*/
public static boolean containsLink(String source) {
// TODO build a better implementation
return source.contains("[[");
}
}
......@@ -4,6 +4,7 @@
<ul>
<li>NullOutputStream is used by the Map feature.</li>
<li>UmlExtractor encapsulates the PlantUML library to decode the UML compressed source.</li>
<li>SourceInformation extracts useful information from the full textual source.</li>
</ul>
</body>
</html>
\ No newline at end of file
<%@ page info="index" contentType="text/html; charset=utf-8" pageEncoding="utf-8" session="false" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%
String contextRoot = request.getContextPath();
String host = "http://" + request.getServerName() + ":" + request.getServerPort();
......@@ -8,6 +8,8 @@ String umltext = "";
String imgurl = "";
String svgurl = "";
String txturl = "";
String mapurl = "";
Object mapNeeded = request.getAttribute("net.sourceforge.plantuml.servlet.mapneeded");
Object encodedAttribute = request.getAttribute("net.sourceforge.plantuml.servlet.encoded");
if (encodedAttribute != null) {
encoded = encodedAttribute.toString();
......@@ -15,6 +17,9 @@ if (encodedAttribute != null) {
imgurl = host + contextRoot + "/img/" + encoded;
svgurl = host + contextRoot + "/svg/" + encoded;
txturl = host + contextRoot + "/txt/" + encoded;
if (mapNeeded != null) {
mapurl = host + contextRoot + "/map/" + encoded;
}
}
}
Object decodedAttribute = request.getAttribute("net.sourceforge.plantuml.servlet.decoded");
......@@ -59,12 +64,19 @@ if (decodedAttribute != null) {
<input type="submit"/>
</p>
</form>
<% if ( !imgurl.isEmpty()) { %>
<% if (!imgurl.isEmpty()) { %>
<hr/>
<a href="<%=svgurl%>">View as SVG</a>&nbsp;
<a href="<%=txturl%>">View as ASCII Art</a>
<p id="diagram">
<img src="<%=imgurl %>" alt="PlantUML diagram"/>
<% if (mapNeeded != null) { %>
<img src="<%=imgurl %>" alt="PlantUML diagram" usemap="#umlmap" />
<map name="umlmap">
<c:import url="<%=mapurl %>" />
</map>
<% } else { %>
<img src="<%=imgurl %>" alt="PlantUML diagram" />
<% } %>
</p>
<% } //endif %>
</div>
......
package net.sourceforge.plantuml.servlet;
import com.meterware.httpunit.GetMethodWebRequest;
import com.meterware.httpunit.HTMLElement;
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebForm;
import com.meterware.httpunit.WebRequest;
......@@ -113,4 +114,23 @@ public class TestForm extends WebappTestCase {
assertEquals(1, response.getImages().length);
}
/**
* Verifies that an image map is produced if the diagram contains a link
*/
public void testImageMap() throws Exception {
WebConversation conversation = new WebConversation();
// Fill the form and submit it
WebRequest request = new GetMethodWebRequest(getServerUrl());
WebResponse response = conversation.getResponse(request);
WebForm formText = response.getForms()[0];
formText.setParameter("text", "@startuml \nBob -> Alice : [[http://yahoo.com]] Hello \n@enduml");
response = formText.submit();
// Analyze response
// Ensure the generated image is present
assertEquals(1, response.getImages().length);
// Ensure the image map is present
HTMLElement maps[] = response.getElementsByTagName("map");
assertEquals(1, maps.length);
}
}
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