/** * Return the applicable default HTML escape setting for this tag. * <p>The default implementation checks the RequestContext's setting, * falling back to {@code false} in case of no explicit default given. * @see #getRequestContext() */ protected boolean isDefaultHtmlEscape() { return getRequestContext().isDefaultHtmlEscape(); }
/** * Retrieve the message for the given code, using the "defaultHtmlEscape" setting. * @param code code of the message * @param defaultMessage the String to return if the lookup fails * @return the message */ public String getMessage(String code, String defaultMessage) { return getMessage(code, null, defaultMessage, isDefaultHtmlEscape()); }
/** * Retrieve the message for the given code, using the "defaultHtmlEscape" setting. * @param code code of the message * @return the message * @throws org.springframework.context.NoSuchMessageException if not found */ public String getMessage(String code) throws NoSuchMessageException { return getMessage(code, null, isDefaultHtmlEscape()); }
/** * Create a BindStatus for the given bind object, using the "defaultHtmlEscape" setting. * @param path the bean and property path for which values and errors will be resolved (e.g. "person.age") * @return the new BindStatus instance * @throws IllegalStateException if no corresponding Errors object found */ public BindStatus getBindStatus(String path) throws IllegalStateException { return new BindStatus(this, path, isDefaultHtmlEscape()); }
/** * Retrieve the message for the given code, using the "defaultHtmlEscape" setting. * @param code code of the message * @param args arguments for the message as a List, or {@code null} if none * @return the message * @throws org.springframework.context.NoSuchMessageException if not found */ public String getMessage(String code, @Nullable List<?> args) throws NoSuchMessageException { return getMessage(code, (args != null ? args.toArray() : null), isDefaultHtmlEscape()); }
/** * Retrieve the message for the given code, using the "defaultHtmlEscape" setting. * @param code code of the message * @param args arguments for the message as a List, or {@code null} if none * @param defaultMessage the String to return if the lookup fails * @return the message */ public String getMessage(String code, @Nullable List<?> args, String defaultMessage) { return getMessage(code, (args != null ? args.toArray() : null), defaultMessage, isDefaultHtmlEscape()); }
/** * Retrieve the message for the given code, using the "defaultHtmlEscape" setting. * @param code code of the message * @param args arguments for the message, or {@code null} if none * @param defaultMessage the String to return if the lookup fails * @return the message */ public String getMessage(String code, @Nullable Object[] args, String defaultMessage) { return getMessage(code, args, defaultMessage, isDefaultHtmlEscape()); }
/** * Retrieve the message for the given code, using the "defaultHtmlEscape" setting. * @param code code of the message * @param args arguments for the message, or {@code null} if none * @return the message * @throws org.springframework.context.NoSuchMessageException if not found */ public String getMessage(String code, @Nullable Object[] args) throws NoSuchMessageException { return getMessage(code, args, isDefaultHtmlEscape()); }
/** * Retrieve the given MessageSourceResolvable (e.g. an ObjectError instance), using the "defaultHtmlEscape" setting. * @param resolvable the MessageSourceResolvable * @return the message * @throws org.springframework.context.NoSuchMessageException if not found */ public String getMessage(MessageSourceResolvable resolvable) throws NoSuchMessageException { return getMessage(resolvable, isDefaultHtmlEscape()); }
/** * Retrieve the Errors instance for the given bind object, using the "defaultHtmlEscape" setting. * @param name name of the bind object * @return the Errors instance, or {@code null} if not found */ @Nullable public Errors getErrors(String name) { return getErrors(name, isDefaultHtmlEscape()); }
/** * Create a BindStatus for the given bind object, using the "defaultHtmlEscape" setting. * @param path the bean and property path for which values and errors will be resolved (e.g. "person.age") * @return the new BindStatus instance * @throws IllegalStateException if no corresponding Errors object found */ public BindStatus getBindStatus(String path) throws IllegalStateException { return new BindStatus(this, path, isDefaultHtmlEscape()); }
/** * Retrieve the message for the given code, using the "defaultHtmlEscape" setting. * @param code code of the message * @param args arguments for the message, or {@code null} if none * @return the message * @throws org.springframework.context.NoSuchMessageException if not found */ public String getMessage(String code, @Nullable Object[] args) throws NoSuchMessageException { return getMessage(code, args, isDefaultHtmlEscape()); }
/** * Retrieve the Errors instance for the given bind object, using the "defaultHtmlEscape" setting. * @param name name of the bind object * @return the Errors instance, or {@code null} if not found */ @Nullable public Errors getErrors(String name) { return getErrors(name, isDefaultHtmlEscape()); }
/** * Return the applicable default HTML escape setting for this tag. * <p>The default implementation checks the RequestContext's setting, * falling back to {@code false} in case of no explicit default given. * @see #getRequestContext() */ protected boolean isDefaultHtmlEscape() { return getRequestContext().isDefaultHtmlEscape(); }
/** * Retrieve the message for the given code, using the "defaultHtmlEscape" setting. * @param code code of the message * @param defaultMessage the String to return if the lookup fails * @return the message */ public String getMessage(String code, String defaultMessage) { return getMessage(code, null, defaultMessage, isDefaultHtmlEscape()); }
/** * Retrieve the message for the given code, using the "defaultHtmlEscape" setting. * @param code code of the message * @return the message * @throws org.springframework.context.NoSuchMessageException if not found */ public String getMessage(String code) throws NoSuchMessageException { return getMessage(code, null, isDefaultHtmlEscape()); }
/** * Retrieve the message for the given code, using the "defaultHtmlEscape" setting. * @param code code of the message * @param args arguments for the message as a List, or {@code null} if none * @return the message * @throws org.springframework.context.NoSuchMessageException if not found */ public String getMessage(String code, @Nullable List<?> args) throws NoSuchMessageException { return getMessage(code, (args != null ? args.toArray() : null), isDefaultHtmlEscape()); }
/** * Retrieve the given MessageSourceResolvable (e.g. an ObjectError instance), using the "defaultHtmlEscape" setting. * @param resolvable the MessageSourceResolvable * @return the message * @throws org.springframework.context.NoSuchMessageException if not found */ public String getMessage(MessageSourceResolvable resolvable) throws NoSuchMessageException { return getMessage(resolvable, isDefaultHtmlEscape()); }
@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()); }
@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()); }