scripting/java/com/sun/star/script/framework/provider/ScriptEditor.java | 61 +++++++++- scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java | 46 ------- scripting/java/com/sun/star/script/framework/provider/javascript/ScriptEditorForJavaScript.java | 8 + 3 files changed, 64 insertions(+), 51 deletions(-)
New commits: commit 3a95d2c35abaa0bd6e72e3ac9bb29d81a1ae29c0 Author: Samuel Mehrbrodt <samuel.mehrbr...@cib.de> AuthorDate: Fri Nov 8 12:37:11 2019 +0100 Commit: Serge Krot (CIB) <serge.k...@cib.de> CommitDate: Fri Nov 8 14:24:54 2019 +0100 Respect DisableMacrosExecution option in javascript editor Change-Id: I44c2d3a706a99839369bd4aff2abbb675e430926 Reviewed-on: https://gerrit.libreoffice.org/82286 Tested-by: Jenkins Reviewed-by: Serge Krot (CIB) <serge.k...@cib.de> (cherry picked from commit 1c42afc194da2288c5a738b727952e80c323885c) Reviewed-on: https://gerrit.libreoffice.org/82295 Tested-by: Serge Krot (CIB) <serge.k...@cib.de> diff --git a/scripting/java/com/sun/star/script/framework/provider/ScriptEditor.java b/scripting/java/com/sun/star/script/framework/provider/ScriptEditor.java index 32ebd2fefb41..dbcb3b0bc7a9 100644 --- a/scripting/java/com/sun/star/script/framework/provider/ScriptEditor.java +++ b/scripting/java/com/sun/star/script/framework/provider/ScriptEditor.java @@ -18,13 +18,62 @@ package com.sun.star.script.framework.provider; +import com.sun.star.beans.NamedValue; +import com.sun.star.configuration.theDefaultProvider; +import com.sun.star.container.XNameAccess; +import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.script.framework.container.ScriptMetaData; import com.sun.star.script.provider.XScriptContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.UnoRuntime; -public interface ScriptEditor { - Object execute() throws Exception; - void indicateErrorLine(int lineNum); - void edit(XScriptContext context, ScriptMetaData entry); - String getTemplate(); - String getExtension(); +import javax.swing.JOptionPane; +import javax.swing.JDialog; + +public abstract class ScriptEditor { + public XScriptContext context; + + public abstract Object execute() throws Exception; + public abstract void indicateErrorLine(int lineNum); + public abstract void edit(XScriptContext context, ScriptMetaData entry); + public abstract String getTemplate(); + public abstract String getExtension(); + + public void setContext(XScriptContext context) { + this.context = context; + } + + public boolean isMacroExectionEnabled() { + XNameAccess xNameAccess = null; + try { + String sAccess = "com.sun.star.configuration.ConfigurationAccess"; + XMultiServiceFactory xMSFCfg = theDefaultProvider.get(context.getComponentContext()); + Object oAccess = xMSFCfg.createInstanceWithArguments(sAccess, + new Object[] { new NamedValue("nodepath", "org.openoffice.Office.Common/Security/Scripting") }); + xNameAccess = UnoRuntime.queryInterface(XNameAccess.class, oAccess); + Object result = xNameAccess.getByName("DisableMacrosExecution"); + boolean bMacrosDisabled = AnyConverter.toBoolean(result); + if (bMacrosDisabled) + return false; + } catch (com.sun.star.uno.Exception e) { + return false; + } + return true; + } + + // Wraps long error messages + private static class NarrowOptionPane extends JOptionPane { + private static final long serialVersionUID = 1L; + public int getMaxCharactersPerLineCount() { + return 100; + } + } + + public void showErrorMessage(String message) { + JOptionPane optionPane = new NarrowOptionPane(); + optionPane.setMessage(message); + optionPane.setMessageType(JOptionPane.ERROR_MESSAGE); + JDialog dialog = optionPane.createDialog(null, "Error"); + dialog.setVisible(true); + } } \ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java index 5c12bc775786..31c26dc51334 100644 --- a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java +++ b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java @@ -17,17 +17,11 @@ */ package com.sun.star.script.framework.provider.beanshell; -import com.sun.star.beans.NamedValue; -import com.sun.star.configuration.theDefaultProvider; -import com.sun.star.container.XNameAccess; -import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.script.framework.container.ScriptMetaData; import com.sun.star.script.framework.provider.ClassLoaderFactory; import com.sun.star.script.framework.provider.ScriptEditor; import com.sun.star.script.framework.provider.SwingInvocation; import com.sun.star.script.provider.XScriptContext; -import com.sun.star.uno.AnyConverter; -import com.sun.star.uno.UnoRuntime; import java.awt.BorderLayout; import java.awt.FlowLayout; @@ -48,7 +42,6 @@ import java.util.Map; import javax.swing.JButton; import javax.swing.JComponent; -import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; @@ -56,7 +49,7 @@ import javax.swing.JPanel; import javax.swing.JToolBar; import javax.swing.BorderFactory; -public class ScriptEditorForBeanShell implements ScriptEditor, ActionListener { +public class ScriptEditorForBeanShell extends ScriptEditor implements ActionListener { private JFrame frame; private String filename; @@ -64,7 +57,6 @@ public class ScriptEditorForBeanShell implements ScriptEditor, ActionListener { private ScriptSourceModel model; private ScriptSourceView view; - private XScriptContext context; private URL scriptURL = null; private ClassLoader cl = null; private JButton saveBtn; @@ -187,24 +179,6 @@ public class ScriptEditorForBeanShell implements ScriptEditor, ActionListener { return model.execute(context, cl); } - private boolean isMacroExectionEnabled() { - XNameAccess xNameAccess = null; - try { - String sAccess = "com.sun.star.configuration.ConfigurationAccess"; - XMultiServiceFactory xMSFCfg = theDefaultProvider.get(context.getComponentContext()); - Object oAccess = xMSFCfg.createInstanceWithArguments(sAccess, - new Object[] { new NamedValue("nodepath", "org.openoffice.Office.Common/Security/Scripting") }); - xNameAccess = UnoRuntime.queryInterface(XNameAccess.class, oAccess); - Object result = xNameAccess.getByName("DisableMacrosExecution"); - boolean bMacrosDisabled = AnyConverter.toBoolean(result); - if (bMacrosDisabled) - return false; - } catch (com.sun.star.uno.Exception e) { - return false; - } - return true; - } - /** * Opens an editor window for the specified ScriptMetaData. * If an editor window is already open for that data it will be @@ -254,7 +228,7 @@ public class ScriptEditorForBeanShell implements ScriptEditor, ActionListener { private ScriptEditorForBeanShell(XScriptContext context, ClassLoader cl, URL url) { - this.context = context; + setContext(context); this.scriptURL = url; this.model = new ScriptSourceModel(url); this.filename = ScriptMetaData.getFileName(url); @@ -295,22 +269,6 @@ public class ScriptEditorForBeanShell implements ScriptEditor, ActionListener { frame.setVisible(true); } - // Wraps long error messages - private static class NarrowOptionPane extends JOptionPane { - private static final long serialVersionUID = 1L; - public int getMaxCharactersPerLineCount() { - return 100; - } - } - - private void showErrorMessage(String message) { - JOptionPane optionPane = new NarrowOptionPane(); - optionPane.setMessage(message); - optionPane.setMessageType(JOptionPane.ERROR_MESSAGE); - JDialog dialog = optionPane.createDialog(null, "Error"); - dialog.setVisible(true); - } - private void initUI() { frame = new JFrame("BeanShell Debug Window: " + filename); frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); diff --git a/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptEditorForJavaScript.java b/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptEditorForJavaScript.java index a43abc25f7cd..4cf5cc3384ca 100644 --- a/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptEditorForJavaScript.java +++ b/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptEditorForJavaScript.java @@ -40,7 +40,7 @@ import org.mozilla.javascript.Scriptable; import org.mozilla.javascript.tools.debugger.Main; import org.mozilla.javascript.tools.debugger.ScopeProvider; -public class ScriptEditorForJavaScript implements ScriptEditor { +public class ScriptEditorForJavaScript extends ScriptEditor { // global ScriptEditorForJavaScript instance private static ScriptEditorForJavaScript theScriptEditorForJavaScript; @@ -194,6 +194,12 @@ public class ScriptEditorForJavaScript implements ScriptEditor { } private ScriptEditorForJavaScript(XScriptContext context, URL url) { + setContext(context); + // Need to check that before showing the window. Checking in execute() has no effect. + if (!isMacroExectionEnabled()) { + showErrorMessage("Macro Execution has been disabled."); + return ; + } initUI(); Scriptable scope = getScope(context); rhinoWindow.openFile(url, scope, new CloseHandler(url)); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits