]> _ Git - cubeextranet.git/blob
e94ac16e9b016a46339c1d17d7bb93aeaeece0d6
[cubeextranet.git] /
1 /*\r
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
8  *\r
9  *      http://www.apache.org/licenses/LICENSE-2.0\r
10  *\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
16  */\r
17 package org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure;\r
18 \r
19 import java.util.ArrayList;\r
20 import java.util.List;\r
21 \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
25 \r
26 /**\r
27  * A User attribute object.\r
28  * \r
29  * @author <a href="mailto:Johannes%20Koch%20%3Ckoch@apache.org%3E">Johannes Koch</a>\r
30  * @version $Revision: $\r
31  */\r
32 public class PDUserAttributeObject extends PDAttributeObject\r
33 {\r
34 \r
35     /**\r
36      * Attribute owner for user properties\r
37      */\r
38     public static final String OWNER_USER_PROPERTIES = "UserProperties";\r
39 \r
40 \r
41     /**\r
42      * Default constructor\r
43      */\r
44     public PDUserAttributeObject()\r
45     {\r
46         this.setOwner(OWNER_USER_PROPERTIES);\r
47     }\r
48 \r
49     /**\r
50      * \r
51      * @param dictionary the dictionary\r
52      */\r
53     public PDUserAttributeObject(COSDictionary dictionary)\r
54     {\r
55         super(dictionary);\r
56     }\r
57 \r
58 \r
59     /**\r
60      * Returns the user properties.\r
61      * \r
62      * @return the user properties\r
63      */\r
64     public List<PDUserProperty> getOwnerUserProperties()\r
65     {\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
70         {\r
71             properties.add(\r
72                 new PDUserProperty((COSDictionary) p.getObject(i), this));\r
73         }\r
74         return properties;\r
75     }\r
76 \r
77     /**\r
78      * Sets the user properties.\r
79      * \r
80      * @param userProperties the user properties\r
81      */\r
82     public void setUserProperties(List<PDUserProperty> userProperties)\r
83     {\r
84         COSArray p = new COSArray();\r
85         for (PDUserProperty userProperty : userProperties)\r
86         {\r
87             p.add(userProperty);\r
88         }\r
89         this.getCOSDictionary().setItem(COSName.P, p);\r
90     }\r
91 \r
92     /**\r
93      * Adds a user property.\r
94      * \r
95      * @param userProperty the user property\r
96      */\r
97     public void addUserProperty(PDUserProperty userProperty)\r
98     {\r
99         COSArray p = (COSArray) this.getCOSDictionary()\r
100             .getDictionaryObject(COSName.P);\r
101         p.add(userProperty);\r
102         this.notifyChanged();\r
103     }\r
104 \r
105     /**\r
106      * Removes a user property.\r
107      * \r
108      * @param userProperty the user property\r
109      */\r
110     public void removeUserProperty(PDUserProperty userProperty)\r
111     {\r
112         if (userProperty == null)\r
113         {\r
114             return;\r
115         }\r
116         COSArray p = (COSArray) this.getCOSDictionary()\r
117             .getDictionaryObject(COSName.P);\r
118         p.remove(userProperty.getCOSObject());\r
119         this.notifyChanged();\r
120     }\r
121 \r
122     public void userPropertyChanged(PDUserProperty userProperty)\r
123     {\r
124         \r
125     }\r
126 \r
127     @Override\r
128     public String toString()\r
129     {\r
130         return new StringBuilder().append(super.toString())\r
131             .append(", userProperties=")\r
132             .append(this.getOwnerUserProperties()).toString();\r
133     }\r
134 \r
135 }\r