added header file
authorJean-Philippe Orsini <orsinije@fr.ibm.com>
Fri, 1 Jul 2016 12:00:02 +0000 (14:00 +0200)
committerJean-Philippe Orsini <orsinije@fr.ibm.com>
Fri, 1 Jul 2016 12:00:02 +0000 (14:00 +0200)
src/main/java/Main.java

index ea54abe..5ce9912 100644 (file)
@@ -5,9 +5,12 @@ import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.StringWriter;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Properties;
+import java.util.logging.Logger;
 
 import org.asciidoctor.Asciidoctor;
 import org.asciidoctor.Asciidoctor.Factory;
@@ -22,7 +25,8 @@ import com.rometools.rome.io.FeedException;
 import com.rometools.rome.io.SyndFeedOutput;
 
 public class Main {
-       private static String KEY_HTML_HEADER = "html.header";
+       private static Logger LOG = Logger.getLogger(Main.class.getSimpleName());
+       private static String KEY_HTML_HEADER_FILE = "html.header.file";
        
         private static File toHTMLFile(File dir, File adoc) {
                 int idx;
@@ -48,8 +52,20 @@ public class Main {
                return ret;
         }
         
-        private static String getHTMLHeader(Properties props) {
-               return null;
+        private static String getHTMLHeader(Properties props) throws IOException {
+               String fileName;
+               File f;
+               
+               fileName = props.getProperty(KEY_HTML_HEADER_FILE);
+               
+               if (fileName == null) {
+                       LOG.info(KEY_HTML_HEADER_FILE + " is not set");
+                       return null;
+               }
+               
+               f = new File(fileName);
+               return new String(Files.readAllBytes(f.toPath()),
+                                 StandardCharsets.UTF_8);
         }
         
        public static void main(String[] args) throws FileNotFoundException, IOException, FeedException {
@@ -87,6 +103,9 @@ public class Main {
                
                news = new StringBuffer();
                news.append("<html>\n");
+               
+               getHTMLHeader(props);
+               
                news.append("<body>\n");
                for (File adoc: adocs) {
                        if (!adoc.getName().endsWith(".adoc"))
@@ -126,5 +145,6 @@ public class Main {
                output.output(feed, new File(outDir, "feed.xml"));
        
                System.out.println(news.toString());
+               Files.write(new File(outDir, "news.html").toPath(), news.toString().getBytes());
        }
 }
\ No newline at end of file