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