当前位置: 首页>>代码示例>>Java>>正文


Java LocalizedTextUtil类代码示例

本文整理汇总了Java中com.opensymphony.xwork2.util.LocalizedTextUtil的典型用法代码示例。如果您正苦于以下问题:Java LocalizedTextUtil类的具体用法?Java LocalizedTextUtil怎么用?Java LocalizedTextUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


LocalizedTextUtil类属于com.opensymphony.xwork2.util包,在下文中一共展示了LocalizedTextUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getErrorMessage

import com.opensymphony.xwork2.util.LocalizedTextUtil; //导入依赖的package包/类
@Override
protected String getErrorMessage() {
    if ((namespace != null) && (namespace.trim().length() > 0)) {
        String contextPath = ServletActionContext.getRequest().getContextPath();
        return LocalizedTextUtil.findDefaultText(
                "struts.exception.missing-package-action.with-context",
                Locale.getDefault(),
                new String[]{namespace, actionName, contextPath}
        );
    } else {
        return super.getErrorMessage();
    }
}
 
开发者ID:txazo,项目名称:struts2,代码行数:14,代码来源:StrutsActionProxy.java

示例2: loadCustomResourceBundles

import com.opensymphony.xwork2.util.LocalizedTextUtil; //导入依赖的package包/类
private void loadCustomResourceBundles(LocatableProperties props) {
    String bundles = props.getProperty(StrutsConstants.STRUTS_CUSTOM_I18N_RESOURCES);
    if (bundles != null && bundles.length() > 0) {
        StringTokenizer customBundles = new StringTokenizer(bundles, ", ");

        while (customBundles.hasMoreTokens()) {
            String name = customBundles.nextToken();
            try {
          	    LOG.trace("Loading global messages from [{}]", name);
                LocalizedTextUtil.addDefaultResourceBundle(name);
            } catch (Exception e) {
                LOG.error("Could not find messages file {}.properties. Skipping", name);
            }
        }
    }
}
 
开发者ID:txazo,项目名称:struts2,代码行数:17,代码来源:DefaultBeanSelectionProvider.java

示例3: getLocaleFromParam

import com.opensymphony.xwork2.util.LocalizedTextUtil; //导入依赖的package包/类
/**
 * Creates a Locale object from the request param, which might
 * be already a Local or a String
 *
 * @param requestedLocale the parameter from the request
 * @return the Locale
 */
protected Locale getLocaleFromParam(Object requestedLocale) {
    Locale locale = null;
    if (requestedLocale != null) {
        locale = (requestedLocale instanceof Locale) ?
                (Locale) requestedLocale :
                LocalizedTextUtil.localeFromString(requestedLocale.toString(), null);
        if (locale != null) {
            LOG.debug("Applied request locale: {}", locale);
        }
    }

    if (locale != null && !Arrays.asList(Locale.getAvailableLocales()).contains(locale)) {
        locale = Locale.getDefault();
    }
    return locale;
}
 
开发者ID:txazo,项目名称:struts2,代码行数:24,代码来源:I18nInterceptor.java

示例4: cleanUp

import com.opensymphony.xwork2.util.LocalizedTextUtil; //导入依赖的package包/类
public void cleanUp() {
    Set<String> names = files.keySet();
    for (String name : names) {
        List<FileItem> items = files.get(name);
        for (FileItem item : items) {
            if (LOG.isDebugEnabled()) {
                String msg = LocalizedTextUtil.findText(this.getClass(), "struts.messages.removing.file",
                        Locale.ENGLISH, "no.message.found", new Object[]{name, item});
                LOG.debug(msg);
            }
            if (!item.isInMemory()) {
                item.delete();
            }
        }
    }
}
 
开发者ID:txazo,项目名称:struts2,代码行数:17,代码来源:JakartaMultiPartRequest.java

示例5: getText

