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