| 1 |
/* |
| 2 |
* @(#)MultilineStringConverter.java 10/24/2008 |
| 3 |
* |
| 4 |
* Copyright 2002 - 2008 JIDE Software Inc. All rights reserved. |
| 5 |
* |
| 6 |
*/ |
| 7 |
package com.jidesoft.converter; |
| 8 |
|
| 9 |
/** |
| 10 |
* Converter which converts a String with new lines to String and convert the new lines to "\n" so that it can be |
| 11 |
* displayed in the UI. |
| 12 |
*/ |
| 13 |
public class MultilineStringConverter implements ObjectConverter { |
| 14 |
public static final ConverterContext CONTEXT = new ConverterContext("MultilineString"); |
| 15 |
|
| 16 |
public String toString(Object object, ConverterContext context) { |
| 17 |
if (object instanceof String) { |
| 18 |
return ((String) object).replaceAll("\\\\n", "\\\\\\\\n").replaceAll("\\\\r", "\\\\\\\\r").replaceAll("\n", "\\\\n").replaceAll("\r", "\\\\r"); |
| 19 |
} |
| 20 |
else if (object == null) { |
| 21 |
return ""; |
| 22 |
} |
| 23 |
else { |
| 24 |
return "" + object; |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
public boolean supportToString(Object object, ConverterContext context) { |
| 29 |
return true; |
| 30 |
} |
| 31 |
|
| 32 |
public Object fromString(String string, ConverterContext context) { |
| 33 |
if (string != null) { |
| 34 |
return string.replaceAll("\\\\\\\\n", "\\\\n").replaceAll("\\\\\\\\r", "\\\\r"); |
| 35 |
} |
| 36 |
else { |
| 37 |
return null; |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
public boolean supportFromString(String string, ConverterContext context) { |
| 42 |
return true; |
| 43 |
} |
| 44 |
} |