From 8bcd7f58acd38f5d5e1731f89be4a10a79d0fdb7 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sat, 23 Jun 2012 22:44:40 +0530 Subject: scruf is "bzr"ed now. --- index/IndexCreator.java | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 index/IndexCreator.java (limited to 'index') 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 -- cgit v1.2.3