View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.monitoring.reporting;
19  
20  import java.text.DateFormat;
21  import java.text.DecimalFormat;
22  import java.text.DecimalFormatSymbols;
23  import java.text.NumberFormat;
24  import java.text.SimpleDateFormat;
25  import java.util.Locale;
26  
27  import org.apache.commons.monitoring.Monitor;
28  import org.apache.commons.monitoring.Role;
29  import org.apache.commons.monitoring.Unit;
30  
31  /**
32   * Support class to implement <code>Renderer.Option</code>
33   *
34   * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
35   */
36  public class OptionsSupport
37      implements Renderer.Options
38  {
39      public boolean render( Monitor monitor )
40      {
41          return true;
42      }
43  
44      public boolean render( Role role, String attribute )
45      {
46          return true;
47      }
48  
49      public boolean renderRole( Role role )
50      {
51          return true;
52      }
53  
54  
55      public Unit unitFor( Role role )
56      {
57          return role.getUnit();
58      }
59  
60      public NumberFormat getDecimalFormat()
61      {
62          // Force JS compatible format
63          DecimalFormatSymbols symbols = new DecimalFormatSymbols();
64          symbols.setDecimalSeparator( '.' );
65          return new DecimalFormat( "0.00", symbols );
66      }
67  
68      public NumberFormat getNumberFormat()
69      {
70          return new DecimalFormat( "0" );
71      }
72  
73      public DateFormat getDateFormat()
74      {
75          return DateFormat.getDateTimeInstance( DateFormat.SHORT, DateFormat.SHORT );
76      }
77  
78  }