View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.shared.release.transform.jdom2;
20  
21  import java.io.IOException;
22  import java.io.InputStream;
23  import java.io.OutputStream;
24  import java.io.PrintStream;
25  import java.io.PrintWriter;
26  import java.io.Reader;
27  import java.io.Writer;
28  import java.util.Enumeration;
29  import java.util.InvalidPropertiesFormatException;
30  import java.util.Properties;
31  import java.util.Set;
32  
33  import org.jdom2.Element;
34  
35  /**
36   * JDOM2 implementation of poms PROPERTIES element
37   * Only few methods are properly implemented as the underlying data structure of {@link java.util.Hashtable} is never populated.
38   *
39   * @author Robert Scholte
40   * @since 3.0
41   */
42  public class JDomProperties extends Properties {
43      private final Element properties;
44  
45      /**
46       * <p>Constructor for JDomProperties.</p>
47       *
48       * @param properties a {@link org.jdom2.Element} object
49       */
50      public JDomProperties(Element properties) {
51          this.properties = properties;
52      }
53  
54      @Override
55      public synchronized Object put(Object key, Object value) {
56          Element property = properties.getChild((String) key, properties.getNamespace());
57  
58          if (property == null) {
59              property = new Element((String) key, properties.getNamespace());
60          }
61          JDomUtils.rewriteValue(property, (String) value);
62  
63          // todo follow specs of Hashtable.put
64          return null;
65      }
66  
67      @Override
68      public synchronized void load(Reader reader) throws IOException {
69          throw new UnsupportedOperationException();
70      }
71  
72      @Override
73      public synchronized void load(InputStream inStream) throws IOException {
74          throw new UnsupportedOperationException();
75      }
76  
77      @SuppressWarnings("deprecation")
78      @Override
79      public void save(OutputStream out, String comments) {
80          throw new UnsupportedOperationException();
81      }
82  
83      @Override
84      public void store(Writer writer, String comments) throws IOException {
85          throw new UnsupportedOperationException();
86      }
87  
88      @Override
89      public void store(OutputStream out, String comments) throws IOException {
90          throw new UnsupportedOperationException();
91      }
92  
93      @Override
94      public synchronized void loadFromXML(InputStream in) throws IOException, InvalidPropertiesFormatException {
95          throw new UnsupportedOperationException();
96      }
97  
98      @Override
99      public void storeToXML(OutputStream os, String comment) throws IOException {
100         throw new UnsupportedOperationException();
101     }
102 
103     @Override
104     public void storeToXML(OutputStream os, String comment, String encoding) throws IOException {
105         throw new UnsupportedOperationException();
106     }
107 
108     @Override
109     public String getProperty(String key) {
110         Element property = properties.getChild(key, properties.getNamespace());
111 
112         if (property == null) {
113             return null;
114         } else {
115             return property.getTextTrim();
116         }
117     }
118 
119     @Override
120     public boolean containsKey(Object key) {
121         if (key instanceof String) {
122             Element property = properties.getChild((String) key, properties.getNamespace());
123             return property != null;
124         }
125         return false;
126     }
127 
128     @Override
129     public String getProperty(String key, String defaultValue) {
130         String property = getProperty(key);
131 
132         return property == null ? defaultValue : property;
133     }
134 
135     @Override
136     public Enumeration<?> propertyNames() {
137         throw new UnsupportedOperationException();
138     }
139 
140     @Override
141     public Set<String> stringPropertyNames() {
142         throw new UnsupportedOperationException();
143     }
144 
145     @Override
146     public void list(PrintStream out) {
147         throw new UnsupportedOperationException();
148     }
149 
150     @Override
151     public void list(PrintWriter out) {
152         throw new UnsupportedOperationException();
153     }
154 }