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 * @version $Id$ 032 */ 033public class ITextHeader 034{ 035 private String title; 036 037 private StringBuilder authors; 038 039 private Date date; 040 041 /** 042 * Default constructor 043 */ 044 public ITextHeader() 045 { 046 // nop 047 } 048 049 /** 050 * Add a title to the Document 051 * 052 * @param title1 the title. 053 */ 054 public final void setTitle( String title1 ) 055 { 056 this.title = title1; 057 } 058 059 /** 060 * Get the title 061 * 062 * @return title as String 063 */ 064 public String getTitle() 065 { 066 if ( this.title == null ) 067 { 068 return ""; 069 } 070 071 return this.title; 072 } 073 074 /** 075 * Add a new author 076 * 077 * @param author the author. 078 */ 079 public void addAuthor( String author ) 080 { 081 if ( this.authors == null ) 082 { 083 this.authors = new StringBuilder(); 084 } 085 else 086 { 087 this.authors.append( ", " ); 088 } 089 090 this.authors.append( author ); 091 } 092 093 /** 094 * Get the authors 095 * 096 * @return the authors as String 097 */ 098 public String getAuthors() 099 { 100 if ( ( this.authors == null ) || ( this.authors.length() == 0 ) ) 101 { 102 return System.getProperty( "user.name" ); 103 } 104 105 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 this.date = new SimpleDateFormat().parse( date1 ); 118 } 119 catch ( ParseException e ) 120 { 121 this.date = new Date(); 122 } 123 } 124 125 /** 126 * Get the date of the document 127 * 128 * @return the date as String 129 */ 130 public String getDate() 131 { 132 if ( this.date == null ) 133 { 134 return new Date( System.currentTimeMillis() ).toString(); 135 } 136 137 return this.date.toString(); 138 } 139}