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
9 * http://www.apache.org/licenses/LICENSE-2.0
\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
17 package org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure;
\r
19 import java.io.IOException;
\r
20 import java.util.Hashtable;
\r
21 import java.util.Map;
\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
30 * A root of a structure tree.
\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
36 public class PDStructureTreeRoot extends PDStructureNode
\r
39 public static final String TYPE = "StructTreeRoot";
\r
43 * Default Constructor.
\r
46 public PDStructureTreeRoot()
\r
52 * Constructor for an existing structure element.
\r
54 * @param dic The existing dictionary.
\r
56 public PDStructureTreeRoot( COSDictionary dic )
\r
63 * Returns the ID tree.
\r
65 * @return the ID tree
\r
67 public PDNameTreeNode getIDTree()
\r
69 COSDictionary idTreeDic = (COSDictionary) this.getCOSDictionary()
\r
70 .getDictionaryObject(COSName.ID_TREE);
\r
71 if (idTreeDic != null)
\r
73 return new PDNameTreeNode(idTreeDic, PDStructureElement.class);
\r
81 * @param idTree the ID tree
\r
83 public void setIDTree(PDNameTreeNode idTree)
\r
85 this.getCOSDictionary().setItem(COSName.ID_TREE, idTree);
\r
89 * Returns the next key in the parent tree.
\r
91 * @return the next key in the parent tree
\r
93 public int getParentTreeNextKey()
\r
95 return this.getCOSDictionary().getInt(COSName.PARENT_TREE_NEXT_KEY);
\r
99 * Returns the role map.
\r
101 * @return the role map
\r
103 @SuppressWarnings("unchecked")
\r
104 public Map<String, String> getRoleMap()
\r
106 COSBase rm = this.getCOSDictionary().getDictionaryObject(COSName.ROLE_MAP);
\r
107 if (rm instanceof COSDictionary)
\r
111 return COSDictionaryMap.convertBasicTypesToMap((COSDictionary) rm);
\r
113 catch (IOException e)
\r
115 e.printStackTrace();
\r
118 return new Hashtable<String, String>();
\r
122 * Sets the role map.
\r
124 * @param roleMap the role map
\r
126 public void setRoleMap(Map<String, String> roleMap)
\r
128 COSDictionary rmDic = new COSDictionary();
\r
129 for (String key : roleMap.keySet())
\r
131 rmDic.setName(key, roleMap.get(key));
\r
133 this.getCOSDictionary().setItem(COSName.ROLE_MAP, rmDic);
\r