001: /**
002: *
003: */package org.emforge.report;
004:
005: import java.util.ArrayList;
006: import java.util.Collection;
007:
008: import javax.faces.model.SelectItem;
009:
010: /**
011: * Contains all supported report view types and knows how to export it
012: *
013: * @author szakusov, 11.03.2008: Implemented to keep all report view types in one place
014: * @todo Format name should be expanded to full name, for example:
015: * <pre>
016: * "PDF" -> "Portable Document Format (PDF)"
017: * </pre>
018: * but in this case we should change some jsp's to display the format names in a listbox
019: */
020: public enum ReportView {
021:
022: PDF(801, "PDF", ".pdf", "application/pdf"), XLS(802, "XLS", ".xls",
023: "application/vnd.ms-excel"), HTML(803, "HTML", ".html",
024: "text/html"), CSV(804, "CSV", ".csv",
025: "text/comma-separated-values"), ODT(805, "ODT", ".odt",
026: "application/odt");
027:
028: private int m_formatType; // format type id
029: private String m_formatName; // format name
030: private String m_extension; // file extension of specified format
031: private String m_contentType; // content type
032:
033: /**
034: * @param i_formatType
035: * @param i_formatName
036: * @param i_extension
037: * @param i_contentType
038: */
039: private ReportView(int i_formatType, String i_formatName,
040: String i_extension, String i_contentType) {
041:
042: m_formatType = i_formatType;
043: m_formatName = i_formatName;
044: m_extension = i_extension;
045: m_contentType = i_contentType;
046: }
047:
048: /**
049: * @return Format type
050: */
051: public int getFormatType() {
052:
053: return m_formatType;
054: }
055:
056: /**
057: * @return Format name
058: */
059: public String getFormatName() {
060:
061: return m_formatName;
062: }
063:
064: /**
065: * @return
066: */
067: public String getExtension() {
068:
069: return m_extension;
070: }
071:
072: /**
073: * @return
074: */
075: public String getContentType() {
076:
077: return m_contentType;
078: }
079:
080: /**
081: * @param i_formatType
082: * @return
083: */
084: public boolean equals(int i_formatType) {
085:
086: return m_formatType == i_formatType;
087: }
088:
089: /**
090: * @param i_formatType
091: * @return
092: */
093: public static ReportView getView(int i_formatType) {
094:
095: ReportView result = null;
096:
097: for (ReportView type : ReportView.values()) {
098: if (type.getFormatType() == i_formatType) {
099: result = type;
100: break;
101: }
102: }
103:
104: return result;
105: }
106:
107: /**
108: * @return
109: */
110: public static Collection<SelectItem> getSelectItems() {
111:
112: Collection<SelectItem> result = new ArrayList<SelectItem>();
113:
114: for (ReportView type : ReportView.values()) {
115: result.add(new SelectItem(type.getFormatType(), type
116: .getFormatName()));
117: }
118:
119: return result;
120: }
121: }
|