Beispiel #1
0
  private void copyFileFromWAR(final String fileName) throws IOException {
    message("Copying file " + fileName + " from WAR...");
    InputStream is = null;
    OutputStream os = null;

    try {
      is = AMSetupServlet.getResourceAsStream(servletCtx, "/WEB-INF/" + fileName);
      os = new FileOutputStream(new File(installRoot + "/" + fileName));
      copy(is, os);
      message("done");
    } catch (final IOException ioe) {
      message("failed: " + ioe.getMessage());
      throw ioe;
    } finally {
      closeIfNotNull(is);
      closeIfNotNull(os);
    }
  }
Beispiel #2
0
  public String getBaseDir(HttpServletRequest req) {
    String basedir = AMSetupServlet.getPresetConfigDir();
    if ((basedir == null) || (basedir.length() == 0)) {
      String tmp = System.getProperty("user.home");
      if (File.separatorChar == '\\') {
        tmp = tmp.replace('\\', '/');
      }
      String uri = req.getRequestURI();
      int idx = uri.indexOf("/", 1);
      if (idx != -1) {
        uri = uri.substring(0, idx);
      }

      basedir = (tmp.endsWith("/")) ? tmp.substring(0, tmp.length() - 1) : tmp;
      basedir += uri;
    }

    return basedir;
  }
Beispiel #3
0
  private void unpackZipFile() throws IOException {
    message("Unzipping " + ZIP_FILE + "...");
    InputStream is = null;
    ZipInputStream zis = null;
    FileOutputStream fos = null;

    try {
      is = AMSetupServlet.getResourceAsStream(servletCtx, ZIP_FILE);
      zis = new ZipInputStream(is);

      for (ZipEntry zipEntry = zis.getNextEntry();
          zipEntry != null;
          zipEntry = zis.getNextEntry()) {
        final File outputFileName = new File(installRoot + "/" + zipEntry.getName());

        if (zipEntry.isDirectory()) {
          outputFileName.mkdir();
        } else {
          // Copy the file.
          fos = new FileOutputStream(outputFileName);
          copy(zis, fos);
          fos.close();

          // Set permissions.
          if (zipEntry.getName().endsWith(".sh") || zipEntry.getName().startsWith("bin")) {
            outputFileName.setExecutable(true);
          }
        }

        zis.closeEntry();
      }

      message("done");
    } catch (final IOException ioe) {
      error("failed: ", ioe);
      throw ioe;
    } finally {
      closeIfNotNull(fos);
      closeIfNotNull(zis);
      closeIfNotNull(is);
    }
  }
Beispiel #4
0
  private int readNewVersion() {
    final String pattern = "config/upgrade/config.ldif.";

    InputStream is = null;
    ZipInputStream zis = null;

    try {
      is = AMSetupServlet.getResourceAsStream(servletCtx, ZIP_FILE);
      zis = new ZipInputStream(is);

      for (ZipEntry zipEntry = zis.getNextEntry();
          zipEntry != null;
          zipEntry = zis.getNextEntry()) {
        final String fileName = zipEntry.getName();

        if (fileName.startsWith(pattern)) {
          final String version = fileName.substring(pattern.length());

          try {
            return Integer.parseInt(version);
          } catch (final NumberFormatException nfe) {
            // TODO: log something?
          }
        }

        zis.closeEntry();
      }
    } catch (final IOException ioe) {
      // TODO: log something?
      return 0;
    } finally {
      closeIfNotNull(zis);
      closeIfNotNull(is);
    }

    // TODO: No version found, log something?
    return 0;
  }
Beispiel #5
0
 public String getAvailablePort(int portNumber) {
   return Integer.toString(AMSetupServlet.getUnusedPort(getHostName(), portNumber, 1000));
 }