home *** CD-ROM | disk | FTP | other *** search
Wrap
package allaire.cfide; import netscape.application.Alert; import netscape.application.Application; import netscape.application.Button; import netscape.application.ExternalWindow; import netscape.application.Label; import netscape.application.Target; import netscape.application.TextField; import netscape.application.View; import netscape.util.Enumeration; import netscape.util.Vector; public class CFServiceControl extends Application implements Target { static final String SERVICE_PARAM = "ServiceName"; static final String PASS_PARAM = "passkey"; static final String DEFAULT_SERVICE = "Cold Fusion Application Server"; static final String SERVICE_ACTION = "Service"; static final String GET_STATE_COMMAND = "State"; static final String START_COMMAND = "Start"; static final String STOP_COMMAND = "Stop"; static final String COMMAND_OK = "OK"; static final String COMMAND_CANCEL = "Cancel"; static final String STARTED_STATE = "Started"; static final String STOPPED_STATE = "Stopped"; static final int INVALID_PASSWORD = -100; static final String START_TITLE = "Start"; static final String STOP_TITLE = "Stop"; static final int X_PADDING = 2; static final int HORIZ_OFFSET = 4; static final int VERT_OFFSET = 4; static final int BUTTON_WIDTH = 60; static final int BUTTON_HEIGHT = 20; static final int FIELD_HEIGHT = 20; static final int PROMPT_WIDTH = 256; static final int PROMPT_HEIGHT = 120; private ExternalWindow m_prompt; private Button m_startButton; private Button m_stopButton; private Label m_label; private TextField m_passwordField; private Button m_buttonOK; private Button m_buttonCancel; private CFNetRouter netRouter; private String m_serviceName; private String m_username; private String m_password; private int m_ErrorCode; private String m_strLastErrorMessage; private String getPassword() { this.m_prompt.center(); this.m_prompt.showModally(); return this.m_passwordField.stringValue(); } public void performCommand(String commandName, Object data) { try { if (commandName.equals("OK")) { this.m_prompt.hide(); return; } if (commandName.equals("Cancel")) { this.reportError("Access denied."); this.m_passwordField.setStringValue(""); this.m_prompt.hide(); return; } this.m_strLastErrorMessage = ""; Vector vectResults = this.netRouter.callRPC("Service", commandName, this.m_serviceName); String resultMessage = ""; for(Enumeration enumResults = vectResults.elements(); enumResults.hasMoreElements(); resultMessage = (String)enumResults.nextElement()) { } this.m_startButton.setEnabled(!resultMessage.equalsIgnoreCase("Started")); this.m_stopButton.setEnabled(!resultMessage.equalsIgnoreCase("Stopped")); } catch (CFRPCServerException var7) { this.m_ErrorCode = var7.getErrorCode(); if (this.m_ErrorCode == -100) { String strPassword = this.getPassword(); if (strPassword.length() >= 1) { this.netRouter.changePassword(strPassword); ((Application)this).performCommandLater(this, commandName, (Object)null); return; } } } catch (Exception var8) { this.reportError(((Throwable)var8).getMessage()); this.m_startButton.setEnabled(true); this.m_stopButton.setEnabled(true); } } private void reportError(String errorMessage) { errorMessage.trim(); if (errorMessage == null) { errorMessage = "An unknown error occurred."; } else if (errorMessage.startsWith("<HTML>")) { errorMessage = "The Cold Fusion IDE service is not running.\n" + "It must be started from the server in order to control\n" + "other Cold Fusion services from this page."; } Alert.runAlertExternally(Alert.notificationImage(), this.m_serviceName + " error", errorMessage, "OK", (String)null, (String)null); } private String getParameter(String paramName, String defaultValue) { String paramValue = ((Application)this).parameterNamed(paramName); if (paramValue == null) { paramValue = defaultValue; } return paramValue; } public void init() { try { super.init(); this.m_strLastErrorMessage = ""; this.m_serviceName = this.getParameter("ServiceName", "Cold Fusion Application Server"); this.m_password = this.getParameter("passkey", ""); this.netRouter = new CFNetRouter("", this.m_password); this.m_startButton = new Button(1, 1, 60, 20); this.m_startButton.setTitle("Start"); this.m_startButton.setCommand("Start"); this.m_startButton.setTarget(this); int m_stopButtonX = this.m_startButton.x() + this.m_startButton.width() + 2; this.m_stopButton = new Button(m_stopButtonX, 1, 60, 20); this.m_stopButton.setTitle("Stop"); this.m_stopButton.setCommand("Stop"); this.m_stopButton.setTarget(this); View v = ((Application)this).mainRootView(); v.addSubview(this.m_startButton); v.addSubview(this.m_stopButton); this.m_prompt = new ExternalWindow(); this.m_prompt.sizeTo(256, 120); this.m_prompt.setResizable(true); this.m_label = new Label(); this.m_label.setTitle("Password: "); this.m_label.sizeToMinSize(); this.m_label.moveTo(4, 4); this.m_prompt.addSubview(this.m_label); this.m_passwordField = new TextField(this.m_label.bounds().x + this.m_label.bounds().width, 4, this.m_prompt.contentSize().width - 8 - this.m_label.bounds().width, 20); this.m_passwordField.setDrawableCharacter('*'); this.m_prompt.addSubview(this.m_passwordField); Button m_buttonCancel = new Button(this.m_passwordField.bounds().x + this.m_passwordField.bounds().width - 60 + 1, this.m_passwordField.bounds().y + this.m_passwordField.height() + 4, 60, 20); m_buttonCancel.setTitle("Cancel"); m_buttonCancel.setCommand("Cancel"); m_buttonCancel.setTarget(this); this.m_prompt.addSubview(m_buttonCancel); Button m_buttonOK = new Button(((View)m_buttonCancel).bounds().x - 60 - 4, ((View)m_buttonCancel).bounds().y, 60, 20); m_buttonOK.setTitle("OK"); m_buttonOK.setCommand("OK"); m_buttonOK.setTarget(this); this.m_prompt.addSubview(m_buttonOK); this.performCommand("State", ""); } catch (Exception var6) { this.m_strLastErrorMessage = ((Throwable)var6).getMessage(); this.reportError(this.m_strLastErrorMessage); } } }