org.apache.struts2.components.Text Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.struts2.components;
import com.opensymphony.xwork2.util.ValueStack;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.struts2.util.TextProviderHelper;
import org.apache.struts2.views.annotations.StrutsTag;
import org.apache.struts2.views.annotations.StrutsTagAttribute;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
*
*
* Render a I18n text message.
*
*
*
* The message must be in a resource bundle
* with the same name as the action that it is associated with. In practice
* this means that you should create a properties file in the same package
* as your Java class with the same name as your class, but with .properties
* extension.
*
*
*
* If the named message is not found in a property file, then the body of the
* tag will be used as default message. If no body is used, then the stack can
* be searched, and if a value is returned, it will written to the output.
* If no value is found on the stack, the key of the message will be written out.
*
*
*
*
*
*
* - name* (String) - the i18n message key
* - escapeHtml (Boolean) - Escape HTML. Defaults to false
* - escapeJavaScript (Boolean) - Escape JavaScript. Defaults to false
* - escapeXml (Boolean) - Escape XML. Defaults to false
* - escapeCsv (Boolean) - Escape CSV. Defaults to false
*
*
*
*
*
* Example:
*
*
*
* Accessing messages from a given bundle (the i18n Shop example bundle in the first example) and using bundle defined through the framework in the second example.
*
*
*
*
*
* <!-- First Example -->
* <s:i18n name="struts.action.test.i18n.Shop">
* <s:text name="main.title"/>
* </s:i18n>
*
* <!-- Second Example -->
* <s:text name="main.title" />
*
* <!-- Third Examlpe -->
* <s:text name="i18n.label.greetings">
* <s:param >Mr Smith</s:param>
* </s:text>
*
*
*
*
*
*
*
*
* <-- Fourth Example -->
* <s:text name="some.key" />
*
* <-- Fifth Example -->
* <s:text name="some.invalid.key" >
* The Default Message That Will Be Displayed
* </s:text>
*
*
*
*
* @see Param
*
*/
@StrutsTag(
name="text",
tldTagClass="org.apache.struts2.views.jsp.TextTag",
description="Render a I18n text message")
public class Text extends ContextBean implements Param.UnnamedParametric {
private static final Logger LOG = LogManager.getLogger(Text.class);
protected List