[TASK] Scriptlet replaced by EL

This commit is contained in:
Maxime Sinclair
2013-10-17 14:39:51 +02:00
parent ccc71e7cd4
commit dc7bc3e179
3 changed files with 44 additions and 56 deletions

View File

@@ -140,12 +140,12 @@ public class PlantUmlServlet extends HttpServlet {
encoded = transcoder.encode(text); encoded = transcoder.encode(text);
} }
request.setAttribute("net.sourceforge.plantuml.servlet.decoded", text); request.setAttribute("decoded", text);
request.setAttribute("net.sourceforge.plantuml.servlet.encoded", encoded); request.setAttribute("encoded", encoded);
// check if an image map is necessary // check if an image map is necessary
if (text != null && PlantumlUtils.hasCMapData(text)) { if (text != null && PlantumlUtils.hasCMapData(text)) {
request.setAttribute("net.sourceforge.plantuml.servlet.mapneeded", Boolean.TRUE); request.setAttribute("mapneeded", Boolean.TRUE);
} }
// forward to index.jsp // forward to index.jsp

View File

@@ -42,8 +42,8 @@ public class Welcome extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
// set the sample // set the sample
request.setAttribute("net.sourceforge.plantuml.servlet.decoded", "Bob -> Alice : hello"); request.setAttribute("decoded", "Bob -> Alice : hello");
request.setAttribute("net.sourceforge.plantuml.servlet.encoded", "SyfFKj2rKt3CoKnELR1Io4ZDoSa70000"); request.setAttribute("encoded", "SyfFKj2rKt3CoKnELR1Io4ZDoSa70000");
// forward to index.jsp // forward to index.jsp
RequestDispatcher dispatcher = request.getRequestDispatcher("/index.jsp"); RequestDispatcher dispatcher = request.getRequestDispatcher("/index.jsp");

View File

@@ -1,31 +1,16 @@
<%@ 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/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String contextRoot = request.getContextPath(); <c:set var="contextroot" value="${pageContext.request.contextPath}" />
String host = "http://" + request.getServerName() + ":" + request.getServerPort(); <c:set var="hostpath" value="http://${pageContext.request.serverName}:${pageContext.request.serverPort}${contextroot}" />
String encoded = ""; <c:if test="${!empty encoded}">
String umltext = ""; <c:set var="imgurl" value="${hostpath}/img/${encoded}" />
String imgurl = ""; <c:set var="svgurl" value="${hostpath}/svg/${encoded}" />
String svgurl = ""; <c:set var="txturl" value="${hostpath}/txt/${encoded}" />
String txturl = ""; <c:if test="${!empty mapneeded}">
Object mapNeeded = request.getAttribute("net.sourceforge.plantuml.servlet.mapneeded"); <c:set var="mapurl" value="${hostpath}/map/${encoded}" />
Object encodedAttribute = request.getAttribute("net.sourceforge.plantuml.servlet.encoded"); </c:if>
if (encodedAttribute != null) { </c:if>
encoded = encodedAttribute.toString();
if (!encoded.isEmpty()) {
imgurl = host + contextRoot + "/img/" + encoded;
svgurl = host + contextRoot + "/svg/" + encoded;
txturl = host + contextRoot + "/txt/" + encoded;
if (mapNeeded != null) {
pageContext.setAttribute("mapurl", host + contextRoot + "/map/" + encoded);
}
}
}
Object decodedAttribute = request.getAttribute("net.sourceforge.plantuml.servlet.decoded");
if (decodedAttribute != null) {
umltext = decodedAttribute.toString();
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <html xmlns="http://www.w3.org/1999/xhtml">
@@ -34,9 +19,9 @@ if (decodedAttribute != null) {
<meta http-equiv="expires" content="0" /> <meta http-equiv="expires" content="0" />
<meta http-equiv="pragma" content="no-cache" /> <meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache, must-revalidate" /> <meta http-equiv="cache-control" content="no-cache, must-revalidate" />
<link rel="stylesheet" href="<%=contextRoot %>/plantuml.css" type="text/css"/> <link rel="stylesheet" href="${contextroot}/plantuml.css" type="text/css"/>
<link rel="icon" href="<%=contextRoot %>/favicon.ico" type="image/x-icon"/> <link rel="icon" href="${contextroot}/favicon.ico" type="image/x-icon"/>
<link rel="shortcut icon" href="<%=contextRoot %>/favicon.ico" type="image/x-icon"/> <link rel="shortcut icon" href="${contextroot}/favicon.ico" type="image/x-icon"/>
<title>PlantUMLServer</title> <title>PlantUMLServer</title>
</head> </head>
<body> <body>
@@ -47,40 +32,43 @@ if (decodedAttribute != null) {
</div> </div>
<div id="content"> <div id="content">
<%-- CONTENT --%> <%-- CONTENT --%>
<form method="post" accept-charset="UTF-8" action="<%=contextRoot %>/form"> <form method="post" accept-charset="UTF-8" action="${contextroot}/form">
<p> <p>
<textarea name="text" cols="120" rows="10"><%=umltext %></textarea> <textarea name="text" cols="120" rows="10"><c:out value="${decoded}"/></textarea>
<br/> <br/>
<input type="submit" /> <input type="submit" />
</p> </p>
</form> </form>
<hr/> <hr/>
You can enter here a previously generated URL: You can enter here a previously generated URL:
<form method="post" action="<%=contextRoot %>/form"> <form method="post" action="${contextroot}/form">
<p> <p>
<input name="url" type="text" size="150" value="<%=imgurl %>" /> <input name="url" type="text" size="150" value="${imgurl}" />
<br/> <br/>
<input type="submit"/> <input type="submit"/>
</p> </p>
</form> </form>
<% if (!imgurl.isEmpty()) { %> <c:if test="${!empty imgurl}">
<hr/> <hr/>
<a href="<%=svgurl%>">View as SVG</a>&nbsp; <a href="${svgurl}">View as SVG</a>&nbsp;
<a href="<%=txturl%>">View as ASCII Art</a>&nbsp; <a href="${txturl}">View as ASCII Art</a>&nbsp;
<% if (mapNeeded != null) { %> <c:if test="${!empty mapurl}">
<a href="<c:out value="${mapurl}"/>">View Map Data</a> <a href="${mapurl}">View Map Data</a>
<% } //endif %> </c:if>
<p id="diagram"> <p id="diagram">
<% if (mapNeeded != null) { %> <c:choose>
<img src="<%=imgurl %>" alt="PlantUML diagram" usemap="#umlmap" /> <c:when test="${!empty mapurl}">
<map name="umlmap"> <img src="${imgurl}" alt="PlantUML diagram" usemap="#umlmap" />
<c:import url="${mapurl}" /> <map name="umlmap">
</map> <c:import url="${mapurl}" />
<% } else { %> </map>
<img src="<%=imgurl %>" alt="PlantUML diagram" /> </c:when>
<% } %> <c:otherwise>
</p> <img src="${imgurl}" alt="PlantUML diagram" />
<% } //endif %> </c:otherwise>
</c:choose>
</p>
</c:if>
</div> </div>
<!-- This comment is used by the TestProxy class <!-- This comment is used by the TestProxy class
@startuml @startuml