1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.kernel.bi.reporting;
16  
17  import java.util.HashMap;
18  import java.util.Map;
19  
20  /**
21   * <a href="ReportFormat.java.html"><b><i>View Source</i></b></a>
22   *
23   * @author Michael C. Han
24   */
25  public enum ReportFormat {
26  
27      CSV("csv"), EXCEL("excel"), HTML("html"), PDF("pdf"), RTF("rtf"),
28      TEXT("text"), XML("xml");
29  
30      public static ReportFormat parse(String value) {
31          ReportFormat reportFormat = _reportFormats.get(value);
32  
33          if (reportFormat != null) {
34              return reportFormat;
35          }
36  
37          if (EXCEL.toString().equalsIgnoreCase(value)) {
38              return EXCEL;
39          }
40          else if (HTML.toString().equalsIgnoreCase(value)) {
41              return HTML;
42          }
43          else if (PDF.toString().equalsIgnoreCase(value)) {
44              return PDF;
45          }
46          else {
47              throw new IllegalArgumentException("Invalid format " + value);
48          }
49      }
50  
51      public String toString() {
52          return _value;
53      }
54  
55      private ReportFormat(String value) {
56          _value = value;
57      }
58  
59      private static final Map<String, ReportFormat> _reportFormats =
60          new HashMap<String, ReportFormat>();
61  
62      static {
63          _reportFormats.put(CSV.toString(), CSV);
64          _reportFormats.put(EXCEL.toString(), EXCEL);
65          _reportFormats.put(HTML.toString(), HTML);
66          _reportFormats.put(PDF.toString(), PDF);
67          _reportFormats.put(RTF.toString(), RTF);
68          _reportFormats.put(TEXT.toString(), TEXT);
69          _reportFormats.put(XML.toString(), XML);
70      }
71  
72      private String _value;
73  
74  }