本文整理汇总了Java中net.sourceforge.stripes.localization.LocalizationUtility类的典型用法代码示例。如果您正苦于以下问题:Java LocalizationUtility类的具体用法?Java LocalizationUtility怎么用?Java LocalizationUtility使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LocalizationUtility类属于net.sourceforge.stripes.localization包,在下文中一共展示了LocalizationUtility类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMessageTemplate
import net.sourceforge.stripes.localization.LocalizationUtility; //导入依赖的package包/类
/**
* Method responsible for using the information supplied to the error object to find a
* message template. In this class this is done simply by looking up the resource
* corresponding to the messageKey supplied in the constructor, first with the FQN
* prepended, then with the action path prepended and finally bare.
*/
@Override
protected String getMessageTemplate(Locale locale) {
String template = null;
Class<? extends ActionBean> beanclass = getBeanclass();
if (beanclass != null) {
template = LocalizationUtility.getErrorMessage(locale, beanclass.getName() + "." + messageKey);
}
if (template == null) {
String actionPath = getActionPath();
if (actionPath != null) {
template = LocalizationUtility.getErrorMessage(locale, actionPath + "." + messageKey);
}
}
if (template == null) {
template = LocalizationUtility.getErrorMessage(locale, messageKey);
}
if (template == null) {
throw new MissingResourceException(
"Could not find an error message with key: " + messageKey, null, null);
}
return template;
}
示例2: resolveFieldName
import net.sourceforge.stripes.localization.LocalizationUtility; //导入依赖的package包/类
/**
* Takes the form field name supplied and tries first to resolve a String in the locale
* specific bundle for the field name, and if that fails, will try to make a semi-friendly
* name by parsing the form field name. The result is stored in replacementParameters[0]
* for message template parameter replacement.
*/
protected void resolveFieldName(Locale locale) {
log.debug("Looking up localized field name with messageKey: ", this.fieldNameKey);
if (this.fieldNameKey == null) {
getReplacementParameters()[0] = "FIELD NAME NOT SUPPLIED IN CODE";
}
else {
getReplacementParameters()[0] =
LocalizationUtility.getLocalizedFieldName(this.fieldNameKey,
this.actionPath,
this.beanclass,
locale);
if (getReplacementParameters()[0] == null) {
getReplacementParameters()[0] =
LocalizationUtility.makePseudoFriendlyName(this.fieldNameKey);
}
}
}
示例3: getLocalizedFieldName
import net.sourceforge.stripes.localization.LocalizationUtility; //导入依赖的package包/类
/**
* Attempts to fetch a "field name" resource from the localization bundle. Delegates
* to {@link LocalizationUtility#getLocalizedFieldName(String, String, Class, java.util.Locale)}
*
* @param name the field name or resource to look up
* @return the localized String corresponding to the name provided
* @throws StripesJspException
*/
protected String getLocalizedFieldName(final String name) throws StripesJspException {
Locale locale = getPageContext().getRequest().getLocale();
FormTag form = null;
try { form = getParentFormTag(); }
catch (StripesJspException sje) { /* Do nothing. */}
String actionPath = null;
Class<? extends ActionBean> beanClass = null;
if (form != null) {
actionPath = form.getAction();
beanClass = form.getActionBeanClass();
}
else {
ActionBean mainBean = (ActionBean) getPageContext().getRequest().getAttribute(StripesConstants.REQ_ATTR_ACTION_BEAN);
if (mainBean != null) {
beanClass = mainBean.getClass();
}
}
return LocalizationUtility.getLocalizedFieldName(name, actionPath, beanClass, locale);
}
示例4: doEndInputTag
import net.sourceforge.stripes.localization.LocalizationUtility; //导入依赖的package包/类
/**
* Performs the main work of the tag as described in the class level javadoc.
* @return EVAL_PAGE in all cases.
* @throws JspException if an IOException is encountered writing to the output stream.
*/
@Override
public int doEndInputTag() throws JspException {
try {
String label = getLocalizedFieldName();
String fieldName = getAttributes().remove("name");
if (label == null) {
label = getBodyContentAsString();
}
if (label == null) {
if (fieldName != null) {
label = LocalizationUtility.makePseudoFriendlyName(fieldName);
}
else {
label = "Label could not find localized field name and had no body nor name attribute.";
}
}
// Write out the tag
writeOpenTag(getPageContext().getOut(), "label");
getPageContext().getOut().write(label);
writeCloseTag(getPageContext().getOut(), "label");
// Reset the field name so as to not screw up tag pooling
if (this.nameSet) {
super.setName(fieldName);
}
return EVAL_PAGE;
}
catch (IOException ioe) {
throw new StripesJspException("Encountered an exception while trying to write to " +
"the output from the stripes:label tag handler class, InputLabelTag.", ioe);
}
}
示例5: testSimpleClassName
import net.sourceforge.stripes.localization.LocalizationUtility; //导入依赖的package包/类
@Test(groups = "fast")
public void testSimpleClassName() throws Exception {
String output = LocalizationUtility.getSimpleName(TestEnum.class);
Assert.assertEquals(output, "LocalizationUtilityTest.TestEnum");
output = LocalizationUtility.getSimpleName(A.B.C.class);
Assert.assertEquals(output, "LocalizationUtilityTest.A.B.C");
}
示例6: getMessageTemplate
import net.sourceforge.stripes.localization.LocalizationUtility; //导入依赖的package包/类
/**
* Overrides getMessageTemplate to perform a scoped search for a message template as defined in
* the class level javadoc.
*/
@Override
protected String getMessageTemplate(Locale locale) {
String name1=null, name2=null, name3=null, name4=null, name5=null, name6=null,
name7=null, name8=null, name9=null, name10=null, name11=null;
final String actionPath = getActionPath();
final String fqn = getBeanclass().getName();
final String fieldName = getFieldName();
// 1. com.myco.KittenDetailActionBean.age.outOfRange
name1 = fqn + "." + fieldName + "." + this.key;
String template = LocalizationUtility.getErrorMessage(locale, name1);
if (template == null) {
// 2. com.myco.KittenDetailActionBean.age.errorMessage
name2 = fqn + "." + fieldName + "." + DEFAULT_NAME;
template = LocalizationUtility.getErrorMessage(locale, name2);
}
if (template == null) {
// 3. /cats/KittenDetail.action.age.outOfRange
name3 = actionPath + "." + fieldName + "." + this.key;
template = LocalizationUtility.getErrorMessage(locale, name3);
}
if (template == null) {
// 4. /cats/KittenDetail.action.age.errorMessage
name4 = actionPath + "." + fieldName + "." + DEFAULT_NAME;
template = LocalizationUtility.getErrorMessage(locale, name4);
}
if (template == null) {
// 5. age.outOfRange
name5 = fieldName + "." + this.key;
template = LocalizationUtility.getErrorMessage(locale, name5);
}
if (template == null) {
// 6. age.errorMessage
name6 = fieldName + "." + DEFAULT_NAME;
template = LocalizationUtility.getErrorMessage(locale, name6);
}
if (template == null) {
// 7. com.myco.KittenDetailActionBean.outOfRange
name7 = fqn + "." + this.key;
template = LocalizationUtility.getErrorMessage(locale, name7);
}
if (template == null) {
// 8. com.myco.KittenDetailActionBean.outOfRange
name8 = fqn + "." + DEFAULT_NAME;
template = LocalizationUtility.getErrorMessage(locale, name8);
}
if (template == null) {
// 9. /cats/KittenDetail.action.outOfRange
name9 = actionPath + "." + this.key;
template = LocalizationUtility.getErrorMessage(locale, name9);
}
if (template == null) {
// 10. /cats/KittenDetail.action.errorMessage
name10 = actionPath + "." + DEFAULT_NAME;
template = LocalizationUtility.getErrorMessage(locale, name10);
}
if (template == null) {
// 11. converter.integer.outOfRange
name11 = this.defaultScope + "." + this.key;
template = LocalizationUtility.getErrorMessage(locale, name11);
}
if (template == null) {
throw new MissingResourceException(
"Could not find an error message with any of the following keys: " +
"'" + name1 + "', '" + name2 + "', '" + name3 + "', '" +
name4 + "', '" + name5 + "', '" + name6 + "', '" + name7 + "'." +
name8 + "', '" + name9 + "', '" + name10 + "', '" + name11 + "'.", null, null
);
}
return template;
}
示例7: doStartTag
import net.sourceforge.stripes.localization.LocalizationUtility; //导入依赖的package包/类
/**
* Iterates through the collection and generates the list of Entry objects that can then
* be sorted and rendered into options. It is assumed that each element in the collection
* has non-null values for the properties specified for generating the label and value.
*
* @return SKIP_BODY in all cases
* @throws JspException if either the label or value attributes specify properties that are
* not present on the beans in the collection
*/
@Override
public int doStartTag() throws JspException {
if (this.collection == null)
return SKIP_BODY;
String labelProperty = getLabel();
String valueProperty = getValue();
String groupProperty = getGroup();
try {
Locale locale = getPageContext().getRequest().getLocale();
boolean attemptToLocalizeLabels = isAttemptToLocalizeLabels();
for (Object item : this.collection) {
Class<? extends Object> clazz = item.getClass();
// Lookup the bean properties for the label, value and group
Object label = (labelProperty == null) ? item : BeanUtil.getPropertyValue(labelProperty, item);
Object value = (valueProperty == null) ? item : BeanUtil.getPropertyValue(valueProperty, item);
Object group = (groupProperty == null) ? null : BeanUtil.getPropertyValue(groupProperty, item);
if (attemptToLocalizeLabels) {
// Try to localize the label
String packageName = clazz.getPackage() == null ? "" : clazz.getPackage().getName();
String simpleName = LocalizationUtility.getSimpleName(clazz);
String localizedLabel = null;
if (label != null) {
localizedLabel = LocalizationUtility.getLocalizedFieldName
(simpleName + "." + label, packageName, null, locale);
}
if (localizedLabel == null && value != null) {
localizedLabel = LocalizationUtility.getLocalizedFieldName
(simpleName + "." + value, packageName, null, locale);
}
if (localizedLabel != null) label = localizedLabel;
// Try to localize the group
if (group != null) {
String localizedGroup = LocalizationUtility.getLocalizedFieldName(
simpleName + "." + group, packageName, null, locale);
if (localizedGroup != null) group = localizedGroup;
}
}
addEntry(item, label, value, group);
}
}
catch (ExpressionException ee) {
throw new StripesJspException("A problem occurred generating an options-collection. " +
"Most likely either [" + labelProperty + "] or ["+ valueProperty + "] is not a " +
"valid property of the beans in the collection: " + this.collection, ee);
}
return SKIP_BODY;
}
示例8: testBaseCase
import net.sourceforge.stripes.localization.LocalizationUtility; //导入依赖的package包/类
@Test(groups="fast")
public void testBaseCase() throws Exception {
String input = "Hello";
String output = LocalizationUtility.makePseudoFriendlyName(input);
Assert.assertEquals(output, input);
}
示例9: testSimpleCase
import net.sourceforge.stripes.localization.LocalizationUtility; //导入依赖的package包/类
@Test(groups="fast")
public void testSimpleCase() throws Exception {
String input = "hello";
String output = LocalizationUtility.makePseudoFriendlyName(input);
Assert.assertEquals(output, "Hello");
}
示例10: testWithPeriod
import net.sourceforge.stripes.localization.LocalizationUtility; //导入依赖的package包/类
@Test(groups="fast")
public void testWithPeriod() throws Exception {
String input = "bug.name";
String output = LocalizationUtility.makePseudoFriendlyName(input);
Assert.assertEquals(output, "Bug Name");
}
示例11: testWithStudlyCaps
import net.sourceforge.stripes.localization.LocalizationUtility; //导入依赖的package包/类
@Test(groups="fast")
public void testWithStudlyCaps() throws Exception {
String input = "bugName";
String output = LocalizationUtility.makePseudoFriendlyName(input);
Assert.assertEquals(output, "Bug Name");
}
示例12: testComplexName
import net.sourceforge.stripes.localization.LocalizationUtility; //导入依赖的package包/类
@Test(groups="fast")
public void testComplexName() throws Exception {
String input = "bug.submittedBy.firstName";
String output = LocalizationUtility.makePseudoFriendlyName(input);
Assert.assertEquals(output, "Bug Submitted By First Name");
}