1 package net.sf.jabref.export.layout.format;
3 import net.sf.jabref.export.layout.AbstractParamLayoutFormatter;
6 import java.util.ArrayList;
9 * Formatter that does regexp replacement.
11 * To use this formatter, a two-part argument must be given. The parts are
12 * separated by a comma. To indicate the comma character, use an escape
15 * The first part is the regular expression to search for. The regular expression
16 * is written normally, without extra escape sequences for backslashes. A description
17 * of Java regular expressions can be found at:
18 * http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html
20 * The second part is the text to replace all matches with.
23 * \format[Replace(and,&)]{\author} :
24 * will output the "author" field after replacing all occurences of "and"
27 * \format[Replace(\s,_)]{\author} :
28 * will output the "author" field after replacing all whitespace
31 * \format[Replace(\,,;)]{\author} :
32 * will output the "author" field after replacing all commas by semicolons.
35 public class Replace extends AbstractParamLayoutFormatter {
37 private String regex = null, replaceWith = null;
40 public void setArgument(String arg) {
41 String[] parts = parseArgument(arg);
44 return; // TODO: too few arguments. Print an error message here?
46 replaceWith = parts[1];
50 public String format(String fieldText) {
52 return fieldText; // TODO: argument missing or invalid. Print an error message here?
53 return fieldText.replaceAll(regex, replaceWith);