]> _ Git - cubeextranet.git/blob
6e67799e2de03dd88dc4532987adc9fe72851690
[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.logicalstructure;
18
19 import java.io.IOException;
20 import java.util.Hashtable;
21 import java.util.Map;
22
23 import org.apache.pdfbox.cos.COSBase;
24 import org.apache.pdfbox.cos.COSDictionary;
25 import org.apache.pdfbox.cos.COSName;
26 import org.apache.pdfbox.pdmodel.common.COSDictionaryMap;
27 import org.apache.pdfbox.pdmodel.common.PDNameTreeNode;
28
29 /**
30  * A root of a structure tree.
31  *
32  * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>,
33  *  <a href="mailto:Johannes%20Koch%20%3Ckoch@apache.org%3E">Johannes Koch</a>
34  * @version $Revision: 1.2 $
35  */
36 public class PDStructureTreeRoot extends PDStructureNode
37 {
38
39     public static final String TYPE = "StructTreeRoot";
40
41
42     /**
43      * Default Constructor.
44      *
45      */
46     public PDStructureTreeRoot()
47     {
48         super(TYPE);
49     }
50
51     /**
52      * Constructor for an existing structure element.
53      *
54      * @param dic The existing dictionary.
55      */
56     public PDStructureTreeRoot( COSDictionary dic )
57     {
58         super(dic);
59     }
60
61
62     /**
63      * Returns the ID tree.
64      * 
65      * @return the ID tree
66      */
67     public PDNameTreeNode getIDTree()
68     {
69         COSDictionary idTreeDic = (COSDictionary) this.getCOSDictionary()
70             .getDictionaryObject(COSName.ID_TREE);
71         if (idTreeDic != null)
72         {
73             return new PDNameTreeNode(idTreeDic, PDStructureElement.class);
74         }
75         return null;
76     }
77
78     /**
79      * Sets the ID tree.
80      * 
81      * @param idTree the ID tree
82      */
83     public void setIDTree(PDNameTreeNode idTree)
84     {
85         this.getCOSDictionary().setItem(COSName.ID_TREE, idTree);
86     }
87
88     /**
89      * Returns the next key in the parent tree.
90      * 
91      * @return the next key in the parent tree
92      */
93     public int getParentTreeNextKey()
94     {
95         return this.getCOSDictionary().getInt(COSName.PARENT_TREE_NEXT_KEY);
96     }
97
98     /**
99      * Returns the role map.
100      * 
101      * @return the role map
102      */
103     @SuppressWarnings("unchecked")
104     public Map<String, String> getRoleMap()
105     {
106         COSBase rm = this.getCOSDictionary().getDictionaryObject(COSName.ROLE_MAP);
107         if (rm instanceof COSDictionary)
108         {
109             try
110             {
111                 return COSDictionaryMap.convertBasicTypesToMap((COSDictionary) rm);
112             }
113             catch (IOException e)
114             {
115                 e.printStackTrace();
116             }
117         }
118         return new Hashtable<String, String>();
119     }
120
121     /**
122      * Sets the role map.
123      * 
124      * @param roleMap the role map
125      */
126     public void setRoleMap(Map<String, String> roleMap)
127     {
128         COSDictionary rmDic = new COSDictionary();
129         for (String key : roleMap.keySet())
130         {
131             rmDic.setName(key, roleMap.get(key));
132         }
133         this.getCOSDictionary().setItem(COSName.ROLE_MAP, rmDic);
134     }
135
136 }