1 package org.apache.maven.index;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.lucene.analysis.Token;
23 import org.apache.lucene.analysis.TokenStream;
24 import org.apache.lucene.search.highlight.Fragmenter;
25
26 public class OneLineFragmenter
27 implements Fragmenter
28 {
29 private String text;
30
31 public void start( String originalText )
32 {
33 setText( originalText );
34 }
35
36 public boolean isNewFragment( Token nextToken )
37 {
38
39
40 boolean result =
41 isNewline( getChar( nextToken.startOffset() - 1 ) ) || isNewline( getChar( nextToken.startOffset() - 2 ) );
42
43 return result;
44 }
45
46 protected boolean isNewline( char c )
47 {
48 return c == '\n';
49 }
50
51 protected char getChar( int pos )
52 {
53 if ( ( pos < 0 ) || ( pos > ( getText().length() - 1 ) ) )
54 {
55
56 return ' ';
57 }
58 else
59 {
60 return getText().charAt( pos );
61 }
62 }
63
64 public String getText()
65 {
66 return text;
67 }
68
69 public void setText( String text )
70 {
71 this.text = text;
72 }
73
74 public boolean isNewFragment()
75 {
76
77 return false;
78 }
79
80 public void start( String arg0, TokenStream arg1 )
81 {
82
83
84 }
85 }