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

📄 associationservice.java

📁 JDesktop Integration Components (JDIC)
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     */
    public Association getAssociationByContent(URL url) {
        if (url == null) {
            throw new IllegalArgumentException("The specified URL is null");
        }
        
        Association assoc = null;
        String mimeType = appAssocReader.getMimeTypeByURL(url);

        if (mimeType != null) {
            // Get association by mime type.
            assoc = getMimeTypeAssociation(mimeType);
        }
        
        if (assoc == null) {
            // Get association by file extension.
            String fileExt = AppUtility.getFileExtensionByURL(url);

            if (fileExt != null) {
                assoc = getFileExtensionAssociation(fileExt);
            }
        }
            
        return assoc;
    }        
  
    /**
     * Registers the given association in the user specific level.
     * <p>
     * <ul>
     *   <li> For Microsoft Windows platforms: the file extension list and MIME 
     *        type can't both be null. If any of the description, icon file name, action 
     *        list fields is not null, the file extension list couldn't be empty.
     *        <p> 
     *        For Windows NT, Windows Me/98/95: the registration is always system 
     *        wide, since all users share the same association information.
     *        <p> 
     *        For Windows 2000 and Windows XP: the registration is only applied to 
     *        this specific user.
     * 
     *   <li> For Gnome/Unix platforms: both the name and MIME type fields need to 
     *        be specified to perform this operation.
     * </ul>
     * 
     * @param assoc a given <code>Association</code> object.
     * @throws IllegalArgumentException if the given association is not valid for 
     *         this operation.
     * @throws AssociationAlreadyRegisteredException if the given association 
     *         already exists in the system.
     * @throws RegisterFailedException if the given association fails to be 
     *         registered in the system.
     */
    public void registerUserAssociation(Association assoc) 
            throws AssociationAlreadyRegisteredException, RegisterFailedException {
        if (assoc == null) {
            throw new IllegalArgumentException("The specified association is null");
        }

        // Check whether the specified association is valid for registration.
        try {
            appAssocWriter.checkAssociationValidForRegistration(assoc); 
        } catch (IllegalArgumentException e) {
            throw e;
        }
        
        // Check whether the specified association already exists.
        if (appAssocWriter.isAssociationExist(assoc, AppAssociationWriter.USER_LEVEL)) {
            throw new AssociationAlreadyRegisteredException("Assocation already exists!");  
        }            

        // Perform registration.                
        appAssocWriter.registerAssociation(assoc, AppAssociationWriter.USER_LEVEL);
    }                

    /**
     * Unregisters the given association in the user specific level.
     * <p>
     * <ul>
     *   <li> For Microsoft Windows platforms: either the MIME type or the file extension
     *        list field needs to be specified to perform this operation.
     *        <p>
     *        For Windows NT, Windows Me/98/95: the unregistration is always system wide, 
     *        since all users share the same association information.
     *        <p>
     *        For Windows 2000 and Windows XP: the unregistration is only applied to 
     *        this specific user.
     *
     *   <li> For Gnome/Unix platforms: only the name field needs to be specified to 
     *        perform this operation.
     * </ul>
     * <P>
     * 
     * @param assoc a given Association object.
     * @throws IllegalArgumentException if the given association is not valid for 
     *         this operation.
     * @throws AssociationNotRegisteredException if the given association doesn't 
     *         exist in the system.
     * @throws RegisterFailedException if the given association fails to be 
     *         unregistered in the system.   
     */
    public void unregisterUserAssociation(Association assoc) 
            throws AssociationNotRegisteredException, RegisterFailedException {
        if (assoc == null) {
            throw new IllegalArgumentException("The specified association is null");
        }

        // Check whether the specified association is valid for unregistration.
        try {
            appAssocWriter.checkAssociationValidForUnregistration(assoc);
        } catch (IllegalArgumentException e) {
            throw e;
        }
        
        // Check whether the specified association not exists.
        if (!appAssocWriter.isAssociationExist(assoc, AppAssociationWriter.USER_LEVEL)) {
            throw new AssociationNotRegisteredException("Assocation not exists!");  
        }            

        // Perform unregistration.
        appAssocWriter.unregisterAssociation(assoc, AppAssociationWriter.USER_LEVEL);
    }

    /**
     * Registers the given association in the system level.
     * <p>
     * <ul>
     *   <li> For Microsoft Windows platforms: the file extension list and MIME 
     *        type can't all be null. If any of the description, icon file name, action
     *        list fields is not null, the file extension list couldn't be empty.
     *        <p> 
     *        For Windows XP: the user needs the administrator permission to 
     *        access the system association information in the registry.
     * 
     *  <li>  For Gnome/Unix platforms: both the name and MIME type fields need to 
     *        be specified to perform this operation.
     * </ul>
     * 
     * @param assoc a given <code>Association</code> object.
     * @throws IllegalArgumentException if the given association is not valid for 
     *         this operation.
     * @throws AssociationAlreadyRegisteredException if the given association 
     *         already exists in the system.
     * @throws RegisterFailedException if the given association fails to be 
     *         registered in the system.
     */
    public void registerSystemAssociation(Association assoc) 
            throws AssociationAlreadyRegisteredException, RegisterFailedException {
        if (assoc == null) {
            throw new IllegalArgumentException("The specified association is null");
        }

        // Check whether the specified association is valid for registration.
        try {
            appAssocWriter.checkAssociationValidForRegistration(assoc);
        } catch (IllegalArgumentException e) {
            throw e;
        }
        
        // Check whether the specified association already exists.
        if (appAssocWriter.isAssociationExist(assoc, AppAssociationWriter.SYSTEM_LEVEL)) {
            throw new AssociationAlreadyRegisteredException("Assocation already exists!");  
        }            

        // Perform registration.
        appAssocWriter.registerAssociation(assoc, AppAssociationWriter.SYSTEM_LEVEL);
    }

    /**
     * Unregisters the given association in the system level.
     * <p>
     * <ul>
     *   <li> For Microsoft Windows platforms: either the MIME type or the file extension
     *        list field needs to be specified to perform this operation.
     *        <p>
     *        For Windows XP: the user needs the administrator permission to access the 
     *        system association information in the registry.
     *
     *   <li> For Gnome/Unix platforms: only the name field needs to be specified to 
     *        perform this operation.
     * </ul>
     * <P>
     * 
     * @param assoc a given Association object.
     * @throws IllegalArgumentException if the given association is not valid for 
     *         this operation.
     * @throws AssociationNotRegisteredException if the given association doesn't 
     *         exist in the system.
     * @throws RegisterFailedException if the given association fails to be 
     *         unregistered in the system.   
     */
    public void unregisterSystemAssociation(Association assoc)
        throws AssociationNotRegisteredException, RegisterFailedException {
        if (assoc == null) {
            throw new IllegalArgumentException("The specified association is null");
        }

        // Check whether the specified association is valid for unregistration.
        try {
            appAssocWriter.checkAssociationValidForUnregistration(assoc); 
        } catch (IllegalArgumentException e) {
            throw e;
        }
        
        // Check whether the specified association not exists.
        if (!appAssocWriter.isAssociationExist(assoc, AppAssociationWriter.SYSTEM_LEVEL)) {
            throw new AssociationNotRegisteredException("Assocation not existed!");  
        }            

        appAssocWriter.unregisterAssociation(assoc, AppAssociationWriter.SYSTEM_LEVEL);
    }
}

⌨️ 快捷键说明

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