Java Code Examples for org.apache.commons.lang.StringEscapeUtils#escapeCsv()
The following examples show how to use
org.apache.commons.lang.StringEscapeUtils#escapeCsv() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DBConfiguration.java From aliyun-maxcompute-data-collectors with Apache License 2.0 | 6 votes |
/** * Converts connection properties to a String to be passed to the mappers. * @param properties JDBC connection parameters * @return String to be passed to configuration */ protected static String propertiesToString(Properties properties) { List<String> propertiesList = new ArrayList<String>(properties.size()); for(Entry<Object, Object> property : properties.entrySet()) { String key = StringEscapeUtils.escapeCsv(property.getKey().toString()); if (key.equals(property.getKey().toString()) && key.contains("=")) { key = "\"" + key + "\""; } String val = StringEscapeUtils.escapeCsv(property.getValue().toString()); if (val.equals(property.getValue().toString()) && val.contains("=")) { val = "\"" + val + "\""; } propertiesList.add(StringEscapeUtils.escapeCsv(key + "=" + val)); } return StringUtils.join(propertiesList, ','); }
Example 2
Source File: GroovyTemplate.java From restcommander with Apache License 2.0 | 6 votes |
/** * This method is faster to call from groovy than __safe() since we only evaluate val.toString() * if we need to */ public String __safeFaster(Object val) { if (val != null) { if (val instanceof RawData) { return ((RawData) val).data; } else if (!template.name.endsWith(".html") || TagContext.hasParentTag("verbatim")) { if (template.name.endsWith(".xml")) { return StringEscapeUtils.escapeXml(val.toString()); } else if (template.name.endsWith(".csv")) { return StringEscapeUtils.escapeCsv(val.toString()); } return val.toString(); } else { return HTML.htmlEscape(val.toString()); } } else { return ""; } }
Example 3
Source File: EscapeUtils.java From common_gui_tools with Apache License 2.0 | 6 votes |
/** * 转义字符. * * @param string 字符 * @param type 字符类型 */ public static String escape(String string, String type) { String unescape = "不支持对" + type + "字符的转义"; if (type.equals(LanguageUtils.CONST_HTML)) { unescape = StringEscapeUtils.escapeHtml(string); } else if (type.equals(LanguageUtils.CONST_XML)) { unescape = StringEscapeUtils.escapeXml(string); } else if (type.equals(LanguageUtils.CONST_SQL)) { unescape = StringEscapeUtils.escapeSql(string); } else if (type.equals(LanguageUtils.CONST_JAVA)) { unescape = StringEscapeUtils.escapeJava(string); } else if (type.equals(LanguageUtils.CONST_JavaScript)) { unescape = StringEscapeUtils.escapeJavaScript(string); } else if (type.equals(LanguageUtils.CONST_CSV)) { unescape = StringEscapeUtils.escapeCsv(string); } return unescape; }
Example 4
Source File: Pql.java From googleads-java-lib with Apache License 2.0 | 6 votes |
/** * Gets the underlying value of the {@code Value} object that should be used for CSV conversion * (i.e. DateTimeValue will return a String representation, but NumberValue will return a Long or * Double). * * @param apiValue the api value to convert * @return the CSV conversion value of the api value or {@code null} if the underlying value is * null * @throws IllegalArgumentException if value cannot be converted */ private static Object getCsvValue(Object apiValue) { if (apiValue == null) { return null; } else if (apiValue instanceof DateTime) { return DateTimes.toStringWithTimeZone((DateTime) apiValue); } else if (apiValue instanceof Date) { return DateTimes.toString((Date) apiValue); } else if (apiValue instanceof Set<?>) { Set<Object> csvValues = new LinkedHashSet<Object>(); for (Object entry : (Set<?>) apiValue) { Object csvValue = getCsvValue(entry); validateSetValueEntryForSet(csvValue, csvValues); if (csvValue instanceof String) { csvValue = StringEscapeUtils.escapeCsv((String) csvValue); } csvValues.add(csvValue); } return Joiner.on(",").join(csvValues); } else if (apiValue instanceof Targeting) { throw new IllegalArgumentException("Unsupported Value type [" + apiValue.getClass() + "]"); } else { return apiValue; } }
Example 5
Source File: Pql.java From googleads-java-lib with Apache License 2.0 | 6 votes |
/** * Gets the underlying value of the {@code Value} object that should be used for CSV conversion * (i.e. DateTimeValue will return a String representation, but NumberValue will return a Long or * Double). * * @param apiValue the api value to convert * @return the CSV conversion value of the api value or {@code null} if the underlying value is * null * @throws IllegalArgumentException if value cannot be converted */ private static Object getCsvValue(Object apiValue) { if (apiValue == null) { return null; } else if (apiValue instanceof DateTime) { return DateTimes.toStringWithTimeZone((DateTime) apiValue); } else if (apiValue instanceof Date) { return DateTimes.toString((Date) apiValue); } else if (apiValue instanceof Set<?>) { Set<Object> csvValues = new LinkedHashSet<Object>(); for (Object entry : (Set<?>) apiValue) { Object csvValue = getCsvValue(entry); validateSetValueEntryForSet(csvValue, csvValues); if (csvValue instanceof String) { csvValue = StringEscapeUtils.escapeCsv((String) csvValue); } csvValues.add(csvValue); } return Joiner.on(",").join(csvValues); } else if (apiValue instanceof Targeting) { throw new IllegalArgumentException("Unsupported Value type [" + apiValue.getClass() + "]"); } else { return apiValue; } }
Example 6
Source File: Pql.java From googleads-java-lib with Apache License 2.0 | 6 votes |
/** * Gets the underlying value of the {@code Value} object that should be used for CSV conversion * (i.e. DateTimeValue will return a String representation, but NumberValue will return a Long or * Double). * * @param apiValue the api value to convert * @return the CSV conversion value of the api value or {@code null} if the underlying value is * null * @throws IllegalArgumentException if value cannot be converted */ private static Object getCsvValue(Object apiValue) { if (apiValue == null) { return null; } else if (apiValue instanceof DateTime) { return DateTimes.toStringWithTimeZone((DateTime) apiValue); } else if (apiValue instanceof Date) { return DateTimes.toString((Date) apiValue); } else if (apiValue instanceof Set<?>) { Set<Object> csvValues = new LinkedHashSet<Object>(); for (Object entry : (Set<?>) apiValue) { Object csvValue = getCsvValue(entry); validateSetValueEntryForSet(csvValue, csvValues); if (csvValue instanceof String) { csvValue = StringEscapeUtils.escapeCsv((String) csvValue); } csvValues.add(csvValue); } return Joiner.on(",").join(csvValues); } else if (apiValue instanceof Targeting) { throw new IllegalArgumentException("Unsupported Value type [" + apiValue.getClass() + "]"); } else { return apiValue; } }
Example 7
Source File: Pql.java From googleads-java-lib with Apache License 2.0 | 6 votes |
/** * Gets the underlying value of the {@code Value} object that should be used for CSV conversion * (i.e. DateTimeValue will return a String representation, but NumberValue will return a Long or * Double). * * @param apiValue the api value to convert * @return the CSV conversion value of the api value or {@code null} if the underlying value is * null * @throws IllegalArgumentException if value cannot be converted */ private static Object getCsvValue(Object apiValue) { if (apiValue == null) { return null; } else if (apiValue instanceof DateTime) { return DateTimes.toStringWithTimeZone((DateTime) apiValue); } else if (apiValue instanceof Date) { return DateTimes.toString((Date) apiValue); } else if (apiValue instanceof Set<?>) { Set<Object> csvValues = new LinkedHashSet<Object>(); for (Object entry : (Set<?>) apiValue) { Object csvValue = getCsvValue(entry); validateSetValueEntryForSet(csvValue, csvValues); if (csvValue instanceof String) { csvValue = StringEscapeUtils.escapeCsv((String) csvValue); } csvValues.add(csvValue); } return Joiner.on(",").join(csvValues); } else if (apiValue instanceof Targeting) { throw new IllegalArgumentException("Unsupported Value type [" + apiValue.getClass() + "]"); } else { return apiValue; } }
Example 8
Source File: Pql.java From googleads-java-lib with Apache License 2.0 | 6 votes |
/** * Gets the underlying value of the {@code Value} object that should be used for CSV conversion * (i.e. DateTimeValue will return a String representation, but NumberValue will return a Long or * Double). * * @param apiValue the api value to convert * @return the CSV conversion value of the api value or {@code null} if the underlying value is * null * @throws IllegalArgumentException if value cannot be converted */ private static Object getCsvValue(Object apiValue) { if (apiValue == null) { return null; } else if (apiValue instanceof DateTime) { return DateTimes.toStringWithTimeZone((DateTime) apiValue); } else if (apiValue instanceof Date) { return DateTimes.toString((Date) apiValue); } else if (apiValue instanceof Set<?>) { Set<Object> csvValues = new LinkedHashSet<Object>(); for (Object entry : (Set<?>) apiValue) { Object csvValue = getCsvValue(entry); validateSetValueEntryForSet(csvValue, csvValues); if (csvValue instanceof String) { csvValue = StringEscapeUtils.escapeCsv((String) csvValue); } csvValues.add(csvValue); } return Joiner.on(",").join(csvValues); } else if (apiValue instanceof Targeting) { throw new IllegalArgumentException("Unsupported Value type [" + apiValue.getClass() + "]"); } else { return apiValue; } }
Example 9
Source File: Pql.java From googleads-java-lib with Apache License 2.0 | 6 votes |
/** * Gets the underlying value of the {@code Value} object that should be used for CSV conversion * (i.e. DateTimeValue will return a String representation, but NumberValue will return a Long or * Double). * * @param apiValue the api value to convert * @return the CSV conversion value of the api value or {@code null} if the underlying value is * null * @throws IllegalArgumentException if value cannot be converted */ private static Object getCsvValue(Object apiValue) { if (apiValue == null) { return null; } else if (apiValue instanceof DateTime) { return DateTimes.toStringWithTimeZone((DateTime) apiValue); } else if (apiValue instanceof Date) { return DateTimes.toString((Date) apiValue); } else if (apiValue instanceof Set<?>) { Set<Object> csvValues = new LinkedHashSet<Object>(); for (Object entry : (Set<?>) apiValue) { Object csvValue = getCsvValue(entry); validateSetValueEntryForSet(csvValue, csvValues); if (csvValue instanceof String) { csvValue = StringEscapeUtils.escapeCsv((String) csvValue); } csvValues.add(csvValue); } return Joiner.on(",").join(csvValues); } else if (apiValue instanceof Targeting) { throw new IllegalArgumentException("Unsupported Value type [" + apiValue.getClass() + "]"); } else { return apiValue; } }
Example 10
Source File: Pql.java From googleads-java-lib with Apache License 2.0 | 6 votes |
/** * Gets the underlying value of the {@code Value} object that should be used for CSV conversion * (i.e. DateTimeValue will return a String representation, but NumberValue will return a Long or * Double). * * @param apiValue the api value to convert * @return the CSV conversion value of the api value or {@code null} if the underlying value is * null * @throws IllegalArgumentException if value cannot be converted */ private static Object getCsvValue(Object apiValue) { if (apiValue == null) { return null; } else if (apiValue instanceof DateTime) { return DateTimes.toStringWithTimeZone((DateTime) apiValue); } else if (apiValue instanceof Date) { return DateTimes.toString((Date) apiValue); } else if (apiValue instanceof Set<?>) { Set<Object> csvValues = new LinkedHashSet<Object>(); for (Object entry : (Set<?>) apiValue) { Object csvValue = getCsvValue(entry); validateSetValueEntryForSet(csvValue, csvValues); if (csvValue instanceof String) { csvValue = StringEscapeUtils.escapeCsv((String) csvValue); } csvValues.add(csvValue); } return Joiner.on(",").join(csvValues); } else if (apiValue instanceof Targeting) { throw new IllegalArgumentException("Unsupported Value type [" + apiValue.getClass() + "]"); } else { return apiValue; } }
Example 11
Source File: Pql.java From googleads-java-lib with Apache License 2.0 | 6 votes |
/** * Gets the underlying value of the {@code Value} object that should be used for CSV conversion * (i.e. DateTimeValue will return a String representation, but NumberValue will return a Long or * Double). * * @param apiValue the api value to convert * @return the CSV conversion value of the api value or {@code null} if the underlying value is * null * @throws IllegalArgumentException if value cannot be converted */ private static Object getCsvValue(Object apiValue) { if (apiValue == null) { return null; } else if (apiValue instanceof DateTime) { return DateTimes.toStringWithTimeZone((DateTime) apiValue); } else if (apiValue instanceof Date) { return DateTimes.toString((Date) apiValue); } else if (apiValue instanceof Set<?>) { Set<Object> csvValues = new LinkedHashSet<Object>(); for (Object entry : (Set<?>) apiValue) { Object csvValue = getCsvValue(entry); validateSetValueEntryForSet(csvValue, csvValues); if (csvValue instanceof String) { csvValue = StringEscapeUtils.escapeCsv((String) csvValue); } csvValues.add(csvValue); } return Joiner.on(",").join(csvValues); } else if (apiValue instanceof Targeting) { throw new IllegalArgumentException("Unsupported Value type [" + apiValue.getClass() + "]"); } else { return apiValue; } }
Example 12
Source File: LamsSecurityUtil.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Takes care about blank values. Besides, escapes CSV sensitive symbols (commas, quotes, etc) and then encodes it to be sent as a URL parameter. * * @param value * @param CSV * @return * @throws UnsupportedEncodingException */ private static String escapeValue(String value) throws UnsupportedEncodingException { final String DUMMY_VALUE = "-"; String notBlankValue = StringUtils.isBlank(value) ? DUMMY_VALUE : value; String escapedCsv = StringEscapeUtils.escapeCsv(notBlankValue); String encodedValue = URLEncoder.encode(escapedCsv, "utf8"); return encodedValue; }