Java Code Examples for javax.servlet.jsp.PageContext#getServletContext()

The following examples show how to use javax.servlet.jsp.PageContext#getServletContext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HtmlEscapeTagTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void htmlEscapeTagWithContextParamTrue() throws JspException {
	PageContext pc = createPageContext();
	MockServletContext sc = (MockServletContext) pc.getServletContext();
	sc.addInitParameter(WebUtils.HTML_ESCAPE_CONTEXT_PARAM, "true");
	HtmlEscapeTag tag = new HtmlEscapeTag();
	tag.setDefaultHtmlEscape(false);
	tag.setPageContext(pc);
	tag.doStartTag();

	assertTrue("Correct default", !tag.getRequestContext().isDefaultHtmlEscape());
	tag.setDefaultHtmlEscape(true);
	assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
	assertTrue("Correctly enabled", tag.getRequestContext().isDefaultHtmlEscape());
	tag.setDefaultHtmlEscape(false);
	assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
	assertTrue("Correctly disabled", !tag.getRequestContext().isDefaultHtmlEscape());
}
 
Example 2
Source File: HtmlEscapeTagTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void htmlEscapeTagWithContextParamFalse() throws JspException {
	PageContext pc = createPageContext();
	MockServletContext sc = (MockServletContext) pc.getServletContext();
	HtmlEscapeTag tag = new HtmlEscapeTag();
	tag.setPageContext(pc);
	tag.doStartTag();

	sc.addInitParameter(WebUtils.HTML_ESCAPE_CONTEXT_PARAM, "false");
	assertTrue("Correct default", !tag.getRequestContext().isDefaultHtmlEscape());
	tag.setDefaultHtmlEscape(true);
	assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
	assertTrue("Correctly enabled", tag.getRequestContext().isDefaultHtmlEscape());
	tag.setDefaultHtmlEscape(false);
	assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
	assertTrue("Correctly disabled", !tag.getRequestContext().isDefaultHtmlEscape());
}
 
Example 3
Source File: MessageTagTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
@SuppressWarnings("rawtypes")
public void requestContext() throws ServletException {
	PageContext pc = createPageContext();
	RequestContext rc = new RequestContext((HttpServletRequest) pc.getRequest(), pc.getServletContext());
	assertEquals("test message", rc.getMessage("test"));
	assertEquals("test message", rc.getMessage("test", (Object[]) null));
	assertEquals("test message", rc.getMessage("test", "default"));
	assertEquals("test message", rc.getMessage("test", (Object[]) null, "default"));
	assertEquals("test arg1 message arg2",
			rc.getMessage("testArgs", new String[] {"arg1", "arg2"}, "default"));
	assertEquals("test arg1 message arg2",
			rc.getMessage("testArgs", Arrays.asList(new String[] {"arg1", "arg2"}), "default"));
	assertEquals("default", rc.getMessage("testa", "default"));
	assertEquals("default", rc.getMessage("testa", (List) null, "default"));
	MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(new String[] {"test"});
	assertEquals("test message", rc.getMessage(resolvable));
}
 
Example 4
Source File: HtmlEscapeTagTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void htmlEscapeTagWithContextParamTrue() throws JspException {
	PageContext pc = createPageContext();
	MockServletContext sc = (MockServletContext) pc.getServletContext();
	sc.addInitParameter(WebUtils.HTML_ESCAPE_CONTEXT_PARAM, "true");
	HtmlEscapeTag tag = new HtmlEscapeTag();
	tag.setDefaultHtmlEscape(false);
	tag.setPageContext(pc);
	tag.doStartTag();

	assertTrue("Correct default", !tag.getRequestContext().isDefaultHtmlEscape());
	tag.setDefaultHtmlEscape(true);
	assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
	assertTrue("Correctly enabled", tag.getRequestContext().isDefaultHtmlEscape());
	tag.setDefaultHtmlEscape(false);
	assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
	assertTrue("Correctly disabled", !tag.getRequestContext().isDefaultHtmlEscape());
}
 
