List of usage examples for java.util Currency getInstance
public static Currency getInstance(Locale locale)
Currency
instance for the country of the given locale. From source file:org.orcid.frontend.web.controllers.FundingsController.java
@RequestMapping(value = "/funding/currencyValidate.json", method = RequestMethod.POST) public @ResponseBody FundingForm validateCurrency(@RequestBody FundingForm funding) { funding.getCurrencyCode().setErrors(new ArrayList<String>()); if (!PojoUtil.isEmpty(funding.getCurrencyCode())) { try {//from w ww . j ava 2 s .c om Currency.getInstance(funding.getCurrencyCode().getValue()); } catch (IllegalArgumentException iae) { setError(funding.getCurrencyCode(), "Invalid.fundings.currency"); } } return funding; }
From source file:org.noerp.base.util.UtilHttp.java
/** * Get the currency string from the session. * @param session HttpSession object to use for lookup * @return String The ISO currency code/*from w w w. j ava 2 s .c o m*/ */ public static String getCurrencyUom(HttpSession session, String appDefaultCurrencyUom) { // session, should override all if set there String iso = (String) session.getAttribute("currencyUom"); // check userLogin next, ie if nothing to override in the session if (iso == null) { Map<String, ?> userLogin = UtilGenerics.cast(session.getAttribute("userLogin")); if (userLogin == null) { userLogin = UtilGenerics.cast(session.getAttribute("autoUserLogin")); } if (userLogin != null) { iso = (String) userLogin.get("lastCurrencyUom"); } } // no user currency? before global default try appDefaultCurrencyUom if specified if (iso == null && !UtilValidate.isEmpty(appDefaultCurrencyUom)) { iso = appDefaultCurrencyUom; } // if none is set we will use the configured default if (iso == null) { try { iso = UtilProperties.getPropertyValue("general", "currency.uom.id.default", "USD"); } catch (Exception e) { Debug.logWarning("Error getting the general:currency.uom.id.default value: " + e.toString(), module); } } // if still none we will use the default for whatever locale we can get... if (iso == null) { Currency cur = Currency.getInstance(getLocale(session)); iso = cur.getCurrencyCode(); } return iso; }
From source file:org.apache.ofbiz.base.util.UtilHttp.java
/** * Get the currency string from the session. * @param session HttpSession object to use for lookup * @return String The ISO currency code//w w w. ja va 2 s . co m */ public static String getCurrencyUom(HttpSession session, String appDefaultCurrencyUom) { // session, should override all if set there String iso = (String) session.getAttribute("currencyUom"); // check userLogin next, ie if nothing to override in the session if (iso == null) { Map<String, ?> userLogin = UtilGenerics.cast(session.getAttribute("userLogin")); if (userLogin == null) { userLogin = UtilGenerics.cast(session.getAttribute("autoUserLogin")); } if (userLogin != null) { iso = (String) userLogin.get("lastCurrencyUom"); } } // no user currency? before global default try appDefaultCurrencyUom if specified if (iso == null && UtilValidate.isNotEmpty(appDefaultCurrencyUom)) { iso = appDefaultCurrencyUom; } // if none is set we will use the configured default if (iso == null) { try { iso = UtilProperties.getPropertyValue("general", "currency.uom.id.default", "USD"); } catch (Exception e) { Debug.logWarning("Error getting the general:currency.uom.id.default value: " + e.toString(), module); } } // if still none we will use the default for whatever currency we can get... if (iso == null) { Currency cur = Currency.getInstance(getLocale(session)); iso = cur.getCurrencyCode(); } return iso; }
From source file:org.rythmengine.utils.S.java
/** * Format give data into currency using locale info from the engine specified * /*from www .j ava 2 s . c om*/ * <p>The method accept any data type. When <code>null</code> is found then * <code>NullPointerException</code> will be thrown out; if an <code>Number</code> * is passed in, it will be type cast to <code>Number</code>; otherwise * a <code>Double.valueOf(data.toString())</code> is used to find out * the number</p> * * @param template * @param data * @param currencyCode * @param locale * @return the currency */ public static String formatCurrency(ITemplate template, Object data, String currencyCode, Locale locale) { if (null == data) throw new NullPointerException(); Number number; if (data instanceof Number) { number = (Number) data; } else { number = Double.parseDouble(data.toString()); } if (null == locale) locale = I18N.locale(template); Currency currency = null == currencyCode ? Currency.getInstance(locale) : Currency.getInstance(currencyCode); NumberFormat numberFormat = NumberFormat.getCurrencyInstance(locale); numberFormat.setCurrency(currency); numberFormat.setMaximumFractionDigits(currency.getDefaultFractionDigits()); String s = numberFormat.format(number); s = s.replace(currency.getCurrencyCode(), currency.getSymbol(locale)); return s; }
From source file:org.dasein.persist.PersistentCache.java
@SuppressWarnings({ "rawtypes", "unchecked" }) protected Object mapValue(String fieldName, Object dataStoreValue, Class<?> toType, ParameterizedType ptype) throws PersistenceException { LookupDelegate delegate = getLookupDelegate(fieldName); if (dataStoreValue != null && delegate != null && !delegate.validate(dataStoreValue.toString())) { throw new PersistenceException("Value " + dataStoreValue + " for " + fieldName + " is not valid."); }/*from w ww . ja va 2 s . c o m*/ try { if (toType.equals(String.class)) { if (dataStoreValue != null && !(dataStoreValue instanceof String)) { dataStoreValue = dataStoreValue.toString(); } } else if (Enum.class.isAssignableFrom(toType)) { if (dataStoreValue != null) { Enum e = Enum.valueOf((Class<? extends Enum>) toType, dataStoreValue.toString()); dataStoreValue = e; } } else if (toType.equals(Boolean.class) || toType.equals(boolean.class)) { if (dataStoreValue == null) { dataStoreValue = false; } else if (!(dataStoreValue instanceof Boolean)) { if (Number.class.isAssignableFrom(dataStoreValue.getClass())) { dataStoreValue = (((Number) dataStoreValue).intValue() != 0); } else { dataStoreValue = (dataStoreValue.toString().trim().equalsIgnoreCase("true") || dataStoreValue.toString().trim().equalsIgnoreCase("y")); } } } else if (Number.class.isAssignableFrom(toType) || toType.equals(byte.class) || toType.equals(short.class) || toType.equals(long.class) || toType.equals(int.class) || toType.equals(float.class) || toType.equals(double.class)) { if (dataStoreValue == null) { if (toType.equals(int.class) || toType.equals(short.class) || toType.equals(long.class)) { dataStoreValue = 0; } else if (toType.equals(float.class) || toType.equals(double.class)) { dataStoreValue = 0.0f; } } else if (toType.equals(Number.class)) { if (!(dataStoreValue instanceof Number)) { if (dataStoreValue instanceof String) { try { dataStoreValue = Double.parseDouble((String) dataStoreValue); } catch (NumberFormatException e) { throw new PersistenceException("Unable to map " + fieldName + " as " + toType + " using " + dataStoreValue); } } else if (dataStoreValue instanceof Boolean) { dataStoreValue = (((Boolean) dataStoreValue) ? 1 : 0); } else { throw new PersistenceException( "Unable to map " + fieldName + " as " + toType + " using " + dataStoreValue); } } } else if (toType.equals(Integer.class) || toType.equals(int.class)) { if (dataStoreValue instanceof Number) { if (!(dataStoreValue instanceof Integer)) { dataStoreValue = ((Number) dataStoreValue).intValue(); } } else if (dataStoreValue instanceof String) { try { dataStoreValue = Integer.parseInt((String) dataStoreValue); } catch (NumberFormatException e) { throw new PersistenceException( "Unable to map " + fieldName + " as " + toType + " using " + dataStoreValue); } } else if (dataStoreValue instanceof Boolean) { dataStoreValue = (((Boolean) dataStoreValue) ? 1 : 0); } else { throw new PersistenceException( "Unable to map " + fieldName + " as " + toType + " using " + dataStoreValue); } } else if (toType.equals(Long.class) || toType.equals(long.class)) { if (dataStoreValue instanceof Number) { if (!(dataStoreValue instanceof Long)) { dataStoreValue = ((Number) dataStoreValue).longValue(); } } else if (dataStoreValue instanceof String) { try { dataStoreValue = Long.parseLong((String) dataStoreValue); } catch (NumberFormatException e) { throw new PersistenceException( "Unable to map " + fieldName + " as " + toType + " using " + dataStoreValue); } } else if (dataStoreValue instanceof Boolean) { dataStoreValue = (((Boolean) dataStoreValue) ? 1L : 0L); } else { throw new PersistenceException( "Unable to map " + fieldName + " as " + toType + " using " + dataStoreValue); } } else if (toType.equals(Byte.class) || toType.equals(byte.class)) { if (dataStoreValue instanceof Number) { if (!(dataStoreValue instanceof Byte)) { dataStoreValue = ((Number) dataStoreValue).byteValue(); } } else if (dataStoreValue instanceof String) { try { dataStoreValue = Byte.parseByte((String) dataStoreValue); } catch (NumberFormatException e) { throw new PersistenceException( "Unable to map " + fieldName + " as " + toType + " using " + dataStoreValue); } } else if (dataStoreValue instanceof Boolean) { dataStoreValue = (((Boolean) dataStoreValue) ? 1 : 0); } else { throw new PersistenceException( "Unable to map " + fieldName + " as " + toType + " using " + dataStoreValue); } } else if (toType.equals(Short.class) || toType.equals(short.class)) { if (dataStoreValue instanceof Number) { if (!(dataStoreValue instanceof Short)) { dataStoreValue = ((Number) dataStoreValue).shortValue(); } } else if (dataStoreValue instanceof String) { try { dataStoreValue = Short.parseShort((String) dataStoreValue); } catch (NumberFormatException e) { throw new PersistenceException( "Unable to map " + fieldName + " as " + toType + " using " + dataStoreValue); } } else if (dataStoreValue instanceof Boolean) { dataStoreValue = (((Boolean) dataStoreValue) ? 1 : 0); } else { throw new PersistenceException( "Unable to map " + fieldName + " as " + toType + " using " + dataStoreValue); } } else if (toType.equals(Double.class) || toType.equals(double.class)) { if (dataStoreValue instanceof Number) { if (!(dataStoreValue instanceof Double)) { dataStoreValue = ((Number) dataStoreValue).doubleValue(); } } else if (dataStoreValue instanceof String) { try { dataStoreValue = Double.parseDouble((String) dataStoreValue); } catch (NumberFormatException e) { throw new PersistenceException( "Unable to map " + fieldName + " as " + toType + " using " + dataStoreValue); } } else if (dataStoreValue instanceof Boolean) { dataStoreValue = (((Boolean) dataStoreValue) ? 1.0 : 0.0); } else { throw new PersistenceException( "Unable to map " + fieldName + " as " + toType + " using " + dataStoreValue); } } else if (toType.equals(Float.class) || toType.equals(float.class)) { if (dataStoreValue instanceof Number) { if (!(dataStoreValue instanceof Float)) { dataStoreValue = ((Number) dataStoreValue).floatValue(); } } else if (dataStoreValue instanceof String) { try { dataStoreValue = Float.parseFloat((String) dataStoreValue); } catch (NumberFormatException e) { throw new PersistenceException( "Unable to map " + fieldName + " as " + toType + " using " + dataStoreValue); } } else if (dataStoreValue instanceof Boolean) { dataStoreValue = (((Boolean) dataStoreValue) ? 1.0f : 0.0f); } else { throw new PersistenceException( "Unable to map " + fieldName + " as " + toType + " using " + dataStoreValue); } } else if (toType.equals(BigDecimal.class)) { if (dataStoreValue instanceof Number) { if (!(dataStoreValue instanceof BigDecimal)) { if (dataStoreValue instanceof BigInteger) { dataStoreValue = new BigDecimal((BigInteger) dataStoreValue); } else { dataStoreValue = BigDecimal.valueOf(((Number) dataStoreValue).doubleValue()); } } } else if (dataStoreValue instanceof String) { try { dataStoreValue = new BigDecimal((String) dataStoreValue); } catch (NumberFormatException e) { throw new PersistenceException( "Unable to map " + fieldName + " as " + toType + " using " + dataStoreValue); } } else if (dataStoreValue instanceof Boolean) { dataStoreValue = new BigDecimal((((Boolean) dataStoreValue) ? 1.0 : 0.0)); } else { throw new PersistenceException( "Unable to map " + fieldName + " as " + toType + " using " + dataStoreValue); } } else if (toType.equals(BigInteger.class)) { if (dataStoreValue instanceof Number) { if (!(dataStoreValue instanceof BigInteger)) { if (dataStoreValue instanceof BigDecimal) { dataStoreValue = ((BigDecimal) dataStoreValue).toBigInteger(); } else { dataStoreValue = BigInteger.valueOf(((Number) dataStoreValue).longValue()); } } } else if (dataStoreValue instanceof String) { try { dataStoreValue = new BigDecimal((String) dataStoreValue); } catch (NumberFormatException e) { throw new PersistenceException( "Unable to map " + fieldName + " as " + toType + " using " + dataStoreValue); } } else if (dataStoreValue instanceof Boolean) { dataStoreValue = new BigDecimal((((Boolean) dataStoreValue) ? 1.0 : 0.0)); } else { throw new PersistenceException( "Unable to map " + fieldName + " as " + toType + " using " + dataStoreValue); } } else if (dataStoreValue != null) { logger.error("Type of dataStoreValue=" + dataStoreValue.getClass()); throw new PersistenceException( "Unable to map " + fieldName + " as " + toType + " using " + dataStoreValue); } } else if (toType.equals(Locale.class)) { if (dataStoreValue != null && !(dataStoreValue instanceof Locale)) { String[] parts = dataStoreValue.toString().split("_"); if (parts != null && parts.length > 1) { dataStoreValue = new Locale(parts[0], parts[1]); } else { dataStoreValue = new Locale(parts[0]); } } } else if (Measured.class.isAssignableFrom(toType)) { if (dataStoreValue != null && ptype != null) { if (Number.class.isAssignableFrom(dataStoreValue.getClass())) { Constructor<? extends Measured> constructor = null; double value = ((Number) dataStoreValue).doubleValue(); for (Constructor<?> c : toType.getDeclaredConstructors()) { Class[] args = c.getParameterTypes(); if (args != null && args.length == 2 && Number.class.isAssignableFrom(args[0]) && UnitOfMeasure.class.isAssignableFrom(args[1])) { constructor = (Constructor<? extends Measured>) c; break; } } if (constructor == null) { throw new PersistenceException("Unable to map with no proper constructor"); } dataStoreValue = constructor.newInstance(value, ((Class<?>) ptype.getActualTypeArguments()[0]).newInstance()); } else if (!(dataStoreValue instanceof Measured)) { try { dataStoreValue = Double.parseDouble(dataStoreValue.toString()); } catch (NumberFormatException e) { Method method = null; for (Method m : toType.getDeclaredMethods()) { if (Modifier.isStatic(m.getModifiers()) && m.getName().equals("valueOf")) { if (m.getParameterTypes().length == 1 && m.getParameterTypes()[0].equals(String.class)) { method = m; break; } } } if (method == null) { throw new PersistenceException("Don't know how to map " + dataStoreValue + " to " + toType + "<" + ptype + ">"); } dataStoreValue = method.invoke(null, dataStoreValue.toString()); } } // just because we converted it to a measured object above doesn't mean // we have the unit of measure right if (dataStoreValue instanceof Measured) { UnitOfMeasure targetUom = (UnitOfMeasure) ((Class<?>) ptype.getActualTypeArguments()[0]) .newInstance(); if (!(((Measured) dataStoreValue).getUnitOfMeasure()).equals(targetUom)) { dataStoreValue = ((Measured) dataStoreValue).convertTo( (UnitOfMeasure) ((Class<?>) ptype.getActualTypeArguments()[0]).newInstance()); } } } } else if (toType.equals(UUID.class)) { if (dataStoreValue != null && !(dataStoreValue instanceof UUID)) { dataStoreValue = UUID.fromString(dataStoreValue.toString()); } } else if (toType.equals(TimeZone.class)) { if (dataStoreValue != null && !(dataStoreValue instanceof TimeZone)) { dataStoreValue = TimeZone.getTimeZone(dataStoreValue.toString()); } } else if (toType.equals(Currency.class)) { if (dataStoreValue != null && !(dataStoreValue instanceof Currency)) { dataStoreValue = Currency.getInstance(dataStoreValue.toString()); } } else if (toType.isArray()) { Class<?> t = toType.getComponentType(); if (dataStoreValue == null) { dataStoreValue = Array.newInstance(t, 0); } else if (dataStoreValue instanceof JSONArray) { JSONArray arr = (JSONArray) dataStoreValue; if (long.class.isAssignableFrom(t)) { long[] replacement = (long[]) Array.newInstance(long.class, arr.length()); for (int i = 0; i < arr.length(); i++) { replacement[i] = (Long) mapValue(fieldName, arr.get(i), t, null); } dataStoreValue = replacement; } else if (int.class.isAssignableFrom(t)) { int[] replacement = (int[]) Array.newInstance(int.class, arr.length()); for (int i = 0; i < arr.length(); i++) { replacement[i] = (Integer) mapValue(fieldName, arr.get(i), t, null); } dataStoreValue = replacement; } else if (float.class.isAssignableFrom(t)) { float[] replacement = (float[]) Array.newInstance(float.class, arr.length()); for (int i = 0; i < arr.length(); i++) { replacement[i] = (Float) mapValue(fieldName, arr.get(i), t, null); } dataStoreValue = replacement; } else if (double.class.isAssignableFrom(t)) { double[] replacement = (double[]) Array.newInstance(double.class, arr.length()); for (int i = 0; i < arr.length(); i++) { replacement[i] = (Double) mapValue(fieldName, arr.get(i), t, null); } dataStoreValue = replacement; } else if (boolean.class.isAssignableFrom(t)) { boolean[] replacement = (boolean[]) Array.newInstance(boolean.class, arr.length()); for (int i = 0; i < arr.length(); i++) { replacement[i] = (Boolean) mapValue(fieldName, arr.get(i), t, null); } dataStoreValue = replacement; } else { Object[] replacement = (Object[]) Array.newInstance(t, arr.length()); for (int i = 0; i < arr.length(); i++) { replacement[i] = mapValue(fieldName, arr.get(i), t, null); } dataStoreValue = replacement; } } else if (!dataStoreValue.getClass().isArray()) { logger.error("Unable to map data store type " + dataStoreValue.getClass().getName() + " to " + toType.getName()); logger.error("Value of " + fieldName + "=" + dataStoreValue); throw new PersistenceException("Data store type=" + dataStoreValue.getClass().getName()); } } else if (dataStoreValue != null && !toType.isAssignableFrom(dataStoreValue.getClass())) { Annotation[] alist = toType.getDeclaredAnnotations(); boolean autoJSON = false; for (Annotation a : alist) { if (a instanceof AutoJSON) { autoJSON = true; } } if (autoJSON) { dataStoreValue = autoDeJSON(toType, (JSONObject) dataStoreValue); } else { try { Method m = toType.getDeclaredMethod("valueOf", JSONObject.class); dataStoreValue = m.invoke(null, dataStoreValue); } catch (NoSuchMethodException ignore) { try { Method m = toType.getDeclaredMethod("valueOf", String.class); if (m != null) { dataStoreValue = m.invoke(null, dataStoreValue.toString()); } else { throw new PersistenceException( "No valueOf() field in " + toType + " for mapping " + fieldName); } } catch (NoSuchMethodException e) { throw new PersistenceException("No valueOf() field in " + toType + " for mapping " + fieldName + " with " + dataStoreValue + ": (" + dataStoreValue.getClass().getName() + " vs " + toType.getName() + ")"); } } } } } catch (Exception e) { String err = "Error mapping field in " + toType + " for " + fieldName + ": " + e.getMessage(); logger.error(err, e); throw new PersistenceException(); } return dataStoreValue; }
From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractSubscriptionController.java
@RequestMapping(value = ("/browse_catalog"), method = RequestMethod.GET) public String anonymousCatalog(ModelMap map, @RequestParam(value = "serviceInstanceUUID", required = false) final String serviceInstanceUUID, @RequestParam(value = "currencyCode", required = false) String currencyCode, @RequestParam(value = "resourceType", required = false) final String resourceType, @RequestParam(value = "channelCode", required = false) final String channelCode, final HttpServletRequest request) { logger.debug("### anonymousCatalog method starting...(GET)"); final String successView = "anonymous.catalog"; if (config.getValue(Names.com_citrix_cpbm_public_catalog_display).equals("true")) { Channel channel = null;/*from w w w . j a va 2s . c om*/ if (StringUtils.isNotBlank(channelCode)) { channel = channelService.locateByChannelCode(channelCode); } else { channel = channelService.getDefaultServiceProviderChannel(); } final Catalog catalog = channel.getCatalog(); List<CurrencyValue> currencies = catalog.getSupportedCurrencyValuesByOrder(); map.addAttribute("channel", channel); map.addAttribute("currencies", currencies); map.addAttribute("anonymousBrowsing", true); CurrencyValue currency = currencies.get(0); if (StringUtils.isNotBlank(currencyCode)) { currency = currencyValueService.locateBYCurrencyCode(currencyCode); } map.addAttribute("selectedCurrency", currency); map.addAttribute(UserContextInterceptor.MIN_FRACTION_DIGITS, Currency.getInstance(currency.getCurrencyCode()).getDefaultFractionDigits()); final Tenant tenant = tenantService.getSystemTenant(); final Channel finalChannel = channel; Map<String, Object> finalMap = privilegeService .runAsPortal(new PrivilegedAction<Map<String, Object>>() { @Override public Map<String, Object> run() { ModelMap modelMap = new ModelMap(); try { getResourceComponentsAndFilterData(tenant, null, serviceInstanceUUID, null, resourceType, modelMap, request, successView, finalChannel.getName()); } catch (ConnectorManagementServiceException e) { logger.debug("Error occured ", e); } return modelMap; } }); map.addAllAttributes(finalMap); map.addAttribute("supportedLocaleList", this.getLocaleDisplayName(listSupportedLocales())); // anonymousBrowsing and preview catalog will have default UI Because in cutom UI SSO happens which can leads to // security threats map.addAttribute("customEditorTag", null); map.addAttribute("customComponentSelector", null); } else { throw new NoSuchDefinitionException(); } return successView; }
From source file:de.schildbach.pte.VrsProvider.java
private static List<Fare> parseFare(final JSONObject costs) throws JSONException { List<Fare> fares = new ArrayList<>(); if (costs != null) { final String name = costs.optString("name", null); // e.g. "VRS-Tarif", "NRW-Tarif" final String text = costs.optString("text", null); // e.g. "Preisstufe 4 [RegioTicket] 7,70 ", // "VRR-Tarif! (Details: www.vrr.de)", "17,30 (2.Kl) / PauschalpreisTickets gltig" float price = (float) costs.optDouble("price", 0.0); // e.g. 7.7 or not existent outside VRS // long zone = costs.getLong("zone"); // e.g. 2600 final String level = costs.has("level") ? "Preisstufe " + costs.getString("level") : null; // e.g. // "4" if (name != null && price != 0.0 && level != null) { fares.add(new Fare(name, Fare.Type.ADULT, Currency.getInstance("EUR"), price, level, null /* units */)); } else if (name != null && name.equals("NRW-Tarif") && text != null) { Matcher matcher = nrwTarifPattern.matcher(text); if (matcher.find()) { fares.add(new Fare(name, Fare.Type.ADULT, Currency.getInstance("EUR"), Float.parseFloat(matcher.group(0).replace(",", ".")), null /* level */, null /* units */)); }/*ww w . jav a2 s . c o m*/ } } return fares; }
From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractProductBundlesController.java
private void populateEntitlementForm(String bundleCode, ModelMap map, Date revisionDate) { EntitlementForm entitlementForm = new EntitlementForm(); ProductBundle bundle = productBundleService.findProductBundleByCode(bundleCode); Entitlement entitlement = new Entitlement(); entitlement.setProductBundle(bundle); entitlement.setCreatedBy(getCurrentUser()); entitlement.setUpdatedBy(getCurrentUser()); entitlementForm.setEntitlement(entitlement); List<Product> products = productBundleService.getAllowedProductsForEntitlementsInProductBundle(bundle, revisionDate, null);//from ww w . j av a2 s .co m map.addAttribute("entitlementForm", entitlementForm); map.addAttribute("products", products); map.addAttribute("currency", Currency.getInstance(config.getValue(Names.com_citrix_cpbm_portal_settings_default_currency))); }
From source file:com.concursive.connect.web.modules.wiki.utils.WikiPDFUtils.java
public static String getFieldValue(WikiPDFContext context, CustomFormField field) { // Return output based on type switch (field.getType()) { case CustomFormField.TEXTAREA: return StringUtils.replace(field.getValue(), "^", CRLF); case CustomFormField.SELECT: return field.getValue(); case CustomFormField.CHECKBOX: if ("true".equals(field.getValue())) { return "Yes"; } else {//from ww w.j a v a2 s . c o m return "No"; } case CustomFormField.CALENDAR: String calendarValue = field.getValue(); if (StringUtils.hasText(calendarValue)) { try { String convertedDate = DateUtils.getUserToServerDateTimeString(null, DateFormat.SHORT, DateFormat.LONG, field.getValue()); Timestamp timestamp = DatabaseUtils.parseTimestamp(convertedDate); Locale locale = Locale.getDefault(); int dateFormat = DateFormat.SHORT; SimpleDateFormat dateFormatter = (SimpleDateFormat) SimpleDateFormat.getDateInstance(dateFormat, locale); calendarValue = dateFormatter.format(timestamp); } catch (Exception e) { LOG.error(e); } } return calendarValue; case CustomFormField.PERCENT: return field.getValue() + "%"; case CustomFormField.INTEGER: // Determine the value to display in the field String integerValue = StringUtils.toHtmlValue(field.getValue()); if (StringUtils.hasText(integerValue)) { try { NumberFormat formatter = NumberFormat.getInstance(); integerValue = formatter.format(StringUtils.getIntegerNumber(field.getValue())); } catch (Exception e) { LOG.warn("Could not integer format: " + field.getValue()); } } return integerValue; case CustomFormField.FLOAT: // Determine the value to display in the field String decimalValue = field.getValue(); if (StringUtils.hasText(decimalValue)) { try { NumberFormat formatter = NumberFormat.getInstance(); decimalValue = formatter.format(StringUtils.getDoubleNumber(field.getValue())); } catch (Exception e) { LOG.warn("Could not decimal format: " + field.getValue()); } } return decimalValue; case CustomFormField.CURRENCY: // Use a currency for formatting String currencyCode = field.getValueCurrency(); if (currencyCode == null) { currencyCode = field.getCurrency(); } if (!StringUtils.hasText(currencyCode)) { currencyCode = "USD"; } try { NumberFormat formatter = NumberFormat.getCurrencyInstance(); if (currencyCode != null) { Currency currency = Currency.getInstance(currencyCode); formatter.setCurrency(currency); } return (formatter.format(StringUtils.getDoubleNumber(field.getValue()))); } catch (Exception e) { LOG.error(e.getMessage()); } return field.getValue(); case CustomFormField.EMAIL: return field.getValue(); case CustomFormField.PHONE: PhoneNumberBean phone = new PhoneNumberBean(); phone.setNumber(field.getValue()); PhoneNumberUtils.format(phone, Locale.getDefault()); return phone.toString(); case CustomFormField.URL: String value = StringUtils.toHtmlValue(field.getValue()); if (StringUtils.hasText(value)) { if (!value.contains("://")) { value = "http://" + value; } if (value.contains("://")) { return value; } } return value; case CustomFormField.IMAGE: String image = field.getValue(); if (StringUtils.hasText(image)) { return "WikiImage:" + image; } return image; default: return field.getValue(); } }
From source file:net.sourceforge.eclipsetrader.core.internal.XMLRepository.java
private SecurityGroup loadSecurityGroup(NodeList node) { SecurityGroup group = new SecurityGroup( new Integer(Integer.parseInt(((Node) node).getAttributes().getNamedItem("id").getNodeValue()))); //$NON-NLS-1$ for (int i = 0; i < node.getLength(); i++) { Node item = node.item(i); String nodeName = item.getNodeName(); Node value = item.getFirstChild(); if (value != null) { if (nodeName.equals("code")) //$NON-NLS-1$ group.setCode(value.getNodeValue()); else if (nodeName.equals("description")) //$NON-NLS-1$ group.setDescription(value.getNodeValue()); else if (nodeName.equals("currency")) //$NON-NLS-1$ group.setCurrency(Currency.getInstance(value.getNodeValue())); }/*from ww w . j av a2 s. c om*/ if (nodeName.equals("security")) //$NON-NLS-1$ { Security obj = loadSecurity(item.getChildNodes()); obj.setGroup(group); obj.setRepository(this); obj.clearChanged(); allSecurities().add(obj); } else if (nodeName.equals("group")) //$NON-NLS-1$ { SecurityGroup obj = loadSecurityGroup(item.getChildNodes()); obj.setParentGroup(group); obj.setRepository(this); obj.clearChanged(); allSecurityGroups().add(obj); } } group.clearChanged(); securityGroupsMap.put(group.getId(), group); return group; }