Search in sources :

Example 11 with ResourceController

use of org.freeplane.core.resources.ResourceController in project freeplane by freeplane.

the class MMapController method newDocumentationMap.

public void newDocumentationMap(final String file) {
    final NodeAndMapReference nodeAndMapReference = new NodeAndMapReference(file);
    final ResourceController resourceController = ResourceController.getResourceController();
    final File userDir = new File(resourceController.getFreeplaneUserDirectory());
    final File baseDir = new File(resourceController.getInstallationBaseDir());
    final String languageCode = resourceController.getLanguageCode();
    final File localFile = ConfigurationUtils.getLocalizedFile(new File[] { userDir, baseDir }, nodeAndMapReference.getMapReference(), languageCode);
    if (localFile == null) {
        String errorMessage = TextUtils.format("invalid_file_msg", file);
        UITools.errorMessage(errorMessage);
        return;
    }
    try {
        final URL endUrl = localFile.toURL();
        try {
            if (endUrl.getFile().endsWith(".mm")) {
                Controller.getCurrentController().selectMode(MModeController.MODENAME);
                newDocumentationMap(endUrl);
                if (nodeAndMapReference.hasNodeReference())
                    select(nodeAndMapReference.getNodeReference());
            } else {
                Controller.getCurrentController().getViewController().openDocument(endUrl);
            }
        } catch (final Exception e1) {
            LogUtils.severe(e1);
        }
    } catch (final MalformedURLException e1) {
        LogUtils.warn(e1);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ResourceController(org.freeplane.core.resources.ResourceController) NodeAndMapReference(org.freeplane.features.url.NodeAndMapReference) File(java.io.File) URL(java.net.URL) XMLException(org.freeplane.n3.nanoxml.XMLException) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 12 with ResourceController

use of org.freeplane.core.resources.ResourceController in project freeplane by freeplane.

the class SpellCheckerController method registerDictionaries.

private void registerDictionaries(final File orthoDir) {
    if (!orthoDir.isDirectory())
        return;
    final String[] dictionaryList = orthoDir.list(new FilenameFilter() {

        public boolean accept(final File dir, final String name) {
            return name.length() == "dictionary_XX.ortho".length() && name.startsWith("dictionary_") && name.endsWith(".ortho");
        }
    });
    if (dictionaryList.length == 0) {
        return;
    }
    final ResourceController resourceController = ResourceController.getResourceController();
    SpellChecker.setUserDictionaryProvider(new FileUserDictionary(resourceController.getFreeplaneUserDirectory()));
    final StringBuilder availableLocales = new StringBuilder();
    for (int i = 0; i < dictionaryList.length; i++) {
        final String language = dictionaryList[i].substring("dictionary_".length(), "dictionary_".length() + 2);
        availableLocales.append(language);
        availableLocales.append(",");
    }
    try {
        SpellChecker.registerDictionaries(orthoDir.toURI().toURL(), availableLocales.toString(), null, ".ortho");
        spellCheckerEnabled = true;
    } catch (final MalformedURLException e) {
        LogUtils.severe(e);
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) FileUserDictionary(com.inet.jortho.FileUserDictionary) MalformedURLException(java.net.MalformedURLException) ResourceController(org.freeplane.core.resources.ResourceController) File(java.io.File)

Example 13 with ResourceController

use of org.freeplane.core.resources.ResourceController in project freeplane by freeplane.

the class SignedScriptHandler method signScript.

public String signScript(final String pScript) {
    final ScriptContents content = new ScriptContents(pScript);
    final EnterPasswordDialog pwdDialog = new EnterPasswordDialog(UITools.getCurrentFrame(), false);
    pwdDialog.setModal(true);
    pwdDialog.setVisible(true);
    if (pwdDialog.getResult() == EnterPasswordDialog.CANCEL) {
        return content.mScript;
    }
    final char[] password = pwdDialog.getPassword().toString().toCharArray();
    initializeKeystore(password);
    try {
        final Signature instance = Signature.getInstance("SHA1withDSA");
        String keyName = FREEPLANE_SCRIPT_KEY_NAME;
        final ResourceController resourceController = ResourceController.getResourceController();
        String propertyKeyName = resourceController.getProperty(ScriptingPermissions.RESOURCES_SCRIPT_USER_KEY_NAME_FOR_SIGNING);
        if (propertyKeyName == null || propertyKeyName.trim().length() == 0) {
            resourceController.setProperty(ScriptingPermissions.RESOURCES_SCRIPT_USER_KEY_NAME_FOR_SIGNING, FREEPLANE_SCRIPT_KEY_NAME);
            propertyKeyName = keyName;
        }
        if (content.mKeyName != null) {
            keyName = content.mKeyName;
        } else {
            content.mKeyName = propertyKeyName;
            keyName = content.mKeyName;
        }
        instance.initSign((PrivateKey) SignedScriptHandler.mKeyStore.getKey(keyName, password));
        instance.update(content.mScript.getBytes());
        final byte[] signature = instance.sign();
        content.mSignature = DesEncrypter.toBase64(signature);
        return content.toString();
    } catch (final Exception e) {
        if (!(e instanceof KeyStoreException))
            LogUtils.severe(e);
        UITools.errorMessage(e.getLocalizedMessage());
    }
    return content.mScript;
}
Also used : ResourceController(org.freeplane.core.resources.ResourceController) Signature(java.security.Signature) KeyStoreException(java.security.KeyStoreException) EnterPasswordDialog(org.freeplane.core.ui.components.EnterPasswordDialog) IOException(java.io.IOException) KeyStoreException(java.security.KeyStoreException) FileNotFoundException(java.io.FileNotFoundException)

Example 14 with ResourceController

use of org.freeplane.core.resources.ResourceController in project freeplane by freeplane.

the class AddOnInstallerPanel method createInstallActionListener.

private ActionListener createInstallActionListener() {
    return new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            final Controller controller = Controller.getCurrentController();
            try {
                LogUtils.info("installing add-on from " + urlField.getText());
                controller.getViewController().setWaitingCursor(true);
                final URL url = toURL(urlField.getText());
                setStatusInfo(getText("status.installing"));
                final ModeController modeController = controller.getModeController(MModeController.MODENAME);
                final MFileManager fileManager = (MFileManager) MFileManager.getController(modeController);
                MapModel newMap = new MMapModel();
                if (!fileManager.loadCatchExceptions(url, newMap)) {
                    LogUtils.warn("can not load " + url);
                    return;
                }
                controller.getModeController().getMapController().fireMapCreated(newMap);
                AddOnProperties addOn = (AddOnProperties) ScriptingEngine.executeScript(newMap.getRootNode(), getInstallScriptSource(), ScriptingPermissions.getPermissiveScriptingPermissions());
                if (addOn != null) {
                    setStatusInfo(getText("status.success", addOn.getName()));
                    AddOnsController.getController().registerInstalledAddOn(addOn);
                    final ManageAddOnsPanel managementPanel = addOn.isTheme() ? manageThemesPanel : manageAddOnsPanel;
                    managementPanel.getTableModel().addAddOn(addOn);
                    urlField.setText("");
                    ((JTabbedPane) getParent()).setSelectedComponent(managementPanel);
                    selectLastAddOn(managementPanel);
                }
            } catch (Exception ex) {
                UITools.errorMessage(getText("error", ex.toString()));
            } finally {
                controller.getViewController().setWaitingCursor(false);
            }
        }

        private String getInstallScriptSource() throws IOException {
            final ResourceController resourceController = ResourceController.getResourceController();
            final File scriptDir = new File(resourceController.getInstallationBaseDir(), "scripts");
            final File installScript = new File(scriptDir, "installScriptAddOn.groovy");
            if (!installScript.exists())
                throw new RuntimeException("internal error: installer not found at " + installScript);
            return FileUtils.slurpFile(installScript);
        }

        private URL toURL(String urlText) throws MalformedURLException {
            try {
                return new URL(urlText);
            } catch (Exception e2) {
                return new File(urlText).toURI().toURL();
            }
        }
    };
}
Also used : ActionEvent(java.awt.event.ActionEvent) MMapModel(org.freeplane.features.map.mindmapmode.MMapModel) JTabbedPane(javax.swing.JTabbedPane) MFileManager(org.freeplane.features.url.mindmapmode.MFileManager) ModeController(org.freeplane.features.mode.ModeController) MModeController(org.freeplane.features.mode.mindmapmode.MModeController) MMapModel(org.freeplane.features.map.mindmapmode.MMapModel) MapModel(org.freeplane.features.map.MapModel) AddOnsController(org.freeplane.main.addons.AddOnsController) ResourceController(org.freeplane.core.resources.ResourceController) Controller(org.freeplane.features.mode.Controller) ModeController(org.freeplane.features.mode.ModeController) MModeController(org.freeplane.features.mode.mindmapmode.MModeController) URL(java.net.URL) AddOnProperties(org.freeplane.main.addons.AddOnProperties) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ActionListener(java.awt.event.ActionListener) ResourceController(org.freeplane.core.resources.ResourceController) File(java.io.File)

Example 15 with ResourceController

use of org.freeplane.core.resources.ResourceController in project freeplane by freeplane.

the class IconStoreFactory method getUserIcons.

private static List<MindIcon> getUserIcons() {
    final ResourceController resourceController = ResourceController.getResourceController();
    if (resourceController.isApplet()) {
        return Collections.emptyList();
    }
    final File iconDir = new File(resourceController.getFreeplaneUserDirectory(), "icons");
    if (!iconDir.exists()) {
        LogUtils.info("creating user icons directory " + iconDir);
        iconDir.mkdirs();
        return Collections.emptyList();
    }
    return IconStoreFactory.getUserIcons(iconDir, "");
}
Also used : ResourceController(org.freeplane.core.resources.ResourceController) File(java.io.File)

Aggregations

ResourceController (org.freeplane.core.resources.ResourceController)31 File (java.io.File)8 IOException (java.io.IOException)7 URL (java.net.URL)6 MalformedURLException (java.net.MalformedURLException)4 URISyntaxException (java.net.URISyntaxException)3 Point (java.awt.Point)2 BufferedInputStream (java.io.BufferedInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStream (java.io.InputStream)2 StringReader (java.io.StringReader)2 Box (javax.swing.Box)2 Controller (org.freeplane.features.mode.Controller)2 ModeController (org.freeplane.features.mode.ModeController)2 MModeController (org.freeplane.features.mode.mindmapmode.MModeController)2 FileUserDictionary (com.inet.jortho.FileUserDictionary)1 LanguageChangeEvent (com.inet.jortho.LanguageChangeEvent)1 LanguageChangeListener (com.inet.jortho.LanguageChangeListener)1 Color (java.awt.Color)1 Dimension (java.awt.Dimension)1