Example 5
Source File: HtmlEscapeTagTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void htmlEscapeTagWithContextParamFalse() throws JspException {
	PageContext pc = createPageContext();
	MockServletContext sc = (MockServletContext) pc.getServletContext();
	HtmlEscapeTag tag = new HtmlEscapeTag();
	tag.setPageContext(pc);
	tag.doStartTag();

	sc.addInitParameter(WebUtils.HTML_ESCAPE_CONTEXT_PARAM, "false");
	assertTrue("Correct default", !tag.getRequestContext().isDefaultHtmlEscape());
	tag.setDefaultHtmlEscape(true);
	assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
	assertTrue("Correctly enabled", tag.getRequestContext().isDefaultHtmlEscape());
	tag.setDefaultHtmlEscape(false);
	assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
	assertTrue("Correctly disabled", !tag.getRequestContext().isDefaultHtmlEscape());
}
 
Example 6
Source File: MessageTagTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("rawtypes")
public void requestContext() throws ServletException {
	PageContext pc = createPageContext();
	RequestContext rc = new RequestContext((HttpServletRequest) pc.getRequest(), pc.getServletContext());
	assertEquals("test message", rc.getMessage("test"));
	assertEquals("test message", rc.getMessage("test", (Object[]) null));
	assertEquals("test message", rc.getMessage("test", "default"));
	assertEquals("test message", rc.getMessage("test", (Object[]) null, "default"));
	assertEquals("test arg1 message arg2",
			rc.getMessage("testArgs", new String[] {"arg1", "arg2"}, "default"));
	assertEquals("test arg1 message arg2",
			rc.getMessage("testArgs", Arrays.asList(new String[] {"arg1", "arg2"}), "default"));
	assertEquals("default", rc.getMessage("testa", "default"));
	assertEquals("default", rc.getMessage("testa", (List) null, "default"));
	MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(new String[] {"test"});
	assertEquals("test message", rc.getMessage(resolvable));
}
 
Example 7
Source File: HtmlEscapeTagTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void htmlEscapeTagWithContextParamTrue() throws JspException {
	PageContext pc = createPageContext();
	MockServletContext sc = (MockServletContext) pc.getServletContext();
	sc.addInitParameter(WebUtils.HTML_ESCAPE_CONTEXT_PARAM, "true");
	HtmlEscapeTag tag = new HtmlEscapeTag();
	tag.setDefaultHtmlEscape(false);
	tag.setPageContext(pc);
	tag.doStartTag();

	assertTrue("Correct default", !tag.getRequestContext().isDefaultHtmlEscape());
	tag.setDefaultHtmlEscape(true);
	assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
	assertTrue("Correctly enabled", tag.getRequestContext().isDefaultHtmlEscape());
	tag.setDefaultHtmlEscape(false);
	assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
	assertTrue("Correctly disabled", !tag.getRequestContext().isDefaultHtmlEscape());
}
 
Example 8
Source File: HtmlEscapeTagTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void htmlEscapeTagWithContextParamFalse() throws JspException {
	PageContext pc = createPageContext();
	MockServletContext sc = (MockServletContext) pc.getServletContext();
	HtmlEscapeTag tag = new HtmlEscapeTag();
	tag.setPageContext(pc);
	tag.doStartTag();

	sc.addInitParameter(WebUtils.HTML_ESCAPE_CONTEXT_PARAM, "false");
	assertTrue("Correct default", !tag.getRequestContext().isDefaultHtmlEscape());
	tag.setDefaultHtmlEscape(true);
	assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
	assertTrue("Correctly enabled", tag.getRequestContext().isDefaultHtmlEscape());
	tag.setDefaultHtmlEscape(false);
	assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
	assertTrue("Correctly disabled", !tag.getRequestContext().isDefaultHtmlEscape());
}
 
