📄 graphicalinstaller.java
字号:
/* * @(#)GraphicalInstaller.java 1.22 02/09/12 @(#) * * Copyright (c) 2001-2002 Sun Microsystems, Inc. All rights reserved. * PROPRIETARY/CONFIDENTIAL * Use is subject to license terms. */package com.sun.midp.dev;import java.io.*;import java.util.*;import javax.microedition.io.*;import javax.microedition.lcdui.*;import javax.microedition.midlet.*;import javax.microedition.rms.*;import com.sun.midp.io.j2me.storage.*;import com.sun.midp.lcdui.Resource;import com.sun.midp.midlet.*;import com.sun.midp.midletsuite.*;import com.sun.midp.security.*;/** * The Graphical MIDlet suite manager. * <p> * Let the user install a suite from a list of suites * obtained using an HTML URL given by the user. This list is derived by * extracting the links with hrefs that are in quotes and end with ".jad" from * the HTML page. An href in an extracted link is assumed to be an absolute * URL for a MIDP application descriptor. */public class GraphicalInstaller extends MIDlet implements CommandListener { /** Standard timeout for alerts. */ static final int ALERT_TIMEOUT = 1250; /** settings database */ static final String SETTINGS_STORE = "settings"; /** record id of selected midlet */ static final int URL_RECORD_ID = 1; /** record is of the last installed midlet */ static final int SELECTED_MIDLET_RECORD_ID = 2; /** So the static method can know if there is a color display. */ static boolean colorDisplay; /** The installer that is being used to install or update a suite. */ private Installer installer; /** Display for this MIDlet. */ private Display display; /** Contains the default URL for the install list. */ private String defaultInstallListUrl = "http://"; /** Contains the URL the user typed in. */ private TextBox urlTextBox; /** Form obtain a password and a username. */ private Form passwordForm; /** Contains the username for installing. */ private TextField usernameField; /** Contains the password for installing. */ private TextField passwordField; /** Background installer that holds state for the current install. */ private BackgroundInstaller backgroundInstaller; /** Displays the progress of the install. */ private Form progressForm; /** Gauge for progress form index. */ private int progressGaugeIndex; /** URL for progress form index. */ private int progressUrlIndex; /** Keeps track of when the display last changed, in millseconds. */ private long lastDisplayChange; /** What to display to the user when the current action is cancelled. */ private String cancelledMessage; /** What to display to the user when the current action is finishing. */ private String finishingMessage; /** Displays a list of suites to install to the user. */ private List installListBox; /** Contains a list of suites to install. */ private Vector installList; /** Command object for "Back" command in the URL form. */ private Command endCmd = new Command(Resource.getString("Back"), Command.BACK, 1); /** Command object for URL screen to go and discover available suites. */ private Command discoverCmd = new Command(Resource.getString("Go"), Command.SCREEN, 1); /** Command object for URL screen to save the URL for suites. */ private Command saveCmd = new Command(Resource.getString("Save"), Command.SCREEN, 2); /** Command object for "Back" command in the suite list form. */ private Command backCmd = new Command(Resource.getString("Back"), Command.BACK, 1); /** Command object for "Install" command in the suite list form . */ private Command installCmd = new Command( Resource.getString("Install"), Command.ITEM, 1); /** Command object for "Stop" command for progress form. */ private Command stopCmd = new Command(Resource.getString("Stop"), Command.STOP, 1); /** Command object for "Cancel" command for the confirm form. */ private Command cancelCmd = new Command( Resource.getString("Cancel"), Command.CANCEL, 1); /** Command object for "Install" command for the confirm download form. */ private Command continueCmd = new Command(Resource.getString("Install"), Command.OK, 1); /** Command object for "Next" command for password form. */ private Command nextCmd = new Command(Resource.getString("Next"), Command.OK, 1); /** Command object for "continue" command for warning form. */ private Command okCmd = new Command(Resource.getString("Continue"), Command.OK, 1); /** Command object for "OK" command for exception form. */ private Command exceptionCmd = new Command(Resource.getString("OK"), Command.OK, 1); /** Command object for "Yes" command for keep RMS form. */ private Command keepRMSCmd = new Command(Resource.getString("Yes"), Command.OK, 1); /** Command object for "No" command for keep RMS form. */ private Command removeRMSCmd = new Command(Resource.getString("No"), Command.CANCEL, 1); /** * Gets an icon from storage. * * @param iconName name without a path * @return icon image */ static Image getIconFromStorage(String iconName) { String iconFilename; RandomAccessStream stream; byte[] rawPng; iconFilename = File.getStorageRoot() + iconName; stream = new RandomAccessStream(); try { stream.connect(iconFilename, Connector.READ); rawPng = new byte[stream.getSizeOf()]; stream.readBytes(rawPng, 0, rawPng.length); stream.disconnect(); return Image.createImage(rawPng, 0, rawPng.length); } catch (java.io.IOException noImage) { } return null; } /** * Translate an InvalidJadException into a message for the user. * * @param exception exception to translate * @param name name of the MIDlet suite to insert into the message * @param vendor vendor of the MIDlet suite to insert into the message, * can be null * @param version version of the MIDlet suite to insert into the message, * can be null * @param jadUrl URL of a JAD, can be null * * @return message to display to the user */ private static String translateJadException( InvalidJadException exception, String name, String vendor, String version, String jadUrl) { String[] values = {name, vendor, version, jadUrl, exception.getExtraData()}; String key; switch (exception.getReason()) { case InvalidJadException.OLD_VERSION: key = "An OLDER version of %1 has been found. " + "Continuing will replace the version installed on your " + "phone.\n\n" + "Currently installed: %5\n" + "Version found: %3\n" + "Vendor: %2\n" + "Website: %4\n\n" + "Would you like to continue?"; break; case InvalidJadException.ALREADY_INSTALLED: key = "This version of %1 is already installed on your phone. " + "Continuing will replace the version installed on your " + "phone.\n\n" + "Currently installed: %5\n" + "Version found: %3\n" + "Vendor: %2\n" + "Website: %4\n\n" + "Would you like to continue?"; break; case InvalidJadException.NEW_VERSION: key = "A NEWER version of %1 is has been found. " + "Continuing will replace the version installed on your " + "phone.\n\n" + "Currently installed: %5\n" + "Latest available: %3\n" + "Vendor: %2\n" + "Website: %4\n\n" + "Would you like to continue?"; break; case InvalidJadException.JAD_SERVER_NOT_FOUND: case InvalidJadException.JAD_NOT_FOUND: case InvalidJadException.INVALID_JAD_URL: key = "%1 cannot be found at this URL. " + "Contact the application provider for more information."; break; case InvalidJadException.INVALID_JAD_TYPE: key = "The application file (.jad) for %1 does not appear to " + "be the correct type. Contact the application provider " + "for more information."; break; case InvalidJadException.MISSING_PROVIDER_CERT: case InvalidJadException.MISSING_SUITE_NAME: case InvalidJadException.MISSING_VENDOR: case InvalidJadException.MISSING_VERSION: case InvalidJadException.MISSING_JAR_URL: case InvalidJadException.MISSING_JAR_SIZE: key = "%1 cannot be installed because critical information is " + "missing from the application file (.jad)."; break; case InvalidJadException.MISSING_CONFIGURATION: case InvalidJadException.MISSING_PROFILE: key = "%1 cannot be installed because critical information is " + "missing from the application file (.jar)."; break; case InvalidJadException.INVALID_KEY: case InvalidJadException.INVALID_VALUE: case InvalidJadException.INVALID_VERSION: case InvalidJadException.PUSH_FORMAT_FAILURE: case InvalidJadException.PUSH_CLASS_FAILURE: key = "%1 cannot be installed because critical " + "information is not formatted correctly or is invalid. " + "Contact your application provider to correct this " + "situation."; break; case InvalidJadException.DEVICE_INCOMPATIBLE: key = "%1 is not designed to work with this device and cannot " + "be installed."; break; case InvalidJadException.JAD_MOVED: key = "The new version of %1 is not from the same provider " + "as the old version. The download URLs do not match. " + "Do you want to install the new version?" + "\n\nOld URL: %5\nNew URL: %4"; break; case InvalidJadException.INSUFFICIENT_STORAGE: key = "There is not enough room to install %1 (%5K is needed " + "for installation.). Try removing other items to free " + "up space."; break; case InvalidJadException.JAR_SERVER_NOT_FOUND: case InvalidJadException.JAR_NOT_FOUND: case InvalidJadException.INVALID_JAR_URL: key = "The application file (.jar) for %1 cannot be found at " + "its URL. Contact the application provider for more " + "information."; break; case InvalidJadException.INVALID_JAR_TYPE: key = "The application file (.jar) for %1 does not appear to " + "be the correct type. Contact the application provider " + "for more information."; break; case InvalidJadException.SUITE_NAME_MISMATCH: case InvalidJadException.VERSION_MISMATCH: case InvalidJadException.VENDOR_MISMATCH: case InvalidJadException.JAR_SIZE_MISMATCH: case InvalidJadException.ATTRIBUTE_MISMATCH: key = "%1 cannot be installed because critical information " + "between the website and the application file does not " + "match."; break; case InvalidJadException.CORRUPT_JAR: key = "The application file (.jar) for %1 appears to be " + "corrupt. Contact the application provider " + "for more information."; break; case InvalidJadException.CANNOT_AUTH: key = "The website has requested to authenticate the user " + "in way that this device does not support."; break; case InvalidJadException.CORRUPT_PROVIDER_CERT: case InvalidJadException.INVALID_PROVIDER_CERT: case InvalidJadException.CORRUPT_SIGNATURE: case InvalidJadException.INVALID_SIGNATURE: case InvalidJadException.UNSUPPORTED_CERT: key = "%1 cannnot be installed because the application files " + "cannot verified. Contact your application " + "provider to correct this situation."; break; case InvalidJadException.UNKNOWN_CA: key = "%1 cannot be installed. The system does recognize who " + "is trying to authorize the application. Contact your " + "service provider to correct this situation. \n\n%5"; break; case InvalidJadException.EXPIRED_PROVIDER_CERT: key = "%1 cannot be installed. The trusted certificate used to " + "authorize the application has expired. Contact your " + "application provider to correct this situation."; break; case InvalidJadException.EXPIRED_CA_KEY: key = "%1 cannot be installed. The public key used for " + "authorization has expired. Contact your service " + "provider to correct this situation."; break; case InvalidJadException.AUTHORIZATION_FAILURE: key = "%1 cannot be installed because it does not have " + "permission to the operation it requires."; break; case InvalidJadException.PUSH_DUP_FAILURE: key = "%1 cannot be installed. %1 is requires the use of a " + "particular network resource to listen for network " + "information. This resource is in use by another " + "application. Try removing the other application and " + "re-installing."; break; case InvalidJadException.PUSH_PROTO_FAILURE: key = "%1 cannot be installed. %1 is requires the use of a " + "particular network resource to listen for network " + "information. This network resource is not supported on " + "this device."; break; case InvalidJadException.TRUSTED_OVERWRITE_FAILURE: key = "The new version of %1, cannot be installed. " + "The old version of %1 is authorized by %5. " + "The new version is not authorized. " + "Authorized applications cannot be replaced by " + "unauthorized applications."; break; default: return exception.getMessage(); } return Resource.getString(key, values); } /** * Create and initialize a new graphical installer MIDlet. * The Display is retreived and the list of MIDlet will be retrived or * update a currently installed suite. */ GraphicalInstaller() { String storageName; installer = Installer.getInstaller(); display = Display.getDisplay(this); colorDisplay = display.isColor(); initSettings(); restoreSettings(); storageName = getAppProperty("storageName"); if (storageName != null) { updateSuite(storageName); return; } // get the URL of a list of suites to install getUrl(); } /** * Start. */ public void startApp() { } /** * Pause; there are no resources that need to be released. */ public void pauseApp() { } /** * Destroy cleans up. * * @param unconditional is ignored; this object always * destroys itself when requested. */ public void destroyApp(boolean unconditional) { if (installer != null) { installer.stopInstalling(); } /* The backgroundInstaller could be waiting for the user. */ cancelBackgroundInstall(); } /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -