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

📄 jnlppackageinfo.java

📁 JDesktop Integration Components (JDIC)
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * Gets whether to create a shortcut after the installation.     * @return True if the installation will create a shortcut.     */    public boolean getShortcutEnabled() {        return shortcutEnabled;    }    /**     * Sets whether to create a shortcut during the installation process.     * @param shortcut True if the installation will create a shortcut.     */    public void setShortcutEnabled(boolean shortcut) {        shortcutEnabled = shortcut;    }    /**     * Gets whether to create an association during the installation process.     * @return True if the installation will create an association.     */    public boolean getAssociationEnabled() {        return enableAssociation;    }    /**     * Sets whether to create an association during the installation process.     * @param association True if the installation will create an association.     */    public void setAssociationEnabled(boolean association) {        enableAssociation = association;    }    /**     * Gets whether we need to localize the installation package.     * @return True if localization supported.     */    public boolean getLocalizationEnabled() {        return enableLocalization;    }    /**     * Sets whether we need to provide localization support.     * @param globalization True if localization supported.     */    public void setGlocalizationEnabled(boolean globalization) {        enableLocalization = globalization;    }    /**     * Gets the license directory.     * @return The directory containing all the license files.     */    public String getLicenseDirPath() {        return licenseDirPath;    }    /**     * Sets the license directory.     * @param theLicenseDirPath The directory containing all the license files.     */    public void setLicenseDirPath(String theLicenseDirPath) {        licenseDirPath = theLicenseDirPath;    }    /**     * Sets whether to show license info during installation process.     * @param bShow True if license info gets displayed durinig installation.     */    public void setShowLicense(boolean bShow) {        enableLicense = bShow;    }    /**     * Gets whether to show license info during installation process.     * @return True if license info gets displayed during installation process.     */    public boolean getShowLicense() {        return enableLicense;    }    /**     * Gets a unique temp directory.     * @return The path of the uniqe temp directory.     * @throws IOException If failed to get such a directory.     */    public String getUniqueTmpDirPath() throws IOException {        if (uniqueTmpDirPath == null) {            uniqueTmpDirPath = FileOperUtility.createUniqueTmpDir();        }        return uniqueTmpDirPath;    }    /**     * Gets localized jnlp file field.     * @param locale The given locale name.     * @param info  The name of the jnlp file field.     * @return The lolized jnlp field content string.     */    public String getLocalizedJnlpInfo(String locale, String info) {        int localeIndex = getLocaleIndex(locale);        String ret = null;        if (info.compareToIgnoreCase(JnlpConstants.JNLP_FIELD_TITLE) == 0) {            ret = titles[localeIndex];        } else if (            info.compareToIgnoreCase(JnlpConstants.JNLP_FIELD_VENDOR) == 0) {            ret = vendors[localeIndex];        } else if (            info.compareToIgnoreCase(JnlpConstants.JNLP_FIELD_LICENSE) == 0) {            ret = licenses[localeIndex];        } else if (            info.compareToIgnoreCase(JnlpConstants.JNLP_FIELD_DESCRIPTION)                == 0) {            ret = descriptions[localeIndex];        }        return ret;    }    /**     * Gets the corresponding locale index.     * @param locale The given locale string.     * @return The index of the locale string.     */    protected int getLocaleIndex(String locale) {        int index = -1;        for (int i = 0; i < JnlpConstants.LOCALES.length; i++) {            if (locale.compareToIgnoreCase(JnlpConstants.LOCALES[i]) == 0) {                index = i;                break;            }        }        return index;    }        /**     * get remote resources to local directory, and set the related fields of     * the JnlpPackageInfo     *      * @param jnlp points to the remote jnlp file     * @throws IOException     */    public void parseRemoteJnlpInfo(URL jnlp)             throws IOException {        if (jnlp == null)             throw new IOException("url is null when trying to parse JnlpInfo");        String localBase = FileOperUtility.createUniqueTmpDir();        URL localJnlp = FileOperUtility.getRemoteResource(jnlp, localBase);        setResourcePath(localBase);        parseLocalJnlpInfo(localJnlp);    }        /**     * add file path to JnlpRefFilePath     *      * @param url points to the file     * @param codebase      * @throws IOException     */    public void addJnlpRefFilePath(URL url, URL codebase) throws IOException {        String relPath = FileOperUtility.getRelativePath(                url.toString(), codebase.toString());        jnlpRefFilePaths.add(relPath);    }        /**     * set related fields of the JnlpPackageInfo according to the local jnlp     * file     *      * @param jnlp points to the local jnlp file     * @throws IOException     */    public void parseLocalJnlpInfo(URL jnlp) throws IOException {        URL codebase = null;                if (jnlp == null)             throw new IOException("url is null when trying to parse JnlpInfo");                if (resourceDirPath == null || resourceDirPath.length() <= 0)            throw new IOException("resourcePath have not been set");                try {            File jnlpFile = new File(jnlp.toURI());            setJnlpFilePath(jnlpFile.getPath());            LaunchDesc laDesc = LaunchDescFactory.buildDescriptor(jnlp);            codebase = laDesc.getCodebase();            setJnlpFileHref(laDesc.getCanonicalHome().toString());            InformationDesc infoDesc = laDesc.getInformation();            setTitle(JnlpConstants.LOCALE_EN, infoDesc.getTitle());            setVendor(JnlpConstants.LOCALE_EN, infoDesc.getVendor());            setDescription(JnlpConstants.LOCALE_EN,                     infoDesc.getDescription(InformationDesc.DESC_DEFAULT));            addJnlpRefFilePaths(jnlp);        } catch (Exception e) {        	e.printStackTrace();        }    }    public void addJnlpRefFilePaths(URL jnlp) throws IOException{                if (jnlp == null)             throw new IOException("url is null when trying to parse JnlpInfo");                if (resourceDirPath == null || resourceDirPath.length() <= 0)            throw new IOException("resourcePath have not been set");                try {        	File jnlpFile = new File(jnlp.toURI());            jnlpRefFilePaths.add(jnlpFile.getAbsolutePath());            LaunchDesc laDesc = LaunchDescFactory.buildDescriptor(jnlp);            URL codebase = laDesc.getCodebase();            InformationDesc infoDesc = laDesc.getInformation();            IconDesc[] iconArray = infoDesc.getIcons();            for (int i = 0; i < iconArray.length; i++) {                URL iconURL = iconArray[i].getLocation();                this.addJnlpRefFilePath(iconURL, codebase);            }            ResourcesDesc reDesc = laDesc.getResources();            reDesc.visit(                    new JDICPackagerFileRefVisitor(codebase,                            resourceDirPath, this));        } catch (Exception e) {        	e.printStackTrace();        }    }    /**     * set title in the given locale     *      * @param index     * @param title     */    public void setTitle(int index, String title) {        titles[index] = title;       }        /**     * set vector in the given locale     *      * @param index     * @param vendor     */    public void setVendor(int index, String vendor) {        vendors[index] = vendor;       }        /**     * set description in the give locale     *      * @param index     * @param description     */    public void setDescription(int index, String description) {        descriptions[index] = description;       }        /**     * set license in the give locale     *      * @param index     * @param license     */    public void setLicense(int index, String license) {        licenses[index] = license;       }        /**     * set localized information to the jnlpPackagerInfo     *      * @throws IOException     */    public void setLocalizedInformation()            throws IOException {        File jnlpFile = null;        jnlpFile = new File(getJnlpFilePath());                if (jnlpFile == null) {            throw new IOException("Cannot find local jnlp file: " +                    jnlpFile.getPath());           }        byte[] bits;        try {             bits = LaunchDescFactory.readBytes(new FileInputStream(jnlpFile),                jnlpFile.length());        } catch (Exception e) {            throw new IOException("Exception when build localized InfoDesc " +                    e.getMessage());           }        setLocalizedInformation(bits);                for (int i = 0; i < JnlpConstants.LOCALES.length; i++) {            if (titles[i] == null || titles[i].length() == 0) {                titles[i] = titles[JnlpConstants.LOCALE_EN];               }                        if (vendors[i] == null || vendors[i].length() == 0) {                vendors[i] = vendors[JnlpConstants.LOCALE_EN];               }                        if (descriptions[i] == null || descriptions[i].length() == 0) {                descriptions[i] = descriptions[JnlpConstants.LOCALE_EN];               }        }    }        private void setLocalizedInformation(byte[] bits)            throws IOException {        String source;        String encoding;        XMLNode root;        try {            source = XMLEncoding.decodeXML(bits);        } catch (Exception e) {            throw new IOException("exception determining encoding of jnlp " +                    "file: " + e.getMessage());        }        try {            root = (new XMLParser(source)).parse();        } catch (Exception e) {            throw new IOException("exception parsing jnlp file " +                    e.getMessage());        }                try {            XMLUtils.visitElements(root, "<information>",                    new JDICPackagerInfoElementVisitor(this));        } catch (Exception e) {            throw new IOException("exception creating InformationDesc " +                    e.getMessage());           }    }}/** * ResourceVisitor to add all the local resource file paths to * JnlpPackageInfo.jnlpRefFilePaths */class JDICPackagerFileRefVisitor implements ResourceVisitor {    private URL codebase = null;     private String localBase = null;    private JnlpPackageInfo pkgInfo = null;    public JDICPackagerFileRefVisitor(URL incodebase, String inlocalbase,            JnlpPackageInfo inpkgInfo) {        codebase = incodebase;        localBase = inlocalbase;        pkgInfo = inpkgInfo;    }    public void visitJARDesc(JARDesc jad) {        try {            pkgInfo.addJnlpRefFilePath(jad.getLocation(), codebase);        } catch (IOException ioE) {            ioE.printStackTrace();           }    }        public void visitExtensionDesc(ExtensionDesc ed) {        String relPath = FileOperUtility.getRelativePath(                ed.getLocation().toString(), codebase.toString());        File tmpFile = new File(pkgInfo.getResourceDirPath() + File.separator +                relPath);        try {            pkgInfo.addJnlpRefFilePaths(tmpFile.toURL());        } catch (IOException ioE) {            ioE.printStackTrace();           }    }        public void visitPropertyDesc(PropertyDesc prd) {}    public void visitJREDesc(JREDesc jrd) {}    public void visitPackageDesc(PackageDesc pad) {}}/** * Element Visitor to set informations in different locales. */class JDICPackagerInfoElementVisitor extends XMLUtils.ElementVisitor {    private JnlpPackageInfo pkgInfo;        public JDICPackagerInfoElementVisitor(JnlpPackageInfo inpkgInfo) {        pkgInfo = inpkgInfo;    }        public void visitElement(XMLNode e) throws BadFieldException,        MissingFieldException {        String[] locales = GeneralUtil.getStringList(                XMLUtils.getAttribute(e, "", "locale", null));        for (int i = 0; i < JnlpConstants.LOCALES.length; i++) {             if (matchLocale(JnlpConstants.LOCALES[i], locales)) {                 String title = XMLUtils.getElementContents(e, "<title>");                 pkgInfo.setTitle(i, title);                 String vendor = XMLUtils.getElementContents(e, "<vendor>");                 pkgInfo.setVendor(i, vendor);                 String description = XMLUtils.getElementContentsWithAttribute(                        e, "<description>", "kind", "", null);                 pkgInfo.setDescription(i, description);             }        }    }        private boolean matchLocale(String locale, String[] locales) {        boolean match = false;        if (locales == null)            return match;                for (int i = 0; i < locales.length; i++) {            if (locales[i] != null && locales[i].equals(locale)) {                match = true;                break;            }        }                return match;    }}

⌨️ 快捷键说明

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