Coverage Report - org.apache.maven.doxia.module.itext.ITextHeader
 
Classes in this File Line Coverage Branch Coverage Complexity
ITextHeader
78%
18/23
50%
5/10
2,286
 
 1  
 package org.apache.maven.doxia.module.itext;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.text.ParseException;
 23  
 import java.text.SimpleDateFormat;
 24  
 
 25  
 import java.util.Date;
 26  
 
 27  
 /**
 28  
  * Header object containing meta-informations.
 29  
  *
 30  
  * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
 31  
  * @version $Id: ITextHeader.java 763762 2009-04-09 18:19:56Z ltheussl $
 32  
  */
 33  
 public class ITextHeader
 34  
 {
 35  
     private String title;
 36  
 
 37  
     private StringBuffer authors;
 38  
 
 39  
     private Date date;
 40  
 
 41  
     /**
 42  
      * Default constructor
 43  
      */
 44  
     public ITextHeader()
 45  8
     {
 46  
         // nop
 47  8
     }
 48  
 
 49  
     /**
 50  
      * Add a title to the Document
 51  
      *
 52  
      * @param title1 the title.
 53  
      */
 54  
     public final void setTitle( String title1 )
 55  
     {
 56  4
         this.title = title1;
 57  4
     }
 58  
 
 59  
     /**
 60  
      * Get the title
 61  
      *
 62  
      * @return title as String
 63  
      */
 64  
     public String getTitle()
 65  
     {
 66  40
         if ( this.title == null )
 67  
         {
 68  0
             return "";
 69  
         }
 70  
 
 71  40
         return this.title;
 72  
     }
 73  
 
 74  
     /**
 75  
      * Add a new author
 76  
      *
 77  
      * @param author the author.
 78  
      */
 79  
     public void addAuthor( String author )
 80  
     {
 81  4
         if ( this.authors == null )
 82  
         {
 83  4
             this.authors = new StringBuffer();
 84  
         }
 85  
         else
 86  
         {
 87  0
             this.authors.append( ", " );
 88  
         }
 89  
 
 90  4
         this.authors.append( author );
 91  4
     }
 92  
 
 93  
     /**
 94  
      * Get the authors
 95  
      *
 96  
      * @return the authors as String
 97  
      */
 98  
     public String getAuthors()
 99  
     {
 100  4
         if ( ( this.authors == null ) || ( this.authors.length() == 0 ) )
 101  
         {
 102  0
             return System.getProperty( "user.name" );
 103  
         }
 104  
 
 105  4
         return this.authors.toString();
 106  
     }
 107  
 
 108  
     /**
 109  
      * Add a date to the document
 110  
      *
 111  
      * @param date1 a date as String
 112  
      */
 113  
     public void setDate( String date1 )
 114  
     {
 115  
         try
 116  
         {
 117  4
             this.date = new SimpleDateFormat().parse( date1 );
 118  
         }
 119  4
         catch ( ParseException e )
 120  
         {
 121  4
             this.date = new Date();
 122  0
         }
 123  4
     }
 124  
 
 125  
     /**
 126  
      * Get the date of the document
 127  
      *
 128  
      * @return the date as String
 129  
      */
 130  
     public String getDate()
 131  
     {
 132  4
         if ( this.date == null )
 133  
         {
 134  0
             return new Date( System.currentTimeMillis() ).toString();
 135  
         }
 136  
 
 137  4
         return this.date.toString();
 138  
     }
 139  
 }