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

📄 winappassociationwriter.java

📁 JDesktop Integration Components (JDIC)
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (C) 2004 Sun Microsystems, Inc. All rights reserved. Use is * subject to license terms. *  * This program is free software; you can redistribute it and/or modify * it under the terms of the Lesser GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. *  * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * General Public License for more details. *  * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA. */ package org.jdesktop.jdic.filetypes.internal;import java.util.Iterator;import java.util.List;import org.jdesktop.jdic.filetypes.Association;import org.jdesktop.jdic.filetypes.RegisterFailedException;/** * Concrete implementation of the AppAssociationWriter class for Windows platform. */public class WinAppAssociationWriter implements AppAssociationWriter {    /**     * Inline class for restoreing association registration/unregistration failure.     */    protected class BackupAssociation {        // Mime type retrieved from the specified association object.        private String curMimeType;           // File extension retrieved from the specified association object.        private String curFileExt;        private boolean curMimeTypeExisted;        private boolean curFileExtExisted;        private String backupMimeType;        private String backupClassID;        private String backupFileExt;        /**         * Suppresses default constructor for noninstantiability.         */        private BackupAssociation() {}         /**         * Constructor for class BackupAssociation         *         * @param assoc the given Association (not null).         * @param regLevel the given registeration level.         */        protected BackupAssociation(Association assoc, int regLevel) {            curMimeType = assoc.getMimeType();            Iterator iter = null;            List temFileExtList = assoc.getFileExtList();            if (temFileExtList != null) {                iter = temFileExtList.iterator();            }            if (iter != null) {                if (iter.hasNext()) {                    curFileExt = (String) iter.next();                   }            }                        if (curMimeType != null) {                curMimeTypeExisted = WinRegistryUtil.isMimeTypeExist(curMimeType, regLevel);            } else {                curMimeTypeExisted = false;            }                        if (curFileExt != null) {                curFileExtExisted = WinRegistryUtil.isFileExtExist(curFileExt, regLevel);            } else {                curFileExtExisted = false;            }                if (curMimeTypeExisted) {                backupFileExt = WinRegistryUtil.getFileExtByMimeType(curMimeType, regLevel);            }                if (curFileExtExisted) {                backupClassID = WinRegistryUtil.getClassIDByFileExt(curFileExt, regLevel);                backupMimeType = WinRegistryUtil.getMimeTypeByFileExt(curFileExt, regLevel);            }                    }        /**         * Retrieve mime type         *         * @return mime type         */        protected String getCurMimeType() {            return curMimeType;        }                /**         * Retrieves file extension          *         * @return file extension         */        protected String getCurFileExt() {            return curFileExt;        }            /**         * Return true if the mime type existed in the Windows registry table         *          * @return true if the mime type existed         */        protected boolean getCurMimeTypeExisted() {            return curMimeTypeExisted;        }        /**         * Returns true if the file extension existed in the Windows registry table         *         * @return true if the file extension existed         */        protected boolean getCurFileExtExisted() {            return curFileExtExisted;        }                    /**         * Returns the backup mime type information         *          * @return backup mime type information         */        protected String getBackupMimeType() {            return backupMimeType;        }        /**         * Returns the backup class ID         *          * @return backup class ID information         */        protected String getBackupClassID() {            return backupClassID;        }        /**         * Returns backup file extension         *         * @return backup file extensio         */        protected String getBackupFileExt() {            return backupFileExt;        }    }    /**     * Restores association registration failure.     *     * @param backupAssoc backup association (not null)     * @param regLevel given regLevel     */    private void restoreAssociationRegistration(BackupAssociation backupAssoc, int regLevel) {        try {            String curMimeType = backupAssoc.getCurMimeType();            String curFileExt = backupAssoc.getCurFileExt();                                    if (!backupAssoc.getCurMimeTypeExisted()) {                if (curMimeType != null) {                    WinRegistryUtil.removeMimeType(curMimeType, regLevel);                }            } else {                String backupFileExt = backupAssoc.getBackupFileExt();                if (backupFileExt != null) {                    WinRegistryUtil.setFileExtByMimeType(backupFileExt,                        curMimeType, regLevel);                }            }            if (!backupAssoc.getCurFileExtExisted()) {                if (curFileExt != null) {                    WinRegistryUtil.removeFileExt(curFileExt, regLevel);                }            } else {                String backupMimeType = backupAssoc.getBackupMimeType();                if (backupMimeType != null) {                    WinRegistryUtil.setMimeTypeByFileExt(backupMimeType,                        curFileExt, regLevel);                }                String backupClassID = backupAssoc.getBackupClassID();                if (backupClassID != null) {                    WinRegistryUtil.setClassIDByFileExt(curFileExt,                         backupClassID, regLevel);                }            }           } catch (RegisterFailedException e) {        }    }    /**     * Restores association unregistration failure.     *      * @param backupAssoc backup association     * @param regLevel given regLevel     */    private void restoreAssociationUnregistration(BackupAssociation backupAssoc, int regLevel) {        try {            String curMimeType = backupAssoc.getCurMimeType();            String curFileExt = backupAssoc.getCurFileExt();                        if (backupAssoc.getCurMimeTypeExisted()) {                WinRegistryUtil.addMimeType(curMimeType, regLevel);                String backupFileExt = backupAssoc.getBackupFileExt();                if (backupFileExt != null) {                    WinRegistryUtil.setFileExtByMimeType(backupFileExt,                         curMimeType, regLevel);                }               }                    if (backupAssoc.getCurFileExtExisted()) {                WinRegistryUtil.addFileExt(curFileExt, regLevel);                String backupMimeType = backupAssoc.getBackupMimeType();                String backupClassID = backupAssoc.getBackupClassID();                                if (backupMimeType != null) {                    WinRegistryUtil.setMimeTypeByFileExt(backupMimeType,                        curFileExt, regLevel);                }                if (backupClassID != null) {                    WinRegistryUtil.setClassIDByFileExt(curFileExt,                         backupClassID, regLevel);                }            }         } catch (RegisterFailedException e) {        }    }    /**     * Checks whether the given assocation is valid for registration.     * <PRE>         * 1. The file extension list and mime type can't all be null     * 2. If any of the fileds: description, iconFile, actionList is not null,      *    then fileExtensionList should not be empty     * </PRE>     *      * @param assoc a given Association object.     * @throws IllegalArgumentException if the given association is not valid for registration.     */    public void checkAssociationValidForRegistration(Association assoc)         throws IllegalArgumentException {

⌨️ 快捷键说明

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