diff options
43 files changed, 1136 insertions, 883 deletions
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 3a4f413e9a0a..b9df352d56e4 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 da0fa02294aa..a4350fb92d59 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 076d63810d7b..23999a1c1e8c 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 c5abd3a5412d..bc52cb534357 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 b06689541b39..3bf1ba5eaf25 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 346c8a9bc607..e816f8e6dbd0 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 67a18e647c71..634fa1a7eec8 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 5d7f0ed628f9..0c9d41d60ae8 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 d5b97bd0f3b2..be72d785e9e1 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 1bde7eba9c62..14ebb2421cb5 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 65d6f4e68a28..796314f00bf0 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 32bf9e57a3ef..303bb1a5b1d2 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 78cbb2cf7784..2c36a579c3a9 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 d14a2d73f3a0..64269f3dd740 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) { + if (!url.endsWith("/")) { url += "/"; } @@ -83,6 +88,7 @@ public class UnoPkgContainer extends ParcelContainer { } public void deRegisterPackageContainer(String url) { + if (!url.endsWith("/")) { url += "/"; } @@ -136,13 +142,15 @@ public class UnoPkgContainer extends ParcelContainer { try { processUnoPackage(thepackage, language); } catch (com.sun.star.lang.IllegalArgumentException ila) { - LogUtils.DEBUG("Failed to process " + thepackage + " for " + language); + LogUtils.DEBUG("Failed to process " + thepackage + + " for " + language); LogUtils.DEBUG(" Reason: " + ila); } catch (Exception e) { // TODO proper exception or do we wish // to ignore errors here LogUtils.DEBUG("Something very wrong!!!!!"); - LogUtils.DEBUG("Failed to process " + thepackage + " for " + language); + LogUtils.DEBUG("Failed to process " + thepackage + + " for " + language); LogUtils.DEBUG(" Reason: " + e); } } @@ -153,15 +161,12 @@ public class UnoPkgContainer extends ParcelContainer { } } - @Override public ScriptMetaData findScript(ParsedScriptUri psu) throws com.sun.star.container.NoSuchElementException, - com.sun.star.lang.WrappedTargetException + com.sun.star.lang.WrappedTargetException { - { ScriptMetaData scriptData = null; - String functionName = psu.function; String parcelName = psu.parcel; String location = psu.location; @@ -175,9 +180,10 @@ public class UnoPkgContainer extends ParcelContainer { ParcelContainer pc = getChildContainer(location); if (pc == null) { - throw new com.sun.star.lang.WrappedTargetException("Failed to resolve script " , - null, new com.sun.star.lang.IllegalArgumentException("Cannot resolve script location for script = " - + functionName)); + throw new com.sun.star.lang.WrappedTargetException( + "Failed to resolve script " , null, + new com.sun.star.lang.IllegalArgumentException( + "Cannot resolve script location for script = " + functionName)); } return pc.findScript(psu); @@ -185,18 +191,24 @@ public class UnoPkgContainer extends ParcelContainer { private DeployedUnoPackagesDB getUnoPackagesDB() throws com.sun.star.lang.WrappedTargetException { + InputStream is = null; DeployedUnoPackagesDB dp = null; try { - String packagesUrl = PathUtils.make_url(extensionDb, - "/Scripts/" + extensionRepository + "-extension-desc.xml"); - LogUtils.DEBUG("getUnoPackagesDB() looking for existing db in " + packagesUrl); + + String packagesUrl = + PathUtils.make_url(extensionDb, + "/Scripts/" + extensionRepository + "-extension-desc.xml"); + + LogUtils.DEBUG("getUnoPackagesDB() looking for existing db in " + + packagesUrl); if (m_xSFA.exists(packagesUrl)) { if (packagesUrl.startsWith("vnd.sun.star.tdoc")) { // handles using XStorage directly - throw new com.sun.star.lang.WrappedTargetException("Can't handle documents yet"); + throw new com.sun.star.lang.WrappedTargetException( + "Can't handle documents yet"); } is = new XInputStreamWrapper(m_xSFA.openFileRead(packagesUrl)); @@ -208,7 +220,8 @@ public class UnoPkgContainer extends ParcelContainer { } catch (Exception ignore) { } } else { - LogUtils.DEBUG("getUnoPackagesDB() " + packagesUrl + " does not exist"); + LogUtils.DEBUG("getUnoPackagesDB() " + packagesUrl + + " does not exist"); } } catch (Exception e) { LogUtils.DEBUG("getUnoPackagesDB() caught Exception: " + e); @@ -230,14 +243,18 @@ public class UnoPkgContainer extends ParcelContainer { private void writeUnoPackageDB(DeployedUnoPackagesDB dp) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.lang.WrappedTargetException { + LogUtils.DEBUG("In writeUnoPackageDB() "); XOutputStream xos = null; OutputStream os = null; try { - String packagesUrl = PathUtils.make_url(extensionDb, - "/Scripts/" + extensionRepository + "-extension-desc.xml"); + + String packagesUrl = + PathUtils.make_url(extensionDb, "/Scripts/" + extensionRepository + + "-extension-desc.xml"); + xos = m_xSFA.openFileWrite(packagesUrl); XTruncate xTrc = UnoRuntime.queryInterface(XTruncate.class, xos); @@ -271,10 +288,13 @@ public class UnoPkgContainer extends ParcelContainer { } public void processUnoPackage(XPackage dPackage, - String language) throws com.sun.star.lang.IllegalArgumentException, + String language) throws + com.sun.star.lang.IllegalArgumentException, com.sun.star.lang.WrappedTargetException, com.sun.star.container.ElementExistException { + LogUtils.DEBUG("** in processUnoPackage "); + String uri = dPackage.getURL(); if (!uri.endsWith("/")) { @@ -283,12 +303,12 @@ public class UnoPkgContainer extends ParcelContainer { LogUtils.DEBUG("** processUnoPackage getURL() -> " + uri); LogUtils.DEBUG("** processUnoPackage getName() -> " + dPackage.getName()); - LogUtils.DEBUG("** processUnoPackage getMediaType() -> " + - dPackage.getPackageType().getMediaType()); + LogUtils.DEBUG("** processUnoPackage getMediaType() -> " + + dPackage.getPackageType().getMediaType()); try { - LogUtils.DEBUG("** processUnoPackage getDisplayName() -> " + - dPackage.getDisplayName()); + LogUtils.DEBUG("** processUnoPackage getDisplayName() -> " + + dPackage.getDisplayName()); } catch (com.sun.star.deployment.ExtensionRemovedException e) { throw new com.sun.star.lang.WrappedTargetException(e.getMessage(), this, e); } @@ -310,12 +330,15 @@ public class UnoPkgContainer extends ParcelContainer { } private void processUnoPackage(String uri, - String language) throws com.sun.star.lang.IllegalArgumentException, + String language) throws + com.sun.star.lang.IllegalArgumentException, com.sun.star.lang.WrappedTargetException, com.sun.star.container.ElementExistException { + if (hasRegisteredUnoPkgContainer(uri)) { - throw new com.sun.star.container.ElementExistException("Already a registered uno package " - + uri + " for language " + language); + throw new com.sun.star.container.ElementExistException( + "Already a registered uno package " + uri + " for language " + + language); } LogUtils.DEBUG("processUnoPackage - URL = " + uri); @@ -327,6 +350,7 @@ public class UnoPkgContainer extends ParcelContainer { uri.contains("$UNO_USER_PACKAGES_CACHE/") || uri.contains("$UNO_SHARED_PACKAGES_CACHE/") || uri.contains("$BUNDLED_EXTENSIONS/")) { + //its in a bundle need to determine the uno-package file its in LogUtils.DEBUG("processUnoPackage - is part of a uno bundle"); @@ -339,25 +363,28 @@ public class UnoPkgContainer extends ParcelContainer { if (index > -1) { parentUrl = uri.substring(0, index); - LogUtils.DEBUG("processUnoPackage - composition is contained in " + parentUrl); + LogUtils.DEBUG("processUnoPackage - composition is contained in " + + parentUrl); } ParcelContainer pkgContainer = getChildContainerForURL(parentUrl); if (pkgContainer == null) { - pkgContainer = new ParcelContainer(this, m_xCtx, parentUrl, language, false); + pkgContainer = + new ParcelContainer(this, m_xCtx, parentUrl, language, false); if (pkgContainer.loadParcel(uri) == null) { - throw new com.sun.star.lang.IllegalArgumentException("Couldn't load script library from composition package " - + uri + " for language " + language); - + throw new com.sun.star.lang.IllegalArgumentException( + "Couldn't load script library from composition package " + + uri + " for language " + language); } addChildContainer(pkgContainer); } else { if (pkgContainer.loadParcel(uri) == null) { - throw new com.sun.star.lang.IllegalArgumentException("Couldn't load script library from composition package " - + uri + " for language " + language); + throw new com.sun.star.lang.IllegalArgumentException( + "Couldn't load script library from composition package " + + uri + " for language " + language); } } @@ -367,13 +394,12 @@ public class UnoPkgContainer extends ParcelContainer { // stand-alone library package, e.g. not contained in // an uno package if (loadParcel(uri) == null) { - throw new com.sun.star.lang.IllegalArgumentException("Couldn't load script library package " - + uri + " for language " + language); + throw new com.sun.star.lang.IllegalArgumentException( + "Couldn't load script library package " + uri + + " for language " + language); } registerPackageContainer(uri, this); } - } - -} +}
\ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/container/XMLParser.java b/scripting/java/com/sun/star/script/framework/container/XMLParser.java index 0e06c883bc05..38e504ff4d6e 100644 --- a/scripting/java/com/sun/star/script/framework/container/XMLParser.java +++ b/scripting/java/com/sun/star/script/framework/container/XMLParser.java @@ -27,4 +27,4 @@ import org.w3c.dom.Document; public interface XMLParser { Document parse(InputStream inputStream) throws IOException; void write(Document doc, OutputStream out) throws IOException; -} +}
\ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/container/XMLParserFactory.java b/scripting/java/com/sun/star/script/framework/container/XMLParserFactory.java index 4ad477d6f6a5..45b10e9df3df 100644 --- a/scripting/java/com/sun/star/script/framework/container/XMLParserFactory.java +++ b/scripting/java/com/sun/star/script/framework/container/XMLParserFactory.java @@ -48,8 +48,6 @@ public class XMLParserFactory { return parser; } - - public static void setOfficeDTDURL(String url) { officedtdurl = url; } @@ -63,11 +61,11 @@ public class XMLParserFactory { } public Document parse(InputStream inputStream) throws IOException { + Document result = null; try { DocumentBuilder builder = factory.newDocumentBuilder(); - InputSource is = new InputSource(inputStream); if (officedtdurl != null) { @@ -87,6 +85,7 @@ public class XMLParserFactory { } public void write(Document doc, OutputStream out) throws IOException { + Class<?> clazz = doc.getClass(); String name = clazz.getName(); @@ -100,8 +99,10 @@ public class XMLParserFactory { // these DOM implementations are self writing Method write; + write = clazz.getDeclaredMethod("write", new Class[] {OutputStream.class}); + write.invoke(doc, new Object[] {out}); } else { // try xerces serialize package using introspection @@ -111,47 +112,61 @@ public class XMLParserFactory { Class<?> formatterClass = null; try { - serializerClass = Class.forName( - "org.apache.xml.serialize.XMLSerializer", true, cl); - formatterClass = Class.forName( - "org.apache.xml.serialize.OutputFormat", true, cl); + + serializerClass = + Class.forName("org.apache.xml.serialize.XMLSerializer", + true, cl); + + formatterClass = + Class.forName("org.apache.xml.serialize.OutputFormat", + true, cl); + } catch (ClassNotFoundException cnfe) { String prefix = "com.sun.org.apache.xml.internal."; - serializerClass = Class.forName( - prefix + "serialize.XMLSerializer" , true, cl); - formatterClass = Class.forName( - prefix + "serialize.OutputFormat", true, cl); + serializerClass = + Class.forName(prefix + "serialize.XMLSerializer", + true, cl); + + formatterClass = + Class.forName(prefix + "serialize.OutputFormat", + true, cl); } Object serializerObject = serializerClass.newInstance(); Object formatterObject = formatterClass.newInstance(); // improve output readability using the OutputFormat class - Method method = formatterClass.getMethod("setMethod", - new Class[] {String.class}); + Method method = + formatterClass.getMethod("setMethod", + new Class[] {String.class}); + method.invoke(formatterObject, new Object[] {"xml"}); + method = formatterClass.getMethod("setIndenting", new Class[] {Boolean.TYPE}); + method.invoke(formatterObject, new Object[] {Boolean.TRUE}); // now set up an instance of XMLSerializer with our // OutputStream and serialize our Document method = serializerClass.getMethod("setOutputByteStream", new Class[] {OutputStream.class}); + method.invoke(serializerObject, new Object[] {out}); + method = serializerClass.getMethod("setOutputFormat", new Class[] {formatterClass}); - method.invoke(serializerObject, - new Object[] {formatterObject}); - method = serializerClass.getMethod("asDOMSerializer", - new Class[0]); - Object impl = method.invoke(serializerObject, - new Object[0]); + method.invoke(serializerObject, new Object[] {formatterObject}); + + method = serializerClass.getMethod("asDOMSerializer", new Class[0]); + + Object impl = method.invoke(serializerObject, new Object[0]); method = impl.getClass().getMethod("serialize", new Class[] {Document.class}); + method.invoke(impl, new Object[] {doc}); } } catch (NoSuchMethodException ex) { @@ -163,4 +178,4 @@ public class XMLParserFactory { } } } -} +}
\ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/io/UCBStreamHandler.java b/scripting/java/com/sun/star/script/framework/io/UCBStreamHandler.java index 69d7c82db66e..969f79119f5b 100644 --- a/scripting/java/com/sun/star/script/framework/io/UCBStreamHandler.java +++ b/scripting/java/com/sun/star/script/framework/io/UCBStreamHandler.java @@ -59,8 +59,9 @@ public class UCBStreamHandler extends URLStreamHandler { @Override public void parseURL(URL url, String spec, int start, int limit) { - LogUtils.DEBUG("**XUCBStreamHandler, parseURL: " + url + " spec: " + spec + - " start: " + start + " limit: " + limit); + + LogUtils.DEBUG("**XUCBStreamHandler, parseURL: " + url + " spec: " + + spec + " start: " + start + " limit: " + limit); String file = url.getFile(); @@ -99,10 +100,13 @@ public class UCBStreamHandler extends URLStreamHandler { return getFileStreamFromUCB(sUrl); } else { String path = sUrl.substring(0, sUrl.lastIndexOf(separator)); - String file = sUrl.substring( - sUrl.lastIndexOf(separator) + separator.length()); - LogUtils.DEBUG("getInputStream, load of file from another file eg. " + file + - " from " + path); + + String file = + sUrl.substring(sUrl.lastIndexOf(separator) + separator.length()); + + LogUtils.DEBUG("getInputStream, load of file from another file eg. " + + file + " from " + path); + return getUCBStream(file, path); } } @@ -121,11 +125,14 @@ public class UCBStreamHandler extends URLStreamHandler { throw new java.io.IOException("File is read only"); } - LogUtils.DEBUG("getOutputStream, create o/p stream for file eg. " + path); + LogUtils.DEBUG("getOutputStream, create o/p stream for file eg. " + + path); // we will only deal with simple file write XOutputStream xos = m_xSimpleFileAccess.openFileWrite(path); - XTruncate xtrunc = UnoRuntime.queryInterface(XTruncate.class, xos); + + XTruncate xtrunc = + UnoRuntime.queryInterface(XTruncate.class, xos); if (xtrunc != null) { xtrunc.truncate(); @@ -135,7 +142,8 @@ public class UCBStreamHandler extends URLStreamHandler { } if (os == null) { - throw new IOException("Failed to get OutputStream for " + sUrl); + throw new IOException("Failed to get OutputStream for " + + sUrl); } } catch (com.sun.star.ucb.CommandAbortedException cae) { LogUtils.DEBUG("caught exception: " + cae.toString() + @@ -155,9 +163,8 @@ public class UCBStreamHandler extends URLStreamHandler { } } + private InputStream getUCBStream(String file, String path) throws IOException { - private InputStream getUCBStream(String file, String path) - throws IOException { InputStream is = null; InputStream result = null; @@ -197,10 +204,11 @@ public class UCBStreamHandler extends URLStreamHandler { return result; } - private InputStream getFileStreamFromJarStream(String file, InputStream is) - throws IOException { - ZipEntry entry; + private InputStream getFileStreamFromJarStream(String file, + InputStream is) throws + IOException { + ZipEntry entry; ZipInputStream zis = new ZipInputStream(is); while (zis.available() != 0) { @@ -214,8 +222,8 @@ public class UCBStreamHandler extends URLStreamHandler { return null; } - private InputStream getFileStreamFromUCB(String path) - throws IOException { + private InputStream getFileStreamFromUCB(String path) throws IOException { + InputStream result = null; XInputStream xInputStream = null; @@ -258,13 +266,12 @@ public class UCBStreamHandler extends URLStreamHandler { try { xInputStream.closeInput(); } catch (Exception e2) { - LogUtils.DEBUG( - "Error closing XInputStream:" + e2.getMessage()); + LogUtils.DEBUG("Error closing XInputStream: " + + e2.getMessage()); } } } return result; } - -} +}
\ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/io/XInputStreamImpl.java b/scripting/java/com/sun/star/script/framework/io/XInputStreamImpl.java index 3fcc07ca2a57..90766c51c553 100644 --- a/scripting/java/com/sun/star/script/framework/io/XInputStreamImpl.java +++ b/scripting/java/com/sun/star/script/framework/io/XInputStreamImpl.java @@ -24,7 +24,9 @@ import java.io.IOException; import java.io.InputStream; public class XInputStreamImpl implements XInputStream { + private InputStream is; + public XInputStreamImpl(InputStream is) { this.is = is; } @@ -32,8 +34,8 @@ public class XInputStreamImpl implements XInputStream { public int readBytes(/*OUT*/byte[][] aData, /*IN*/int nBytesToRead) throws com.sun.star.io.NotConnectedException, com.sun.star.io.BufferSizeExceededException, com.sun.star.io.IOException { - aData[ 0 ] = new byte[ nBytesToRead ]; + aData[ 0 ] = new byte[ nBytesToRead ]; int totalBytesRead = 0; try { @@ -56,6 +58,7 @@ public class XInputStreamImpl implements XInputStream { public int readSomeBytes(/*OUT*/byte[][] aData, /*IN*/int nMaxBytesToRead) throws com.sun.star.io.NotConnectedException, com.sun.star.io.BufferSizeExceededException, com.sun.star.io.IOException { + int bytesToRead = nMaxBytesToRead; int availableBytes = available(); @@ -70,6 +73,7 @@ public class XInputStreamImpl implements XInputStream { public void skipBytes(/*IN*/int nBytesToSkip) throws com.sun.star.io.NotConnectedException, com.sun.star.io.BufferSizeExceededException, com.sun.star.io.IOException { + try { is.skip(nBytesToSkip); } catch (IOException e) { @@ -77,8 +81,9 @@ public class XInputStreamImpl implements XInputStream { } } - public int available() throws com.sun.star.io.NotConnectedException, - com.sun.star.io.IOException { + public int available() throws + com.sun.star.io.NotConnectedException, com.sun.star.io.IOException { + int bytesAvail = 0; try { @@ -90,13 +95,13 @@ public class XInputStreamImpl implements XInputStream { return bytesAvail; } - public void closeInput() throws com.sun.star.io.NotConnectedException, - com.sun.star.io.IOException { + public void closeInput() throws + com.sun.star.io.NotConnectedException, com.sun.star.io.IOException { + try { is.close(); } catch (IOException e) { throw new com.sun.star.io.IOException(e); } } - -} +}
\ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/io/XInputStreamWrapper.java b/scripting/java/com/sun/star/script/framework/io/XInputStreamWrapper.java index 881502500a8b..402c1582ee45 100644 --- a/scripting/java/com/sun/star/script/framework/io/XInputStreamWrapper.java +++ b/scripting/java/com/sun/star/script/framework/io/XInputStreamWrapper.java @@ -22,6 +22,7 @@ import com.sun.star.io.XInputStream; import java.io.InputStream; public class XInputStreamWrapper extends InputStream { + private XInputStream m_xInputStream; public XInputStreamWrapper(XInputStream xInputStream) { @@ -85,5 +86,4 @@ public class XInputStreamWrapper extends InputStream { throw new java.io.IOException(ioe.getMessage()); } } - -} +}
\ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/io/XOutputStreamWrapper.java b/scripting/java/com/sun/star/script/framework/io/XOutputStreamWrapper.java index 3f7e8296b194..80ab81c60537 100644 --- a/scripting/java/com/sun/star/script/framework/io/XOutputStreamWrapper.java +++ b/scripting/java/com/sun/star/script/framework/io/XOutputStreamWrapper.java @@ -22,13 +22,15 @@ import com.sun.star.io.XOutputStream; import java.io.OutputStream; public class XOutputStreamWrapper extends OutputStream { + private XOutputStream m_xOutputStream; + public XOutputStreamWrapper(XOutputStream xOs) { this.m_xOutputStream = xOs; } + @Override - public void write(int b) - throws java.io.IOException { + public void write(int b) throws java.io.IOException { if (m_xOutputStream == null) { throw new java.io.IOException("Stream is null"); } @@ -42,9 +44,9 @@ public class XOutputStreamWrapper extends OutputStream { throw new java.io.IOException(ioe.getMessage()); } } + @Override - public void write(byte[] b) - throws java.io.IOException { + public void write(byte[] b) throws java.io.IOException { if (m_xOutputStream == null) { throw new java.io.IOException("Stream is null"); @@ -57,8 +59,7 @@ public class XOutputStreamWrapper extends OutputStream { } } @Override - public void write(byte[] b, int off, int len) - throws java.io.IOException { + public void write(byte[] b, int off, int len) throws java.io.IOException { if (m_xOutputStream == null) { throw new java.io.IOException("Stream is null"); } @@ -74,8 +75,7 @@ public class XOutputStreamWrapper extends OutputStream { } @Override - public void flush() - throws java.io.IOException { + public void flush() throws java.io.IOException { if (m_xOutputStream == null) { throw new java.io.IOException("Stream is null"); } @@ -86,9 +86,9 @@ public class XOutputStreamWrapper extends OutputStream { throw new java.io.IOException(ioe.getMessage()); } } + @Override - public void close() - throws java.io.IOException { + public void close() throws java.io.IOException { if (m_xOutputStream == null) { throw new java.io.IOException("Stream is null"); } @@ -99,6 +99,4 @@ public class XOutputStreamWrapper extends OutputStream { throw new java.io.IOException(ioe.getMessage()); } } - -} - +}
\ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/io/XStorageHelper.java b/scripting/java/com/sun/star/script/framework/io/XStorageHelper.java index 55710a2cca52..c0132cabc687 100644 --- a/scripting/java/com/sun/star/script/framework/io/XStorageHelper.java +++ b/scripting/java/com/sun/star/script/framework/io/XStorageHelper.java @@ -50,8 +50,8 @@ import java.util.HashMap; import java.util.Map; import java.util.StringTokenizer; - public class XStorageHelper implements XEventListener { + XStorage[] xStorages; XStream xStream; XInputStream xIs = null; @@ -61,8 +61,10 @@ public class XStorageHelper implements XEventListener { private static XStorageHelper listener = new XStorageHelper(); private XStorageHelper() {} + public XStorageHelper(String path, int mode, boolean create) throws IOException { + String modelUrl = null; int indexOfScriptsDir = path.lastIndexOf("Scripts"); @@ -82,10 +84,13 @@ public class XStorageHelper implements XEventListener { } XDocumentSubStorageSupplier xDocumentSubStorageSupplier = - UnoRuntime.queryInterface( - XDocumentSubStorageSupplier.class, xModel); - xStorages = new XStorage[tokens.countTokens() ]; - LogUtils.DEBUG("XStorageHelper ctor, path chunks length: " + xStorages.length); + UnoRuntime.queryInterface(XDocumentSubStorageSupplier.class, + xModel); + + xStorages = new XStorage[tokens.countTokens()]; + + LogUtils.DEBUG("XStorageHelper ctor, path chunks length: " + + xStorages.length); for (int i = 0; i < xStorages.length; i++) { LogUtils.DEBUG("XStorageHelper, processing index " + i); @@ -94,16 +99,20 @@ public class XStorageHelper implements XEventListener { XStorage storage = null; if (i == 0) { - storage = xDocumentSubStorageSupplier.getDocumentSubStorage(name, mode); + storage = xDocumentSubStorageSupplier.getDocumentSubStorage(name, mode); if (storage == null) { LogUtils.DEBUG("** boo hoo Storage is null "); } - XPropertySet xProps = UnoRuntime.queryInterface(XPropertySet.class, storage); + XPropertySet xProps = + UnoRuntime.queryInterface(XPropertySet.class, storage); if (xProps != null) { - String mediaType = AnyConverter.toString(xProps.getPropertyValue("MediaType")); + + String mediaType = + AnyConverter.toString(xProps.getPropertyValue("MediaType")); + LogUtils.DEBUG("***** media type is " + mediaType); if (!mediaType.equals("scripts")) { @@ -111,8 +120,9 @@ public class XStorageHelper implements XEventListener { } } } else { - XNameAccess xNameAccess = UnoRuntime.queryInterface(XNameAccess.class, - xStorages[i - 1]); + + XNameAccess xNameAccess = + UnoRuntime.queryInterface(XNameAccess.class, xStorages[i - 1]); if (xNameAccess == null) { disposeObject(); @@ -124,7 +134,8 @@ public class XStorageHelper implements XEventListener { throw new IOException("No subdir: " + name); } else { // attempt to create new storage - LogUtils.DEBUG("Attempt to create new storage for " + name); + LogUtils.DEBUG("Attempt to create new storage for " + + name); } } @@ -137,7 +148,7 @@ public class XStorageHelper implements XEventListener { throw new IOException("storage not found: " + name); } - xStorages[ i ] = storage; + xStorages[i] = storage; } } catch (com.sun.star.io.IOException ioe) { @@ -171,15 +182,19 @@ public class XStorageHelper implements XEventListener { modelMap.remove(model); } } + public XStorage getStorage() { return xStorages[ xStorages.length - 1 ]; } + public XModel getModel() { return xModel; } + public void disposeObject() { disposeObject(false); } + public void disposeObject(boolean shouldCommit) { LogUtils.DEBUG("In disposeObject"); @@ -202,12 +217,14 @@ public class XStorageHelper implements XEventListener { } } + static public void disposeObject(XInterface xInterface) { if (xInterface == null) { return; } - XComponent xComponent = UnoRuntime.queryInterface(XComponent.class, xInterface); + XComponent xComponent = + UnoRuntime.queryInterface(XComponent.class, xInterface); if (xComponent == null) { return; @@ -215,9 +232,11 @@ public class XStorageHelper implements XEventListener { xComponent.dispose(); } + static public void commit(XInterface xInterface) { - XTransactedObject xTrans = UnoRuntime.queryInterface(XTransactedObject.class, - xInterface); + + XTransactedObject xTrans = + UnoRuntime.queryInterface(XTransactedObject.class, xInterface); if (xTrans != null) { try { @@ -232,6 +251,4 @@ public class XStorageHelper implements XEventListener { //TODO does not cater for untitled documents return modelMap.get(url); } - -} - +}
\ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/log/LogUtils.java b/scripting/java/com/sun/star/script/framework/log/LogUtils.java index e6ed7ff61dbe..183f94a65b48 100644 --- a/scripting/java/com/sun/star/script/framework/log/LogUtils.java +++ b/scripting/java/com/sun/star/script/framework/log/LogUtils.java @@ -73,4 +73,4 @@ public class LogUtils { return result; } -} +}
\ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/provider/ClassLoaderFactory.java b/scripting/java/com/sun/star/script/framework/provider/ClassLoaderFactory.java index 2df0e5459ce5..b3f3c50b8603 100644 --- a/scripting/java/com/sun/star/script/framework/provider/ClassLoaderFactory.java +++ b/scripting/java/com/sun/star/script/framework/provider/ClassLoaderFactory.java @@ -28,6 +28,7 @@ import java.net.URLClassLoader; * Class Loader Factory */ public class ClassLoaderFactory { + private ClassLoaderFactory() {} public static ClassLoader getURLClassLoader(ScriptMetaData scriptData) { @@ -41,9 +42,9 @@ public class ClassLoaderFactory { return getURLClassLoader(parent, classPath); } + private static ClassLoader getURLClassLoader(ClassLoader parent, URL[] classpath) { return new URLClassLoader(classpath, parent); } - -} +}
\ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/provider/EditorScriptContext.java b/scripting/java/com/sun/star/script/framework/provider/EditorScriptContext.java index f00697f8738e..c6165818b6b7 100644 --- a/scripting/java/com/sun/star/script/framework/provider/EditorScriptContext.java +++ b/scripting/java/com/sun/star/script/framework/provider/EditorScriptContext.java @@ -28,8 +28,10 @@ import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XComponentContext; public class EditorScriptContext implements XScriptContext { + private XDesktop m_xDeskTop; private XComponentContext m_xComponentContext; + public EditorScriptContext(XComponentContext xmComponentContext, XDesktop xDesktop) { this.m_xComponentContext = xmComponentContext; @@ -42,15 +44,18 @@ public class EditorScriptContext implements XScriptContext { @return XModel interface */ public XModel getDocument() { - XModel xModel = UnoRuntime.queryInterface(XModel.class, - m_xDeskTop.getCurrentComponent()); + + XModel xModel = + UnoRuntime.queryInterface(XModel.class, m_xDeskTop.getCurrentComponent()); return xModel; } public XScriptInvocationContext getInvocationContext() { - XScriptInvocationContext xContext = UnoRuntime.queryInterface( - XScriptInvocationContext.class, getDocument()); + + XScriptInvocationContext xContext = + UnoRuntime.queryInterface(XScriptInvocationContext.class, getDocument()); + return xContext; } @@ -71,5 +76,4 @@ public class EditorScriptContext implements XScriptContext { public XComponentContext getComponentContext() { return m_xComponentContext; } - -} +}
\ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/provider/NoSuitableClassLoaderException.java b/scripting/java/com/sun/star/script/framework/provider/NoSuitableClassLoaderException.java index c9c103256a39..a2b0c6b1d7cb 100644 --- a/scripting/java/com/sun/star/script/framework/provider/NoSuitableClassLoaderException.java +++ b/scripting/java/com/sun/star/script/framework/provider/NoSuitableClassLoaderException.java @@ -19,6 +19,7 @@ package com.sun.star.script.framework.provider; public class NoSuitableClassLoaderException extends Exception { + /** * Constructs an <code>NoSuitableClassLoaderException</code> with <code>null</code> * as its error detail message. @@ -26,6 +27,7 @@ public class NoSuitableClassLoaderException extends Exception { public NoSuitableClassLoaderException() { super(); } + /** * Constructs an <code>NoSuitBaleClassLoaderException</code> with the specified detail * message. The error message string <code>s</code> can later be @@ -37,5 +39,4 @@ public class NoSuitableClassLoaderException extends Exception { public NoSuitableClassLoaderException(String s) { super(s); } - -} +}
\ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/provider/PathUtils.java b/scripting/java/com/sun/star/script/framework/provider/PathUtils.java index 97c222445f1e..08b859f4eafa 100644 --- a/scripting/java/com/sun/star/script/framework/provider/PathUtils.java +++ b/scripting/java/com/sun/star/script/framework/provider/PathUtils.java @@ -27,7 +27,6 @@ import java.util.StringTokenizer; public class PathUtils { - public static String BOOTSTRAP_NAME; private static boolean m_windows = false; @@ -38,13 +37,15 @@ public class PathUtils { BOOTSTRAP_NAME = m_windows ? "bootstrap.ini" : "bootstraprc"; } + public static String getOidForModel(XModel xModel) { String oid = ""; if (xModel != null) { try { - Method getOid = IQueryInterface.class.getMethod("getOid", - (java.lang.Class[])null); + + Method getOid = + IQueryInterface.class.getMethod("getOid", (java.lang.Class[])null); if (getOid != null) { oid = (String)getOid.invoke(xModel, new Object[0]); @@ -56,6 +57,7 @@ public class PathUtils { return oid; } + static public String make_url(String baseUrl, String url) { StringBuilder buff = new StringBuilder(baseUrl.length() + url.length()); buff.append(baseUrl); @@ -78,4 +80,4 @@ public class PathUtils { private PathUtils() { } -} +}
\ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/provider/ScriptContext.java b/scripting/java/com/sun/star/script/framework/provider/ScriptContext.java index c23f15123e5a..19f8bfc1080f 100644 --- a/scripting/java/com/sun/star/script/framework/provider/ScriptContext.java +++ b/scripting/java/com/sun/star/script/framework/provider/ScriptContext.java @@ -15,6 +15,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ + package com.sun.star.script.framework.provider; import com.sun.star.beans.PropertyAttribute; @@ -36,13 +37,13 @@ import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XComponentContext; public class ScriptContext extends PropertySet implements XScriptContext { + private final static String HM_DOC_REF = "DocumentReference"; private final static String HM_DESKTOP = "Desktop"; private final static String HM_COMPONENT_CONTEXT = "ComponentContext"; private final static String DOC_URI = "SCRIPTING_DOC_URI"; - private XModel m_xModel = null; private XScriptInvocationContext m_xInvocationContext = null; @@ -50,24 +51,30 @@ public class ScriptContext extends PropertySet implements XScriptContext { private XComponentContext m_xComponentContext = null; - private ScriptContext(XComponentContext xmComponentContext, - XDesktop xDesktop, XModel xModel, XScriptInvocationContext xInvocContext) { + private ScriptContext(XComponentContext xmComponentContext, XDesktop xDesktop, + XModel xModel, XScriptInvocationContext xInvocContext) { + this.m_xDeskTop = xDesktop; this.m_xComponentContext = xmComponentContext; this.m_xModel = xModel; this.m_xInvocationContext = xInvocContext; if (m_xModel != null) { + registerProperty(DOC_URI, new Type(String.class), (short)(PropertyAttribute.MAYBEVOID | PropertyAttribute.TRANSIENT), "m_sDocURI"); + } registerProperty(HM_DOC_REF, new Type(XModel.class), - (short)(PropertyAttribute.MAYBEVOID | PropertyAttribute.TRANSIENT), "m_xModel"); + (short)(PropertyAttribute.MAYBEVOID | PropertyAttribute.TRANSIENT), + "m_xModel"); + registerProperty(HM_DESKTOP, new Type(XDesktop.class), (short)(PropertyAttribute.MAYBEVOID | PropertyAttribute.TRANSIENT), "m_xDeskTop"); + registerProperty(HM_COMPONENT_CONTEXT, new Type(XDesktop.class), (short)(PropertyAttribute.MAYBEVOID | PropertyAttribute.TRANSIENT), "m_xComponentContext"); @@ -76,12 +83,14 @@ public class ScriptContext extends PropertySet implements XScriptContext { public static XScriptContext createContext(XModel xModel, XScriptInvocationContext xInvocContext, XComponentContext xCtxt, XMultiComponentFactory xMCF) { + XScriptContext sc = null; try { - Object xInterface = xMCF.createInstanceWithContext( - "com.sun.star.frame.Desktop", xCtxt); + Object xInterface = + xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xCtxt); + XDesktop xDesktop = UnoRuntime.queryInterface(XDesktop.class, xInterface); if (xModel != null) { @@ -128,5 +137,4 @@ public class ScriptContext extends PropertySet implements XScriptContext { public XComponentContext getComponentContext() { return m_xComponentContext; } - -} +}
\ No newline at end of file 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 ff5113c49bb5..32ebd2fefb41 100644 --- a/scripting/java/com/sun/star/script/framework/provider/ScriptEditor.java +++ b/scripting/java/com/sun/star/script/framework/provider/ScriptEditor.java @@ -27,4 +27,4 @@ public interface ScriptEditor { void edit(XScriptContext context, ScriptMetaData entry); String getTemplate(); String getExtension(); -} +}
\ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/provider/ScriptProvider.java b/scripting/java/com/sun/star/script/framework/provider/ScriptProvider.java index bee5727bf02f..bcef577491ac 100644 --- a/scripting/java/com/sun/star/script/framework/provider/ScriptProvider.java +++ b/scripting/java/com/sun/star/script/framework/provider/ScriptProvider.java @@ -73,16 +73,15 @@ import com.sun.star.uno.XComponentContext; import com.sun.star.util.XMacroExpander; -public abstract class ScriptProvider - implements XScriptProvider, XBrowseNode, XPropertySet, XInvocation, - XInitialization, XTypeProvider, XServiceInfo, XNameContainer { +public abstract class ScriptProvider implements + XScriptProvider, XBrowseNode, XPropertySet, XInvocation, XInitialization, + XTypeProvider, XServiceInfo, XNameContainer { + private final String[] __serviceNames = { "com.sun.star.script.provider.ScriptProviderFor", "com.sun.star.script.provider.LanguageScriptProvider" }; - - protected String language; protected XComponentContext m_xContext; @@ -94,6 +93,7 @@ public abstract class ScriptProvider // proxies to helper objects which implement interfaces private XPropertySet m_xPropertySetProxy; private XInvocation m_xInvocationProxy; + // TODO should this be implemented in this class private XBrowseNode m_xBrowseNodeProxy; private XScriptContext m_xScriptContext; @@ -117,19 +117,21 @@ public abstract class ScriptProvider "multicomponent factory - rethrowing Exception."); } - Object serviceObj = m_xContext.getValueByName( - "/singletons/com.sun.star.util.theMacroExpander"); + Object serviceObj = + m_xContext.getValueByName( + "/singletons/com.sun.star.util.theMacroExpander"); - XMacroExpander me = (XMacroExpander) AnyConverter.toObject( - new Type(XMacroExpander.class), serviceObj); + XMacroExpander me = + (XMacroExpander) AnyConverter.toObject( + new Type(XMacroExpander.class), serviceObj); - XMLParserFactory.setOfficeDTDURL(me.expandMacros( - "$BRAND_BASE_DIR/$BRAND_SHARE_SUBDIR/dtd/officedocument/1_0/")); + XMLParserFactory.setOfficeDTDURL( + me.expandMacros( + "$BRAND_BASE_DIR/$BRAND_SHARE_SUBDIR/dtd/officedocument/1_0/")); } catch (Exception e) { LogUtils.DEBUG(LogUtils.getTrace(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( "Error constructing ScriptProvider: " + e); e2.initCause(e); throw e2; @@ -158,30 +160,31 @@ public abstract class ScriptProvider if (AnyConverter.getType(aArguments[0]).getTypeClass().equals( TypeClass.INTERFACE)) { // try whether it denotes a XScriptInvocationContext - m_xInvocContext = UnoRuntime.queryInterface( - XScriptInvocationContext.class, aArguments[0]); + m_xInvocContext = + UnoRuntime.queryInterface(XScriptInvocationContext.class, aArguments[0]); if (m_xInvocContext != null) { // if so, obtain the document - by definition, this must be // the ScriptContainer - m_xModel = UnoRuntime.queryInterface(XModel.class, - m_xInvocContext.getScriptContainer()); + m_xModel = + UnoRuntime.queryInterface(XModel.class, m_xInvocContext.getScriptContainer()); } else { // otherwise, check whether it's an XModel - m_xModel = UnoRuntime.queryInterface(XModel.class, - m_xInvocContext.getScriptContainer()); + m_xModel = + UnoRuntime.queryInterface(XModel.class, m_xInvocContext.getScriptContainer()); } if (m_xModel == null) { throw new com.sun.star.uno.Exception( "ScriptProvider argument must be either a string, a valid XScriptInvocationContext, " - + - "or an XModel", this); + + "or an XModel", this); } contextUrl = getDocUrlFromModel(m_xModel); m_container = new ParcelContainer(m_xContext, contextUrl, language); + } else if (AnyConverter.isString(aArguments[0])) { + String originalContextURL = AnyConverter.toString(aArguments[0]); LogUtils.DEBUG("creating Application, path: " + originalContextURL); contextUrl = originalContextURL; @@ -196,19 +199,19 @@ public abstract class ScriptProvider if (originalContextURL.startsWith("bundled")) { contextUrl = "vnd.sun.star.expand:$BUNDLED_EXTENSIONS"; - extensionDb = "vnd.sun.star.expand:${$BRAND_INI_DIR/" + PathUtils.BOOTSTRAP_NAME - + "::UserInstallation}/user"; + extensionDb = "vnd.sun.star.expand:${$BRAND_INI_DIR/" + + PathUtils.BOOTSTRAP_NAME + "::UserInstallation}/user"; extensionRepository = "bundled"; } else if (originalContextURL.startsWith("share")) { contextUrl = "vnd.sun.star.expand:$BRAND_BASE_DIR/$BRAND_SHARE_SUBDIR"; - extensionDb = "vnd.sun.star.expand:${$BRAND_INI_DIR/" + PathUtils.BOOTSTRAP_NAME - + "::UserInstallation}/user"; + extensionDb = "vnd.sun.star.expand:${$BRAND_INI_DIR/" + + PathUtils.BOOTSTRAP_NAME + "::UserInstallation}/user"; extensionRepository = "shared"; } else if (originalContextURL.startsWith("user")) { - contextUrl = "vnd.sun.star.expand:${$BRAND_INI_DIR/" + PathUtils.BOOTSTRAP_NAME - + "::UserInstallation}/user"; - extensionDb = "vnd.sun.star.expand:${$BRAND_INI_DIR/" + PathUtils.BOOTSTRAP_NAME - + "::UserInstallation}/user"; + contextUrl = "vnd.sun.star.expand:${$BRAND_INI_DIR/" + + PathUtils.BOOTSTRAP_NAME + "::UserInstallation}/user"; + extensionDb = "vnd.sun.star.expand:${$BRAND_INI_DIR/" + + PathUtils.BOOTSTRAP_NAME + "::UserInstallation}/user"; extensionRepository = "user"; } @@ -217,15 +220,18 @@ public abstract class ScriptProvider if (!originalContextURL.equals(contextUrl) && !extensionRepository.equals("bundled")) { + contextUrl = PathUtils.make_url(contextUrl, "uno_packages"); } } if (isPkgProvider) { - m_container = new UnoPkgContainer(m_xContext, contextUrl, extensionDb, - extensionRepository, language); + m_container = + new UnoPkgContainer(m_xContext, contextUrl, extensionDb, extensionRepository, + language); } else { - m_container = new ParcelContainer(m_xContext, contextUrl, language); + m_container = + new ParcelContainer(m_xContext, contextUrl, language); } } } else { @@ -238,13 +244,13 @@ public abstract class ScriptProvider // TODO should all be done in this class instead of // deleagation???? - m_xBrowseNodeProxy = new ProviderBrowseNode(this, - m_container, m_xContext); + m_xBrowseNodeProxy = + new ProviderBrowseNode(this, m_container, m_xContext); - m_xInvocationProxy = UnoRuntime.queryInterface(XInvocation.class, - m_xBrowseNodeProxy); - m_xPropertySetProxy = UnoRuntime.queryInterface(XPropertySet.class, - m_xBrowseNodeProxy); + m_xInvocationProxy = + UnoRuntime.queryInterface(XInvocation.class, m_xBrowseNodeProxy); + m_xPropertySetProxy = + UnoRuntime.queryInterface(XPropertySet.class, m_xBrowseNodeProxy); } else { // this is ok, for example when executing a script from the // command line @@ -270,6 +276,7 @@ public abstract class ScriptProvider retValue[ 5 ] = new Type(XPropertySet.class); retValue[ 6 ] = new Type(XInvocation.class); retValue[ 7 ] = new Type(com.sun.star.container.XNameContainer.class); + return retValue; } @@ -316,11 +323,8 @@ public abstract class ScriptProvider return __serviceNames; } - - - public abstract XScript getScript(/*IN*/String scriptURI) - throws com.sun.star.uno.RuntimeException, - ScriptFrameworkErrorException; + public abstract XScript getScript(/*IN*/String scriptURI) throws + com.sun.star.uno.RuntimeException, ScriptFrameworkErrorException; // TODO need to encapsulate this better, // Some factory concept for creating/accessing Editor @@ -329,14 +333,14 @@ public abstract class ScriptProvider // This method is used to determine whether the ScriptProvider // has a ScriptEditor public abstract boolean hasScriptEditor(); + // TODO see above // This method is used to get the ScriptEditor for this ScriptProvider public abstract ScriptEditor getScriptEditor(); public ScriptMetaData getScriptData(/*IN*/String scriptURI) throws - ScriptFrameworkErrorException + ScriptFrameworkErrorException { - { try { ParsedScriptUri details = m_container.parseScriptUri(scriptURI); @@ -344,16 +348,16 @@ public abstract class ScriptProvider ScriptMetaData scriptData = m_container.findScript(details); if (scriptData == null) { - throw new ScriptFrameworkErrorException(details.function + " does not exist", - null, details.function, language, ScriptFrameworkErrorType.NO_SUCH_SCRIPT); + throw new ScriptFrameworkErrorException( + details.function + " does not exist", null, details.function, language, + ScriptFrameworkErrorType.NO_SUCH_SCRIPT); } return scriptData; } catch (com.sun.star.container.NoSuchElementException nse) { - ScriptFrameworkErrorException e2 - = new ScriptFrameworkErrorException( - nse.getMessage(), null, details.function, language, - ScriptFrameworkErrorType.NO_SUCH_SCRIPT); + ScriptFrameworkErrorException e2 = + new ScriptFrameworkErrorException(nse.getMessage(), null, details.function, + language, ScriptFrameworkErrorType.NO_SUCH_SCRIPT); e2.initCause(nse); throw e2; } catch (com.sun.star.lang.WrappedTargetException wta) { @@ -365,10 +369,9 @@ public abstract class ScriptProvider message = wrapped.getMessage(); } - ScriptFrameworkErrorException e2 - = new ScriptFrameworkErrorException( - message, null, details.function, language, - ScriptFrameworkErrorType.UNKNOWN); + ScriptFrameworkErrorException e2 = + new ScriptFrameworkErrorException(message, null, details.function, language, + ScriptFrameworkErrorType.UNKNOWN); e2.initCause(wta); throw e2; } @@ -383,7 +386,6 @@ public abstract class ScriptProvider } } - // Implementation of XBrowseNode interface public String getName() { return language; @@ -422,23 +424,25 @@ public abstract class ScriptProvider } 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 { + return m_xInvocationProxy.invoke( aFunctionName, aParams, aOutParamIndex, aOutParam); } - 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 { + m_xInvocationProxy.setValue(aPropertyName, aValue); } - public Object getValue(String aPropertyName) - throws com.sun.star.beans.UnknownPropertyException { + public Object getValue(String aPropertyName) throws + com.sun.star.beans.UnknownPropertyException { return m_xInvocationProxy.getValue(aPropertyName); } @@ -454,65 +458,69 @@ public abstract class ScriptProvider return m_xPropertySetProxy.getPropertySetInfo(); } - public void setPropertyValue(String aPropertyName, Object aValue) - throws com.sun.star.beans.UnknownPropertyException, + public void setPropertyValue(String aPropertyName, Object aValue) throws + com.sun.star.beans.UnknownPropertyException, com.sun.star.beans.PropertyVetoException, com.sun.star.lang.IllegalArgumentException, com.sun.star.lang.WrappedTargetException { + m_xPropertySetProxy.setPropertyValue(aPropertyName, aValue); } - public Object getPropertyValue(String PropertyName) - throws com.sun.star.beans.UnknownPropertyException, + public Object getPropertyValue(String PropertyName) throws + com.sun.star.beans.UnknownPropertyException, com.sun.star.lang.WrappedTargetException { + return m_xPropertySetProxy.getPropertyValue(PropertyName); } - public void addPropertyChangeListener( - String aPropertyName, XPropertyChangeListener xListener) - throws com.sun.star.beans.UnknownPropertyException, + public void addPropertyChangeListener(String aPropertyName, + XPropertyChangeListener xListener) throws + com.sun.star.beans.UnknownPropertyException, com.sun.star.lang.WrappedTargetException { + m_xPropertySetProxy.addPropertyChangeListener(aPropertyName, xListener); } public void removePropertyChangeListener( - String aPropertyName, XPropertyChangeListener aListener) - throws com.sun.star.beans.UnknownPropertyException, + String aPropertyName, XPropertyChangeListener aListener) throws + com.sun.star.beans.UnknownPropertyException, com.sun.star.lang.WrappedTargetException { + m_xPropertySetProxy.removePropertyChangeListener( aPropertyName, aListener); } public void addVetoableChangeListener( - String PropertyName, XVetoableChangeListener aListener) - throws com.sun.star.beans.UnknownPropertyException, + String PropertyName, XVetoableChangeListener aListener) throws + com.sun.star.beans.UnknownPropertyException, com.sun.star.lang.WrappedTargetException { + m_xPropertySetProxy.addVetoableChangeListener(PropertyName, aListener); } - public void removeVetoableChangeListener( - String PropertyName, XVetoableChangeListener aListener) - throws com.sun.star.beans.UnknownPropertyException, + public void removeVetoableChangeListener(String PropertyName, + XVetoableChangeListener aListener) throws + com.sun.star.beans.UnknownPropertyException, com.sun.star.lang.WrappedTargetException { + m_xPropertySetProxy.removeVetoableChangeListener( PropertyName, aListener); + } public java.lang.Object getByName(String aName) throws com.sun.star.container.NoSuchElementException, com.sun.star.lang.WrappedTargetException { + // TODO needs implementing? - throw new com.sun.star.uno.RuntimeException( - "getByName not implemented"); + throw new com.sun.star.uno.RuntimeException("getByName not implemented"); } public String[] getElementNames() { // TODO needs implementing? - throw new com.sun.star.uno.RuntimeException( - "getElementNames not implemented"); - + throw new com.sun.star.uno.RuntimeException("getElementNames not implemented"); } - // Performs the getRegStatus functionality for the PkgMgr public boolean hasByName(String aName) { return ((UnoPkgContainer)m_container).hasRegisteredUnoPkgContainer(aName); @@ -526,27 +534,25 @@ public abstract class ScriptProvider public boolean hasElements() { // TODO needs implementing? - throw new com.sun.star.uno.RuntimeException( - "hasElements not implemented"); + throw new com.sun.star.uno.RuntimeException("hasElements not implemented"); } - 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 needs implementing - if (true) { - throw new com.sun.star.uno.RuntimeException( - "replaceByName not implemented"); - } + // TODO needs implementing + throw new com.sun.star.uno.RuntimeException("replaceByName not implemented"); } - public void insertByName(String aName, - java.lang.Object aElement) throws com.sun.star.lang.IllegalArgumentException, + public void insertByName(String aName, java.lang.Object aElement) throws + com.sun.star.lang.IllegalArgumentException, com.sun.star.container.ElementExistException, com.sun.star.lang.WrappedTargetException { - LogUtils.DEBUG("Provider for " + language + " received register for package " + - aName); + + LogUtils.DEBUG("Provider for " + language + " received register for package " + + aName); + XPackage newPackage = UnoRuntime.queryInterface(XPackage.class, aElement); if (aName.length() == 0) { @@ -564,10 +570,13 @@ public abstract class ScriptProvider public void removeByName(String Name) throws com.sun.star.container.NoSuchElementException, com.sun.star.lang.WrappedTargetException { - LogUtils.DEBUG("In ScriptProvider.removeByName() for " + Name + - " this provider = " + language); - ParcelContainer c = ((UnoPkgContainer)m_container).getRegisteredUnoPkgContainer( - Name); + + LogUtils.DEBUG("In ScriptProvider.removeByName() for " + Name + + " this provider = " + language); + + ParcelContainer c = + ((UnoPkgContainer)m_container).getRegisteredUnoPkgContainer( + Name); if (c != null) { String libName; @@ -599,19 +608,19 @@ public abstract class ScriptProvider XTransientDocumentsDocumentContentFactory factory = null; try { + factory = UnoRuntime.queryInterface( XTransientDocumentsDocumentContentFactory.class, m_xMultiComponentFactory.createInstanceWithContext( "com.sun.star.frame.TransientDocumentsDocumentContentFactory", - m_xContext - ) - ); + m_xContext)); + } catch (Exception ex) { } if (factory == null) - throw new com.sun.star.uno.RuntimeException("ScriptProvider: unable to create a TDOC context factory.", - this); + throw new com.sun.star.uno.RuntimeException( + "ScriptProvider: unable to create a TDOC context factory.", this); try { XContent content = factory.createDocumentContent(document); @@ -624,8 +633,10 @@ public abstract class ScriptProvider } private XModel getModelFromDocUrl(String docUrl) { - LogUtils.DEBUG("getModelFromDocUrl - searching for match for ->" + docUrl + - "<-"); + + LogUtils.DEBUG("getModelFromDocUrl - searching for match for ->" + + docUrl + "<-"); + XModel xModel = null; try { @@ -633,13 +644,10 @@ public abstract class ScriptProvider XContentIdentifier xCntId = ucb.createContentIdentifier(docUrl); - XContent xCnt = ucb.queryContent(xCntId); - - XCommandProcessor xCmd = UnoRuntime.queryInterface(XCommandProcessor.class, - xCnt); - + XCommandProcessor xCmd = + UnoRuntime.queryInterface(XCommandProcessor.class, xCnt); Property[] pArgs = new Property[ ] { new Property() }; pArgs[ 0 ].Name = "DocumentModel"; @@ -654,18 +662,15 @@ public abstract class ScriptProvider com.sun.star.ucb.XCommandEnvironment env = null ; Object result = xCmd.execute(command, 0, env) ; - XRow values = UnoRuntime.queryInterface(XRow.class, - result); + XRow values = UnoRuntime.queryInterface(XRow.class, result); xModel = UnoRuntime.queryInterface(XModel.class, values.getObject(1, null)); + } catch (Exception ignore) { LogUtils.DEBUG("Failed to get model exception " + ignore); - } return xModel; } - - -} +}
\ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/provider/SwingInvocation.java b/scripting/java/com/sun/star/script/framework/provider/SwingInvocation.java index 1a0e2ff4f14d..c0ff3dab91db 100644 --- a/scripting/java/com/sun/star/script/framework/provider/SwingInvocation.java +++ b/scripting/java/com/sun/star/script/framework/provider/SwingInvocation.java @@ -25,6 +25,7 @@ import javax.swing.SwingUtilities; // (also, the current thread must not wait for that fresh thread to terminate, // as that would cause a deadlock if this thread is the AppKit thread): public final class SwingInvocation { + public static void invoke(final Runnable doRun) { new Thread("SwingInvocation") { @Override @@ -35,4 +36,4 @@ public final class SwingInvocation { } private SwingInvocation() {} -} +}
\ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/provider/beanshell/PlainSourceView.java b/scripting/java/com/sun/star/script/framework/provider/beanshell/PlainSourceView.java index ff9525be9204..514af0001e03 100644 --- a/scripting/java/com/sun/star/script/framework/provider/beanshell/PlainSourceView.java +++ b/scripting/java/com/sun/star/script/framework/provider/beanshell/PlainSourceView.java @@ -31,8 +31,8 @@ import javax.swing.JTextArea; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; -public class PlainSourceView extends JScrollPane - implements ScriptSourceView, DocumentListener { +public class PlainSourceView extends JScrollPane implements + ScriptSourceView, DocumentListener { private ScriptSourceModel model; private JTextArea ta; @@ -238,4 +238,4 @@ class GlyphGutter extends JComponent { g.setColor(Color.black); g.drawPolygon(arrow); } -} +}
\ 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 f5ac82b8ae4e..a95b2a1a0a6d 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 @@ -44,8 +44,8 @@ import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; -public class ScriptEditorForBeanShell - implements ScriptEditor, ActionListener { +public class ScriptEditorForBeanShell implements ScriptEditor, ActionListener { + private JFrame frame; private String filename; @@ -60,8 +60,8 @@ public class ScriptEditorForBeanShell private static ScriptEditorForBeanShell theScriptEditorForBeanShell; // global list of ScriptEditors, key is URL of file being edited - private static Map<URL, ScriptEditorForBeanShell> BEING_EDITED = new - HashMap<URL, ScriptEditorForBeanShell>(); + private static Map<URL, ScriptEditorForBeanShell> BEING_EDITED = + new HashMap<URL, ScriptEditorForBeanShell>(); // template for new BeanShell scripts private static String BSHTEMPLATE; @@ -69,9 +69,7 @@ public class ScriptEditorForBeanShell // try to load the template for BeanShell scripts static { try { - URL url = - ScriptEditorForBeanShell.class.getResource("template.bsh"); - + URL url = ScriptEditorForBeanShell.class.getResource("template.bsh"); InputStream in = url.openStream(); StringBuilder buf = new StringBuilder(); byte[] b = new byte[1024]; @@ -153,7 +151,6 @@ public class ScriptEditorForBeanShell return "bsh"; } - /** * Indicates the line where error occurred * @@ -161,6 +158,7 @@ public class ScriptEditorForBeanShell public void indicateErrorLine(int lineNum) { model.indicateErrorLine(lineNum); } + /** * Executes the script edited by the editor * @@ -169,6 +167,7 @@ public class ScriptEditorForBeanShell frame.toFront(); return model.execute(context, cl); } + /** * Opens an editor window for the specified ScriptMetaData. * If an editor window is already open for that data it will be @@ -232,8 +231,9 @@ public class ScriptEditorForBeanShell this.cl = cl; try { - Class<?> c = Class.forName( - "org.openoffice.netbeans.editor.NetBeansSourceView"); + + Class<?> c = + Class.forName("org.openoffice.netbeans.editor.NetBeansSourceView"); Class<?>[] types = new Class[] { ScriptSourceModel.class }; @@ -297,9 +297,9 @@ public class ScriptEditorForBeanShell private void doClose() { if (view.isModified()) { + int result = JOptionPane.showConfirmDialog(frame, - "The script has been modified. " + - "Do you want to save the changes?"); + "The script has been modified. Do you want to save the changes?"); if (result == JOptionPane.CANCEL_OPTION) { // don't close the window, just return @@ -379,4 +379,4 @@ public class ScriptEditorForBeanShell view.clear(); } } -} +}
\ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptProviderForBeanShell.java b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptProviderForBeanShell.java index d552446e43d5..e4aa8fc56f7f 100644 --- a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptProviderForBeanShell.java +++ b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptProviderForBeanShell.java @@ -54,25 +54,30 @@ import java.net.URL; import java.util.StringTokenizer; public class ScriptProviderForBeanShell { + public static class ScriptProviderForBeanShell_2 extends ScriptProvider { + public ScriptProviderForBeanShell_2(XComponentContext ctx) { super(ctx, "BeanShell"); } @Override - public XScript getScript(/*IN*/String scriptURI) - throws com.sun.star.uno.RuntimeException, - ScriptFrameworkErrorException { + public XScript getScript(/*IN*/String scriptURI) throws + com.sun.star.uno.RuntimeException, ScriptFrameworkErrorException { + ScriptMetaData scriptData = getScriptData(scriptURI); try { - ScriptImpl script = new ScriptImpl(m_xContext, scriptData, m_xModel, - m_xInvocContext); + + ScriptImpl script = + new ScriptImpl(m_xContext, scriptData, m_xModel, m_xInvocContext); + return script; } catch (com.sun.star.uno.RuntimeException re) { - throw new ScriptFrameworkErrorException("Failed to create script object: " + - re.getMessage(), - null, scriptData.getLanguageName(), language, ScriptFrameworkErrorType.UNKNOWN); + throw new ScriptFrameworkErrorException( + "Failed to create script object: " + re.getMessage(), + null, scriptData.getLanguageName(), language, + ScriptFrameworkErrorType.UNKNOWN); } } @@ -99,18 +104,20 @@ public class ScriptProviderForBeanShell { * the component * @see com.sun.star.comp.loader.JavaLoader */ - public static XSingleServiceFactory __getServiceFactory(String implName, - XMultiServiceFactory multiFactory, - XRegistryKey regKey) { + public static XSingleServiceFactory __getServiceFactory( + String implName, XMultiServiceFactory multiFactory, XRegistryKey regKey) { + XSingleServiceFactory xSingleServiceFactory = null; if (implName.equals( ScriptProviderForBeanShell.ScriptProviderForBeanShell_2.class.getName())) { - xSingleServiceFactory = FactoryHelper.getServiceFactory( - ScriptProviderForBeanShell.ScriptProviderForBeanShell_2.class, - "com.sun.star.script.provider.ScriptProviderForBeanShell", - multiFactory, - regKey); + + xSingleServiceFactory = + FactoryHelper.getServiceFactory( + ScriptProviderForBeanShell.ScriptProviderForBeanShell_2.class, + "com.sun.star.script.provider.ScriptProviderForBeanShell", + multiFactory, regKey); + } return xSingleServiceFactory; @@ -118,6 +125,7 @@ public class ScriptProviderForBeanShell { } class ScriptImpl implements XScript { + private ScriptMetaData metaData; private XComponentContext m_xContext; private XMultiComponentFactory m_xMultiComponentFactory; @@ -125,7 +133,9 @@ class ScriptImpl implements XScript { private XScriptInvocationContext m_xInvocContext; ScriptImpl(XComponentContext ctx, ScriptMetaData metaData, XModel xModel, - XScriptInvocationContext xContext) throws com.sun.star.uno.RuntimeException { + XScriptInvocationContext xContext) throws + com.sun.star.uno.RuntimeException { + this.metaData = metaData; this.m_xContext = ctx; this.m_xModel = xModel; @@ -136,12 +146,12 @@ class ScriptImpl implements XScript { } catch (Exception e) { LogUtils.DEBUG(LogUtils.getTrace(e)); throw new com.sun.star.uno.RuntimeException( - "Error constructing ScriptImpl [beanshell]: " - + e.getMessage()); + "Error constructing ScriptImpl [beanshell]: " + e.getMessage()); } LogUtils.DEBUG("ScriptImpl [beanshell] script data = " + metaData); } + /** * documentStorageID and document reference * for use in script name resolving @@ -167,14 +177,13 @@ class ScriptImpl implements XScript { public Object invoke(/*IN*/Object[] aParams, /*OUT*/short[][] aOutParamIndex, - /*OUT*/Object[][] aOutParam) - throws ScriptFrameworkErrorException, - InvocationTargetException { + /*OUT*/Object[][] aOutParam) throws + ScriptFrameworkErrorException, InvocationTargetException { + // Initialise the out parameters - not used at the moment aOutParamIndex[0] = new short[0]; aOutParam[0] = new Object[0]; - ClassLoader cl = null; URL sourceUrl = null; @@ -202,6 +211,7 @@ class ScriptImpl implements XScript { interpreter.setClassLoader(cl); try { + interpreter.set("XSCRIPTCONTEXT", ScriptContext.createContext(m_xModel, m_xInvocContext, m_xContext, m_xMultiComponentFactory)); @@ -219,8 +229,7 @@ class ScriptImpl implements XScript { Object result; ScriptEditorForBeanShell editor = - ScriptEditorForBeanShell.getEditor( - sourceUrl); + ScriptEditorForBeanShell.getEditor(sourceUrl); if (editor != null) { result = editor.execute(); @@ -250,34 +259,37 @@ class ScriptImpl implements XScript { return result; } catch (bsh.ParseException pe) { - throw new InvocationTargetException("Beanshell failed to parse " + - metaData.getLanguageName(), null, processBshException(pe, - metaData.getLanguageName())); + throw new InvocationTargetException( + "Beanshell failed to parse " + metaData.getLanguageName(), + null, processBshException(pe, metaData.getLanguageName())); } catch (bsh.TargetError te) { - throw new InvocationTargetException("Beanshell uncaught exception for " + - metaData.getLanguageName(), null, processBshException(te, - metaData.getLanguageName())); + throw new InvocationTargetException( + "Beanshell uncaught exception for " + metaData.getLanguageName(), + null, processBshException(te, metaData.getLanguageName())); } catch (bsh.EvalError ex) { - throw new InvocationTargetException("Beanshell error for " + - metaData.getLanguageName(), null, processBshException(ex, - metaData.getLanguageName())); + throw new InvocationTargetException( + "Beanshell error for " + metaData.getLanguageName(), + null, processBshException(ex, metaData.getLanguageName())); } catch (Exception e) { throw new ScriptFrameworkErrorException( - "Failed to read script", null, - metaData.getLanguageName(), metaData.getLanguage(), - ScriptFrameworkErrorType.UNKNOWN); + "Failed to read script", null, metaData.getLanguageName(), + metaData.getLanguage(), ScriptFrameworkErrorType.UNKNOWN); } } private void raiseEditor(int lineNum) { try { URL sourceUrl = metaData.getSourceURL(); - ScriptEditorForBeanShell editor = ScriptEditorForBeanShell.getEditor(sourceUrl); + + ScriptEditorForBeanShell editor = + ScriptEditorForBeanShell.getEditor(sourceUrl); if (editor == null) { editor = ScriptEditorForBeanShell.getEditor(); + editor.edit( - ScriptContext.createContext(m_xModel, m_xInvocContext, - m_xContext, m_xMultiComponentFactory), metaData); + ScriptContext.createContext(m_xModel, m_xInvocContext, m_xContext, + m_xMultiComponentFactory), metaData); + editor = ScriptEditorForBeanShell.getEditor(sourceUrl); } @@ -288,8 +300,9 @@ class ScriptImpl implements XScript { } } - private ScriptErrorRaisedException processBshException(bsh.EvalError e, - String script) { + private ScriptErrorRaisedException processBshException( + bsh.EvalError e, String script) { + LogUtils.DEBUG("Beanshell error RAW message " + e.getMessage()); String message = e.getMessage(); int usefulInfoIndex = message.lastIndexOf("\' :"); @@ -315,7 +328,9 @@ class ScriptImpl implements XScript { if (index > -1) { String toParse = full.substring(index); LogUtils.DEBUG("About to parse " + toParse); - StringTokenizer tokenizer = new StringTokenizer(full.substring(index), ":"); + + StringTokenizer tokenizer = + new StringTokenizer(full.substring(index), ":"); if (tokenizer.countTokens() > 2) { LogUtils.DEBUG("First token = " + (String)tokenizer.nextElement()); @@ -324,24 +339,31 @@ class ScriptImpl implements XScript { } } - ScriptExceptionRaisedException se = new ScriptExceptionRaisedException(message); + ScriptExceptionRaisedException se = + new ScriptExceptionRaisedException(message); + se.lineNum = lineNum; se.scriptName = script; se.exceptionType = wrappedException; se.language = "BeanShell"; + LogUtils.DEBUG("UnCaught Exception error: "); LogUtils.DEBUG("\tscript: " + script); LogUtils.DEBUG("\tline: " + lineNum); LogUtils.DEBUG("\twrapped exception: " + wrappedException); LogUtils.DEBUG("\tmessage: " + message); + return se; + } else { LogUtils.DEBUG("Error or ParseError Exception error: "); LogUtils.DEBUG("\tscript: " + script); LogUtils.DEBUG("\tline: " + lineNum); LogUtils.DEBUG("\tmessage: " + message); - return new ScriptErrorRaisedException(message, null, script, "BeanShell", - lineNum); + + return new ScriptErrorRaisedException(message, null, script, + "BeanShell", lineNum); + } } -} +}
\ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptSourceModel.java b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptSourceModel.java index df686bf2b857..67041ff2cdb8 100644 --- a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptSourceModel.java +++ b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptSourceModel.java @@ -116,9 +116,10 @@ public class ScriptSourceModel { return result; } + public void indicateErrorLine(int lineNum) { System.out.println("Beanshell indicateErrorLine " + lineNum); currentPosition = lineNum - 1; view.update(); } -} +}
\ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptSourceView.java b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptSourceView.java index 0055d44889e8..c60b6f1ac57a 100644 --- a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptSourceView.java +++ b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptSourceView.java @@ -23,4 +23,4 @@ public interface ScriptSourceView { boolean isModified(); void setModified(boolean value); String getText(); -} +}
\ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/provider/java/Resolver.java b/scripting/java/com/sun/star/script/framework/provider/java/Resolver.java index ab5103070210..8192f4724265 100644 --- a/scripting/java/com/sun/star/script/framework/provider/java/Resolver.java +++ b/scripting/java/com/sun/star/script/framework/provider/java/Resolver.java @@ -15,7 +15,6 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ - package com.sun.star.script.framework.provider.java; /** @@ -23,8 +22,8 @@ package com.sun.star.script.framework.provider.java; * want to implement an algorithm for obtaining a ScriptProxy object * for a particular ScriptDescriptor and Class */ - public interface Resolver { + /** * Returns a ScriptProxy object for the given ScriptDescriptor and Class * @@ -32,7 +31,6 @@ public interface Resolver { * @param c A Class * @return The ScriptProxy value */ - ScriptProxy getProxy(ScriptDescriptor sd, Class<?> c) - throws NoSuchMethodException; -} - + ScriptProxy getProxy(ScriptDescriptor sd, Class<?> c) throws + NoSuchMethodException; +}
\ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/provider/java/ScriptDescriptor.java b/scripting/java/com/sun/star/script/framework/provider/java/ScriptDescriptor.java index 5b38bc0c2e1f..9d45332f7ca2 100644 --- a/scripting/java/com/sun/star/script/framework/provider/java/ScriptDescriptor.java +++ b/scripting/java/com/sun/star/script/framework/provider/java/ScriptDescriptor.java @@ -15,7 +15,6 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ - package com.sun.star.script.framework.provider.java; import java.util.ArrayList; @@ -27,6 +26,7 @@ import java.util.StringTokenizer; * criteria that should be used for finding a particular script */ public class ScriptDescriptor { + private String m_name; private String m_methodName; private String m_className; @@ -39,8 +39,7 @@ public class ScriptDescriptor { * @param name Script Name * @exception IllegalArgumentException if the given name does not contain a "." */ - public ScriptDescriptor(String name) - throws IllegalArgumentException { + public ScriptDescriptor(String name) throws IllegalArgumentException { int idx = name.lastIndexOf('.'); if (idx == -1) { @@ -70,7 +69,6 @@ public class ScriptDescriptor { return m_className; } - /** * Gets the method name of this <code>ScriptDescriptor</code> * @@ -80,7 +78,6 @@ public class ScriptDescriptor { return m_methodName; } - /** * Sets the classpath value stored by this <code>ScriptDescriptor</code> * @@ -103,7 +100,6 @@ public class ScriptDescriptor { this.m_classpath = classpath; } - /** * Gets the classpath value stored by this <code>ScriptDescriptor</code> * @@ -113,7 +109,6 @@ public class ScriptDescriptor { return m_classpath; } - /** * Adds the given <code>Class</code> to the list of argument types stored in * this ScriptDescriptor @@ -125,10 +120,6 @@ public class ScriptDescriptor { m_argumentTypes.add(clazz); } - - - - /** * Gets a list of the types of the arguments stored in this * <code>ScriptDescriptor</code> @@ -138,15 +129,13 @@ public class ScriptDescriptor { * @return The argumentTypes value */ - public synchronized Class<?>[] - getArgumentTypes() { + public synchronized Class<?>[] getArgumentTypes() { if (m_argumentTypes.size() > 0) return m_argumentTypes.toArray(new Class[ m_argumentTypes.size() ]); else return null; } - /** * Returns a <code>String</code> representation of this * <code>ScriptDescriptor</code> @@ -173,5 +162,4 @@ public class ScriptDescriptor { return description.toString(); } -} - +}
\ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/provider/java/ScriptProviderForJava.java b/scripting/java/com/sun/star/script/framework/provider/java/ScriptProviderForJava.java index 5f51587a29c8..bc896cb2103e 100644 --- a/scripting/java/com/sun/star/script/framework/provider/java/ScriptProviderForJava.java +++ b/scripting/java/com/sun/star/script/framework/provider/java/ScriptProviderForJava.java @@ -49,7 +49,9 @@ import java.util.ArrayList; import java.util.Map; public class ScriptProviderForJava { + public static class _ScriptProviderForJava extends ScriptProvider { + private Resolver m_resolutionPolicy = new StrictResolver(); public _ScriptProviderForJava(XComponentContext ctx) { @@ -57,25 +59,26 @@ public class ScriptProviderForJava { } @Override - public XScript getScript(/*IN*/String scriptURI) - throws com.sun.star.uno.RuntimeException, - ScriptFrameworkErrorException { + public XScript getScript(/*IN*/String scriptURI) throws + com.sun.star.uno.RuntimeException, ScriptFrameworkErrorException { + ScriptMetaData scriptData = getScriptData(scriptURI); try { - ScriptImpl script = new ScriptImpl(m_xContext, m_resolutionPolicy, scriptData, - m_xModel, m_xInvocContext); + + ScriptImpl script = + new ScriptImpl(m_xContext, m_resolutionPolicy, scriptData, m_xModel, + m_xInvocContext); + return script; } catch (com.sun.star.uno.RuntimeException re) { - ScriptFrameworkErrorException e2 = - new ScriptFrameworkErrorException( - "Failed to create script object: " + re, - null, scriptData.getLanguageName(), language, + ScriptFrameworkErrorException e2 = new ScriptFrameworkErrorException( + "Failed to create script object: " + re, null, + scriptData.getLanguageName(), language, ScriptFrameworkErrorType.UNKNOWN); e2.initCause(re); throw e2; } - } @Override @@ -101,18 +104,20 @@ public class ScriptProviderForJava { * the component * @see com.sun.star.comp.loader.JavaLoader */ - public static XSingleServiceFactory __getServiceFactory(String implName, - XMultiServiceFactory multiFactory, - XRegistryKey regKey) { + public static XSingleServiceFactory __getServiceFactory( + String implName, XMultiServiceFactory multiFactory, XRegistryKey regKey) { + XSingleServiceFactory xSingleServiceFactory = null; if (implName.equals( ScriptProviderForJava._ScriptProviderForJava.class.getName())) { - xSingleServiceFactory = FactoryHelper.getServiceFactory( - ScriptProviderForJava._ScriptProviderForJava.class, - "com.sun.star.script.provider.ScriptProviderForJava", - multiFactory, - regKey); + + xSingleServiceFactory = + FactoryHelper.getServiceFactory( + ScriptProviderForJava._ScriptProviderForJava.class, + "com.sun.star.script.provider.ScriptProviderForJava", + multiFactory, regKey); + } return xSingleServiceFactory; @@ -120,15 +125,18 @@ public class ScriptProviderForJava { } class ScriptImpl implements XScript { + private ScriptMetaData metaData; private XComponentContext m_xContext; private XModel m_xModel; private XScriptInvocationContext m_xInvocContext; private XMultiComponentFactory m_xMultiComponentFactory; private Resolver m_resolutionPolicy; + ScriptImpl(XComponentContext ctx, Resolver resolver, ScriptMetaData metaData, XModel xModel, XScriptInvocationContext xInvocContext) throws com.sun.star.uno.RuntimeException { + this.metaData = metaData; this.m_xContext = ctx; this.m_xModel = xModel; @@ -139,8 +147,7 @@ class ScriptImpl implements XScript { this.m_xMultiComponentFactory = m_xContext.getServiceManager(); } catch (Exception e) { LogUtils.DEBUG(LogUtils.getTrace(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( "Error constructing ScriptProvider: " + e); e2.initCause(e); throw e2; @@ -148,6 +155,7 @@ class ScriptImpl implements XScript { LogUtils.DEBUG("ScriptImpl [java] script data = " + metaData); } + /** * Invoke * @@ -161,14 +169,13 @@ class ScriptImpl implements XScript { * @throws com.sun.star.reflection.InvocationTargetException If the running script throws an exception * this information is captured and rethrown as this exception type. */ - public Object invoke( /*IN*/Object[] params, /*OUT*/short[][] aOutParamIndex, - /*OUT*/Object[][] aOutParam) - - throws ScriptFrameworkErrorException, + /*OUT*/Object[][] aOutParam) throws + ScriptFrameworkErrorException, com.sun.star.reflection.InvocationTargetException { + LogUtils.DEBUG("** ScriptProviderForJava::invoke: Starting..."); // Initialise the out parameters - not used at the moment @@ -184,8 +191,10 @@ class ScriptImpl implements XScript { try { LogUtils.DEBUG("Classloader starting..."); - scriptLoader = ClassLoaderFactory.getURLClassLoader( - metaData); + + scriptLoader = + ClassLoaderFactory.getURLClassLoader(metaData); + LogUtils.DEBUG("Classloader finished..."); } catch (ArrayStoreException e) { // Framework error @@ -204,8 +213,10 @@ class ScriptImpl implements XScript { LogUtils.DEBUG("Parameter Mapping..."); // Setup Context Object - XScriptContext xSc = ScriptContext.createContext(m_xModel, m_xInvocContext, - m_xContext, m_xMultiComponentFactory); + XScriptContext xSc = + ScriptContext.createContext(m_xModel, m_xInvocContext, + m_xContext, m_xMultiComponentFactory); + scriptDesc.addArgumentType(XScriptContext.class); invocationArgList.add(xSc); @@ -218,22 +229,22 @@ class ScriptImpl implements XScript { invocationArgs = invocationArgList.toArray(); } - - LogUtils.DEBUG("ScriptProxy starting... "); ScriptProxy script = null; try { + String className = metaData.getLanguageName().substring(0, metaData.getLanguageName().lastIndexOf('.')); + LogUtils.DEBUG("About to load Class " + className + " starting... "); long start = new java.util.Date().getTime(); Class<?> c = scriptLoader.loadClass(className); long end = new java.util.Date().getTime(); - LogUtils.DEBUG("loadClass took: " + String.valueOf(end - start) + - "milliseconds"); + LogUtils.DEBUG("loadClass took: " + String.valueOf(end - start) + + "milliseconds"); try { LogUtils.DEBUG("class loaded ... "); @@ -241,21 +252,17 @@ class ScriptImpl implements XScript { LogUtils.DEBUG("script resolved ... "); } catch (NoSuchMethodException e) { // Framework error - ScriptFrameworkErrorException e2 = - new ScriptFrameworkErrorException( - e.toString(), null, - metaData.getLanguageName(), metaData.getLanguage(), - ScriptFrameworkErrorType.NO_SUCH_SCRIPT); + ScriptFrameworkErrorException e2 = new ScriptFrameworkErrorException( + e.toString(), null, metaData.getLanguageName(), + metaData.getLanguage(), ScriptFrameworkErrorType.NO_SUCH_SCRIPT); e2.initCause(e); throw e2; } } catch (ClassNotFoundException e) { // Framework error - ScriptFrameworkErrorException e2 = - new ScriptFrameworkErrorException( - e.toString(), null, - metaData.getLanguageName(), metaData.getLanguage(), - ScriptFrameworkErrorType.NO_SUCH_SCRIPT); + ScriptFrameworkErrorException e2 = new ScriptFrameworkErrorException( + e.toString(), null, metaData.getLanguageName(), + metaData.getLanguage(), ScriptFrameworkErrorType.NO_SUCH_SCRIPT); e2.initCause(e); throw e2; } @@ -267,40 +274,37 @@ class ScriptImpl implements XScript { long start = new java.util.Date().getTime(); result = script.invoke(invocationArgs); long end = new java.util.Date().getTime(); - - LogUtils.DEBUG("invoke took: " + - String.valueOf(end - start) + "milliseconds"); + LogUtils.DEBUG("invoke took: " + String.valueOf(end - start) + + "milliseconds"); } catch (java.lang.IllegalArgumentException iae) { - ScriptFrameworkErrorException e2 = - new ScriptFrameworkErrorException( - iae.getMessage(), null, - metaData.getLanguageName(), metaData.getLanguage(), - ScriptFrameworkErrorType.UNKNOWN); + ScriptFrameworkErrorException e2 = new ScriptFrameworkErrorException( + iae.getMessage(), null, metaData.getLanguageName(), + metaData.getLanguage(), ScriptFrameworkErrorType.UNKNOWN); e2.initCause(iae); throw e2; } catch (java.lang.IllegalAccessException ia) { - ScriptFrameworkErrorException e2 = - new ScriptFrameworkErrorException( - ia.toString(), null, - metaData.getLanguageName(), metaData.getLanguage(), - ScriptFrameworkErrorType.UNKNOWN); + ScriptFrameworkErrorException e2 = new ScriptFrameworkErrorException( + ia.toString(), null, metaData.getLanguageName(), + metaData.getLanguage(), ScriptFrameworkErrorType.UNKNOWN); e2.initCause(ia); throw e2; } catch (java.lang.reflect.InvocationTargetException ite) { Throwable targetException = ite.getTargetException(); + ScriptExceptionRaisedException se = - new ScriptExceptionRaisedException( - targetException.toString()); + new ScriptExceptionRaisedException(targetException.toString()); + se.lineNum = -1; se.scriptName = metaData.getLanguageName(); se.language = "Java"; se.exceptionType = targetException.getClass().getName(); + throw new com.sun.star.reflection.InvocationTargetException( "Scripting Framework error executing script ", null, se); + } catch (Exception unknown) { ScriptExceptionRaisedException se = - new ScriptExceptionRaisedException( - unknown.toString()); + new ScriptExceptionRaisedException(unknown.toString()); se.lineNum = -1; se.scriptName = metaData.getLanguageName(); se.language = "Java"; @@ -320,4 +324,4 @@ class ScriptImpl implements XScript { return result; } -} +}
\ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/provider/java/ScriptProxy.java b/scripting/java/com/sun/star/script/framework/provider/java/ScriptProxy.java index 7ca6de411167..e8ab74b4fb9b 100644 --- a/scripting/java/com/sun/star/script/framework/provider/java/ScriptProxy.java +++ b/scripting/java/com/sun/star/script/framework/provider/java/ScriptProxy.java @@ -15,7 +15,6 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ - package com.sun.star.script.framework.provider.java; import java.lang.reflect.InvocationTargetException; @@ -27,10 +26,10 @@ import java.lang.reflect.Method; * @see java.lang.reflect.Method */ public class ScriptProxy { + private Object m_targetObject; private Method m_method; - /** * Constructs a <code>ScriptProxy</code> object for the given * <code>Method</code> @@ -41,7 +40,6 @@ public class ScriptProxy { this.m_method = method; } - /** * Sets the <code>Object</code> on which the ScriptProxy should invoke * the method @@ -52,7 +50,6 @@ public class ScriptProxy { m_targetObject = obj; } - /** * Invokes the method contained in this <code>ScriptProxy</code>, * any exceptions resulting from the invocation will be thrown @@ -64,10 +61,9 @@ public class ScriptProxy { * @see java.lang.reflect.Method for the exceptions * that may be thrown */ - public Object invoke(Object[] args) - throws IllegalAccessException, InvocationTargetException, - IllegalArgumentException { + public Object invoke(Object[] args) throws + IllegalAccessException, InvocationTargetException, IllegalArgumentException { + return m_method.invoke(m_targetObject, args); } -} - +}
\ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/provider/java/StrictResolver.java b/scripting/java/com/sun/star/script/framework/provider/java/StrictResolver.java index c530dc36ee08..a7b580272c9f 100644 --- a/scripting/java/com/sun/star/script/framework/provider/java/StrictResolver.java +++ b/scripting/java/com/sun/star/script/framework/provider/java/StrictResolver.java @@ -31,6 +31,7 @@ import java.lang.reflect.Modifier; * can be found in the Class. */ public class StrictResolver implements Resolver { + /** *Constructor for the StrictResolver object */ @@ -47,8 +48,9 @@ public class StrictResolver implements Resolver { * @param c the Class file in which to search for the method * @return the ScriptProxy matching the criteria, or null if no match is found */ - public ScriptProxy getProxy(ScriptDescriptor sd, Class<?> c) - throws NoSuchMethodException { + public ScriptProxy getProxy(ScriptDescriptor sd, Class<?> c) throws + NoSuchMethodException { + Method m = null; LogUtils.DEBUG("StrictResolver.getProxy() for: " + sd.toString()); @@ -56,11 +58,13 @@ public class StrictResolver implements Resolver { try { m = resolveArguments(sd, c); } catch (ClassNotFoundException e) { - throw new NoSuchMethodException("StrictResolver.getProxy: Can't find method: " - + sd.getMethodName() + ":" + e.getMessage()); + throw new NoSuchMethodException( + "StrictResolver.getProxy: Can't find method: " + sd.getMethodName() + + ":" + e.getMessage()); } catch (NoSuchMethodException e) { - throw new NoSuchMethodException("StrictResolver.getProxy: Can't find method: " - + sd.getMethodName() + ":" + e.getMessage()); + throw new NoSuchMethodException( + "StrictResolver.getProxy: Can't find method: " + sd.getMethodName() + + ":" + e.getMessage()); } ScriptProxy sp = new ScriptProxy(m); @@ -73,11 +77,11 @@ public class StrictResolver implements Resolver { try { o = c.newInstance(); } catch (InstantiationException ie) { - throw new NoSuchMethodException("getScriptProxy: Can't instantiate: " + - c.getName()); + throw new NoSuchMethodException( + "getScriptProxy: Can't instantiate: " + c.getName()); } catch (IllegalAccessException iae) { - throw new NoSuchMethodException("getScriptProxy: Can't access: " - + c.getName()); + throw new NoSuchMethodException( + "getScriptProxy: Can't access: " + c.getName()); } sp.setTargetObject(o); @@ -86,7 +90,6 @@ public class StrictResolver implements Resolver { return sp; } - /** * Description of the Method * @@ -96,9 +99,9 @@ public class StrictResolver implements Resolver { * @exception ClassNotFoundException * @exception NoSuchMethodException */ - private Method resolveArguments(ScriptDescriptor sd, Class<?> c) - throws ClassNotFoundException, NoSuchMethodException { + private Method resolveArguments(ScriptDescriptor sd, Class<?> c) throws + ClassNotFoundException, NoSuchMethodException { + return c.getMethod(sd.getMethodName(), sd.getArgumentTypes()); } -} - +}
\ No newline at end of file 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 94b2e570efd4..4fb29852d303 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 @@ -41,6 +41,7 @@ import org.mozilla.javascript.tools.debugger.Main; import org.mozilla.javascript.tools.debugger.ScopeProvider; public class ScriptEditorForJavaScript implements ScriptEditor { + // global ScriptEditorForJavaScript instance private static ScriptEditorForJavaScript theScriptEditorForJavaScript; @@ -55,9 +56,7 @@ public class ScriptEditorForJavaScript implements ScriptEditor { static { try { - URL url = - ScriptEditorForJavaScript.class.getResource("template.js"); - + URL url = ScriptEditorForJavaScript.class.getResource("template.js"); InputStream in = url.openStream(); StringBuilder buf = new StringBuilder(); byte[] b = new byte[1024]; @@ -83,8 +82,7 @@ public class ScriptEditorForJavaScript implements ScriptEditor { public static synchronized ScriptEditorForJavaScript getEditor() { if (theScriptEditorForJavaScript == null) { - theScriptEditorForJavaScript = - new ScriptEditorForJavaScript(); + theScriptEditorForJavaScript = new ScriptEditorForJavaScript(); } return theScriptEditorForJavaScript; @@ -170,12 +168,10 @@ public class ScriptEditorForJavaScript implements ScriptEditor { new Runnable() { public void run() { synchronized (BEING_EDITED) { - ScriptEditorForJavaScript editor = - BEING_EDITED.get(url); + ScriptEditorForJavaScript editor = BEING_EDITED.get(url); if (editor == null) { - editor = new ScriptEditorForJavaScript( - context, url); + editor = new ScriptEditorForJavaScript(context, url); BEING_EDITED.put(url, editor); } } @@ -200,8 +196,6 @@ public class ScriptEditorForJavaScript implements ScriptEditor { initUI(); Scriptable scope = getScope(context); this.rhinoWindow.openFile(url, scope, new closeHandler(url)); - - this.scriptURL = url; } @@ -293,8 +287,7 @@ public class ScriptEditorForJavaScript implements ScriptEditor { Scriptable jsCtxt = Context.toObject(xsctxt, scope); scope.put("XSCRIPTCONTEXT", scope, jsCtxt); - Scriptable jsArgs = Context.toObject( - new Object[0], scope); + Scriptable jsArgs = Context.toObject(new Object[0], scope); scope.put("ARGUMENTS", scope, jsArgs); Context.exit(); @@ -302,14 +295,17 @@ public class ScriptEditorForJavaScript implements ScriptEditor { } private class closeHandler implements Runnable { + private URL url; + private closeHandler(URL url) { this.url = url; } + public void run() { synchronized (BEING_EDITED) { BEING_EDITED.remove(this.url); } } } -} +}
\ No newline at end of file diff --git a/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptProviderForJavaScript.java b/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptProviderForJavaScript.java index e837818c95bd..c347e8097b19 100644 --- a/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptProviderForJavaScript.java +++ b/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptProviderForJavaScript.java @@ -52,15 +52,16 @@ import org.mozilla.javascript.JavaScriptException; import org.mozilla.javascript.Scriptable; public class ScriptProviderForJavaScript { + public static class ScriptProviderForJavaScript_2 extends ScriptProvider { + public ScriptProviderForJavaScript_2(XComponentContext ctx) { super(ctx, "JavaScript"); } @Override public XScript getScript(/*IN*/String scriptURI) - throws com.sun.star.uno.RuntimeException, - ScriptFrameworkErrorException { + throws com.sun.star.uno.RuntimeException, ScriptFrameworkErrorException { ScriptMetaData scriptData = null; try { @@ -69,9 +70,9 @@ public class ScriptProviderForJavaScript { m_xInvocContext); return script; } catch (com.sun.star.uno.RuntimeException re) { - throw new ScriptFrameworkErrorException("Failed to create script object: " + - re.getMessage(), - null, scriptData.getLanguageName(), language, ScriptFrameworkErrorType.UNKNOWN); + throw new ScriptFrameworkErrorException( + "Failed to create script object: " + re.getMessage(), + null, scriptData.getLanguageName(), language, ScriptFrameworkErrorType.UNKNOWN); } } @@ -99,23 +100,27 @@ public class ScriptProviderForJavaScript { * @see com.sun.star.comp.loader.JavaLoader */ public static XSingleServiceFactory __getServiceFactory(String implName, - XMultiServiceFactory multiFactory, - XRegistryKey regKey) { + XMultiServiceFactory multiFactory, XRegistryKey regKey) { + XSingleServiceFactory xSingleServiceFactory = null; if (implName.equals( ScriptProviderForJavaScript.ScriptProviderForJavaScript_2.class.getName())) { - xSingleServiceFactory = FactoryHelper.getServiceFactory( - ScriptProviderForJavaScript.ScriptProviderForJavaScript_2.class, - "com.sun.star.script.provider.ScriptProviderForJavaScript", - multiFactory, - regKey); + + xSingleServiceFactory = + FactoryHelper.getServiceFactory( + ScriptProviderForJavaScript.ScriptProviderForJavaScript_2.class, + "com.sun.star.script.provider.ScriptProviderForJavaScript", + multiFactory, regKey); + } return xSingleServiceFactory; } } + class ScriptImpl implements XScript { + private ScriptMetaData metaData; private XComponentContext m_xContext; private XMultiComponentFactory m_xMultiComponentFactory; @@ -125,6 +130,7 @@ class ScriptImpl implements XScript { ScriptImpl(XComponentContext ctx, ScriptMetaData metaData, XModel xModel, XScriptInvocationContext xInvocContext) throws com.sun.star.uno.RuntimeException { + this.metaData = metaData; this.m_xContext = ctx; this.m_xModel = xModel; @@ -167,19 +173,16 @@ class ScriptImpl implements XScript { * ScriptErrorRaisedException or * ScriptExceptionRaisedException */ - public Object invoke( /*IN*/Object[] params, /*OUT*/short[][] aOutParamIndex, /*OUT*/Object[][] aOutParam) - throws ScriptFrameworkErrorException, InvocationTargetException { + // Initialise the out parameters - not used at the moment aOutParamIndex[0] = new short[0]; aOutParam[0] = new Object[0]; - - ClassLoader cl = null; URL sourceUrl = null; @@ -198,9 +201,9 @@ class ScriptImpl implements XScript { try { String editorURL = sourceUrl.toString(); Object result = null; + ScriptEditorForJavaScript editor = - ScriptEditorForJavaScript.getEditor( - metaData.getSourceURL()); + ScriptEditorForJavaScript.getEditor(metaData.getSourceURL()); if (editor != null) { editorURL = editor.getURL(); @@ -252,22 +255,24 @@ class ScriptImpl implements XScript { */ ImporterTopLevel scope = new ImporterTopLevel(ctxt); - Scriptable jsCtxt = Context.toObject( - ScriptContext.createContext( - m_xModel, m_xInvocContext, m_xContext, - m_xMultiComponentFactory), scope); + Scriptable jsCtxt = + Context.toObject( + ScriptContext.createContext( + m_xModel, m_xInvocContext, m_xContext, + m_xMultiComponentFactory), + scope); + scope.put("XSCRIPTCONTEXT", scope, jsCtxt); Scriptable jsArgs = Context.toObject(params, scope); scope.put("ARGUMENTS", scope, jsArgs); - result = ctxt.evaluateString(scope, - source, "<stdin>", 1, null); + result = ctxt.evaluateString(scope, source, "<stdin>", 1, null); result = Context.toString(result); return result; } catch (JavaScriptException jse) { - LogUtils.DEBUG("Caught JavaScriptException exception for JavaScript type = " + - jse.getClass()); + LogUtils.DEBUG("Caught JavaScriptException exception for JavaScript type = " + + jse.getClass()); String message = jse.getMessage(); Object wrap = jse.getValue(); LogUtils.DEBUG("\t message " + message); @@ -286,15 +291,14 @@ class ScriptImpl implements XScript { LogUtils.DEBUG("\t language " + se.language); LogUtils.DEBUG("\t scriptName " + se.scriptName); raiseEditor(se.lineNum); - throw new InvocationTargetException("JavaScript uncaught exception" + - metaData.getLanguageName(), null, se); + throw new InvocationTargetException( + "JavaScript uncaught exception" + metaData.getLanguageName(), null, se); } catch (Exception ex) { LogUtils.DEBUG("Caught Exception " + ex); LogUtils.DEBUG("rethrowing as ScriptFramework error"); throw new ScriptFrameworkErrorException( - ex.getMessage(), null, - metaData.getLanguageName(), metaData.getLanguage(), - ScriptFrameworkErrorType.UNKNOWN); + ex.getMessage(), null, metaData.getLanguageName(), + metaData.getLanguage(), ScriptFrameworkErrorType.UNKNOWN); } finally { if (ctxt != null) { Context.exit(); @@ -305,14 +309,18 @@ class ScriptImpl implements XScript { private void raiseEditor(int lineNum) { try { URL sourceUrl = metaData.getSourceURL(); - ScriptEditorForJavaScript editor = ScriptEditorForJavaScript.getEditor( - sourceUrl); + + ScriptEditorForJavaScript editor = + ScriptEditorForJavaScript.getEditor(sourceUrl); if (editor == null) { editor = ScriptEditorForJavaScript.getEditor(); + editor.edit( ScriptContext.createContext(m_xModel, m_xInvocContext, - m_xContext, m_xMultiComponentFactory), metaData); + m_xContext, m_xMultiComponentFactory), + metaData); + editor = ScriptEditorForJavaScript.getEditor(sourceUrl); } @@ -324,5 +332,4 @@ class ScriptImpl implements XScript { } catch (Exception ignore) { } } -} - +}
\ No newline at end of file diff --git a/scripting/java/org/openoffice/netbeans/modules/office/actions/DeployParcelAction.java b/scripting/java/org/openoffice/netbeans/modules/office/actions/DeployParcelAction.java index e662faea400f..04a17a8976fc 100644 --- a/scripting/java/org/openoffice/netbeans/modules/office/actions/DeployParcelAction.java +++ b/scripting/java/org/openoffice/netbeans/modules/office/actions/DeployParcelAction.java @@ -216,10 +216,10 @@ public class DeployParcelAction extends CookieAction implements chooser.setFileFilter(new FileFilter() { public boolean accept(File file) { return file.isDirectory() || - file.getName().endsWith(".sxw") || - file.getName().endsWith(".sxc") || - file.getName().endsWith(".sxd") || - file.getName().endsWith(".sxi"); + file.getName().endsWith(".sxw") || + file.getName().endsWith(".sxc") || + file.getName().endsWith(".sxd") || + file.getName().endsWith(".sxi"); } public String getDescription() { |