update jetty and tomcat to latest version
This commit is contained in:
@@ -26,10 +26,11 @@ package net.sourceforge.plantuml.servlet;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.IIOException;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import net.sourceforge.plantuml.FileFormat;
|
||||
import net.sourceforge.plantuml.servlet.utility.UmlExtractor;
|
||||
|
||||
@@ -23,30 +23,30 @@
|
||||
*/
|
||||
package net.sourceforge.plantuml.servlet;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import net.sourceforge.plantuml.BlockUml;
|
||||
import net.sourceforge.plantuml.ErrorUml;
|
||||
import net.sourceforge.plantuml.FileFormat;
|
||||
import net.sourceforge.plantuml.FileFormatOption;
|
||||
import net.sourceforge.plantuml.OptionFlags;
|
||||
import net.sourceforge.plantuml.NullOutputStream;
|
||||
import net.sourceforge.plantuml.OptionFlags;
|
||||
import net.sourceforge.plantuml.SourceStringReader;
|
||||
import net.sourceforge.plantuml.StringUtils;
|
||||
import net.sourceforge.plantuml.code.Base64Coder;
|
||||
import net.sourceforge.plantuml.core.DiagramDescription;
|
||||
import net.sourceforge.plantuml.core.Diagram;
|
||||
import net.sourceforge.plantuml.core.DiagramDescription;
|
||||
import net.sourceforge.plantuml.core.ImageData;
|
||||
import net.sourceforge.plantuml.version.Version;
|
||||
import net.sourceforge.plantuml.error.PSystemError;
|
||||
import net.sourceforge.plantuml.ErrorUml;
|
||||
import net.sourceforge.plantuml.version.Version;
|
||||
|
||||
/**
|
||||
* Delegates the diagram generation from the UML source and the filling of the HTTP response with the diagram in the
|
||||
|
||||
@@ -23,15 +23,16 @@
|
||||
*/
|
||||
package net.sourceforge.plantuml.servlet;
|
||||
|
||||
import net.sourceforge.plantuml.syntax.LanguageDescriptor;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import net.sourceforge.plantuml.syntax.LanguageDescriptor;
|
||||
|
||||
/**
|
||||
* Servlet used to inspect the language keywords of the running PlantUML server.
|
||||
* Same as {@code java -jar plantuml.jar -language}
|
||||
|
||||
@@ -26,10 +26,11 @@ package net.sourceforge.plantuml.servlet;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.IIOException;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import net.sourceforge.plantuml.FileFormat;
|
||||
import net.sourceforge.plantuml.servlet.utility.UmlExtractor;
|
||||
|
||||
@@ -31,10 +31,10 @@ import java.net.URL;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import net.sourceforge.plantuml.FileFormat;
|
||||
import net.sourceforge.plantuml.FileFormatOption;
|
||||
|
||||
@@ -31,17 +31,20 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import jakarta.servlet.RequestDispatcher;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import net.sourceforge.plantuml.OptionFlags;
|
||||
import net.sourceforge.plantuml.api.PlantumlUtils;
|
||||
import net.sourceforge.plantuml.code.Transcoder;
|
||||
import net.sourceforge.plantuml.code.TranscoderUtil;
|
||||
import net.sourceforge.plantuml.png.MetadataTag;
|
||||
import net.sourceforge.plantuml.servlet.utility.Configuration;
|
||||
import net.sourceforge.plantuml.servlet.utility.UmlExtractor;
|
||||
|
||||
/**
|
||||
* Original idea from Achim Abeling for Confluence macro.
|
||||
@@ -81,62 +84,36 @@ public class PlantUmlServlet extends HttpServlet {
|
||||
@Override
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
||||
request.setCharacterEncoding("UTF-8");
|
||||
String text = request.getParameter("text");
|
||||
|
||||
String metadata = request.getParameter("metadata");
|
||||
if (metadata != null) {
|
||||
InputStream img = null;
|
||||
try {
|
||||
img = getImage(new URL(metadata));
|
||||
MetadataTag metadataTag = new MetadataTag(img, "plantuml");
|
||||
String data = metadataTag.getData();
|
||||
if (data != null) {
|
||||
text = data;
|
||||
}
|
||||
} finally {
|
||||
if (img != null) {
|
||||
img.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
text = getTextFromUrl(request, text);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// textual diagram source
|
||||
final String text = getText(request).trim();
|
||||
|
||||
// no Text form has been submitted
|
||||
if (text == null || text.trim().isEmpty()) {
|
||||
if (text.isEmpty()) {
|
||||
redirectNow(request, response, DEFAULT_ENCODED_TEXT);
|
||||
return;
|
||||
}
|
||||
|
||||
final String encoded = getTranscoder().encode(text);
|
||||
request.setAttribute("decoded", text);
|
||||
request.setAttribute("encoded", encoded);
|
||||
|
||||
// check if an image map is necessary
|
||||
if (text != null && PlantumlUtils.hasCMapData(text)) {
|
||||
request.setAttribute("mapneeded", Boolean.TRUE);
|
||||
}
|
||||
|
||||
// forward to index.jsp
|
||||
prepareRequestForDispatch(request, text);
|
||||
final RequestDispatcher dispatcher = request.getRequestDispatcher("/index.jsp");
|
||||
dispatcher.forward(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
|
||||
IOException {
|
||||
protected void doPost(
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response
|
||||
) throws ServletException, IOException {
|
||||
request.setCharacterEncoding("UTF-8");
|
||||
|
||||
String text = request.getParameter("text");
|
||||
String encoded = DEFAULT_ENCODED_TEXT;
|
||||
|
||||
// encoded diagram source
|
||||
String encoded;
|
||||
try {
|
||||
text = getTextFromUrl(request, text);
|
||||
String text = getText(request).trim();
|
||||
encoded = getTranscoder().encode(text);
|
||||
} catch (Exception e) {
|
||||
encoded = DEFAULT_ENCODED_TEXT;
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -144,16 +121,59 @@ public class PlantUmlServlet extends HttpServlet {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get textual diagram source from URL.
|
||||
* Get textual diagram.
|
||||
* Search for textual diagram in following order:
|
||||
* 1. URL {@link PlantUmlServlet.getTextFromUrl}
|
||||
* 2. metadata
|
||||
* 3. request parameter "text"
|
||||
*
|
||||
* @param request http request which contains the source URL
|
||||
* @param text fallback textual diagram source
|
||||
* @param request http request
|
||||
*
|
||||
* @return if successful textual diagram source from URL; otherwise fallback {@code text}
|
||||
* @return if successful textual diagram source; otherwise empty string
|
||||
*
|
||||
* @throws IOException if an input or output exception occurred
|
||||
*/
|
||||
private String getTextFromUrl(HttpServletRequest request, String text) throws IOException {
|
||||
private String getText(final HttpServletRequest request) throws IOException {
|
||||
String text;
|
||||
// 1. URL
|
||||
try {
|
||||
text = getTextFromUrl(request);
|
||||
if (text != null && !text.isEmpty()) {
|
||||
return text;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 2. metadata
|
||||
String metadata = request.getParameter("metadata");
|
||||
if (metadata != null) {
|
||||
try (InputStream img = getImage(new URL(metadata))) {
|
||||
MetadataTag metadataTag = new MetadataTag(img, "plantuml");
|
||||
String data = metadataTag.getData();
|
||||
if (data != null) {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 3. request parameter text
|
||||
text = request.getParameter("text");
|
||||
if (text != null && !text.isEmpty()) {
|
||||
return text;
|
||||
}
|
||||
// nothing found
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get textual diagram source from URL.
|
||||
*
|
||||
* @param request http request which contains the source URL
|
||||
*
|
||||
* @return if successful textual diagram source from URL; otherwise empty string
|
||||
*
|
||||
* @throws IOException if an input or output exception occurred
|
||||
*/
|
||||
private String getTextFromUrl(HttpServletRequest request) throws IOException {
|
||||
final Matcher recoverUml = RECOVER_UML_PATTERN.matcher(
|
||||
request.getRequestURI().substring(request.getContextPath().length())
|
||||
);
|
||||
@@ -171,8 +191,75 @@ public class PlantUmlServlet extends HttpServlet {
|
||||
}
|
||||
return getTranscoder().decode(url);
|
||||
}
|
||||
// fallback
|
||||
return text;
|
||||
// nothing found
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare request for dispatch and get request dispatcher.
|
||||
*
|
||||
* @param request http request which will be further prepared for dispatch
|
||||
* @param text textual diagram source
|
||||
*
|
||||
* @throws IOException if an input or output exception occurred
|
||||
*/
|
||||
private void prepareRequestForDispatch(HttpServletRequest request, String text) throws IOException {
|
||||
// diagram sources
|
||||
final String encoded = getTranscoder().encode(text);
|
||||
request.setAttribute("decoded", text);
|
||||
request.setAttribute("encoded", encoded);
|
||||
// properties
|
||||
request.setAttribute("showSocialButtons", Configuration.get("SHOW_SOCIAL_BUTTONS"));
|
||||
request.setAttribute("showGithubRibbon", Configuration.get("SHOW_GITHUB_RIBBON"));
|
||||
// URL base
|
||||
final String hostpath = getHostpath(request);
|
||||
request.setAttribute("hostpath", hostpath);
|
||||
// image URLs
|
||||
final boolean hasImg = !text.isEmpty();
|
||||
request.setAttribute("hasImg", hasImg);
|
||||
request.setAttribute("imgurl", hostpath + "/png/" + encoded);
|
||||
request.setAttribute("svgurl", hostpath + "/svg/" + encoded);
|
||||
request.setAttribute("txturl", hostpath + "/txt/" + encoded);
|
||||
request.setAttribute("mapurl", hostpath + "/map/" + encoded);
|
||||
// map for diagram source if necessary
|
||||
final boolean hasMap = PlantumlUtils.hasCMapData(text);
|
||||
request.setAttribute("hasMap", hasMap);
|
||||
String map = "";
|
||||
if (hasMap) {
|
||||
try {
|
||||
map = UmlExtractor.extractMap(text);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
request.setAttribute("map", map);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get hostpath (URL base) from request.
|
||||
*
|
||||
* @param request http request
|
||||
*
|
||||
* @return hostpath
|
||||
*/
|
||||
private String getHostpath(final HttpServletRequest request) {
|
||||
// port
|
||||
String port = "";
|
||||
if (
|
||||
(request.getScheme() == "http" && request.getServerPort() != 80)
|
||||
||
|
||||
(request.getScheme() == "https" && request.getServerPort() != 443)
|
||||
) {
|
||||
port = ":" + request.getServerPort();
|
||||
}
|
||||
// scheme
|
||||
String scheme = request.getScheme();
|
||||
final String forwardedProto = request.getHeader("x-forwarded-proto");
|
||||
if (forwardedProto != null && !forwardedProto.isEmpty()) {
|
||||
scheme = forwardedProto;
|
||||
}
|
||||
// hostpath
|
||||
return scheme + "://" + request.getServerName() + port + request.getContextPath();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,11 +29,17 @@ import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.security.cert.Certificate;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.imageio.IIOException;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLPeerUnverifiedException;
|
||||
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import net.sourceforge.plantuml.BlockUml;
|
||||
import net.sourceforge.plantuml.FileFormat;
|
||||
@@ -42,13 +48,6 @@ import net.sourceforge.plantuml.SourceStringReader;
|
||||
import net.sourceforge.plantuml.core.Diagram;
|
||||
import net.sourceforge.plantuml.core.UmlSource;
|
||||
|
||||
import java.security.cert.Certificate;
|
||||
import java.util.List;
|
||||
|
||||
import javax.imageio.IIOException;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLPeerUnverifiedException;
|
||||
|
||||
/**
|
||||
* Proxy servlet of the webapp.
|
||||
* This servlet retrieves the diagram source of a web resource (web html page)
|
||||
|
||||
@@ -23,20 +23,21 @@
|
||||
*/
|
||||
package net.sourceforge.plantuml.servlet;
|
||||
|
||||
import net.sourceforge.plantuml.FileFormat;
|
||||
import net.sourceforge.plantuml.OptionFlags;
|
||||
import net.sourceforge.plantuml.servlet.utility.UmlExtractor;
|
||||
|
||||
import javax.imageio.IIOException;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.imageio.IIOException;
|
||||
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import net.sourceforge.plantuml.FileFormat;
|
||||
import net.sourceforge.plantuml.OptionFlags;
|
||||
import net.sourceforge.plantuml.servlet.utility.UmlExtractor;
|
||||
|
||||
/**
|
||||
* Common service servlet to produce diagram from compressed UML source contained in the end part of the requested URI.
|
||||
*/
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
/* ========================================================================
|
||||
* PlantUML : a free UML diagram generator
|
||||
* ========================================================================
|
||||
*
|
||||
* Project Info: https://plantuml.com
|
||||
*
|
||||
* 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;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* Welcome servlet of the webapp.
|
||||
* Displays the sample Bob and Alice sequence diagram.
|
||||
*/
|
||||
@SuppressWarnings("SERIAL")
|
||||
public class Welcome extends HttpServlet {
|
||||
|
||||
@Override
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
||||
|
||||
// set the sample
|
||||
request.setAttribute("decoded", "Bob -> Alice : hello");
|
||||
request.setAttribute("encoded", "SyfFKj2rKt3CoKnELR1Io4ZDoSa70000");
|
||||
|
||||
// forward to index.jsp
|
||||
RequestDispatcher dispatcher = request.getRequestDispatcher("/index.jsp");
|
||||
dispatcher.forward(request, response);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -85,10 +85,10 @@ public final class Configuration {
|
||||
* @return true if the value is "on"
|
||||
*/
|
||||
public static boolean get(final String key) {
|
||||
if (instance.config.getProperty(key) == null) {
|
||||
if (get().getProperty(key) == null) {
|
||||
return false;
|
||||
}
|
||||
return instance.config.getProperty(key).startsWith("on");
|
||||
return get().getProperty(key).startsWith("on");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,9 +27,14 @@ import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
|
||||
import net.sourceforge.plantuml.FileFormat;
|
||||
import net.sourceforge.plantuml.FileFormatOption;
|
||||
import net.sourceforge.plantuml.OptionFlags;
|
||||
import net.sourceforge.plantuml.SourceStringReader;
|
||||
import net.sourceforge.plantuml.code.Transcoder;
|
||||
import net.sourceforge.plantuml.code.TranscoderUtil;
|
||||
import net.sourceforge.plantuml.core.Diagram;
|
||||
import net.sourceforge.plantuml.core.ImageData;
|
||||
|
||||
/**
|
||||
* Utility class to extract the UML source from the compressed UML source contained in the end part
|
||||
@@ -84,4 +89,36 @@ public abstract class UmlExtractor {
|
||||
return uml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get image map from uml.
|
||||
*
|
||||
* @param uml textual diagram source
|
||||
*
|
||||
* @return image map of the diagram in HTML format if the image has some position information; otherwise `null`
|
||||
*
|
||||
* @throws IOException if an input or output exception occurred
|
||||
*/
|
||||
public static String extractMap(final String uml) throws IOException {
|
||||
return extractMap(uml, FileFormat.PNG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get image map from uml.
|
||||
*
|
||||
* @param uml textual diagram source
|
||||
* @param fileFormat underlying file format of uml image
|
||||
*
|
||||
* @return image map of the diagram in HTML format if the image has some position information; otherwise `null`
|
||||
*
|
||||
* @throws IOException if an input or output exception occurred
|
||||
*/
|
||||
public static String extractMap(final String uml, final FileFormat fileFormat) throws IOException {
|
||||
Diagram diagram = new SourceStringReader(uml).getBlocks().get(0).getDiagram();
|
||||
ImageData map = diagram.exportDiagram(new NullOutputStream(), 0, new FileFormatOption(fileFormat, false));
|
||||
if (map.containsCMapData()) {
|
||||
return map.getCMapData("plantuml");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user