Author: jvanzyl Date: Sun Nov 27 06:45:18 2005 New Revision: 349240 URL: http://svn.apache.org/viewcvs?rev=349240&view=rev Log: o some more code submitted by Juan F. Codagnone, which I'm using in a confluence parser.
Added: maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/common/ maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/common/ByLineReaderSource.java (with props) maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/common/ByLineSource.java (with props) Added: maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/common/ByLineReaderSource.java URL: http://svn.apache.org/viewcvs/maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/common/ByLineReaderSource.java?rev=349240&view=auto ============================================================================== --- maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/common/ByLineReaderSource.java (added) +++ maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/common/ByLineReaderSource.java Sun Nov 27 06:45:18 2005 @@ -0,0 +1,158 @@ +/* + * Originaly from org.apache.doxia.module.apt.AptReaderSource. It was modified + * to get unget support + */ +package org.apache.maven.doxia.module.common; + +import java.io.IOException; +import java.io.LineNumberReader; +import java.io.Reader; + +import org.apache.maven.doxia.module.apt.AptParseException; + +/** + * [EMAIL PROTECTED] org.apache.maven.doxia.module.common.ByLineSource} default implementation + */ +public class ByLineReaderSource implements ByLineSource +{ + /** + * reader + */ + private LineNumberReader reader; + /** + * current line number + */ + private int lineNumber; + + /** + * holds the last line returned by getNextLine() + */ + private String lastLine; + + /** + * <code>true</code> if ungetLine() was called and no getNextLine() was + * called + */ + private boolean ungetted = false; + + /** + * Creates the ByLineReaderSource. + * + * @param in real source :) + */ + public ByLineReaderSource( final Reader in ) + { + reader = new LineNumberReader( in ); + + lineNumber = -1; + } + + /** + * @see ByLineSource#getNextLine() + */ + public final String getNextLine() throws AptParseException + { + if ( reader == null ) + { + return null; + } + + if ( ungetted ) + { + ungetted = false; + return lastLine; + } + + String line; + + try + { + line = reader.readLine(); + if ( line == null ) + { + reader.close(); + reader = null; + } + else + { + lineNumber = reader.getLineNumber(); + } + } + catch ( IOException e ) + { + throw new AptParseException( e ); + } + + lastLine = line; + + return line; + } + + /** + * @see ByLineSource#getName() + */ + public final String getName() + { + return ""; + } + + /** + * @see ByLineSource#getLineNumber() + */ + public final int getLineNumber() + { + return lineNumber; + } + + /** + * @see ByLineSource#close() + */ + public final void close() + { + if ( reader != null ) + { + try + { + reader.close(); + } + catch ( IOException ignored ) + { + // ignore + } + } + reader = null; + } + + /** + * @see ByLineSource#ungetLine() + */ + public final void ungetLine() throws IllegalStateException + { + if ( ungetted ) + { + throw new IllegalStateException( + "we support only one level of ungetLine()" ); + } + ungetted = true; + } + + /** + * @see ByLineSource#unget(String) + */ + public final void unget( final String s ) throws IllegalStateException + { + if ( s == null ) + { + throw new IllegalArgumentException( "argument can't be null" ); + } + if ( s.length() == 0 ) + { + // dont do anything + } + else + { + ungetLine(); + lastLine = s; + } + } +} \ No newline at end of file Propchange: maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/common/ByLineReaderSource.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/common/ByLineReaderSource.java ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Added: maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/common/ByLineSource.java URL: http://svn.apache.org/viewcvs/maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/common/ByLineSource.java?rev=349240&view=auto ============================================================================== --- maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/common/ByLineSource.java (added) +++ maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/common/ByLineSource.java Sun Nov 27 06:45:18 2005 @@ -0,0 +1,48 @@ +package org.apache.maven.doxia.module.common; + +import org.apache.maven.doxia.parser.ParseException; + +/** + * The token are the new lines :) + * + * @author Juan F. Codagnone + * @since Nov 4, 2005 + */ +public interface ByLineSource +{ + /** + * @return the next line. <code>null</code> if we reached the end. + * @throws ParseException on I/O error + */ + String getNextLine() throws ParseException; + + /** + * @return the name of the input. could be the filename for example + */ + String getName(); + + /** + * @return the current line number + */ + int getLineNumber(); + + /** + * @throws IllegalStateException if the ungetLine/unget is called more than + * one time without calling getNextLine() + */ + void ungetLine() throws IllegalStateException; + + + /** + * @param s some text to push back to the parser + * @throws IllegalStateException if the ungetLine/unget is called more than + * one time without calling getNextLine() + */ + void unget( String s ) throws IllegalStateException; + + + /** + * close the source ... + */ + void close(); +} Propchange: maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/common/ByLineSource.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/module/common/ByLineSource.java ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision"