⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xletinstallerimpl.java

📁 This is a resource based on j2me embedded,if you dont understand,you can connection with me .
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                // Now it is time to install the applications into the system        Properties apps[] = desc.getApplications();        if (apps == null) {            return null;        }                Hashtable installedContentHashtable = new Hashtable();        for (int i = 0; i < apps.length; i++) {            Properties app = apps[i];                        // sanity check            if (app == null) {                continue;            }                        String appTitle = app.getProperty("JUMPApplication_title");            if (appTitle == null) {                return null;            }                        // Properties object to hold application properties to be written to .app file            // The key values in this properties object should match the key values            // defined for application descriptor files.            Properties appProperties = new Properties();                        String appIDHashKey = getAvailableAppIdHashKey();            if (appIDHashKey == null) {                trace("ERROR: Could not obtain an id hash key value.");                return null;            } else {                appProperties.setProperty(DESCRIPTOR_ID_KEY, appIDHashKey);            }                        // Retrieve the filename of the icon            //String iconFileName = app.getIconPath().getFile();            String iconFileName = app.getProperty("JUMPApplication_iconPath");                        // extract the icon image from the jar file and place it in            // the icons/ directory within the app repository            String iconPath = extractIconFromJar(jarPath, iconFileName.trim(), appIDHashKey);                        // create an app descriptor file in the menu/ directory for            // the new app so that the appmanager can recognize it.            // make sure the descriptor pathname is uniqe and doesn't exist.            String descriptorsDir = REPOSITORY_DESCRIPTORS_DIRNAME + '/';                        appProperties.setProperty(DESCRIPTOR_BUNDLENAME_KEY, bundleName);            appProperties.setProperty(DESCRIPTOR_APPMODEL_KEY, app.getProperty("JUMPApplication_appModel"));            appProperties.setProperty(getInstallerInitialClassKey(), app.getProperty(getPropertyInstallerInitialClassKey()));            appProperties.setProperty(DESCRIPTOR_JARPATH_KEY, jarPath);            appProperties.setProperty(DESCRIPTOR_TITLE_KEY, appTitle);            if (iconPath != null) {                appProperties.setProperty(DESCRIPTOR_ICON_KEY, iconPath);            }            String securityLevel = desc.getSecurityLevel();            if (securityLevel != null) {                appProperties.setProperty(DESCRIPTOR_SECURITYLEVEL_KEY, securityLevel);            }                        String appDescriptorPath = descriptorsDir + appTitle + '-' + appIDHashKey + APP_DESCRIPTOR_EXTENSION;            if (new File(appDescriptorPath).exists()) {                System.out.println("*** Error installing bundle: A descriptor with this name is already installed.");                return null;            }            // create application descriptor file            boolean result = createAppDescriptor(appDescriptorPath, appProperties);            // create JUMPApplication object for the app            if (result) {                JUMPApplication module = createJUMPApplication(appDescriptorPath);                trace("--> createJUMPApplication returns: " + module.toString());                if (module != null) {                    installedContentHashtable.put(appIDHashKey, module);                    addInstalledAppIdEntry(appIDHashKey, module);                }            }        }                // return installed content        int size = installedContentHashtable.size();        if (size > 0) {            Vector jumpAppObjectsVector = new Vector();            JUMPContent content[] = new JUMPContent[size];            for (Enumeration e = installedContentHashtable.keys() ; e.hasMoreElements() ;) {                Object key = e.nextElement();                Object app = installedContentHashtable.get(key);                jumpAppObjectsVector.add(app);            }            return (JUMPContent[])jumpAppObjectsVector.toArray(new JUMPContent[]{});        } else {            return null;        }    };        /**     * Uninstall content.     * @param content the object to be uninstalled     */    public void uninstall(JUMPContent content) {        // sanity check        if (content == null) {            return;        }                JUMPApplication app = (JUMPApplication)content;                String bundleName = getBundleName(app);        JUMPApplication[] apps = getAppsInBundle(bundleName);                if (apps == null || bundleName == null) {            return;        }        // Currently, calling JUMPExecutive.getInstance returns null.  Therefore, we// cannot use the JUMPUserInputManager APIs until this is fixed.  When this is// fixed, the following code can be uncommented.        //        if (apps.length > 1) {//            JUMPExecutive executive = JUMPExecutive.getInstance();//            if (executive == null) {//                System.out.println("ERROR: The JUMP Executive instance is null.");//                return;//            }//            JUMPUserInputManager uiManager = executive.getUserInputManager();//            String str = "This application belongs to the bundle: " + bundleName + " which contains multiple applications.  Do you wish to remove the bundle and all of its applications?";//            boolean rc = uiManager.showDialog(str, null, "OK", "Cancel");//            if (!rc) {//                return;//            }//        }                if (apps.length > 1) {            System.out.print(app.getAppType().toString());            System.out.print(": " + app.getTitle() + " is contained within a bundle" );            System.out.println("that contains the following applications:" );            System.out.print("  ");            for (int i = 0; i < apps.length; i++) {                JUMPApplication application = (JUMPApplication)apps[i];                System.out.print(application.getTitle());                if (i < (apps.length - 1)) {                    System.out.print(", ");                }            }            System.out.println("");//            String value = System.getProperty("jump.installer.interactive");//            if (value.toLowerCase().equals("true")) {//                System.out.println("Deleting this bundle will remove all of the applications.");//                while ( true ) {//                    String message = "Do you wish to proceed? [y/n]: ";//                    String answer = Utilities.promptUser(message);//                    if (answer.toLowerCase().equals("y")) {//                        break;//                    } else if (answer.toLowerCase().equals("n")){//                        return;//                    } else {//                        System.out.println("ERROR: Illegal response.");//                    }//                }//                //            } else {                System.out.println("All applications will be removed.");//            }        }                trace(getString("AttemptingToRemove") + bundleName);                // Get the path to the app bundle's jar file, which is assumed        // to be the first entry in the classpath.        String jarPath = getAppClasspath(app);        boolean result1 = removeJarFile(jarPath);        if (!result1) {            trace(getString("CannotRemoveApplicationJar") + ": " + jarPath);        }                // Remove the icon and app descriptor for each app in the bundle        for (int i = 0; i < apps.length; i++) {                        int appId = apps[i].getId();            removeInstalledAppIdEntry(Integer.toString(appId));                        // Remove the icon and app descriptor for each app            boolean result2 = removeAppDescriptor(apps[i]);            if (!result2) {                trace(getString("CouldNotRemoveAppDescriptor") + apps[i].getTitle());            }                        boolean result3 = removeIcon(apps[i].getIconPath());            if (!result3) {                trace(getString("CouldNotRemoveIcon") + apps[i].getTitle());            }                        if (result1 && result2 && result3) {                System.out.println(getString("SuccessfulUninstall") + apps[i].getTitle());            }        }    };        /**     * Update content from given location.  For XLET and Main applications, the behavior is to uninstall the current bundle and install the new bundle.     * @param content object to be updated     * @param location URL location of content to update with     * @param desc object describing the bundle to update with     */    public void update(JUMPContent content, URL location, JUMPDownloadDescriptor desc) {        uninstall(content);        install(location, desc);    };        /**     * Get all installed content of type XLET     * @return Array of JUMPApplication objects that are XLETs     */    public JUMPContent[] getInstalled() {                Vector nodeVector = new Vector();                storeHandle = openStore(true);                // get the listing of all nodes starting at the root.        JUMPNode.List list = null;        try {            list = (JUMPNode.List) storeHandle.getNode(REPOSITORY_DESCRIPTORS_DIRNAME);        } catch (IOException e) {            trace("Exception in getNode(): " + e.toString());        }                closeStore(storeHandle);                if (list == null) {            return null;        }                for (Iterator itn = list.getChildren(); itn.hasNext(); ) {            JUMPNode node = (JUMPNode) itn.next();            JUMPApplication app = createJUMPApplication(node.getURI());                        // Identify only the xlets or main apps, not both at the same time            if (app != null && app.getAppType() == getInstallerAppModel()) {                nodeVector.add(app);            }        }        return (JUMPApplication[])nodeVector.toArray(new JUMPApplication[]{});    };        /**     * Given the application object, return the name of the bundle the application belongs to     * @param app application object     * @return the names of the bundle this application belongs to     */    protected String getBundleName(JUMPApplication app) {        XLETApplication xletApp = (XLETApplication)app;        return xletApp.getBundle();    }        /**     * Given the bundle name, return the application objects within the bundle     * @param bundle name of content bundle     * @return the application objects belonging to the bundle     */    protected JUMPApplication[] getAppsInBundle(String bundle) {        JUMPApplication[] apps = (JUMPApplication[]) getInstalled();        Vector appsVector = new Vector();        for (int i = 0; i < apps.length; i++) {            XLETApplication xletApp = (XLETApplication)apps[i];            if (xletApp.getBundle().equals(bundle)) {                appsVector.add(apps[i]);            }        }        Object[] objs = appsVector.toArray();        JUMPApplication[] bundleApps = new JUMPApplication[objs.length];        for (int i = 0; i < objs.length; i++ ) {            bundleApps[i] = (JUMPApplication)objs[i];        }        return bundleApps;    }        private String extractIconFromJar(String jarFile, String iconFile) {        return (extractIconFromJar(jarFile, iconFile, null));    }        private String extractIconFromJar(String jarFile, String iconFile, String id) {                String iconFileName = null;        String iconFilePath = null;                JarFile jar = null;                try {            jar = new JarFile(jarFile);        } catch (Exception e) {            e.printStackTrace();            return null;        }                trace("extractIconFromJar(): jarfile: " + jarFile + "  icon: " + iconFile);                ZipEntry entry = jar.getEntry(iconFile);        if (entry == null) {            trace(getString("CouldNotExtract") + iconFile);            return null;        }                int index = iconFile.lastIndexOf('/');        if (index != -1) {            iconFileName = iconFile.substring(index + 1,                    iconFile.length());        } else {            iconFileName = iconFile;        }                if (id != null) {            // Get extention of file            int dotindex = iconFileName.lastIndexOf('.');            if (dotindex == -1) {                return null;            }                        // The path up until the extention.            String pathToExtention = iconFileName.substring(0, dotindex);                        // The extention            String extention = iconFileName.substring(dotindex);                        iconFileName = pathToExtention + '-' + id + extention;        }                String iconsDir = contentStoreDir + REPOSITORY_ICONS_DIRNAME + '/';        iconFilePath = iconsDir + iconFileName;        if (new File(iconFilePath).exists()) {            System.out.println("*** Warning installing bundle: An icon with this name is already installed.");            return iconFilePath;        } else {            trace("Saving icon file: " + iconFilePath);        }                try {                        InputStream zis = jar.getInputStream(entry);                        int size = (int) entry.getSize();            // -1 means unknown size.            if (size == -1) {                trace(getString("IconFileSizeError"));                return null;            }                        byte[] buffer = copyBuffer(zis, size);                        File f = new File(iconFilePath);            FileOutputStream fos = new FileOutputStream(f);            fos.write(buffer);            fos.close();                        return iconFilePath;                    } catch (Exception e) {            e.printStackTrace();        }        return null;    }        /**     * This is necessary to avoid issues when downloading and installing the     * same app on the device, or at least an app with the same exact name.     * Simply concat a number, starting with 2, to the end of the path until     * a path is found that doesn't already exist.     */    private String createUniquePathName(String original) {                int NUM = 2;        int LIMIT  = 1000;                // Get extention of file        int dotindex = original.lastIndexOf('.');        if (dotindex == -1) {            return null;        }        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -