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.util.ArrayList;
20 import java.util.Iterator;
21 import java.util.List;
22 import java.util.Map.Entry;
24 import org.apache.pdfbox.cos.COSBase;
25 import org.apache.pdfbox.cos.COSDictionary;
26 import org.apache.pdfbox.cos.COSName;
29 * A default attribute object.
31 * @author <a href="mailto:Johannes%20Koch%20%3Ckoch@apache.org%3E">Johannes Koch</a>
32 * @version $Revision: $
34 public class PDDefaultAttributeObject extends PDAttributeObject
38 * Default constructor.
40 public PDDefaultAttributeObject()
45 * Creates a default attribute object with a given dictionary.
47 * @param dictionary the dictionary
49 public PDDefaultAttributeObject(COSDictionary dictionary)
56 * Gets the attribute names.
58 * @return the attribute names
60 public List<String> getAttributeNames()
62 List<String> attrNames = new ArrayList<String>();
63 for (Entry<COSName, COSBase> entry : this.getCOSDictionary().entrySet())
65 COSName key = entry.getKey();
66 if (!COSName.O.equals(key))
68 attrNames.add(key.getName());
75 * Gets the attribute value for a given name.
77 * @param attrName the given attribute name
78 * @return the attribute value for a given name
80 public COSBase getAttributeValue(String attrName)
82 return this.getCOSDictionary().getDictionaryObject(attrName);
86 * Gets the attribute value for a given name.
88 * @param attrName the given attribute name
89 * @param defaultValue the default value
90 * @return the attribute value for a given name
92 protected COSBase getAttributeValue(String attrName, COSBase defaultValue)
94 COSBase value = this.getCOSDictionary().getDictionaryObject(attrName);
105 * @param attrName the attribute name
106 * @param attrValue the attribute value
108 public void setAttribute(String attrName, COSBase attrValue)
110 COSBase old = this.getAttributeValue(attrName);
111 this.getCOSDictionary().setItem(COSName.getPDFName(attrName), attrValue);
112 this.potentiallyNotifyChanged(old, attrValue);
116 public String toString()
118 StringBuilder sb = new StringBuilder().append(super.toString())
119 .append(", attributes={");
120 Iterator<String> it = this.getAttributeNames().iterator();
123 String name = it.next();
124 sb.append(name).append('=').append(this.getAttributeValue(name));
130 return sb.append('}').toString();