| 1 |
/* |
| 2 |
* @(#) FileConverter.java |
| 3 |
* |
| 4 |
* Copyright 2002 - 2003 JIDE Software. All rights reserved. |
| 5 |
*/ |
| 6 |
package com.jidesoft.converter; |
| 7 |
|
| 8 |
import java.io.File; |
| 9 |
|
| 10 |
/** |
| 11 |
* Converter which converts File to String and converts it back. |
| 12 |
*/ |
| 13 |
public class FileConverter implements ObjectConverter { |
| 14 |
public String toString(Object object, ConverterContext context) { |
| 15 |
if (object == null || !(object instanceof File)) { |
| 16 |
return null; |
| 17 |
} |
| 18 |
else { |
| 19 |
return ((File) object).getAbsolutePath(); |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
public boolean supportToString(Object object, ConverterContext context) { |
| 24 |
return true; |
| 25 |
} |
| 26 |
|
| 27 |
public Object fromString(String string, ConverterContext context) { |
| 28 |
if (string == null || string.trim().length() == 0) { |
| 29 |
return null; |
| 30 |
} |
| 31 |
return new File(string); |
| 32 |
} |
| 33 |
|
| 34 |
public boolean supportFromString(String string, ConverterContext context) { |
| 35 |
return true; |
| 36 |
} |
| 37 |
} |