View Javadoc

1   /*  Copyright 2004 Ryan Ackley
2    *
3    *  Licensed under the Apache License, Version 2.0 (the "License");
4    *  you may not use this file except in compliance with the License.
5    *  You may obtain a copy of the License at
6    *
7    *      http://www.apache.org/licenses/LICENSE-2.0
8    *
9    *  Unless required by applicable law or agreed to in writing, software
10   *  distributed under the License is distributed on an "AS IS" BASIS,
11   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   *  See the License for the specific language governing permissions and
13   *  limitations under the License.
14   */
15  package org.apache.tika.parser.microsoft;
16  
17  
18  /**
19   * This class acts as a StringBuffer for text from a word document. It allows
20   * processing of character before they
21   * 
22   */
23  public class WordTextBuffer
24  {
25    Appendable _buf;
26    boolean _hold;
27  
28    public WordTextBuffer(Appendable appendable)
29    {
30      _buf = appendable;
31      _hold = false;
32    }
33  
34    public void append(String text) throws java.io.IOException
35    {
36      char[] letters = text.toCharArray();
37      for (int x = 0; x < letters.length; x++)
38      {
39        switch(letters[x])
40        {
41          case '\r':
42            _buf.append("\r\n");
43            break;
44          case 0x13:
45            _hold = true;
46            break;
47          case 0x14:
48            _hold = false;
49            break;
50          default:
51            if (!_hold)
52            {
53              _buf.append(letters[x]);
54            }
55            break;
56        }
57      }
58    }
59  
60  }