package journal.reader; import java.io.FileReader; import java.io.IOException; import java.io.Reader; import java.text.ParseException; import journal.action.Action; import journal.action.PrintAction; public class JournalParser { private Tokenizer tokenizer; private Reader reader; private Options options; public JournalParser(Reader reader, Options options) { this.reader = reader; this.tokenizer = new Tokenizer(this.reader); this.options = options; } public JournalEntry parseNext() throws ParseException, IOException { Token startToken = tokenizer.nextToken(); if (startToken == null) return null; if (startToken.getType() == Token.Type.START_TOKEN) { if (ActionType.TransactionAction.contains(startToken.getAction()) ) { Token pidToken = tokenizer.nextToken(); Token timestampToken = tokenizer.nextToken(); return new TransactionJournalEntry(startToken, pidToken, timestampToken); } else if (startToken.getAction() == ActionType.NOTE_MARKER) { Token typeToken = tokenizer.nextToken(); Token timestampToken = tokenizer.nextToken(); Token versionToken = tokenizer.nextToken(); Token[] intToken = new Token[5]; for( int i = 0; i < 5; i++) { intToken[i] = tokenizer.nextToken(); } Token[] stringToken = new Token[5]; for( int i = 0; i < 5; i++) { stringToken[i] = tokenizer.nextToken(); } NoteJournalEntry noteEntry = new NoteJournalEntry(startToken, typeToken, timestampToken, versionToken, intToken, stringToken); if( noteEntry.getJournalType() == NoteJournalEntry.JournalType.CHECKPOINT_HEADER ) { int flag = noteEntry.getIntegerFlags()[0]; if( (flag & NoteJournalEntry.JournalDBFlags.C0.flag) > 0) { // case sensitive if( options.isCaseInsensitive() ) { System.err.println("Checkpoint is case-sensitve, but insensitive option chosen. Changing to case-sensitive"); options.setCaseInsensitive(false); } } else if( (flag & NoteJournalEntry.JournalDBFlags.C1.flag) > 0) { // case sensitive if( ! options.isCaseInsensitive() ) { System.err.println("Checkpoint is case insensitve, but sensitive option chosen."); System.err.println("Changing to case insensitive"); options.setCaseInsensitive(true); } } if( (flag & NoteJournalEntry.JournalDBFlags.UNICODE.flag) > 0) { if( ! options.isUnicode() ) { System.err.println("Checkpoint has Unicode enabled, setting option"); options.setUnicode(true); } } else { if( options.isUnicode() ) { System.err.println("Checkpoint does not have Unicode enabled, unsetting option"); options.setUnicode(false); } } } return noteEntry; } else if (startToken.getAction() == ActionType.DELETE_MARKER) { Token nameToken = tokenizer.nextToken(); Token revToken = tokenizer.nextToken(); Token typeToken = tokenizer.nextToken(); Token cmdToken = tokenizer.nextToken(); Token filespecToken = tokenizer.nextToken(); DeleteJournalEntry journalEntry = new DeleteJournalEntry(startToken, nameToken, revToken, typeToken, cmdToken, filespecToken); return journalEntry; } else { Token versionToken = tokenizer.nextToken(); if (versionToken.getType() == Token.Type.INTEGER_TOKEN) { Token tableToken = tokenizer.nextToken(); if (tableToken.getType() == Token.Type.STRING_TOKEN) { DataJournalEntry journalEntry = new DataJournalEntry(startToken, versionToken, tableToken); Token token = tokenizer.nextToken(); while (token != null && token.getType() != Token.Type.START_TOKEN) { try { journalEntry.addArgument(token); } catch (RuntimeException e) { e.printStackTrace(); System.out.println("Token is " + token); throw new ParseException("Trouble : " + token, token.getLine()); } token = tokenizer.nextToken(); } if (token != null) tokenizer.pushToken(token); // need to return start token for next entry return journalEntry; } else { throw new ParseException("Illegal tableToken : " + tableToken, tableToken.getLine()); } } else { throw new ParseException("Illegal versionToken : " + versionToken, versionToken.getLine()); } } } else { throw new ParseException("Illegal StartToken : " + startToken, startToken.getLine()); } } public static void main(String[] args) { if (args.length < 1) { System.err.println("Usage : JournalParser journalFileName"); System.exit(1); } String fileName = args[0]; Options options = new Options(); options.setOutputStream(System.out); Action action = new PrintAction(); action.setDefaultOptions(options); while (true) { try { Reader fileReader = new FileReader(fileName); JournalParser parser = new JournalParser(fileReader, options); JournalEntry entry = parser.parseNext(); while (entry != null) { entry.invokeAction(action); entry = parser.parseNext(); } break; } catch (Exception e) { e.printStackTrace(); break; } } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#6 | 8200 | Sven Erik Knop |
JournalReader can now process delete records (@dl@). Also fixed processing of type 12 note records = journaldbchecksum |
||
#5 | 8168 | Sven Erik Knop |
Fixed JournalParser main function. PrintAction needs default options to work. |
||
#4 | 8020 | Sven Erik Knop | Replace public Option attributes with setters and getters. | ||
#3 | 8019 | Sven Erik Knop | Safety checks for case-sensitivity and Unicode, now provided in the checkpoint. | ||
#2 | 7874 | Sven Erik Knop | Upgrade to 2010.2 including new JournalNotes. | ||
#1 | 7589 | Sven Erik Knop | Rescue attempt to recover missing files from the JournalReader | ||
//guest/sven_erik_knop/JournalReader/src/journal/reader/JournalParser.java | |||||
#2 | 7375 | Sven Erik Knop |
Major update of the JournalReader. Complete rewrite of the command line parsing Change in the options parsing within the journal reader New SQLLoader action. Currently only against MySQL (needs MySQL JDBC driver) with fixed database and user name. This will be replaced by a config file at some stage. |
||
#1 | 7374 | Sven Erik Knop | Rename/move file(s) - correct location for Eclipse project | ||
//guest/sven_erik_knop/JournalReader/journal/reader/JournalParser.java | |||||
#1 | 6467 | Sven Erik Knop |
Added JournalReader, a Java library of useful tools to read and process checkpoints and journals. Added are a readme.txt to explain some details, and a jar file that contains the compiled class files. The programs will need Java 1.6 to run. |