View Javadoc
1   /*
2    * Copyright 2010 FatWire Corporation. All Rights Reserved.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *    http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package tools.gsf.properties;
17  
18  import com.fatwire.assetapi.data.AssetId;
19  import tools.gsf.facade.assetapi.AssetIdUtils;
20  import org.apache.commons.lang3.StringUtils;
21  
22  import java.io.Serializable;
23  
24  /**
25   * TODO: Add class/interface details
26   *
27   * @author Tony Field
28   * @since 11-09-02
29   */
30  final class PropertyImpl implements Property, Serializable {
31      /**
32       *
33       */
34      private static final long serialVersionUID = 692797066527955686L;
35      String name;
36      String description;
37      String value;
38      String propertyAssetType;
39  
40      PropertyImpl(String propertyAssetType, String name, String description, String value) {
41          this.name = name;
42          this.value = value;
43          this.propertyAssetType = propertyAssetType;
44      }
45  
46      public String getName() {
47          return name;
48      }
49  
50      public String getDescription() {
51          return description;
52      }
53  
54      public boolean isNull() {
55          return value == null;
56      }
57  
58      public boolean asBoolean() {
59          return Boolean.getBoolean(value);
60      }
61  
62      public String asString() {
63          return value;
64      }
65  
66      public long asLong() {
67          return Long.valueOf(value);
68      }
69  
70      public int asInt() {
71          return Integer.valueOf(value);
72      }
73  
74      public AssetId asAssetId() {
75          return AssetIdUtils.fromString(value);
76      }
77  
78      public String toString() {
79          // Basic password suppression
80          if (!StringUtils.isEmpty(name) &&
81                  (name.startsWith("password") ||
82                          name.startsWith("pwd"))) {
83              return this.propertyAssetType + ":" + name + "= (value blanked by password protection mechanism)";
84          } else {
85              return this.propertyAssetType + ":" + name + "=" + value; // todo: smart password suppression
86          }
87      }
88  }