View Javadoc
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   */
32  public class ITextHeader
33  {
34      private String title;
35  
36      private StringBuilder authors;
37  
38      private Date date;
39  
40      /**
41       * Default constructor
42       */
43      public ITextHeader()
44      {
45          // nop
46      }
47  
48      /**
49       * Add a title to the Document
50       *
51       * @param title1 the title.
52       */
53      public final void setTitle( String title1 )
54      {
55          this.title = title1;
56      }
57  
58      /**
59       * Get the title
60       *
61       * @return title as String
62       */
63      public String getTitle()
64      {
65          if ( this.title == null )
66          {
67              return "";
68          }
69  
70          return this.title;
71      }
72  
73      /**
74       * Add a new author
75       *
76       * @param author the author.
77       */
78      public void addAuthor( String author )
79      {
80          if ( this.authors == null )
81          {
82              this.authors = new StringBuilder();
83          }
84          else
85          {
86              this.authors.append( ", " );
87          }
88  
89          this.authors.append( author );
90      }
91  
92      /**
93       * Get the authors
94       *
95       * @return the authors as String
96       */
97      public String getAuthors()
98      {
99          if ( ( this.authors == null ) || ( this.authors.length() == 0 ) )
100         {
101             return System.getProperty( "user.name" );
102         }
103 
104         return this.authors.toString();
105     }
106 
107     /**
108      * Add a date to the document
109      *
110      * @param date1 a date as String
111      */
112     public void setDate( String date1 )
113     {
114         try
115         {
116             this.date = new SimpleDateFormat().parse( date1 );
117         }
118         catch ( ParseException e )
119         {
120             this.date = new Date();
121         }
122     }
123 
124     /**
125      * Get the date of the document
126      *
127      * @return the date as String
128      */
129     public String getDate()
130     {
131         if ( this.date == null )
132         {
133             return new Date( System.currentTimeMillis() ).toString();
134         }
135 
136         return this.date.toString();
137     }
138 }