Coverage Report - org.jtheque.utils.HTMLWriter
 
Classes in this File Line Coverage Branch Coverage Complexity
HTMLWriter
0%
0/26
0%
0/8
1.667
 
 1  
 package org.jtheque.utils;
 2  
 
 3  
 /*
 4  
  * This file is part of JTheque.
 5  
  *
 6  
  * JTheque is free software: you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published by
 8  
  * the Free Software Foundation, either version 3 of the License.
 9  
  *
 10  
  * JTheque is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  
  * GNU General Public License for more details.
 14  
  *
 15  
  * You should have received a copy of the GNU General Public License
 16  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 17  
  */
 18  
 
 19  
 import java.io.Closeable;
 20  
 import java.io.PrintWriter;
 21  
 
 22  
 /**
 23  
  * A HTML Writer.
 24  
  *
 25  
  * @author Baptiste Wicht
 26  
  */
 27  
 public final class HTMLWriter implements Closeable {
 28  
     private final PrintWriter writer;
 29  
 
 30  
     /**
 31  
      * Construct a new HTML Writer.
 32  
      *
 33  
      * @param writer The print writer in which we write.
 34  
      */
 35  
     public HTMLWriter(PrintWriter writer) {
 36  0
         super();
 37  
 
 38  0
         this.writer = writer;
 39  0
     }
 40  
 
 41  
     @Override
 42  
     public void close() {
 43  0
         if (writer != null) {
 44  0
             writer.close();
 45  
         }
 46  0
     }
 47  
 
 48  
     /**
 49  
      * Writer an HTML Header.
 50  
      *
 51  
      * @param title The title of the page.
 52  
      */
 53  
     public void writeHeader(String title) {
 54  0
         writer.println("<html><head><title>" + title + "</title></head><body>");
 55  0
     }
 56  
 
 57  
     /**
 58  
      * Write the footer.
 59  
      */
 60  
     public void writeFooter() {
 61  0
         writer.println("</body></html>");
 62  0
     }
 63  
 
 64  
     /**
 65  
      * Write a Hx title.
 66  
      *
 67  
      * @param h    The level of the title.
 68  
      * @param text The text of the title part.
 69  
      */
 70  
     public void writeHx(int h, String text) {
 71  0
         writer.println("<h" + h + '>' + text + "</h" + h + '>');
 72  0
     }
 73  
 
 74  
     /**
 75  
      * Write a table.
 76  
      *
 77  
      * @param width   The width of the table.
 78  
      * @param borders The border configuration.
 79  
      * @param widths  The widths of the columns.
 80  
      * @param headers The headers of the table.
 81  
      * @param data    The data of the table.
 82  
      */
 83  
     public void writeTable(int width, String borders, int[] widths,
 84  
                            String[] headers, Iterable<Iterable<String>> data) {
 85  0
         writer.println("<table width=\"" + width + "\" border=\"" + borders + "\">");
 86  
 
 87  0
         writer.println("<tr>");
 88  
 
 89  0
         int i = 0;
 90  0
         for (String header : headers) {
 91  0
             writer.println("<th width=\"" + widths[i] + "%\">" + header + "</th>");
 92  0
             i++;
 93  
         }
 94  
 
 95  0
         writer.println("</tr>");
 96  
 
 97  0
         for (Iterable<String> row : data) {
 98  0
             writer.println("<tr>");
 99  
 
 100  0
             for (String column : row) {
 101  0
                 writer.println("<td>" + column + "</td>");
 102  
             }
 103  
 
 104  0
             writer.println("</tr>");
 105  
         }
 106  
 
 107  0
         writer.println("</table>");
 108  0
     }
 109  
 }