<%@ page contentType="text/html;charset=GBK" %>

<%
/**
 *	$RCSfile: data.jsp,v $
 *	$Revision: 1.1.1.1 $
 *	$Date: 2002/09/09 13:50:10 $
 */
%>

<%@ page import="java.io.*,
                 java.util.*,
				 java.text.*,
				 com.jivesoftware.util.*,
                 com.jivesoftware.forum.*,
				 com.jivesoftware.forum.database.*,
				 com.jivesoftware.forum.util.*"
    errorPage="error.jsp"
%>

<%@ include file="global.jsp" %>

<%! // Global vars, methods, etc

    // Date formatter for filenames
    final static SimpleDateFormat fileDateFormatter =
        new SimpleDateFormat("yyyy-MM-dd");
   	final static DecimalFormat megFormatter = new DecimalFormat("0.00");
    final static DecimalFormat kFormatter = new DecimalFormat("0.00");
%>

<%	// Get parameters
    boolean export = ParamUtils.getBooleanParameter(request,"export");
    boolean doImport = ParamUtils.getBooleanParameter(request,"import");
    String filename = ParamUtils.getParameter(request,"filename");

    // Do an export
    if (export) {
        DbForumFactory dbForumFactory = (DbForumFactory)(((ForumFactoryProxy)forumFactory).getProxiedForumFactory());
        DbDataExport exporter = new DbDataExport(dbForumFactory);
        exporter.export(false);
        response.sendRedirect("data.jsp");
        return;
    }

    // Do an import
    if (doImport) {
        DbForumFactory dbForumFactory = (DbForumFactory)(((ForumFactoryProxy)forumFactory).getProxiedForumFactory());
        DbDataImport importer = new DbDataImport(dbForumFactory);
        Reader in = new BufferedReader(new InputStreamReader(new FileInputStream(
				new File(JiveGlobals.getJiveHome() + System.getProperty("file.separator")
				+ "data" + System.getProperty("file.separator") + filename)),"UTF8"));
        importer.doImport(in);
		System.out.println("**DEBUG**:import data !");
        response.sendRedirect("data.jsp");
        return;
    }
%>

<%@ include file="header.jsp" %>

<p>

<%  // Title of this page and breadcrumbs
    String title = "数据导入 &amp; 导出";
    String[][] breadcrumbs = {
        {"主页面", "main.jsp"},
        {title, "data.jsp"}
    };
%>
<%@ include file="title.jsp" %>

<font size="-1">
数据导入和导出功能允许你向Jive论坛中写入数据或者从中读取数据。所有的数据都使用Jive XML 格式。
</font>

<p>

<font size="-1"><b>导入数据</b></font>

<form action="data.jsp">
<input type="hidden" name="import" value="true">
<ul>
    <font size="-1">
    请从以下文件中选择一个导入。
    <p>
    </font>
    <table bgcolor="<%= tblBorderColor %>" cellpadding="0" cellspacing="0" border="0">
    <tr><td>
    <table bgcolor="<%= tblBorderColor %>" cellpadding="3" cellspacing="1" border="0" width="100%">
    <tr bgcolor="#eeeeee">
        <td align="center"><font face="verdana" size="-2">&nbsp;</font></td>
        <td align="center"><font face="verdana" size="-2"><b>文件名</b></font></td>
        <td align="center"><font face="verdana" size="-2"><b>大小</b></font></td>
    </tr>
<%  boolean foundXMLFiles = false;
    try {
        File dataDir = new File(JiveGlobals.getJiveHome() + System.getProperty("file.separator") + "data");
        String[] filenames = dataDir.list();
        for (int i=0; i<filenames.length; i++) {
            if (filenames[i].endsWith(".xml")) {
                foundXMLFiles = true;
                File xmlFile = new File(dataDir, filenames[i]);
                double size = xmlFile.length();
                String displaySize = "";
                if ((size/(1024.0*1024.0)) < 1.0) {
                    displaySize = kFormatter.format(size/(1024.0)) + " K";
                }
                else {
                    displaySize = megFormatter.format(size/(1024.0*1024.0)) + " MB";
                }
%>
        <tr bgcolor="#ffffff"><td><input type="radio" name="filename" value="<%= filenames[i] %>" id="rb<%= i %>"></td>
            <td>
                <font size="-1">
                <nobr><label for="rb<%= i %>"><%= filenames[i] %></label>&nbsp;&nbsp;&nbsp;</nobr>
                </font>
            </td>
            <td>
                <font size="-1">
                <%= displaySize %>
                </font>
            </td>
        </tr>
<%
            }
        }
    }
    catch (Exception e) {}

    if (!foundXMLFiles) {
%>
        <tr bgcolor="#ffffff">
            <td colspan="3" align="center"><font size="-1"><i>没有可导入的文件。</i></font></td>
        </tr>
<%
    }
%>
    </table>
    </td></tr>
    </table>
    <%  if (foundXMLFiles) { %>
    <p>
    <input type="submit" value="导入">
    <%  } %>
</ul>
</form>

<p>

<font size="-1"><b>导出数据</b></font>

<%  String file = JiveGlobals.getJiveHome() + System.getProperty("file.separator") + "data" + System.getProperty("file.separator") + fileDateFormatter.format(new Date()) + ".xml";
%>

<form action="data.jsp">
<input type="hidden" name="export" value="true">
<ul>
    <font size="-1">
    将当前数据导出到:
    </font>
    <ul>
    <tt><%= file %></tt>
    </ul>
    <input type="submit" value="导出">
</ul>
</form>

</body>
</html>


