net.haefelingerit.tagmod
Class Parser

java.lang.Object
  extended by net.haefelingerit.tagmod.Parser

public class Parser
extends Object

This class implements a parser to analyze a log file containing tag operations.

The format of the file is rather simple:

The following example shows such a line

 0x1 p="foo/bar" o="add" t="r-1.0" D="2008-12-20 
 13:29:43 UTC" U="alibaba"
 

The following code snippet shows a typical usage pattern of this class:
    parser.open(file);
    while (parser.advance())
      if (parser.match(last, now)) {
         // do something with parser.m 
      }
    parser.close();
 

Author:
geronimo

Field Summary
protected  boolean cont
          A flag to indicate whether it makes sense to read further.
protected  String line
          The current line - or null if no line has been read so far.
protected  int lineno
          The current line.
protected  Matcher m
          A line matcher.
protected  String pname
          The project name.
protected  String re_tagaction
          The regular expression to match tag actions.
protected  String re_tagvalue
          The regular expression to match tag values.
protected  BufferedReader reader
          The underlying text stream
protected  Pattern regex
          The overall regular expression a line must comply to.
protected  SimpleDateFormat sdf
          The standard date format.
 
Constructor Summary
Parser()
           
 
Method Summary
 boolean advance()
          Digest on further line from the log file.
 void close()
          Tell the parser to close the underlying reader.
protected  boolean match(Date last, Date now)
          Checks whether the current line matches.
protected  Date mkdate(String s)
          A helper method to translate a date string into a date object.
 void open(File file)
          Tell this parser to use this file for reading.
static String quote(String s)
          A helper method similar to Pattern.quote(String) found in Java 5.
 void reset()
          A method to reset the parser in its initial state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lineno

protected int lineno
The current line.


cont

protected boolean cont
A flag to indicate whether it makes sense to read further.


reader

protected BufferedReader reader
The underlying text stream


line

protected String line
The current line - or null if no line has been read so far.


sdf

protected SimpleDateFormat sdf
The standard date format.


m

protected Matcher m
A line matcher. Use this matcher to retrieve individual fields.


re_tagaction

protected String re_tagaction
The regular expression to match tag actions.


re_tagvalue

protected String re_tagvalue
The regular expression to match tag values.


pname

protected String pname
The project name.


regex

protected Pattern regex
The overall regular expression a line must comply to.

Constructor Detail

Parser

public Parser()
Method Detail

reset

public void reset()
           throws Exception
A method to reset the parser in its initial state.

Throws:
Exception

quote

public static String quote(String s)
A helper method similar to Pattern.quote(String) found in Java 5. In fact this method exists only to be Java 1.4 compatible.


advance

public boolean advance()
                throws IOException
Digest on further line from the log file.

Returns:
true if reading on further line was successful.
Throws:
IOException - if reading underlying reader or stream is not possible.

open

public void open(File file)
Tell this parser to use this file for reading. If opening is not possible an error is written to the log stream.

Parameters:
file - not null

close

public void close()
Tell the parser to close the underlying reader.


mkdate

protected Date mkdate(String s)
A helper method to translate a date string into a date object. The format of the date string is expected to be YYYY-MM-DD HH:MM:SS UTC. If translation is not possible, null is returned.

Parameters:
s - not null

match

protected boolean match(Date last,
                        Date now)
Checks whether the current line matches.



Copyright © 2009. All Rights Reserved.