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);
}
}
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);
}
}
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;
}
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();
}
}
};
}
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, "");
}
Aggregations