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.inject.Named;
26  import java.lang.invoke.MethodHandles;
27  import java.text.ParseException;
28  import java.text.SimpleDateFormat;
29  import java.util.Calendar;
30  import java.util.Currency;
31  import java.util.Date;
32  import java.util.GregorianCalendar;
33  
34  @Named
35  public class CurrentValueController {
36  
37    private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
38  
39    private String string;
40    private Date date;
41    private Currency currency;
42  
43    public CurrentValueController() {
44  
45      string = "simple string";
46  
47      try {
48        this.date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("1969-07-24 16:50:35");
49      } catch (final ParseException e) {
50        LOG.error("", e);
51      }
52  
53      currency = Currency.getInstance("TTD");
54    }
55  
56    public String toUpperCase(final String text) {
57      return text != null ? text.toUpperCase() : null;
58    }
59  
60    public Date plus50(final Date base) {
61      if (date == null) {
62        return null;
63      }
64      final GregorianCalendar calendar = new GregorianCalendar();
65      calendar.setTime(date);
66      calendar.add(Calendar.YEAR, 50);
67      return calendar.getTime();
68    }
69  
70    public Currency toCurrency(final String currencyString) {
71      return Currency.getInstance(currencyString);
72    }
73  
74    public String getString() {
75      return string;
76    }
77  
78    public Date getDate() {
79      return date;
80    }
81  
82    public Currency getCurrency() {
83      return currency;
84    }
85  }