<%@ page language="java" import="java.util.zip.*,java.util.*,java.io.*" %> Corinis Installer
Corinis Setup
<% tempdir = fixBinaryPathEnding(request.getParameter("tempDir")); webdir = request.getParameter("webDir"); xsldir = fixBinaryPathEnding(request.getParameter("xslDir")); templatedir = fixBinaryPathEnding(request.getParameter("templateDir")); logdir = fixBinaryPathEnding(request.getParameter("logDir")); filelibdir = fixBinaryPathEnding(request.getParameter("filelibDir")); filelibwebdir = fixWebPathEnding(request.getParameter("filelibwebDir")); appdir = fixBinaryPathEnding(request.getParameter("appDir")); instdir = fixBinaryPathEnding(request.getParameter("instDir")); if (request.getParameter("step") == null || "1".equals(request.getParameter("step")) || getCoreZip(instdir) == null) { %>

Step 1/5:
Basic Checks
and
Directories

Fields in orange are directories that will be created.
Fields in red need correction.
© Corinis 2005
<% } // end step 1 else { if ("2".equals(request.getParameter("step"))) { %>

Step 2/5:
Getting information for installation/setup

The most important fields are the admin password and the database configuration.
© Corinis 2005
<% } // end step 2 else { if ("3".equals(request.getParameter("step"))) { if (request.getParameter("install") == null) { %>

Step 3/5
Start installation

All information collected. Please verify the installation directories;
© Corinis 2005
<% } else { %>

Step 4/5
Installing Files....

Setup will now install all core admin files and create a configuration xml based on the information entered.
© Corinis 2005
/admin/setup.jsp?app=<%=request.getParameter("app")%>&firstrun'" name="install" value="Database setup..."/>
<% }// do the install! }// end step 3 } // end else step 2 } // end else step 1 %> <%! String tempdir = null; String webdir = null; String appdir = null; String xsldir = null; String templatedir = null; String logdir = null; String filelibdir = null; String filelibwebdir = null; String instdir = null; char pathSep; void createTilSubDir (String sdir) { String seperator; if (sdir.indexOf("/") != -1) seperator = "/"; else seperator = "\\\\"; String[] dirs = sdir.split(seperator); try { String tildir = ""; for (int i = 0; i < dirs.length; i++) { tildir += dirs[i] + "/"; new File(tildir).mkdir(); } } catch (Exception e) { // skip exceptions } } String writeInputForm (String name) { return "
"; } String writeHiddenFormParam () { return (tempdir==null?"":"") + (webdir==null?"":"") + (appdir==null?"":"") + (xsldir==null?"":"") + (logdir==null?"":"") + (instdir==null?"":"") + (filelibdir==null?"":"") + (filelibwebdir==null?"":"") + (templatedir==null?"":""); } String checkDirectories (String[] options) { for (int i=0; i < options.length; i++) { File f = new File(options[i]); if (f.exists() && f.isDirectory() && f.canWrite()) return options[i]; } return null; } String file2String (File in) { String o = null; try { FileReader r = new FileReader(in); StringWriter sw = new StringWriter(); org.apache.commons.io.CopyUtils.copy (r, sw); o = sw.toString(); r.close(); sw.close(); } catch (FileNotFoundException e) { System.err.println("File Not found: " + e.getMessage()); } catch (IOException e) { e.printStackTrace(); } return o; } String stream2String (InputStream in) { String o = null; try { StringWriter sw = new StringWriter(); org.apache.commons.io.CopyUtils.copy (in, sw); o = sw.toString(); sw.close(); } catch (IOException e) { e.printStackTrace(); } return o; } /** * Writes a String to a file. * @param in the string to write * @param out the file to write to * @param append true to append */ void string2File (String in, File out, boolean append) { try { FileWriter sw = new FileWriter(out, append); StringReader r = new StringReader(in); org.apache.commons.io.CopyUtils.copy (r, sw); r.close(); sw.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } String replaceString(String tstring, String searchString, String replaceString) { if (tstring == null) return null; StringBuffer tstr = new StringBuffer(tstring.length()); int i, j = 0; while ((i = tstring.indexOf(searchString, j)) != -1) { tstr.append(tstring.substring(j, i)); tstr.append(replaceString); j = i + searchString.length(); } tstr.append(tstring.substring(j)); return tstr.toString(); } void writeZipFiles (File zip, String prefix, File to) { try { // open the zip and see if there is a documentation/corinis.xml in there ZipInputStream in = new ZipInputStream(new FileInputStream(zip)); ZipEntry entry = in.getNextEntry(); while(entry != null) { if(entry.getName().toLowerCase().startsWith(prefix.toLowerCase()) && !entry.isDirectory()) { char sep = entry.getName().indexOf('/')!=-1?'/':'\\'; String dirName = entry.getName().substring(prefix.length()-1, entry.getName().lastIndexOf(sep)); String fname = entry.getName().substring(entry.getName().lastIndexOf(sep)); createTilSubDir(to.getAbsolutePath() + "/" + dirName); org.apache.commons.io.CopyUtils.copy (in, new FileOutputStream(to.getAbsolutePath() + "/" + dirName + "/" + fname)); } in.closeEntry(); entry = in.getNextEntry(); } in.close(); } catch (Exception ignore) { // ignore me ignore.printStackTrace(); } } String getFileFromZip (String file, File zip) { try { // open the zip and see if there is a documentation/corinis.xml in there ZipInputStream in = new ZipInputStream(new FileInputStream(zip)); ZipEntry entry = in.getNextEntry(); while(entry != null) { if (!entry.isDirectory()) { if(entry.getName().toLowerCase().endsWith(file)) { String o = stream2String(in); in.closeEntry(); in.close(); return o; } } in.closeEntry(); entry = in.getNextEntry(); } in.close(); } catch (Exception ignore) { // ignore me } return null; } /** * Get the core zip file from a specified directory */ File getCoreZip (String dir) { File path = new File(dir); File[] zips = path.listFiles(); for (int i = 0; i < zips.length; i++) { if (zips[i].getName().toLowerCase().endsWith("zip")) { if (zips[i].getName().toLowerCase().startsWith("core")) { try { // open the zip and see if there is a documentation/corinis.xml in there ZipInputStream in = new ZipInputStream(new FileInputStream(zips[i])); ZipEntry entry = in.getNextEntry(); while(entry != null) { if (!entry.isDirectory()) { if(entry.getName().toLowerCase().endsWith("corinis.xml")) { in.closeEntry(); in.close(); return zips[i]; } } in.closeEntry(); entry = in.getNextEntry(); } } catch (Exception ignore) { // ignore me } } } } return null; } /** * Checks if a web path ends with a slash, if not it is added. * @param webPath the path to check * @return the path with a fixed ending (/) */ public String fixWebPathEnding(String webPath) { if (webPath == null) return null; return webPath.endsWith("/")?webPath:(webPath+"/"); } /** * Checks and fixes a binary path (so it ends with a slash or backslash). * @param binaryPath the path to check * @return the fixed path (ending with / or \) */ public String fixBinaryPathEnding(String binaryPath) { if (binaryPath == null) return null; if (!binaryPath.endsWith("/") && !binaryPath.endsWith("\\")) { return binaryPath.indexOf('\\')!=-1?binaryPath+"\\":binaryPath+"/"; } return binaryPath; } %>