From f6f99c41dbd86f85ce816ea8d388e44e04aed6cc Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sat, 27 Oct 2012 16:34:13 +0530 Subject: modified: .bzrignore conversion/ConvertDirectory.java (bug-fix) It is checked whether file "index" is modified since the last conversion. This check was not performed before. conversion/ConvertFile.java Some optimization there. Now we check if the file content is "empty" before we delve into conversion. index/IndexCreator.java # "index" file is created in the directory, if it is not created. # write() renamed to shouldConvert(). The method now returns true when a link is added to 'index' or when the index.html file does not exists. io/ReadFile.java # Exception message for made verbose. todo --- .bzrignore | 1 + conversion/ConvertDirectory.java | 5 +++-- conversion/ConvertFile.java | 44 +++++++++++++++++++++------------------- index/IndexCreator.java | 35 ++++++++++++++++++++++++-------- io/ReadFile.java | 2 +- todo | 7 ------- 6 files changed, 54 insertions(+), 40 deletions(-) diff --git a/.bzrignore b/.bzrignore index e19e389..499a518 100644 --- a/.bzrignore +++ b/.bzrignore @@ -1,2 +1,3 @@ scribble *.class +test diff --git a/conversion/ConvertDirectory.java b/conversion/ConvertDirectory.java index 3cc6a36..3b70a71 100644 --- a/conversion/ConvertDirectory.java +++ b/conversion/ConvertDirectory.java @@ -55,8 +55,9 @@ public class ConvertDirectory { } } - boolean modified = index.write(); - if(modified) + boolean convertIndex = (index.shouldConvert() || + canConvert.check(index.indexFile())); + if(convertIndex) html.convert(index.indexFile()); } } diff --git a/conversion/ConvertFile.java b/conversion/ConvertFile.java index 37da060..6767717 100644 --- a/conversion/ConvertFile.java +++ b/conversion/ConvertFile.java @@ -30,28 +30,30 @@ public class ConvertFile { private List parsers; private ReadFile readFile; public ConvertFile() { - parsers = new ParserList().list(); + parsers = new ParserList().list(); } public void convert(File file) { - /** - * footer is optional, so it is null - * by default. - */ - PresentFile.footer = null; - /** - * takes the present file reference - * for use outside this method. - */ - PresentFile.file = file; - readFile = new ReadFile(file); - String fileContent = readFile.getContent(); - // start conversion. - for(Parser p:parsers) { - fileContent = p.parse(fileContent); - } - - // Write converted file to respective html file. - File outputFile = new File(file.getAbsolutePath()+".html"); - new WriteFile(outputFile,fileContent).write(); + /** + * footer is optional, so it is null + * by default. + */ + PresentFile.footer = null; + /** + * takes the present file reference + * for use outside this method. + */ + PresentFile.file = file; + readFile = new ReadFile(file); + String fileContent = readFile.getContent(); + if(!fileContent.equals("")) { + // start conversion. + for(Parser p:parsers) { + fileContent = p.parse(fileContent); + + } + } + // Write converted file to respective html file. + File outputFile = new File(file.getAbsolutePath()+".html"); + new WriteFile(outputFile,fileContent).write(); } } diff --git a/index/IndexCreator.java b/index/IndexCreator.java index fc469ce..f86f03a 100644 --- a/index/IndexCreator.java +++ b/index/IndexCreator.java @@ -33,13 +33,20 @@ public class IndexCreator { // set to true, if index file is modified. boolean modified = false; public IndexCreator(File directory) { - this.directory = directory; - index = new File(directory,"index"); - indexContent = new StringBuilder(); - if(index.exists()) { - indexContent.append(new ReadFile(index). - getContent()); - } + this.directory = directory; + index = new File(directory,"index"); + indexContent = new StringBuilder(); + if(index.exists()) { + indexContent.append(new ReadFile(index). + getContent()); + }else { + try { + index.createNewFile(); + }catch(IOException e) { + throw new RuntimeException("Unable to create file: "+ + index.getAbsolutePath(),e); + } + } } public void add(File file) { String fileName = file.getName(); @@ -53,10 +60,20 @@ public class IndexCreator { modified=true; } } - public boolean write() { + public boolean shouldConvert() { + // we assume that index.html exists. + boolean indexHTMLExists=true; if(modified) new WriteFile(index,indexContent.toString()).write(); - return modified; + // Check for this existence of index.html. + if(!(new File(directory,"index.html").exists())) { + indexHTMLExists=false; + } + /** + * returns true either when 'index' is modified or + * when index.html does not exists. + */ + return (modified || !indexHTMLExists); } public File indexFile() { return index; diff --git a/io/ReadFile.java b/io/ReadFile.java index beccdc3..2607b16 100644 --- a/io/ReadFile.java +++ b/io/ReadFile.java @@ -44,7 +44,7 @@ public class ReadFile { new FileReader(file)); }catch(FileNotFoundException e) { throw new RuntimeException("Unable to open file :" - +file.getName()); + +file.getAbsolutePath()); } String line; StringBuilder sbuilder = new StringBuilder(); diff --git a/todo b/todo index d3c02c7..42ffce6 100644 --- a/todo +++ b/todo @@ -1,10 +1,3 @@ -# Write a introductory page for scruf. - + A scruffy begining. - + Liberated. - + Download. - + Rebuke, Critique, etc - + Improve. - # Test it by generating your _full_ homepage using scruf. # Documentation on how to use scruf. -- cgit v1.2.3