import com.opensymphony.xwork2.util.LocalizedTextUtil; //导入依赖的package包/类
/**
 * Gets a message based on a key using the supplied args, as defined in
 * {@link java.text.MessageFormat}, or, if the message is not found, a supplied
 * default value is returned. Instead of using the value stack in the ActionContext
 * this version of the getText() method uses the provided value stack.
 *
 * @param key    the resource bundle key that is to be searched for
 * @param defaultValue the default value which will be returned if no message is found
 * @param args         a list args to be used in a {@link java.text.MessageFormat} message
 * @param stack        the value stack to use for finding the text
 * @return the message as found in the resource bundle, or defaultValue if none is found
 */
public String getText(String key, String defaultValue, List<?> args, ValueStack stack) {
    Object[] argsArray = ((args != null) ? args.toArray() : null);
    Locale locale;
    if (stack == null){
    	locale = getLocale();
    }else{
    	locale = (Locale) stack.getContext().get(ActionContext.LOCALE);
    }
    if (locale == null) {
        locale = getLocale();
    }
    if (clazz != null) {
        return LocalizedTextUtil.findText(clazz, key, locale, defaultValue, argsArray, stack);
    } else {
        return LocalizedTextUtil.findText(bundle, key, locale, defaultValue, argsArray, stack);
    }
}
 
开发者ID:txazo,项目名称:struts2,代码行数:30,代码来源:TextProviderSupport.java

示例6: onSetUpInTransaction

import com.opensymphony.xwork2.util.LocalizedTextUtil; //导入依赖的package包/类
@SuppressWarnings("unchecked")
   @Override
   protected void onSetUpInTransaction() {
LocalizedTextUtil.addDefaultResourceBundle(Constants.BUNDLE_KEY);
// ActionContext.getContext().setSession(new HashMap<Object, Object>());

// change the port on the mailSender so it doesn't conflict with an
// existing SMTP server on localhost
// JavaMailSenderImpl mailSender = (JavaMailSenderImpl)
// applicationContext.getBean("mailSender");
mailSender.setPort(2525);
mailSender.setHost("localhost");

// populate the request so getRequest().getSession() doesn't fail in
// BaseAction.java

setUpActionContext();
   }
 
开发者ID:gisgraphy,项目名称:gisgraphy,代码行数:19,代码来源:BaseActionTestCase.java

示例7: init_PreloadConfiguration

import com.opensymphony.xwork2.util.LocalizedTextUtil; //导入依赖的package包/类
private Container init_PreloadConfiguration() {
    // 源码解析: 获取容器
    Container container = getContainer();

    // 源码解析: 是否reload资源文件
    boolean reloadi18n = Boolean.valueOf(container.getInstance(String.class, StrutsConstants.STRUTS_I18N_RELOAD));
    LocalizedTextUtil.setReloadBundles(reloadi18n);

    // 源码解析: 是否开发模式
    boolean devMode = Boolean.valueOf(container.getInstance(String.class, StrutsConstants.STRUTS_DEVMODE));
    LocalizedTextUtil.setDevMode(devMode);

    return container;
}
 
开发者ID:txazo,项目名称:struts2,代码行数:15,代码来源:Dispatcher.java

示例8: createContextMap

import com.opensymphony.xwork2.util.LocalizedTextUtil; //导入依赖的package包/类
/**
 * Merge all application and servlet attributes into a single <tt>HashMap</tt> to represent the entire
 * <tt>Action</tt> context.
 *
 * @param requestMap     a Map of all request attributes.
 * @param parameterMap   a Map of all request parameters.
 * @param sessionMap     a Map of all session attributes.
 * @param applicationMap a Map of all servlet context attributes.
 * @param request        the HttpServletRequest object.
 * @param response       the HttpServletResponse object.
 * @return a HashMap representing the <tt>Action</tt> context.
 *
 * @since 2.3.17
 */
