KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > susebox > jtopas > spi > StandardSeparatorHandler


1 /*
2  * StandardSeparatorHandler.java: Implementation of the SeparatorHandler
3  *
4  * Copyright (C) 2002 Heiko Blau
5  *
6  * This file belongs to the JTopas Library.
7  * JTopas is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or (at your
10  * option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE.
15  * See the GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License along
18  * with JTopas. If not, write to the
19  *
20  * Free Software Foundation, Inc.
21  * 59 Temple Place, Suite 330,
22  * Boston, MA 02111-1307
23  * USA
24  *
25  * or check the Internet: http://www.fsf.org
26  *
27  * Contact:
28  * email: heiko@susebox.de
29  */

30
31 package de.susebox.jtopas.spi;
32
33
34 //-----------------------------------------------------------------------------
35
// Imports
36
//
37
import de.susebox.jtopas.TokenizerProperty;
38 import de.susebox.jtopas.TokenizerProperties;
39 import de.susebox.jtopas.Flags;
40
41
42 //-----------------------------------------------------------------------------
43
// class StandardSeparatorHandler
44
//
45

46 /**<p>
47  * Simple implementation of the {@link SeparatorHandler} interface. This class
48  * works only with the {@link de.susebox.jtopas.TokenizerProperties} interface
49  * methods and is aware of changes in these properties. It does not cache any
50  * information and is therefore a more or less slow way to handle separators.
51  *</p><p>
52  * This class is a bridge between arbitrary {@link de.susebox.jtopas.Tokenizer}
53  * implementations using the SPI interface {@link SeparatorHandler} and any
54  * {@link de.susebox.jtopas.TokenizerProperties} implementation that does not
55  * implement the <code>SeparatorHandler</code> interface itself.
56  *</p>
57  *
58  * @see SeparatorHandler
59  * @see de.susebox.jtopas.Tokenizer
60  * @see de.susebox.jtopas.TokenizerProperties
61  * @author Heiko Blau
62  */

63 public class StandardSeparatorHandler implements SeparatorHandler {
64   
65   /**
66    * The constructor takes the {@link de.susebox.jtopas.TokenizerProperties}
67    * that provide the separators.
68    *
69    * @param props the {@link de.susebox.jtopas.TokenizerProperties} to take the
70    * separators from
71    */

72   public StandardSeparatorHandler(TokenizerProperties props) {
73     _properties = props;
74   }
75   
76   /**
77    * This method checks if the character is a separator.
78    *
79    * @param testChar check this character
80    * @return <code>true</code> if the given character is a separator,
81    * <code>false</code> otherwise
82    */

83   public boolean isSeparator(char testChar) {
84     String JavaDoc separators;
85     
86     if (_properties != null && (separators = _properties.getWhitespaces()) != null) {
87       if (_properties.isFlagSet(Flags.F_NO_CASE)) {
88         return separators.toLowerCase().indexOf(Character.toLowerCase(testChar)) >= 0;
89       } else {
90         return separators.indexOf(testChar) >= 0;
91       }
92     } else {
93       return false;
94     }
95   }
96
97   
98   //---------------------------------------------------------------------------
99
// Members
100
//
101

102   /**
103    * The {@link TokenizerProperties} that provide the separators and the
104    * control flags.
105    */

106   private TokenizerProperties _properties = null;
107 }
108
Popular Tags