View Javadoc

1   package org.paneris.bibliomania;
2   
3   import org.melati.poem.ValidationPoemException;
4   import org.paneris.bibliomania.generated.BookFormatBase;
5   
6   import org.apache.oro.text.regex.MalformedPatternException;
7   import org.apache.oro.text.regex.Perl5Compiler;
8   import org.apache.oro.text.regex.Perl5Pattern;
9   
10  public class BookFormat extends BookFormatBase {
11    public BookFormat() {}
12  
13    private Perl5Pattern regexp = null;
14    private boolean regexpValid = true;
15  
16    public void setDescriptionregexp(String re) {
17      try {
18        Perl5Pattern newRegexp = (Perl5Pattern)new Perl5Compiler().compile(
19                                     re, Perl5Compiler.CASE_INSENSITIVE_MASK);
20        super.setDescriptionregexp(re);
21        regexp = newRegexp;
22        regexpValid = true;
23      }
24      catch (MalformedPatternException e) {
25        throw new ValidationPoemException(null, e);
26      }
27    }
28  
29    public Perl5Pattern getDescriptionPerl5Regexp() {
30      if (!regexpValid)
31        return null;
32  
33      if (regexp != null) 
34        return regexp;
35      else
36        try {
37          regexp =
38              (Perl5Pattern)new Perl5Compiler().compile(
39                  getDescriptionregexp(), Perl5Compiler.CASE_INSENSITIVE_MASK);
40          regexpValid = true;
41          return regexp;
42        }
43        catch (MalformedPatternException e) {
44          regexpValid = false;
45          return regexp;
46        }
47    }
48  }