public HashMap<String,Object> createContextMap(Map requestMap,
                                Map parameterMap,
                                Map sessionMap,
                                Map applicationMap,
                                HttpServletRequest request,
                                HttpServletResponse response) {
    HashMap<String, Object> extraContext = new HashMap<>();
    extraContext.put(ActionContext.PARAMETERS, new HashMap(parameterMap));
    extraContext.put(ActionContext.SESSION, sessionMap);
    extraContext.put(ActionContext.APPLICATION, applicationMap);

    Locale locale;
    if (defaultLocale != null) {
        locale = LocalizedTextUtil.localeFromString(defaultLocale, request.getLocale());
    } else {
        locale = request.getLocale();
    }

    extraContext.put(ActionContext.LOCALE, locale);

    extraContext.put(StrutsStatics.HTTP_REQUEST, request);
    extraContext.put(StrutsStatics.HTTP_RESPONSE, response);
    extraContext.put(StrutsStatics.SERVLET_CONTEXT, servletContext);

    // helpers to get access to request/session/application scope
    extraContext.put("request", requestMap);
    extraContext.put("session", sessionMap);
    extraContext.put("application", applicationMap);
    extraContext.put("parameters", parameterMap);

    AttributeMap attrMap = new AttributeMap(extraContext);
    extraContext.put("attr", attrMap);

    return extraContext;
}
 
开发者ID:txazo,项目名称:struts2,代码行数:50,代码来源:Dispatcher.java

示例9: prepare

import com.opensymphony.xwork2.util.LocalizedTextUtil; //导入依赖的package包/类
/**
 * Prepare a request, including setting the encoding and locale.
 *
 * @param request The request
 * @param response The response
 */
public void prepare(HttpServletRequest request, HttpServletResponse response) {
    String encoding = null;
    if (defaultEncoding != null) {
        encoding = defaultEncoding;
    }
    // check for Ajax request to use UTF-8 encoding strictly http://www.w3.org/TR/XMLHttpRequest/#the-send-method
    if ("XMLHttpRequest".equals(request.getHeader("X-Requested-With"))) {
        encoding = "UTF-8";
    }

    Locale locale = null;
    if (defaultLocale != null) {
        locale = LocalizedTextUtil.localeFromString(defaultLocale, request.getLocale());
    }

    if (encoding != null) {
        applyEncoding(request, encoding);
    }

    if (locale != null) {
        response.setLocale(locale);
    }

    if (paramsWorkaroundEnabled) {
        request.getParameter("foo"); // simply read any parameter (existing or not) to "prime" the request
    }
}
 
开发者ID:txazo,项目名称:struts2,代码行数:34,代码来源:Dispatcher.java

示例10: validToken

import com.opensymphony.xwork2.util.LocalizedTextUtil; //导入依赖的package包/类
/**
   * Checks for a valid transaction token in the current request params. If a valid token is found, it is
   * removed so the it is not valid again.
   *
   * @return false if there was no token set into the params (check by looking for {@link #TOKEN_NAME_FIELD}), true if a valid token is found
   */
  public static boolean validToken() {
      String tokenName = getTokenName();

      if (tokenName == null) {
          LOG.debug("No token name found -> Invalid token ");
          return false;
      }

      String token = getToken(tokenName);

      if (token == null) {
          LOG.debug("No token found for token name {} -> Invalid token ", tokenName);
          return false;
      }

      Map session = ActionContext.getContext().getSession();
String tokenSessionName = buildTokenSessionAttributeName(tokenName);
      String sessionToken = (String) session.get(tokenSessionName);

      if (!token.equals(sessionToken)) {
          if (LOG.isWarnEnabled()) {
              LOG.warn(LocalizedTextUtil.findText(TokenHelper.class, "struts.internal.invalid.token", ActionContext.getContext().getLocale(), "Form token {0} does not match the session token {1}.", new Object[]{
                      token, sessionToken
              }));
          }

          return false;
      }

      // remove the token so it won't be used again
      session.remove(tokenSessionName);

      return true;
  }
 
开发者ID:txazo,项目名称:struts2,代码行数:41,代码来源:TokenHelper.java

示例11: start

