]> _ Git - cubeextranet.git/blob
0376f161fe232db8340ea0694bf480978dae28ca
[cubeextranet.git] /
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 package org.apache.pdfbox.pdmodel.documentinterchange.markedcontent;
18
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import org.apache.pdfbox.cos.COSDictionary;
23 import org.apache.pdfbox.cos.COSName;
24 import org.apache.pdfbox.pdmodel.documentinterchange.taggedpdf.PDArtifactMarkedContent;
25 import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObject;
26 import org.apache.pdfbox.util.TextPosition;
27
28 /**
29  * A marked content.
30  * 
31  * @author <a href="mailto:Johannes%20Koch%20%3Ckoch@apache.org%3E">Johannes Koch</a>
32  * @version $Revision: $
33  */
34 public class PDMarkedContent
35 {
36
37     /**
38      * Creates a marked-content sequence.
39      * 
40      * @param tag the tag
41      * @param properties the properties
42      * @return the marked-content sequence
43      */
44     public static PDMarkedContent create(COSName tag, COSDictionary properties)
45     {
46         if (COSName.ARTIFACT.equals(tag))
47         {
48             new PDArtifactMarkedContent(properties);
49         }
50         return new PDMarkedContent(tag, properties);
51     }
52
53
54     private String tag;
55     private COSDictionary properties;
56     private List<Object> contents;
57
58
59     /**
60      * Creates a new marked content object.
61      * 
62      * @param tag the tag
63      * @param properties the properties
64      */
65     public PDMarkedContent(COSName tag, COSDictionary properties)
66     {
67         this.tag = tag == null ? null : tag.getName();
68         this.properties = properties;
69         this.contents = new ArrayList<Object>();
70     }
71
72
73     /**
74      * Gets the tag.
75      * 
76      * @return the tag
77      */
78     public String getTag()
79     {
80         return this.tag;
81     }
82
83     /**
84      * Gets the properties.
85      * 
86      * @return the properties
87      */
88     public COSDictionary getProperties()
89     {
90         return this.properties;
91     }
92
93     /**
94      * Gets the marked-content identifier.
95      * 
96      * @return the marked-content identifier
97      */
98     public int getMCID()
99     {
100         return this.getProperties() == null ? null :
101             this.getProperties().getInt(COSName.MCID);
102     }
103
104     /**
105      * Gets the language (Lang).
106      * 
107      * @return the language
108      */
109     public String getLanguage()
110     {
111         return this.getProperties() == null ? null :
112             this.getProperties().getNameAsString(COSName.LANG);
113     }
114
115     /**
116      * Gets the actual text (ActualText).
117      * 
118      * @return the actual text
119      */
120     public String getActualText()
121     {
122         return this.getProperties() == null ? null :
123             this.getProperties().getString(COSName.ACTUAL_TEXT);
124     }
125
126     /**
127      * Gets the alternate description (Alt).
128      * 
129      * @return the alternate description
130      */
131     public String getAlternateDescription()
132     {
133         return this.getProperties() == null ? null :
134             this.getProperties().getString(COSName.ALT);
135     }
136
137     /**
138      * Gets the expanded form (E).
139      * 
140      * @return the expanded form
141      */
142     public String getExpandedForm()
143     {
144         return this.getProperties() == null ? null :
145             this.getProperties().getString(COSName.E);
146     }
147
148     /**
149      * Gets the contents of the marked content sequence. Can be
150      * <ul>
151      *   <li>{@link TextPosition},</li>
152      *   <li>{@link PDMarkedContent}, or</li>
153      *   <li>{@link PDXObject}.</li>
154      * </ul>
155      * 
156      * @return the contents of the marked content sequence
157      */
158     public List<Object> getContents()
159     {
160         return this.contents;
161     }
162
163     /**
164      * Adds a text position to the contents.
165      * 
166      * @param text the text position
167      */
168     public void addText(TextPosition text)
169     {
170         this.getContents().add(text);
171     }
172
173     /**
174      * Adds a marked content to the contents.
175      * 
176      * @param markedContent the marked content
177      */
178     public void addMarkedContent(PDMarkedContent markedContent)
179     {
180         this.getContents().add(markedContent);
181     }
182
183     /**
184      * Adds an XObject to the contents.
185      * 
186      * @param xobject the XObject
187      */
188     public void addXObject(PDXObject xobject)
189     {
190         this.getContents().add(xobject);
191     }
192
193
194     @Override
195     public String toString()
196     {
197         StringBuilder sb = new StringBuilder("tag=").append(this.tag)
198             .append(", properties=").append(this.properties);
199         sb.append(", contents=").append(this.contents);
200         return sb.toString();
201     }
202
203 }