List of usage examples for org.apache.wicket.resource.loader IStringResourceLoader loadStringResource
String loadStringResource(Component component, String key, Locale locale, String style, String variation);
From source file:ch.bd.qv.quiz.ping.TranslationPingResponder.java
License:Apache License
@TransactionAttribute(TransactionAttributeType.REQUIRED) @Override//from w ww . ja v a 2 s . c o m public boolean isValid() { List<BaseQuestion> questions = questionBean.getAllQuestions(); //no further check if any of these two apply if (questions.isEmpty()) { values.add("No Questions loaded. This application is doomed."); failed = true; return false; } if (radio + check + free > questions.size()) { values.add("Not enough questions for a total size of " + (radio + check + free)); failed = true; return false; } IStringResourceLoader resLoader = new SimplePropertyResourceLoader(pathToResourceFolders); List<String> keys = new ArrayList<>(); for (BaseQuestion bq : questions) { keys.add(bq.getQuestionKey()); if (bq instanceof RadioQuestion) { RadioQuestion rq = (RadioQuestion) bq; keys.addAll(rq.getAnswerKeys()); keys.add(rq.getRightAnswerKeys()); if (!rq.getAnswerKeys().contains(rq.getRightAnswerKeys())) { failed = true; values.add(rq.getRightAnswerKeys() + " is not present in RadioQuestion"); } } if (bq instanceof CheckQuestion) { CheckQuestion cq = (CheckQuestion) bq; keys.addAll(cq.getAnswerKeys()); keys.addAll(cq.getRightAnswersKeys()); if (!cq.getAnswerKeys().containsAll(cq.getRightAnswersKeys())) { failed = true; values.add(Joiner.on(":").join(cq.getRightAnswersKeys()) + " one or more are not present in CheckQuestion"); } } } for (String key : keys) { for (Locale loc : supportedLocales) { LOGGER.debug("key: " + key + " locale: " + loc); if (null == resLoader.loadStringResource(getClass(), key, loc, null, null)) { values.add("Key: " + key + " is not translated in lang: " + loc); failed = true; } else { LOGGER.debug("...found"); } } } return !failed; }
From source file:com.norconex.commons.wicket.model.ClassResourceModel.java
License:Apache License
@Override protected String load() { Locale theLocale = locale;//from w w w. j ava 2 s .c o m if (theLocale == null) { theLocale = Session.get().getLocale(); } List<IStringResourceLoader> loaders = Application.get().getResourceSettings().getStringResourceLoaders(); for (IStringResourceLoader loader : loaders) { String string = loader.loadStringResource(klass, key, theLocale, Session.get().getStyle(), null); if (StringUtils.isNotBlank(string)) { return string; } } return null; }
From source file:com.norconex.commons.wicket.resource.loader.StringResourceLoaderUtil.java
License:Apache License
/** * Relies on the {@link PackageStringResourceLoader} class to get * a string.//w w w .j a va 2 s . c o m * @param klass the class used derive the package * @param key the string key * @param locale locale to use to return string * @return the proper string */ public static String getString(final Class<?> klass, final String key, final Locale locale) { List<IStringResourceLoader> loaders = Application.get().getResourceSettings().getStringResourceLoaders(); for (IStringResourceLoader loader : loaders) { String string = loader.loadStringResource(klass, key, locale, Session.get().getStyle(), null); if (StringUtils.isNotBlank(string)) { return string; } } return null; }
From source file:org.hippoecm.frontend.plugins.standards.ClassResourceModel.java
License:Apache License
@Override protected String load() { Iterator<IStringResourceLoader> iter = Application.get().getResourceSettings().getStringResourceLoaders() .iterator();/* w ww.j av a 2 s . co m*/ String value = null; while (iter.hasNext()) { IStringResourceLoader loader = iter.next(); value = loader.loadStringResource(clazz, key, locale, style, null); if (value != null) { break; } } if (value != null) { if (parameters != null) { final MessageFormat format = new MessageFormat(value, locale); value = format.format(parameters); } return value; } if (RuntimeConfigurationType.DEVELOPMENT.equals(Application.get().getConfigurationType())) { throw new RuntimeException("No translation found for " + this); } else { return key; } }
From source file:org.wicketstuff.rest.utils.wicket.bundle.DefaultBundleResolver.java
License:Apache License
@Override public String getMessage(String key, Map<String, Object> vars) { String resourceValue = null;/*from w w w.ja v a 2 s . co m*/ List<IStringResourceLoader> resourceLoaders = Application.get().getResourceSettings() .getStringResourceLoaders(); Locale locale = Session.get().getLocale(); String style = Session.get().getStyle(); outerloop: for (IStringResourceLoader stringResourceLoader : resourceLoaders) { for (Class<?> clazz : targetClasses) { resourceValue = stringResourceLoader.loadStringResource(clazz, key, locale, style, null); if (resourceValue != null) { break outerloop; } } } StringConverterInterpolator interpolator = new StringConverterInterpolator( resourceValue != null ? resourceValue : "", vars, false, locale); return interpolator.toString(); }
From source file:org.wicketstuff.rest.utils.wicket.DefaultBundleResolver.java
License:Apache License
@Override public String getMessage(String key, Map<String, Object> vars) { String resourceValue = null;/* w w w.ja v a2 s. c o m*/ List<IStringResourceLoader> resourceLoaders = Application.get().getResourceSettings() .getStringResourceLoaders(); Locale locale = Session.get().getLocale(); String style = Session.get().getStyle(); for (IStringResourceLoader stringResourceLoader : resourceLoaders) { resourceValue = stringResourceLoader.loadStringResource(clazz, key, locale, style, null); if (resourceValue != null) break; } StringConverterInterpolator interpolator = new StringConverterInterpolator( resourceValue != null ? resourceValue : "", vars, false, locale); return interpolator.toString(); }