KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pdfbox > pdmodel > common > PDNamedTextStream


1 /**
2  * Copyright (c) 2004, www.pdfbox.org
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * 3. Neither the name of pdfbox; nor the names of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * http://www.pdfbox.org
29  *
30  */

31 package org.pdfbox.pdmodel.common;
32
33 import org.pdfbox.cos.COSBase;
34 import org.pdfbox.cos.COSName;
35
36 /**
37  * A named text stream is a combination of a name and a PDTextStream object. This
38  * is used in name trees.
39  *
40  * @author <a HREF="mailto:ben@benlitchfield.com">Ben Litchfield</a>
41  * @version $Revision: 1.3 $
42  */

43 public class PDNamedTextStream implements DualCOSObjectable
44 {
45     private COSName streamName;
46     private PDTextStream stream;
47
48     /**
49      * Constructor.
50      */

51     public PDNamedTextStream()
52     {
53         //default constructor
54
}
55
56     /**
57      * Constructor.
58      *
59      * @param name The name of the stream.
60      * @param str The stream.
61      */

62     public PDNamedTextStream( COSName name, COSBase str )
63     {
64         streamName = name;
65         stream = PDTextStream.createTextStream( str );
66     }
67
68     /**
69      * The name of the named text stream.
70      *
71      * @return The stream name.
72      */

73     public String JavaDoc getName()
74     {
75         String JavaDoc name = null;
76         if( streamName != null )
77         {
78             name = streamName.getName();
79         }
80         return name;
81     }
82
83     /**
84      * This will set the name of the named text stream.
85      *
86      * @param name The name of the named text stream.
87      */

88     public void setName( String JavaDoc name )
89     {
90         streamName = COSName.getPDFName( name );
91     }
92
93     /**
94      * This will get the stream.
95      *
96      * @return The stream associated with this name.
97      */

98     public PDTextStream getStream()
99     {
100         return stream;
101     }
102
103     /**
104      * This will set the stream.
105      *
106      * @param str The stream associated with this name.
107      */

108     public void setStream( PDTextStream str )
109     {
110         stream = str;
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 getFirstCOSObject()
119     {
120         return streamName;
121     }
122
123     /**
124      * Convert this standard java object to a COS object.
125      *
126      * @return The cos object that matches this Java object.
127      */

128     public COSBase getSecondCOSObject()
129     {
130         COSBase retval = null;
131         if( stream != null )
132         {
133             retval = stream.getCOSObject();
134         }
135         return retval;
136     }
137 }
Popular Tags