1 package org.apache.maven.index;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
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 // text: /org/sonatype/...
39 // tokens: org sonatype
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 // return no newline ;)
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 // TODO Auto-generated method stub
77 return false;
78 }
79
80 public void start( String arg0, TokenStream arg1 )
81 {
82 // TODO Auto-generated method stub
83
84 }
85 }