001: /**
002: * Copyright (c) 2004, www.pdfbox.org
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions are met:
007: *
008: * 1. Redistributions of source code must retain the above copyright notice,
009: * this list of conditions and the following disclaimer.
010: * 2. Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: * 3. Neither the name of pdfbox; nor the names of its
014: * contributors may be used to endorse or promote products derived from this
015: * software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
018: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
019: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
020: * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
021: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
022: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
023: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
024: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
026: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: *
028: * http://www.pdfbox.org
029: *
030: */package org.pdfbox.pdmodel.common;
031:
032: import org.pdfbox.cos.COSBase;
033: import org.pdfbox.cos.COSName;
034:
035: /**
036: * A named text stream is a combination of a name and a PDTextStream object. This
037: * is used in name trees.
038: *
039: * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
040: * @version $Revision: 1.3 $
041: */
042: public class PDNamedTextStream implements DualCOSObjectable {
043: private COSName streamName;
044: private PDTextStream stream;
045:
046: /**
047: * Constructor.
048: */
049: public PDNamedTextStream() {
050: //default constructor
051: }
052:
053: /**
054: * Constructor.
055: *
056: * @param name The name of the stream.
057: * @param str The stream.
058: */
059: public PDNamedTextStream(COSName name, COSBase str) {
060: streamName = name;
061: stream = PDTextStream.createTextStream(str);
062: }
063:
064: /**
065: * The name of the named text stream.
066: *
067: * @return The stream name.
068: */
069: public String getName() {
070: String name = null;
071: if (streamName != null) {
072: name = streamName.getName();
073: }
074: return name;
075: }
076:
077: /**
078: * This will set the name of the named text stream.
079: *
080: * @param name The name of the named text stream.
081: */
082: public void setName(String name) {
083: streamName = COSName.getPDFName(name);
084: }
085:
086: /**
087: * This will get the stream.
088: *
089: * @return The stream associated with this name.
090: */
091: public PDTextStream getStream() {
092: return stream;
093: }
094:
095: /**
096: * This will set the stream.
097: *
098: * @param str The stream associated with this name.
099: */
100: public void setStream(PDTextStream str) {
101: stream = str;
102: }
103:
104: /**
105: * Convert this standard java object to a COS object.
106: *
107: * @return The cos object that matches this Java object.
108: */
109: public COSBase getFirstCOSObject() {
110: return streamName;
111: }
112:
113: /**
114: * Convert this standard java object to a COS object.
115: *
116: * @return The cos object that matches this Java object.
117: */
118: public COSBase getSecondCOSObject() {
119: COSBase retval = null;
120: if (stream != null) {
121: retval = stream.getCOSObject();
122: }
123: return retval;
124: }
125: }
|