private Locale defaulted(Locale locale) { return locale != null ? locale : threadLocale.getLocale(); }
public Calendar coerce(Date input) { Calendar calendar = Calendar.getInstance(threadLocale.getLocale()); calendar.setTime(input); return calendar; } }));
private String getLocale() { final String prefix = String.format("classpath:/META-INF/modules/tjq/vendor/ui/i18n/jquery.ui.datepicker-%s", locale.getLocale().getLanguage()); final Resource withCountryExtension = typeCoercer.coerce(String.format("%s-%s.js", prefix, locale.getLocale().getCountry()), Resource.class); if (withCountryExtension.exists()) { return String.format("%s-%s", locale.getLocale().getLanguage(), locale.getLocale().getCountry()); } final Resource withLanguageExtension = typeCoercer.coerce(String.format("%s.js", prefix), Resource.class); if (withLanguageExtension.exists()) { return locale.getLocale().getLanguage(); } return "en-GB"; }
/** * @see javax.validation.MessageInterpolator#interpolate(java.lang.String, javax.validation.MessageInterpolator.Context) */ @Override public String interpolate(String messageTemplate, Context context) { return interpolate(messageTemplate, context, threadLocale.getLocale()); }
public ComponentResourceSelector buildSelectorForRequest() { return new ComponentResourceSelector(threadLocale.getLocale()); } }
public Messages createObject() { Locale locale = threadLocale.getLocale(); Messages messages = localeToMessages.get(locale); if (messages == null) { messages = messagesSource.getApplicationCatalog(locale); localeToMessages.put(locale, messages); } return messages; } }
/** * @see javax.validation.MessageInterpolator#interpolate(java.lang.String, javax.validation.MessageInterpolator.Context) */ @Override public String interpolate(String messageTemplate, Context context) { return interpolate(messageTemplate, context, threadLocale.getLocale()); }
protected final void train_getLocale(ThreadLocale threadLocale, Locale locale) { expect(threadLocale.getLocale()).andReturn(locale); }
protected final void train_getLocale(ThreadLocale threadLocale, Locale locale) { expect(threadLocale.getLocale()).andReturn(locale); }
public DateFormat coerce(String input) { final SimpleDateFormat dateFormat = new SimpleDateFormat(input, threadLocale.getLocale()); final String lenient = objectLocator.getService(SymbolSource.class).valueForSymbol(SymbolConstants.LENIENT_DATE_FORMAT); dateFormat.setLenient(Boolean.parseBoolean(lenient)); return dateFormat; } }));
public List<Asset> getJavaScriptLibraries() { String jQueryUIPath = symbolSource.valueForSymbol(JQuerySymbolConstants.JQUERY_UI_PATH); if ( ! jQueryUIPath.endsWith("/")) { jQueryUIPath += "/"; } final List<Asset> javaScriptStack = new ArrayList<Asset>(); javaScriptStack.add(assetSource.getClasspathAsset(String.format("%s/datepicker.js", jQueryUIPath))); final Asset datePickerI18nAsset = getLocaleAsset(threadLocale.getLocale(), jQueryUIPath); if (includeDatePickerI18N && datePickerI18nAsset != null) { javaScriptStack.add(datePickerI18nAsset); } javaScriptStack.add(assetSource.getExpandedAsset("${assets.path}/components/datefield/datefield.js")); return javaScriptStack; }
public StreamableResource assembleJavaScriptResourceForStack(String stackName, boolean compress, JavaScriptAggregationStrategy javascriptAggregationStrategy) throws IOException { Locale locale = threadLocale.getLocale(); return assembleJavascriptResourceForStack(new Parameters(locale, stackName, compress, javascriptAggregationStrategy)); }
public String getInitialization() { Locale locale = threadLocale.getLocale(); JSONObject spec = new JSONObject(); DateFormatSymbols symbols = new DateFormatSymbols(locale); spec.put("months", new JSONArray((Object[]) symbols.getMonths())); StringBuilder days = new StringBuilder(); String[] weekdays = symbols.getWeekdays(); Calendar c = Calendar.getInstance(locale); int firstDay = c.getFirstDayOfWeek(); // DatePicker needs them in order from monday to sunday. for (int i = Calendar.MONDAY; i <= Calendar.SATURDAY; i++) { days.append(weekdays[i].substring(0, 1)); } days.append(weekdays[Calendar.SUNDAY].substring(0, 1)); spec.put("days", days.toString().toLowerCase(locale)); // jQuery DatePicker widget expects 0 to be sunday. Calendar defines SUNDAY as 1, MONDAY as 2, etc. spec.put("firstDay", firstDay-1); // set language spec.put("language", locale.getLanguage()); // TODO: Skip localization if locale is English? return String.format("Tapestry.DateField.initLocalization(%s);", spec.toString(compactJSON)); }
private List<String> combinedStackURL(String stackName, JavaScriptStack stack) { try { StreamableResource assembled = assembler.assembleJavaScriptResourceForStack(stackName, compressionAnalyzer.isGZipSupported(), stack.getJavaScriptAggregationStrategy()); String path = threadLocale.getLocale().toString() + '/' + stackName + ".js"; String stackURL = assetPathConstructor.constructAssetPath(RequestConstants.STACK_FOLDER, path, assembled); return CollectionFactory.newList(stackURL); } catch (IOException ex) { throw new RuntimeException(String.format("Unable to construct path for '%s' JavaScript stack: %s", stackName, ExceptionUtils.toMessage(ex)), ex); } }
private NumericFormatter getParseFormatter(Class type) { Locale locale = threadLocale.getLocale(); DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale); if (type.equals(BigInteger.class)) return new BigIntegerNumericFormatter(symbols); if (type.equals(BigDecimal.class)) return new BigDecimalNumericFormatter(symbols); // We don't cache NumberFormat instances because they are not thread safe. // Perhaps we should turn this service into a perthread so that we can cache // (for the duration of a request)? // We don't cache the rest of these, because they are built on DecimalFormat which is // not thread safe. if (isIntegerType(type)) { NumberFormat format = NumberFormat.getIntegerInstance(locale); return new NumericFormatterImpl(format); } DecimalFormat df = (DecimalFormat) NumberFormat.getNumberInstance(locale); if (type.equals(BigDecimal.class)) df.setParseBigDecimal(true); return new NumericFormatterImpl(df); }
public void renderMarkup(MarkupWriter writer, MarkupRenderer renderer) { renderer.renderMarkup(writer); // After that's done (i.e., pretty much all rendering), touch it up a little. Element html = writer.getDocument().find("html"); // If it is an HTML document, with a root HTML node, add attributes // to describe locale, and if debug is enabled. if (html != null) { html.attributes("data-locale", threadLocale.getLocale().toString()); if (debugEnabled) { html.attributes("data-debug-enabled", "true"); } } } }
private NumericFormatter getOutputFormatter(Class type) { Locale locale = threadLocale.getLocale(); DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale); if (type.equals(BigInteger.class)) return new BigIntegerNumericFormatter(symbols); if (type.equals(BigDecimal.class)) return new BigDecimalNumericFormatter(symbols); // We don't cache the rest of these, because they are built on DecimalFormat which is // not thread safe. if (!isIntegerType(type)) { NumberFormat format = NumberFormat.getNumberInstance(locale); return new NumericFormatterImpl(format); } DecimalFormat df = new DecimalFormat(toString(symbols.getZeroDigit()), symbols); return new NumericFormatterImpl(df); }