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 org.apache.pdfbox.cos.COSBase;
20 import org.apache.pdfbox.cos.COSDictionary;
21 import org.apache.pdfbox.cos.COSName;
22 import org.apache.pdfbox.pdmodel.common.PDDictionaryWrapper;
27 * @author <a href="mailto:Johannes%20Koch%20%3Ckoch@apache.org%3E">Johannes Koch</a>
28 * @version $Revision: $
30 public class PDUserProperty extends PDDictionaryWrapper
33 private final PDUserAttributeObject userAttributeObject;
36 * Creates a new user property.
38 * @param the user attribute object
40 public PDUserProperty(PDUserAttributeObject userAttributeObject)
42 this.userAttributeObject = userAttributeObject;
46 * Creates a user property with a given dictionary.
48 * @param dictionary the dictionary
49 * @param the user attribute object
51 public PDUserProperty(COSDictionary dictionary,
52 PDUserAttributeObject userAttributeObject)
55 this.userAttributeObject = userAttributeObject;
60 * Returns the property name.
62 * @return the property name
64 public String getName()
66 return this.getCOSDictionary().getNameAsString(COSName.N);
70 * Sets the property name.
72 * @param name the property name
74 public void setName(String name)
76 this.potentiallyNotifyChanged(this.getName(), name);
77 this.getCOSDictionary().setName(COSName.N, name);
81 * Returns the property value.
83 * @return the property value
85 public COSBase getValue()
87 return this.getCOSDictionary().getDictionaryObject(COSName.V);
91 * Sets the property value.
93 * @param value the property value
95 public void setValue(COSBase value)
97 this.potentiallyNotifyChanged(this.getValue(), value);
98 this.getCOSDictionary().setItem(COSName.V, value);
102 * Returns the string for the property value.
104 * @return the string for the property value
106 public String getFormattedValue()
108 return this.getCOSDictionary().getString(COSName.F);
112 * Sets the string for the property value.
114 * @param formattedValue the string for the property value
116 public void setFormattedValue(String formattedValue)
118 this.potentiallyNotifyChanged(this.getFormattedValue(), formattedValue);
119 this.getCOSDictionary().setString(COSName.F, formattedValue);
123 * Shall the property be hidden?
125 * @return <code>true</code> if the property shall be hidden,
126 * <code>false</code> otherwise
128 public boolean isHidden()
130 return this.getCOSDictionary().getBoolean(COSName.H, false);
134 * Specifies whether the property shall be hidden.
136 * @param hidden <code>true</code> if the property shall be hidden,
137 * <code>false</code> otherwise
139 public void setHidden(boolean hidden)
141 this.potentiallyNotifyChanged(this.isHidden(), hidden);
142 this.getCOSDictionary().setBoolean(COSName.H, hidden);
147 public String toString()
149 return new StringBuilder("Name=").append(this.getName())
150 .append(", Value=").append(this.getValue())
151 .append(", FormattedValue=").append(this.getFormattedValue())
152 .append(", Hidden=").append(this.isHidden()).toString();
157 * Notifies the user attribute object if the user property is changed.
159 * @param oldEntry old entry
160 * @param newEntry new entry
162 private void potentiallyNotifyChanged(Object oldEntry, Object newEntry)
164 if (this.isEntryChanged(oldEntry, newEntry))
166 this.userAttributeObject.userPropertyChanged(this);
171 * Is the value changed?
173 * @param oldEntry old entry
174 * @param newEntry new entry
175 * @return <code>true</code> if the entry is changed, <code>false</code>
178 private boolean isEntryChanged(Object oldEntry, Object newEntry)
180 if (oldEntry == null)
182 if (newEntry == null)
188 return !oldEntry.equals(newEntry);