[pal-cvs 3885] [1620] supported csv download, and minor fixes.

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2008年 12月 23日 (火) 11:59:53 JST


Revision: 1620
          http://svn.sourceforge.jp/view?root=pal&view=rev&rev=1620
Author:   shinsuke
Date:     2008-12-23 11:59:52 +0900 (Tue, 23 Dec 2008)

Log Message:
-----------
supported csv download, and minor fixes.

Added Paths:
-----------
    timecard/trunk/src/main/java/jp/sf/pal/timecard/util/ReportUtil.java


-------------- next part --------------
Added: timecard/trunk/src/main/java/jp/sf/pal/timecard/util/ReportUtil.java
===================================================================
--- timecard/trunk/src/main/java/jp/sf/pal/timecard/util/ReportUtil.java	                        (rev 0)
+++ timecard/trunk/src/main/java/jp/sf/pal/timecard/util/ReportUtil.java	2008-12-23 02:59:52 UTC (rev 1620)
@@ -0,0 +1,141 @@
+package jp.sf.pal.timecard.util;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+import javax.servlet.http.HttpServletResponse;
+
+import jp.sf.pal.timecard.db.exentity.DailyReport;
+import jp.sf.pal.timecard.db.exentity.MonthlyReport;
+
+import org.seasar.framework.exception.IORuntimeException;
+import org.seasar.struts.util.ResponseUtil;
+
+public class ReportUtil {
+    public static void downloadCsv(String fileName, byte[] data) {
+        HttpServletResponse response = ResponseUtil.getResponse();
+        try {
+            response.setContentType("application/x-csv");
+            response.setHeader("Content-disposition", "attachment; filename=\""
+                    + fileName + "\"");
+            OutputStream out = response.getOutputStream();
+            try {
+                out.write(data);
+            } finally {
+                out.close();
+            }
+        } catch (IOException e) {
+            throw new IORuntimeException(e);
+        }
+    }
+
+    public static String getCsvReport(MonthlyReport monthlyReport, Locale locale) {
+        ResourceBundle resourceBundle = ResourceBundle.getBundle("application",
+                locale);
+
+        String year = monthlyReport.getYear().toString();
+        String month = monthlyReport.getMonth().toString();
+        if (month.length() == 1) {
+            month = "0" + month;
+        }
+        StringBuilder sb = new StringBuilder();
+        sb.append(resourceBundle.getString("labels.date"));
+        sb.append(",");
+        sb.append(resourceBundle.getString("labels.s_start_time"));
+        sb.append(",");
+        sb.append(resourceBundle.getString("labels.s_end_time"));
+        sb.append(",");
+        sb.append(resourceBundle.getString("labels.s_break_time"));
+        sb.append(",");
+        sb.append(resourceBundle.getString("labels.s_otj_time"));
+        sb.append(",");
+        sb.append(resourceBundle.getString("labels.s_working_time"));
+        sb.append(",");
+        sb.append(resourceBundle.getString("labels.s_working_status"));
+        sb.append(",");
+        sb.append(resourceBundle.getString("labels.reason"));
+        sb.append(",");
+        sb.append("\r\n");
+        for (DailyReport dailyReport : monthlyReport.getDailyReportList()) {
+            sb.append(year + "/" + month + "/"
+                    + dailyReport.getDate().toString());
+            sb.append(",");
+            sb.append(convertEmptyIfNull(dailyReport.getFormattedStartTime()));
+            sb.append(",");
+            sb.append(convertEmptyIfNull(dailyReport.getFormattedEndTime()));
+            sb.append(",");
+            sb.append(convertEmptyIfNull(dailyReport.getFormattedBreakTime()));
+            sb.append(",");
+            sb.append(convertEmptyIfNull(dailyReport.getFormattedOtjTime()));
+            sb.append(",");
+            sb
+                    .append(convertEmptyIfNull(dailyReport
+                            .getFormattedWorkingTime()));
+            sb.append(",");
+            sb.append(getWorkTypeLabel(resourceBundle, dailyReport
+                    .getWorkingType()));
+            sb.append(",");
+            sb.append("\""
+                    + convertEmptyIfNull(dailyReport.getMemo()).replaceAll(
+                            "\"", "\"\"") + "\"");
+            sb.append("\r\n");
+        }
+        return sb.toString();
+    }
+
+    private static String convertEmptyIfNull(String value) {
+        if (value != null) {
+            return value;
+        }
+        return "";
+    }
+
+    private static String getWorkTypeLabel(ResourceBundle resourceBundle,
+            int workingType) {
+        if (workingType == 1) {
+            return resourceBundle.getString("labels.ws1");
+        } else if (workingType == 2) {
+            return resourceBundle.getString("labels.ws2");
+        } else if (workingType == 3) {
+            return resourceBundle.getString("labels.ws3");
+        } else if (workingType == 4) {
+            return resourceBundle.getString("labels.ws4");
+        } else if (workingType == 200) {
+            return resourceBundle.getString("labels.ws200");
+        } else if (workingType == 100) {
+            return resourceBundle.getString("labels.ws100");
+        } else if (workingType == 101) {
+            return resourceBundle.getString("labels.ws101");
+        } else if (workingType == 102) {
+            return resourceBundle.getString("labels.ws102");
+        } else if (workingType == 20) {
+            return resourceBundle.getString("labels.ws20");
+        } else if (workingType == 21) {
+            return resourceBundle.getString("labels.ws21");
+        } else if (workingType == 22) {
+            return resourceBundle.getString("labels.ws22");
+        } else if (workingType == 30) {
+            return resourceBundle.getString("labels.ws30");
+        } else if (workingType == 31) {
+            return resourceBundle.getString("labels.ws31");
+        } else if (workingType == 32) {
+            return resourceBundle.getString("labels.ws32");
+        } else if (workingType == 40) {
+            return resourceBundle.getString("labels.ws40");
+        } else if (workingType == 41) {
+            return resourceBundle.getString("labels.ws41");
+        } else if (workingType == 42) {
+            return resourceBundle.getString("labels.ws42");
+        } else if (workingType == 110) {
+            return resourceBundle.getString("labels.ws110");
+        } else if (workingType == 111) {
+            return resourceBundle.getString("labels.ws111");
+        } else if (workingType == 112) {
+            return resourceBundle.getString("labels.ws112");
+        }
+        return "";
+
+    }
+}


Property changes on: timecard/trunk/src/main/java/jp/sf/pal/timecard/util/ReportUtil.java
___________________________________________________________________
Name: svn:eol-style
   + native


pal-cvs メーリングリストの案内
Back to archive index