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.List;
\r
22 import org.apache.pdfbox.cos.COSArray;
\r
23 import org.apache.pdfbox.cos.COSDictionary;
\r
24 import org.apache.pdfbox.cos.COSName;
\r
27 * A User attribute object.
\r
29 * @author <a href="mailto:Johannes%20Koch%20%3Ckoch@apache.org%3E">Johannes Koch</a>
\r
30 * @version $Revision: $
\r
32 public class PDUserAttributeObject extends PDAttributeObject
\r
36 * Attribute owner for user properties
\r
38 public static final String OWNER_USER_PROPERTIES = "UserProperties";
\r
42 * Default constructor
\r
44 public PDUserAttributeObject()
\r
46 this.setOwner(OWNER_USER_PROPERTIES);
\r
51 * @param dictionary the dictionary
\r
53 public PDUserAttributeObject(COSDictionary dictionary)
\r
60 * Returns the user properties.
\r
62 * @return the user properties
\r
64 public List<PDUserProperty> getOwnerUserProperties()
\r
66 COSArray p = (COSArray) this.getCOSDictionary()
\r
67 .getDictionaryObject(COSName.P);
\r
68 List<PDUserProperty> properties = new ArrayList<PDUserProperty>(p.size());
\r
69 for (int i = 0; i < p.size(); i++)
\r
72 new PDUserProperty((COSDictionary) p.getObject(i), this));
\r
78 * Sets the user properties.
\r
80 * @param userProperties the user properties
\r
82 public void setUserProperties(List<PDUserProperty> userProperties)
\r
84 COSArray p = new COSArray();
\r
85 for (PDUserProperty userProperty : userProperties)
\r
87 p.add(userProperty);
\r
89 this.getCOSDictionary().setItem(COSName.P, p);
\r
93 * Adds a user property.
\r
95 * @param userProperty the user property
\r
97 public void addUserProperty(PDUserProperty userProperty)
\r
99 COSArray p = (COSArray) this.getCOSDictionary()
\r
100 .getDictionaryObject(COSName.P);
\r
101 p.add(userProperty);
\r
102 this.notifyChanged();
\r
106 * Removes a user property.
\r
108 * @param userProperty the user property
\r
110 public void removeUserProperty(PDUserProperty userProperty)
\r
112 if (userProperty == null)
\r
116 COSArray p = (COSArray) this.getCOSDictionary()
\r
117 .getDictionaryObject(COSName.P);
\r
118 p.remove(userProperty.getCOSObject());
\r
119 this.notifyChanged();
\r
122 public void userPropertyChanged(PDUserProperty userProperty)
\r
128 public String toString()
\r
130 return new StringBuilder().append(super.toString())
\r
131 .append(", userProperties=")
\r
132 .append(this.getOwnerUserProperties()).toString();
\r