mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
WW-4789 WW-3788 Cleans up code & JavaDocs formatting
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 -->
|
||||
* <!--
|
||||
|
||||
@@ -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 {
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@ import javax.servlet.jsp.PageContext;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* Unit test for {@link ActionTag}.
|
||||
*/
|
||||
@@ -156,7 +155,7 @@ public class ActionTagTest extends AbstractTagTest {
|
||||
TestActionTagResult result = (TestActionTagResult) component.getProxy().getInvocation().getResult();
|
||||
|
||||
assertTrue(stack.getContext().containsKey(ServletActionContext.PAGE_CONTEXT));
|
||||
assertTrue(stack.getContext().get(ServletActionContext.PAGE_CONTEXT)instanceof PageContext);
|
||||
assertTrue(stack.getContext().get(ServletActionContext.PAGE_CONTEXT) instanceof PageContext);
|
||||
assertTrue(result.isExecuted());
|
||||
}
|
||||
|
||||
@@ -177,11 +176,11 @@ public class ActionTagTest extends AbstractTagTest {
|
||||
TestActionTagResult result = (TestActionTagResult) component.getProxy().getInvocation().getResult();
|
||||
|
||||
assertTrue(stack.getContext().containsKey(ServletActionContext.PAGE_CONTEXT));
|
||||
assertTrue(stack.getContext().get(ServletActionContext.PAGE_CONTEXT)instanceof PageContext);
|
||||
assertTrue(stack.getContext().get(ServletActionContext.PAGE_CONTEXT) instanceof PageContext);
|
||||
assertNull(result); // result is never executed, hence never set into invocation
|
||||
}
|
||||
|
||||
public void testExecuteButResetReturnSameInvocation() throws Exception {
|
||||
public void testExecuteButResetReturnSameInvocation() throws Exception {
|
||||
Mock mockActionInv = new Mock(ActionInvocation.class);
|
||||
ActionTag tag = new ActionTag();
|
||||
tag.setPageContext(pageContext);
|
||||
@@ -199,7 +198,7 @@ public class ActionTagTest extends AbstractTagTest {
|
||||
ActionComponent component = (ActionComponent) tag.getComponent();
|
||||
|
||||
tag.doEndTag();
|
||||
assertSame(oldInvocation, ActionContext.getContext().getActionInvocation());
|
||||
assertSame(oldInvocation, ActionContext.getContext().getActionInvocation());
|
||||
}
|
||||
|
||||
public void testIngoreContextParamsFalse() throws Exception {
|
||||
@@ -236,7 +235,7 @@ public class ActionTagTest extends AbstractTagTest {
|
||||
tag.setIgnoreContextParams(true);
|
||||
|
||||
Map<String, String[]> params = new HashMap<>();
|
||||
params.put("user", new String[] { "Santa Claus" });
|
||||
params.put("user", new String[]{"Santa Claus"});
|
||||
ActionContext.getContext().setParameters(HttpParameters.create(params).build());
|
||||
|
||||
tag.doStartTag();
|
||||
@@ -264,7 +263,7 @@ public class ActionTagTest extends AbstractTagTest {
|
||||
tag.doEndTag();
|
||||
fail("Should have thrown RuntimeException");
|
||||
} catch (StrutsException e) {
|
||||
assertEquals("tag 'actioncomponent', field 'name': Action name is required. Example: updatePerson", e.getMessage());
|
||||
assertEquals("tag 'actioncomponent', field 'name': Action name is required. Example: updatePerson", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,7 +286,7 @@ public class ActionTagTest extends AbstractTagTest {
|
||||
tag.setNamespace("");
|
||||
tag.setName("testActionTagAction!input");
|
||||
tag.setExecuteResult(true);
|
||||
((DefaultActionMapper)container.getInstance(ActionMapper.class)).setAllowDynamicMethodCalls("true");
|
||||
((DefaultActionMapper) container.getInstance(ActionMapper.class)).setAllowDynamicMethodCalls("true");
|
||||
|
||||
tag.doStartTag();
|
||||
|
||||
@@ -299,13 +298,15 @@ public class ActionTagTest extends AbstractTagTest {
|
||||
TestActionTagResult result = (TestActionTagResult) component.getProxy().getInvocation().getResult();
|
||||
|
||||
assertTrue(stack.getContext().containsKey(ServletActionContext.PAGE_CONTEXT));
|
||||
assertTrue(stack.getContext().get(ServletActionContext.PAGE_CONTEXT)instanceof PageContext);
|
||||
assertTrue(stack.getContext().get(ServletActionContext.PAGE_CONTEXT) instanceof PageContext);
|
||||
assertTrue(result.isExecuted());
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
initDispatcher(new HashMap<String, String>() {{ put("configProviders", TestConfigurationProvider.class.getName()); }});
|
||||
initDispatcher(new HashMap<String, String>() {{
|
||||
put("configProviders", TestConfigurationProvider.class.getName());
|
||||
}});
|
||||
createMocks();
|
||||
}
|
||||
|
||||
|
||||
@@ -34,17 +34,17 @@ import java.util.Map;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
|
||||
|
||||
/**
|
||||
* <!-- START SNIPPET: description -->
|
||||
* <p>
|
||||
* An interceptor that makes sure there are not validation errors before allowing the interceptor chain to continue.
|
||||
* <b>This interceptor does not perform any validation</b>.
|
||||
*
|
||||
* <p>
|
||||
* Copied from the {@link com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor}, this interceptor adds support
|
||||
* for error handling of Restful operations. For example, if an validation error is discovered, a map of errors
|
||||
* is created and processed to be returned, using the appropriate content handler for rendering the body.
|
||||
* </p>
|
||||
*
|
||||
* <p>Copied from the {@link com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor}, this interceptor adds support for error handling of Restful
|
||||
* operations. For example, if an validation error is discovered, a map of errors is created and processed to be
|
||||
* returned, using the appropriate content handler for rendering the body.</p>
|
||||
*
|
||||
* <p>This interceptor does nothing if the name of the method being invoked is specified in the <b>excludeMethods</b>
|
||||
* <p>
|
||||
* This interceptor does nothing if the name of the method being invoked is specified in the <b>excludeMethods</b>
|
||||
* parameter. <b>excludeMethods</b> accepts a comma-delimited list of method names. For example, requests to
|
||||
* <b>foo!input.action</b> and <b>foo!back.action</b> will be skipped by this interceptor if you set the
|
||||
* <b>excludeMethods</b> parameter to "input, back".
|
||||
@@ -58,34 +58,20 @@ import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
|
||||
* all methods for both parameters.
|
||||
* See {@link MethodFilterInterceptor} for more info.
|
||||
* </p>
|
||||
* <!-- END SNIPPET: description -->
|
||||
*
|
||||
* <p><u>Interceptor parameters:</u></p>
|
||||
* <p>
|
||||
* <!-- START SNIPPET: parameters -->
|
||||
* <b>Interceptor parameters:</b>
|
||||
*
|
||||
* <ul>
|
||||
*
|
||||
* <li>inputResultName - Default to "input". Determine the result name to be returned when
|
||||
* an action / field error is found.</li>
|
||||
*
|
||||
* </ul>
|
||||
* <p>
|
||||
* <!-- END SNIPPET: parameters -->
|
||||
*
|
||||
* <p><u>Extending the interceptor:</u></p>
|
||||
* <p>
|
||||
* <!-- START SNIPPET: extending -->
|
||||
* <p>
|
||||
* <b>Extending the interceptor:</b>
|
||||
* There are no known extension points for this interceptor.
|
||||
* </p>
|
||||
* <!-- END SNIPPET: extending -->
|
||||
*
|
||||
* <p><u>Example code:</u></p>
|
||||
* <b>Example code:</b>
|
||||
*
|
||||
* <pre>
|
||||
* <!-- START SNIPPET: example -->
|
||||
*
|
||||
* <action name="someAction" class="com.examples.SomeAction">
|
||||
* <interceptor-ref name="params"/>
|
||||
* <interceptor-ref name="validation"/>
|
||||
@@ -118,8 +104,6 @@ import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
|
||||
* </interceptor-ref>
|
||||
* <result name="success">good_result.ftl</result>
|
||||
* </action>
|
||||
*
|
||||
* <!-- END SNIPPET: example -->
|
||||
* </pre>
|
||||
*
|
||||
* @author Jason Carreira
|
||||
|
||||
Reference in New Issue
Block a user