001/* 002 * $Id: Meta.java 4784 2011-03-15 08:33:00Z blowagie $ 003 * 004 * This file is part of the iText (R) project. 005 * Copyright (c) 1998-2011 1T3XT BVBA 006 * Authors: Bruno Lowagie, Paulo Soares, et al. 007 * 008 * This program is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU Affero General Public License version 3 010 * as published by the Free Software Foundation with the addition of the 011 * following permission added to Section 15 as permitted in Section 7(a): 012 * FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY 1T3XT, 013 * 1T3XT DISCLAIMS THE WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. 014 * 015 * This program is distributed in the hope that it will be useful, but 016 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 017 * or FITNESS FOR A PARTICULAR PURPOSE. 018 * See the GNU Affero General Public License for more details. 019 * You should have received a copy of the GNU Affero General Public License 020 * along with this program; if not, see http://www.gnu.org/licenses or write to 021 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 022 * Boston, MA, 02110-1301 USA, or download the license from the following URL: 023 * http://itextpdf.com/terms-of-use/ 024 * 025 * The interactive user interfaces in modified source and object code versions 026 * of this program must display Appropriate Legal Notices, as required under 027 * Section 5 of the GNU Affero General Public License. 028 * 029 * In accordance with Section 7(b) of the GNU Affero General Public License, 030 * a covered work must retain the producer line in every PDF that is created 031 * or manipulated using iText. 032 * 033 * You can be released from the requirements of the license by purchasing 034 * a commercial license. Buying such a license is mandatory as soon as you 035 * develop commercial activities involving the iText software without 036 * disclosing the source code of your own applications. 037 * These activities include: offering paid services to customers as an ASP, 038 * serving PDFs on the fly in a web application, shipping iText with a closed 039 * source product. 040 * 041 * For more information, please contact iText Software Corp. at this 042 * address: sales@itextpdf.com 043 */ 044package com.itextpdf.text; 045 046import java.util.List; 047import java.util.ArrayList; 048 049/** 050 * This is an <CODE>Element</CODE> that contains 051 * some meta information about the document. 052 * <P> 053 * An object of type <CODE>Meta</CODE> can not be constructed by the user. 054 * User defined meta information should be placed in a <CODE>Header</CODE>-object. 055 * <CODE>Meta</CODE> is reserved for: Subject, Keywords, Author, Title, Producer 056 * and Creationdate information. 057 * 058 * @see Element 059 * @see Header 060 */ 061 062public class Meta implements Element { 063 064 // membervariables 065 066 /** This is the type of Meta-information this object contains. */ 067 private final int type; 068 069 /** This is the content of the Meta-information. */ 070 private final StringBuffer content; 071 072 /** 073 * The possible value of an alignment attribute. 074 * @since 5.0.6 (moved from ElementTags) 075 */ 076 public static final String UNKNOWN = "unknown"; 077 078 /** 079 * The possible value of an alignment attribute. 080 * @since 5.0.6 (moved from ElementTags) 081 */ 082 public static final String PRODUCER = "producer"; 083 084 /** 085 * The possible value of an alignment attribute. 086 * @since 5.0.6 (moved from ElementTags) 087 */ 088 public static final String CREATIONDATE = "creationdate"; 089 090 /** 091 * The possible value of an alignment attribute. 092 * @since 5.0.6 (moved from ElementTags) 093 */ 094 public static final String AUTHOR = "author"; 095 096 /** 097 * The possible value of an alignment attribute. 098 * @since 5.0.6 (moved from ElementTags) 099 */ 100 public static final String KEYWORDS = "keywords"; 101 102 /** 103 * The possible value of an alignment attribute. 104 * @since 5.0.6 (moved from ElementTags) 105 */ 106 public static final String SUBJECT = "subject"; 107 108 /** 109 * The possible value of an alignment attribute. 110 * @since 5.0.6 (moved from ElementTags) 111 */ 112 public static final String TITLE = "title"; 113 114 // constructors 115 116 /** 117 * Constructs a <CODE>Meta</CODE>. 118 * 119 * @param type the type of meta-information 120 * @param content the content 121 */ 122 Meta(final int type, final String content) { 123 this.type = type; 124 this.content = new StringBuffer(content); 125 } 126 127 /** 128 * Constructs a <CODE>Meta</CODE>. 129 * 130 * @param tag the tagname of the meta-information 131 * @param content the content 132 */ 133 public Meta(final String tag, final String content) { 134 this.type = Meta.getType(tag); 135 this.content = new StringBuffer(content); 136 } 137 138 // implementation of the Element-methods 139 140 /** 141 * Processes the element by adding it (or the different parts) to a 142 * <CODE>ElementListener</CODE>. 143 * 144 * @param listener the <CODE>ElementListener</CODE> 145 * @return <CODE>true</CODE> if the element was processed successfully 146 */ 147 public boolean process(final ElementListener listener) { 148 try { 149 return listener.add(this); 150 } 151 catch(DocumentException de) { 152 return false; 153 } 154 } 155 156 /** 157 * Gets the type of the text element. 158 * 159 * @return a type 160 */ 161 public int type() { 162 return type; 163 } 164 165 /** 166 * Gets all the chunks in this element. 167 * 168 * @return an <CODE>ArrayList</CODE> 169 */ 170 public List<Chunk> getChunks() { 171 return new ArrayList<Chunk>(); 172 } 173 174 /** 175 * @see com.itextpdf.text.Element#isContent() 176 * @since iText 2.0.8 177 */ 178 public boolean isContent() { 179 return false; 180 } 181 182 /** 183 * @see com.itextpdf.text.Element#isNestable() 184 * @since iText 2.0.8 185 */ 186 public boolean isNestable() { 187 return false; 188 } 189 190 // methods 191 192 /** 193 * appends some text to this <CODE>Meta</CODE>. 194 * 195 * @param string a <CODE>String</CODE> 196 * @return a <CODE>StringBuffer</CODE> 197 */ 198 public StringBuffer append(final String string) { 199 return content.append(string); 200 } 201 202 // methods to retrieve information 203 204 /** 205 * Returns the content of the meta information. 206 * 207 * @return a <CODE>String</CODE> 208 */ 209 public String getContent() { 210 return content.toString(); 211 } 212 213 /** 214 * Returns the name of the meta information. 215 * 216 * @return a <CODE>String</CODE> 217 */ 218 219 public String getName() { 220 switch (type) { 221 case Element.SUBJECT: 222 return Meta.SUBJECT; 223 case Element.KEYWORDS: 224 return Meta.KEYWORDS; 225 case Element.AUTHOR: 226 return Meta.AUTHOR; 227 case Element.TITLE: 228 return Meta.TITLE; 229 case Element.PRODUCER: 230 return Meta.PRODUCER; 231 case Element.CREATIONDATE: 232 return Meta.CREATIONDATE; 233 default: 234 return Meta.UNKNOWN; 235 } 236 } 237 238 /** 239 * Returns the name of the meta information. 240 * 241 * @param tag iText tag for meta information 242 * @return the Element value corresponding with the given tag 243 */ 244 public static int getType(final String tag) { 245 if (Meta.SUBJECT.equals(tag)) { 246 return Element.SUBJECT; 247 } 248 if (Meta.KEYWORDS.equals(tag)) { 249 return Element.KEYWORDS; 250 } 251 if (Meta.AUTHOR.equals(tag)) { 252 return Element.AUTHOR; 253 } 254 if (Meta.TITLE.equals(tag)) { 255 return Element.TITLE; 256 } 257 if (Meta.PRODUCER.equals(tag)) { 258 return Element.PRODUCER; 259 } 260 if (Meta.CREATIONDATE.equals(tag)) { 261 return Element.CREATIONDATE; 262 } 263 return Element.HEADER; 264 } 265 266}