mirror of
https://github.com/octoleo/plantuml-server.git
synced 2025-01-03 05:00:14 +00:00
[FEATURE] Map usage integrated in the interactive servlet
JSTL (without EL) added
This commit is contained in:
parent
13ac55e09e
commit
7d7bdca930
5
pom.xml
5
pom.xml
@ -75,6 +75,11 @@
|
|||||||
<artifactId>plantuml</artifactId>
|
<artifactId>plantuml</artifactId>
|
||||||
<version>LATEST</version>
|
<version>LATEST</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.servlet</groupId>
|
||||||
|
<artifactId>jstl</artifactId>
|
||||||
|
<version>1.2</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>HTTPClient</groupId>
|
<groupId>HTTPClient</groupId>
|
||||||
<artifactId>HTTPClient</artifactId>
|
<artifactId>HTTPClient</artifactId>
|
||||||
|
@ -42,6 +42,7 @@ import net.sourceforge.plantuml.SourceStringReader;
|
|||||||
import net.sourceforge.plantuml.StringUtils;
|
import net.sourceforge.plantuml.StringUtils;
|
||||||
import net.sourceforge.plantuml.code.Transcoder;
|
import net.sourceforge.plantuml.code.Transcoder;
|
||||||
import net.sourceforge.plantuml.code.TranscoderUtil;
|
import net.sourceforge.plantuml.code.TranscoderUtil;
|
||||||
|
import net.sourceforge.plantuml.servlet.utility.SourceInformation;
|
||||||
import HTTPClient.CookieModule;
|
import HTTPClient.CookieModule;
|
||||||
import HTTPClient.HTTPConnection;
|
import HTTPClient.HTTPConnection;
|
||||||
import HTTPClient.HTTPResponse;
|
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.decoded", text);
|
||||||
request.setAttribute("net.sourceforge.plantuml.servlet.encoded", encoded);
|
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
|
// forward to index.jsp
|
||||||
RequestDispatcher dispatcher = request.getRequestDispatcher("/index.jsp");
|
RequestDispatcher dispatcher = request.getRequestDispatcher("/index.jsp");
|
||||||
|
@ -0,0 +1,40 @@
|
|||||||
|
/* ========================================================================
|
||||||
|
* 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>
|
<ul>
|
||||||
<li>NullOutputStream is used by the Map feature.</li>
|
<li>NullOutputStream is used by the Map feature.</li>
|
||||||
<li>UmlExtractor encapsulates the PlantUML library to decode the UML compressed source.</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>
|
</ul>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -1,5 +1,5 @@
|
|||||||
<%@ page info="index" contentType="text/html; charset=utf-8" pageEncoding="utf-8" session="false" %>
|
<%@ 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 contextRoot = request.getContextPath();
|
||||||
String host = "http://" + request.getServerName() + ":" + request.getServerPort();
|
String host = "http://" + request.getServerName() + ":" + request.getServerPort();
|
||||||
@ -8,6 +8,8 @@ String umltext = "";
|
|||||||
String imgurl = "";
|
String imgurl = "";
|
||||||
String svgurl = "";
|
String svgurl = "";
|
||||||
String txturl = "";
|
String txturl = "";
|
||||||
|
String mapurl = "";
|
||||||
|
Object mapNeeded = request.getAttribute("net.sourceforge.plantuml.servlet.mapneeded");
|
||||||
Object encodedAttribute = request.getAttribute("net.sourceforge.plantuml.servlet.encoded");
|
Object encodedAttribute = request.getAttribute("net.sourceforge.plantuml.servlet.encoded");
|
||||||
if (encodedAttribute != null) {
|
if (encodedAttribute != null) {
|
||||||
encoded = encodedAttribute.toString();
|
encoded = encodedAttribute.toString();
|
||||||
@ -15,6 +17,9 @@ if (encodedAttribute != null) {
|
|||||||
imgurl = host + contextRoot + "/img/" + encoded;
|
imgurl = host + contextRoot + "/img/" + encoded;
|
||||||
svgurl = host + contextRoot + "/svg/" + encoded;
|
svgurl = host + contextRoot + "/svg/" + encoded;
|
||||||
txturl = host + contextRoot + "/txt/" + encoded;
|
txturl = host + contextRoot + "/txt/" + encoded;
|
||||||
|
if (mapNeeded != null) {
|
||||||
|
mapurl = host + contextRoot + "/map/" + encoded;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Object decodedAttribute = request.getAttribute("net.sourceforge.plantuml.servlet.decoded");
|
Object decodedAttribute = request.getAttribute("net.sourceforge.plantuml.servlet.decoded");
|
||||||
@ -59,12 +64,19 @@ if (decodedAttribute != null) {
|
|||||||
<input type="submit"/>
|
<input type="submit"/>
|
||||||
</p>
|
</p>
|
||||||
</form>
|
</form>
|
||||||
<% if ( !imgurl.isEmpty()) { %>
|
<% if (!imgurl.isEmpty()) { %>
|
||||||
<hr/>
|
<hr/>
|
||||||
<a href="<%=svgurl%>">View as SVG</a>
|
<a href="<%=svgurl%>">View as SVG</a>
|
||||||
<a href="<%=txturl%>">View as ASCII Art</a>
|
<a href="<%=txturl%>">View as ASCII Art</a>
|
||||||
<p id="diagram">
|
<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>
|
</p>
|
||||||
<% } //endif %>
|
<% } //endif %>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.sourceforge.plantuml.servlet;
|
package net.sourceforge.plantuml.servlet;
|
||||||
|
|
||||||
import com.meterware.httpunit.GetMethodWebRequest;
|
import com.meterware.httpunit.GetMethodWebRequest;
|
||||||
|
import com.meterware.httpunit.HTMLElement;
|
||||||
import com.meterware.httpunit.WebConversation;
|
import com.meterware.httpunit.WebConversation;
|
||||||
import com.meterware.httpunit.WebForm;
|
import com.meterware.httpunit.WebForm;
|
||||||
import com.meterware.httpunit.WebRequest;
|
import com.meterware.httpunit.WebRequest;
|
||||||
@ -113,4 +114,23 @@ public class TestForm extends WebappTestCase {
|
|||||||
assertEquals(1, response.getImages().length);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user