scripting/java/Framework/com/sun/star/script/framework/security/SecurityDialog.java | 246 ++++++---- scripting/java/com/sun/star/script/framework/browse/DialogFactory.java | 95 ++- scripting/java/com/sun/star/script/framework/browse/ParcelBrowseNode.java | 86 +-- scripting/java/com/sun/star/script/framework/browse/PkgProviderBrowseNode.java | 6 scripting/java/com/sun/star/script/framework/browse/ProviderBrowseNode.java | 70 +- scripting/java/com/sun/star/script/framework/browse/ScriptBrowseNode.java | 114 ++-- scripting/java/com/sun/star/script/framework/container/DeployedUnoPackagesDB.java | 8 scripting/java/com/sun/star/script/framework/container/Parcel.java | 63 +- scripting/java/com/sun/star/script/framework/container/ParcelContainer.java | 177 ++++--- scripting/java/com/sun/star/script/framework/container/ParcelDescriptor.java | 15 scripting/java/com/sun/star/script/framework/container/ParsedScriptUri.java | 3 scripting/java/com/sun/star/script/framework/container/ScriptEntry.java | 9 scripting/java/com/sun/star/script/framework/container/ScriptMetaData.java | 52 +- scripting/java/com/sun/star/script/framework/container/UnoPkgContainer.java | 100 ++-- scripting/java/com/sun/star/script/framework/container/XMLParser.java | 2 scripting/java/com/sun/star/script/framework/container/XMLParserFactory.java | 55 +- scripting/java/com/sun/star/script/framework/io/UCBStreamHandler.java | 47 + scripting/java/com/sun/star/script/framework/io/XInputStreamImpl.java | 19 scripting/java/com/sun/star/script/framework/io/XInputStreamWrapper.java | 4 scripting/java/com/sun/star/script/framework/io/XOutputStreamWrapper.java | 24 scripting/java/com/sun/star/script/framework/io/XStorageHelper.java | 53 +- scripting/java/com/sun/star/script/framework/log/LogUtils.java | 2 scripting/java/com/sun/star/script/framework/provider/ClassLoaderFactory.java | 5 scripting/java/com/sun/star/script/framework/provider/EditorScriptContext.java | 16 scripting/java/com/sun/star/script/framework/provider/NoSuitableClassLoaderException.java | 5 scripting/java/com/sun/star/script/framework/provider/PathUtils.java | 10 scripting/java/com/sun/star/script/framework/provider/ScriptContext.java | 24 scripting/java/com/sun/star/script/framework/provider/ScriptEditor.java | 2 scripting/java/com/sun/star/script/framework/provider/ScriptProvider.java | 239 ++++----- scripting/java/com/sun/star/script/framework/provider/SwingInvocation.java | 3 scripting/java/com/sun/star/script/framework/provider/beanshell/PlainSourceView.java | 6 scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java | 26 - scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptProviderForBeanShell.java | 116 ++-- scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptSourceModel.java | 3 scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptSourceView.java | 2 scripting/java/com/sun/star/script/framework/provider/java/Resolver.java | 10 scripting/java/com/sun/star/script/framework/provider/java/ScriptDescriptor.java | 20 scripting/java/com/sun/star/script/framework/provider/java/ScriptProviderForJava.java | 124 ++--- scripting/java/com/sun/star/script/framework/provider/java/ScriptProxy.java | 14 scripting/java/com/sun/star/script/framework/provider/java/StrictResolver.java | 33 - scripting/java/com/sun/star/script/framework/provider/javascript/ScriptEditorForJavaScript.java | 24 scripting/java/com/sun/star/script/framework/provider/javascript/ScriptProviderForJavaScript.java | 79 +-- scripting/java/org/openoffice/netbeans/modules/office/actions/DeployParcelAction.java | 8 43 files changed, 1136 insertions(+), 883 deletions(-)
New commits: commit e41597eade24f04893752a4339112b13419fefdd Author: Robert Antoni Buj i Gelonch <robert....@gmail.com> Date: Fri Oct 3 17:07:28 2014 +0200 scripting: line break (code formatting) Change-Id: Ib1a8d7e4bdaad2f4eae822d9af280fd5b6f9dd7b Reviewed-on: https://gerrit.libreoffice.org/11794 Reviewed-by: David Tardon <dtar...@redhat.com> Tested-by: David Tardon <dtar...@redhat.com> diff --git a/scripting/java/Framework/com/sun/star/script/framework/security/SecurityDialog.java b/scripting/java/Framework/com/sun/star/script/framework/security/SecurityDialog.java index 3a4f413..b9df352 100644 --- a/scripting/java/Framework/com/sun/star/script/framework/security/SecurityDialog.java +++ b/scripting/java/Framework/com/sun/star/script/framework/security/SecurityDialog.java @@ -55,29 +55,35 @@ import com.sun.star.uno.RuntimeException; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XComponentContext; -public class SecurityDialog extends WeakBase implements XComponent, - XServiceInfo, XDialog, - XInitialization { +public class SecurityDialog extends WeakBase implements + XComponent, XServiceInfo, XDialog, XInitialization { static final String __serviceName = "com.sun.star.script.framework.security.SecurityDialog"; private static final String _label1Name = "Label1"; + private static final String _label1String = "This document contains macros. Do you want to allow these macros to be run?"; private static final String _label2Name = "Label2"; + private static final String _label2String = "This document contains macros. According to the security settings, the"; + private static final String _label3Name = "Label3"; + private static final String _label3String = "macros in this document should not be run. Do you want to run them"; + private static final String _label4Name = "Label4"; private static final String _label4String = "anyway?"; private static final String _checkBoxName = "CheckBox"; + private static final String _checkBoxString = "Add this directory to the list of secure paths: "; + private static final String _label5Name = "Label5"; private static final String _title = "Run Macro"; @@ -173,8 +179,7 @@ public class SecurityDialog extends WeakBase implements XComponent, } } else { - LogUtils.DEBUG("no checkbox: # of args=" + - args.length); + LogUtils.DEBUG("no checkbox: # of args=" + args.length); cbIncrW = 0; cbIncrH = 0; checkBoxDialog = false; @@ -197,13 +202,17 @@ public class SecurityDialog extends WeakBase implements XComponent, // static component operations public static XSingleServiceFactory __getServiceFactory(String implName, - XMultiServiceFactory multiFactory, - XRegistryKey regKey) { + XMultiServiceFactory multiFactory, XRegistryKey regKey) { + XSingleServiceFactory xSingleServiceFactory = null; if (implName.equals(SecurityDialog.class.getName())) { - xSingleServiceFactory = FactoryHelper.getServiceFactory( - SecurityDialog.class, SecurityDialog.__serviceName, multiFactory, regKey); + + xSingleServiceFactory = + FactoryHelper.getServiceFactory(SecurityDialog.class, + SecurityDialog.__serviceName, + multiFactory, regKey); + } return xSingleServiceFactory; @@ -226,7 +235,6 @@ public class SecurityDialog extends WeakBase implements XComponent, return retValue; } - /** method for creating a dialog at runtime */ private XDialog createDialog() throws com.sun.star.uno.Exception { @@ -236,10 +244,13 @@ public class SecurityDialog extends WeakBase implements XComponent, _xComponentContext.getServiceManager(); // create the dialog model and set the properties - Object dialogModel = xMultiComponentFactory.createInstanceWithContext( - "com.sun.star.awt.UnoControlDialogModel", _xComponentContext); - XPropertySet xPSetDialog = UnoRuntime.queryInterface( - XPropertySet.class, dialogModel); + Object dialogModel = + xMultiComponentFactory.createInstanceWithContext( + "com.sun.star.awt.UnoControlDialogModel", _xComponentContext); + + XPropertySet xPSetDialog = + UnoRuntime.queryInterface(XPropertySet.class, dialogModel); + xPSetDialog.setPropertyValue("PositionX", Integer.valueOf(dialogX)); xPSetDialog.setPropertyValue("PositionY", Integer.valueOf(dialogY)); xPSetDialog.setPropertyValue("Width", Integer.valueOf(dialogW + cbIncrW)); @@ -247,20 +258,26 @@ public class SecurityDialog extends WeakBase implements XComponent, xPSetDialog.setPropertyValue("Title", _title); // get the service manager from the dialog model - XMultiServiceFactory xMultiServiceFactory = UnoRuntime.queryInterface( - XMultiServiceFactory.class, dialogModel); + XMultiServiceFactory xMultiServiceFactory = + UnoRuntime.queryInterface(XMultiServiceFactory.class, dialogModel); // create the Run Macro button model and set the properties - Object runButtonModel = xMultiServiceFactory.createInstance( - "com.sun.star.awt.UnoControlButtonModel"); - XPropertySet xPSetButton = UnoRuntime.queryInterface( - XPropertySet.class, runButtonModel); + Object runButtonModel = + xMultiServiceFactory.createInstance( + "com.sun.star.awt.UnoControlButtonModel"); + + XPropertySet xPSetButton = + UnoRuntime.queryInterface(XPropertySet.class, runButtonModel); + LogUtils.DEBUG("run: x=" + (((dialogW + cbIncrW) / 2) - runButtonW - 1)); LogUtils.DEBUG("run: y=" + (dialogH + cbIncrH - runButtonH - 1)); - xPSetButton.setPropertyValue("PositionX", - Integer.valueOf((((dialogW + cbIncrW) / 2) - runButtonW - 1))); - xPSetButton.setPropertyValue("PositionY", - Integer.valueOf(dialogH + cbIncrH - runButtonH - 1)); + + xPSetButton.setPropertyValue( + "PositionX", Integer.valueOf((((dialogW + cbIncrW) / 2) - runButtonW - 1))); + + xPSetButton.setPropertyValue( + "PositionY", Integer.valueOf(dialogH + cbIncrH - runButtonH - 1)); + xPSetButton.setPropertyValue("Width", Integer.valueOf(runButtonW)); xPSetButton.setPropertyValue("Height", Integer.valueOf(runButtonH)); xPSetButton.setPropertyValue("Name", _runButtonName); @@ -268,16 +285,22 @@ public class SecurityDialog extends WeakBase implements XComponent, xPSetButton.setPropertyValue("Label", _runMacro); // create the Dont Run Macro button model and set the properties - Object doNotRunButtonModel = xMultiServiceFactory.createInstance( - "com.sun.star.awt.UnoControlButtonModel"); - xPSetButton = UnoRuntime.queryInterface( - XPropertySet.class, doNotRunButtonModel); + Object doNotRunButtonModel = + xMultiServiceFactory.createInstance( + "com.sun.star.awt.UnoControlButtonModel"); + + xPSetButton = + UnoRuntime.queryInterface(XPropertySet.class, doNotRunButtonModel); + LogUtils.DEBUG("dontrun: x=" + (((dialogW + cbIncrW) / 2) - 1)); LogUtils.DEBUG("dontrun: y=" + (dialogH + cbIncrH - doNotRunButtonH - 1)); - xPSetButton.setPropertyValue("PositionX", - Integer.valueOf((((dialogW + cbIncrW) / 2) + 1))); - xPSetButton.setPropertyValue("PositionY", - Integer.valueOf((dialogH + cbIncrH - doNotRunButtonH - 1))); + + xPSetButton.setPropertyValue( + "PositionX", Integer.valueOf((((dialogW + cbIncrW) / 2) + 1))); + + xPSetButton.setPropertyValue( + "PositionY", Integer.valueOf((dialogH + cbIncrH - doNotRunButtonH - 1))); + xPSetButton.setPropertyValue("Width", Integer.valueOf(doNotRunButtonW)); xPSetButton.setPropertyValue("Height", Integer.valueOf(doNotRunButtonH)); xPSetButton.setPropertyValue("Name", _doNotRunButtonName); @@ -285,18 +308,23 @@ public class SecurityDialog extends WeakBase implements XComponent, xPSetButton.setPropertyValue("Label", _doNotRunMacro); // insert the control models into the dialog model - XNameContainer xNameCont = UnoRuntime.queryInterface( - XNameContainer.class, dialogModel); + XNameContainer xNameCont = + UnoRuntime.queryInterface(XNameContainer.class, dialogModel); + xNameCont.insertByName(_runButtonName, runButtonModel); xNameCont.insertByName(_doNotRunButtonName, doNotRunButtonModel); if (checkBoxDialog) { LogUtils.DEBUG("creating label & checkbox"); + // create the label model and set the properties - Object label2Model = xMultiServiceFactory.createInstance( - "com.sun.star.awt.UnoControlFixedTextModel"); - XPropertySet xPSetLabel = UnoRuntime.queryInterface( - XPropertySet.class, label2Model); + Object label2Model = + xMultiServiceFactory.createInstance( + "com.sun.star.awt.UnoControlFixedTextModel"); + + XPropertySet xPSetLabel = + UnoRuntime.queryInterface(XPropertySet.class, label2Model); + xPSetLabel.setPropertyValue("PositionX", Integer.valueOf(label2X)); xPSetLabel.setPropertyValue("PositionY", Integer.valueOf(label2Y)); xPSetLabel.setPropertyValue("Width", Integer.valueOf(label2W)); @@ -306,10 +334,13 @@ public class SecurityDialog extends WeakBase implements XComponent, xPSetLabel.setPropertyValue("Label", _label2String); // create the label model and set the properties - Object label3Model = xMultiServiceFactory.createInstance( - "com.sun.star.awt.UnoControlFixedTextModel"); - XPropertySet xPSetLabel3 = UnoRuntime.queryInterface( - XPropertySet.class, label3Model); + Object label3Model = + xMultiServiceFactory.createInstance( + "com.sun.star.awt.UnoControlFixedTextModel"); + + XPropertySet xPSetLabel3 = + UnoRuntime.queryInterface(XPropertySet.class, label3Model); + xPSetLabel3.setPropertyValue("PositionX", Integer.valueOf(label3X)); xPSetLabel3.setPropertyValue("PositionY", Integer.valueOf(label3Y)); xPSetLabel3.setPropertyValue("Width", Integer.valueOf(label3W)); @@ -319,10 +350,13 @@ public class SecurityDialog extends WeakBase implements XComponent, xPSetLabel3.setPropertyValue("Label", _label3String); // create the label model and set the properties - Object label4Model = xMultiServiceFactory.createInstance( - "com.sun.star.awt.UnoControlFixedTextModel"); - XPropertySet xPSetLabel4 = UnoRuntime.queryInterface( - XPropertySet.class, label4Model); + Object label4Model = + xMultiServiceFactory.createInstance( + "com.sun.star.awt.UnoControlFixedTextModel"); + + XPropertySet xPSetLabel4 = + UnoRuntime.queryInterface(XPropertySet.class, label4Model); + xPSetLabel4.setPropertyValue("PositionX", Integer.valueOf(label4X)); xPSetLabel4.setPropertyValue("PositionY", Integer.valueOf(label4Y)); xPSetLabel4.setPropertyValue("Width", Integer.valueOf(label4W)); @@ -332,10 +366,13 @@ public class SecurityDialog extends WeakBase implements XComponent, xPSetLabel4.setPropertyValue("Label", _label4String); // create the checkbox model and set the properties - Object checkBoxModel = xMultiServiceFactory.createInstance( - "com.sun.star.awt.UnoControlCheckBoxModel"); - XPropertySet xPSetCheckBox = UnoRuntime.queryInterface( - XPropertySet.class, checkBoxModel); + Object checkBoxModel = + xMultiServiceFactory.createInstance( + "com.sun.star.awt.UnoControlCheckBoxModel"); + + XPropertySet xPSetCheckBox = + UnoRuntime.queryInterface(XPropertySet.class, checkBoxModel); + xPSetCheckBox.setPropertyValue("PositionX", Integer.valueOf(checkBoxX)); xPSetCheckBox.setPropertyValue("PositionY", Integer.valueOf(checkBoxY)); xPSetCheckBox.setPropertyValue("Width", Integer.valueOf(checkBoxW)); @@ -352,11 +389,15 @@ public class SecurityDialog extends WeakBase implements XComponent, xNameCont.insertByName(_checkBoxName, checkBoxModel); if (extraPathLine) { + // create the label model and set the properties - Object label5Model = xMultiServiceFactory.createInstance( - "com.sun.star.awt.UnoControlFixedTextModel"); - XPropertySet xPSetLabel5 = UnoRuntime.queryInterface( - XPropertySet.class, label5Model); + Object label5Model = + xMultiServiceFactory.createInstance( + "com.sun.star.awt.UnoControlFixedTextModel"); + + XPropertySet xPSetLabel5 = + UnoRuntime.queryInterface(XPropertySet.class, label5Model); + xPSetLabel5.setPropertyValue("PositionX", Integer.valueOf(label5X)); xPSetLabel5.setPropertyValue("PositionY", Integer.valueOf(label5Y)); xPSetLabel5.setPropertyValue("Width", Integer.valueOf(label5W)); @@ -368,10 +409,13 @@ public class SecurityDialog extends WeakBase implements XComponent, } } else { // create the label model and set the properties - Object labelModel = xMultiServiceFactory.createInstance( - "com.sun.star.awt.UnoControlFixedTextModel"); - XPropertySet xPSetLabel = UnoRuntime.queryInterface( - XPropertySet.class, labelModel); + Object labelModel = + xMultiServiceFactory.createInstance( + "com.sun.star.awt.UnoControlFixedTextModel"); + + XPropertySet xPSetLabel = + UnoRuntime.queryInterface(XPropertySet.class, labelModel); + xPSetLabel.setPropertyValue("PositionX", Integer.valueOf(label1X)); xPSetLabel.setPropertyValue("PositionY", Integer.valueOf(label1Y)); xPSetLabel.setPropertyValue("Width", Integer.valueOf(label1W)); @@ -385,53 +429,63 @@ public class SecurityDialog extends WeakBase implements XComponent, } // create the dialog control and set the model - Object dialog = xMultiComponentFactory.createInstanceWithContext( - "com.sun.star.awt.UnoControlDialog", _xComponentContext); - XControl xControl = UnoRuntime.queryInterface( - XControl.class, dialog); - XControlModel xControlModel = UnoRuntime.queryInterface( - XControlModel.class, dialogModel); + Object dialog = + xMultiComponentFactory.createInstanceWithContext( + "com.sun.star.awt.UnoControlDialog", _xComponentContext); + + XControl xControl = + UnoRuntime.queryInterface(XControl.class, dialog); + + XControlModel xControlModel = + UnoRuntime.queryInterface(XControlModel.class, dialogModel); + xControl.setModel(xControlModel); // add an action listener to the button control - XControlContainer xControlCont = UnoRuntime.queryInterface( - XControlContainer.class, dialog); + XControlContainer xControlCont = + UnoRuntime.queryInterface(XControlContainer.class, dialog); // Add to yes button Object objectButton = xControlCont.getControl(_runButtonName); - XButton xButton = UnoRuntime.queryInterface( - XButton.class, objectButton); + + XButton xButton = + UnoRuntime.queryInterface(XButton.class, objectButton); + xButton.addActionListener(new ActionListenerImpl(_runButtonName)); // add to no button objectButton = xControlCont.getControl(_doNotRunButtonName); - xButton = UnoRuntime.queryInterface( - XButton.class, objectButton); + + xButton = + UnoRuntime.queryInterface(XButton.class, objectButton); + xButton.addActionListener(new ActionListenerImpl(_doNotRunButtonName)); if (checkBoxDialog) { // add to checkbox Object objectCheckBox = xControlCont.getControl(_checkBoxName); - XCheckBox xCheckBox = UnoRuntime.queryInterface( - XCheckBox.class, objectCheckBox); + + XCheckBox xCheckBox = + UnoRuntime.queryInterface(XCheckBox.class, objectCheckBox); + xCheckBox.addItemListener(new ItemListenerImpl(xControlCont)); } // create a peer - Object toolkit = xMultiComponentFactory.createInstanceWithContext( - "com.sun.star.awt.ExtToolkit", _xComponentContext); - XToolkit xToolkit = UnoRuntime.queryInterface( - XToolkit.class, toolkit); - XWindow xWindow = UnoRuntime.queryInterface( - XWindow.class, xControl); + Object toolkit = + xMultiComponentFactory.createInstanceWithContext( + "com.sun.star.awt.ExtToolkit", _xComponentContext); + + XToolkit xToolkit = UnoRuntime.queryInterface(XToolkit.class, toolkit); + XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, xControl); xWindow.setVisible(false); xControl.createPeer(xToolkit, null); // return the dialog - XDialog xDialog = UnoRuntime.queryInterface( - XDialog.class, dialog); + XDialog xDialog = UnoRuntime.queryInterface(XDialog.class, dialog); return xDialog; } + public short execute() { short result = 0; @@ -464,26 +518,33 @@ public class SecurityDialog extends WeakBase implements XComponent, } public void dispose() { - XComponent xComponent = UnoRuntime.queryInterface( - XComponent.class, _xDialog); + + XComponent xComponent = + UnoRuntime.queryInterface(XComponent.class, _xDialog); + xComponent.dispose(); } public void addEventListener(com.sun.star.lang.XEventListener xListener) { - XComponent xComponent = UnoRuntime.queryInterface( - XComponent.class, _xDialog); + + XComponent xComponent = + UnoRuntime.queryInterface(XComponent.class, _xDialog); + xComponent.addEventListener(xListener); } - public void removeEventListener(com.sun.star.lang.XEventListener aListener) { - XComponent xComponent = UnoRuntime.queryInterface( - XComponent.class, _xDialog); + + XComponent xComponent = + UnoRuntime.queryInterface(XComponent.class, _xDialog); + xComponent.removeEventListener(aListener); } private class ActionListenerImpl implements com.sun.star.awt.XActionListener { + private String _buttonName; + private ActionListenerImpl(String buttonName) { _buttonName = buttonName; } @@ -496,17 +557,20 @@ public class SecurityDialog extends WeakBase implements XComponent, public void actionPerformed(ActionEvent actionEvent) { _pushed = _buttonName; LogUtils.DEBUG("** Button pushed ->" + _pushed); - _xDialog.endExecute(); } } private class ItemListenerImpl implements com.sun.star.awt.XItemListener { + private XCheckBox _xCheckBox; + private ItemListenerImpl(XControlContainer xControlCont) { Object objectCheckBox = xControlCont.getControl(_checkBoxName); - _xCheckBox = UnoRuntime.queryInterface( - XCheckBox.class, objectCheckBox); + + _xCheckBox = + UnoRuntime.queryInterface(XCheckBox.class, objectCheckBox); + } // XEventListener @@ -520,4 +584,4 @@ public class SecurityDialog extends WeakBase implements XComponent, LogUtils.DEBUG("** checkbox state ->" + _checkBoxState); } } -} +} \ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/browse/DialogFactory.java b/scripting/java/com/sun/star/script/framework/browse/DialogFactory.java index da0fa02..a4350fb 100644 --- a/scripting/java/com/sun/star/script/framework/browse/DialogFactory.java +++ b/scripting/java/com/sun/star/script/framework/browse/DialogFactory.java @@ -39,6 +39,7 @@ import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XComponentContext; public class DialogFactory { + private static DialogFactory factory; private XComponentContext xComponentContext; @@ -58,8 +59,7 @@ public class DialogFactory { } } - public static DialogFactory getDialogFactory() - throws java.lang.Exception { + public static DialogFactory getDialogFactory() throws java.lang.Exception { if (factory == null) { throw new java.lang.Exception("DialogFactory not initialized"); } @@ -67,8 +67,6 @@ public class DialogFactory { return factory; } - - public String showInputDialog(String title, String prompt) { final XDialog xDialog; @@ -79,19 +77,22 @@ public class DialogFactory { } // add an action listener to the button controls - XControlContainer controls = UnoRuntime.queryInterface(XControlContainer.class, - xDialog); + XControlContainer controls = + UnoRuntime.queryInterface(XControlContainer.class, xDialog); + + XButton okButton = + UnoRuntime.queryInterface(XButton.class, controls.getControl("Ok")); - XButton okButton = UnoRuntime.queryInterface( - XButton.class, controls.getControl("Ok")); okButton.setActionCommand("Ok"); - XButton cancelButton = UnoRuntime.queryInterface( - XButton.class, controls.getControl("Cancel")); + XButton cancelButton = + UnoRuntime.queryInterface(XButton.class, controls.getControl("Cancel")); + cancelButton.setActionCommand("Cancel"); - final XTextComponent textField = UnoRuntime.queryInterface( - XTextComponent.class, controls.getControl("NameField")); + final XTextComponent textField = + UnoRuntime.queryInterface(XTextComponent.class, + controls.getControl("NameField")); final ResultHolder resultHolder = new ResultHolder(); @@ -120,8 +121,9 @@ public class DialogFactory { return (String)resultHolder.getResult(); } - private void setDimensions(Object o, int x, int y, int width, int height) - throws com.sun.star.uno.Exception { + private void setDimensions(Object o, int x, int y, int width, int height) throws + com.sun.star.uno.Exception { + XPropertySet props = UnoRuntime.queryInterface(XPropertySet.class, o); props.setPropertyValue("PositionX", Integer.valueOf(x)); @@ -130,8 +132,9 @@ public class DialogFactory { props.setPropertyValue("Width", Integer.valueOf(width)); } - private XDialog createInputDialog(String title, String prompt) - throws com.sun.star.uno.Exception { + private XDialog createInputDialog(String title, String prompt) throws + com.sun.star.uno.Exception { + if (title == null || title.length() == 0) { title = "Scripting Framework"; } @@ -146,18 +149,19 @@ public class DialogFactory { // create the dialog model and set the properties Object dialogModel = xMultiComponentFactory.createInstanceWithContext( - "com.sun.star.awt.UnoControlDialogModel", xComponentContext); + "com.sun.star.awt.UnoControlDialogModel", + xComponentContext); setDimensions(dialogModel, 100, 100, 157, 58); - XPropertySet props = UnoRuntime.queryInterface( - XPropertySet.class, dialogModel); + XPropertySet props = + UnoRuntime.queryInterface(XPropertySet.class, dialogModel); + props.setPropertyValue("Title", title); // get the service manager from the dialog model XMultiServiceFactory xMultiServiceFactory = - UnoRuntime.queryInterface( - XMultiServiceFactory.class, dialogModel); + UnoRuntime.queryInterface(XMultiServiceFactory.class, dialogModel); // create the label model and set the properties Object label = xMultiServiceFactory.createInstance( @@ -165,8 +169,9 @@ public class DialogFactory { setDimensions(label, 15, 5, 134, 12); - XPropertySet labelProps = UnoRuntime.queryInterface( - XPropertySet.class, label); + XPropertySet labelProps = + UnoRuntime.queryInterface(XPropertySet.class, label); + labelProps.setPropertyValue("Name", "PromptLabel"); labelProps.setPropertyValue("Label", prompt); @@ -176,8 +181,9 @@ public class DialogFactory { setDimensions(edit, 15, 18, 134, 12); - XPropertySet editProps = UnoRuntime.queryInterface( - XPropertySet.class, edit); + XPropertySet editProps = + UnoRuntime.queryInterface(XPropertySet.class, edit); + editProps.setPropertyValue("Name", "NameField"); // create the OK button @@ -186,8 +192,9 @@ public class DialogFactory { setDimensions(okButtonModel, 40, 39, 38, 15); - XPropertySet buttonProps = UnoRuntime.queryInterface( - XPropertySet.class, okButtonModel); + XPropertySet buttonProps = + UnoRuntime.queryInterface(XPropertySet.class, okButtonModel); + buttonProps.setPropertyValue("Name", "Ok"); buttonProps.setPropertyValue("Label", "Ok"); @@ -197,14 +204,15 @@ public class DialogFactory { setDimensions(cancelButtonModel, 83, 39, 38, 15); - buttonProps = UnoRuntime.queryInterface( - XPropertySet.class, cancelButtonModel); + buttonProps = + UnoRuntime.queryInterface(XPropertySet.class, cancelButtonModel); + buttonProps.setPropertyValue("Name", "Cancel"); buttonProps.setPropertyValue("Label", "Cancel"); // insert the control models into the dialog model - XNameContainer xNameCont = UnoRuntime.queryInterface(XNameContainer.class, - dialogModel); + XNameContainer xNameCont = + UnoRuntime.queryInterface(XNameContainer.class, dialogModel); xNameCont.insertByName("PromptLabel", label); xNameCont.insertByName("NameField", edit); @@ -213,21 +221,23 @@ public class DialogFactory { // create the dialog control and set the model Object dialog = xMultiComponentFactory.createInstanceWithContext( - "com.sun.star.awt.UnoControlDialog", xComponentContext); - XControl xControl = UnoRuntime.queryInterface( - XControl.class, dialog); + "com.sun.star.awt.UnoControlDialog", + xComponentContext); + + XControl xControl = UnoRuntime.queryInterface(XControl.class, dialog); + + XControlModel xControlModel = + UnoRuntime.queryInterface(XControlModel.class, dialogModel); - XControlModel xControlModel = UnoRuntime.queryInterface(XControlModel.class, - dialogModel); xControl.setModel(xControlModel); // create a peer Object toolkit = xMultiComponentFactory.createInstanceWithContext( - "com.sun.star.awt.ExtToolkit", xComponentContext); - XToolkit xToolkit = UnoRuntime.queryInterface( - XToolkit.class, toolkit); - XWindow xWindow = UnoRuntime.queryInterface( - XWindow.class, xControl); + "com.sun.star.awt.ExtToolkit", + xComponentContext); + + XToolkit xToolkit = UnoRuntime.queryInterface(XToolkit.class, toolkit); + XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, xControl); xWindow.setVisible(false); xControl.createPeer(xToolkit, null); @@ -235,6 +245,7 @@ public class DialogFactory { } private static class ResultHolder { + private Object result = null; public Object getResult() { @@ -245,4 +256,4 @@ public class DialogFactory { this.result = result; } } -} +} \ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/browse/ParcelBrowseNode.java b/scripting/java/com/sun/star/script/framework/browse/ParcelBrowseNode.java index 076d638..23999a1 100644 --- a/scripting/java/com/sun/star/script/framework/browse/ParcelBrowseNode.java +++ b/scripting/java/com/sun/star/script/framework/browse/ParcelBrowseNode.java @@ -48,19 +48,17 @@ import java.util.HashMap; import javax.swing.JOptionPane; -public class ParcelBrowseNode extends PropertySet - implements XBrowseNode, XInvocation { +public class ParcelBrowseNode extends PropertySet implements + XBrowseNode, XInvocation { + private ScriptProvider provider; private Collection<XBrowseNode> browsenodes; private ParcelContainer container; private Parcel parcel; - - - - public ParcelBrowseNode(ScriptProvider provider, ParcelContainer container, String parcelName) { + this.provider = provider; this.container = container; @@ -68,30 +66,28 @@ public class ParcelBrowseNode extends PropertySet try { this.parcel = (Parcel)this.container.getByName(parcelName); } catch (Exception e) { - LogUtils.DEBUG("** Exception: " + e); - LogUtils.DEBUG(" ** Failed to get parcel named " + - parcelName + " from container"); + LogUtils.DEBUG(" ** Failed to get parcel named " + parcelName + + " from container"); } - registerProperty("Deletable", new Type(boolean.class), - (short)0, "deletable"); - registerProperty("Editable", new Type(boolean.class), - (short)0, "editable"); - registerProperty("Creatable", new Type(boolean.class), - (short)0, "creatable"); - registerProperty("Renamable", new Type(boolean.class), - (short)0, "renamable"); + registerProperty("Deletable", new Type(boolean.class), (short)0, "deletable"); + registerProperty("Editable", new Type(boolean.class), (short)0, "editable"); + registerProperty("Creatable", new Type(boolean.class), (short)0, "creatable"); + registerProperty("Renamable", new Type(boolean.class), (short)0, "renamable"); String parcelDirUrl = parcel.getPathToParcel(); XComponentContext xCtx = provider.getScriptingContext().getComponentContext(); XMultiComponentFactory xFac = xCtx.getServiceManager(); try { - XSimpleFileAccess xSFA = UnoRuntime.queryInterface(XSimpleFileAccess.class, - xFac.createInstanceWithContext( - "com.sun.star.ucb.SimpleFileAccess", - xCtx)); + + XSimpleFileAccess xSFA = + UnoRuntime.queryInterface(XSimpleFileAccess.class, + xFac.createInstanceWithContext( + "com.sun.star.ucb.SimpleFileAccess", + xCtx)); + } catch (com.sun.star.uno.Exception e) { // TODO propagate potential errors LogUtils.DEBUG("Caught exception creating ParcelBrowseNode " + e); @@ -150,11 +146,13 @@ public class ParcelBrowseNode extends PropertySet } public Object invoke(String aFunctionName, Object[] aParams, - short[][] aOutParamIndex, Object[][] aOutParam) - throws com.sun.star.lang.IllegalArgumentException, + short[][] aOutParamIndex, Object[][] aOutParam) throws + com.sun.star.lang.IllegalArgumentException, com.sun.star.script.CannotConvertException, com.sun.star.reflection.InvocationTargetException { + LogUtils.DEBUG("ParcelBrowseNode invoke for " + aFunctionName); + // Initialise the out parameters - not used but prevents error in // UNO bridge aOutParamIndex[0] = new short[0]; @@ -166,21 +164,22 @@ public class ParcelBrowseNode extends PropertySet try { String newName; - if (aParams == null || aParams.length < 1 || - !AnyConverter.isString(aParams[0])) { + if (aParams == null || aParams.length < 1 + || !AnyConverter.isString(aParams[0])) { + String prompt = "Enter name for new Script"; String title = "Create Script"; // try to get a DialogFactory instance, if it fails // just use a Swing JOptionPane to prompt for the name try { - DialogFactory dialogFactory = - DialogFactory.getDialogFactory(); - + DialogFactory dialogFactory = DialogFactory.getDialogFactory(); newName = dialogFactory.showInputDialog(title, prompt); } catch (Exception e) { + newName = JOptionPane.showInputDialog(null, prompt, title, JOptionPane.QUESTION_MESSAGE); + } } else { newName = AnyConverter.toString(aParams[0]); @@ -190,7 +189,10 @@ public class ParcelBrowseNode extends PropertySet result = new Any(new Type(Boolean.class), Boolean.FALSE); } else { String source = provider.getScriptEditor().getTemplate(); - String languageName = newName + "." + provider.getScriptEditor().getExtension(); + + String languageName = + newName + "." + provider.getScriptEditor().getExtension(); + String language = container.getLanguage(); ScriptEntry entry = new ScriptEntry(language, languageName, "", @@ -200,7 +202,8 @@ public class ParcelBrowseNode extends PropertySet ScriptMetaData data = new ScriptMetaData(parcel, entry, source); parcel.insertByName(languageName, data); - ScriptBrowseNode sbn = new ScriptBrowseNode(provider, parcel, languageName); + ScriptBrowseNode sbn = + new ScriptBrowseNode(provider, parcel, languageName); if (browsenodes == null) { LogUtils.DEBUG("browsenodes null!!"); @@ -208,14 +211,12 @@ public class ParcelBrowseNode extends PropertySet } browsenodes.add(sbn); - result = new Any(new Type(XBrowseNode.class), sbn); } } catch (Exception e) { LogUtils.DEBUG("ParcelBrowseNode[create] failed with: " + e); LogUtils.DEBUG(LogUtils.getTrace(e)); result = new Any(new Type(Boolean.class), Boolean.FALSE); - } } else if (aFunctionName.equals("Deletable")) { try { @@ -228,6 +229,7 @@ public class ParcelBrowseNode extends PropertySet result = new Any(new Type(Boolean.class), Boolean.FALSE); } } else if (aFunctionName.equals("Renamable")) { + String newName = null; try { @@ -240,13 +242,13 @@ public class ParcelBrowseNode extends PropertySet // try to get a DialogFactory instance, if it fails // just use a Swing JOptionPane to prompt for the name try { - DialogFactory dialogFactory = - DialogFactory.getDialogFactory(); - + DialogFactory dialogFactory = DialogFactory.getDialogFactory(); newName = dialogFactory.showInputDialog(title, prompt); } catch (Exception e) { + newName = JOptionPane.showInputDialog(null, prompt, title, JOptionPane.QUESTION_MESSAGE); + } } else { newName = AnyConverter.toString(aParams[0]); @@ -259,8 +261,8 @@ public class ParcelBrowseNode extends PropertySet getChildNodes(); } - ScriptBrowseNode[] childNodes = browsenodes.toArray(new - ScriptBrowseNode[browsenodes.size()]); + ScriptBrowseNode[] childNodes = + browsenodes.toArray(new ScriptBrowseNode[browsenodes.size()]); for (int index = 0; index < childNodes.length; index++) { childNodes[ index ].updateURI(p); @@ -280,14 +282,14 @@ public class ParcelBrowseNode extends PropertySet return result; } - public void setValue(String aPropertyName, Object aValue) - throws com.sun.star.beans.UnknownPropertyException, + public void setValue(String aPropertyName, Object aValue) throws + com.sun.star.beans.UnknownPropertyException, com.sun.star.script.CannotConvertException, com.sun.star.reflection.InvocationTargetException { } - public Object getValue(String aPropertyName) - throws com.sun.star.beans.UnknownPropertyException { + public Object getValue(String aPropertyName) throws + com.sun.star.beans.UnknownPropertyException { return null; } @@ -298,4 +300,4 @@ public class ParcelBrowseNode extends PropertySet public boolean hasProperty(String aName) { return false; } -} +} \ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/browse/PkgProviderBrowseNode.java b/scripting/java/com/sun/star/script/framework/browse/PkgProviderBrowseNode.java index c5abd3a..bc52cb5 100644 --- a/scripting/java/com/sun/star/script/framework/browse/PkgProviderBrowseNode.java +++ b/scripting/java/com/sun/star/script/framework/browse/PkgProviderBrowseNode.java @@ -24,12 +24,13 @@ import com.sun.star.script.framework.provider.ScriptProvider; import com.sun.star.uno.XComponentContext; - public class PkgProviderBrowseNode extends ProviderBrowseNode { public PkgProviderBrowseNode(ScriptProvider provider, ParcelContainer container, XComponentContext xCtx) { + super(provider, container, xCtx); + LogUtils.DEBUG("*** PkgProviderBrowseNode ctor container name = " + container.getName()); LogUtils.DEBUG("*** PkgProviderBrowseNode ctor container path = " + @@ -38,8 +39,7 @@ public class PkgProviderBrowseNode extends ProviderBrowseNode { container.getElementNames().length); } - @Override - public String getName() { + @Override public String getName() { return (container != null) ? container.getName() : "Unknown"; } diff --git a/scripting/java/com/sun/star/script/framework/browse/ProviderBrowseNode.java b/scripting/java/com/sun/star/script/framework/browse/ProviderBrowseNode.java index b066895..3bf1ba5 100644 --- a/scripting/java/com/sun/star/script/framework/browse/ProviderBrowseNode.java +++ b/scripting/java/com/sun/star/script/framework/browse/ProviderBrowseNode.java @@ -44,37 +44,32 @@ import java.util.Collection; import javax.swing.JOptionPane; -public class ProviderBrowseNode extends PropertySet - implements XBrowseNode, XInvocation { +public class ProviderBrowseNode extends PropertySet implements + XBrowseNode, XInvocation { + private ScriptProvider provider; private Collection<XBrowseNode> browsenodes; private String name; protected ParcelContainer container; - private XComponentContext m_xCtx; - - - - public ProviderBrowseNode(ScriptProvider provider, ParcelContainer container, XComponentContext xCtx) { + LogUtils.DEBUG("*** ProviderBrowseNode ctor"); this.container = container; this.name = this.container.getLanguage(); this.provider = provider; this.m_xCtx = xCtx; - registerProperty("Deletable", new Type(boolean.class), - (short)0, "deletable"); - registerProperty("Creatable", new Type(boolean.class), - (short)0, "creatable"); - registerProperty("Editable", new Type(boolean.class), - (short)0, "editable"); + registerProperty("Deletable", new Type(boolean.class), (short)0, "deletable"); + registerProperty("Creatable", new Type(boolean.class), (short)0, "creatable"); + registerProperty("Editable", new Type(boolean.class), (short)0, "editable"); XSimpleFileAccess xSFA = null; XMultiComponentFactory xFac = m_xCtx.getServiceManager(); try { + xSFA = UnoRuntime.queryInterface(XSimpleFileAccess.class, xFac.createInstanceWithContext( "com.sun.star.ucb.SimpleFileAccess", @@ -84,7 +79,6 @@ public class ProviderBrowseNode extends PropertySet catch (com.sun.star.uno.Exception e) { LogUtils.DEBUG("Caught exception in creation of ProviderBrowseNode "); LogUtils.DEBUG(LogUtils.getTrace(e)); - } } @@ -96,9 +90,11 @@ public class ProviderBrowseNode extends PropertySet LogUtils.DEBUG("***** ProviderBrowseNode.getChildNodes()"); if (hasChildNodes()) { + // needs initialisation? LogUtils.DEBUG("** ProviderBrowseNode.getChildNodes(), container is " + container); + String[] parcels = container.getElementNames(); browsenodes = new ArrayList<XBrowseNode>(parcels.length); @@ -113,13 +109,16 @@ public class ProviderBrowseNode extends PropertySet } ParcelContainer[] packageContainers = container.getChildContainers(); + LogUtils.DEBUG("**** For container named " + container.getName() + - " with root path " + container.getParcelContainerDir() + " has " + - packageContainers.length + " child containers "); + " with root path " + container.getParcelContainerDir() + + " has " + packageContainers.length + " child containers "); for (ParcelContainer packageContainer : packageContainers) { - XBrowseNode node = new PkgProviderBrowseNode(provider, packageContainer, - m_xCtx); + + XBrowseNode node = + new PkgProviderBrowseNode(provider, packageContainer, m_xCtx); + browsenodes.add(node); } } else { @@ -134,15 +133,13 @@ public class ProviderBrowseNode extends PropertySet boolean result = true; if (container == null || - (!container.hasElements() && - container.getChildContainers().length == 0)) { + (!container.hasElements() && container.getChildContainers().length == 0)) { + result = false; } - LogUtils.DEBUG("***** ProviderBrowseNode.hasChildNodes(): " + - "name=" + name + - ", path=" + container.getParcelContainerDir() + - ", result=" + result); + LogUtils.DEBUG("***** ProviderBrowseNode.hasChildNodes(): " + "name=" + name + + ", path=" + container.getParcelContainerDir() + ", result=" + result); return result; } @@ -162,10 +159,11 @@ public class ProviderBrowseNode extends PropertySet } public Object invoke(String aFunctionName, Object[] aParams, - short[][] aOutParamIndex, Object[][] aOutParam) - throws com.sun.star.lang.IllegalArgumentException, + short[][] aOutParamIndex, Object[][] aOutParam) throws + com.sun.star.lang.IllegalArgumentException, com.sun.star.script.CannotConvertException, com.sun.star.reflection.InvocationTargetException { + // Initialise the out parameters - not used but prevents error in // UNO bridge aOutParamIndex[0] = new short[0]; @@ -179,19 +177,20 @@ public class ProviderBrowseNode extends PropertySet if (aParams == null || aParams.length < 1 || !AnyConverter.isString(aParams[0])) { + String prompt = "Enter name for new Parcel"; String title = "Create Parcel"; // try to get a DialogFactory instance, if it fails // just use a Swing JOptionPane to prompt for the name try { - DialogFactory dialogFactory = - DialogFactory.getDialogFactory(); - + DialogFactory dialogFactory = DialogFactory.getDialogFactory(); name = dialogFactory.showInputDialog(title, prompt); } catch (Exception e) { + name = JOptionPane.showInputDialog(null, prompt, title, JOptionPane.QUESTION_MESSAGE); + } } else { name = AnyConverter.toString(aParams[0]); @@ -215,8 +214,6 @@ public class ProviderBrowseNode extends PropertySet } browsenodes.add(parcel); - - result = new Any(new Type(XBrowseNode.class), parcel); } } @@ -233,14 +230,15 @@ public class ProviderBrowseNode extends PropertySet return result; } - public void setValue(String aPropertyName, Object aValue) - throws com.sun.star.beans.UnknownPropertyException, + public void setValue(String aPropertyName, Object aValue) throws + com.sun.star.beans.UnknownPropertyException, com.sun.star.script.CannotConvertException, com.sun.star.reflection.InvocationTargetException { } - public Object getValue(String aPropertyName) - throws com.sun.star.beans.UnknownPropertyException { + public Object getValue(String aPropertyName) throws + com.sun.star.beans.UnknownPropertyException { + return null; } @@ -251,4 +249,4 @@ public class ProviderBrowseNode extends PropertySet public boolean hasProperty(String aName) { return false; } -} +} \ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/browse/ScriptBrowseNode.java b/scripting/java/com/sun/star/script/framework/browse/ScriptBrowseNode.java index 346c8a9..e816f8e 100644 --- a/scripting/java/com/sun/star/script/framework/browse/ScriptBrowseNode.java +++ b/scripting/java/com/sun/star/script/framework/browse/ScriptBrowseNode.java @@ -50,20 +50,20 @@ import com.sun.star.uno.XComponentContext; import java.util.HashMap; -public class ScriptBrowseNode extends PropertySet - implements XBrowseNode, XInvocation { +public class ScriptBrowseNode extends PropertySet implements + XBrowseNode, XInvocation { + private ScriptProvider provider; private Parcel parent; private String name; - private boolean editable = false; private boolean deletable = false; private boolean renamable = false; - public ScriptBrowseNode(ScriptProvider provider, Parcel parent, - String name) { + public ScriptBrowseNode(ScriptProvider provider, Parcel parent, String name) { + this.provider = provider; this.name = name; this.parent = parent; @@ -72,10 +72,12 @@ public class ScriptBrowseNode extends PropertySet try { ScriptMetaData data = (ScriptMetaData)parent.getByName(name); - XSimpleFileAccess xSFA = UnoRuntime.queryInterface(XSimpleFileAccess.class, - xFac.createInstanceWithContext( - "com.sun.star.ucb.SimpleFileAccess", - xCtx)); + + XSimpleFileAccess xSFA = UnoRuntime.queryInterface( + XSimpleFileAccess.class, + xFac.createInstanceWithContext( + "com.sun.star.ucb.SimpleFileAccess", + xCtx)); if (provider.hasScriptEditor()) { this.editable = true; @@ -83,8 +85,10 @@ public class ScriptBrowseNode extends PropertySet try { if (!parent.isUnoPkg() && !xSFA.isReadOnly(parent.getPathToParcel())) { + this.deletable = true; this.renamable = true; + } } // TODO propagate errors @@ -98,23 +102,20 @@ public class ScriptBrowseNode extends PropertySet } // TODO fix exception types to be caught here, should we rethrow? catch (Exception e) { - LogUtils.DEBUG("** caught exception getting script data for " + name + " ->" + - e.toString()); + + LogUtils.DEBUG("** caught exception getting script data for " + name + + " ->" + e.toString()); + } - registerProperty("Deletable", new Type(boolean.class), - (short)0, "deletable"); - registerProperty("Editable", new Type(boolean.class), - (short)0, "editable"); - registerProperty("Renamable", new Type(boolean.class), - (short)0, "renamable"); - registerProperty("URI", new Type(String.class), - (short)0, "uri"); - registerProperty("Description", new Type(String.class), - (short)0, "description"); + registerProperty("Deletable", new Type(boolean.class), (short)0, "deletable"); + registerProperty("Editable", new Type(boolean.class), (short)0, "editable"); + registerProperty("Renamable", new Type(boolean.class), (short)0, "renamable"); + registerProperty("URI", new Type(String.class), (short)0, "uri"); + registerProperty("Description", new Type(String.class), (short)0, + "description"); } - public String getName() { return name; } @@ -143,11 +144,10 @@ public class ScriptBrowseNode extends PropertySet try { data = (ScriptMetaData)parent.getByName(name); } - // TODO fix exception types to be caught here, should we rethrow? catch (Exception e) { - LogUtils.DEBUG("** caught exception getting script data for " + name + " ->" + - e.toString()); + LogUtils.DEBUG("** caught exception getting script data for " + name + + " ->" + e.toString()); } } // implementation of XInvocation interface @@ -156,10 +156,11 @@ public class ScriptBrowseNode extends PropertySet } public Object invoke(String aFunctionName, Object[] aParams, - short[][] aOutParamIndex, Object[][] aOutParam) - throws com.sun.star.lang.IllegalArgumentException, + short[][] aOutParamIndex, Object[][] aOutParam) throws + com.sun.star.lang.IllegalArgumentException, com.sun.star.script.CannotConvertException, com.sun.star.reflection.InvocationTargetException { + // Initialise the out parameters - not used but prevents error in // UNO bridge aOutParamIndex[0] = new short[0]; @@ -169,31 +170,37 @@ public class ScriptBrowseNode extends PropertySet if (aFunctionName.equals("Editable")) { if (!editable) { - NoSupportException nse = new NoSupportException( - aFunctionName + " is not editable "); + + NoSupportException nse = + new NoSupportException(aFunctionName + " is not editable "); throw new InvocationTargetException( "Scripting framework error editing script", null, nse); + } - XScriptContext ctxt = provider.getScriptingContext(); + XScriptContext ctxt = provider.getScriptingContext(); ScriptMetaData data = null; try { data = (ScriptMetaData)parent.getByName(name); } catch (NoSuchElementException nse) { + throw new com.sun.star.lang.IllegalArgumentException( name + " does not exist or can't be found "); + } catch (com.sun.star.lang.WrappedTargetException wte) { + // rethrow throw new InvocationTargetException( - "Scripting framework editing script ", - null, wte.TargetException); + "Scripting framework editing script ", null, wte.TargetException); + } provider.getScriptEditor().edit(ctxt, data); } else if (aFunctionName.equals("Deletable")) { if (!deletable) { + NoSupportException nse = new NoSupportException( aFunctionName + " is not supported for this node"); @@ -205,19 +212,23 @@ public class ScriptBrowseNode extends PropertySet parent.removeByName(name); result = new Any(new Type(Boolean.class), Boolean.TRUE); } catch (NoSuchElementException nse) { + throw new com.sun.star.lang.IllegalArgumentException( name + " does not exist or can't be found "); + } catch (WrappedTargetException wte) { + // rethrow throw new InvocationTargetException( - "Scripting framework deleting script ", - null, wte.TargetException); + "Scripting framework deleting script ", null, wte.TargetException); + } } else if (aFunctionName.equals("Renamable")) { result = new Any(new Type(XBrowseNode.class), new XBrowseNode[0]); if (!renamable) { + NoSupportException nse = new NoSupportException( aFunctionName + " is not supported for this node"); @@ -232,15 +243,17 @@ public class ScriptBrowseNode extends PropertySet String oldSource = oldData.getSource(); LogUtils.DEBUG("Create renamed script"); + String languageName = newName + "." + provider.getScriptEditor().getExtension(); + String language = provider.getName(); - ScriptEntry entry = new ScriptEntry( - language, languageName, "", new HashMap<String, String>()); + ScriptEntry entry = new ScriptEntry(language, languageName, "", + new HashMap<String, String>()); - ScriptMetaData data = new ScriptMetaData( - parent, entry, oldSource); + ScriptMetaData data = + new ScriptMetaData(parent, entry, oldSource); parent.insertByName(languageName, data); @@ -250,35 +263,42 @@ public class ScriptBrowseNode extends PropertySet name = languageName; result = new Any(new Type(XBrowseNode.class), this); } catch (NoSuchElementException nse) { + throw new com.sun.star.lang.IllegalArgumentException( name + " does not exist or can't be found "); + } catch (ElementExistException eee) { + // rethrow throw new InvocationTargetException( - "Scripting framework error renaming script ", - null, eee); + "Scripting framework error renaming script ", null, eee); + } catch (WrappedTargetException wte) { + // rethrow throw new InvocationTargetException( - "Scripting framework rename script ", - null, wte.TargetException); + "Scripting framework rename script ", null, wte.TargetException); + } } else { + throw new com.sun.star.lang.IllegalArgumentException( "Function " + aFunctionName + " not supported."); + } return result; } - public void setValue(String aPropertyName, Object aValue) - throws com.sun.star.beans.UnknownPropertyException, + public void setValue(String aPropertyName, Object aValue) throws + com.sun.star.beans.UnknownPropertyException, com.sun.star.script.CannotConvertException, com.sun.star.reflection.InvocationTargetException { } - public Object getValue(String aPropertyName) - throws com.sun.star.beans.UnknownPropertyException { + public Object getValue(String aPropertyName) throws + com.sun.star.beans.UnknownPropertyException { + return null; } @@ -289,4 +309,4 @@ public class ScriptBrowseNode extends PropertySet public boolean hasProperty(String aName) { return false; } -} +} \ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/container/DeployedUnoPackagesDB.java b/scripting/java/com/sun/star/script/framework/container/DeployedUnoPackagesDB.java index 67a18e64..634fa1a 100644 --- a/scripting/java/com/sun/star/script/framework/container/DeployedUnoPackagesDB.java +++ b/scripting/java/com/sun/star/script/framework/container/DeployedUnoPackagesDB.java @@ -41,6 +41,7 @@ public class DeployedUnoPackagesDB { private Document document = null; public DeployedUnoPackagesDB() throws IOException { + ByteArrayInputStream bis = null; try { @@ -61,6 +62,7 @@ public class DeployedUnoPackagesDB { } public String[] getDeployedPackages(String language) { + ArrayList<String> packageUrls = new ArrayList<String>(4); Element main = document.getDocumentElement(); Element root = null; @@ -87,10 +89,10 @@ public class DeployedUnoPackagesDB { (len = packages.getLength()) != 0) { for (int i = 0; i < len; i++) { - Element e = (Element)packages.item(i); packageUrls.add(e.getAttribute("value")); } + } } @@ -111,6 +113,7 @@ public class DeployedUnoPackagesDB { public boolean removePackage(String language, String url) { + Element main = document.getDocumentElement(); Element langNode = null; int len = 0; @@ -153,6 +156,7 @@ public class DeployedUnoPackagesDB { } public void addPackage(String language, String url) { + Element main = document.getDocumentElement(); Element langNode = null; Element pkgNode = null; @@ -184,4 +188,4 @@ public class DeployedUnoPackagesDB { //add to the Top Element main.appendChild(langNode); } -} +} \ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/container/Parcel.java b/scripting/java/com/sun/star/script/framework/container/Parcel.java index 5d7f0ed..0c9d41d 100644 --- a/scripting/java/com/sun/star/script/framework/container/Parcel.java +++ b/scripting/java/com/sun/star/script/framework/container/Parcel.java @@ -34,18 +34,22 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; public class Parcel implements XNameContainer { + private ParcelDescriptor m_descriptor; private String name; protected ParcelContainer parent; protected XSimpleFileAccess m_xSFA; + public Parcel(XSimpleFileAccess xSFA, ParcelContainer parent, ParcelDescriptor desc, String parcelName) { + this(parent, desc, parcelName); this.m_xSFA = xSFA; } private Parcel(ParcelContainer parent, ParcelDescriptor desc, String parcelName) { + this.parent = parent; this.m_descriptor = desc; this.name = parcelName; @@ -64,9 +68,11 @@ public class Parcel implements XNameContainer { public String getName() { return name; } + public java.lang.Object getByName(String aName) throws com.sun.star.container.NoSuchElementException, com.sun.star.lang.WrappedTargetException { + LogUtils.DEBUG("** Parcel.getByName for " + aName); ScriptEntry thescript = null; @@ -100,7 +106,9 @@ public class Parcel implements XNameContainer { LogUtils.DEBUG("returning date for " + aName); return data; } + public String[] getElementNames() { + String[] results = new String[0]; if (m_descriptor != null) { @@ -114,6 +122,7 @@ public class Parcel implements XNameContainer { return results; } + public boolean hasByName(String aName) { boolean result = true; @@ -144,10 +153,11 @@ public class Parcel implements XNameContainer { return m_descriptor != null && m_descriptor.getScriptEntries().length > 0; } - public void replaceByName(String aName, - java.lang.Object aElement) throws com.sun.star.lang.IllegalArgumentException, + public void replaceByName(String aName, java.lang.Object aElement) throws + com.sun.star.lang.IllegalArgumentException, com.sun.star.container.NoSuchElementException, com.sun.star.lang.WrappedTargetException { + // TODO check type of aElement // if not ok, throw IllegalArgument if (m_descriptor != null) { @@ -159,11 +169,10 @@ public class Parcel implements XNameContainer { // TODO needs to create source file ( if there is one ) //m_descriptor.write(); } else { - throw new com.sun.star.container.NoSuchElementException("No script named " + - aName); + throw new com.sun.star.container.NoSuchElementException( + "No script named " + aName); } - } // TO DO should catch specified exceptions catch (Exception e) { @@ -174,9 +183,10 @@ public class Parcel implements XNameContainer { } // create - public void insertByName(String aName, - java.lang.Object aElement) throws com.sun.star.lang.IllegalArgumentException, - ElementExistException, com.sun.star.lang.WrappedTargetException { + public void insertByName(String aName, java.lang.Object aElement) throws + com.sun.star.lang.IllegalArgumentException, ElementExistException, + com.sun.star.lang.WrappedTargetException { + // TODO check the type of aElement and throw# // if not appropriate try { @@ -190,8 +200,8 @@ public class Parcel implements XNameContainer { LogUtils.DEBUG("Inserting source: " + script.getSource()); if (!script.writeSourceFile()) { - throw new com.sun.star.lang.WrappedTargetException("Failed to create source file " - + script.getLanguageName()); + throw new com.sun.star.lang.WrappedTargetException( + "Failed to create source file " + script.getLanguageName()); } } @@ -203,18 +213,19 @@ public class Parcel implements XNameContainer { } } - private void writeParcelDescriptor() throws com.sun.star.ucb.CommandAbortedException, com.sun.star.io.IOException, com.sun.star.uno.Exception, java.io.IOException { - String pathToDescriptor = PathUtils.make_url( - getPathToParcel(), ParcelDescriptor.PARCEL_DESCRIPTOR_NAME); - XSimpleFileAccess2 xSFA2 = UnoRuntime.queryInterface(XSimpleFileAccess2.class, - m_xSFA); + String pathToDescriptor = + PathUtils.make_url(getPathToParcel(), ParcelDescriptor.PARCEL_DESCRIPTOR_NAME); + + XSimpleFileAccess2 xSFA2 = + UnoRuntime.queryInterface(XSimpleFileAccess2.class, m_xSFA); if (xSFA2 != null) { + ByteArrayOutputStream bos = null; ByteArrayInputStream bis = null; XInputStreamImpl xis = null; @@ -240,23 +251,26 @@ public class Parcel implements XNameContainer { public void removeByName(String Name) throws com.sun.star.container.NoSuchElementException, com.sun.star.lang.WrappedTargetException { + try { ScriptMetaData script = (ScriptMetaData)getByName(Name); if (script != null) { if (!script.removeSourceFile()) { - LogUtils.DEBUG("** Parcel.removeByName Failed to remove script " + Name); - throw new com.sun.star.lang.WrappedTargetException("Failed to remove script " + - Name); + LogUtils.DEBUG("** Parcel.removeByName Failed to remove script " + + Name); + throw new com.sun.star.lang.WrappedTargetException( + "Failed to remove script " + Name); } - LogUtils.DEBUG("** Parcel.removeByName have removed script source file " + - Name); + LogUtils.DEBUG("** Parcel.removeByName have removed script source file " + + Name); + m_descriptor.removeScriptEntry(script); writeParcelDescriptor(); } else { - throw new com.sun.star.container.NoSuchElementException("No script named " + - Name); + throw new com.sun.star.container.NoSuchElementException( + "No script named " + Name); } } catch (Exception e) { @@ -265,6 +279,7 @@ public class Parcel implements XNameContainer { } } + // rename parcel public void rename(String name) { this.name = name; @@ -273,6 +288,7 @@ public class Parcel implements XNameContainer { public ParcelContainer getParent() { return parent; } + /** * Returns the path of this <tt>Parcel</tt> * @@ -283,5 +299,4 @@ public class Parcel implements XNameContainer { return path; } -} - +} \ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/container/ParcelContainer.java b/scripting/java/com/sun/star/script/framework/container/ParcelContainer.java index d5b97bd..be72d78 100644 --- a/scripting/java/com/sun/star/script/framework/container/ParcelContainer.java +++ b/scripting/java/com/sun/star/script/framework/container/ParcelContainer.java @@ -56,8 +56,8 @@ import java.util.StringTokenizer; * The <code>ParcelContainer</code> object is used to store the * ScripingFramework specific Libraries. */ - public class ParcelContainer implements XNameAccess { + protected String language; protected String containerUrl; private Collection<Parcel> parcels = new ArrayList<Parcel>(10); @@ -78,7 +78,6 @@ public class ParcelContainer implements XNameAccess { return isPkgContainer; } - /** * Returns this <tt>ParcelContainer</tt>'s parent * @@ -101,8 +100,8 @@ public class ParcelContainer implements XNameAccess { } return childContainers.toArray(new ParcelContainer[childContainers.size()]); - } + /** * Removes a child <tt>ParcelContainer</tt> * from this instance. @@ -137,8 +136,9 @@ public class ParcelContainer implements XNameAccess { ParcelContainer result = null; for (ParcelContainer c : childContainers) { - String location = ScriptMetaData.getLocationPlaceHolder( - c.containerUrl, c.getName()); + + String location = + ScriptMetaData.getLocationPlaceHolder(c.containerUrl, c.getName()); if (key.equals(location)) { result = c; @@ -193,7 +193,8 @@ public class ParcelContainer implements XNameAccess { name = decodedUrl.substring(indexOfSlash + 1); } } catch (UnsupportedEncodingException e) { - com.sun.star.uno.RuntimeException e2 = new com.sun.star.uno.RuntimeException(); + com.sun.star.uno.RuntimeException e2 = + new com.sun.star.uno.RuntimeException(); e2.initCause(e); throw e2; } @@ -211,10 +212,10 @@ public class ParcelContainer implements XNameAccess { * @param language language for which entries are stored */ public ParcelContainer(XComponentContext xCtx, String containerUrl, - String language) throws com.sun.star.lang.IllegalArgumentException, - com.sun.star.lang.WrappedTargetException + String language) throws + com.sun.star.lang.IllegalArgumentException, + com.sun.star.lang.WrappedTargetException { - { this(null, xCtx, containerUrl, language, true); } @@ -230,6 +231,7 @@ public class ParcelContainer implements XNameAccess { String language, boolean loadParcels) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.lang.WrappedTargetException { + this(null, xCtx, containerUrl, language, loadParcels); } @@ -244,12 +246,13 @@ public class ParcelContainer implements XNameAccess { */ public ParcelContainer(ParcelContainer parent, XComponentContext xCtx, String containerUrl, String language, - boolean loadParcels) throws com.sun.star.lang.IllegalArgumentException, - com.sun.star.lang.WrappedTargetException + boolean loadParcels) throws + com.sun.star.lang.IllegalArgumentException, + com.sun.star.lang.WrappedTargetException { - { LogUtils.DEBUG("Creating ParcelContainer for " + containerUrl + " loadParcels = " + loadParcels + " language = " + language); + this.m_xCtx = xCtx; this.language = language; this.parent = parent; @@ -282,10 +285,12 @@ public class ParcelContainer implements XNameAccess { } try { + m_xSFA = UnoRuntime.queryInterface( XSimpleFileAccess.class, m_xCtx.getServiceManager().createInstanceWithContext( "com.sun.star.ucb.SimpleFileAccess", m_xCtx)); + } catch (Exception e) { // TODO should throw LogUtils.DEBUG("Error instantiating simplefile access "); @@ -307,6 +312,7 @@ public class ParcelContainer implements XNameAccess { public Object getByName(String aName) throws com.sun.star.container.NoSuchElementException, WrappedTargetException { + Parcel parcel = null; try { @@ -331,7 +337,9 @@ public class ParcelContainer implements XNameAccess { } public String[] getElementNames() { + if (hasElements()) { + Parcel[] theParcels = parcels.toArray(new Parcel[parcels.size()]); String[] names = new String[ theParcels.length ]; @@ -344,7 +352,9 @@ public class ParcelContainer implements XNameAccess { return new String[0]; } + public boolean hasByName(String aName) { + boolean isFound = false; try { @@ -358,15 +368,18 @@ public class ParcelContainer implements XNameAccess { return isFound; } + public Type getElementType() { return new Type(); } + public boolean hasElements() { return !(parcels == null || parcels.isEmpty()); } private void loadParcels() throws com.sun.star.lang.IllegalArgumentException, com.sun.star.lang.WrappedTargetException { + try { LogUtils.DEBUG("About to load parcels from " + containerUrl); @@ -405,18 +418,21 @@ public class ParcelContainer implements XNameAccess { } } - public XNameContainer createParcel(String name) throws ElementExistException, - com.sun.star.lang.WrappedTargetException { + public XNameContainer createParcel(String name) throws + ElementExistException, com.sun.star.lang.WrappedTargetException { + Parcel p = null; if (hasByName(name)) { throw new ElementExistException("Parcel " + name + " already exists"); } - String pathToParcel = PathUtils.make_url(getParcelContainerDir() , name); + String pathToParcel = PathUtils.make_url(getParcelContainerDir(), name); try { - LogUtils.DEBUG("ParcelContainer.createParcel, creating folder " + pathToParcel); + LogUtils.DEBUG("ParcelContainer.createParcel, creating folder " + + pathToParcel); + m_xSFA.createFolder(pathToParcel); LogUtils.DEBUG("ParcelContainer.createParcel, folder " + pathToParcel + @@ -424,10 +440,12 @@ public class ParcelContainer implements XNameAccess { ParcelDescriptor pd = new ParcelDescriptor(); pd.setLanguage(language); - String parcelDesc = PathUtils.make_url(pathToParcel, - ParcelDescriptor.PARCEL_DESCRIPTOR_NAME); - XSimpleFileAccess2 xSFA2 = UnoRuntime.queryInterface(XSimpleFileAccess2.class, - m_xSFA); + + String parcelDesc = + PathUtils.make_url(pathToParcel, ParcelDescriptor.PARCEL_DESCRIPTOR_NAME); + + XSimpleFileAccess2 xSFA2 = + UnoRuntime.queryInterface(XSimpleFileAccess2.class, m_xSFA); if (xSFA2 != null) { LogUtils.DEBUG("createParcel() Using XSIMPLEFILEACCESS2 " + parcelDesc); @@ -441,8 +459,8 @@ public class ParcelContainer implements XNameAccess { p = loadParcel(pathToParcel); } } catch (Exception e) { - - LogUtils.DEBUG("createParcel() Exception while attempting to create = " + name); + LogUtils.DEBUG("createParcel() Exception while attempting to create = " + + name); throw new com.sun.star.lang.WrappedTargetException(e); } @@ -453,27 +471,29 @@ public class ParcelContainer implements XNameAccess { com.sun.star.lang.WrappedTargetException, com.sun.star.lang.IllegalArgumentException { - String parcelDescUrl = PathUtils.make_url(parcelUrl, - ParcelDescriptor.PARCEL_DESCRIPTOR_NAME); - Parcel parcel = null; + String parcelDescUrl = + PathUtils.make_url(parcelUrl, ParcelDescriptor.PARCEL_DESCRIPTOR_NAME); + Parcel parcel = null; XInputStream xis = null; InputStream is = null; try { if (m_xSFA.exists(parcelDescUrl)) { + LogUtils.DEBUG("ParcelContainer.loadParcel opening " + parcelDescUrl); + xis = m_xSFA.openFileRead(parcelDescUrl); is = new XInputStreamWrapper(xis); - ParcelDescriptor pd = new ParcelDescriptor(is) ; try { is.close(); is = null; } catch (Exception e) { - LogUtils.DEBUG("ParcelContainer.loadParcel Exception when closing stream for " - + parcelDescUrl + " :" + e); + LogUtils.DEBUG( + "ParcelContainer.loadParcel Exception when closing stream for " + + parcelDescUrl + " :" + e); } LogUtils.DEBUG("ParcelContainer.loadParcel closed " + parcelDescUrl); @@ -490,25 +510,24 @@ public class ParcelContainer implements XNameAccess { parcel = new Parcel(m_xSFA, this, pd, name); - LogUtils.DEBUG(" ParcelContainer.loadParcel created parcel for " + parcelDescUrl - + " for language " + language); + LogUtils.DEBUG(" ParcelContainer.loadParcel created parcel for " + + parcelDescUrl + " for language " + language); + parcels.add(parcel); } else { throw new java.io.IOException(parcelDescUrl + " does NOT exist!"); } } catch (com.sun.star.ucb.CommandAbortedException e) { - - LogUtils.DEBUG("loadParcel() Exception while accessing filesystem url = " + - parcelDescUrl + e); + LogUtils.DEBUG("loadParcel() Exception while accessing filesystem url = " + + parcelDescUrl + e); throw new com.sun.star.lang.WrappedTargetException(e); } catch (java.io.IOException e) { LogUtils.DEBUG("ParcelContainer.loadParcel() caught IOException while accessing " + parcelDescUrl + ": " + e); throw new com.sun.star.lang.WrappedTargetException(e); } catch (com.sun.star.uno.Exception e) { - - LogUtils.DEBUG("loadParcel() Exception while accessing filesystem url = " + - parcelDescUrl + e); + LogUtils.DEBUG("loadParcel() Exception while accessing filesystem url = " + + parcelDescUrl + e); throw new com.sun.star.lang.WrappedTargetException(e); } @@ -528,34 +547,39 @@ public class ParcelContainer implements XNameAccess { return parcel; } - public void renameParcel(String oldName, - String newName) throws com.sun.star.container.NoSuchElementException, + public void renameParcel(String oldName, String newName) throws + com.sun.star.container.NoSuchElementException, com.sun.star.lang.WrappedTargetException { + LogUtils.DEBUG(" ** ParcelContainer Renaming parcel " + oldName + " to " + newName); LogUtils.DEBUG(" ** ParcelContainer is " + this); + Parcel p = (Parcel)getByName(oldName); if (p == null) { - throw new com.sun.star.container.NoSuchElementException("No parcel named " + - oldName); + throw new com.sun.star.container.NoSuchElementException( + "No parcel named " + oldName); } - String oldParcelDirUrl = PathUtils.make_url(getParcelContainerDir(), - oldName); - String newParcelDirUrl = PathUtils.make_url(getParcelContainerDir(), - newName); + String oldParcelDirUrl = + PathUtils.make_url(getParcelContainerDir(), oldName); + + String newParcelDirUrl = + PathUtils.make_url(getParcelContainerDir(), newName); try { if (!m_xSFA.isFolder(oldParcelDirUrl)) { - Exception e = new com.sun.star.io.IOException("Invalid Parcel directory: " + - oldName); + Exception e = new com.sun.star.io.IOException( + "Invalid Parcel directory: " + oldName); throw new com.sun.star.lang.WrappedTargetException(e); } - LogUtils.DEBUG(" ** ParcelContainer Renaming folder " + oldParcelDirUrl + " to " - + newParcelDirUrl); + LogUtils.DEBUG(" ** ParcelContainer Renaming folder " + oldParcelDirUrl + + " to " + newParcelDirUrl); + m_xSFA.move(oldParcelDirUrl, newParcelDirUrl); + } catch (com.sun.star.ucb.CommandAbortedException ce) { LogUtils.DEBUG(" ** ParcelContainer Renaming failed with " + ce); throw new com.sun.star.lang.WrappedTargetException(ce); @@ -570,30 +594,33 @@ public class ParcelContainer implements XNameAccess { public boolean removeParcel(String name) throws com.sun.star.container.NoSuchElementException, com.sun.star.lang.WrappedTargetException { + Parcel p = (Parcel)getByName(name); if (p == null) { - throw new com.sun.star.container.NoSuchElementException("No parcel named " + - name); + throw new com.sun.star.container.NoSuchElementException( + "No parcel named " + name); } return parcels.remove(p); } + public boolean deleteParcel(String name) throws com.sun.star.container.NoSuchElementException, com.sun.star.lang.WrappedTargetException { - LogUtils.DEBUG("deleteParcel for containerURL " + containerUrl + " name = " + - name + " Langueg = " + language); + + LogUtils.DEBUG("deleteParcel for containerURL " + containerUrl + + " name = " + name + " Langueg = " + language); Parcel p = (Parcel)getByName(name); if (p == null) { - throw new com.sun.star.container.NoSuchElementException("No parcel named " + - name); + throw new com.sun.star.container.NoSuchElementException( + "No parcel named " + name); } try { - String pathToParcel = PathUtils.make_url(getParcelContainerDir(), name); + String pathToParcel = PathUtils.make_url(getParcelContainerDir(), name); m_xSFA.kill(pathToParcel); } catch (Exception e) { LogUtils.DEBUG("Error deleteing parcel " + name); @@ -610,13 +637,16 @@ public class ParcelContainer implements XNameAccess { public ScriptMetaData findScript(ParsedScriptUri parsedUri) throws com.sun.star.container.NoSuchElementException, com.sun.star.lang.WrappedTargetException { + Parcel p = (Parcel)getByName(parsedUri.parcel); ScriptMetaData scriptData = (ScriptMetaData)p.getByName(parsedUri.function); + LogUtils.DEBUG("** found script data for " + parsedUri.function + " script is " + scriptData); - return scriptData; + return scriptData; } + public ParsedScriptUri parseScriptUri(String scriptURI) throws com.sun.star.lang.IllegalArgumentException { @@ -625,28 +655,32 @@ public class ParcelContainer implements XNameAccess { try { xMcFac = m_xCtx.getServiceManager(); - xFac = UnoRuntime.queryInterface(XUriReferenceFactory.class, - xMcFac.createInstanceWithContext( - "com.sun.star.uri.UriReferenceFactory", m_xCtx)); + + xFac = UnoRuntime.queryInterface( + XUriReferenceFactory.class, xMcFac.createInstanceWithContext( + "com.sun.star.uri.UriReferenceFactory", m_xCtx)); + } catch (com.sun.star.uno.Exception e) { LogUtils.DEBUG("Problems parsing URL:" + e.toString()); - throw new com.sun.star.lang.IllegalArgumentException(e, "Problems parsing URL"); + throw new com.sun.star.lang.IllegalArgumentException( + e, "Problems parsing URL"); } if (xFac == null) { LogUtils.DEBUG("Failed to create UrlReference factory"); - throw new com.sun.star.lang.IllegalArgumentException("Failed to create UrlReference factory for url " - + scriptURI); + throw new com.sun.star.lang.IllegalArgumentException( + "Failed to create UrlReference factory for url " + scriptURI); } XUriReference uriRef = xFac.parse(scriptURI); - XVndSunStarScriptUrl sfUri = UnoRuntime.queryInterface( - XVndSunStarScriptUrl.class, uriRef); + + XVndSunStarScriptUrl sfUri = + UnoRuntime.queryInterface(XVndSunStarScriptUrl.class, uriRef); if (sfUri == null) { LogUtils.DEBUG("Failed to parse url"); - throw new com.sun.star.lang.IllegalArgumentException("Failed to parse url " + - scriptURI); + throw new com.sun.star.lang.IllegalArgumentException( + "Failed to parse url " + scriptURI); } ParsedScriptUri parsedUri = new ParsedScriptUri(); @@ -662,9 +696,11 @@ public class ParcelContainer implements XNameAccess { } if (parsedUri.function != null && (parsedUri.function.length() > 0)) { + // strip out parcel name - parsedUri.function = parsedUri.function.substring(parsedUri.parcel.length() + - 1); + parsedUri.function = + parsedUri.function.substring(parsedUri.parcel.length() + 1); + } // parse location @@ -678,8 +714,7 @@ public class ParcelContainer implements XNameAccess { "\nfunction = " + parsedUri.function + "\nparcel = " + parsedUri.parcel + "\nlocation = " + parsedUri.location); + return parsedUri; } - - -} +} \ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/container/ParcelDescriptor.java b/scripting/java/com/sun/star/script/framework/container/ParcelDescriptor.java index 1bde7eb..14ebb24 100644 --- a/scripting/java/com/sun/star/script/framework/container/ParcelDescriptor.java +++ b/scripting/java/com/sun/star/script/framework/container/ParcelDescriptor.java @@ -42,8 +42,8 @@ public class ParcelDescriptor { PARCEL_DESCRIPTOR_NAME = "parcel-descriptor.xml"; // Collection of all ParcelDescriptor created for files - private static final Map<File, ParcelDescriptor> PARCEL_DESCRIPTOR_MAP = new - HashMap<File, ParcelDescriptor>(5); + private static final Map<File, ParcelDescriptor> PARCEL_DESCRIPTOR_MAP = + new HashMap<File, ParcelDescriptor>(5); // This is the default contents of a parcel descriptor to be used when // creating empty descriptors @@ -57,10 +57,6 @@ public class ParcelDescriptor { private String language = null; private Map<String, String> languagedepprops = new HashMap<String, String>(3); - - - - public ParcelDescriptor() throws IOException { ByteArrayInputStream bis = null; @@ -148,6 +144,7 @@ public class ParcelDescriptor { } public ScriptEntry[] getScriptEntries() { + ArrayList<ScriptEntry> scripts = new ArrayList<ScriptEntry>(); NodeList scriptNodes; int len; @@ -217,8 +214,8 @@ public class ParcelDescriptor { } } - ScriptEntry entry = new ScriptEntry(language, languagename, "", langProps, - description); + ScriptEntry entry = + new ScriptEntry(language, languagename, "", langProps, description); scripts.add(entry); } @@ -375,4 +372,4 @@ public class ParcelDescriptor { //add to the Top Element main.appendChild(root); } -} +} \ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/container/ParsedScriptUri.java b/scripting/java/com/sun/star/script/framework/container/ParsedScriptUri.java index 65d6f4e..796314f 100644 --- a/scripting/java/com/sun/star/script/framework/container/ParsedScriptUri.java +++ b/scripting/java/com/sun/star/script/framework/container/ParsedScriptUri.java @@ -22,5 +22,4 @@ public class ParsedScriptUri { public String location; public String function; public String parcel; -} - +} \ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/container/ScriptEntry.java b/scripting/java/com/sun/star/script/framework/container/ScriptEntry.java index 32bf9e5..303bb1a 100644 --- a/scripting/java/com/sun/star/script/framework/container/ScriptEntry.java +++ b/scripting/java/com/sun/star/script/framework/container/ScriptEntry.java @@ -33,6 +33,7 @@ public class ScriptEntry implements Cloneable { public ScriptEntry(String language, String languagename, String location) { + this.language = language; this.languagename = languagename; // logical name/ function name concept @@ -114,7 +115,9 @@ public class ScriptEntry implements Cloneable { @Override public String toString() { - return "\nLogicalName = " + logicalname + "\nLanguageName = " + languagename + - "\nLocation = " + location + "\nLanguaguageProperties = " + languagedepprops; + return "\nLogicalName = " + logicalname + + "\nLanguageName = " + languagename + + "\nLocation = " + location + + "\nLanguaguageProperties = " + languagedepprops; } -} +} \ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/container/ScriptMetaData.java b/scripting/java/com/sun/star/script/framework/container/ScriptMetaData.java index 78cbb2c..2c36a57 100644 --- a/scripting/java/com/sun/star/script/framework/container/ScriptMetaData.java +++ b/scripting/java/com/sun/star/script/framework/container/ScriptMetaData.java @@ -36,6 +36,7 @@ import java.util.ArrayList; import java.util.StringTokenizer; public class ScriptMetaData extends ScriptEntry { + private boolean hasSource = false; private String locationPlaceHolder = ""; private String source; @@ -51,7 +52,6 @@ public class ScriptMetaData extends ScriptEntry { this.hasSource = true; this.source = source; } - } public boolean hasSource() { @@ -71,18 +71,18 @@ public class ScriptMetaData extends ScriptEntry { } public String getScriptFullURL() { - String url = "vnd.sun.star.script:" + parent.getName() + "." + getLanguageName() - + - "?" + "language=" + getLanguage() + - "&location=" + getParcelLocation(); + String url = "vnd.sun.star.script:" + parent.getName() + "." + + getLanguageName() + "?" + "language=" + getLanguage() + + "&location=" + getParcelLocation(); + return url; } public String getShortFormScriptURL() { - String url = "vnd.sun.star.script:" + parent.getName() + "." + getLanguageName() - + - "?" + "language=" + getLanguage() + - "&location=" + getLocationPlaceHolder(); + String url = "vnd.sun.star.script:" + parent.getName() + "." + + getLanguageName() + "?" + "language=" + getLanguage() + + "&location=" + getLocationPlaceHolder(); + return url; } @@ -93,21 +93,18 @@ public class ScriptMetaData extends ScriptEntry { "vnd.sun.star.expand:$BRAND_BASE_DIR/$BRAND_SHARE_SUBDIR"; private static final String USER = - "vnd.sun.star.expand:${$BRAND_INI_DIR/" + - PathUtils.BOOTSTRAP_NAME + - "::UserInstallation}/user"; + "vnd.sun.star.expand:${$BRAND_INI_DIR/" + PathUtils.BOOTSTRAP_NAME + + "::UserInstallation}/user"; private static final String UNO_USER_PACKAGES1 = "vnd.sun.star.expand:$UNO_USER_PACKAGES_CACHE"; - private static final String UNO_USER_PACKAGES2 = - USER + "/uno_packages"; + private static final String UNO_USER_PACKAGES2 = USER + "/uno_packages"; private static final String UNO_SHARED_PACKAGES1 = "$UNO_SHARED_PACKAGES_CACHE"; - private static final String UNO_SHARED_PACKAGES2 = - SHARE + "/uno_packages"; + private static final String UNO_SHARED_PACKAGES2 = SHARE + "/uno_packages"; public static String getLocationPlaceHolder(String url, String pkgname) { String result = "Unknown"; @@ -177,7 +174,6 @@ public class ScriptMetaData extends ScriptEntry { return parent.getPathToParcel(); } - @Override public String toString() { return "\nParcelLocation = " + getParcelLocation() + "\nLocationPlaceHolder = " @@ -230,8 +226,8 @@ public class ScriptMetaData extends ScriptEntry { LogUtils.DEBUG(LogUtils.getTrace(e)); return new URL[0]; } - } + private URL createURL(String path) throws java.net.MalformedURLException { int indexOfColon = path.indexOf(':'); String scheme = path.substring(0, indexOfColon); @@ -246,7 +242,9 @@ public class ScriptMetaData extends ScriptEntry { public void loadSource() { try { URL sourceUrl = getSourceURL(); - LogUtils.DEBUG("** In load source BUT not loading yet for " + sourceUrl); + + LogUtils.DEBUG("** In load source BUT not loading yet for " + + sourceUrl); if (sourceUrl != null) { StringBuilder buf = new StringBuilder(); @@ -262,7 +260,8 @@ public class ScriptMetaData extends ScriptEntry { try { in.close(); } catch (java.io.IOException ignore) { - LogUtils.DEBUG("** Failed to read scriot from url " + ignore.toString()); + LogUtils.DEBUG("** Failed to read scriot from url " + + ignore.toString()); } source = buf.toString(); @@ -273,13 +272,15 @@ public class ScriptMetaData extends ScriptEntry { } } + protected boolean writeSourceFile() { String sourceFilePath = parent.getPathToParcel() + "/" + getLanguageName(); boolean result = false; try { - XSimpleFileAccess2 xSFA2 = UnoRuntime.queryInterface(XSimpleFileAccess2.class, - parent.m_xSFA); + + XSimpleFileAccess2 xSFA2 = + UnoRuntime.queryInterface(XSimpleFileAccess2.class, parent.m_xSFA); if (xSFA2 != null) { ByteArrayInputStream bis = new ByteArrayInputStream(getSourceBytes()); @@ -291,13 +292,12 @@ public class ScriptMetaData extends ScriptEntry { } // TODO re-examine exception processing should probably throw // exceptions back to caller - catch (Exception ignore) - - { + catch (Exception ignore) { } return result; } + protected boolean removeSourceFile() { String parcelLocation = parent.getPathToParcel(); String sourceFilePath = parcelLocation + "/" + getLanguageName(); @@ -320,4 +320,4 @@ public class ScriptMetaData extends ScriptEntry { LogUtils.DEBUG("Creating script url for " + sUrl); return createURL(sUrl); } -} +} \ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/container/UnoPkgContainer.java b/scripting/java/com/sun/star/script/framework/container/UnoPkgContainer.java index d14a2d7..64269f3 100644 --- a/scripting/java/com/sun/star/script/framework/container/UnoPkgContainer.java +++ b/scripting/java/com/sun/star/script/framework/container/UnoPkgContainer.java @@ -45,8 +45,10 @@ public class UnoPkgContainer extends ParcelContainer { public UnoPkgContainer(XComponentContext xCtx, String locationURL, String _extensionDb, String _extensionRepository, - String language) throws com.sun.star.lang.IllegalArgumentException, + String language) throws + com.sun.star.lang.IllegalArgumentException, com.sun.star.lang.WrappedTargetException { + super(xCtx, locationURL, language, false); extensionDb = _extensionDb; extensionRepository = _extensionRepository; @@ -55,6 +57,7 @@ public class UnoPkgContainer extends ParcelContainer { // gets the ParcelContainer for persisted uno packages public ParcelContainer getRegisteredUnoPkgContainer(String url) { + if (!url.endsWith("/")) { url += "/"; } @@ -62,6 +65,7 @@ public class UnoPkgContainer extends ParcelContainer { LogUtils.DEBUG("** getRegisterPackage ctx = " + containerUrl); LogUtils.DEBUG("** getRegisterPackage for uri " + url); LogUtils.DEBUG("** getRegisterPackage for langugage " + language); + ParcelContainer result = registeredPackages.get(url); LogUtils.DEBUG("getRegisterPackage result is " + result); return result; @@ -72,6 +76,7 @@ public class UnoPkgContainer extends ParcelContainer { } private void registerPackageContainer(String url, ParcelContainer c) { + ... etc. - the rest is truncated _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits