package com.dianping.cat.message.consumer.model.failure;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;

import com.dianping.cat.consumer.model.failure.entity.FailureReport;
import com.dianping.cat.consumer.model.failure.transform.DefaultJsonBuilder;
import com.site.helper.Files;

public class FailureReportStore {

	private static final SimpleDateFormat SDF = new SimpleDateFormat(
			"yyyy-MM-dd HH:mm");

	public static void storeToHtml(File file, FailureReport report) {
		try {
			Files.forIO().writeTo(file, getStoreString(report));
		} catch (IOException e) {
			throw new RuntimeException(String.format(
					"Unable to create file %s!", file), e);
		}
	}

	public static String getStoreString(FailureReport report) {
		StringBuilder result = new StringBuilder();
		DefaultJsonBuilder jsonBuilder = new DefaultJsonBuilder();

		jsonBuilder.visitFailureReport(report);

		String jsonString = jsonBuilder.getString();

		result.append("<html><head>").append("<title>")
				.append("Failure Report ").append("From ")
				.append(SDF.format(report.getStartTime())).append(" To ")
				.append(SDF.format(report.getEndTime())).append("</title>")
				.append("<body>").append(jsonString).append("</body>")
				.append("</html>");
		return result.toString();
	}
}

@@ -440,16 +440,58 @@
 :mm%22);%0A%0A
+%09private static final String END = %22%5Cn%22;%0A%0A
 %09public 
@@ -1026,39 +1026,86 @@
 tml%3E
-%3Chead%3E%22).append(%22%3Ctitle%3E%22)%0A%09%09%09%09
+%22).append(END).append(%22%3Chead%3E%22).append(END)%0A%09%09%09%09.append(%22%3Ctitle%3E%22).append(END)
 .app
@@ -1126,16 +1126,21 @@
 eport %22)
+%0A%09%09%09%09
 .append(
@@ -1147,21 +1147,16 @@
 %22From %22)
-%0A%09%09%09%09
 .append(
@@ -1181,32 +1181,37 @@
 getStartTime()))
+%0A%09%09%09%09
 .append(%22 To %22)%0A
@@ -1209,21 +1209,16 @@
 (%22 To %22)
-%0A%09%09%09%09
 .append(
@@ -1249,16 +1249,33 @@
 Time()))
+%0A%09%09%09%09.append(END)
 .append(
@@ -1285,21 +1285,28 @@
 title%3E%22)
-%0A%09%09%09%09
+.append(END)
 .append(
@@ -1314,16 +1314,33 @@
 %3Cbody%3E%22)
+%0A%09%09%09%09.append(END)
 .append(
@@ -1364,24 +1364,36 @@
 d(%22%3C/body%3E%22)
+.append(END)
 %0A%09%09%09%09.append
@@ -1403,16 +1403,28 @@
 /html%3E%22)
+.append(END)
 ;%0A%09%09retu

format the html