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