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 org.apache.maven.shared.release.transform.MavenCoordinate;
22  import org.jdom2.Element;
23  
24  /**
25   * <p>JDomMavenCoordinate class.</p>
26   *
27   * @author Robert Scholte
28   * @since 3.0
29   */
30  public class JDomMavenCoordinate implements MavenCoordinate {
31      private final Element element;
32  
33      /**
34       * <p>Constructor for JDomMavenCoordinate.</p>
35       *
36       * @param elm a {@link org.jdom2.Element} object
37       */
38      public JDomMavenCoordinate(Element elm) {
39          this.element = elm;
40      }
41  
42      @Override
43      public String getGroupId() {
44          return element.getChildTextTrim("groupId", element.getNamespace());
45      }
46  
47      @Override
48      public String getArtifactId() {
49          return element.getChildTextTrim("artifactId", element.getNamespace());
50      }
51  
52      @Override
53      public String getVersion() {
54          Element version = getVersionElement();
55          if (version == null) {
56              return null;
57          } else {
58              return version.getTextTrim();
59          }
60      }
61  
62      private Element getVersionElement() {
63          return element.getChild("version", element.getNamespace());
64      }
65  
66      @Override
67      public void setVersion(String version) {
68          JDomUtils.rewriteValue(getVersionElement(), version);
69      }
70  
71      @Override
72      public String getName() {
73          return element.getName();
74      }
75  }