All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.itextpdf.text.Meta Maven / Gradle / Ivy

/*
 * $Id: ac7125fb172516f1a8e697bd13b9dc6d1f56c3c6 $
 *
 * This file is part of the iText (R) project.
 * Copyright (c) 1998-2016 iText Group NV
 * Authors: Bruno Lowagie, Paulo Soares, et al.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License version 3
 * as published by the Free Software Foundation with the addition of the
 * following permission added to Section 15 as permitted in Section 7(a):
 * FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
 * ITEXT GROUP. ITEXT GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
 * OF THIRD PARTY RIGHTS
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Affero General Public License for more details.
 * You should have received a copy of the GNU Affero General Public License
 * along with this program; if not, see http://www.gnu.org/licenses or write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA, 02110-1301 USA, or download the license from the following URL:
 * http://itextpdf.com/terms-of-use/
 *
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License.
 *
 * In accordance with Section 7(b) of the GNU Affero General Public License,
 * a covered work must retain the producer line in every PDF that is created
 * or manipulated using iText.
 *
 * You can be released from the requirements of the license by purchasing
 * a commercial license. Buying such a license is mandatory as soon as you
 * develop commercial activities involving the iText software without
 * disclosing the source code of your own applications.
 * These activities include: offering paid services to customers as an ASP,
 * serving PDFs on the fly in a web application, shipping iText with a closed
 * source product.
 *
 * For more information, please contact iText Software Corp. at this
 * address: [email protected]
 */
package com.itextpdf.text;

import java.util.List;
import java.util.ArrayList;

/**
 * This is an Element that contains
 * some meta information about the document.
 * 

* An object of type Meta can not be constructed by the user. * User defined meta information should be placed in a Header-object. * Meta is reserved for: Subject, Keywords, Author, Title, Producer * and Creationdate information. * * @see Element * @see Header */ public class Meta implements Element { // membervariables /** This is the type of Meta-information this object contains. */ private final int type; /** This is the content of the Meta-information. */ private final StringBuffer content; /** * The possible value of an alignment attribute. * @since 5.0.6 (moved from ElementTags) */ public static final String UNKNOWN = "unknown"; /** * The possible value of an alignment attribute. * @since 5.0.6 (moved from ElementTags) */ public static final String PRODUCER = "producer"; /** * The possible value of an alignment attribute. * @since 5.0.6 (moved from ElementTags) */ public static final String CREATIONDATE = "creationdate"; /** * The possible value of an alignment attribute. * @since 5.0.6 (moved from ElementTags) */ public static final String AUTHOR = "author"; /** * The possible value of an alignment attribute. * @since 5.0.6 (moved from ElementTags) */ public static final String KEYWORDS = "keywords"; /** * The possible value of an alignment attribute. * @since 5.0.6 (moved from ElementTags) */ public static final String SUBJECT = "subject"; /** * The possible value of an alignment attribute. * @since 5.0.6 (moved from ElementTags) */ public static final String TITLE = "title"; // constructors /** * Constructs a Meta. * * @param type the type of meta-information * @param content the content */ Meta(final int type, final String content) { this.type = type; this.content = new StringBuffer(content); } /** * Constructs a Meta. * * @param tag the tagname of the meta-information * @param content the content */ public Meta(final String tag, final String content) { this.type = Meta.getType(tag); this.content = new StringBuffer(content); } // implementation of the Element-methods /** * Processes the element by adding it (or the different parts) to a * ElementListener. * * @param listener the ElementListener * @return true if the element was processed successfully */ public boolean process(final ElementListener listener) { try { return listener.add(this); } catch(DocumentException de) { return false; } } /** * Gets the type of the text element. * * @return a type */ public int type() { return type; } /** * Gets all the chunks in this element. * * @return an ArrayList */ public List getChunks() { return new ArrayList(); } /** * @see com.itextpdf.text.Element#isContent() * @since iText 2.0.8 */ public boolean isContent() { return false; } /** * @see com.itextpdf.text.Element#isNestable() * @since iText 2.0.8 */ public boolean isNestable() { return false; } // methods /** * appends some text to this Meta. * * @param string a String * @return a StringBuffer */ public StringBuffer append(final String string) { return content.append(string); } // methods to retrieve information /** * Returns the content of the meta information. * * @return a String */ public String getContent() { return content.toString(); } /** * Returns the name of the meta information. * * @return a String */ public String getName() { switch (type) { case Element.SUBJECT: return Meta.SUBJECT; case Element.KEYWORDS: return Meta.KEYWORDS; case Element.AUTHOR: return Meta.AUTHOR; case Element.TITLE: return Meta.TITLE; case Element.PRODUCER: return Meta.PRODUCER; case Element.CREATIONDATE: return Meta.CREATIONDATE; default: return Meta.UNKNOWN; } } /** * Returns the name of the meta information. * * @param tag iText tag for meta information * @return the Element value corresponding with the given tag */ public static int getType(final String tag) { if (Meta.SUBJECT.equals(tag)) { return Element.SUBJECT; } if (Meta.KEYWORDS.equals(tag)) { return Element.KEYWORDS; } if (Meta.AUTHOR.equals(tag)) { return Element.AUTHOR; } if (Meta.TITLE.equals(tag)) { return Element.TITLE; } if (Meta.PRODUCER.equals(tag)) { return Element.PRODUCER; } if (Meta.CREATIONDATE.equals(tag)) { return Element.CREATIONDATE; } return Element.HEADER; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy