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

<%@ 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="include/global.jsp" %>
 
<%! // Global vars, methods, etc
    
    // Date formatter for filenames
    private static SimpleDateFormat fileDateFormatter =
        new SimpleDateFormat("yyyy-MM-dd");
%>
 
<%	// 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)(((DbForumFactoryProxy)forumFactory).getProxiedForumFactory());
        DbDataExport exporter = new DbDataExport(dbForumFactory);
        exporter.export(false);
        response.sendRedirect("data.jsp");
        return;
    }
    
    // Do an import
    if (doImport) {
        DbForumFactory dbForumFactory = (DbForumFactory)(((DbForumFactoryProxy)forumFactory).getProxiedForumFactory());
        DbDataImport importer = new DbDataImport(dbForumFactory);
        Reader in = new FileReader(new File(JiveGlobals.getJiveHome() + System.getProperty("file.separator") + "data" + System.getProperty("file.separator") + filename));
        importer.doImport(in);
        response.sendRedirect("data.jsp");
        return;
    }
%>

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

<p>

<%  // Title of this page and breadcrumbs
    String title = "Date Import &amp; Export";
    String[][] breadcrumbs = {
        {"Main", "main.jsp"},
        {"Date Import &amp; Export", "data.jsp"}
    };
%>
<%@ include file="include/title.jsp" %>

<font size="-1">
The import and export functions allow you to read data into and write
data from your Jive Forums installation. All data uses the Jive XML format.
</font>

<p>

<font size="-1"><b>Import Jive Data</b></font>

<form action="data.jsp">
<input type="hidden" name="import" value="true">
<ul>
    <font size="-1">
    Choose a file below to import:
    <br>
    </font>
    <table>
<%  boolean foundXMLFiles = false;
    try {
        File jiveHomeDir = new File(JiveGlobals.getJiveHome() + System.getProperty("file.separator") + "data");
        String[] filenames = jiveHomeDir.list();
        for (int i=0; i<filenames.length; i++) {
            if (filenames[i].endsWith(".xml")) {
                foundXMLFiles = true;
%>
        <tr><td>&nbsp;</td>
            <td><input type="radio" name="filename" value="<%= filenames[i] %>"></td>
            <td><font size="-1"><%= filenames[i] %></font></td>
        </tr>
<%
            }
        }
    }
    catch (Exception e) {}
    
    if (!foundXMLFiles) {
%>
        <tr><td colspan="3"><font size="-1"><i>(No files to import.)</i></font></td>
        </tr>
<%
    }
    else {
%>
        <tr><td colspan="3"><input type="submit" value="Import"></td>
        </tr>
<%
    }
%>
    </table>
</ul>
</form>

<p>

<font size="-1"><b>Export Jive Data</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">
    Export current Jive data to:
    </font>
    <ul>
    <tt><%= file %></tt>
    </ul>
    <input type="submit" value="Export">
</ul>
</form>

</body>
</html>


