001package org.apache.maven.doxia.module.itext; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.text.ParseException; 023import java.text.SimpleDateFormat; 024 025import java.util.Date; 026 027/** 028 * Header object containing meta-informations. 029 * 030 * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a> 031 */ 032public class ITextHeader 033{ 034 private String title; 035 036 private StringBuilder authors; 037 038 private Date date; 039 040 /** 041 * Default constructor 042 */ 043 public ITextHeader() 044 { 045 // nop 046 } 047 048 /** 049 * Add a title to the Document 050 * 051 * @param title1 the title. 052 */ 053 public final void setTitle( String title1 ) 054 { 055 this.title = title1; 056 } 057 058 /** 059 * Get the title 060 * 061 * @return title as String 062 */ 063 public String getTitle() 064 { 065 if ( this.title == null ) 066 { 067 return ""; 068 } 069 070 return this.title; 071 } 072 073 /** 074 * Add a new author 075 * 076 * @param author the author. 077 */ 078 public void addAuthor( String author ) 079 { 080 if ( this.authors == null ) 081 { 082 this.authors = new StringBuilder(); 083 } 084 else 085 { 086 this.authors.append( ", " ); 087 } 088 089 this.authors.append( author ); 090 } 091 092 /** 093 * Get the authors 094 * 095 * @return the authors as String 096 */ 097 public String getAuthors() 098 { 099 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}