Example 9
Source File: MessageTagTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
@SuppressWarnings("rawtypes")
public void requestContext() throws ServletException {
	PageContext pc = createPageContext();
	RequestContext rc = new RequestContext((HttpServletRequest) pc.getRequest(), pc.getServletContext());
	assertEquals("test message", rc.getMessage("test"));
	assertEquals("test message", rc.getMessage("test", (Object[]) null));
	assertEquals("test message", rc.getMessage("test", "default"));
	assertEquals("test message", rc.getMessage("test", (Object[]) null, "default"));
	assertEquals("test arg1 message arg2",
			rc.getMessage("testArgs", new String[] {"arg1", "arg2"}, "default"));
	assertEquals("test arg1 message arg2",
			rc.getMessage("testArgs", Arrays.asList(new String[] {"arg1", "arg2"}), "default"));
	assertEquals("default", rc.getMessage("testa", "default"));
	assertEquals("default", rc.getMessage("testa", (List) null, "default"));
	MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(new String[] {"test"});
	assertEquals("test message", rc.getMessage(resolvable));
}
 
Example 10
Source File: ImplicitObjectELResolver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 *
 * Creates the Map that maps init parameter name to single init
 * parameter value.
 **/
public static Map createInitParamMap (PageContext pContext)
{
  final ServletContext context = pContext.getServletContext ();
  return new EnumeratedMap ()
    {
      public Enumeration enumerateKeys () 
      {
        return context.getInitParameterNames ();
      }

      public Object getValue (Object pKey) 
      {
        if (pKey instanceof String) {
          return context.getInitParameter ((String) pKey);
        }
        else {
          return null;
        }
      }

      public boolean isMutable ()
      {
        return false;
      }
    };
}
 
Example 11
Source File: Include.java    From Bootstrap.jsp with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void doTag() throws JspException, IOException {
	final JspWriter writer = this.getJspContext().getOut();
	final PageContext pageContext = (PageContext) this.getJspContext();
	final ServletContext sc = pageContext.getServletContext();
	InputStream in = sc.getResourceAsStream(this.path);
	InputStreamReader reader = new InputStreamReader(in);
	this.write(reader, writer);
}
 
Example 12
Source File: WebBean.java    From Openfire with Apache License 2.0 5 votes vote down vote up
public void init(PageContext pageContext){
    this.request = (HttpServletRequest)pageContext.getRequest();
    this.response = (HttpServletResponse)pageContext.getResponse();
    this.session = pageContext.getSession();
    this.application = pageContext.getServletContext();
    this.out = pageContext.getOut();
}
 
Example 13
Source File: JspToolContext.java    From velocity-tools with Apache License 2.0 5 votes vote down vote up
public JspToolContext(VelocityEngine velocity,
                      PageContext pageContext)
{
    super(velocity,
          (HttpServletRequest)pageContext.getRequest(),
          (HttpServletResponse)pageContext.getResponse(),
          pageContext.getServletContext());

    this.pageContext = pageContext;
}
 
Example 14
Source File: JspAwareRequestContext.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Create a new JspAwareRequestContext for the given page context,
 * using the given model attributes for Errors retrieval.
 * @param pageContext current JSP page context
 * @param model the model attributes for the current view
 * (can be {@code null}, using the request attributes for Errors retrieval)
 */
public JspAwareRequestContext(PageContext pageContext, @Nullable Map<String, Object> model) {
	super((HttpServletRequest) pageContext.getRequest(), (HttpServletResponse) pageContext.getResponse(),
			pageContext.getServletContext(), model);
	this.pageContext = pageContext;
}
 
Example 15
Source File: JspAwareRequestContext.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Create a new JspAwareRequestContext for the given page context,
 * using the given model attributes for Errors retrieval.
 * @param pageContext current JSP page context
 * @param model the model attributes for the current view
 * (can be {@code null}, using the request attributes for Errors retrieval)
 */
public JspAwareRequestContext(PageContext pageContext, @Nullable Map<String, Object> model) {
	super((HttpServletRequest) pageContext.getRequest(), (HttpServletResponse) pageContext.getResponse(),
			pageContext.getServletContext(), model);
	this.pageContext = pageContext;
}