From ceed73fa063ffb3b72d21c8a8800122c115acc58 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sat, 10 Nov 2012 11:29:31 +0530 Subject: marked-up files should have a '.scruffy' extension from now on. This commit is an un-stable commit. It has bugs. removed: io/PresentFile.java (moved to status/PresentFile.java) added: conversion/CreateHtmlFile.java (creates a corresponding '.html' file for a given '.scruffy' marked-up file) (needs some fine-tuning) status/PresentFile.java (see above) modified: conversion/ConvertFile.java (CreatHtmlFile object takes care of producing a corresponding html 'File') conversion/FileSieve.java (regex modified to reflect the '.scruffy' extension) index/IndexCreator.java (edits to reflect the '.scruffy' extension) parsers/BackButton.java (edit to reflect the '.scruffy' extension) parsers/DocumentName.java (edit to reflect the package change for PresentFile class) parsers/Header.java (edit to reflect the package change for PresentFile class) todo (updated todo) --- conversion/ConvertFile.java | 8 +++++--- conversion/CreateHtmlFile.java | 22 ++++++++++++++++++++++ conversion/FileSieve.java | 14 ++++++++++++-- 3 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 conversion/CreateHtmlFile.java (limited to 'conversion') diff --git a/conversion/ConvertFile.java b/conversion/ConvertFile.java index 4f2d7bd..5065ad0 100644 --- a/conversion/ConvertFile.java +++ b/conversion/ConvertFile.java @@ -25,12 +25,15 @@ import scruf.io.*; import scruf.parsers.*; import java.util.*; import java.io.*; +import scruf.status.*; public class ConvertFile { private List parsers; private ReadFile readFile; + private CreateHtmlFile htmlFile; public ConvertFile() { parsers = new ParserList().list(); + htmlFile = new CreateHtmlFile(); } public void convert(File file) { /** @@ -47,8 +50,7 @@ public class ConvertFile { } } - // Write converted file to respective html file. - File outputFile = new File(file.getAbsolutePath()+".html"); - new WriteFile(outputFile,fileContent).write(); + // Write to corresponding html file. + new WriteFile(htmlFile.create(),fileContent).write(); } } diff --git a/conversion/CreateHtmlFile.java b/conversion/CreateHtmlFile.java new file mode 100644 index 0000000..ecd86c1 --- /dev/null +++ b/conversion/CreateHtmlFile.java @@ -0,0 +1,22 @@ +package scruf.conversion; + +import java.io.*; +import java.util.regex.*; +import scruf.status.*; + +public class CreateHtmlFile { + private Pattern pattern = Pattern.compile("(.+?\\.)scruffy"); + private Matcher matcher; + public File create() { + File htmlFile=null; + matcher = pattern.matcher(PresentFile.file.getName()); + if(matcher.find()) { + htmlFile = new File(PresentFile.file.getParentFile(), + matcher.group(1)+"html"); + }else { + System.err.println("ERROR: something wrong with scruf: unable to create html file"+ + " for "+PresentFile.file.getName()); + } + return htmlFile; + } +} \ No newline at end of file diff --git a/conversion/FileSieve.java b/conversion/FileSieve.java index 8d53648..3571433 100644 --- a/conversion/FileSieve.java +++ b/conversion/FileSieve.java @@ -28,9 +28,19 @@ public class FileSieve implements FileFilter { // this method return true, if this file doesn't represent // a html file. public boolean accept(File pathname) { - Pattern pattern = Pattern.compile("(.+\\.(html|png|jpg|css|tar|ttf))|(.+?\\~)|(index)|(\\..+)|(\\#.+?\\#)"); + // check if this is a directory, if yes, accept immediately. + if(pathname.isDirectory() && (!pathname.isHidden())) { + return true; + } + Pattern pattern = Pattern.compile(".+?\\.scruffy$"); + Pattern indexPattern = Pattern.compile("^index\\.scruffy$"); Matcher matcher = pattern.matcher(pathname.getName()); + Matcher indexMatcher = indexPattern.matcher(pathname.getName()); boolean bool = matcher.find(); - return !bool; + if(bool) { + // don't 'accept' if the file is 'index.scruffy'. + bool = !(indexMatcher.find()); + } + return bool; } } -- cgit v1.2.3