/** * Build the display value of the supplied {@code Object}, HTML escaped * as required. This version is <strong>not</strong> {@link PropertyEditor}-aware. * @see #getDisplayString(Object, java.beans.PropertyEditor, boolean) */ public static String getDisplayString(@Nullable Object value, boolean htmlEscape) { String displayValue = ObjectUtils.getDisplayString(value); return (htmlEscape ? HtmlUtils.htmlEscape(displayValue) : displayValue); }
if (boundValue != null && boundValue.getClass().isEnum()) { Enum<?> boundEnum = (Enum<?>) boundValue; String enumCodeAsString = ObjectUtils.getDisplayString(boundEnum.name()); if (enumCodeAsString.equals(candidateDisplayString)) { return true; String enumLabelAsString = ObjectUtils.getDisplayString(boundEnum.toString()); if (enumLabelAsString.equals(candidateDisplayString)) { return true; else if (ObjectUtils.getDisplayString(boundValue).equals(candidateDisplayString)) { return true;
/** * Override resolve CSS class since error class is not supported. */ @Override protected String resolveCssClass() throws JspException { return ObjectUtils.getDisplayString(evaluate("cssClass", getCssClass())); }
/** * Build the display value of the supplied {@code Object}, HTML escaped * as required. This version is <strong>not</strong> {@link PropertyEditor}-aware. * @see #getDisplayString(Object, java.beans.PropertyEditor, boolean) */ public static String getDisplayString(@Nullable Object value, boolean htmlEscape) { String displayValue = ObjectUtils.getDisplayString(value); return (htmlEscape ? HtmlUtils.htmlEscape(displayValue) : displayValue); }
/** * Gets the appropriate CSS class to use based on the state of the current * {@link org.springframework.web.servlet.support.BindStatus} object. */ protected String resolveCssClass() throws JspException { if (getBindStatus().isError() && StringUtils.hasText(getCssErrorClass())) { return ObjectUtils.getDisplayString(evaluate("cssErrorClass", getCssErrorClass())); } else { return ObjectUtils.getDisplayString(evaluate("cssClass", getCssClass())); } }
@Override public int doEndTag() throws JspException { EvaluationContext evaluationContext = (EvaluationContext) this.pageContext.getAttribute(EVALUATION_CONTEXT_PAGE_ATTRIBUTE); if (evaluationContext == null) { evaluationContext = createEvaluationContext(this.pageContext); this.pageContext.setAttribute(EVALUATION_CONTEXT_PAGE_ATTRIBUTE, evaluationContext); } if (this.var != null) { Object result = (this.expression != null ? this.expression.getValue(evaluationContext) : null); this.pageContext.setAttribute(this.var, result, this.scope); } else { try { String result = (this.expression != null ? this.expression.getValue(evaluationContext, String.class) : null); result = ObjectUtils.getDisplayString(result); result = htmlEscape(result); result = (this.javaScriptEscape ? JavaScriptUtils.javaScriptEscape(result) : result); this.pageContext.getOut().print(result); } catch (IOException ex) { throw new JspException(ex); } } return EVAL_PAGE; }
/** * Override resolve CSS class since error class is not supported. */ @Override protected String resolveCssClass() throws JspException { return ObjectUtils.getDisplayString(evaluate("cssClass", getCssClass())); }
String itemLabel = getItemLabel(); String valueProperty = (itemValue != null ? ObjectUtils.getDisplayString(evaluate("itemValue", itemValue)) : null); String labelProperty = (itemLabel != null ? ObjectUtils.getDisplayString(evaluate("itemLabel", itemLabel)) : null);
/** * Gets the appropriate CSS class to use based on the state of the current * {@link org.springframework.web.servlet.support.BindStatus} object. */ protected String resolveCssClass() throws JspException { if (getBindStatus().isError() && StringUtils.hasText(getCssErrorClass())) { return ObjectUtils.getDisplayString(evaluate("cssErrorClass", getCssErrorClass())); } else { return ObjectUtils.getDisplayString(evaluate("cssClass", getCssClass())); } }
@Override public int doEndTag() throws JspException { EvaluationContext evaluationContext = (EvaluationContext) this.pageContext.getAttribute(EVALUATION_CONTEXT_PAGE_ATTRIBUTE); if (evaluationContext == null) { evaluationContext = createEvaluationContext(this.pageContext); this.pageContext.setAttribute(EVALUATION_CONTEXT_PAGE_ATTRIBUTE, evaluationContext); } if (this.var != null) { Object result = (this.expression != null ? this.expression.getValue(evaluationContext) : null); this.pageContext.setAttribute(this.var, result, this.scope); } else { try { String result = (this.expression != null ? this.expression.getValue(evaluationContext, String.class) : null); result = ObjectUtils.getDisplayString(result); result = htmlEscape(result); result = (this.javaScriptEscape ? JavaScriptUtils.javaScriptEscape(result) : result); this.pageContext.getOut().print(result); } catch (IOException ex) { throw new JspException(ex); } } return EVAL_PAGE; }
protected void configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac, ServletContext sc) { if (ObjectUtils.identityToString(wac).equals(wac.getId())) { // The application context id is still set to its original default value // -> assign a more useful id based on available information String idParam = sc.getInitParameter(CONTEXT_ID_PARAM); if (idParam != null) { wac.setId(idParam); } else { // Generate default id... wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + ObjectUtils.getDisplayString(sc.getContextPath())); } } wac.setServletContext(sc); String configLocationParam = sc.getInitParameter(CONFIG_LOCATION_PARAM); if (configLocationParam != null) { wac.setConfigLocation(configLocationParam); } // The wac environment's #initPropertySources will be called in any case when the context // is refreshed; do it eagerly here to ensure servlet property sources are in place for // use in any post-processing or initialization that occurs below prior to #refresh ConfigurableEnvironment env = wac.getEnvironment(); if (env instanceof ConfigurableWebEnvironment) { ((ConfigurableWebEnvironment) env).initPropertySources(sc, null); } customizeContext(sc, wac); wac.refresh(); }
@Override protected int writeTagContent(TagWriter tagWriter) throws JspException { SelectTag selectTag = getSelectTag(); Object items = getItems(); Object itemsObject = null; if (items != null) { itemsObject = (items instanceof String ? evaluate("items", items) : items); } else { Class<?> selectTagBoundType = selectTag.getBindStatus().getValueType(); if (selectTagBoundType != null && selectTagBoundType.isEnum()) { itemsObject = selectTagBoundType.getEnumConstants(); } } if (itemsObject != null) { String selectName = selectTag.getName(); String itemValue = getItemValue(); String itemLabel = getItemLabel(); String valueProperty = (itemValue != null ? ObjectUtils.getDisplayString(evaluate("itemValue", itemValue)) : null); String labelProperty = (itemLabel != null ? ObjectUtils.getDisplayString(evaluate("itemLabel", itemLabel)) : null); OptionsWriter optionWriter = new OptionsWriter(selectName, itemsObject, valueProperty, labelProperty); optionWriter.writeOptions(tagWriter); } return SKIP_BODY; }
protected void configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac, ServletContext sc) { if (ObjectUtils.identityToString(wac).equals(wac.getId())) { // The application context id is still set to its original default value // -> assign a more useful id based on available information String idParam = sc.getInitParameter(CONTEXT_ID_PARAM); if (idParam != null) { wac.setId(idParam); } else { // Generate default id... wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + ObjectUtils.getDisplayString(sc.getContextPath())); } } wac.setServletContext(sc); String configLocationParam = sc.getInitParameter(CONFIG_LOCATION_PARAM); if (configLocationParam != null) { wac.setConfigLocation(configLocationParam); } // The wac environment's #initPropertySources will be called in any case when the context // is refreshed; do it eagerly here to ensure servlet property sources are in place for // use in any post-processing or initialization that occurs below prior to #refresh ConfigurableEnvironment env = wac.getEnvironment(); if (env instanceof ConfigurableWebEnvironment) { ((ConfigurableWebEnvironment) env).initPropertySources(sc, null); } customizeContext(sc, wac); wac.refresh(); }
@Override protected void renderDefaultContent(TagWriter tagWriter) throws JspException { tagWriter.startTag(getElement()); writeDefaultAttributes(tagWriter); String delimiter = ObjectUtils.getDisplayString(evaluate("delimiter", getDelimiter())); String[] errorMessages = getBindStatus().getErrorMessages(); for (int i = 0; i < errorMessages.length; i++) { String errorMessage = errorMessages[i]; if (i > 0) { tagWriter.appendValue(delimiter); } tagWriter.appendValue(getDisplayString(errorMessage)); } tagWriter.endTag(); }
final String selectName = getName(); String valueProperty = (getItemValue() != null ? ObjectUtils.getDisplayString(evaluate("itemValue", getItemValue())) : null); String labelProperty = (getItemLabel() != null ? ObjectUtils.getDisplayString(evaluate("itemLabel", getItemLabel())) : null); OptionWriter optionWriter = new OptionWriter(itemsObject, getBindStatus(), valueProperty, labelProperty, isHtmlEscape()) {
protected void configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac) { if (ObjectUtils.identityToString(wac).equals(wac.getId())) { // The application context id is still set to its original default value // -> assign a more useful id based on available information if (this.contextId != null) { wac.setId(this.contextId); } else { // Generate default id... wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + ObjectUtils.getDisplayString(getServletContext().getContextPath()) + '/' + getServletName()); } } wac.setServletContext(getServletContext()); wac.setServletConfig(getServletConfig()); wac.setNamespace(getNamespace()); wac.addApplicationListener(new SourceFilteringListener(wac, new ContextRefreshListener())); // The wac environment's #initPropertySources will be called in any case when the context // is refreshed; do it eagerly here to ensure servlet property sources are in place for // use in any post-processing or initialization that occurs below prior to #refresh ConfigurableEnvironment env = wac.getEnvironment(); if (env instanceof ConfigurableWebEnvironment) { ((ConfigurableWebEnvironment) env).initPropertySources(getServletContext(), getServletConfig()); } postProcessWebApplicationContext(wac); applyInitializers(wac); wac.refresh(); }
@Override protected void renderDefaultContent(TagWriter tagWriter) throws JspException { tagWriter.startTag(getElement()); writeDefaultAttributes(tagWriter); String delimiter = ObjectUtils.getDisplayString(evaluate("delimiter", getDelimiter())); String[] errorMessages = getBindStatus().getErrorMessages(); for (int i = 0; i < errorMessages.length; i++) { String errorMessage = errorMessages[i]; if (i > 0) { tagWriter.appendValue(delimiter); } tagWriter.appendValue(getDisplayString(errorMessage)); } tagWriter.endTag(); }
/** * Writes the optional attributes configured via this base class to the supplied {@link TagWriter}. * The set of optional attributes that will be rendered includes any non-standard dynamic attributes. * Called by {@link #writeDefaultAttributes(TagWriter)}. */ protected void writeOptionalAttributes(TagWriter tagWriter) throws JspException { tagWriter.writeOptionalAttributeValue(CLASS_ATTRIBUTE, resolveCssClass()); tagWriter.writeOptionalAttributeValue(STYLE_ATTRIBUTE, ObjectUtils.getDisplayString(evaluate("cssStyle", getCssStyle()))); writeOptionalAttribute(tagWriter, LANG_ATTRIBUTE, getLang()); writeOptionalAttribute(tagWriter, TITLE_ATTRIBUTE, getTitle()); writeOptionalAttribute(tagWriter, DIR_ATTRIBUTE, getDir()); writeOptionalAttribute(tagWriter, TABINDEX_ATTRIBUTE, getTabindex()); writeOptionalAttribute(tagWriter, ONCLICK_ATTRIBUTE, getOnclick()); writeOptionalAttribute(tagWriter, ONDBLCLICK_ATTRIBUTE, getOndblclick()); writeOptionalAttribute(tagWriter, ONMOUSEDOWN_ATTRIBUTE, getOnmousedown()); writeOptionalAttribute(tagWriter, ONMOUSEUP_ATTRIBUTE, getOnmouseup()); writeOptionalAttribute(tagWriter, ONMOUSEOVER_ATTRIBUTE, getOnmouseover()); writeOptionalAttribute(tagWriter, ONMOUSEMOVE_ATTRIBUTE, getOnmousemove()); writeOptionalAttribute(tagWriter, ONMOUSEOUT_ATTRIBUTE, getOnmouseout()); writeOptionalAttribute(tagWriter, ONKEYPRESS_ATTRIBUTE, getOnkeypress()); writeOptionalAttribute(tagWriter, ONKEYUP_ATTRIBUTE, getOnkeyup()); writeOptionalAttribute(tagWriter, ONKEYDOWN_ATTRIBUTE, getOnkeydown()); if (!CollectionUtils.isEmpty(this.dynamicAttributes)) { for (String attr : this.dynamicAttributes.keySet()) { tagWriter.writeOptionalAttributeValue(attr, getDisplayString(this.dynamicAttributes.get(attr))); } } }
protected void configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac) { if (ObjectUtils.identityToString(wac).equals(wac.getId())) { // The application context id is still set to its original default value // -> assign a more useful id based on available information if (this.contextId != null) { wac.setId(this.contextId); } else { // Generate default id... wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + ObjectUtils.getDisplayString(getServletContext().getContextPath()) + '/' + getServletName()); } } wac.setServletContext(getServletContext()); wac.setServletConfig(getServletConfig()); wac.setNamespace(getNamespace()); wac.addApplicationListener(new SourceFilteringListener(wac, new ContextRefreshListener())); // The wac environment's #initPropertySources will be called in any case when the context // is refreshed; do it eagerly here to ensure servlet property sources are in place for // use in any post-processing or initialization that occurs below prior to #refresh ConfigurableEnvironment env = wac.getEnvironment(); if (env instanceof ConfigurableWebEnvironment) { ((ConfigurableWebEnvironment) env).initPropertySources(getServletContext(), getServletConfig()); } postProcessWebApplicationContext(wac); applyInitializers(wac); wac.refresh(); }
/** * Writes the optional attributes configured via this base class to the supplied {@link TagWriter}. * The set of optional attributes that will be rendered includes any non-standard dynamic attributes. * Called by {@link #writeDefaultAttributes(TagWriter)}. */ protected void writeOptionalAttributes(TagWriter tagWriter) throws JspException { tagWriter.writeOptionalAttributeValue(CLASS_ATTRIBUTE, resolveCssClass()); tagWriter.writeOptionalAttributeValue(STYLE_ATTRIBUTE, ObjectUtils.getDisplayString(evaluate("cssStyle", getCssStyle()))); writeOptionalAttribute(tagWriter, LANG_ATTRIBUTE, getLang()); writeOptionalAttribute(tagWriter, TITLE_ATTRIBUTE, getTitle()); writeOptionalAttribute(tagWriter, DIR_ATTRIBUTE, getDir()); writeOptionalAttribute(tagWriter, TABINDEX_ATTRIBUTE, getTabindex()); writeOptionalAttribute(tagWriter, ONCLICK_ATTRIBUTE, getOnclick()); writeOptionalAttribute(tagWriter, ONDBLCLICK_ATTRIBUTE, getOndblclick()); writeOptionalAttribute(tagWriter, ONMOUSEDOWN_ATTRIBUTE, getOnmousedown()); writeOptionalAttribute(tagWriter, ONMOUSEUP_ATTRIBUTE, getOnmouseup()); writeOptionalAttribute(tagWriter, ONMOUSEOVER_ATTRIBUTE, getOnmouseover()); writeOptionalAttribute(tagWriter, ONMOUSEMOVE_ATTRIBUTE, getOnmousemove()); writeOptionalAttribute(tagWriter, ONMOUSEOUT_ATTRIBUTE, getOnmouseout()); writeOptionalAttribute(tagWriter, ONKEYPRESS_ATTRIBUTE, getOnkeypress()); writeOptionalAttribute(tagWriter, ONKEYUP_ATTRIBUTE, getOnkeyup()); writeOptionalAttribute(tagWriter, ONKEYDOWN_ATTRIBUTE, getOnkeydown()); if (!CollectionUtils.isEmpty(this.dynamicAttributes)) { for (String attr : this.dynamicAttributes.keySet()) { tagWriter.writeOptionalAttributeValue(attr, getDisplayString(this.dynamicAttributes.get(attr))); } } }