package net.sourceforge.rtf.format;
import java.text.FieldPosition;
import java.text.Format;
import java.text.ParsePosition;
import net.sourceforge.rtf.format.rtfcode.RTFCodeString;
import net.sourceforge.rtf.util.StringUtils;
/**
*
* Format RTF code like transform :
* <ul>
* <li> \n with \\par</li>
* <li> \r with \\par</li>
* <li> \t with \\tab</li>
* </ul>
* @version 1.0.11
* @author <a href="mailto:angelo.zerr@gmail.com">Angelo ZERR</a>
*
*/
public class NewDefaultRTFCodeStringFormat extends Format {
public StringBuffer format(Object obj, StringBuffer stringbuffer, FieldPosition fieldposition) {
if (obj == null || !(obj instanceof RTFCodeString))
return new StringBuffer();
StringBuffer content = new StringBuffer(((RTFCodeString)obj).getContent());
// Replace \n with \\par
String formattedContent = StringUtils.sub(content.toString(), "\n", "\\par ");
//Replace \r with \\par
formattedContent = StringUtils.sub(formattedContent, "\r", "\\par ");
//Replace \t with \\tab
formattedContent = StringUtils.sub(formattedContent, "\t", "\\tab ");
return new StringBuffer(formattedContent);
}
public Object parseObject(String s, ParsePosition parseposition) {
// TODO Auto-generated method stub
return null;
}
}
Partager