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  
20  package org.apache.myfaces.tobago.example.demo;
21  
22  import org.slf4j.Logger;
23  import org.slf4j.LoggerFactory;
24  
25  import javax.enterprise.context.RequestScoped;
26  import javax.faces.event.AjaxBehaviorEvent;
27  import javax.inject.Named;
28  import java.io.Serializable;
29  import java.lang.invoke.MethodHandles;
30  import java.util.ArrayList;
31  import java.util.Collections;
32  import java.util.List;
33  
34  @RequestScoped
35  @Named
36  public class ApiController implements Serializable {
37  
38    private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
39  
40    private List<Release> releases;
41    private boolean onlyCurrent = true;
42  
43    public ApiController() {
44      init();
45    }
46  
47    public void init(final AjaxBehaviorEvent event) {
48      init();
49    }
50  
51    private void init() {
52      releases = new ArrayList<>();
53      for (Release release : Release.values()) {
54        if (!release.isUnreleased() && (!onlyCurrent || release.isCurrent())) {
55          releases.add(release);
56        }
57      }
58      Collections.reverse(releases);
59    }
60  
61    public List<Release> getReleases() {
62      return releases;
63    }
64  
65    public String getBase() {
66      return "http://myfaces.apache.org/tobago";
67    }
68  
69    public boolean isOnlyCurrent() {
70      return onlyCurrent;
71    }
72  
73    public void setOnlyCurrent(boolean onlyCurrent) {
74      this.onlyCurrent = onlyCurrent;
75    }
76  
77    public String getVersion430() {
78      return Release.v4_3_0.getVersion();
79    }
80  
81    public String getCurrentRelease() {
82      for (Release release : releases) {
83        if (release.isCurrent()) {
84          return release.getVersion();
85        }
86      }
87      LOG.error("No current release found!");
88      return "4.5.0"; // should not happen
89    }
90  
91    public String getJiraUrl(final String version) {
92      final Release release = Release.valueOf("v" + version.replaceAll("\\.", "_"));
93      return "https://issues.apache.org/jira/secure/ReleaseNote.jspa?projectId=12310273&version=" + release.getJira();
94    }
95  }