KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pdfbox > util > PDFOperator


1 /**
2  * Copyright (c) 2003-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.util;
32
33 import java.util.Collections JavaDoc;
34 import java.util.HashMap JavaDoc;
35 import java.util.Map JavaDoc;
36
37 /**
38  * This class represents an Operator in the content stream.
39  *
40  * @author <a HREF="mailto:ben@benlitchfield.com">Ben Litchfield</a>
41  * @version $Revision: 1.14 $
42  */

43 public class PDFOperator
44 {
45     private String JavaDoc theOperator;
46     private byte[] imageData;
47     private ImageParameters imageParameters;
48
49     private static Map JavaDoc operators = Collections.synchronizedMap( new HashMap JavaDoc() );
50
51     /**
52      * Constructor.
53      *
54      * @param aOperator The operator that this object will represent.
55      */

56     private PDFOperator( String JavaDoc aOperator )
57     {
58         theOperator = aOperator;
59         if( aOperator.startsWith( "/" ) )
60         {
61             throw new RuntimeException JavaDoc( "Operators are not allowed to start with / '" + aOperator + "'" );
62         }
63     }
64
65     /**
66      * This is used to create/cache operators in the system.
67      *
68      * @param operator The operator for the system.
69      *
70      * @return The operator that matches the operator keyword.
71      */

72     public static PDFOperator getOperator( String JavaDoc operator )
73     {
74         PDFOperator operation = null;
75         if( operator.equals( "ID" ) || operator.equals( "BI" ) )
76         {
77             //we can't cache the ID operators.
78
operation = new PDFOperator( operator );
79         }
80         else
81         {
82             operation = (PDFOperator)operators.get( operator );
83             if( operation == null )
84             {
85                 operation = new PDFOperator( operator );
86                 operators.put( operator, operation );
87             }
88         }
89
90         return operation;
91     }
92
93     /**
94      * This will get the operation that this operator represents.
95      *
96      * @return The string representation of the operation.
97      */

98     public String JavaDoc getOperation()
99     {
100         return theOperator;
101     }
102
103     /**
104      * This will print a string rep of this class.
105      *
106      * @return A string rep of this class.
107      */

108     public String JavaDoc toString()
109     {
110         return "PDFOperator{" + theOperator + "}";
111     }
112
113     /**
114      * This is the special case for the ID operator where there are just random
115      * bytes inlined the stream.
116      *
117      * @return Value of property imageData.
118      */

119     public byte[] getImageData()
120     {
121         return this.imageData;
122     }
123
124     /**
125      * This will set the image data, this is only used for the ID operator.
126      *
127      * @param imageDataArray New value of property imageData.
128      */

129     public void setImageData(byte[] imageDataArray)
130     {
131         imageData = imageDataArray;
132     }
133
134     /**
135      * This will get the image parameters, this is only valid for BI operators.
136      *
137      * @return The image parameters.
138      */

139     public ImageParameters getImageParameters()
140     {
141         return imageParameters;
142     }
143
144     /**
145      * This will set the image parameters, this is only valid for BI operators.
146      *
147      * @param params The image parameters.
148      */

149     public void setImageParameters( ImageParameters params)
150     {
151         imageParameters = params;
152     }
153 }
Popular Tags