001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.bi.reporting;
016    
017    import java.util.HashMap;
018    import java.util.Map;
019    
020    /**
021     * @author Michael C. Han
022     */
023    public enum ReportFormat {
024    
025            CSV("csv"), EXCEL("excel"), HTML("html"), PDF("pdf"), RTF("rtf"),
026            TEXT("text"), XML("xml");
027    
028            public static ReportFormat parse(String value) {
029                    ReportFormat reportFormat = _reportFormats.get(value);
030    
031                    if (reportFormat != null) {
032                            return reportFormat;
033                    }
034    
035                    if (EXCEL.toString().equalsIgnoreCase(value)) {
036                            return EXCEL;
037                    }
038                    else if (HTML.toString().equalsIgnoreCase(value)) {
039                            return HTML;
040                    }
041                    else if (PDF.toString().equalsIgnoreCase(value)) {
042                            return PDF;
043                    }
044                    else {
045                            throw new IllegalArgumentException("Invalid format " + value);
046                    }
047            }
048    
049            public String toString() {
050                    return _value;
051            }
052    
053            private ReportFormat(String value) {
054                    _value = value;
055            }
056    
057            private static final Map<String, ReportFormat> _reportFormats =
058                    new HashMap<String, ReportFormat>();
059    
060            static {
061                    _reportFormats.put(CSV.toString(), CSV);
062                    _reportFormats.put(EXCEL.toString(), EXCEL);
063                    _reportFormats.put(HTML.toString(), HTML);
064                    _reportFormats.put(PDF.toString(), PDF);
065                    _reportFormats.put(RTF.toString(), RTF);
066                    _reportFormats.put(TEXT.toString(), TEXT);
067                    _reportFormats.put(XML.toString(), XML);
068            }
069    
070            private String _value;
071    
072    }