diff options
Diffstat (limited to 'conversion')
-rw-r--r-- | conversion/CanConvert.java | 3 | ||||
-rw-r--r-- | conversion/ConvertDirectory.java | 25 | ||||
-rw-r--r-- | conversion/ConvertFile.java | 41 | ||||
-rw-r--r-- | conversion/CreateHtmlFile.java | 51 | ||||
-rw-r--r-- | conversion/FileSieve.java | 14 | ||||
-rw-r--r-- | conversion/ignore/Ignored.java | 54 |
6 files changed, 159 insertions, 29 deletions
diff --git a/conversion/CanConvert.java b/conversion/CanConvert.java index baf62c5..8f704e7 100644 --- a/conversion/CanConvert.java +++ b/conversion/CanConvert.java @@ -25,9 +25,10 @@ import java.io.*; public class CanConvert { private File htmlFile; + private CreateHtmlFile createHtml = new CreateHtmlFile(); private long modified1, modified2; public boolean check(File file) { - htmlFile = new File(file.getAbsolutePath()+".html"); + htmlFile = createHtml.create(file); modified1 = file.lastModified(); modified2 = htmlFile.lastModified(); if(modified1 > modified2) { diff --git a/conversion/ConvertDirectory.java b/conversion/ConvertDirectory.java index 3cc6a36..a5717bb 100644 --- a/conversion/ConvertDirectory.java +++ b/conversion/ConvertDirectory.java @@ -23,6 +23,8 @@ package scruf.conversion; import java.io.*; import scruf.index.*; +import scruf.status.*; +import scruf.conversion.ignore.*; public class ConvertDirectory { private ConvertFile html; @@ -38,25 +40,38 @@ public class ConvertDirectory { " No conversion done on."); return; } + // Ignored object maintains a list of 'ignored' sub-directories + // in this directory. + Ignored ignored = new Ignored(directory); // index creator for the present directory. IndexCreator index = new IndexCreator(directory); // iterate through the directory. + System.out.println("Current Directory: "+directory.getAbsolutePath()); for(File file:directory.listFiles(new FileSieve())) { if(file.isFile()) { can = canConvert.check(file); if(can) { - System.out.println("Converting..."+file.getName()); + System.out.println("Converting..."+file.getAbsolutePath()); html.convert(file); index.add(file); } } else if(file.isDirectory()) { - this.convert(file); + // Perform conversion, only if, directory + // is not a ignored directory. + if(!ignored.ignored(file)) { + ++DirectoryInfo.level; + this.convert(file); + } } } - - boolean modified = index.write(); - if(modified) + boolean convertIndex = (index.shouldConvert() || + canConvert.check(index.indexFile())); + if(convertIndex) { + System.out.println("Converting..."+index.indexFile().getAbsolutePath()); html.convert(index.indexFile()); + } + --DirectoryInfo.level; } + } diff --git a/conversion/ConvertFile.java b/conversion/ConvertFile.java index 37da060..5065ad0 100644 --- a/conversion/ConvertFile.java +++ b/conversion/ConvertFile.java @@ -25,33 +25,32 @@ import scruf.io.*; import scruf.parsers.*; import java.util.*; import java.io.*; +import scruf.status.*; public class ConvertFile { private List<Parser> parsers; private ReadFile readFile; + private CreateHtmlFile htmlFile; public ConvertFile() { - parsers = new ParserList().list(); + parsers = new ParserList().list(); + htmlFile = new CreateHtmlFile(); } 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(); + /** + * 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 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..729b3cf --- /dev/null +++ b/conversion/CreateHtmlFile.java @@ -0,0 +1,51 @@ +/*+ + * Copyright 2012 rsiddharth + * Email: <rsiddharth@ninthfloor.org> + * + * 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 <http://www.gnu.org/licenses/>. + */ + + +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; + private File htmlFile=null; + /** + * This method uses PresentFile.file as the 'file' for + * which a corresponding 'htmlFile' has to be created. + */ + public File create() { + return create(PresentFile.file); + } + public File create(File file) { + htmlFile=null; + matcher = pattern.matcher(file.getName()); + if(matcher.find()) { + htmlFile = new File(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; + } +} 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; } } diff --git a/conversion/ignore/Ignored.java b/conversion/ignore/Ignored.java new file mode 100644 index 0000000..a13434e --- /dev/null +++ b/conversion/ignore/Ignored.java @@ -0,0 +1,54 @@ +/*+ + * Copyright 2012 rsiddharth + * Email: <rsiddharth@ninthfloor.org> + * + * 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 <http://www.gnu.org/licenses/>. + */ + + +package scruf.conversion.ignore; + +import java.io.*; +import scruf.io.*; + +public class Ignored { + private String ignoredList[]; + public Ignored(File directory) { + File ignoredFile = new File(directory,".ignored"); + if(ignoredFile.exists()) { + ignoredList = new ReadFile(ignoredFile).split("\n"); + } + } + public boolean ignored(File subdirectory) { + boolean ignored = false; + if(ignoredList!=null) { + for(String dir:ignoredList) { + if(subdirectory.getName().matches(dir)) { + System.out.println("Ignoring Directory: "+ + subdirectory.getAbsolutePath()); + ignored = true; + break; + } + } + } + return ignored; + } +} + +/** + CVS/ + /home/rsd/projects/scruf/www/CVS/ + */ |