KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lowagie > text > Meta


1 /*
2  * $Id: Meta.java 2748 2007-05-12 15:11:48Z blowagie $
3  * $Name$
4  *
5  * Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
6  *
7  * The contents of this file are subject to the Mozilla Public License Version 1.1
8  * (the "License"); you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the License.
14  *
15  * The Original Code is 'iText, a free JAVA-PDF library'.
16  *
17  * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
18  * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
19  * All Rights Reserved.
20  * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
21  * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
22  *
23  * Contributor(s): all the names of the contributors are added in the source code
24  * where applicable.
25  *
26  * Alternatively, the contents of this file may be used under the terms of the
27  * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
28  * provisions of LGPL are applicable instead of those above. If you wish to
29  * allow use of your version of this file only under the terms of the LGPL
30  * License and not to allow others to use your version of this file under
31  * the MPL, indicate your decision by deleting the provisions above and
32  * replace them with the notice and other provisions required by the LGPL.
33  * If you do not delete the provisions above, a recipient may use your version
34  * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
35  *
36  * This library is free software; you can redistribute it and/or modify it
37  * under the terms of the MPL as stated above or under the terms of the GNU
38  * Library General Public License as published by the Free Software Foundation;
39  * either version 2 of the License, or any later version.
40  *
41  * This library is distributed in the hope that it will be useful, but WITHOUT
42  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
43  * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
44  * details.
45  *
46  * If you didn't download this code from the following link, you should check if
47  * you aren't using an obsolete version:
48  * http://www.lowagie.com/iText/
49  */

50
51 package com.lowagie.text;
52
53 import java.util.ArrayList JavaDoc;
54
55 /**
56  * This is an <CODE>Element</CODE> that contains
57  * some meta information about the document.
58  * <P>
59  * An object of type <CODE>Meta</CODE> can not be constructed by the user.
60  * Userdefined meta information should be placed in a <CODE>Header</CODE>-object.
61  * <CODE>Meta</CODE> is reserved for: Subject, Keywords, Author, Title, Producer
62  * and Creationdate information.
63  *
64  * @see Element
65  * @see Header
66  */

67
68 public class Meta implements Element {
69     
70     // membervariables
71

72     /** This is the type of Meta-information this object contains. */
73     private int type;
74     
75     /** This is the content of the Meta-information. */
76     private StringBuffer JavaDoc content;
77     
78     // constructors
79

80     /**
81      * Constructs a <CODE>Meta</CODE>.
82      *
83      * @param type the type of meta-information
84      * @param content the content
85      */

86     Meta(int type, String JavaDoc content) {
87         this.type = type;
88         this.content = new StringBuffer JavaDoc(content);
89     }
90     
91     /**
92      * Constructs a <CODE>Meta</CODE>.
93      *
94      * @param tag the tagname of the meta-information
95      * @param content the content
96      */

97     public Meta(String JavaDoc tag, String JavaDoc content) {
98         this.type = Meta.getType(tag);
99         this.content = new StringBuffer JavaDoc(content);
100     }
101     
102     // implementation of the Element-methods
103

104     /**
105      * Processes the element by adding it (or the different parts) to a
106      * <CODE>ElementListener</CODE>.
107      *
108      * @param listener the <CODE>ElementListener</CODE>
109      * @return <CODE>true</CODE> if the element was processed successfully
110      */

111     public boolean process(ElementListener listener) {
112         try {
113             return listener.add(this);
114         }
115         catch(DocumentException de) {
116             return false;
117         }
118     }
119     
120     /**
121      * Gets the type of the text element.
122      *
123      * @return a type
124      */

125     public int type() {
126         return type;
127     }
128     
129     /**
130      * Gets all the chunks in this element.
131      *
132      * @return an <CODE>ArrayList</CODE>
133      */

134     public ArrayList JavaDoc getChunks() {
135         return new ArrayList JavaDoc();
136     }
137     
138     // methods
139

140     /**
141      * appends some text to this <CODE>Meta</CODE>.
142      *
143      * @param string a <CODE>String</CODE>
144      * @return a <CODE>StringBuffer</CODE>
145      */

146     public StringBuffer JavaDoc append(String JavaDoc string) {
147         return content.append(string);
148     }
149     
150     // methods to retrieve information
151

152     /**
153      * Returns the content of the meta information.
154      *
155      * @return a <CODE>String</CODE>
156      */

157     public String JavaDoc getContent() {
158         return content.toString();
159     }
160
161     /**
162      * Returns the name of the meta information.
163      *
164      * @return a <CODE>String</CODE>
165      */

166     
167     public String JavaDoc getName() {
168         switch (type) {
169             case Element.SUBJECT:
170                 return ElementTags.SUBJECT;
171             case Element.KEYWORDS:
172                 return ElementTags.KEYWORDS;
173             case Element.AUTHOR:
174                 return ElementTags.AUTHOR;
175             case Element.TITLE:
176                 return ElementTags.TITLE;
177             case Element.PRODUCER:
178                 return ElementTags.PRODUCER;
179             case Element.CREATIONDATE:
180                 return ElementTags.CREATIONDATE;
181                 default:
182                     return ElementTags.UNKNOWN;
183         }
184     }
185     
186     /**
187      * Returns the name of the meta information.
188      *
189      * @param tag iText tag for meta information
190      * @return the Element value corresponding with the given tag
191      */

192     public static int getType(String JavaDoc tag) {
193         if (ElementTags.SUBJECT.equals(tag)) {
194             return Element.SUBJECT;
195         }
196         if (ElementTags.KEYWORDS.equals(tag)) {
197             return Element.KEYWORDS;
198         }
199         if (ElementTags.AUTHOR.equals(tag)) {
200             return Element.AUTHOR;
201         }
202         if (ElementTags.TITLE.equals(tag)) {
203             return Element.TITLE;
204         }
205         if (ElementTags.PRODUCER.equals(tag)) {
206             return Element.PRODUCER;
207         }
208         if (ElementTags.CREATIONDATE.equals(tag)) {
209             return Element.CREATIONDATE;
210         }
211         return Element.HEADER;
212     }
213     
214     // deprecated
215

216     /**
217      * Returns the name of the meta information.
218      *
219      * @return a <CODE>String</CODE>
220      * @deprecated Use {@link #getName()} instead
221      */

222     public String JavaDoc name() {
223         return getName();
224     }
225     
226     /**
227      * Returns the content of the meta information.
228      *
229      * @return a <CODE>String</CODE>
230      * @deprecated Use {@link #getContent()} instead
231      */

232     public String JavaDoc content() {
233         return getContent();
234     }
235 }
Popular Tags