1 package org.apache.maven.doxia.module.apt;
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 java.io.IOException;
23 import java.io.LineNumberReader;
24 import java.io.Reader;
25
26 import org.codehaus.plexus.util.IOUtil;
27
28 /**
29 * Reader for apt source documents.
30 *
31 * @version $Id: AptReaderSource.java 746982 2009-02-23 12:25:50Z vsiveton $
32 */
33 public class AptReaderSource
34 implements AptSource
35 {
36 /** A reader. */
37 private LineNumberReader reader;
38
39 /** lineNumber. */
40 private int lineNumber;
41
42 /**
43 * Constructor: intialize reader.
44 *
45 * @param in the reader.
46 */
47 public AptReaderSource( Reader in )
48 {
49 reader = new LineNumberReader( in );
50
51 lineNumber = -1;
52 }
53
54 /** {@inheritDoc} */
55 public String getNextLine()
56 throws AptParseException
57 {
58 if ( reader == null )
59 {
60 return null;
61 }
62
63 String line;
64
65 try
66 {
67 line = reader.readLine();
68 if ( line == null )
69 {
70 reader.close();
71 reader = null;
72 }
73 else
74 {
75 lineNumber = reader.getLineNumber();
76 }
77 }
78 catch ( IOException e )
79 {
80 // TODO handle column number
81 throw new AptParseException( "IOException: " + e.getMessage(), e, lineNumber, -1 );
82 }
83
84 return line;
85 }
86
87 /** {@inheritDoc} */
88 public String getName()
89 {
90 return "";
91 }
92
93 /** {@inheritDoc} */
94 public int getLineNumber()
95 {
96 return lineNumber;
97 }
98
99 /**
100 * Closes the reader associated with this AptReaderSource.
101 */
102 public void close()
103 {
104 IOUtil.close( reader );
105 reader = null;
106 }
107 }