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