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

📄 xletinstallerimpl.java

📁 This is a resource based on j2me embedded,if you dont understand,you can connection with me .
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        // The path up until the extention.        String pathToExtention = original.substring(0, dotindex);                // The extention        String extention = original.substring(dotindex);                // Get the file name minus the extention        int fileSeparatorIndex = original.lastIndexOf('/');        String fileName = null;        if (fileSeparatorIndex != -1) {            fileName = original.substring(fileSeparatorIndex + 1, dotindex);        } else {            return null;        }                // First, check if the original name is unique        String testPath = original;        File testPathFile = new File(testPath);        while (testPathFile.exists() && NUM < LIMIT) {            String EXTRA = '(' + Integer.toString(NUM) + ')';            testPath = pathToExtention + EXTRA + extention;            testPathFile = new File(testPath);                        // Need to change the parent directory of the file if this            // is a jarfile            if (testPath.endsWith(".jar")){                String parentPath = testPathFile.getParent();                testPath = parentPath + EXTRA + '/' + fileName + EXTRA + extention;                testPathFile = new File(testPath);            }            NUM++;        }                if (NUM == LIMIT) {            return null;        }                return testPath;    }        /**     * Create an application descriptor for the given application     * values.  The application descriptor gets saved into the     * application repository's menu directory.     * @param descriptorPath the path within the content store to store the application descriptor     * @param props object containing the properties of the application descriptor     * @return boolean value indicating success or failure     */    private boolean createAppDescriptor(String descriptorPath, Properties props) {                // Convert the paths to the relative path from the content store root,        // we don't want to store the absolute path to the persistant store        removeContentStorePath(props, DESCRIPTOR_ICON_KEY);        removeContentStorePath(props, DESCRIPTOR_JARPATH_KEY);                JUMPData propData = new JUMPData(props);                try {            storeHandle.createDataNode(descriptorPath, propData);        } catch (RuntimeException re) {            re.printStackTrace();            return false;        } catch (IOException ioe) {            ioe.printStackTrace();            return false;        }                return true;    }        /**     * Retrieve an instance of JUMPApplication for the given application or menu.     */    private JUMPApplication createJUMPApplication(String descriptorPath) {                       storeHandle = openStore(true);        JUMPNode appDescriptorNode = null;        try {            appDescriptorNode = storeHandle.getNode(descriptorPath);        } catch (IOException e) {            e.printStackTrace();        }        closeStore(storeHandle);                if (appDescriptorNode == null) {            trace(getString("AppDescriptorNotFound") + descriptorPath);            return null;        }                JUMPData appDescriptorData = null;        if (appDescriptorNode.containsData()) {            appDescriptorData = ((JUMPNode.Data)appDescriptorNode).getData();        } else {            return null;        }                Properties appDescriptorProps = (Properties)appDescriptorData.getValue();        JUMPApplication module = null;                // First, make sure the app type is correct        String appType = (String)appDescriptorProps.getProperty(DESCRIPTOR_APPMODEL_KEY);        if (appType == null || !appType.equals(getInstallerAppModel().getName())) {            return null;        }                // Convert back the path to the absolute path        addContentStorePath(appDescriptorProps, DESCRIPTOR_ICON_KEY);        addContentStorePath(appDescriptorProps, DESCRIPTOR_JARPATH_KEY);                        // Now, obtain the values for specific keys        String classPath = (String)appDescriptorProps.getProperty(DESCRIPTOR_JARPATH_KEY);        if (classPath == null) {            return null;        }                URL classPathURL = null;        try {            classPathURL = new URL("file", null, classPath);            if (classPathURL == null) {                return null;            }        } catch (MalformedURLException ex) {            ex.printStackTrace();            return null;        }                String bundleName = (String)appDescriptorProps.getProperty(DESCRIPTOR_BUNDLENAME_KEY);        if (bundleName == null) {            return null;        }                String title = (String)appDescriptorProps.getProperty(DESCRIPTOR_TITLE_KEY);        if (title == null) {            return null;        }                String iconPath = (String)appDescriptorProps.getProperty(DESCRIPTOR_ICON_KEY);        URL iconPathURL = null;        if (iconPath != null) {            try {                iconPathURL = new URL("file", null, iconPath);                if (iconPathURL == null) {                    return null;                }            } catch (MalformedURLException ex) {                ex.printStackTrace();                return null;            }        } else {            trace("Application: " + title + " doesn't have an icon.");        }        String clazz = (String)appDescriptorProps.getProperty(getInstallerInitialClassKey());                String id = (String)appDescriptorProps.getProperty("id");                module = createJUMPApplicationObject(bundleName, clazz, classPathURL, title, iconPathURL, Integer.parseInt(id));         return module;    }        /**     * Removes the content store dir path from the property represented by the key.     * Used when creating .app file from the JUMPApplication properties list,     * so that .app file in the content sore will not have a full path to store,     * allowing the store to be moved from one location to another.     */    private void removeContentStorePath(Properties props, String key) {        String value = (String) props.remove(key);        if (value == null) return;        props.put(key, value.substring(contentStoreDir.length()));    }        /**     * Prepends the content store dir path to the property represented by the key.     * Used when creating JUMPApplication properties from the .app file     * in the content store, so that the JUMPApplication created have     * proper absolute path corresponding to the current run's contentstore     * root location.     */    private void addContentStorePath(Properties props, String key) {        String value = (String) props.remove(key);        if (value == null) return;        props.put(key, contentStoreDir + value);    }        /**     * Create an instance of JUMPApplication     * @param bundle Name of application bundle that this application belongs to     * @param clazz Initial class of application     * @param classPathURL URL of the classpath of this application     * @param title The user visible title of this application     * @param iconPathURL URL to the path of the icon for this application     * @return application object     */    protected JUMPApplication createJUMPApplicationObject(String bundle,            String clazz, URL classPathURL, String title, URL iconPathURL, int id) {        return new XLETApplication(contentStoreDir, bundle, clazz, classPathURL, title, iconPathURL, id);    }        /**     * Return the application type that this installer module can install     * @return the application type     */    protected JUMPAppModel getInstallerAppModel() {        return JUMPAppModel.XLET;    }        /**     * Get the key value used to specify an application's initial class     * @return initial class key value     */    protected String getInstallerInitialClassKey() {        return "xletName";    }        /**     * Get the key value used to specify an application's initial class from Properties object     * @return initial class key value     */    protected String getPropertyInstallerInitialClassKey() {        return XLETApplication.INITIAL_CLASS_KEY;    }        /**     * Remove the jar file from the content store.     * The current implementation uses java.util.File methods.     * @param jarPath path to the jar file within the content store     * @return boolean value indicating success or failure     */    private boolean removeJarFile(String jarPath) {                // Check to see that the jar file exists, and if so, start        // removing things.        File jarFile = new File(jarPath);        trace("removeJarFile(): " + jarFile);        if (jarFile != null && jarFile.exists()) {            trace("jarFile: " + jarFile + " exists!!! ***");            boolean jarFileDelete = false;            boolean jarFileParentDirDelete = false;            File jarFileParent = null;            try {                jarFileParent = jarFile.getParentFile();                jarFileDelete = jarFile.delete();                if (jarFileParent != null) {                    jarFileParentDirDelete = jarFileParent.delete();                }            } catch (Exception e) {                e.printStackTrace();            }                        if (!jarFileDelete) {                trace(getString("CannotRemoveApplicationJar"));            }            // Print out a message if we cannot remove the parent directory,            // but continue on...            if (!jarFileParentDirDelete) {                trace(getString("CouldNotRemoveApplicationDir"));            }            return true;        } else {            trace(getString("ApplicationJarDoesNotExist"));        }                return false;    }        /**     * Remove application descriptor from content store     * @param applicationName the application for which the application descriptor should be removed     * @return boolean value indicating success or failure     */    private boolean removeAppDescriptor(JUMPApplication app) {        String appTitle = app.getTitle();        String id = Integer.toString(app.getId());        String uri = REPOSITORY_DESCRIPTORS_DIRNAME + '/' + appTitle + '-' + id + APP_DESCRIPTOR_EXTENSION;        storeHandle = openStore(true);        if (storeHandle == null) {            return false;        }        try {            storeHandle.deleteNode(uri);        } catch (IOException e) {            return false;        }        closeStore(storeHandle);        return true;    }        /**     * Remove an icon file from within the content store     * @param iconURL URL of icon file within the content store     * @return boolean value indicating success or failure     */    private boolean removeIcon(URL iconURL) {        String iconFileName = iconURL.getFile();        trace("Trying to remove icon file: " + iconFileName);        File iconFile = new File(iconFileName);        if (iconFile != null && iconFile.exists()) {            try {                iconFile.delete();            } catch (Exception e) {                e.printStackTrace();                return false;            }        } else {            return false;        }        return true;    }        /**     * read from an input stream into a byte buffer[]     * @param is the input stream where the data is located     * @param size the number of bytes to read     * @return byte buffer of read data     */    private byte[] copyBuffer(InputStream is, int size) {        if (is == null) {            return null;        }                byte[] buffer = new byte[size];        try {                        // Read data into buffer            int rb = 0;            int chunk = 0;            while ( (size - rb) > 0) {                chunk = is.read(buffer, rb, size - rb);                if (chunk == -1) {                    break;                }                rb += chunk;            }        } catch (IOException ex) {            ex.printStackTrace();            return null;        }                return buffer;    }        /**     * Obtain the classpath value of the application object     * @param app application object     * @return classpath value of the application object     */    protected String getAppClasspath(JUMPApplication app) {        if (app == null) {            return null;        }        XLETApplication xletApp = (XLETApplication)app;        return xletApp.getClasspath().getFile();    }        /**     * Retrieve a String value from the module's resource bundle     * @param key key value into resource bundle     * @return value pertaining to the key field in the resource bundle     */    private String getString(String key) {        return InstallerFactoryImpl.getString(key);    }        /**     * Simple print command that prints messages if verbose is on     * @param s string to print     */    private void trace(String s) {        if (verbose) {            System.out.println(s);        }        return;    }}

⌨️ 快捷键说明

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