// If this is a new installation, ask the user for a // port for the server; otherwise, return the negative // of the configured port. If the user selects an illegal // port, return zero. private int getPort() { // Note: directory points to the parent of the CTP directory. File ctp = new File(directory, "CTP"); if (suppressFirstPathElement) ctp = ctp.getParentFile(); File config = new File(ctp, "config.xml"); if (!config.exists()) { // No config file - must be a new installation. // Figure out whether this is Windows or something else. String os = System.getProperty("os.name").toLowerCase(); int defPort = ((os.contains("windows") && !programName.equals("ISN")) ? 80 : 1080); int userPort = 0; while (userPort == 0) { String port = JOptionPane.showInputDialog( null, "This is a new " + programName + " installation.\n\n" + "Select a port number for the web server.\n\n", Integer.toString(defPort)); try { userPort = Integer.parseInt(port.trim()); } catch (Exception ex) { userPort = -1; } if ((userPort < 80) || (userPort > 32767)) userPort = 0; } return userPort; } else { try { Document doc = getDocument(config); Element root = doc.getDocumentElement(); Element server = getFirstNamedChild(root, "Server"); String port = server.getAttribute("port"); return -Integer.parseInt(port); } catch (Exception ex) { } } return 0; }