List of usage examples for org.apache.commons.beanutils ConvertUtils convert
public static String convert(Object value)
Convert the specified value into a String.
For more details see ConvertUtilsBean
.
From source file:info.magnolia.importexport.PropertiesImportExport.java
private static String convertBinaryToExportString(Value value) { return "binary:" + ConvertUtils.convert(value); }
From source file:com.dp2345.plugin.PaymentPlugin.java
/** * POST//from w w w. j a va 2s . co m * * @param url * URL * @param parameterMap * ? * @return */ protected String post(String url, Map<String, Object> parameterMap) { Assert.hasText(url); String result = null; CloseableHttpClient httpClient = HttpClients.createDefault(); CloseableHttpResponse httpResponse = null; try { HttpPost httpPost = new HttpPost(url); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); if (parameterMap != null) { for (Entry<String, Object> entry : parameterMap.entrySet()) { String name = entry.getKey(); String value = ConvertUtils.convert(entry.getValue()); if (StringUtils.isNotEmpty(name)) { nameValuePairs.add(new BasicNameValuePair(name, value)); } } } httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8")); httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); result = EntityUtils.toString(httpEntity); EntityUtils.consume(httpEntity); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { httpResponse.close(); } catch (IOException e) { e.printStackTrace(); } } return result; }
From source file:com.dp2345.plugin.PaymentPlugin.java
/** * GET//from ww w. ja v a 2 s .c om * * @param url * URL * @param parameterMap * ? * @return */ protected String get(String url, Map<String, Object> parameterMap) { Assert.hasText(url); String result = null; CloseableHttpClient httpClient = HttpClients.createDefault(); CloseableHttpResponse httpResponse = null; try { List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); if (parameterMap != null) { for (Entry<String, Object> entry : parameterMap.entrySet()) { String name = entry.getKey(); String value = ConvertUtils.convert(entry.getValue()); if (StringUtils.isNotEmpty(name)) { nameValuePairs.add(new BasicNameValuePair(name, value)); } } } HttpGet httpGet = new HttpGet(url + (StringUtils.contains(url, "?") ? "&" : "?") + EntityUtils.toString(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"))); httpResponse = httpClient.execute(httpGet); HttpEntity httpEntity = httpResponse.getEntity(); result = EntityUtils.toString(httpEntity); EntityUtils.consume(httpEntity); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { httpResponse.close(); } catch (IOException e) { e.printStackTrace(); } } return result; }
From source file:com.sammyun.plugin.PaymentPlugin.java
/** * POST/* w ww.j a v a 2s . c o m*/ * * @param url URL * @param parameterMap ? * @return */ protected String post(String url, Map<String, Object> parameterMap) { Assert.hasText(url); String result = null; HttpClient httpClient = new DefaultHttpClient(); try { HttpPost httpPost = new HttpPost(url); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); if (parameterMap != null) { for (Entry<String, Object> entry : parameterMap.entrySet()) { String name = entry.getKey(); String value = ConvertUtils.convert(entry.getValue()); if (StringUtils.isNotEmpty(name)) { nameValuePairs.add(new BasicNameValuePair(name, value)); } } } httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8")); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); result = EntityUtils.toString(httpEntity); EntityUtils.consume(httpEntity); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { httpClient.getConnectionManager().shutdown(); } return result; }
From source file:com.sammyun.plugin.PaymentPlugin.java
/** * GET/* w w w .ja va2s . c o m*/ * * @param url URL * @param parameterMap ? * @return */ protected String get(String url, Map<String, Object> parameterMap) { Assert.hasText(url); String result = null; HttpClient httpClient = new DefaultHttpClient(); try { List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); if (parameterMap != null) { for (Entry<String, Object> entry : parameterMap.entrySet()) { String name = entry.getKey(); String value = ConvertUtils.convert(entry.getValue()); if (StringUtils.isNotEmpty(name)) { nameValuePairs.add(new BasicNameValuePair(name, value)); } } } HttpGet httpGet = new HttpGet(url + (StringUtils.contains(url, "?") ? "&" : "?") + EntityUtils.toString(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"))); HttpResponse httpResponse = httpClient.execute(httpGet); HttpEntity httpEntity = httpResponse.getEntity(); result = EntityUtils.toString(httpEntity); EntityUtils.consume(httpEntity); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { httpClient.getConnectionManager().shutdown(); } return result; }
From source file:com.feilong.core.bean.ConvertUtilTest.java
/** * Test convert utils test22./*from w w w . jav a2 s . co m*/ */ @Test public void testConvertUtilsTest22() { LOGGER.debug(ConvertUtils.convert(888.000f)); LOGGER.debug("{}", ConvertUtils.convert(888.000f, BigDecimal.class)); }
From source file:net.sourceforge.pmd.util.fxdesigner.util.beans.XmlInterfaceVersion1.java
private void parseSingleProperty(Element propertyElement, SimpleBeanModelNode owner) { String typeName = propertyElement.getAttribute(SCHEMA_PROPERTY_TYPE); String name = propertyElement.getAttribute(SCHEMA_PROPERTY_NAME); Class<?> type;//from w w w . j a v a 2s. c o m try { type = ClassUtils.getClass(typeName); } catch (ClassNotFoundException e) { e.printStackTrace(); return; } ConvertUtils.convert(new Object()); Object value = ConvertUtils.convert(propertyElement.getTextContent(), type); owner.addProperty(name, value, type); }
From source file:org.cruk.genologics.api.impl.GenologicsAPIImpl.java
/** * Helper method to {@code expandSearchTerms}: builds up a query string with * joining ampersands and converts the value given into a string. * * @param query The StringBuilder which is building up the query. * @param argument The search parameter. * @param value The value to search for. * * @throws IllegalSearchTermException if {@code value} is null. * * @see #expandSearchTerms(Map)/* w ww .ja va2s. c o m*/ * @see ConvertUtilsBean#convert(Object) */ private void appendQueryTerm(StringBuilder query, String argument, Object value) { if (value == null) { // This message is sensible as find() will not call this method if it // finds the term's immediate value is null. It will only get here with // value == null when looping through an array or collection. throw new IllegalSearchTermException(argument, "Search term \"" + argument + "\" contains a null value."); } String strValue = ConvertUtils.convert(value); if (query.length() > 0) { query.append('&'); } query.append(argument); query.append('='); query.append(strValue); }
From source file:org.metawidget.example.struts.addressbook.form.PersonalContactForm.java
public void setDateOfBirth(Date ofBirth) { mOfBirth = ofBirth; if (mOfBirth != null) { mDateOfBirthAsString = ConvertUtils.convert(mOfBirth); } }
From source file:org.molasdin.wbase.collections.list.ExtendedListDecorator.java
@SuppressWarnings("unchecked") public void sort(final String property, Order order) { if (decorated().isEmpty()) { return;/*from www . ja va 2s.c o m*/ } T item = decorated().get(0); Comparator<T> tmp = null; if (ReflectionHelper.hasFunction(property, item)) { final Transformer<T, Object> transformer = new Transformer<T, Object>() { @Override public Object transform(T o) { return ReflectionHelper.functionValue(property, o); } }; Object val = transformer.transform(item); final boolean isNatural = ReflectionHelper.supportsNaturalOrdering(val); tmp = new Comparator<T>() { @Override public int compare(T o1, T o2) { Object firstResult = transformer.transform(o1); Object secondResult = transformer.transform(o2); if (isNatural) { Comparable f = (Comparable) firstResult; Comparable s = (Comparable) secondResult; return f.compareTo(s); } String f = ConvertUtils.convert(firstResult); String s = ConvertUtils.convert(secondResult); return f.compareTo(s); } }; } else if (PropertyUtils.isReadable(item, property)) { tmp = new BeanComparator(property); } else { throw new RuntimeException("No property"); } Collections.sort(decorated(), tmp); }