From 7d0d748b58711a28f1af0fabe8d399ebc067b898 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Wed, 28 Nov 2012 09:05:54 +0530 Subject: new feature: meta tag for author info is available. removed: parsers/DocumentName.java (MetaParser supersedes this Parser) added: parsers/MetaParser.java (it looks for meta info and updates them to PresentFile) modified: conversion/ConvertFile.java (now it initiates some of the PresentFile fields to null) parsers/Header.java (Meta field 'author' added) parsers/ParserList.java (added MetaParser, removed DocumentName) status/PresentFile.java (new field 'author') todo (update todo) --- parsers/DocumentName.java | 39 --------------------------------------- parsers/Header.java | 1 + parsers/MetaParser.java | 39 +++++++++++++++++++++++++++++++++++++++ parsers/ParserList.java | 2 +- 4 files changed, 41 insertions(+), 40 deletions(-) delete mode 100644 parsers/DocumentName.java create mode 100644 parsers/MetaParser.java (limited to 'parsers') diff --git a/parsers/DocumentName.java b/parsers/DocumentName.java deleted file mode 100644 index 032d7c0..0000000 --- a/parsers/DocumentName.java +++ /dev/null @@ -1,39 +0,0 @@ -/*+ - * Copyright 2012 rsiddharth - * Email: - * - * This file is part of Scruf. - * - * Scruf is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - - -package scruf.parsers; - -import java.io.*; -import scruf.status.*; - -public class DocumentName implements Parser { - public String parse(String fileContent) { - BufferedReader read = - new BufferedReader(new StringReader(fileContent)); - try { - PresentFile.name = read.readLine(); - }catch(IOException e) { - System.err.println("Error reading string "+e); - } - fileContent = new NullIt().nullIt(fileContent,PresentFile.name); - return fileContent; - } -} diff --git a/parsers/Header.java b/parsers/Header.java index 50575c1..8bde4c8 100644 --- a/parsers/Header.java +++ b/parsers/Header.java @@ -37,6 +37,7 @@ public class Header implements Parser { sbuilder.append(" \n"); sbuilder.append("\n"); sbuilder.append(" \n"); + sbuilder.append("\n"); sbuilder.append(""); sbuilder.append(PresentFile.name); sbuilder.append(""); diff --git a/parsers/MetaParser.java b/parsers/MetaParser.java new file mode 100644 index 0000000..3519cf3 --- /dev/null +++ b/parsers/MetaParser.java @@ -0,0 +1,39 @@ +package scruf.parsers; + +import java.util.regex.*; +import scruf.status.*; + +/** + * this class deals with searching the 'scruffy' marked-up document + * for meta-tag related things. + */ + +public class MetaParser implements Parser { + private Pattern pattern; + private Matcher matcher; + private NullIt nullIt; + public MetaParser() { + pattern = Pattern.compile("^meta\\-(.+?)\\:(.+)", + Pattern.MULTILINE); + nullIt = new NullIt(); + + } + public String parse(String fileContent) { + String value; + matcher = pattern.matcher(fileContent); + while(matcher.find()) { + value = matcher.group(2); + if(matcher.group(1).equals("author")) { + PresentFile.author = value; + } + else if(matcher.group(1).equals("title")) { + PresentFile.name = value; + } + // remove the found 'meta' markup to an empty string. + fileContent = nullIt.nullIt(fileContent,matcher.group()); + // reset the matcher with the new file Content. + matcher.reset(fileContent); + } + return fileContent; + } +} \ No newline at end of file diff --git a/parsers/ParserList.java b/parsers/ParserList.java index 2fba376..a40dcb2 100644 --- a/parsers/ParserList.java +++ b/parsers/ParserList.java @@ -29,8 +29,8 @@ public class ParserList { parsers = new ArrayList(); // add Parsers. NOTE: parser order is significant. parsers.add(new QuoteSpecialText()); - parsers.add(new DocumentName()); parsers.add(new CodeBlocks()); + parsers.add(new MetaParser()); parsers.add(new DocumentDate()); parsers.add(new WordDecoration()); parsers.add(new Headings()); -- cgit v1.2.3