CleanStringAccessor.java
01 /*
02  *  Copyright (c) 1995-2010, The University of Sheffield. See the file
03  *  COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
04  *
05  *  This file is part of GATE (see http://gate.ac.uk/), and is free
06  *  software, licenced under the GNU Library General Public License,
07  *  Version 2, June 1991 (in the distribution as file licence.html,
08  *  and also available at http://gate.ac.uk/gate/licence.html).
09  *
10  *  Eric Sword, 09/03/08
11  *
12  *  $Id$
13  */
14 package gate.jape.constraint;
15 
16 import gate.*;
17 
18 /**
19  * Accessor that returns the underlying string of an annotation in a document.
20  * The string is cleaned up a bit as follows:
21  <code>
22  * cleanString = string.replaceAll("\\s+", " ").trim();
23  </code>
24  *
25  @version $Revision$
26  @author esword
27  */
28 public class CleanStringAccessor extends StringAccessor {
29   /**
30    * Return the cleaned up underlying string for the annotation. Context
31    * must be a {@link Document} or an {@link AnnotationSet} which points
32    * to the document.
33    */
34   public Object getValue(Annotation annot, AnnotationSet context) {
35     String retVal = (String)super.getValue(annot, context);
36     if (retVal != null)
37       retVal = retVal.replaceAll("\\s+"" ").trim();
38 
39     return retVal;
40   }
41 
42   /**
43    * Always returns "cleanString", the name of the meta-property which this
44    * accessor provides.
45    */
46   @Override
47   public Object getKey() {
48     return "cleanString";
49   }
50 
51 }