blob: ea3b7c2cadef36d9f587d4fa898abb5ed9dfe15e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
/*******************************************************************************
* Copyright (c) 2004, 2007 Boeing.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.ote.ui.define.reports.output;
import java.util.Date;
import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException;
/**
* @author Roberto E. Escobar
*/
public class OutputFactory {
private static final String SEPARATOR = ".";
private OutputFactory() {
}
public static IReportWriter getReportWriter(OutputFormat format) throws OseeArgumentException {
IReportWriter toReturn = null;
switch (format) {
case EXCEL:
toReturn = new ExcelReportWriter();
break;
case PDF:
case HTML:
case RTF:
toReturn = new ReportWriter(format.name());
break;
default:
throw new OseeArgumentException("Unsupported format [%s]", format);
}
return toReturn;
}
public static String getOutputFilename(OutputFormat format, String reportId) throws OseeArgumentException {
String extension = "";
switch (format) {
case HTML:
extension = "html";
break;
case EXCEL:
extension = "xml";
break;
case PDF:
extension = "pdf";
break;
case RTF:
extension = "rtf";
break;
default:
throw new OseeArgumentException("Unsupported format [%s]", format);
}
StringBuilder builder = new StringBuilder(reportId);
builder.append(SEPARATOR);
builder.append(Long.toString(new Date().getTime()));
builder.append(SEPARATOR);
builder.append(extension);
return builder.toString();
}
public static String getContentType(OutputFormat format) throws OseeArgumentException {
String toReturn = "";
switch (format) {
case HTML:
toReturn = "text/html";
break;
case EXCEL:
toReturn = "application/excel";
break;
case PDF:
toReturn = "application/pdf";
break;
case RTF:
toReturn = "application/rtf";
break;
default:
throw new OseeArgumentException("Unsupported format [%s]", format);
}
return toReturn;
}
}
|