]> _ Git - cubeextranet.git/blob
45acf19a0187036c72e743ca96b564f1b5e5418e
[cubeextranet.git] /
1 /*\r
2  * Licensed to the Apache Software Foundation (ASF) under one or more\r
3  * contributor license agreements.  See the NOTICE file distributed with\r
4  * this work for additional information regarding copyright ownership.\r
5  * The ASF licenses this file to You under the Apache License, Version 2.0\r
6  * (the "License"); you may not use this file except in compliance with\r
7  * the License.  You may obtain a copy of the License at\r
8  *\r
9  *      http://www.apache.org/licenses/LICENSE-2.0\r
10  *\r
11  * Unless required by applicable law or agreed to in writing, software\r
12  * distributed under the License is distributed on an "AS IS" BASIS,\r
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14  * See the License for the specific language governing permissions and\r
15  * limitations under the License.\r
16  */\r
17 package org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure;\r
18 \r
19 import java.io.IOException;\r
20 import java.util.Hashtable;\r
21 import java.util.Map;\r
22 \r
23 import org.apache.pdfbox.cos.COSBase;\r
24 import org.apache.pdfbox.cos.COSDictionary;\r
25 import org.apache.pdfbox.cos.COSName;\r
26 import org.apache.pdfbox.pdmodel.common.COSDictionaryMap;\r
27 import org.apache.pdfbox.pdmodel.common.PDNameTreeNode;\r
28 \r
29 /**\r
30  * A root of a structure tree.\r
31  *\r
32  * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>,\r
33  *  <a href="mailto:Johannes%20Koch%20%3Ckoch@apache.org%3E">Johannes Koch</a>\r
34  * @version $Revision: 1.2 $\r
35  */\r
36 public class PDStructureTreeRoot extends PDStructureNode\r
37 {\r
38 \r
39     public static final String TYPE = "StructTreeRoot";\r
40 \r
41 \r
42     /**\r
43      * Default Constructor.\r
44      *\r
45      */\r
46     public PDStructureTreeRoot()\r
47     {\r
48         super(TYPE);\r
49     }\r
50 \r
51     /**\r
52      * Constructor for an existing structure element.\r
53      *\r
54      * @param dic The existing dictionary.\r
55      */\r
56     public PDStructureTreeRoot( COSDictionary dic )\r
57     {\r
58         super(dic);\r
59     }\r
60 \r
61 \r
62     /**\r
63      * Returns the ID tree.\r
64      * \r
65      * @return the ID tree\r
66      */\r
67     public PDNameTreeNode getIDTree()\r
68     {\r
69         COSDictionary idTreeDic = (COSDictionary) this.getCOSDictionary()\r
70             .getDictionaryObject(COSName.ID_TREE);\r
71         if (idTreeDic != null)\r
72         {\r
73             return new PDNameTreeNode(idTreeDic, PDStructureElement.class);\r
74         }\r
75         return null;\r
76     }\r
77 \r
78     /**\r
79      * Sets the ID tree.\r
80      * \r
81      * @param idTree the ID tree\r
82      */\r
83     public void setIDTree(PDNameTreeNode idTree)\r
84     {\r
85         this.getCOSDictionary().setItem(COSName.ID_TREE, idTree);\r
86     }\r
87 \r
88     /**\r
89      * Returns the next key in the parent tree.\r
90      * \r
91      * @return the next key in the parent tree\r
92      */\r
93     public int getParentTreeNextKey()\r
94     {\r
95         return this.getCOSDictionary().getInt(COSName.PARENT_TREE_NEXT_KEY);\r
96     }\r
97 \r
98     /**\r
99      * Returns the role map.\r
100      * \r
101      * @return the role map\r
102      */\r
103     @SuppressWarnings("unchecked")\r
104     public Map<String, String> getRoleMap()\r
105     {\r
106         COSBase rm = this.getCOSDictionary().getDictionaryObject(COSName.ROLE_MAP);\r
107         if (rm instanceof COSDictionary)\r
108         {\r
109             try\r
110             {\r
111                 return COSDictionaryMap.convertBasicTypesToMap((COSDictionary) rm);\r
112             }\r
113             catch (IOException e)\r
114             {\r
115                 e.printStackTrace();\r
116             }\r
117         }\r
118         return new Hashtable<String, String>();\r
119     }\r
120 \r
121     /**\r
122      * Sets the role map.\r
123      * \r
124      * @param roleMap the role map\r
125      */\r
126     public void setRoleMap(Map<String, String> roleMap)\r
127     {\r
128         COSDictionary rmDic = new COSDictionary();\r
129         for (String key : roleMap.keySet())\r
130         {\r
131             rmDic.setName(key, roleMap.get(key));\r
132         }\r
133         this.getCOSDictionary().setItem(COSName.ROLE_MAP, rmDic);\r
134     }\r
135 \r
136 }\r