/** * Check if the server is ok * * @return status code */ protected int checkIfServerIsOk() { try { StringBuffer buff = getUrl(REQ_TEXT); appendKeyValue(buff, PROP_FILE, FILE_PUBLICSRV); URL url = new URL(buff.toString()); URLConnection urlc = url.openConnection(); InputStream is = urlc.getInputStream(); is.close(); return STATUS_OK; } catch (AddeURLException ae) { String aes = ae.toString(); if (aes.indexOf("Invalid project number") >= 0) { LogUtil.userErrorMessage("Invalid project number"); return STATUS_NEEDSLOGIN; } if (aes.indexOf("Invalid user id") >= 0) { LogUtil.userErrorMessage("Invalid user ID"); return STATUS_NEEDSLOGIN; } if (aes.indexOf("Accounting data") >= 0) { return STATUS_NEEDSLOGIN; } if (aes.indexOf("cannot run server 'txtgserv") >= 0) { return STATUS_OK; } LogUtil.userErrorMessage("Error connecting to server. " + ae.getMessage()); return STATUS_ERROR; } catch (Exception exc) { logException("Connecting to server:" + getServer(), exc); return STATUS_ERROR; } }
/** * Read the groups from the public.srv file on the server * * @return List of groups */ protected List readGroups() { List groups = new ArrayList(); try { String dataType = getDataType(); String type = ((dataType.length() > 0) ? "TYPE=" + dataType : "TYPE=NOTYPE"); StringBuffer buff = getUrl(REQ_TEXT); appendKeyValue(buff, PROP_FILE, FILE_PUBLICSRV); List lines = readTextLines(buff.toString()); // System.err.println ("lines:" + StringUtil.join("\n",lines)); if (lines == null) { return null; } Hashtable seen = new Hashtable(); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i).toString(); if (line.indexOf(type) < 0) { continue; } List toks = StringUtil.split(line, ",", true, true); if (toks.size() == 0) { continue; } String tok = (String) toks.get(0); int idx = tok.indexOf("="); if (idx < 0) { continue; } if (!tok.substring(0, idx).trim().equals("N1")) { continue; } String group = tok.substring(idx + 1).trim(); if (seen.get(group) != null) { continue; } seen.put(group, group); groups.add(group); } } catch (Exception e) { return null; } return groups; }
/** * Get the miscellaneous URL keywords * * @return the key value pairs */ public String getMiscKeywords() { StringBuffer buff = new StringBuffer(); appendMiscKeyValues(buff); return buff.toString(); }