import com.opensymphony.xwork2.util.LocalizedTextUtil; //导入依赖的package包/类
public boolean start(Writer writer) {
    boolean result = super.start(writer);

    try {
        String name = this.findString(this.name, "name", "Resource bundle name is required. Example: foo or foo_en");
        ResourceBundle bundle = (ResourceBundle) findValue("getTexts('" + name + "')");

        if (bundle == null) {
            bundle = LocalizedTextUtil.findResourceBundle(name, (Locale) getStack().getContext().get(ActionContext.LOCALE));
        }

        if (bundle != null) {
            final Locale locale = (Locale) getStack().getContext().get(ActionContext.LOCALE);
            TextProviderFactory tpf = new TextProviderFactory();
            container.inject(tpf);
            textProvider = tpf.createInstance(bundle, new LocaleProvider() {
                public Locale getLocale() {
                    return locale;
                }
            });
            getStack().push(textProvider);
            pushed = true;
        }
    } catch (Exception e) {
        throw new StrutsException("Could not find the bundle " + name, e);
    }

    return result;
}
 
开发者ID:txazo,项目名称:struts2,代码行数:30,代码来源:I18n.java

示例12: getText

import com.opensymphony.xwork2.util.LocalizedTextUtil; //导入依赖的package包/类
public String getText(String key, List<?> args) {
    Object[] params;
    if (args != null) {
        params = args.toArray();
    } else {
        params = EMPTY_ARGS;
    }

    return LocalizedTextUtil.findDefaultText(key, ActionContext.getContext().getLocale(), params);
}
 
开发者ID:txazo,项目名称:struts2,代码行数:11,代码来源:DefaultTextProvider.java

示例13: getErrorMessage

import com.opensymphony.xwork2.util.LocalizedTextUtil; //导入依赖的package包/类
protected String getErrorMessage() {
    if ((namespace != null) && (namespace.trim().length() > 0)) {
        return LocalizedTextUtil.findDefaultText(
                XWorkMessages.MISSING_PACKAGE_ACTION_EXCEPTION,
                Locale.getDefault(),
                new String[]{namespace, actionName});
    } else {
        return LocalizedTextUtil.findDefaultText(
                XWorkMessages.MISSING_ACTION_EXCEPTION,
                Locale.getDefault(),
                new String[]{actionName});
    }
}
 
开发者ID:txazo,项目名称:struts2,代码行数:14,代码来源:DefaultActionProxy.java

示例14: hasKey

import com.opensymphony.xwork2.util.LocalizedTextUtil; //导入依赖的package包/类
/**
 * Checks if a key is available in the resource bundles associated with this action.
 * The resource bundles are searched, starting with the one associated
 * with this particular action, and testing all its superclasses' bundles.
 * It will stop once a bundle is found that contains the given text. This gives
 * a cascading style that allow global texts to be defined for an application base
 * class.
 */
public boolean hasKey(String key) {
	String message;
	if (clazz != null) {
        message =  LocalizedTextUtil.findText(clazz, key, getLocale(), null, new Object[0] );
    } else {
        message = LocalizedTextUtil.findText(bundle, key, getLocale(), null, new Object[0]);
    }
	return message != null;
}
 
开发者ID:txazo,项目名称:struts2,代码行数:18,代码来源:TextProviderSupport.java

示例15: configMessages

import com.opensymphony.xwork2.util.LocalizedTextUtil; //导入依赖的package包/类
private void configMessages() {
	if (messagesConfigured)
		return;
	LocalizedTextUtil.addDefaultResourceBundle("hibernateplugin-messages");
	for (String messageFile:getMessageFiles()) {
		LocalizedTextUtil.addDefaultResourceBundle(messageFile);			
	}
	messagesConfigured = true;
}
 
开发者ID:javalover123,项目名称:full-hibernate-plugin-for-struts2,代码行数:10,代码来源:InternalHibernatePluginInterceptor.java


注:本文中的com.opensymphony.xwork2.util.LocalizedTextUtil类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。