1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package org.openoffice.netbeans.modules.office.utils; 25 26 import java.io.File; 27 import java.io.IOException; 28 import java.beans.PropertyVetoException; 29 30 import org.openide.filesystems.Repository; 31 import org.openide.filesystems.FileSystem; 32 import org.openide.filesystems.JarFileSystem; 33 34 import org.openoffice.idesupport.SVersionRCFile; 35 import org.openoffice.netbeans.modules.office.options.OfficeSettings; 36 37 public class FrameworkJarChecker { 38 mountDependencies()39 public static void mountDependencies() { 40 String unoilPath = SVersionRCFile.getPathForUnoil( 41 OfficeSettings.getDefault().getOfficeDirectory().getPath()); 42 43 if (unoilPath == null) 44 return; 45 46 File unoilFile = new File(unoilPath + File.separator + "unoil.jar"); 47 JarFileSystem jfs = new JarFileSystem(); 48 try { 49 jfs.setJarFile(unoilFile); 50 } 51 catch (IOException ioe) { 52 return; 53 } 54 catch (PropertyVetoException pve) { 55 return; 56 } 57 58 FileSystem result; 59 try { 60 result = 61 Repository.getDefault().findFileSystem(jfs.getSystemName()); 62 } 63 catch(Exception exp) { 64 result = null; 65 } 66 finally { 67 jfs.removeNotify(); 68 } 69 70 if(result == null) { 71 // warnBeforeMount(); 72 JarFileSystem newjfs = new JarFileSystem(); 73 try { 74 newjfs.setJarFile(unoilFile); 75 } 76 catch (IOException ioe) { 77 return; 78 } 79 catch (PropertyVetoException pve) { 80 return; 81 } 82 Repository.getDefault().addFileSystem(newjfs); 83 newjfs.setHidden(true); 84 } 85 } 86 unmountDependencies()87 public static void unmountDependencies() { 88 String unoilPath = SVersionRCFile.getPathForUnoil( 89 OfficeSettings.getDefault().getOfficeDirectory().getPath()); 90 91 if (unoilPath == null) 92 return; 93 94 File unoilFile = new File(unoilPath + File.separator + "unoil.jar"); 95 JarFileSystem jfs = new JarFileSystem(); 96 try { 97 jfs.setJarFile(unoilFile); 98 } 99 catch (IOException ioe) { 100 return; 101 } 102 catch (PropertyVetoException pve) { 103 return; 104 } 105 106 FileSystem result; 107 try { 108 result = 109 Repository.getDefault().findFileSystem(jfs.getSystemName()); 110 if(result != null) 111 Repository.getDefault().removeFileSystem(result); 112 } 113 catch(Exception exp) { 114 } 115 } 116 warnBeforeMount()117 private static void warnBeforeMount() { 118 OfficeSettings settings = OfficeSettings.getDefault(); 119 120 if (settings.getWarnBeforeMount() == false) 121 return; 122 123 String message = "The Office Scripting Framework support jar file " + 124 "is not mounted, so Office scripts will not compile. NetBeans " + 125 "is going to mount this jar file automatically."; 126 127 String prompt = "Show this message in future."; 128 129 NagDialog warning = NagDialog.createInformationDialog( 130 message, prompt, true); 131 132 if (warning.getState() == false) { 133 settings.setWarnBeforeMount(false); 134 } 135 } 136 } 137