diff options
author | rsiddharth <rsiddharth@ninthfloor.org> | 2012-06-23 22:44:40 +0530 |
---|---|---|
committer | rsiddharth <rsiddharth@ninthfloor.org> | 2012-06-23 22:44:40 +0530 |
commit | 8bcd7f58acd38f5d5e1731f89be4a10a79d0fdb7 (patch) | |
tree | 6c1d4dfc97d77230ecf95d4e0f8b4fe1cde5b739 /index/IndexCreator.java |
scruf is "bzr"ed now.
Diffstat (limited to 'index/IndexCreator.java')
-rw-r--r-- | index/IndexCreator.java | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/index/IndexCreator.java b/index/IndexCreator.java new file mode 100644 index 0000000..76f8ebc --- /dev/null +++ b/index/IndexCreator.java @@ -0,0 +1,53 @@ +package scruf.index; + +import java.io.*; +import java.util.regex.*; +import scruf.io.*; +import scruf.conversion.*; + +public class IndexCreator { + private File directory; + private File index; + private StringBuilder indexContent; + // 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()); + } + } + public void add(File file) { + String fileName = file.getName(); + if(shouldAdd(fileName)) { + System.out.println("New Entry: "+fileName); + indexContent.append("[[./"); + indexContent.append(fileName+".html"); + indexContent.append("|"); + indexContent.append(PresentFile.name); + indexContent.append("]]\n"); + modified=true; + } + } + public boolean write() { + if(modified) + new WriteFile(index,indexContent.toString()).write(); + return modified; + } + public File indexFile() { + return index; + } + private boolean shouldAdd(String fileName) { + String regex = ".*"+fileName+".*"; + // checks if fileName is already there in index. + boolean check1 = !(Pattern.compile(regex). + matcher(indexContent.toString()).find()); + // checks if fileName is index itself. + boolean check2 = !(Pattern.matches(fileName,"index")); + boolean add = (check1 && check2); + return add; + } +}
\ No newline at end of file |