private static void saveRemoteResources(String extensionSite, ExtensionWrapper ext) { List extList = ext.getResourceList(); for (Iterator iter = extList.iterator(); iter.hasNext(); ) { String resource = (String) iter.next(); try { URL resURL = new URL(extensionSite + "/" + ext.getCategory() + ext.getName()); byte[] bitsAndBytes = null; DataInputStream dis = new DataInputStream(resURL.openStream()); dis.readFully(bitsAndBytes); FileOutputStream fos = new FileOutputStream( "c:\temp\ttt.jar" // manager.getPlugInDirectory()+ ext.getName() ); fos.write(bitsAndBytes); fos.close(); dis.close(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
private static File[] downloadAndSaveResources( String extensionSite, ExtensionWrapper ext, File plugInDirectory) { // TODO pull down resources from ext and save to pluginDir List fileList = new ArrayList(ext.getResourceList().size()); for (Iterator iter = ext.getResourceList().iterator(); iter.hasNext(); ) { String resourceName = (String) iter.next(); try { URL resURL = new URL( // + ext.getCategory() + "/" "jar:" + extensionSite + resourceName + "!/"); JarURLConnection juc = (JarURLConnection) resURL.openConnection(); JarFile jf = juc.getJarFile(); Enumeration enumer = jf.entries(); String resourceFile = plugInDirectory + File.separator + resourceName; fileList.add(new File(resourceFile)); FileOutputStream fos = new FileOutputStream(resourceFile); System.out.println(":vv " + resourceFile); JarOutputStream jos = new JarOutputStream(fos); while (enumer.hasMoreElements()) { JarEntry je = (JarEntry) enumer.nextElement(); jos.putNextEntry(new JarEntry(je)); InputStream in = jf.getInputStream(je); int c; // TODO FIXME use a buffered reader!!! while ((c = in.read()) >= 0) { jos.write(c); } in.close(); } jos.closeEntry(); jos.close(); fos.close(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return (File[]) fileList.toArray(new File[fileList.size()]); }
/** * Opens a project. * * @param directory Where the project is stored. * @return the BProject that describes the newly opened project or null if it cannot be opened. */ public final BProject openProject(File directory) { if (!myWrapper.isValid()) throw new ExtensionUnloadedException(); // Yes somebody may just call it with null, for fun.. if (directory == null) return null; Project openProj = Project.openProject(directory.getAbsolutePath(), null); if (openProj == null) return null; // a hack, since bluej does not handle "opening" of projects correctly. // this code should really be into openProject or it should not be possible to open // a project is the initial package name is not there. Package pkg = openProj.getCachedPackage(openProj.getInitialPackageName()); if (pkg == null) return null; // I make a new identifier out of this Identifier aProject = new Identifier(openProj, pkg); // This will make the frame if not already there. should not be needed... try { aProject.getPackageFrame(); } catch (ExtensionException exc) { } // Note: the previous Identifier is not used here. return openProj.getBProject(); }
/** * Creates a new BlueJ project. * * @param directory where you want the project be placed, it must be writable. * @param projectType the type of project, such as ME or SE. * @return the newly created BProject if successful, null otherwise. */ public BProject newProject(File directory, int projectType) { if (!myWrapper.isValid()) throw new ExtensionUnloadedException(); String pathString = directory.getAbsolutePath(); if (!pathString.endsWith(File.separator)) pathString += File.separator; if (!Project.createNewProject(pathString, projectType == ME_PROJECT)) return null; return openProject(directory); }
/** * Notify to all valid extensions that this menu Item is about to be displayed. * * @param event The associated event */ @Override public void popupMenuWillBecomeVisible(PopupMenuEvent event) { int itemsCount = 0; JPopupMenu aPopup = (JPopupMenu) event.getSource(); MenuElement[] elements = aPopup.getSubElements(); for (int index = 0; index < elements.length; index++) { JComponent aComponent = (JComponent) elements[index].getComponent(); if (aComponent == null) { continue; } if (!(aComponent instanceof JMenuItem)) { continue; } ExtensionWrapper aWrapper = (ExtensionWrapper) aComponent.getClientProperty("bluej.extmgr.ExtensionWrapper"); if (aWrapper == null) { continue; } if (!aWrapper.isValid()) { popupMenu.remove(aComponent); continue; } aWrapper.safePostMenuItem(menuGenerator, (JMenuItem) aComponent); itemsCount++; } if (itemsCount <= 0) { popupMenu.remove(menuSeparator); } }
/** * Returns the language-dependent label with the given key. The search order is to look first in * the extension's <code>label</code> files and if the requested label is not found in the BlueJ * system <code>label</code> files. Extensions' labels are stored in a Property format and must be * jarred together with the extension. The path searched is equivalent to the bluej/lib/[language] * style used for the BlueJ system labels. E.g. to create a set of labels which can be used by * English, Italian and German users of an extension, the following files would need to be present * in the extension's Jar file: * * <pre> * lib/english/label * lib/italian/label * lib/german/label * </pre> * * The files named <code>label</code> would contain the actual label key/value pairs. * * @param key Description of the Parameter * @return The label value */ public String getLabel(String key) { if (!myWrapper.isValid()) throw new ExtensionUnloadedException(); // If there are no label for this extension I can only return the system ones. if (localLabels == null) return Config.getString(key, key); // In theory there are label for this extension let me try to get them String aLabel = localLabels.getProperty(key, null); // Found what I wanted, job done. if (aLabel != null) return aLabel; // ok, the only hope is to get it from the system return Config.getString(key, key); }
/** * Returns all currently open projects. Returns an empty array if no projects are open. * * @return The openProjects value */ public BProject[] getOpenProjects() { if (!myWrapper.isValid()) throw new ExtensionUnloadedException(); Collection projects = Project.getProjects(); BProject[] result = new BProject[projects.size()]; Iterator iter; int index; for (iter = projects.iterator(), index = 0; iter.hasNext(); index++) { Project prj = (Project) iter.next(); result[index] = prj.getBProject(); } return result; }
/** * Returns the currently selected package. The current package is the one that is currently * selected by the user interface. It can return null if there is no currently open package. * * @return The currentPackage value */ public BPackage getCurrentPackage() { if (!myWrapper.isValid()) throw new ExtensionUnloadedException(); // This is here and NOT into a BProject since it depends on user interface. PkgMgrFrame pmf = PkgMgrFrame.getMostRecent(); // If there is nothing at all open there is no Frame open... if (pmf == null) return null; Package pkg = pmf.getPackage(); // The frame may be there BUT have no package. if (pkg == null) return null; return pkg.getBPackage(); }
/** * Constructor for a BlueJ proxy object. See the ExtensionBridge class * * @param aWrapper Description of the Parameter * @param aPrefManager Description of the Parameter */ BlueJ(ExtensionWrapper aWrapper, ExtensionPrefManager aPrefManager) { myWrapper = aWrapper; prefManager = aPrefManager; eventListeners = new ArrayList(); applicationListeners = new ArrayList(); packageListeners = new ArrayList(); compileListeners = new ArrayList(); invocationListeners = new ArrayList(); classListeners = new ArrayList(); /* I do NOT want lazy initialization otherwise I may try to load it * may times just because I cannof find anything. * Or having state variables to know I I did load it but had nothing found */ localLabels = myWrapper.getLabelProperties(); }
public static final void remove(List fileList, ExtensionWrapper ext, TaskMonitor monitor) throws Exception { List resourceList = ext.getResourceList(); for (Iterator iter = fileList.iterator(); iter.hasNext(); ) { File file = (File) iter.next(); if (file.isFile()) { if (resourceList.contains(file.getName())) { // System.out.println("will delete: " + file); monitor.report( I18N.get("deejump.pluging.manager.ExtensionHelper.Deleting-file") + " " + file); boolean deleted = false; try { deleted = file.delete(); } catch (SecurityException e) { // TODO decide if re-throw here or handle or log?? e.printStackTrace(); } // TODO throw exc if false. // hmm no exception thrown? // file permissions? // bye bye System.out.println( I18N.get("deejump.pluging.manager.ExtensionHelper.deleted") + " '" + file + "': " + deleted); // ???? above hasn't worked, file locked? del on exited didn'T work... // put file on a list and finish it off? // inlcude in a plug-in, listener --> workbench.isclosed -> del file! // file.deleteOnExit(); } } } }
/** * Sets a property associated with this extension into the standard BlueJ property repository. The * property name does not need to be fully qualified since a prefix will be prepended to it. * * @param property The name of the required global property * @param value the required value of that property. */ public void setExtensionPropertyString(String property, String value) { if (!myWrapper.isValid()) throw new ExtensionUnloadedException(); String thisKey = myWrapper.getSettingsString(property); Config.putPropString(thisKey, value); }
/** * Return a property associated with this extension from the standard BlueJ property repository. * You must use the setExtensionPropertyString to write any property that you want stored. You can * then come back and retrieve it using this function. * * @param property The name of the required global property. * @param def The default value to use if the property cannot be found. * @return the value of that property. */ public String getExtensionPropertyString(String property, String def) { if (!myWrapper.isValid()) throw new ExtensionUnloadedException(); String thisKey = myWrapper.getSettingsString(property); return Config.getPropString(thisKey, def); }
/** * Returns a property from BlueJ's properties, or the given default value if the property is not * currently set. * * @param property The name of the required global property * @param def The default value to use if the property cannot be found. * @return the value of the property. */ public String getBlueJPropertyString(String property, String def) { if (!myWrapper.isValid()) throw new ExtensionUnloadedException(); return Config.getPropString(property, def); }
/** * Returns the path of the user configuration directory. This can be used to locate user dependent * information. Having the directory you can then locate a file within it. * * @return The userConfigDir value */ public File getUserConfigDir() { if (!myWrapper.isValid()) throw new ExtensionUnloadedException(); return Config.getUserConfigDir(); }
/** * Returns the path of the <code><BLUEJ_HOME>/lib</code> system directory. This can be used * to locate systemwide configuration files. Having the directory you can then locate a file * within it. * * @return The systemLibDir value */ public File getSystemLibDir() { if (!myWrapper.isValid()) throw new ExtensionUnloadedException(); return Config.getBlueJLibDir(); }
/** * Install a new preference panel for this extension. If you want to delete a previously installed * preference panel, then set it to null * * @param prefGen a class instance that implements the PreferenceGenerator interface. */ public void setPreferenceGenerator(PreferenceGenerator prefGen) { if (!myWrapper.isValid()) throw new ExtensionUnloadedException(); currentPrefGen = prefGen; prefManager.panelRevalidate(); }
/** * Install a new menu generator for this extension. If you want to delete a previously installed * menu, then set it to null * * @param menuGen The new menuGenerator value */ public void setMenuGenerator(MenuGenerator menuGen) { if (!myWrapper.isValid()) throw new ExtensionUnloadedException(); currentMenuGen = menuGen; }
/** * Returns the current frame being displayed. Can be used (e.g.) as a "parent" frame for * positioning modal dialogs. If there is a package currently open, it's probably better to use * its <code>getFrame()</code> method to provide better placement. * * @return The currentFrame value */ public Frame getCurrentFrame() { if (!myWrapper.isValid()) throw new ExtensionUnloadedException(); return PkgMgrFrame.getMostRecent(); }
@Override public int compareTo(ExtensionWrapper<T> o) { return (getOrdinal() - o.getOrdinal()); }