This is an automated email from the ASF dual-hosted git repository. lukaszlenart pushed a commit to branch action-context-boost in repository https://gitbox.apache.org/repos/asf/struts.git
commit 6c76275af69fa64067fc1bf5281bfd8e1eb210a5 Author: Lukasz Lenart <lukaszlen...@apache.org> AuthorDate: Tue Apr 28 08:14:45 2020 +0200 WW-4789 WW-3788 Cleans up code & JavaDocs formatting --- .../org/apache/struts2/result/PlainTextResult.java | 17 +---------- .../struts2/result/ServletRedirectResult.java | 20 ++----------- .../org/apache/struts2/result/StreamResult.java | 28 +++++------------ .../org/apache/struts2/views/util/ContextUtil.java | 35 +++++++++++----------- 4 files changed, 27 insertions(+), 73 deletions(-) diff --git a/core/src/main/java/org/apache/struts2/result/PlainTextResult.java b/core/src/main/java/org/apache/struts2/result/PlainTextResult.java index c264817..7baaa05 100644 --- a/core/src/main/java/org/apache/struts2/result/PlainTextResult.java +++ b/core/src/main/java/org/apache/struts2/result/PlainTextResult.java @@ -31,15 +31,8 @@ import java.io.PrintWriter; import java.nio.charset.Charset; /** - * <!-- START SNIPPET: description --> - * <p> * A result that send the content out as plain text. Useful typically when needed * to display the raw content of a JSP or Html file for example. - * <p> - * <!-- END SNIPPET: description --> - * <p> - * <p> - * <!-- START SNIPPET: params --> * * <ul> * <li>location (default) = location of the file (jsp/html) to be displayed as plain text.</li> @@ -47,26 +40,18 @@ import java.nio.charset.Charset; * response type (eg. Content-Type=text/plain; charset=UTF-8) and when reading * using a Reader. Some example of charSet would be UTF-8, ISO-8859-1 etc. * </ul> - * <p> - * <!-- END SNIPPET: params --> - * - * - * <pre> - * <!-- START SNIPPET: example --> * + * <pre> * <action name="displayJspRawContent" > * <result type="plainText">/myJspFile.jsp</result> * </action> * - * * <action name="displayJspRawContent" > * <result type="plainText"> * <param name="location">/myJspFile.jsp</param> * <param name="charSet">UTF-8</param> * </result> * </action> - * - * <!-- END SNIPPET: example --> * </pre> */ public class PlainTextResult extends StrutsResultSupport { diff --git a/core/src/main/java/org/apache/struts2/result/ServletRedirectResult.java b/core/src/main/java/org/apache/struts2/result/ServletRedirectResult.java index 0973492..9d7b461 100644 --- a/core/src/main/java/org/apache/struts2/result/ServletRedirectResult.java +++ b/core/src/main/java/org/apache/struts2/result/ServletRedirectResult.java @@ -46,8 +46,6 @@ import java.util.Map; import static javax.servlet.http.HttpServletResponse.SC_FOUND; /** - * <!-- START SNIPPET: description --> - * <p> * Calls the {@link HttpServletResponse#sendRedirect(String) sendRedirect} * method to the location specified. The response is told to redirect the * browser to the specified location (a new request from the client). The @@ -56,33 +54,19 @@ import static javax.servlet.http.HttpServletResponse.SC_FOUND; * available. This is because actions are built on a single-thread model. The * only way to pass data is through the session or with web parameters * (url?name=value) which can be OGNL expressions. - * </p> - * <!-- END SNIPPET: description --> - * <p> + * * <b>This result type takes the following parameters:</b> - * </p> - * <!-- START SNIPPET: params --> * * <ul> - * * <li><b>location (default)</b> - the location to go to after execution.</li> - * * <li><b>parse</b> - true by default. If set to false, the location param will * not be parsed for Ognl expressions.</li> - * * <li><b>anchor</b> - Optional. Also known as "fragment" or colloquially as * "hash". You can specify an anchor for a result.</li> * </ul> - * - * <p> * This result follows the same rules from {@link StrutsResultSupport}. - * </p> - * <p> - * <!-- END SNIPPET: params --> - * <p> - * <b>Example:</b> - * </p> * + * <b>Example:</b> * <pre> * <!-- START SNIPPET: example --> * <!-- diff --git a/core/src/main/java/org/apache/struts2/result/StreamResult.java b/core/src/main/java/org/apache/struts2/result/StreamResult.java index 47dbc45..711929f 100644 --- a/core/src/main/java/org/apache/struts2/result/StreamResult.java +++ b/core/src/main/java/org/apache/struts2/result/StreamResult.java @@ -27,60 +27,46 @@ import java.io.InputStream; import java.io.OutputStream; /** - * <!-- START SNIPPET: description --> - * <p> * A custom Result type for sending raw data (via an InputStream) directly to the * HttpServletResponse. Very useful for allowing users to download content. - * </p> - * <!-- END SNIPPET: description --> - * <p> + * * <b>This result type takes the following parameters:</b> - * </p> - * <!-- START SNIPPET: params --> * * <ul> - * * <li><b>contentType</b> - the stream mime-type as sent to the web browser * (default = <code>text/plain</code>).</li> - * * <li><b>contentLength</b> - the stream length in bytes (the browser displays a * progress bar).</li> - * * <li><b>contentDisposition</b> - the content disposition header value for * specifing the file name (default = <code>inline</code>, values are typically * <i>attachment;filename="document.pdf"</i>.</li> - * * <li><b>inputName</b> - the name of the InputStream property from the chained * action (default = <code>inputStream</code>).</li> - * * <li><b>bufferSize</b> - the size of the buffer to copy from input to output * (default = <code>1024</code>).</li> - * * <li><b>allowCaching</b> if set to 'false' it will set the headers 'Pragma' and 'Cache-Control' * to 'no-cahce', and prevent client from caching the content. (default = <code>true</code>) - * * <li><b>contentCharSet</b> if set to a string, ';charset=value' will be added to the * content-type header, where value is the string set. If set to an expression, the result * of evaluating the expression will be used. If not set, then no charset will be set on * the header</li> * </ul> * - * <p>These parameters can also be set by exposing a similarly named getter method on your Action. For example, you can - * provide <code>getContentType()</code> to override that parameter for the current action.</p> * <p> - * <!-- END SNIPPET: params --> - * <p> - * <b>Example:</b> + * These parameters can also be set by exposing a similarly named getter method on your Action. For example, you can + * provide <code>getContentType()</code> to override that parameter for the current action. * </p> * - * <pre><!-- START SNIPPET: example --> + * <b>Example:</b> + * + * <pre> * <result name="success" type="stream"> * <param name="contentType">image/jpeg</param> * <param name="inputName">imageStream</param> * <param name="contentDisposition">attachment;filename="document.pdf"</param> * <param name="bufferSize">1024</param> * </result> - * <!-- END SNIPPET: example --></pre> + * </pre> */ public class StreamResult extends StrutsResultSupport { diff --git a/core/src/main/java/org/apache/struts2/views/util/ContextUtil.java b/core/src/main/java/org/apache/struts2/views/util/ContextUtil.java index d213f5a..7cc1aab 100644 --- a/core/src/main/java/org/apache/struts2/views/util/ContextUtil.java +++ b/core/src/main/java/org/apache/struts2/views/util/ContextUtil.java @@ -18,26 +18,20 @@ */ package org.apache.struts2.views.util; -import java.util.HashMap; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionInvocation; +import com.opensymphony.xwork2.util.ValueStack; import org.apache.struts2.StrutsConstants; import org.apache.struts2.util.StrutsUtil; import org.apache.struts2.views.jsp.ui.OgnlTool; -import com.opensymphony.xwork2.ActionContext; -import com.opensymphony.xwork2.ActionInvocation; -import com.opensymphony.xwork2.conversion.impl.XWorkConverter; -import com.opensymphony.xwork2.inject.Container; -import com.opensymphony.xwork2.inject.Inject; -import com.opensymphony.xwork2.util.ValueStack; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.HashMap; +import java.util.Map; /** * Value Stack's Context related Utilities. - * */ public class ContextUtil { public static final String REQUEST = "request"; @@ -48,7 +42,7 @@ public class ContextUtil { public static final String OGNL = "ognl"; public static final String STRUTS = "struts"; public static final String ACTION = "action"; - + public static Map<String, Object> getStandardContext(ValueStack stack, HttpServletRequest req, HttpServletResponse res) { HashMap<String, Object> map = new HashMap<>(); map.put(REQUEST, req); @@ -68,6 +62,7 @@ public class ContextUtil { /** * Return true if either Configuration's altSyntax is on or the stack context's useAltSyntax is on + * * @param context stack's context * @return boolean */ @@ -76,18 +71,22 @@ public class ContextUtil { // plus the Configuration implementation should cache the properties, which the framework's // configuration implementation does String tagAltSytnax = ActionContext.of(context).getContainer().getInstance(String.class, StrutsConstants.STRUTS_TAG_ALTSYNTAX); - return "true".equals(tagAltSytnax) ||( - (context.containsKey("useAltSyntax") && - context.get("useAltSyntax") != null && - "true".equals(context.get("useAltSyntax").toString()))); + + return "true".equals(tagAltSytnax) || ( + (context.containsKey("useAltSyntax") && + context.get("useAltSyntax") != null && + "true".equals(context.get("useAltSyntax").toString())) + ); } /** * Returns a String for overriding the default templateSuffix if templateSuffix is on the stack + * * @param context stack's context * @return String */ public static String getTemplateSuffix(Map<String, Object> context) { return context.containsKey("templateSuffix") ? (String) context.get("templateSuffix") : null; } + }