From 6f42a714399f4d0c46dad95c7c11bcd513c27eaa Mon Sep 17 00:00:00 2001 From: Robert Antoni Buj i Gelonch Date: Thu, 25 Sep 2014 19:41:12 +0200 Subject: scripting: Format_java_code.sh initial run Conflicts: scripting/java/com/sun/star/script/framework/io/UCBStreamHandler.java Change-Id: I09b94d8c96dfbaf498bd93a0088feb80a9e4afb6 --- .../script/framework/security/SecurityDialog.java | 460 ++++++++------- .../script/framework/browse/DialogFactory.java | 135 ++--- .../script/framework/browse/ParcelBrowseNode.java | 215 +++---- .../framework/browse/PkgProviderBrowseNode.java | 19 +- .../framework/browse/ProviderBrowseNode.java | 154 +++--- .../script/framework/browse/ScriptBrowseNode.java | 187 +++---- .../framework/container/DeployedUnoPackagesDB.java | 99 ++-- .../star/script/framework/container/Parcel.java | 265 +++++---- .../framework/container/ParcelContainer.java | 616 ++++++++++----------- .../framework/container/ParcelDescriptor.java | 87 +-- .../framework/container/ParsedScriptUri.java | 3 +- .../script/framework/container/ScriptEntry.java | 29 +- .../script/framework/container/ScriptMetaData.java | 317 +++++------ .../framework/container/UnoPkgContainer.java | 418 +++++++------- .../framework/container/XMLParserFactory.java | 40 +- .../star/script/framework/io/UCBStreamHandler.java | 143 +++-- .../star/script/framework/io/XInputStreamImpl.java | 78 ++- .../script/framework/io/XInputStreamWrapper.java | 38 +- .../script/framework/io/XOutputStreamWrapper.java | 156 +++--- .../star/script/framework/io/XStorageHelper.java | 207 +++---- .../sun/star/script/framework/log/LogUtils.java | 44 +- .../framework/provider/ClassLoaderFactory.java | 23 +- .../framework/provider/EditorScriptContext.java | 28 +- .../provider/NoSuitableClassLoaderException.java | 9 +- .../star/script/framework/provider/PathUtils.java | 59 +- .../script/framework/provider/ScriptContext.java | 68 ++- .../script/framework/provider/ScriptEditor.java | 5 +- .../script/framework/provider/ScriptProvider.java | 549 +++++++++--------- .../script/framework/provider/SwingInvocation.java | 6 +- .../provider/beanshell/PlainSourceView.java | 15 +- .../beanshell/ScriptEditorForBeanShell.java | 179 +++--- .../beanshell/ScriptProviderForBeanShell.java | 442 +++++++-------- .../provider/beanshell/ScriptSourceModel.java | 96 ++-- .../script/framework/provider/java/Resolver.java | 2 +- .../framework/provider/java/ScriptDescriptor.java | 85 ++- .../provider/java/ScriptProviderForJava.java | 417 +++++++------- .../framework/provider/java/ScriptProxy.java | 16 +- .../framework/provider/java/StrictResolver.java | 72 +-- .../javascript/ScriptEditorForJavaScript.java | 154 +++--- .../javascript/ScriptProviderForJavaScript.java | 417 +++++++------- .../openoffice/idesupport/CommandLineTools.java | 92 ++- .../org/openoffice/idesupport/ExtensionFinder.java | 7 +- .../java/org/openoffice/idesupport/JavaFinder.java | 71 ++- .../org/openoffice/idesupport/LocalOffice.java | 12 +- .../org/openoffice/idesupport/OfficeDocument.java | 38 +- .../openoffice/idesupport/OfficeInstallation.java | 3 +- .../org/openoffice/idesupport/SVersionRCFile.java | 63 +-- .../idesupport/filter/BinaryOnlyFilter.java | 1 + .../idesupport/filter/ExceptParcelFilter.java | 4 +- .../idesupport/localoffice/LocalOfficeImpl.java | 52 +- .../openoffice/idesupport/ui/ConfigurePanel.java | 43 +- .../org/openoffice/idesupport/ui/ScriptPanel.java | 10 +- .../org/openoffice/idesupport/xml/Manifest.java | 17 +- .../openoffice/idesupport/zip/ParcelZipper.java | 41 +- .../org/openoffice/netbeans/editor/JavaKit.java | 21 +- .../netbeans/editor/NetBeansSourceView.java | 31 +- .../modules/office/actions/BuildParcelAction.java | 2 +- .../office/actions/ConfigureParcelAction.java | 6 +- .../modules/office/actions/DeployParcelAction.java | 33 +- .../office/actions/MountDocumentAction.java | 34 +- .../modules/office/actions/MountParcelAction.java | 34 +- .../office/actions/OfficeDocumentCookie.java | 3 +- .../office/actions/OfficeDocumentSupport.java | 25 +- .../modules/office/actions/ParcelCookie.java | 3 +- .../actions/ParcelDescriptorEditorSupport.java | 14 +- .../actions/ParcelDescriptorParserCookie.java | 3 +- .../actions/ParcelDescriptorParserSupport.java | 23 +- .../modules/office/actions/ParcelFolderCookie.java | 3 +- .../office/actions/ParcelFolderSupport.java | 76 ++- .../modules/office/actions/ParcelSupport.java | 56 +- .../office/filesystem/OpenOfficeDocFileSystem.java | 546 +++++++++--------- .../OpenOfficeDocFileSystemBeanInfo.java | 44 +- .../office/loader/OfficeDocumentDataLoader.java | 33 +- .../office/loader/OfficeDocumentDataNode.java | 15 +- .../office/loader/OfficeDocumentDataObject.java | 3 +- .../office/loader/ParcelContentsFolder.java | 36 +- .../loader/ParcelContentsFolderDataLoader.java | 15 +- .../modules/office/loader/ParcelDataLoader.java | 23 +- .../modules/office/loader/ParcelDataNode.java | 10 +- .../modules/office/loader/ParcelDataObject.java | 3 +- .../office/loader/ParcelDescriptorDataLoader.java | 25 +- .../office/loader/ParcelDescriptorDataObject.java | 5 +- .../modules/office/loader/ParcelFolder.java | 208 +++---- .../office/loader/ParcelFolderDataLoader.java | 35 +- .../office/nodes/OfficeDocumentChildren.java | 14 +- .../office/nodes/ParcelDescriptorChildren.java | 5 +- .../netbeans/modules/office/nodes/ScriptNode.java | 15 +- .../modules/office/options/OfficeSettings.java | 3 +- .../office/options/OfficeSettingsBeanInfo.java | 57 +- .../modules/office/utils/FrameworkJarChecker.java | 48 +- .../modules/office/utils/ManifestParser.java | 10 +- .../netbeans/modules/office/utils/NagDialog.java | 22 +- .../modules/office/utils/OfficeModule.java | 11 +- .../modules/office/utils/PackageRemover.java | 17 +- .../netbeans/modules/office/utils/ZipMounter.java | 24 +- .../office/wizard/InstallationPathDescriptor.java | 3 +- .../office/wizard/InstallationPathIterator.java | 14 +- .../modules/office/wizard/JavaScriptIterator.java | 37 +- .../office/wizard/ParcelContentsIterator.java | 25 +- .../office/wizard/ParcelPropertiesPanel.java | 1 + .../office/wizard/ParcelPropertiesVisualPanel.java | 17 +- .../modules/office/wizard/SelectPathPanel.java | 10 +- .../office/wizard/SelectPathVisualPanel.java | 21 +- 103 files changed, 4049 insertions(+), 4479 deletions(-) (limited to 'scripting/java') 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 a1088260f470..e789d86dd647 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 @@ -49,23 +49,29 @@ import com.sun.star.uno.XComponentContext; import com.sun.star.script.framework.log.LogUtils; -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"; + 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 _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 _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 _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 _checkBoxString = + "Add this directory to the list of secure paths: "; private static final String _label5Name = "Label5"; private static final String _title = "Run Macro"; @@ -120,9 +126,9 @@ XInitialization { private boolean checkBoxDialog; private short _checkBoxState = 0; - private boolean extraPathLine=false; - private String checkBoxPath=""; - private String checkBoxPath2=""; + private boolean extraPathLine = false; + private String checkBoxPath = ""; + private String checkBoxPath2 = ""; private static final int lineWrapLength = 21; private static final int lineWrapH = 12; private String _pushed = _doNotRunButtonName; @@ -130,96 +136,89 @@ XInitialization { private XComponentContext _xComponentContext; private XDialog _xDialog; - public SecurityDialog( XComponentContext xComponentContext ) - { - LogUtils.DEBUG( "SecurityDialog ctor" ); + public SecurityDialog(XComponentContext xComponentContext) { + LogUtils.DEBUG("SecurityDialog ctor"); _xComponentContext = xComponentContext; } - public void initialize( Object[] args ) throws RuntimeException - { - LogUtils.DEBUG( "SecurityDialog init" ); + public void initialize(Object[] args) throws RuntimeException { + LogUtils.DEBUG("SecurityDialog init"); + // figure out if we need a checkbox - if ( args.length == 1 && AnyConverter.isString( args[0] ) ) - { + if (args.length == 1 && AnyConverter.isString(args[0])) { //check args is a path // set checkBoxPath with the arg - LogUtils.DEBUG( "checkbox" ); - try - { - checkBoxPath = AnyConverter.toString( args[0] ); - } - catch ( IllegalArgumentException e ) - { - throw new RuntimeException( "SecurityDialog::initialize: " + e.getMessage() ); + LogUtils.DEBUG("checkbox"); + + try { + checkBoxPath = AnyConverter.toString(args[0]); + } catch (IllegalArgumentException e) { + throw new RuntimeException("SecurityDialog::initialize: " + e.getMessage()); } - LogUtils.DEBUG( "path: " + checkBoxPath ); + + LogUtils.DEBUG("path: " + checkBoxPath); checkBoxDialog = true; - if( checkBoxPath.length() > lineWrapLength ) - { + + if (checkBoxPath.length() > lineWrapLength) { extraPathLine = true; cbIncrH += lineWrapH; - checkBoxPath2 = checkBoxPath.substring( lineWrapLength ); - checkBoxPath = checkBoxPath.substring( 0, lineWrapLength ); + checkBoxPath2 = checkBoxPath.substring(lineWrapLength); + checkBoxPath = checkBoxPath.substring(0, lineWrapLength); } - } - else - { - LogUtils.DEBUG( "no checkbox: # of args=" + - args.length ); + } else { + LogUtils.DEBUG("no checkbox: # of args=" + + args.length); cbIncrW = 0; cbIncrH = 0; checkBoxDialog = false; } // now try and create the dialog - try - { + try { _xDialog = createDialog(); - } - catch ( com.sun.star.uno.Exception e ) - { - LogUtils.DEBUG( "Couldn't create dialog" ); - LogUtils.DEBUG( "uno message: " + e.getMessage()); - throw new RuntimeException( e.getMessage() ); - } - catch ( Exception e ) - { - LogUtils.DEBUG( "Couldn't create dialog" ); - LogUtils.DEBUG( "message: " + e.getMessage()); - throw new RuntimeException( e.getMessage() ); + } catch (com.sun.star.uno.Exception e) { + LogUtils.DEBUG("Couldn't create dialog"); + LogUtils.DEBUG("uno message: " + e.getMessage()); + throw new RuntimeException(e.getMessage()); + } catch (Exception e) { + LogUtils.DEBUG("Couldn't create dialog"); + LogUtils.DEBUG("message: " + e.getMessage()); + throw new RuntimeException(e.getMessage()); } } // static component operations - 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( SecurityDialog.class.getName() ) ) { + + if (implName.equals(SecurityDialog.class.getName())) { xSingleServiceFactory = FactoryHelper.getServiceFactory( - SecurityDialog.class, SecurityDialog.__serviceName, multiFactory, regKey ); + SecurityDialog.class, SecurityDialog.__serviceName, multiFactory, regKey); } + return xSingleServiceFactory; } // XServiceInfo - public String getImplementationName( ) { + public String getImplementationName() { return getClass().getName(); } // XServiceInfo - public boolean supportsService( /*IN*/String serviceName ) { - if ( serviceName.equals( __serviceName)) + public boolean supportsService(/*IN*/String serviceName) { + if (serviceName.equals(__serviceName)) return true; + return false; } // XServiceInfo - public String[] getSupportedServiceNames( ) { - String[] retValue= new String[0]; + public String[] getSupportedServiceNames() { + String[] retValue = new String[0]; retValue[0] = __serviceName; return retValue; } @@ -230,299 +229,292 @@ XInitialization { private XDialog createDialog() throws com.sun.star.uno.Exception { // get the service manager from the component context - XMultiComponentFactory xMultiComponentFactory = _xComponentContext.getServiceManager(); + XMultiComponentFactory xMultiComponentFactory = + _xComponentContext.getServiceManager(); // create the dialog model and set the properties Object dialogModel = xMultiComponentFactory.createInstanceWithContext( - "com.sun.star.awt.UnoControlDialogModel", _xComponentContext ); + "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 )); - xPSetDialog.setPropertyValue( "Height", Integer.valueOf( dialogH+cbIncrH )); - xPSetDialog.setPropertyValue( "Title", _title ); + XPropertySet.class, dialogModel); + xPSetDialog.setPropertyValue("PositionX", Integer.valueOf(dialogX)); + xPSetDialog.setPropertyValue("PositionY", Integer.valueOf(dialogY)); + xPSetDialog.setPropertyValue("Width", Integer.valueOf(dialogW + cbIncrW)); + xPSetDialog.setPropertyValue("Height", Integer.valueOf(dialogH + cbIncrH)); + xPSetDialog.setPropertyValue("Title", _title); // get the service manager from the dialog model XMultiServiceFactory xMultiServiceFactory = UnoRuntime.queryInterface( - XMultiServiceFactory.class, dialogModel ); + XMultiServiceFactory.class, dialogModel); // create the Run Macro button model and set the properties Object runButtonModel = xMultiServiceFactory.createInstance( - "com.sun.star.awt.UnoControlButtonModel" ); + "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( "Width", Integer.valueOf( runButtonW )); - xPSetButton.setPropertyValue( "Height", Integer.valueOf( runButtonH )); - xPSetButton.setPropertyValue( "Name", _runButtonName ); - xPSetButton.setPropertyValue( "TabIndex", Short.valueOf( (short)1 ) ); - xPSetButton.setPropertyValue( "Label", _runMacro ); + 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("Width", Integer.valueOf(runButtonW)); + xPSetButton.setPropertyValue("Height", Integer.valueOf(runButtonH)); + xPSetButton.setPropertyValue("Name", _runButtonName); + xPSetButton.setPropertyValue("TabIndex", Short.valueOf((short)1)); + xPSetButton.setPropertyValue("Label", _runMacro); // create the Dont Run Macro button model and set the properties Object doNotRunButtonModel = xMultiServiceFactory.createInstance( - "com.sun.star.awt.UnoControlButtonModel" ); + "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( "Width", Integer.valueOf( doNotRunButtonW )); - xPSetButton.setPropertyValue( "Height", Integer.valueOf( doNotRunButtonH )); - xPSetButton.setPropertyValue( "Name", _doNotRunButtonName ); - xPSetButton.setPropertyValue( "TabIndex", Short.valueOf( (short)0 ) ); - xPSetButton.setPropertyValue( "Label", _doNotRunMacro ); + 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("Width", Integer.valueOf(doNotRunButtonW)); + xPSetButton.setPropertyValue("Height", Integer.valueOf(doNotRunButtonH)); + xPSetButton.setPropertyValue("Name", _doNotRunButtonName); + xPSetButton.setPropertyValue("TabIndex", Short.valueOf((short)0)); + xPSetButton.setPropertyValue("Label", _doNotRunMacro); // insert the control models into the dialog model XNameContainer xNameCont = UnoRuntime.queryInterface( - XNameContainer.class, dialogModel ); - xNameCont.insertByName( _runButtonName, runButtonModel ); - xNameCont.insertByName( _doNotRunButtonName, doNotRunButtonModel ); + XNameContainer.class, dialogModel); + xNameCont.insertByName(_runButtonName, runButtonModel); + xNameCont.insertByName(_doNotRunButtonName, doNotRunButtonModel); - if ( checkBoxDialog ) - { + if (checkBoxDialog) { LogUtils.DEBUG("creating label & checkbox"); // create the label model and set the properties Object label2Model = xMultiServiceFactory.createInstance( - "com.sun.star.awt.UnoControlFixedTextModel" ); + "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 )); - xPSetLabel.setPropertyValue( "Height", Integer.valueOf( label2H )); - xPSetLabel.setPropertyValue( "Name", _label2Name ); - xPSetLabel.setPropertyValue( "TabIndex", Short.valueOf( (short)1 ) ); - xPSetLabel.setPropertyValue( "Label", _label2String ); + XPropertySet.class, label2Model); + xPSetLabel.setPropertyValue("PositionX", Integer.valueOf(label2X)); + xPSetLabel.setPropertyValue("PositionY", Integer.valueOf(label2Y)); + xPSetLabel.setPropertyValue("Width", Integer.valueOf(label2W)); + xPSetLabel.setPropertyValue("Height", Integer.valueOf(label2H)); + xPSetLabel.setPropertyValue("Name", _label2Name); + xPSetLabel.setPropertyValue("TabIndex", Short.valueOf((short)1)); + xPSetLabel.setPropertyValue("Label", _label2String); // create the label model and set the properties Object label3Model = xMultiServiceFactory.createInstance( - "com.sun.star.awt.UnoControlFixedTextModel" ); + "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 )); - xPSetLabel3.setPropertyValue( "Height", Integer.valueOf( label3H )); - xPSetLabel3.setPropertyValue( "Name", _label3Name ); - xPSetLabel3.setPropertyValue( "TabIndex", Short.valueOf( (short)1 ) ); - xPSetLabel3.setPropertyValue( "Label", _label3String ); + XPropertySet.class, label3Model); + xPSetLabel3.setPropertyValue("PositionX", Integer.valueOf(label3X)); + xPSetLabel3.setPropertyValue("PositionY", Integer.valueOf(label3Y)); + xPSetLabel3.setPropertyValue("Width", Integer.valueOf(label3W)); + xPSetLabel3.setPropertyValue("Height", Integer.valueOf(label3H)); + xPSetLabel3.setPropertyValue("Name", _label3Name); + xPSetLabel3.setPropertyValue("TabIndex", Short.valueOf((short)1)); + xPSetLabel3.setPropertyValue("Label", _label3String); // create the label model and set the properties Object label4Model = xMultiServiceFactory.createInstance( - "com.sun.star.awt.UnoControlFixedTextModel" ); + "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 )); - xPSetLabel4.setPropertyValue( "Height", Integer.valueOf( label4H )); - xPSetLabel4.setPropertyValue( "Name", _label4Name ); - xPSetLabel4.setPropertyValue( "TabIndex", Short.valueOf( (short)1 ) ); - xPSetLabel4.setPropertyValue( "Label", _label4String ); + XPropertySet.class, label4Model); + xPSetLabel4.setPropertyValue("PositionX", Integer.valueOf(label4X)); + xPSetLabel4.setPropertyValue("PositionY", Integer.valueOf(label4Y)); + xPSetLabel4.setPropertyValue("Width", Integer.valueOf(label4W)); + xPSetLabel4.setPropertyValue("Height", Integer.valueOf(label4H)); + xPSetLabel4.setPropertyValue("Name", _label4Name); + xPSetLabel4.setPropertyValue("TabIndex", Short.valueOf((short)1)); + xPSetLabel4.setPropertyValue("Label", _label4String); // create the checkbox model and set the properties Object checkBoxModel = xMultiServiceFactory.createInstance( - "com.sun.star.awt.UnoControlCheckBoxModel" ); + "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 )); - xPSetCheckBox.setPropertyValue( "Height", Integer.valueOf( checkBoxH )); - xPSetCheckBox.setPropertyValue( "State", Short.valueOf((short)0) ); - xPSetCheckBox.setPropertyValue( "Name", _checkBoxName ); - xPSetCheckBox.setPropertyValue( "TabIndex", Short.valueOf( (short)1 ) ); - xPSetCheckBox.setPropertyValue( "Label", _checkBoxString +checkBoxPath ); + XPropertySet.class, checkBoxModel); + xPSetCheckBox.setPropertyValue("PositionX", Integer.valueOf(checkBoxX)); + xPSetCheckBox.setPropertyValue("PositionY", Integer.valueOf(checkBoxY)); + xPSetCheckBox.setPropertyValue("Width", Integer.valueOf(checkBoxW)); + xPSetCheckBox.setPropertyValue("Height", Integer.valueOf(checkBoxH)); + xPSetCheckBox.setPropertyValue("State", Short.valueOf((short)0)); + xPSetCheckBox.setPropertyValue("Name", _checkBoxName); + xPSetCheckBox.setPropertyValue("TabIndex", Short.valueOf((short)1)); + xPSetCheckBox.setPropertyValue("Label", _checkBoxString + checkBoxPath); // insert the control models into the dialog model - xNameCont.insertByName( _label2Name, label2Model ); - xNameCont.insertByName( _label3Name, label3Model ); - xNameCont.insertByName( _label4Name, label4Model ); - 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 ); - xPSetLabel5.setPropertyValue( "PositionX", Integer.valueOf( label5X )); - xPSetLabel5.setPropertyValue( "PositionY", Integer.valueOf( label5Y )); - xPSetLabel5.setPropertyValue( "Width", Integer.valueOf( label5W )); - xPSetLabel5.setPropertyValue( "Height", Integer.valueOf( label5H )); - xPSetLabel5.setPropertyValue( "Name", _label5Name ); - xPSetLabel5.setPropertyValue( "TabIndex", Short.valueOf( (short)1 ) ); - xPSetLabel5.setPropertyValue( "Label", checkBoxPath2 ); - xNameCont.insertByName( _label5Name, label5Model ); + xNameCont.insertByName(_label2Name, label2Model); + xNameCont.insertByName(_label3Name, label3Model); + xNameCont.insertByName(_label4Name, label4Model); + 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); + xPSetLabel5.setPropertyValue("PositionX", Integer.valueOf(label5X)); + xPSetLabel5.setPropertyValue("PositionY", Integer.valueOf(label5Y)); + xPSetLabel5.setPropertyValue("Width", Integer.valueOf(label5W)); + xPSetLabel5.setPropertyValue("Height", Integer.valueOf(label5H)); + xPSetLabel5.setPropertyValue("Name", _label5Name); + xPSetLabel5.setPropertyValue("TabIndex", Short.valueOf((short)1)); + xPSetLabel5.setPropertyValue("Label", checkBoxPath2); + xNameCont.insertByName(_label5Name, label5Model); } - } - else - { + } else { // create the label model and set the properties Object labelModel = xMultiServiceFactory.createInstance( - "com.sun.star.awt.UnoControlFixedTextModel" ); + "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 )); - xPSetLabel.setPropertyValue( "Height", Integer.valueOf( label1H )); - xPSetLabel.setPropertyValue( "Name", _label1Name ); - xPSetLabel.setPropertyValue( "TabIndex", Short.valueOf( (short)1 ) ); - xPSetLabel.setPropertyValue( "Label", _label1String ); + XPropertySet.class, labelModel); + xPSetLabel.setPropertyValue("PositionX", Integer.valueOf(label1X)); + xPSetLabel.setPropertyValue("PositionY", Integer.valueOf(label1Y)); + xPSetLabel.setPropertyValue("Width", Integer.valueOf(label1W)); + xPSetLabel.setPropertyValue("Height", Integer.valueOf(label1H)); + xPSetLabel.setPropertyValue("Name", _label1Name); + xPSetLabel.setPropertyValue("TabIndex", Short.valueOf((short)1)); + xPSetLabel.setPropertyValue("Label", _label1String); // insert the control models into the dialog model - xNameCont.insertByName( _label1Name, labelModel ); + xNameCont.insertByName(_label1Name, labelModel); } // create the dialog control and set the model Object dialog = xMultiComponentFactory.createInstanceWithContext( - "com.sun.star.awt.UnoControlDialog", _xComponentContext ); + "com.sun.star.awt.UnoControlDialog", _xComponentContext); XControl xControl = UnoRuntime.queryInterface( - XControl.class, dialog ); + XControl.class, dialog); XControlModel xControlModel = UnoRuntime.queryInterface( - XControlModel.class, dialogModel ); - xControl.setModel( xControlModel ); + XControlModel.class, dialogModel); + xControl.setModel(xControlModel); // add an action listener to the button control XControlContainer xControlCont = UnoRuntime.queryInterface( - XControlContainer.class, dialog ); + XControlContainer.class, dialog); // Add to yes button - Object objectButton = xControlCont.getControl( _runButtonName ); + Object objectButton = xControlCont.getControl(_runButtonName); XButton xButton = UnoRuntime.queryInterface( - XButton.class, objectButton ); - xButton.addActionListener( new ActionListenerImpl( _runButtonName ) ); + XButton.class, objectButton); + xButton.addActionListener(new ActionListenerImpl(_runButtonName)); // add to no button - objectButton = xControlCont.getControl( _doNotRunButtonName ); + objectButton = xControlCont.getControl(_doNotRunButtonName); xButton = UnoRuntime.queryInterface( - XButton.class, objectButton ); - xButton.addActionListener( new ActionListenerImpl( _doNotRunButtonName ) ); + XButton.class, objectButton); + xButton.addActionListener(new ActionListenerImpl(_doNotRunButtonName)); - if ( checkBoxDialog ) - { + if (checkBoxDialog) { // add to checkbox - Object objectCheckBox = xControlCont.getControl( _checkBoxName ); + Object objectCheckBox = xControlCont.getControl(_checkBoxName); XCheckBox xCheckBox = UnoRuntime.queryInterface( - XCheckBox.class, objectCheckBox ); - xCheckBox.addItemListener(new ItemListenerImpl( xControlCont ) ); + XCheckBox.class, objectCheckBox); + xCheckBox.addItemListener(new ItemListenerImpl(xControlCont)); } // create a peer Object toolkit = xMultiComponentFactory.createInstanceWithContext( - "com.sun.star.awt.ExtToolkit", _xComponentContext ); + "com.sun.star.awt.ExtToolkit", _xComponentContext); XToolkit xToolkit = UnoRuntime.queryInterface( - XToolkit.class, toolkit ); + XToolkit.class, toolkit); XWindow xWindow = UnoRuntime.queryInterface( - XWindow.class, xControl ); - xWindow.setVisible( false ); - xControl.createPeer( xToolkit, null ); + XWindow.class, xControl); + xWindow.setVisible(false); + xControl.createPeer(xToolkit, null); // return the dialog XDialog xDialog = UnoRuntime.queryInterface( - XDialog.class, dialog ); + XDialog.class, dialog); return xDialog; } - public short execute() - { + public short execute() { short result = 0; _pushed = _doNotRunButtonName; - LogUtils.DEBUG("*DF* Before execute " ); + LogUtils.DEBUG("*DF* Before execute "); _xDialog.execute(); - LogUtils.DEBUG("*DF* After execute " ); + LogUtils.DEBUG("*DF* After execute "); - if ( _pushed.equals( _runButtonName ) ) - { + if (_pushed.equals(_runButtonName)) { result += 1; } - if ( _checkBoxState == 1 ) - { - result +=2; + + if (_checkBoxState == 1) { + result += 2; } + return result; } - public void endExecute() - { + public void endExecute() { _xDialog.endExecute(); } - public String getTitle() - { + public String getTitle() { return _xDialog.getTitle(); - } + } - public void setTitle( String Title ) - { - _xDialog.setTitle( Title ); - } + public void setTitle(String Title) { + _xDialog.setTitle(Title); + } - public void dispose () - { + public void dispose() { XComponent xComponent = UnoRuntime.queryInterface( - XComponent.class, _xDialog ); - xComponent.dispose(); - } + XComponent.class, _xDialog); + xComponent.dispose(); + } - public void addEventListener ( com.sun.star.lang.XEventListener xListener ) - { + public void addEventListener(com.sun.star.lang.XEventListener xListener) { XComponent xComponent = UnoRuntime.queryInterface( - XComponent.class, _xDialog ); - xComponent.addEventListener( xListener ); - } + XComponent.class, _xDialog); + xComponent.addEventListener(xListener); + } - public void removeEventListener ( com.sun.star.lang.XEventListener aListener ) - { + public void removeEventListener(com.sun.star.lang.XEventListener aListener) { XComponent xComponent = UnoRuntime.queryInterface( - XComponent.class, _xDialog ); - xComponent.removeEventListener( aListener ); - } + XComponent.class, _xDialog); + xComponent.removeEventListener(aListener); + } private class ActionListenerImpl implements com.sun.star.awt.XActionListener { private String _buttonName; - private ActionListenerImpl( String buttonName ) { + private ActionListenerImpl(String buttonName) { _buttonName = buttonName; } // XEventListener - public void disposing( EventObject eventObject ) { + public void disposing(EventObject eventObject) { } // XActionListener - public void actionPerformed( ActionEvent actionEvent ) { - _pushed = _buttonName; - LogUtils.DEBUG("** Button pushed ->" + _pushed ); + public void actionPerformed(ActionEvent actionEvent) { + _pushed = _buttonName; + LogUtils.DEBUG("** Button pushed ->" + _pushed); - _xDialog.endExecute(); + _xDialog.endExecute(); } } private class ItemListenerImpl implements com.sun.star.awt.XItemListener { private XCheckBox _xCheckBox; - private ItemListenerImpl( XControlContainer xControlCont ) { - Object objectCheckBox = xControlCont.getControl( _checkBoxName ); + private ItemListenerImpl(XControlContainer xControlCont) { + Object objectCheckBox = xControlCont.getControl(_checkBoxName); _xCheckBox = UnoRuntime.queryInterface( - XCheckBox.class, objectCheckBox ); + XCheckBox.class, objectCheckBox); } // XEventListener - public void disposing( EventObject eventObject ) { + public void disposing(EventObject eventObject) { _xCheckBox = null; } // XAdjustmentListener - public void itemStateChanged( ItemEvent itemEvent ) { - _checkBoxState = _xCheckBox.getState(); - LogUtils.DEBUG("** checkbox state ->" + _checkBoxState ); + public void itemStateChanged(ItemEvent itemEvent) { + _checkBoxState = _xCheckBox.getState(); + LogUtils.DEBUG("** checkbox state ->" + _checkBoxState); } } } 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 1708bdc60888..1883b0d2e05a 100644 --- a/scripting/java/com/sun/star/script/framework/browse/DialogFactory.java +++ b/scripting/java/com/sun/star/script/framework/browse/DialogFactory.java @@ -31,26 +31,20 @@ import com.sun.star.container.XNameContainer; import com.sun.star.awt.*; -public class DialogFactory -{ +public class DialogFactory { private static DialogFactory factory; private XComponentContext xComponentContext; // singleton - private DialogFactory(XComponentContext xComponentContext) - { + private DialogFactory(XComponentContext xComponentContext) { this.xComponentContext = xComponentContext; factory = this; - } - - public static void createDialogFactory(XComponentContext xComponentContext) - { - if (factory == null) - { - synchronized(DialogFactory.class) - { - if (factory == null) - { + } + + public static void createDialogFactory(XComponentContext xComponentContext) { + if (factory == null) { + synchronized (DialogFactory.class) { + if (factory == null) { factory = new DialogFactory(xComponentContext); } } @@ -58,65 +52,58 @@ public class DialogFactory } public static DialogFactory getDialogFactory() - throws java.lang.Exception - { - if (factory == null) - { + throws java.lang.Exception { + if (factory == null) { throw new java.lang.Exception("DialogFactory not initialized"); } + return factory; } - public String showInputDialog(String title, String prompt) - { + public String showInputDialog(String title, String prompt) { final XDialog xDialog; - try - { + + try { xDialog = createInputDialog(title, prompt); - } - catch (com.sun.star.uno.Exception e) - { + } catch (com.sun.star.uno.Exception e) { return null; } // 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.class, controls.getControl("Ok")); okButton.setActionCommand("Ok"); XButton cancelButton = UnoRuntime.queryInterface( - XButton.class, controls.getControl("Cancel")); + XButton.class, controls.getControl("Cancel")); cancelButton.setActionCommand("Cancel"); final XTextComponent textField = UnoRuntime.queryInterface( - XTextComponent.class, controls.getControl("NameField")); + XTextComponent.class, controls.getControl("NameField")); final ResultHolder resultHolder = new ResultHolder(); com.sun.star.awt.XActionListener listener = - new com.sun.star.awt.XActionListener() - { - public void actionPerformed(com.sun.star.awt.ActionEvent e) { - if (e.ActionCommand.equals("Cancel")) - { - resultHolder.setResult(null); - xDialog.endExecute(); - } - else - { - resultHolder.setResult(textField.getText()); - xDialog.endExecute(); - } + new com.sun.star.awt.XActionListener() { + public void actionPerformed(com.sun.star.awt.ActionEvent e) { + if (e.ActionCommand.equals("Cancel")) { + resultHolder.setResult(null); + xDialog.endExecute(); + } else { + resultHolder.setResult(textField.getText()); + xDialog.endExecute(); } + } - public void disposing(EventObject o) { - // does nothing - } - }; + public void disposing(EventObject o) { + // does nothing + } + }; okButton.addActionListener(listener); cancelButton.addActionListener(listener); @@ -127,8 +114,7 @@ public class DialogFactory } private void setDimensions(Object o, int x, int y, int width, int height) - throws com.sun.star.uno.Exception - { + throws com.sun.star.uno.Exception { XPropertySet props = UnoRuntime.queryInterface(XPropertySet.class, o); props.setPropertyValue("PositionX", Integer.valueOf(x)); @@ -138,15 +124,12 @@ public class DialogFactory } private XDialog createInputDialog(String title, String prompt) - throws com.sun.star.uno.Exception - { - if (title == null || title.length() == 0) - { + throws com.sun.star.uno.Exception { + if (title == null || title.length() == 0) { title = "Scripting Framework"; } - if (prompt == null || prompt.length() == 0) - { + if (prompt == null || prompt.length() == 0) { prompt = "Enter name"; } @@ -156,64 +139,65 @@ 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.class, dialogModel); props.setPropertyValue("Title", title); // get the service manager from the dialog model XMultiServiceFactory xMultiServiceFactory = UnoRuntime.queryInterface( - XMultiServiceFactory.class, dialogModel); + XMultiServiceFactory.class, dialogModel); // create the label model and set the properties Object label = xMultiServiceFactory.createInstance( - "com.sun.star.awt.UnoControlFixedTextModel"); + "com.sun.star.awt.UnoControlFixedTextModel"); setDimensions(label, 15, 5, 134, 12); XPropertySet labelProps = UnoRuntime.queryInterface( - XPropertySet.class, label); + XPropertySet.class, label); labelProps.setPropertyValue("Name", "PromptLabel"); labelProps.setPropertyValue("Label", prompt); // create the text field Object edit = xMultiServiceFactory.createInstance( - "com.sun.star.awt.UnoControlEditModel"); + "com.sun.star.awt.UnoControlEditModel"); setDimensions(edit, 15, 18, 134, 12); XPropertySet editProps = UnoRuntime.queryInterface( - XPropertySet.class, edit); + XPropertySet.class, edit); editProps.setPropertyValue("Name", "NameField"); // create the OK button Object okButtonModel = xMultiServiceFactory.createInstance( - "com.sun.star.awt.UnoControlButtonModel"); + "com.sun.star.awt.UnoControlButtonModel"); setDimensions(okButtonModel, 40, 39, 38, 15); XPropertySet buttonProps = UnoRuntime.queryInterface( - XPropertySet.class, okButtonModel); + XPropertySet.class, okButtonModel); buttonProps.setPropertyValue("Name", "Ok"); buttonProps.setPropertyValue("Label", "Ok"); // create the Cancel button Object cancelButtonModel = xMultiServiceFactory.createInstance( - "com.sun.star.awt.UnoControlButtonModel"); + "com.sun.star.awt.UnoControlButtonModel"); setDimensions(cancelButtonModel, 83, 39, 38, 15); buttonProps = UnoRuntime.queryInterface( - XPropertySet.class, cancelButtonModel); + 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); @@ -222,20 +206,21 @@ public class DialogFactory // create the dialog control and set the model Object dialog = xMultiComponentFactory.createInstanceWithContext( - "com.sun.star.awt.UnoControlDialog", xComponentContext); + "com.sun.star.awt.UnoControlDialog", xComponentContext); XControl xControl = UnoRuntime.queryInterface( - XControl.class, dialog); + 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); + "com.sun.star.awt.ExtToolkit", xComponentContext); XToolkit xToolkit = UnoRuntime.queryInterface( - XToolkit.class, toolkit); + XToolkit.class, toolkit); XWindow xWindow = UnoRuntime.queryInterface( - XWindow.class, xControl); + XWindow.class, xControl); xWindow.setVisible(false); xControl.createPeer(xToolkit, null); @@ -245,13 +230,11 @@ public class DialogFactory private static class ResultHolder { private Object result = null; - public Object getResult() - { + public Object getResult() { return result; } - public void setResult(Object result) - { + public void setResult(Object result) { this.result = result; } } 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 a2e2423ffd56..0e4f2bdea05e 100644 --- a/scripting/java/com/sun/star/script/framework/browse/ParcelBrowseNode.java +++ b/scripting/java/com/sun/star/script/framework/browse/ParcelBrowseNode.java @@ -50,8 +50,7 @@ import java.util.*; import javax.swing.JOptionPane; public class ParcelBrowseNode extends PropertySet - implements XBrowseNode, XInvocation -{ + implements XBrowseNode, XInvocation { private ScriptProvider provider; private Collection browsenodes; private ParcelContainer container; @@ -61,46 +60,43 @@ public class ParcelBrowseNode extends PropertySet - public ParcelBrowseNode( ScriptProvider provider, ParcelContainer container, String parcelName ) { + public ParcelBrowseNode(ScriptProvider provider, ParcelContainer container, + String parcelName) { this.provider = provider; this.container = container; // TODO decide whether exception is propagated out or not - try - { - this.parcel = (Parcel)this.container.getByName( parcelName ); - } - catch ( Exception e ) - { + try { + this.parcel = (Parcel)this.container.getByName(parcelName); + } catch (Exception e) { - LogUtils.DEBUG("** Exception: " + e ); + LogUtils.DEBUG("** Exception: " + e); LogUtils.DEBUG(" ** Failed to get parcel named " + - parcelName + " from container" ); + parcelName + " from container"); } + registerProperty("Deletable", new Type(boolean.class), - (short)0, "deletable"); + (short)0, "deletable"); registerProperty("Editable", new Type(boolean.class), - (short)0, "editable"); + (short)0, "editable"); registerProperty("Creatable", new Type(boolean.class), - (short)0, "creatable"); + (short)0, "creatable"); registerProperty("Renamable", new Type(boolean.class), - (short)0, "renamable"); + (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 ) ); - } - catch ( com.sun.star.uno.Exception e ) - { + + try { + 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 ); - LogUtils.DEBUG( LogUtils.getTrace( e ) ); + LogUtils.DEBUG("Caught exception creating ParcelBrowseNode " + e); + LogUtils.DEBUG(LogUtils.getTrace(e)); } } @@ -110,36 +106,30 @@ public class ParcelBrowseNode extends PropertySet } public XBrowseNode[] getChildNodes() { - try - { + try { - if ( hasChildNodes() ) - { + if (hasChildNodes()) { String[] names = parcel.getElementNames(); - browsenodes = new ArrayList( names.length ); + browsenodes = new ArrayList(names.length); for (String name : names) { browsenodes.add(new ScriptBrowseNode(provider, parcel, name)); } - } - else - { - LogUtils.DEBUG("ParcelBrowseNode.getChildeNodes no children " ); + } else { + LogUtils.DEBUG("ParcelBrowseNode.getChildeNodes no children "); return new XBrowseNode[0]; } - } - catch ( Exception e ) - { - LogUtils.DEBUG("Failed to getChildeNodes, exception: " + e ); - LogUtils.DEBUG( LogUtils.getTrace( e ) ); + } catch (Exception e) { + LogUtils.DEBUG("Failed to getChildeNodes, exception: " + e); + LogUtils.DEBUG(LogUtils.getTrace(e)); return new XBrowseNode[0]; } + return browsenodes.toArray(new XBrowseNode[browsenodes.size()]); } public boolean hasChildNodes() { - if ( container != null && container.hasByName( getName() ) && parcel != null ) - { + if (container != null && container.hasByName(getName()) && parcel != null) { return parcel.hasElements(); } @@ -151,8 +141,7 @@ public class ParcelBrowseNode extends PropertySet } @Override - public String toString() - { + public String toString() { return getName(); } @@ -163,11 +152,10 @@ public class ParcelBrowseNode extends PropertySet public Object invoke(String aFunctionName, Object[] aParams, 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 ); + 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]; @@ -175,137 +163,112 @@ public class ParcelBrowseNode extends PropertySet Any result = new Any(new Type(Boolean.class), Boolean.TRUE); - if (aFunctionName.equals("Creatable")) - { - try - { + if (aFunctionName.equals("Creatable")) { + try { String newName; if (aParams == null || aParams.length < 1 || - !AnyConverter.isString(aParams[0])) - { + !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 - { + try { DialogFactory dialogFactory = DialogFactory.getDialogFactory(); newName = dialogFactory.showInputDialog(title, prompt); - } - catch (Exception e) - { + } catch (Exception e) { newName = JOptionPane.showInputDialog(null, prompt, title, - JOptionPane.QUESTION_MESSAGE); + JOptionPane.QUESTION_MESSAGE); } - } - else { + } else { newName = AnyConverter.toString(aParams[0]); } - if ( newName == null || newName.length() == 0) - { + if (newName == null || newName.length() == 0) { result = new Any(new Type(Boolean.class), Boolean.FALSE); - } - else - { + } else { String source = provider.getScriptEditor().getTemplate(); String languageName = newName + "." + provider.getScriptEditor().getExtension(); String language = container.getLanguage(); - ScriptEntry entry = new ScriptEntry( language, languageName, "", new HashMap() ); + ScriptEntry entry = new ScriptEntry(language, languageName, "", + new HashMap()); - Parcel parcel = (Parcel)container.getByName( getName() ); - ScriptMetaData data = new ScriptMetaData( parcel, entry, source ); - parcel.insertByName( languageName, data ); + Parcel parcel = (Parcel)container.getByName(getName()); + 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!!"); - browsenodes = new ArrayList(4); + if (browsenodes == null) { + LogUtils.DEBUG("browsenodes null!!"); + browsenodes = new ArrayList(4); } + 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 ) ); + } 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 - { - if ( container.deleteParcel(getName()) ) - { + } else if (aFunctionName.equals("Deletable")) { + try { + if (container.deleteParcel(getName())) { result = new Any(new Type(Boolean.class), Boolean.TRUE); - } - else - { + } else { result = new Any(new Type(Boolean.class), Boolean.FALSE); } - } - catch (Exception e) - { + } catch (Exception e) { result = new Any(new Type(Boolean.class), Boolean.FALSE); } - } - else if (aFunctionName.equals("Renamable")) - { + } else if (aFunctionName.equals("Renamable")) { String newName = null; - try - { + + try { if (aParams == null || aParams.length < 1 || - !AnyConverter.isString(aParams[0])) - { + !AnyConverter.isString(aParams[0])) { String prompt = "Enter new name for Library"; String title = "Rename Library"; // try to get a DialogFactory instance, if it fails // just use a Swing JOptionPane to prompt for the name - try - { + try { DialogFactory dialogFactory = DialogFactory.getDialogFactory(); newName = dialogFactory.showInputDialog(title, prompt); - } - catch (Exception e) - { + } catch (Exception e) { newName = JOptionPane.showInputDialog(null, prompt, title, - JOptionPane.QUESTION_MESSAGE); + JOptionPane.QUESTION_MESSAGE); } - } - else { + } else { newName = AnyConverter.toString(aParams[0]); } - container.renameParcel( getName(), newName ); - Parcel p = (Parcel)container.getByName( newName ); - if(browsenodes == null ) - { + + container.renameParcel(getName(), newName); + Parcel p = (Parcel)container.getByName(newName); + + if (browsenodes == null) { getChildNodes(); } - ScriptBrowseNode[] childNodes = browsenodes.toArray(new ScriptBrowseNode[browsenodes.size()]); - for ( int index = 0; index < childNodes.length; index++ ) - { - childNodes[ index ].updateURI( p ); + ScriptBrowseNode[] childNodes = browsenodes.toArray(new + ScriptBrowseNode[browsenodes.size()]); + + for (int index = 0; index < childNodes.length; index++) { + childNodes[ index ].updateURI(p); } + result = new Any(new Type(XBrowseNode.class), this); - } - catch (Exception e) - { + } catch (Exception e) { result = new Any(new Type(Boolean.class), Boolean.FALSE); } } @@ -319,15 +282,13 @@ public class ParcelBrowseNode extends PropertySet } public void setValue(String aPropertyName, Object aValue) - throws com.sun.star.beans.UnknownPropertyException, - com.sun.star.script.CannotConvertException, - com.sun.star.reflection.InvocationTargetException - { + 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 - { + throws com.sun.star.beans.UnknownPropertyException { return null; } 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 ca5d94de02a3..d611c074acfe 100644 --- a/scripting/java/com/sun/star/script/framework/browse/PkgProviderBrowseNode.java +++ b/scripting/java/com/sun/star/script/framework/browse/PkgProviderBrowseNode.java @@ -25,14 +25,17 @@ import com.sun.star.script.framework.log.*; import com.sun.star.script.framework.container.*; -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 = " + container.getParcelContainerDir()); - LogUtils.DEBUG("*** PkgProviderBrowseNode ctor, container has num parcels = " + container.getElementNames().length); +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 = " + + container.getParcelContainerDir()); + LogUtils.DEBUG("*** PkgProviderBrowseNode ctor, container has num parcels = " + + container.getElementNames().length); } @Override 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 18cefb0d817c..d9b74e5a7807 100644 --- a/scripting/java/com/sun/star/script/framework/browse/ProviderBrowseNode.java +++ b/scripting/java/com/sun/star/script/framework/browse/ProviderBrowseNode.java @@ -43,8 +43,7 @@ import java.util.*; import javax.swing.JOptionPane; public class ProviderBrowseNode extends PropertySet - implements XBrowseNode, XInvocation -{ + implements XBrowseNode, XInvocation { private ScriptProvider provider; private Collection browsenodes; private String name; @@ -56,7 +55,8 @@ public class ProviderBrowseNode extends PropertySet - public ProviderBrowseNode( ScriptProvider provider, ParcelContainer container, XComponentContext xCtx ) { + public ProviderBrowseNode(ScriptProvider provider, ParcelContainer container, + XComponentContext xCtx) { LogUtils.DEBUG("*** ProviderBrowseNode ctor"); this.container = container; this.name = this.container.getLanguage(); @@ -64,25 +64,24 @@ public class ProviderBrowseNode extends PropertySet this.m_xCtx = xCtx; registerProperty("Deletable", new Type(boolean.class), - (short)0, "deletable"); + (short)0, "deletable"); registerProperty("Creatable", new Type(boolean.class), - (short)0, "creatable"); + (short)0, "creatable"); registerProperty("Editable", new Type(boolean.class), - (short)0, "editable"); + (short)0, "editable"); XSimpleFileAccess xSFA = null; XMultiComponentFactory xFac = m_xCtx.getServiceManager(); - try - { - xSFA = UnoRuntime.queryInterface( XSimpleFileAccess.class, - xFac.createInstanceWithContext( - "com.sun.star.ucb.SimpleFileAccess", - xCtx ) ); + + try { + xSFA = UnoRuntime.queryInterface(XSimpleFileAccess.class, + xFac.createInstanceWithContext( + "com.sun.star.ucb.SimpleFileAccess", + xCtx)); } // TODO propage errors - catch( com.sun.star.uno.Exception e ) - { - LogUtils.DEBUG("Caught exception in creation of ProviderBrowseNode "); - LogUtils.DEBUG( LogUtils.getTrace(e)); + catch (com.sun.star.uno.Exception e) { + LogUtils.DEBUG("Caught exception in creation of ProviderBrowseNode "); + LogUtils.DEBUG(LogUtils.getTrace(e)); } } @@ -93,51 +92,55 @@ public class ProviderBrowseNode extends PropertySet public XBrowseNode[] getChildNodes() { LogUtils.DEBUG("***** ProviderBrowseNode.getChildNodes()"); - if ( hasChildNodes() ) - { + + if (hasChildNodes()) { // needs initialisation? - LogUtils.DEBUG("** ProviderBrowseNode.getChildNodes(), container is " + container ); + LogUtils.DEBUG("** ProviderBrowseNode.getChildNodes(), container is " + + container); String[] parcels = container.getElementNames(); - browsenodes = new ArrayList( parcels.length ); + browsenodes = new ArrayList(parcels.length); + for (String parcel : parcels) { try { XBrowseNode node = new ParcelBrowseNode(provider, container, parcel); - browsenodes.add( node ); + browsenodes.add(node); } catch (Exception e) { LogUtils.DEBUG("*** Failed to create parcel node for " + parcel); - LogUtils.DEBUG( e.toString() ); + LogUtils.DEBUG(e.toString()); } } + ParcelContainer[] packageContainers = container.getChildContainers(); - LogUtils.DEBUG("**** For container named " + container.getName() + " with root path " + container.getParcelContainerDir() + " has " + packageContainers.length + " child containers " ); + LogUtils.DEBUG("**** For container named " + container.getName() + + " with root path " + container.getParcelContainerDir() + " has " + + packageContainers.length + " child containers "); for (ParcelContainer packageContainer : packageContainers) { - XBrowseNode node = new PkgProviderBrowseNode(provider, packageContainer, m_xCtx); - browsenodes.add( node ); + XBrowseNode node = new PkgProviderBrowseNode(provider, packageContainer, + m_xCtx); + browsenodes.add(node); } - } - else - { + } else { LogUtils.DEBUG("*** No container available"); return new XBrowseNode[0]; } - return browsenodes.toArray( new XBrowseNode[browsenodes.size()] ); + + return browsenodes.toArray(new XBrowseNode[browsenodes.size()]); } public boolean hasChildNodes() { boolean result = true; - if ( container == null || - ( !container.hasElements() && - container.getChildContainers().length == 0 ) ) - { + if (container == null || + (!container.hasElements() && + container.getChildContainers().length == 0)) { result = false; } LogUtils.DEBUG("***** ProviderBrowseNode.hasChildNodes(): " + - "name=" + name + - ", path=" + container.getParcelContainerDir() + - ", result=" + result ); + "name=" + name + + ", path=" + container.getParcelContainerDir() + + ", result=" + result); return result; } @@ -147,8 +150,7 @@ public class ProviderBrowseNode extends PropertySet } @Override - public String toString() - { + public String toString() { return getName(); } @@ -159,10 +161,9 @@ public class ProviderBrowseNode extends PropertySet public Object invoke(String aFunctionName, Object[] aParams, short[][] aOutParamIndex, Object[][] aOutParam) - throws com.sun.star.lang.IllegalArgumentException, - com.sun.star.script.CannotConvertException, - com.sun.star.reflection.InvocationTargetException - { + 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]; @@ -170,57 +171,45 @@ public class ProviderBrowseNode extends PropertySet Any result = new Any(new Type(Boolean.class), Boolean.TRUE); - if (aFunctionName.equals("Creatable")) - { - try - { + if (aFunctionName.equals("Creatable")) { + try { String name; if (aParams == null || aParams.length < 1 || - !AnyConverter.isString(aParams[0])) - { + !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 - { + try { DialogFactory dialogFactory = DialogFactory.getDialogFactory(); name = dialogFactory.showInputDialog(title, prompt); - } - catch (Exception e) - { + } catch (Exception e) { name = JOptionPane.showInputDialog(null, prompt, title, - JOptionPane.QUESTION_MESSAGE); + JOptionPane.QUESTION_MESSAGE); } - } - else { + } else { name = AnyConverter.toString(aParams[0]); } - if (name == null || name.length() == 0) - { + if (name == null || name.length() == 0) { result = new Any(new Type(Boolean.class), Boolean.FALSE); - } - else - { + } else { - Object newParcel = container.createParcel( name ); - LogUtils.DEBUG("Parcel created " + name + " " + newParcel ); - if ( newParcel == null ) - { + Object newParcel = container.createParcel(name); + LogUtils.DEBUG("Parcel created " + name + " " + newParcel); + + if (newParcel == null) { result = new Any(new Type(Boolean.class), Boolean.FALSE); - } - else - { - ParcelBrowseNode parcel = new ParcelBrowseNode( provider, container, name ); + } else { + ParcelBrowseNode parcel = new ParcelBrowseNode(provider, container, name); LogUtils.DEBUG("created parcel node "); - if ( browsenodes == null ) - { - browsenodes = new ArrayList( 5 ); + + if (browsenodes == null) { + browsenodes = new ArrayList(5); } browsenodes.add(parcel); @@ -229,15 +218,12 @@ public class ProviderBrowseNode extends PropertySet result = new Any(new Type(XBrowseNode.class), parcel); } } - } - catch (Exception e) - { - LogUtils.DEBUG("ProviderBrowseNode[create] failed with: " + e ); - LogUtils.DEBUG( LogUtils.getTrace( e ) ); + } catch (Exception e) { + LogUtils.DEBUG("ProviderBrowseNode[create] failed with: " + e); + LogUtils.DEBUG(LogUtils.getTrace(e)); result = new Any(new Type(Boolean.class), Boolean.FALSE); } - } - else { + } else { throw new com.sun.star.lang.IllegalArgumentException( "Function " + aFunctionName + " not supported."); } @@ -246,15 +232,13 @@ public class ProviderBrowseNode extends PropertySet } public void setValue(String aPropertyName, Object aValue) - throws com.sun.star.beans.UnknownPropertyException, - com.sun.star.script.CannotConvertException, - com.sun.star.reflection.InvocationTargetException - { + 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 - { + throws com.sun.star.beans.UnknownPropertyException { return null; } 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 6073eb03b243..f259da90f097 100644 --- a/scripting/java/com/sun/star/script/framework/browse/ScriptBrowseNode.java +++ b/scripting/java/com/sun/star/script/framework/browse/ScriptBrowseNode.java @@ -46,8 +46,7 @@ import com.sun.star.script.framework.provider.ScriptProvider; import com.sun.star.script.framework.container.*; public class ScriptBrowseNode extends PropertySet - implements XBrowseNode, XInvocation -{ + implements XBrowseNode, XInvocation { private ScriptProvider provider; private Parcel parent; @@ -58,37 +57,33 @@ public class ScriptBrowseNode extends PropertySet 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; XComponentContext xCtx = provider.getScriptingContext().getComponentContext(); XMultiComponentFactory xFac = xCtx.getServiceManager(); - try - { - ScriptMetaData data = (ScriptMetaData)parent.getByName( name ); - XSimpleFileAccess xSFA = UnoRuntime.queryInterface( XSimpleFileAccess.class, - xFac.createInstanceWithContext( - "com.sun.star.ucb.SimpleFileAccess", - xCtx ) ); - - if (provider.hasScriptEditor()) - { + + try { + ScriptMetaData data = (ScriptMetaData)parent.getByName(name); + XSimpleFileAccess xSFA = UnoRuntime.queryInterface(XSimpleFileAccess.class, + xFac.createInstanceWithContext( + "com.sun.star.ucb.SimpleFileAccess", + xCtx)); + + if (provider.hasScriptEditor()) { this.editable = true; - try - { + + try { if (!parent.isUnoPkg() - && !xSFA.isReadOnly(parent.getPathToParcel())) - { + && !xSFA.isReadOnly(parent.getPathToParcel())) { this.deletable = true; this.renamable = true; } } // TODO propagate errors - catch (Exception e) - { + catch (Exception e) { LogUtils.DEBUG("Caught exception in creation of ScriptBrowseNode"); LogUtils.DEBUG(LogUtils.getTrace(e)); } @@ -97,21 +92,21 @@ 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() ); + catch (Exception e) { + LogUtils.DEBUG("** caught exception getting script data for " + name + " ->" + + e.toString()); } registerProperty("Deletable", new Type(boolean.class), - (short)0, "deletable"); + (short)0, "deletable"); registerProperty("Editable", new Type(boolean.class), - (short)0, "editable"); + (short)0, "editable"); registerProperty("Renamable", new Type(boolean.class), - (short)0, "renamable"); + (short)0, "renamable"); registerProperty("URI", new Type(String.class), - (short)0, "uri"); + (short)0, "uri"); registerProperty("Description", new Type(String.class), - (short)0, "description"); + (short)0, "description"); } @@ -136,18 +131,18 @@ public class ScriptBrowseNode extends PropertySet return getName(); } - public void updateURI( Parcel p ) { + public void updateURI(Parcel p) { parent = p; ScriptMetaData data = null; - try - { - data = (ScriptMetaData)parent.getByName( name ); + + 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() ); + catch (Exception e) { + LogUtils.DEBUG("** caught exception getting script data for " + name + " ->" + + e.toString()); } } // implementation of XInvocation interface @@ -157,10 +152,9 @@ public class ScriptBrowseNode extends PropertySet public Object invoke(String aFunctionName, Object[] aParams, short[][] aOutParamIndex, Object[][] aOutParam) - throws com.sun.star.lang.IllegalArgumentException, - com.sun.star.script.CannotConvertException, - com.sun.star.reflection.InvocationTargetException - { + 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]; @@ -168,83 +162,67 @@ public class ScriptBrowseNode extends PropertySet Any result = new Any(new Type(Boolean.class), Boolean.TRUE); - if (aFunctionName.equals("Editable")) - { - if (!editable) - { + if (aFunctionName.equals("Editable")) { + if (!editable) { NoSupportException nse = new NoSupportException( - aFunctionName + " is not editable " ); + aFunctionName + " is not editable "); throw new InvocationTargetException( - "Scripting framework error editing script", null, nse ); + "Scripting framework error editing script", null, nse); } XScriptContext ctxt = provider.getScriptingContext(); ScriptMetaData data = null; - try - { - data = (ScriptMetaData)parent.getByName( name ); - } - catch ( NoSuchElementException nse ) - { + + 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 ) - { + 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 ); + null, wte.TargetException); } provider.getScriptEditor().edit(ctxt, data); - } - else if (aFunctionName.equals("Deletable")) - { - if (!deletable) - { + } else if (aFunctionName.equals("Deletable")) { + if (!deletable) { NoSupportException nse = new NoSupportException( - aFunctionName + " is not supported for this node" ); + aFunctionName + " is not supported for this node"); throw new InvocationTargetException( - "Scripting framework error deleting script", null, nse ); + "Scripting framework error deleting script", null, nse); } - try - { - parent.removeByName( name ); + + try { + parent.removeByName(name); result = new Any(new Type(Boolean.class), Boolean.TRUE); - } - catch ( NoSuchElementException nse ) - { + } catch (NoSuchElementException nse) { throw new com.sun.star.lang.IllegalArgumentException( - name + " does not exist or can't be found " ); - } - catch ( WrappedTargetException wte ) - { + name + " does not exist or can't be found "); + } catch (WrappedTargetException wte) { // rethrow throw new InvocationTargetException( "Scripting framework deleting script ", - null, wte.TargetException ); + null, wte.TargetException); } - } - else if (aFunctionName.equals("Renamable")) - { + } else if (aFunctionName.equals("Renamable")) { result = new Any(new Type(XBrowseNode.class), new XBrowseNode[0]); - if (!renamable) - { + + if (!renamable) { NoSupportException nse = new NoSupportException( - aFunctionName + " is not supported for this node" ); + aFunctionName + " is not supported for this node"); throw new InvocationTargetException( - "Scripting framework error renaming script", null, nse ); + "Scripting framework error renaming script", null, nse); } - try - { + try { String newName = AnyConverter.toString(aParams[0]); - ScriptMetaData oldData = (ScriptMetaData)parent.getByName( name ); + ScriptMetaData oldData = (ScriptMetaData)parent.getByName(name); oldData.loadSource(); String oldSource = oldData.getSource(); @@ -254,40 +232,33 @@ public class ScriptBrowseNode extends PropertySet String language = provider.getName(); ScriptEntry entry = new ScriptEntry( - language, languageName, "", new HashMap() ); + language, languageName, "", new HashMap()); ScriptMetaData data = new ScriptMetaData( - parent, entry, oldSource ); + parent, entry, oldSource); - parent.insertByName( languageName, data ); + parent.insertByName(languageName, data); LogUtils.DEBUG("Now remove old script"); - parent.removeByName( name ); + parent.removeByName(name); name = languageName; result = new Any(new Type(XBrowseNode.class), this); - } - catch ( NoSuchElementException nse ) - { + } catch (NoSuchElementException nse) { throw new com.sun.star.lang.IllegalArgumentException( - name + " does not exist or can't be found " ); - } - catch ( ElementExistException eee ) - { + name + " does not exist or can't be found "); + } catch (ElementExistException eee) { // rethrow throw new InvocationTargetException( "Scripting framework error renaming script ", - null, eee ); - } - catch ( WrappedTargetException wte ) - { + null, eee); + } catch (WrappedTargetException wte) { // rethrow throw new InvocationTargetException( "Scripting framework rename script ", - null, wte.TargetException ); + null, wte.TargetException); } - } - else { + } else { throw new com.sun.star.lang.IllegalArgumentException( "Function " + aFunctionName + " not supported."); } @@ -296,15 +267,13 @@ public class ScriptBrowseNode extends PropertySet } public void setValue(String aPropertyName, Object aValue) - throws com.sun.star.beans.UnknownPropertyException, - com.sun.star.script.CannotConvertException, - com.sun.star.reflection.InvocationTargetException - { + 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 - { + throws com.sun.star.beans.UnknownPropertyException { return null; } 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 efc9347d5d04..4ac952778c87 100644 --- a/scripting/java/com/sun/star/script/framework/container/DeployedUnoPackagesDB.java +++ b/scripting/java/com/sun/star/script/framework/container/DeployedUnoPackagesDB.java @@ -40,11 +40,11 @@ public class DeployedUnoPackagesDB { public DeployedUnoPackagesDB() throws IOException { ByteArrayInputStream bis = null; + try { bis = new ByteArrayInputStream(EMPTY_DOCUMENT); this.document = XMLParserFactory.getParser().parse(bis); - } - finally { + } finally { if (bis != null) bis.close(); } @@ -58,8 +58,7 @@ public class DeployedUnoPackagesDB { this(XMLParserFactory.getParser().parse(is)); } - public String[] getDeployedPackages( String language ) - { + public String[] getDeployedPackages(String language) { ArrayList packageUrls = new ArrayList(4); Element main = document.getDocumentElement(); Element root = null; @@ -67,38 +66,36 @@ public class DeployedUnoPackagesDB { NodeList langNodes = null; if ((langNodes = main.getElementsByTagName("language")) != null && - (len = langNodes.getLength()) != 0) - { - for ( int i=0; itrue if has parent false otherwise */ - public boolean isUnoPkg() { return parent.isUnoPkg(); } + public boolean isUnoPkg() { + return parent.isUnoPkg(); + } - public String getName() - { + 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 ); + 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; - try - { - if ( m_descriptor != null && hasElements() ) - { + + try { + if (m_descriptor != null && hasElements()) { ScriptEntry[] scripts = m_descriptor.getScriptEntries(); - if ( scripts.length != 0 ) - { + + if (scripts.length != 0) { for (ScriptEntry script : scripts) { if (script.getLanguageName().equals(aName)) { thescript = script; @@ -80,51 +80,50 @@ public class Parcel implements XNameContainer } } // catch unknown or un-checked exceptions - catch ( Exception e ) - { + catch (Exception e) { throw new com.sun.star.lang.WrappedTargetException(e); } - if ( thescript == null ) - { - LogUtils.DEBUG("No script for " + aName ); - throw new com.sun.star.container.NoSuchElementException("No script named " + aName ); + + if (thescript == null) { + LogUtils.DEBUG("No script for " + aName); + throw new com.sun.star.container.NoSuchElementException("No script named " + + aName); } - ScriptMetaData data = new ScriptMetaData( this, thescript, null ); - LogUtils.DEBUG("returning date for " + aName ); + ScriptMetaData data = new ScriptMetaData(this, thescript, null); + + LogUtils.DEBUG("returning date for " + aName); return data; } - public String[] getElementNames() - { + public String[] getElementNames() { String[] results = new String[0]; - if ( m_descriptor != null ) - { + + if (m_descriptor != null) { ScriptEntry[] scripts = m_descriptor.getScriptEntries(); results = new String[ scripts.length ]; - for ( int index = 0; index < scripts.length; index++ ) - { + + for (int index = 0; index < scripts.length; index++) { results[ index ] = scripts[ index ].getLanguageName(); } } + return results; } - public boolean hasByName( String aName ) - { + public boolean hasByName(String aName) { boolean result = true; Object containee = null; - try - { - containee = getByName( aName ); - if ( containee != null ) - { + + try { + containee = getByName(aName); + + if (containee != null) { result = true; } - } - catch( Exception e ) - { + } catch (Exception e) { result = false; } + return result; } @@ -136,68 +135,64 @@ public class Parcel implements XNameContainer return new Type(); } - public boolean hasElements() - { + public boolean hasElements() { return m_descriptor != null && m_descriptor.getScriptEntries().length > 0; } - 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 ) - { - try - { - ScriptEntry script = (ScriptEntry)getByName( aName ); - if ( script != null ) - { - //m_descriptor.removeScriptEntry( script ); - // 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 ); - } - - - } - // TO DO should catch specified exceptions - catch ( Exception e ) - { - throw new com.sun.star.lang.WrappedTargetException(); - } - - } - } + 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) { + try { + ScriptEntry script = (ScriptEntry)getByName(aName); + + if (script != null) { + //m_descriptor.removeScriptEntry( script ); + // 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); + } + + + } + // TO DO should catch specified exceptions + catch (Exception e) { + throw new com.sun.star.lang.WrappedTargetException(); + } + + } + } // 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 - { - if ( hasByName( aName ) ) - { - throw new ElementExistException( aName ); + try { + if (hasByName(aName)) { + throw new ElementExistException(aName); } + ScriptMetaData script = (ScriptMetaData)aElement; - if ( script.hasSource() ) - { + if (script.hasSource()) { LogUtils.DEBUG("Inserting source: " + script.getSource()); - if ( !script.writeSourceFile() ) - { - throw new com.sun.star.lang.WrappedTargetException( "Failed to create source file " + script.getLanguageName() ); + + if (!script.writeSourceFile()) { + throw new com.sun.star.lang.WrappedTargetException("Failed to create source file " + + script.getLanguageName()); } } - m_descriptor.addScriptEntry( script ); + + m_descriptor.addScriptEntry(script); writeParcelDescriptor(); - } - catch ( Exception e ) - { + } catch (Exception e) { LogUtils.DEBUG("Failed to insert entry " + aName + ": " + e.getMessage()); throw new com.sun.star.lang.WrappedTargetException(e); } @@ -205,82 +200,80 @@ 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 - { + 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 ); + getPathToParcel(), ParcelDescriptor.PARCEL_DESCRIPTOR_NAME); - XSimpleFileAccess2 xSFA2 = UnoRuntime.queryInterface( XSimpleFileAccess2.class, m_xSFA ); + XSimpleFileAccess2 xSFA2 = UnoRuntime.queryInterface(XSimpleFileAccess2.class, + m_xSFA); - if ( xSFA2 != null ) - { + if (xSFA2 != null) { ByteArrayOutputStream bos = null; ByteArrayInputStream bis = null; XInputStreamImpl xis = null; - try - { - bos = new ByteArrayOutputStream( 1024 ); - m_descriptor.write( bos ); - bis = new ByteArrayInputStream( bos.toByteArray() ); - - xis = new XInputStreamImpl( bis ); - xSFA2.writeFile( pathToDescriptor, xis ); - } - finally - { + + try { + bos = new ByteArrayOutputStream(1024); + m_descriptor.write(bos); + bis = new ByteArrayInputStream(bos.toByteArray()); + + xis = new XInputStreamImpl(bis); + xSFA2.writeFile(pathToDescriptor, xis); + } finally { if (bos != null) bos.close(); + if (bis != null) bis.close(); + if (xis != null) xis.closeInput(); } } } // delete - 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() ) - { + 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); + throw new com.sun.star.lang.WrappedTargetException("Failed to remove script " + + Name); } - LogUtils.DEBUG("** Parcel.removeByName have removed script source file " + Name); - m_descriptor.removeScriptEntry( script ); + + 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 ); + } else { + throw new com.sun.star.container.NoSuchElementException("No script named " + + Name); } - } - catch ( Exception e ) - { - LogUtils.DEBUG("** Parcel.removeByName Exception: " + e ); + } catch (Exception e) { + LogUtils.DEBUG("** Parcel.removeByName Exception: " + e); throw new com.sun.star.lang.WrappedTargetException(e); } } // rename parcel - public void rename( String name ) - { + public void rename(String name) { this.name = name; } - public ParcelContainer getParent() { return parent; } + public ParcelContainer getParent() { + return parent; + } /** * Returns the path of this Parcel * * @return String path to parcel */ - public String getPathToParcel() - { + public String getPathToParcel() { String path = parent.getParcelContainerDir() + "/" + name; return path; } 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 6e954af9b970..75cd6ce542ed 100644 --- a/scripting/java/com/sun/star/script/framework/container/ParcelContainer.java +++ b/scripting/java/com/sun/star/script/framework/container/ParcelContainer.java @@ -43,15 +43,15 @@ import com.sun.star.uri.XVndSunStarScriptUrl; * ScripingFramework specific Libraries. */ -public class ParcelContainer implements XNameAccess -{ +public class ParcelContainer implements XNameAccess { protected String language; protected String containerUrl; private Collection parcels = new ArrayList(10); static protected XSimpleFileAccess m_xSFA; protected XComponentContext m_xCtx; private ParcelContainer parent = null; - private Collection childContainers = new ArrayList(10); + private Collection childContainers = new + ArrayList(10); private boolean isPkgContainer = false; /** @@ -60,7 +60,9 @@ public class ParcelContainer implements XNameAccess * * @return true if has parent false otherwise */ - public boolean isUnoPkg() { return isPkgContainer; } + public boolean isUnoPkg() { + return isPkgContainer; + } /** @@ -68,8 +70,7 @@ public class ParcelContainer implements XNameAccess * * @return ParcelContainer if has parent null otherwise */ - public ParcelContainer parent() - { + public ParcelContainer parent() { return parent; } @@ -80,13 +81,12 @@ public class ParcelContainer implements XNameAccess * @return a new array of ParcelContainers. A zero * length array is returned if no child ParcelContainers. */ - public ParcelContainer[] getChildContainers() - { - if ( childContainers.isEmpty() ) - { + public ParcelContainer[] getChildContainers() { + if (childContainers.isEmpty()) { return new ParcelContainer[0]; } - return childContainers.toArray( new ParcelContainer[childContainers.size()] ); + + return childContainers.toArray(new ParcelContainer[childContainers.size()]); } /** @@ -96,9 +96,8 @@ public class ParcelContainer implements XNameAccess * * @return true if child successfully removed */ - public boolean removeChildContainer( ParcelContainer child ) - { - return childContainers.remove( child ); + public boolean removeChildContainer(ParcelContainer child) { + return childContainers.remove(child); } /** @@ -107,9 +106,8 @@ public class ParcelContainer implements XNameAccess * @param child ParcelContainer to be added. * */ - public void addChildContainer( ParcelContainer child ) - { - childContainers.add( child ); + public void addChildContainer(ParcelContainer child) { + childContainers.add(child); } /** @@ -121,19 +119,19 @@ public class ParcelContainer implements XNameAccess * @return child ParcelContainer or {@code null} if none * found. */ - public ParcelContainer getChildContainer(String key) - { + public ParcelContainer getChildContainer(String key) { ParcelContainer result = null; - for (ParcelContainer c : childContainers) - { + + for (ParcelContainer c : childContainers) { String location = ScriptMetaData.getLocationPlaceHolder( - c.containerUrl, c.getName()); - if ( key.equals( location ) ) - { + c.containerUrl, c.getName()); + + if (key.equals(location)) { result = c; break; } } + return result; } @@ -147,17 +145,16 @@ public class ParcelContainer implements XNameAccess * @return child ParcelContainer or {@code null} if none * found. */ - public ParcelContainer getChildContainerForURL( String containerUrl ) - { + public ParcelContainer getChildContainerForURL(String containerUrl) { ParcelContainer result = null; - for (ParcelContainer c : childContainers) - { - if ( containerUrl.equals( c.containerUrl ) ) - { + + for (ParcelContainer c : childContainers) { + if (containerUrl.equals(c.containerUrl)) { result = c; break; } } + return result; } @@ -168,33 +165,28 @@ public class ParcelContainer implements XNameAccess * @return name of ParcelContainer * found. */ - public String getName() - { + public String getName() { String name = null; + // TODO handler package ParcelContainer? - if ( !containerUrl.startsWith( "vnd.sun.star.tdoc:" ) ) - { - try - { + if (!containerUrl.startsWith("vnd.sun.star.tdoc:")) { + try { // return name - String decodedUrl = java.net.URLDecoder.decode( containerUrl, "UTF-8" ); + String decodedUrl = java.net.URLDecoder.decode(containerUrl, "UTF-8"); int indexOfSlash = decodedUrl.lastIndexOf('/'); - if ( indexOfSlash != -1 ) - { - name = decodedUrl.substring( indexOfSlash + 1 ); + + if (indexOfSlash != -1) { + name = decodedUrl.substring(indexOfSlash + 1); } - } - catch (UnsupportedEncodingException e) - { + } catch (UnsupportedEncodingException e) { com.sun.star.uno.RuntimeException e2 = new com.sun.star.uno.RuntimeException(); e2.initCause(e); throw e2; } - } - else - { + } else { name = "document"; } + return name; } @@ -204,10 +196,12 @@ public class ParcelContainer implements XNameAccess * @param containerUrl location of this container. * @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 + public ParcelContainer(XComponentContext xCtx, String containerUrl, + String language) throws com.sun.star.lang.IllegalArgumentException, + com.sun.star.lang.WrappedTargetException { - this( null, xCtx, containerUrl, language, true ); + this(null, xCtx, containerUrl, language, true); } /** @@ -218,9 +212,11 @@ public class ParcelContainer implements XNameAccess * @param loadParcels set to true if parcels are to be loaded * on construction. */ - public ParcelContainer( XComponentContext xCtx, String containerUrl, String language, boolean loadParcels ) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.lang.WrappedTargetException - { - this( null, xCtx, containerUrl, language, loadParcels ); + public ParcelContainer(XComponentContext xCtx, String containerUrl, + String language, boolean loadParcels) throws + com.sun.star.lang.IllegalArgumentException, + com.sun.star.lang.WrappedTargetException { + this(null, xCtx, containerUrl, language, loadParcels); } /** @@ -232,10 +228,14 @@ public class ParcelContainer implements XNameAccess * @param loadParcels set to true if parcels are to be loaded * on construction. */ - public ParcelContainer( ParcelContainer parent, XComponentContext xCtx, String containerUrl, String language, boolean loadParcels ) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.lang.WrappedTargetException + public ParcelContainer(ParcelContainer parent, XComponentContext xCtx, + String containerUrl, String language, + boolean loadParcels) throws com.sun.star.lang.IllegalArgumentException, + com.sun.star.lang.WrappedTargetException { - LogUtils.DEBUG("Creating ParcelContainer for " + containerUrl + " loadParcels = " + loadParcels + " language = " + language ); + LogUtils.DEBUG("Creating ParcelContainer for " + containerUrl + + " loadParcels = " + loadParcels + " language = " + language); this.m_xCtx = xCtx; this.language = language; this.parent = parent; @@ -244,437 +244,413 @@ public class ParcelContainer implements XNameAccess initSimpleFileAccess(); boolean parentIsPkgContainer = false; - if ( parent != null ) - { + if (parent != null) { parentIsPkgContainer = parent.isUnoPkg(); } - if ( containerUrl.endsWith("uno_packages") || parentIsPkgContainer ) - { + if (containerUrl.endsWith("uno_packages") || parentIsPkgContainer) { isPkgContainer = true; } - if ( loadParcels ) - { + if (loadParcels) { loadParcels(); } } - public String getContainerURL() { return this.containerUrl; } + public String getContainerURL() { + return this.containerUrl; + } - private synchronized void initSimpleFileAccess() - { - if ( m_xSFA != null ) - { + private synchronized void initSimpleFileAccess() { + if (m_xSFA != null) { return; } - try - { + + try { m_xSFA = UnoRuntime.queryInterface( - XSimpleFileAccess.class, - m_xCtx.getServiceManager().createInstanceWithContext( - "com.sun.star.ucb.SimpleFileAccess", m_xCtx ) ); - } - catch ( Exception e ) - { + 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 "); - LogUtils.DEBUG( LogUtils.getTrace( e ) ); + LogUtils.DEBUG(LogUtils.getTrace(e)); } } - public String getParcelContainerDir() - { + public String getParcelContainerDir() { // If this container does not represent an uno-package // then then it is a document, user or share // in each case the convention is to have a Scripts/[language] // dir where scripts reside - if ( !isUnoPkg() ) - { - return PathUtils.make_url( containerUrl , "Scripts/" + language.toLowerCase() ); + if (!isUnoPkg()) { + return PathUtils.make_url(containerUrl , "Scripts/" + language.toLowerCase()); } + return containerUrl; } - public Object getByName( String aName ) throws com.sun.star.container.NoSuchElementException, WrappedTargetException - { + public Object getByName(String aName) throws + com.sun.star.container.NoSuchElementException, WrappedTargetException { Parcel parcel = null; - try - { - if ( hasElements() ) - { - for (Parcel parcelToCheck : parcels) - { - if ( parcelToCheck.getName().equals( aName ) ) - { - parcel = parcelToCheck; - break; + + try { + if (hasElements()) { + for (Parcel parcelToCheck : parcels) { + if (parcelToCheck.getName().equals(aName)) { + parcel = parcelToCheck; + break; } } } - } - catch ( Exception e) - { + } catch (Exception e) { throw new WrappedTargetException(e); } - if ( parcel == null ) - { - throw new com.sun.star.container.NoSuchElementException( "Macro Library " + aName + " not found" ); + + if (parcel == null) { + throw new com.sun.star.container.NoSuchElementException("Macro Library " + aName + + " not found"); } + return parcel; } - public String[] getElementNames() - { - if ( hasElements() ) - { - Parcel[] theParcels = parcels.toArray( new Parcel[parcels.size()] ); + public String[] getElementNames() { + if (hasElements()) { + Parcel[] theParcels = parcels.toArray(new Parcel[parcels.size()]); String[] names = new String[ theParcels.length ]; - for ( int count = 0; count < names.length; count++ ) - { + + for (int count = 0; count < names.length; count++) { names[count] = theParcels[ count ].getName(); } + return names; } return new String[0]; } - public boolean hasByName( String aName ) - { + public boolean hasByName(String aName) { boolean isFound = false; - try - { - if ( getByName( aName ) != null ) - { + + try { + if (getByName(aName) != null) { isFound = true; } - } - catch ( Exception e ) - { + } catch (Exception e) { //TODO - handle trace } + return isFound; } - public Type getElementType() - { + public Type getElementType() { return new Type(); } - public boolean hasElements() - { + 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 ); - if ( m_xSFA.isFolder( getParcelContainerDir() ) ) - { - LogUtils.DEBUG( getParcelContainerDir() + " is a folder " ); - String[] children = m_xSFA.getFolderContents( getParcelContainerDir(), true ); + private void loadParcels() throws com.sun.star.lang.IllegalArgumentException, + com.sun.star.lang.WrappedTargetException { + try { + LogUtils.DEBUG("About to load parcels from " + containerUrl); + + if (m_xSFA.isFolder(getParcelContainerDir())) { + LogUtils.DEBUG(getParcelContainerDir() + " is a folder "); + String[] children = m_xSFA.getFolderContents(getParcelContainerDir(), true); parcels = new ArrayList(children.length); - for (String child : children) - { + + for (String child : children) { LogUtils.DEBUG("Processing " + child); - try - { + + try { loadParcel(child); - } - catch (java.lang.Exception e) - { + } catch (java.lang.Exception e) { // print an error message and move on to // the next parcel - LogUtils.DEBUG("ParcelContainer.loadParcels caught " + e.getClass().getName() + " exception loading parcel " + child + ": " + e.getMessage()); + LogUtils.DEBUG("ParcelContainer.loadParcels caught " + e.getClass().getName() + + " exception loading parcel " + child + ": " + e.getMessage()); } } - } - else - { - LogUtils.DEBUG(" ParcelCOntainer.loadParcels " + getParcelContainerDir() + " is not a folder "); + } else { + LogUtils.DEBUG(" ParcelCOntainer.loadParcels " + getParcelContainerDir() + + " is not a folder "); } - } - catch ( com.sun.star.ucb.CommandAbortedException e ) - { - LogUtils.DEBUG("ParcelContainer.loadParcels caught exception processing folders for " + getParcelContainerDir() ); - LogUtils.DEBUG("TRACE: " + LogUtils.getTrace(e) ); + } catch (com.sun.star.ucb.CommandAbortedException e) { + LogUtils.DEBUG("ParcelContainer.loadParcels caught exception processing folders for " + + getParcelContainerDir()); + LogUtils.DEBUG("TRACE: " + LogUtils.getTrace(e)); throw new com.sun.star.lang.WrappedTargetException(e); - } - catch ( com.sun.star.uno.Exception e ) - { - LogUtils.DEBUG("ParcelContainer.loadParcels caught exception processing folders for " + getParcelContainerDir() ); - LogUtils.DEBUG("TRACE: " + LogUtils.getTrace(e) ); + } catch (com.sun.star.uno.Exception e) { + LogUtils.DEBUG("ParcelContainer.loadParcels caught exception processing folders for " + + getParcelContainerDir()); + LogUtils.DEBUG("TRACE: " + LogUtils.getTrace(e)); throw new com.sun.star.lang.WrappedTargetException(e); } } - 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" ); + + if (hasByName(name)) { + throw new ElementExistException("Parcel " + name + " already exists"); } - String pathToParcel = PathUtils.make_url( getParcelContainerDir() , name ); - try - { - LogUtils.DEBUG("ParcelContainer.createParcel, creating folder " + pathToParcel ); - m_xSFA.createFolder( pathToParcel ); + String pathToParcel = PathUtils.make_url(getParcelContainerDir() , name); + + try { + LogUtils.DEBUG("ParcelContainer.createParcel, creating folder " + pathToParcel); + m_xSFA.createFolder(pathToParcel); - LogUtils.DEBUG("ParcelContainer.createParcel, folder " + pathToParcel + " created "); + LogUtils.DEBUG("ParcelContainer.createParcel, folder " + pathToParcel + + " created "); 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 ); - if ( xSFA2 != null ) - { - LogUtils.DEBUG("createParcel() Using XSIMPLEFILEACCESS2 " + parcelDesc ); - ByteArrayOutputStream bos = new ByteArrayOutputStream( 1024 ); - pd.write( bos ); + pd.setLanguage(language); + 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); + ByteArrayOutputStream bos = new ByteArrayOutputStream(1024); + pd.write(bos); bos.close(); - ByteArrayInputStream bis = new ByteArrayInputStream( bos.toByteArray() ); - XInputStreamImpl xis = new XInputStreamImpl( bis ); - xSFA2.writeFile( parcelDesc, xis ); + ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); + XInputStreamImpl xis = new XInputStreamImpl(bis); + xSFA2.writeFile(parcelDesc, xis); xis.closeInput(); - p = loadParcel( pathToParcel ); + p = loadParcel(pathToParcel); } - } - catch ( Exception e ) - { + } 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); } + return p; } - public Parcel loadParcel( String parcelUrl ) throws com.sun.star.lang.WrappedTargetException, com.sun.star.lang.IllegalArgumentException - { + public Parcel loadParcel(String parcelUrl) throws + com.sun.star.lang.WrappedTargetException, + com.sun.star.lang.IllegalArgumentException { - String parcelDescUrl = PathUtils.make_url( parcelUrl, ParcelDescriptor.PARCEL_DESCRIPTOR_NAME ); + 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 ); + 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 - { + + try { is.close(); is = null; + } catch (Exception e) { + LogUtils.DEBUG("ParcelContainer.loadParcel Exception when closing stream for " + + parcelDescUrl + " :" + e); } - catch ( Exception e ) - { - LogUtils.DEBUG("ParcelContainer.loadParcel Exception when closing stream for " + parcelDescUrl + " :" + e ); - } - LogUtils.DEBUG("ParcelContainer.loadParcel closed " + parcelDescUrl ); - if ( !pd.getLanguage().equals( language ) ) - { + + LogUtils.DEBUG("ParcelContainer.loadParcel closed " + parcelDescUrl); + + if (!pd.getLanguage().equals(language)) { LogUtils.DEBUG("ParcelContainer.loadParcel Language of Parcel does not match this container "); return null; } - LogUtils.DEBUG("Processing " + parcelDescUrl + " closed " ); + + LogUtils.DEBUG("Processing " + parcelDescUrl + " closed "); int indexOfSlash = parcelUrl.lastIndexOf('/'); - String name = parcelUrl.substring( indexOfSlash + 1 ); + String name = parcelUrl.substring(indexOfSlash + 1); - parcel = new Parcel( m_xSFA, this, pd, name ); + parcel = new Parcel(m_xSFA, this, pd, name); - LogUtils.DEBUG(" ParcelContainer.loadParcel created parcel for " + parcelDescUrl + " for language " + language ); - parcels.add( parcel ); - } - else - { - throw new java.io.IOException( parcelDescUrl + " does NOT exist!"); + 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 ) - { + } 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 ); + } 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 ) - { + } 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); } - finally - { - if ( is != null ) - { - try - { + finally { + if (is != null) { + try { is.close(); // is will close xis + } catch (Exception ignore) { } - catch ( Exception ignore ) - { - } - } - else if ( xis != null ) - { - try - { + } else if (xis != null) { + try { xis.closeInput(); - } - catch ( Exception ignore ) - { + } catch (Exception ignore) { } } } + return parcel; } - 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 ); - } - 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 ); + 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); + } + + 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); throw new com.sun.star.lang.WrappedTargetException(e); } - 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 ); + + 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); - } - catch ( com.sun.star.uno.Exception e ) - { - LogUtils.DEBUG(" ** ParcelContainer Renaming failed with " + e ); + } catch (com.sun.star.uno.Exception e) { + LogUtils.DEBUG(" ** ParcelContainer Renaming failed with " + e); throw new com.sun.star.lang.WrappedTargetException(e); } - p.rename( newName ); + p.rename(newName); } // removes but doesn't physically delele parcel from container - 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 ); + 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); } - return parcels.remove( p ); + 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 ); + 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); - Parcel p = (Parcel)getByName( name ); - if ( p == null ) - { - throw new com.sun.star.container.NoSuchElementException("No parcel named " + name ); - } + Parcel p = (Parcel)getByName(name); - try - { - String pathToParcel = PathUtils.make_url( getParcelContainerDir(), name ); - m_xSFA.kill( pathToParcel ); + if (p == null) { + throw new com.sun.star.container.NoSuchElementException("No parcel named " + + name); } - catch( Exception e ) - { - LogUtils.DEBUG("Error deleteing parcel " + name ); + + try { + String pathToParcel = PathUtils.make_url(getParcelContainerDir(), name); + m_xSFA.kill(pathToParcel); + } catch (Exception e) { + LogUtils.DEBUG("Error deleteing parcel " + name); throw new com.sun.star.lang.WrappedTargetException(e); } - return parcels.remove( p ); + return parcels.remove(p); } - public String getLanguage() { return language; } + public String getLanguage() { + return language; + } - 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 ); + 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; } -public ParsedScriptUri parseScriptUri( String scriptURI ) throws com.sun.star.lang.IllegalArgumentException -{ + public ParsedScriptUri parseScriptUri(String scriptURI) throws + com.sun.star.lang.IllegalArgumentException { XMultiComponentFactory xMcFac = null; XUriReferenceFactory xFac = null; - try - { + try { xMcFac = m_xCtx.getServiceManager(); - 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() ); + 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"); } - if ( xFac == null ) - { + + 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 ); + XUriReference uriRef = xFac.parse(scriptURI); + XVndSunStarScriptUrl sfUri = UnoRuntime.queryInterface( + XVndSunStarScriptUrl.class, uriRef); - if ( sfUri == null ) - { + 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(); - parsedUri.function= sfUri.getName(); + parsedUri.function = sfUri.getName(); parsedUri.parcel = ""; // parse parcel name; - StringTokenizer tokenizer = new StringTokenizer( parsedUri.function, "." ); + StringTokenizer tokenizer = new StringTokenizer(parsedUri.function, "."); - if ( tokenizer.hasMoreElements() ) - { + if (tokenizer.hasMoreElements()) { parsedUri.parcel = (String)tokenizer.nextElement(); - LogUtils.DEBUG("** parcelName = " + parsedUri.parcel ); + LogUtils.DEBUG("** parcelName = " + parsedUri.parcel); } - if ( parsedUri.function != null && ( parsedUri.function.length() > 0 ) ) - { + 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 @@ -685,11 +661,11 @@ public ParsedScriptUri parseScriptUri( String scriptURI ) throws com.sun.star.l // time its got to here LogUtils.DEBUG("** location = " + parsedUri.location + - "\nfunction = " + parsedUri.function + - "\nparcel = " + parsedUri.parcel + - "\nlocation = " + parsedUri.location ); + "\nfunction = " + parsedUri.function + + "\nparcel = " + parsedUri.parcel + + "\nlocation = " + parsedUri.location); return parsedUri; -} + } } 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 2d44ff55944e..77b2f9fb3810 100644 --- a/scripting/java/com/sun/star/script/framework/container/ParcelDescriptor.java +++ b/scripting/java/com/sun/star/script/framework/container/ParcelDescriptor.java @@ -38,10 +38,11 @@ public class ParcelDescriptor { // File name to be used for parcel descriptor files public static final String - PARCEL_DESCRIPTOR_NAME = "parcel-descriptor.xml"; + PARCEL_DESCRIPTOR_NAME = "parcel-descriptor.xml"; // Collection of all ParcelDescriptor created for files - private static final Map PARCEL_DESCRIPTOR_MAP = new HashMap(5); + private static final Map PARCEL_DESCRIPTOR_MAP = new + HashMap(5); // This is the default contents of a parcel descriptor to be used when // creating empty descriptors @@ -53,7 +54,7 @@ public class ParcelDescriptor { private File file = null; private Document document = null; private String language = null; - private Map languagedepprops = new HashMap(3); + private Map languagedepprops = new HashMap(3); @@ -61,11 +62,11 @@ public class ParcelDescriptor { public ParcelDescriptor() throws IOException { ByteArrayInputStream bis = null; + try { bis = new ByteArrayInputStream(EMPTY_DOCUMENT); this.document = XMLParserFactory.getParser().parse(bis); - } - finally { + } finally { if (bis != null) bis.close(); } @@ -89,27 +90,28 @@ public class ParcelDescriptor { if (file.exists()) { FileInputStream fis = null; + try { fis = new FileInputStream(file); this.document = XMLParserFactory.getParser().parse(fis); - } - finally { + } finally { if (fis != null) fis.close(); } - } - else { + } else { ByteArrayInputStream bis = null; + try { bis = new ByteArrayInputStream(EMPTY_DOCUMENT); this.document = XMLParserFactory.getParser().parse(bis); - } - finally { + } finally { if (bis != null) bis.close(); } + setLanguage(language); } + initLanguageProperties(); } @@ -128,6 +130,7 @@ public class ParcelDescriptor { language = e.getAttribute("language"); } } + return language; } @@ -138,8 +141,7 @@ public class ParcelDescriptor { try { Element e = document.getDocumentElement(); e.setAttribute("language", language); - } - catch (DOMException de) { + } catch (DOMException de) { } } } @@ -156,7 +158,7 @@ public class ParcelDescriptor { for (int i = 0; i < len; i++) { String language, languagename, logicalname, description = ""; - Map langProps = new HashMap(); + Map langProps = new HashMap(); NodeList nl; Element tmp; @@ -164,6 +166,7 @@ public class ParcelDescriptor { language = scriptElement.getAttribute("language"); nl = scriptElement.getElementsByTagName("logicalname"); + if (nl == null) logicalname = ""; else { @@ -173,15 +176,13 @@ public class ParcelDescriptor { // get the text of the description element nl = scriptElement.getElementsByTagName("locale"); - if (nl != null) - { + + if (nl != null) { nl = nl.item(0).getChildNodes(); - if (nl != null) - { - for (int j = 0 ; j < nl.getLength(); j++) - { - if (nl.item(j).getNodeName().equals("description")) - { + + if (nl != null) { + for (int j = 0 ; j < nl.getLength(); j++) { + if (nl.item(j).getNodeName().equals("description")) { CharacterData cd = (CharacterData)nl.item(j).getFirstChild(); description = cd.getData().trim(); @@ -191,36 +192,41 @@ public class ParcelDescriptor { } nl = scriptElement.getElementsByTagName("functionname"); + if (nl == null) { languagename = ""; } else { tmp = (Element)nl.item(0); languagename = tmp.getAttribute("value"); } + nl = scriptElement.getElementsByTagName("languagedepprops"); - if ( nl != null && nl.getLength() > 0 ) - { + + if (nl != null && nl.getLength() > 0) { NodeList props = ((Element)nl.item(0)).getElementsByTagName("prop"); - if ( props != null ) - { - for ( int j=0; j < props.getLength(); j++ ) - { + + if (props != null) { + for (int j = 0; j < props.getLength(); j++) { tmp = (Element)props.item(j); String key = tmp.getAttribute("name"); String val = tmp.getAttribute("value"); - langProps.put( key,val ); + langProps.put(key, val); } } } - ScriptEntry entry = new ScriptEntry(language, languagename, "", langProps,description); + + ScriptEntry entry = new ScriptEntry(language, languagename, "", langProps, + description); scripts.add(entry); } + return scripts.toArray(new ScriptEntry[scripts.size()]); } public void setScriptEntries(ScriptEntry[] scripts) { clearEntries(); + for (ScriptEntry script : scripts) { addScriptEntry(script); } @@ -228,6 +234,7 @@ public class ParcelDescriptor { public void setScriptEntries(Iterator scripts) { clearEntries(); + while (scripts.hasNext()) addScriptEntry(scripts.next()); } @@ -271,13 +278,11 @@ public class ParcelDescriptor { int len; if ((scriptNodes = document.getElementsByTagName("script")) != null && - (len = scriptNodes.getLength()) != 0) - { + (len = scriptNodes.getLength()) != 0) { for (int i = len - 1; i >= 0; i--) { try { main.removeChild(scriptNodes.item(i)); - } - catch (DOMException de) { + } catch (DOMException de) { // ignore } } @@ -290,8 +295,7 @@ public class ParcelDescriptor { int len; if ((scriptNodes = document.getElementsByTagName("script")) != null && - (len = scriptNodes.getLength()) != 0) - { + (len = scriptNodes.getLength()) != 0) { for (int i = len - 1; i >= 0; i--) { try { Element scriptElement = (Element)scriptNodes.item(i); @@ -299,6 +303,7 @@ public class ParcelDescriptor { NodeList nl = scriptElement.getElementsByTagName("functionname"); + if (nl == null) { continue; } else { @@ -309,8 +314,7 @@ public class ParcelDescriptor { if (languagename.equals(script.getLanguageName())) { main.removeChild(scriptElement); } - } - catch (DOMException de) { + } catch (DOMException de) { // ignore } } @@ -332,10 +336,11 @@ public class ParcelDescriptor { tempitem = document.createElement("description"); String description = script.getDescription(); - if (description == null || description.length() == 0) - { + + if (description == null || description.length() == 0) { description = script.getLogicalName(); } + tempitem.appendChild(document.createTextNode(description)); item.appendChild(tempitem); @@ -354,6 +359,7 @@ public class ParcelDescriptor { item = document.createElement("languagedepprops"); Iterator iter = languagedepprops.keySet().iterator(); + while (iter.hasNext()) { tempitem = document.createElement("prop"); key = iter.next(); @@ -361,6 +367,7 @@ public class ParcelDescriptor { tempitem.setAttribute("value", languagedepprops.get(key)); item.appendChild(tempitem); } + root.appendChild(item); } 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 477604c721ac..65d6f4e68a28 100644 --- a/scripting/java/com/sun/star/script/framework/container/ParsedScriptUri.java +++ b/scripting/java/com/sun/star/script/framework/container/ParsedScriptUri.java @@ -17,8 +17,7 @@ */ package com.sun.star.script.framework.container; -public class ParsedScriptUri -{ +public class ParsedScriptUri { public String location; public String function; 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 b4d6a70e8e22..6f0ae24e9647 100644 --- a/scripting/java/com/sun/star/script/framework/container/ScriptEntry.java +++ b/scripting/java/com/sun/star/script/framework/container/ScriptEntry.java @@ -27,7 +27,7 @@ public class ScriptEntry implements Cloneable { private String logicalname = ""; private String description = ""; - private Map languagedepprops; + private Map languagedepprops; public ScriptEntry(String language, String languagename, String location) { @@ -39,11 +39,10 @@ public class ScriptEntry implements Cloneable { // as logical name also this.logicalname = languagename; this.location = location; - this.languagedepprops = new HashMap(); + this.languagedepprops = new HashMap(); } - public ScriptEntry(ScriptEntry entry) - { + public ScriptEntry(ScriptEntry entry) { this.language = entry.language; this.languagename = entry.languagename; this.logicalname = entry.languagename; @@ -53,15 +52,15 @@ public class ScriptEntry implements Cloneable { } public ScriptEntry(String language, String languagename, - String location, Map languagedepprops) { - this( language, languagename, location ); + String location, Map languagedepprops) { + this(language, languagename, location); this.languagedepprops = languagedepprops; } public ScriptEntry(String language, String languagename, - String location, Map languagedepprops, + String location, Map languagedepprops, String description) { - this( language, languagename, location ); + this(language, languagename, location); this.languagedepprops = languagedepprops; this.description = description; } @@ -77,14 +76,13 @@ public class ScriptEntry implements Cloneable { public boolean equals(ScriptEntry other) { return language.equals(other.getLanguage()) && - languagename.equals(other.getLanguageName()) && - logicalname.equals(other.getLogicalName()) && - languagedepprops.equals(other.getLanguageProperties()) && - location.equals(other.getLocation()); + languagename.equals(other.getLanguageName()) && + logicalname.equals(other.getLogicalName()) && + languagedepprops.equals(other.getLanguageProperties()) && + location.equals(other.getLocation()); } - public Map getLanguageProperties() - { + public Map getLanguageProperties() { return languagedepprops; } @@ -114,6 +112,7 @@ 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; } } 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 d55b226d83df..42d237d44ec5 100644 --- a/scripting/java/com/sun/star/script/framework/container/ScriptMetaData.java +++ b/scripting/java/com/sun/star/script/framework/container/ScriptMetaData.java @@ -42,49 +42,47 @@ public class ScriptMetaData extends ScriptEntry { private Parcel parent; - public ScriptMetaData( Parcel parent, ScriptEntry entry, - String source ) - { - super( entry ); + public ScriptMetaData(Parcel parent, ScriptEntry entry, + String source) { + super(entry); this.parent = parent; - if ( source != null ) - { + + if (source != null) { this.hasSource = true; this.source = source; } } - public boolean hasSource() - { + public boolean hasSource() { return hasSource; } public String getSource() { - return ( source !=null && hasSource ) ? source : null; + return (source != null && hasSource) ? source : null; } public byte[] getSourceBytes() { - return ( source !=null && hasSource ) ? source.getBytes() : null; + return (source != null && hasSource) ? source.getBytes() : null; } public boolean equals(ScriptMetaData other) { return super.equals(other) && hasSource == other.hasSource(); } - public String getScriptFullURL() - { - String url = "vnd.sun.star.script:" + parent.getName() + "." + getLanguageName() + - "?" + "language=" + getLanguage() + - "&location=" + getParcelLocation(); - return url; + public String getScriptFullURL() { + 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(); + public String getShortFormScriptURL() { + String url = "vnd.sun.star.script:" + parent.getName() + "." + getLanguageName() + + + "?" + "language=" + getLanguage() + + "&location=" + getLocationPlaceHolder(); return url; } @@ -111,78 +109,60 @@ public class ScriptMetaData extends ScriptEntry { private static final String UNO_SHARED_PACKAGES2 = SHARE + "/uno_packages"; - public static String getLocationPlaceHolder(String url, String pkgname) - { + public static String getLocationPlaceHolder(String url, String pkgname) { String result = "Unknown"; - if ( url.contains(UNO_USER_PACKAGES1) || - url.contains(UNO_USER_PACKAGES2) ) - { - result = PathUtils.make_url( "user:uno_packages", pkgname ); - } - else if ( url.contains(UNO_SHARED_PACKAGES1) || - url.contains(UNO_SHARED_PACKAGES2) ) - { - result = PathUtils.make_url( "share:uno_packages", pkgname ); - } - else if ( url.indexOf(SHARE) == 0 ) - { + if (url.contains(UNO_USER_PACKAGES1) || + url.contains(UNO_USER_PACKAGES2)) { + result = PathUtils.make_url("user:uno_packages", pkgname); + } else if (url.contains(UNO_SHARED_PACKAGES1) || + url.contains(UNO_SHARED_PACKAGES2)) { + result = PathUtils.make_url("share:uno_packages", pkgname); + } else if (url.indexOf(SHARE) == 0) { result = "share"; - } - else if ( url.indexOf(USER) == 0 ) - { + } else if (url.indexOf(USER) == 0) { result = "user"; - } - else if ( url.indexOf("vnd.sun.star.tdoc:") == 0 ) - { + } else if (url.indexOf("vnd.sun.star.tdoc:") == 0) { result = "document"; } + return result; } - public String getLocationPlaceHolder() - { + public String getLocationPlaceHolder() { String placeHolder = "Unknown"; String pathToParcel = parent.getPathToParcel(); - if ( pathToParcel.contains(UNO_USER_PACKAGES1) || - pathToParcel.contains(UNO_USER_PACKAGES2) ) - { + if (pathToParcel.contains(UNO_USER_PACKAGES1) || + pathToParcel.contains(UNO_USER_PACKAGES2)) { // it's a package placeHolder = "user:uno_packages"; String unoPkg = parent.parent.getName(); - if ( unoPkg != null ) - { - placeHolder = PathUtils.make_url( placeHolder, unoPkg ); + + if (unoPkg != null) { + placeHolder = PathUtils.make_url(placeHolder, unoPkg); } - } - else if ( pathToParcel.contains(UNO_SHARED_PACKAGES1) || - pathToParcel.contains(UNO_SHARED_PACKAGES2) ) - { + } else if (pathToParcel.contains(UNO_SHARED_PACKAGES1) || + pathToParcel.contains(UNO_SHARED_PACKAGES2)) { //its a package placeHolder = "share:uno_packages"; String unoPkg = parent.parent.getName(); - if ( unoPkg != null ) - { - placeHolder = PathUtils.make_url( placeHolder, unoPkg ); + + if (unoPkg != null) { + placeHolder = PathUtils.make_url(placeHolder, unoPkg); } - } - else if ( pathToParcel.indexOf(SHARE) == 0 ) - { + } else if (pathToParcel.indexOf(SHARE) == 0) { placeHolder = "share"; - } - else if ( pathToParcel.indexOf(USER) == 0 ) - { + } else if (pathToParcel.indexOf(USER) == 0) { placeHolder = "user"; - } - else if ( pathToParcel.indexOf("vnd.sun.star.tdoc:") == 0 ) - { + } else if (pathToParcel.indexOf("vnd.sun.star.tdoc:") == 0) { placeHolder = "document"; } + // TODO handling document packages ??? not really sure of package url -/* else - { - } */ + /* else + { + } */ return placeHolder; } @@ -193,76 +173,69 @@ public class ScriptMetaData extends ScriptEntry { // Also if it is to remain needs to be renamed to getParcelLocationURL // return URL string to parcel - public String getParcelLocation() - { + public String getParcelLocation() { return parent.getPathToParcel(); } @Override - public String toString() - { - return "\nParcelLocation = " + getParcelLocation() + "\nLocationPlaceHolder = " + locationPlaceHolder + super.toString(); + public String toString() { + return "\nParcelLocation = " + getParcelLocation() + "\nLocationPlaceHolder = " + + locationPlaceHolder + super.toString(); } - public URL[] getClassPath() - { - try - { - String classpath = getLanguageProperties().get("classpath"); + public URL[] getClassPath() { + try { + String classpath = getLanguageProperties().get("classpath"); - if ( classpath == null ) - { - classpath = ""; - } + if (classpath == null) { + classpath = ""; + } - String parcelPath = getParcelLocation(); - // make sure path ends with / - if ( !parcelPath.endsWith("/") ) - { - parcelPath += "/"; - } + String parcelPath = getParcelLocation(); + + // make sure path ends with / + if (!parcelPath.endsWith("/")) { + parcelPath += "/"; + } - // replace \ with / - parcelPath = parcelPath.replace( '\\', '/' ); + // replace \ with / + parcelPath = parcelPath.replace('\\', '/'); + + ArrayList classPathVec = new ArrayList(); + StringTokenizer stk = new StringTokenizer(classpath, ":"); + + while (stk.hasMoreElements()) { + String relativeClasspath = stk.nextToken(); + String pathToProcess = PathUtils.make_url(parcelPath, relativeClasspath); + URL url = createURL(pathToProcess); + + if (url != null) { + classPathVec.add(url); + } - ArrayList classPathVec = new ArrayList(); - StringTokenizer stk = new StringTokenizer(classpath, ":"); - while ( stk.hasMoreElements() ) - { - String relativeClasspath = stk.nextToken(); - String pathToProcess = PathUtils.make_url( parcelPath, relativeClasspath); - URL url = createURL( pathToProcess ); - if ( url != null ) - { - classPathVec.add ( url ); } - } - if ( classPathVec.size() == 0) - { - URL url = createURL( parcelPath ); - if ( url != null ) - { - classPathVec.add(url); + if (classPathVec.size() == 0) { + URL url = createURL(parcelPath); + + if (url != null) { + classPathVec.add(url); + } } - } - return classPathVec.toArray( new URL[classPathVec.size()]); - } - catch ( Exception e ) - { - LogUtils.DEBUG("Failed to build class path " + e.toString() ); - LogUtils.DEBUG( LogUtils.getTrace( e ) ); - return new URL[0]; - } + return classPathVec.toArray(new URL[classPathVec.size()]); + } catch (Exception e) { + LogUtils.DEBUG("Failed to build class path " + e.toString()); + LogUtils.DEBUG(LogUtils.getTrace(e)); + return new URL[0]; + } } - private URL createURL( String path ) throws java.net.MalformedURLException - { + private URL createURL(String path) throws java.net.MalformedURLException { int indexOfColon = path.indexOf(':'); - String scheme = path.substring( 0, indexOfColon ); - UCBStreamHandler handler = new UCBStreamHandler( scheme, parent.m_xSFA); + String scheme = path.substring(0, indexOfColon); + UCBStreamHandler handler = new UCBStreamHandler(scheme, parent.m_xSFA); path += UCBStreamHandler.separator; return new URL(null, path, handler); @@ -270,87 +243,81 @@ public class ScriptMetaData extends ScriptEntry { // TODO should decide whether this should throw or not // decide whether it should be public or protected ( final ? ) - public void loadSource() - { - try - { - URL sourceUrl = getSourceURL(); - LogUtils.DEBUG("** In load source BUT not loading yet for " + sourceUrl ); - - if ( sourceUrl != null ) - { - StringBuilder buf = new StringBuilder(); - InputStream in = sourceUrl.openStream(); - - byte[] contents = new byte[1024]; - int len; - while ((len = in.read(contents, 0, 1024)) != -1) { - buf.append(new String(contents, 0, len)); - } - - try { - in.close(); - } - catch (java.io.IOException ignore ) { - LogUtils.DEBUG("** Failed to read scriot from url " + ignore.toString() ); - } - - source = buf.toString(); - hasSource = true; + public void loadSource() { + try { + URL sourceUrl = getSourceURL(); + LogUtils.DEBUG("** In load source BUT not loading yet for " + sourceUrl); + + if (sourceUrl != null) { + StringBuilder buf = new StringBuilder(); + InputStream in = sourceUrl.openStream(); + + byte[] contents = new byte[1024]; + int len; + + while ((len = in.read(contents, 0, 1024)) != -1) { + buf.append(new String(contents, 0, len)); + } + + try { + in.close(); + } catch (java.io.IOException ignore) { + LogUtils.DEBUG("** Failed to read scriot from url " + ignore.toString()); } - } - catch (java.io.IOException e) { - LogUtils.DEBUG("** Failed to read scriot from url " + e.toString()); - } + source = buf.toString(); + hasSource = true; + } + } catch (java.io.IOException e) { + LogUtils.DEBUG("** Failed to read scriot from url " + e.toString()); } - protected boolean writeSourceFile() - { + + } + protected boolean writeSourceFile() { String sourceFilePath = parent.getPathToParcel() + "/" + getLanguageName(); boolean result = false; - try - { - XSimpleFileAccess2 xSFA2 = UnoRuntime.queryInterface( XSimpleFileAccess2.class, - parent.m_xSFA ); - if ( xSFA2 != null ) - { - ByteArrayInputStream bis = new ByteArrayInputStream( getSourceBytes() ); - XInputStreamImpl xis = new XInputStreamImpl( bis ); - xSFA2.writeFile( sourceFilePath, xis ); + + try { + XSimpleFileAccess2 xSFA2 = UnoRuntime.queryInterface(XSimpleFileAccess2.class, + parent.m_xSFA); + + if (xSFA2 != null) { + ByteArrayInputStream bis = new ByteArrayInputStream(getSourceBytes()); + XInputStreamImpl xis = new XInputStreamImpl(bis); + xSFA2.writeFile(sourceFilePath, xis); xis.closeInput(); result = true; } } // TODO re-examine exception processing should probably throw // exceptions back to caller - catch ( Exception ignore ) + catch (Exception ignore) { } + return result; } - protected boolean removeSourceFile() - { + protected boolean removeSourceFile() { String parcelLocation = parent.getPathToParcel(); String sourceFilePath = parcelLocation + "/" + getLanguageName(); boolean result = false; - try - { - parent.m_xSFA.kill( sourceFilePath ); + + try { + parent.m_xSFA.kill(sourceFilePath); result = true; } // TODO reexamine exception handling - catch ( Exception e ) - { + catch (Exception e) { } + return result; } - public URL getSourceURL() throws java.net.MalformedURLException - { + public URL getSourceURL() throws java.net.MalformedURLException { String sUrl = getParcelLocation(); - sUrl = PathUtils.make_url( sUrl, getLanguageName() ); - LogUtils.DEBUG("Creating script url for " + sUrl ); - return createURL( sUrl ); + sUrl = PathUtils.make_url(sUrl, getLanguageName()); + LogUtils.DEBUG("Creating script url for " + sUrl); + return createURL(sUrl); } } 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 be9dd42db9f1..9a338e06e35f 100644 --- a/scripting/java/com/sun/star/script/framework/container/UnoPkgContainer.java +++ b/scripting/java/com/sun/star/script/framework/container/UnoPkgContainer.java @@ -33,136 +33,128 @@ import com.sun.star.io.XOutputStream; import com.sun.star.io.XTruncate; import com.sun.star.deployment.XPackage; -public class UnoPkgContainer extends ParcelContainer -{ +public class UnoPkgContainer extends ParcelContainer { - private Map registeredPackages = new HashMap(); + private Map registeredPackages = new + HashMap(); private String extensionDb; private String extensionRepository; - public UnoPkgContainer( XComponentContext xCtx, String locationURL, - String _extensionDb, String _extensionRepository, String language ) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.lang.WrappedTargetException - { - super( xCtx, locationURL, language, false ); + public UnoPkgContainer(XComponentContext xCtx, String locationURL, + String _extensionDb, String _extensionRepository, + String language) throws com.sun.star.lang.IllegalArgumentException, + com.sun.star.lang.WrappedTargetException { + super(xCtx, locationURL, language, false); extensionDb = _extensionDb; extensionRepository = _extensionRepository; init(); } // gets the ParcelContainer for persisted uno packages - public ParcelContainer getRegisteredUnoPkgContainer( String url ) - { - if (!url.endsWith("/")) - { + public ParcelContainer getRegisteredUnoPkgContainer(String url) { + if (!url.endsWith("/")) { url += "/"; } - 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 ); + 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; } - public boolean hasRegisteredUnoPkgContainer( String url ) { - return getRegisteredUnoPkgContainer( url ) != null; + public boolean hasRegisteredUnoPkgContainer(String url) { + return getRegisteredUnoPkgContainer(url) != null; } - private void registerPackageContainer( String url, ParcelContainer c ) - { - if (!url.endsWith("/")) - { + private void registerPackageContainer(String url, ParcelContainer c) { + if (!url.endsWith("/")) { url += "/"; } - LogUtils.DEBUG("RegisterPackage ctx = " + containerUrl ); - LogUtils.DEBUG("RegisterPackage language = " + language ); - LogUtils.DEBUG("RegisterPackage " + c + " for url " + url ); - registeredPackages.put( url, c ); + LogUtils.DEBUG("RegisterPackage ctx = " + containerUrl); + LogUtils.DEBUG("RegisterPackage language = " + language); + LogUtils.DEBUG("RegisterPackage " + c + " for url " + url); + registeredPackages.put(url, c); } - public void deRegisterPackageContainer( String url ) - { - if (!url.endsWith("/")) - { + public void deRegisterPackageContainer(String url) { + if (!url.endsWith("/")) { url += "/"; } - LogUtils.DEBUG("In deRegisterPackageContainer for " + url ); - if ( hasRegisteredUnoPkgContainer( url ) ) - { - try - { + LogUtils.DEBUG("In deRegisterPackageContainer for " + url); + + if (hasRegisteredUnoPkgContainer(url)) { + try { DeployedUnoPackagesDB db = getUnoPackagesDB(); - if ( db != null ) - { - if ( db.removePackage( language, url ) ) - { - writeUnoPackageDB( db ); - ParcelContainer container = registeredPackages.get( url ); - if ( !container.hasElements() ) - { - // When all libraries within a package bundle - // ( for this language ) are removed also - // remove the container from its parent - // Otherwise, a container ( with no containees ) - // representing the uno package bundle will - // still exist and so will get displayed - if ( container.parent() != null ) - { - container.parent().removeChildContainer( container ); - } - } - registeredPackages.remove( url ); - } - } - } - catch (Exception e) - { - //TODO revisit exception handling and exception here - //means something very wrong - LogUtils.DEBUG("***** deRegisterPackageContainer() got exception " + e ); - } + + if (db != null) { + if (db.removePackage(language, url)) { + writeUnoPackageDB(db); + ParcelContainer container = registeredPackages.get(url); + + if (!container.hasElements()) { + // When all libraries within a package bundle + // ( for this language ) are removed also + // remove the container from its parent + // Otherwise, a container ( with no containees ) + // representing the uno package bundle will + // still exist and so will get displayed + if (container.parent() != null) { + container.parent().removeChildContainer(container); + } + } + + registeredPackages.remove(url); + } + } + } catch (Exception e) { + //TODO revisit exception handling and exception here + //means something very wrong + LogUtils.DEBUG("***** deRegisterPackageContainer() got exception " + e); + } } - LogUtils.DEBUG("Leaving deRegisterPackageContainer for " + url ); + + LogUtils.DEBUG("Leaving deRegisterPackageContainer for " + url); } - private void init() throws com.sun.star.lang.IllegalArgumentException - { - LogUtils.DEBUG("getting container for " + containerUrl ); - try - { + private void init() throws com.sun.star.lang.IllegalArgumentException { + LogUtils.DEBUG("getting container for " + containerUrl); + + try { DeployedUnoPackagesDB db = getUnoPackagesDB(); - if ( db != null ) - { - String[] packages = db.getDeployedPackages( language ); + + if (db != null) { + String[] packages = db.getDeployedPackages(language); + for (String thepackage : packages) { try { processUnoPackage(thepackage, language); } catch (com.sun.star.lang.IllegalArgumentException ila) { LogUtils.DEBUG("Failed to process " + thepackage + " for " + language); - LogUtils.DEBUG(" Reason: " + ila ); + 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(" Reason: " + e ); + LogUtils.DEBUG(" Reason: " + e); } } } - } - catch ( com.sun.star.lang.WrappedTargetException e ) - { + } catch (com.sun.star.lang.WrappedTargetException e) { // no deployed packages - LogUtils.DEBUG("No deployed uno-packages for " + containerUrl ); + LogUtils.DEBUG("No deployed uno-packages for " + containerUrl); } } @Override - public ScriptMetaData findScript( ParsedScriptUri psu ) throws com.sun.star.container.NoSuchElementException, com.sun.star.lang.WrappedTargetException + public ScriptMetaData findScript(ParsedScriptUri psu) throws + com.sun.star.container.NoSuchElementException, + com.sun.star.lang.WrappedTargetException { ScriptMetaData scriptData = null; @@ -172,70 +164,59 @@ public class UnoPkgContainer extends ParcelContainer String location = psu.location; LogUtils.DEBUG("*** UnoPkgContainer.findScript() ***" + - "\ncontainerUrl = " + containerUrl + - "\nfunction = " + functionName + - "\nlocation = " + location + - "\nparcel = " + parcelName ); + "\ncontainerUrl = " + containerUrl + + "\nfunction = " + functionName + + "\nlocation = " + location + + "\nparcel = " + parcelName); - ParcelContainer pc = getChildContainer( location ); + 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 ) ); + 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)); } - return pc.findScript( psu ); + return pc.findScript(psu); } - private DeployedUnoPackagesDB getUnoPackagesDB() throws com.sun.star.lang.WrappedTargetException - { + 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 ); - if ( m_xSFA.exists( packagesUrl ) ) - { - if ( packagesUrl.startsWith( "vnd.sun.star.tdoc" ) ) - { + + try { + 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"); } - is = new XInputStreamWrapper( m_xSFA.openFileRead( packagesUrl ) ); - dp = new DeployedUnoPackagesDB( is ); - try - { + is = new XInputStreamWrapper(m_xSFA.openFileRead(packagesUrl)); + dp = new DeployedUnoPackagesDB(is); + + try { is.close(); is = null; + } catch (Exception ignore) { } - catch ( Exception ignore ) - { - } - } - else - { + } else { LogUtils.DEBUG("getUnoPackagesDB() " + packagesUrl + " does not exist"); } - } - catch( Exception e ) - { - LogUtils.DEBUG("getUnoPackagesDB() caught Exception: " + e ); - LogUtils.DEBUG( LogUtils.getTrace( e ) ); + } catch (Exception e) { + LogUtils.DEBUG("getUnoPackagesDB() caught Exception: " + e); + LogUtils.DEBUG(LogUtils.getTrace(e)); throw new com.sun.star.lang.WrappedTargetException(e); - } - finally - { - if ( is != null ) - { - try - { + } finally { + if (is != null) { + try { is.close(); is = null; - } - catch ( Exception ignore ) - { + } catch (Exception ignore) { } } } @@ -243,160 +224,151 @@ public class UnoPkgContainer extends ParcelContainer return dp; } - private void writeUnoPackageDB( DeployedUnoPackagesDB dp ) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.lang.WrappedTargetException - { + 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" ); - xos = m_xSFA.openFileWrite( packagesUrl ); - XTruncate xTrc = UnoRuntime.queryInterface( XTruncate.class, xos ); - if ( xTrc != null ) - { - LogUtils.DEBUG("In writeUnoPackageDB() Truncating...." ); + + try { + String packagesUrl = PathUtils.make_url(extensionDb, + "/Scripts/" + extensionRepository + "-extension-desc.xml"); + xos = m_xSFA.openFileWrite(packagesUrl); + XTruncate xTrc = UnoRuntime.queryInterface(XTruncate.class, xos); + + if (xTrc != null) { + LogUtils.DEBUG("In writeUnoPackageDB() Truncating...."); xTrc.truncate(); + } else { + LogUtils.DEBUG("In writeUnoPackageDB() CAN'T Truncate...."); } - else - { - LogUtils.DEBUG("In writeUnoPackageDB() CAN'T Truncate...." ); - } - os = new XOutputStreamWrapper( xos ); - dp.write( os ); - try - { + + os = new XOutputStreamWrapper(xos); + dp.write(os); + + try { os.close(); // will close xos os = null; + } catch (Exception ignore) { } - catch( Exception ignore ) - { - } - } - catch( Exception e ) - { - LogUtils.DEBUG("In writeUnoPackageDB() Exception: " + e ); + } catch (Exception e) { + LogUtils.DEBUG("In writeUnoPackageDB() Exception: " + e); throw new com.sun.star.lang.WrappedTargetException(e); - } - finally - { - if ( os != null ) - { - try - { + } finally { + if (os != null) { + try { os.close(); // will close xos os = null; - } - catch ( Exception ignore ) - { + } catch (Exception ignore) { } } } } - public void processUnoPackage( XPackage dPackage, String language ) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.lang.WrappedTargetException, com.sun.star.container.ElementExistException - { - LogUtils.DEBUG("** in processUnoPackage " ); + public void processUnoPackage(XPackage dPackage, + 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( "/" ) ) - { + if (!uri.endsWith("/")) { uri += "/"; } - LogUtils.DEBUG("** processUnoPackage getURL() -> " + uri ); - LogUtils.DEBUG("** processUnoPackage getName() -> " + dPackage.getName() ); - LogUtils.DEBUG("** processUnoPackage getMediaType() -> " + dPackage.getPackageType().getMediaType() ); - try - { - LogUtils.DEBUG("** processUnoPackage getDisplayName() -> " + dPackage.getDisplayName() ); - } - catch (com.sun.star.deployment.ExtensionRemovedException e) - { + LogUtils.DEBUG("** processUnoPackage getURL() -> " + uri); + LogUtils.DEBUG("** processUnoPackage getName() -> " + dPackage.getName()); + LogUtils.DEBUG("** processUnoPackage getMediaType() -> " + + dPackage.getPackageType().getMediaType()); + + try { + LogUtils.DEBUG("** processUnoPackage getDisplayName() -> " + + dPackage.getDisplayName()); + } catch (com.sun.star.deployment.ExtensionRemovedException e) { throw new com.sun.star.lang.WrappedTargetException(e.getMessage(), this, e); } - processUnoPackage( uri, language ); + processUnoPackage(uri, language); DeployedUnoPackagesDB db = getUnoPackagesDB(); - if ( db == null ) - { - try - { + + if (db == null) { + try { db = new DeployedUnoPackagesDB(); - } - catch ( java.io.IOException ioe ) - { + } catch (java.io.IOException ioe) { throw new com.sun.star.lang.WrappedTargetException(ioe); } } - db.addPackage( language, uri ); - writeUnoPackageDB( db ); + + db.addPackage(language, uri); + writeUnoPackageDB(db); } - private void processUnoPackage( String uri, 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 ); + private void processUnoPackage(String uri, + 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); } - LogUtils.DEBUG("processUnoPackage - URL = " + uri ); + + LogUtils.DEBUG("processUnoPackage - URL = " + uri); LogUtils.DEBUG("processUnoPackage - script library package"); String parentUrl = uri; - if ( uri.contains("%2Funo_packages%2F") || - uri.contains("/uno_packages/") || - uri.contains("$UNO_USER_PACKAGES_CACHE/") || - uri.contains("$UNO_SHARED_PACKAGES_CACHE/") || - uri.contains("$BUNDLED_EXTENSIONS/") ) - { + if (uri.contains("%2Funo_packages%2F") || + uri.contains("/uno_packages/") || + 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"); int index = uri.lastIndexOf('/'); - if ( uri.endsWith("/") ) - { - uri = uri.substring( 0, index ); + + if (uri.endsWith("/")) { + uri = uri.substring(0, index); index = uri.lastIndexOf('/'); } - if ( index > -1 ) - { - parentUrl = uri.substring( 0, index ); + if (index > -1) { + parentUrl = uri.substring(0, index); LogUtils.DEBUG("processUnoPackage - composition is contained in " + parentUrl); } - ParcelContainer pkgContainer = getChildContainerForURL( parentUrl ); - if ( pkgContainer == null ) - { - 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 ); + ParcelContainer pkgContainer = getChildContainerForURL(parentUrl); + + if (pkgContainer == null) { + 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); } - 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 ); + + 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); } } - registerPackageContainer( uri, pkgContainer ); - } - else - { + + registerPackageContainer(uri, pkgContainer); + } else { // 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 ); + if (loadParcel(uri) == null) { + throw new com.sun.star.lang.IllegalArgumentException("Couldn't load script library package " + + uri + " for language " + language); } - registerPackageContainer( uri, this ); + + registerPackageContainer(uri, this); } } 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 00d39a6c3332..9e17b2c68822 100644 --- a/scripting/java/com/sun/star/script/framework/container/XMLParserFactory.java +++ b/scripting/java/com/sun/star/script/framework/container/XMLParserFactory.java @@ -39,6 +39,7 @@ public class XMLParserFactory { public static synchronized XMLParser getParser() { if (parser == null) parser = new DefaultParser(); + return parser; } @@ -69,16 +70,14 @@ public class XMLParserFactory { } result = builder.parse(is); - } - catch (SAXParseException spe) { + } catch (SAXParseException spe) { throw new IOException(spe.getMessage()); - } - catch (SAXException se) { + } catch (SAXException se) { throw new IOException(se.getMessage()); - } - catch (ParserConfigurationException pce) { + } catch (ParserConfigurationException pce) { throw new IOException(pce.getMessage()); } + return result; } @@ -97,10 +96,9 @@ public class XMLParserFactory { // these DOM implementations are self writing Method write; write = clazz.getDeclaredMethod("write", - new Class[] {OutputStream.class}); + new Class[] {OutputStream.class}); write.invoke(doc, new Object[] {out}); - } - else { + } else { // try xerces serialize package using introspection ClassLoader cl = this.getClass().getClassLoader(); @@ -109,16 +107,16 @@ public class XMLParserFactory { try { serializerClass = Class.forName( - "org.apache.xml.serialize.XMLSerializer", true, cl); + "org.apache.xml.serialize.XMLSerializer", true, cl); formatterClass = Class.forName( - "org.apache.xml.serialize.OutputFormat", true, cl); + "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); + prefix + "serialize.XMLSerializer" , true, cl); formatterClass = Class.forName( - prefix + "serialize.OutputFormat", true, cl); + prefix + "serialize.OutputFormat", true, cl); } Object serializerObject = serializerClass.newInstance(); @@ -126,29 +124,29 @@ public class XMLParserFactory { // improve output readability using the OutputFormat class Method method = formatterClass.getMethod("setMethod", - new Class[] {String.class}); + new Class[] {String.class}); method.invoke(formatterObject, new Object[] {"xml"}); method = formatterClass.getMethod("setIndenting", - new Class[] {Boolean.TYPE}); + 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}); + new Class[] {OutputStream.class}); method.invoke(serializerObject, new Object[] {out}); method = serializerClass.getMethod("setOutputFormat", - new Class[] {formatterClass}); + new Class[] {formatterClass}); method.invoke(serializerObject, - new Object[] {formatterObject}); + new Object[] {formatterObject}); method = serializerClass.getMethod("asDOMSerializer", - new Class[0]); + new Class[0]); Object impl = method.invoke(serializerObject, - new Object[0]); + new Object[0]); method = impl.getClass().getMethod("serialize", - new Class[] {Document.class}); + new Class[] {Document.class}); method.invoke(impl, new Object[] {doc}); } } catch (NoSuchMethodException ex) { 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 33bb67419eea..e4a715060d73 100644 --- a/scripting/java/com/sun/star/script/framework/io/UCBStreamHandler.java +++ b/scripting/java/com/sun/star/script/framework/io/UCBStreamHandler.java @@ -36,28 +36,30 @@ public class UCBStreamHandler extends URLStreamHandler { public final static String separator = "/ucb/"; private XSimpleFileAccess m_xSimpleFileAccess = null; - private HashMap m_jarStreamMap = new HashMap(12); + private HashMap m_jarStreamMap = new + HashMap(12); private static String m_ucbscheme; - public UCBStreamHandler( String scheme, XSimpleFileAccess xSFA ) - { - LogUtils.DEBUG( "UCBStreamHandler ctor, scheme = " + scheme ); + public UCBStreamHandler(String scheme, XSimpleFileAccess xSFA) { + LogUtils.DEBUG("UCBStreamHandler ctor, scheme = " + scheme); UCBStreamHandler.m_ucbscheme = scheme; this.m_xSimpleFileAccess = xSFA; } @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(); + if (file == null) file = spec.substring(start, limit); else file += spec.substring(start, limit); - LogUtils.DEBUG("**For scheme = " + m_ucbscheme ); - LogUtils.DEBUG("**Setting path = " + file ); + LogUtils.DEBUG("**For scheme = " + m_ucbscheme); + LogUtils.DEBUG("**Setting path = " + file); setURL(url, m_ucbscheme, null, -1, null, null, file, null, null); } @@ -78,73 +80,73 @@ public class UCBStreamHandler extends URLStreamHandler { @Override public InputStream getInputStream() throws IOException { - LogUtils.DEBUG("UCBConnectionHandler GetInputStream on " + url ); + LogUtils.DEBUG("UCBConnectionHandler GetInputStream on " + url); String sUrl = url.toString(); + if (sUrl.lastIndexOf(separator) == -1) { - LogUtils.DEBUG("getInputStream straight file load" ); + LogUtils.DEBUG("getInputStream straight file load"); return getFileStreamFromUCB(sUrl); - } - else { - String path = sUrl.substring(0, sUrl.lastIndexOf(separator) ); + } 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 ); + sUrl.lastIndexOf(separator) + separator.length()); + LogUtils.DEBUG("getInputStream, load of file from another file eg. " + file + + " from " + path); return getUCBStream(file, path); } } @Override public OutputStream getOutputStream() throws IOException { - LogUtils.DEBUG("UCBConnectionHandler getOutputStream on " + url ); + LogUtils.DEBUG("UCBConnectionHandler getOutputStream on " + url); OutputStream os = null; - try - { + + try { String sUrl = url.toString(); - if ( !( sUrl.lastIndexOf(separator) == -1) ) { + + if (!(sUrl.lastIndexOf(separator) == -1)) { String path = sUrl.substring(0, sUrl.lastIndexOf(separator)); - if ( m_xSimpleFileAccess.isReadOnly( path ) ) - { + if (m_xSimpleFileAccess.isReadOnly(path)) { 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 ); - if ( xtrunc != null ) - { + XOutputStream xos = m_xSimpleFileAccess.openFileWrite(path); + XTruncate xtrunc = UnoRuntime.queryInterface(XTruncate.class, xos); + + if (xtrunc != null) { xtrunc.truncate(); } - os = new XOutputStreamWrapper( xos ); + + os = new XOutputStreamWrapper(xos); } - if ( os == null ) - { - throw new IOException("Failed to get OutputStream for " + sUrl ); + + if (os == null) { + throw new IOException("Failed to get OutputStream for " + sUrl); } - } - catch ( com.sun.star.ucb.CommandAbortedException cae ) - { - LogUtils.DEBUG("caught exception: " + cae.toString() + " getting writable stream from " + url ); + } catch (com.sun.star.ucb.CommandAbortedException cae) { + LogUtils.DEBUG("caught exception: " + cae.toString() + + " getting writable stream from " + url); IOException newEx = new IOException(cae.getMessage()); newEx.initCause(cae); throw newEx; - } - catch ( com.sun.star.uno.Exception e ) - { - LogUtils.DEBUG("caught unknown exception: " + e.toString() + " getting writable stream from " + url ); + } catch (com.sun.star.uno.Exception e) { + LogUtils.DEBUG("caught unknown exception: " + e.toString() + + " getting writable stream from " + url); IOException newEx = new IOException(e.getMessage()); newEx.initCause(e); throw newEx; } + return os; } } private InputStream getUCBStream(String file, String path) - throws IOException - { + throws IOException { InputStream is = null; InputStream result = null; @@ -155,42 +157,37 @@ public class UCBStreamHandler extends URLStreamHandler { if (is == null) { is = getFileStreamFromUCB(path); m_jarStreamMap.put(path, is); - } - else { + } else { try { is.reset(); - } - catch (IOException e) { + } catch (IOException e) { is.close(); is = getFileStreamFromUCB(path); m_jarStreamMap.put(path, is); } } + result = getFileStreamFromJarStream(file, is); - } - else - { - String fileUrl = PathUtils.make_url(path,file); + } else { + String fileUrl = PathUtils.make_url(path, file); result = getFileStreamFromUCB(fileUrl); } - } - finally { + } finally { if (is != null) { try { is.close(); - } - catch (IOException ioe) { + } catch (IOException ioe) { LogUtils.DEBUG("Caught exception closing stream: " + - ioe.getMessage()); + ioe.getMessage()); } } } + return result; } private InputStream getFileStreamFromJarStream(String file, InputStream is) - throws IOException - { + throws IOException { ZipEntry entry; ZipInputStream zis = new ZipInputStream(is); @@ -202,33 +199,33 @@ public class UCBStreamHandler extends URLStreamHandler { return zis; } } + return null; } private InputStream getFileStreamFromUCB(String path) - throws IOException - { + throws IOException { InputStream result = null; XInputStream xInputStream = null; try { - LogUtils.DEBUG("Trying to read from " + path ); + LogUtils.DEBUG("Trying to read from " + path); xInputStream = m_xSimpleFileAccess.openFileRead(path); - LogUtils.DEBUG("sfa appeared to read file " ); + LogUtils.DEBUG("sfa appeared to read file "); byte[][] inputBytes = new byte[1][]; int sz = m_xSimpleFileAccess.getSize(path); + // TODO don't depend on result of available() or size() // just read stream 'till complete - if ( sz == 0 ) - { - if ( xInputStream.available() > 0 ) - { + if (sz == 0) { + if (xInputStream.available() > 0) { sz = xInputStream.available(); } } - LogUtils.DEBUG("size of file " + path + " is " + sz ); - LogUtils.DEBUG("available = " + xInputStream.available() ); + + LogUtils.DEBUG("size of file " + path + " is " + sz); + LogUtils.DEBUG("available = " + xInputStream.available()); inputBytes[0] = new byte[sz]; int ln = xInputStream.readBytes(inputBytes, sz); @@ -239,27 +236,23 @@ public class UCBStreamHandler extends URLStreamHandler { } result = new ByteArrayInputStream(inputBytes[0]); - } - catch (com.sun.star.io.IOException ioe) { - LogUtils.DEBUG("caught exception " + ioe ); + } catch (com.sun.star.io.IOException ioe) { + LogUtils.DEBUG("caught exception " + ioe); throw new IOException(ioe.getMessage()); - } - catch (com.sun.star.uno.Exception e) { - LogUtils.DEBUG("caught exception " + e ); + } catch (com.sun.star.uno.Exception e) { + LogUtils.DEBUG("caught exception " + e); throw new IOException(e.getMessage()); - } - finally - { + } finally { if (xInputStream != null) { try { xInputStream.closeInput(); - } - catch (Exception e2) { + } catch (Exception e2) { LogUtils.DEBUG( "Error closing XInputStream:" + e2.getMessage()); } } } + return result; } 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 801cb0d4be3a..19d9c508923e 100644 --- a/scripting/java/com/sun/star/script/framework/io/XInputStreamImpl.java +++ b/scripting/java/com/sun/star/script/framework/io/XInputStreamImpl.java @@ -23,86 +23,78 @@ import java.io.InputStream; import com.sun.star.io.XInputStream; -public class XInputStreamImpl implements XInputStream -{ +public class XInputStreamImpl implements XInputStream { private InputStream is; - public XInputStreamImpl( InputStream is ) - { + public XInputStreamImpl(InputStream is) { this.is = is; } - 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 - { + 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 ]; int totalBytesRead = 0; - try - { + try { int bytesRead; - while ( ( bytesRead = is.read( aData[ 0 ], totalBytesRead, nBytesToRead ) ) > 0 && ( totalBytesRead < nBytesToRead ) ) - { + + while ((bytesRead = is.read(aData[ 0 ], totalBytesRead, nBytesToRead)) > 0 + && (totalBytesRead < nBytesToRead)) { totalBytesRead += bytesRead; nBytesToRead -= bytesRead; } - } - catch ( IOException e ) - { + } catch (IOException e) { throw new com.sun.star.io.IOException(e); - } - catch ( IndexOutOfBoundsException aie ) - { + } catch (IndexOutOfBoundsException aie) { throw new com.sun.star.io.BufferSizeExceededException(aie); } + return totalBytesRead; } - 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 - { + 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(); - if ( availableBytes < nMaxBytesToRead ) - { + + if (availableBytes < nMaxBytesToRead) { bytesToRead = availableBytes; } - int read = readBytes( aData, bytesToRead ); + + int read = readBytes(aData, bytesToRead); return read; } - 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 ) - { + 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) { throw new com.sun.star.io.IOException(e); } } - 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 - { + + try { bytesAvail = is.available(); - } - catch ( IOException e ) - { + } catch (IOException e) { throw new com.sun.star.io.IOException(e); } + return bytesAvail; } - public void closeInput( ) throws com.sun.star.io.NotConnectedException, com.sun.star.io.IOException - { - try - { + public void closeInput() throws com.sun.star.io.NotConnectedException, + com.sun.star.io.IOException { + try { is.close(); - } - catch( IOException e ) - { + } catch (IOException e) { throw new com.sun.star.io.IOException(e); } } 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 a1e27793f4f1..8da2bb27ff1b 100644 --- a/scripting/java/com/sun/star/script/framework/io/XInputStreamWrapper.java +++ b/scripting/java/com/sun/star/script/framework/io/XInputStreamWrapper.java @@ -28,69 +28,59 @@ public class XInputStreamWrapper extends InputStream { } @Override - public int read() throws java.io.IOException - { + public int read() throws java.io.IOException { byte[][] byteRet = new byte[1][0]; long numRead; try { numRead = m_xInputStream.readBytes(byteRet, 1); - } - catch (com.sun.star.io.IOException ioe) { + } catch (com.sun.star.io.IOException ioe) { throw new java.io.IOException(ioe.getMessage()); } if (numRead != 1) { return -1; } + return byteRet[0][0]; } @Override - public int read( byte[] b ) throws java.io.IOException - { + public int read(byte[] b) throws java.io.IOException { byte[][] byteRet = new byte[1][]; byteRet[0] = b; - try - { - return m_xInputStream.readBytes( byteRet, b.length ); - } - catch ( com.sun.star.io.IOException ioe) - { + + try { + return m_xInputStream.readBytes(byteRet, b.length); + } catch (com.sun.star.io.IOException ioe) { throw new java.io.IOException(ioe.getMessage()); } } @Override - public long skip(long n) throws java.io.IOException - { + public long skip(long n) throws java.io.IOException { try { m_xInputStream.skipBytes((int)n); return n; - } - catch (com.sun.star.io.IOException ioe) { + } catch (com.sun.star.io.IOException ioe) { throw new java.io.IOException(ioe.getMessage()); } } @Override - public int available() throws java.io.IOException - { + public int available() throws java.io.IOException { try { return m_xInputStream.available(); - } - catch (com.sun.star.io.IOException ioe) { + } catch (com.sun.star.io.IOException ioe) { throw new java.io.IOException(ioe.getMessage()); } } @Override - public void close() throws java.io.IOException - { + public void close() throws java.io.IOException { try { m_xInputStream.closeInput(); - } - catch (com.sun.star.io.IOException ioe) { + } catch (com.sun.star.io.IOException ioe) { throw new java.io.IOException(ioe.getMessage()); } } 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 b1c663c54a7c..1d54b136811f 100644 --- a/scripting/java/com/sun/star/script/framework/io/XOutputStreamWrapper.java +++ b/scripting/java/com/sun/star/script/framework/io/XOutputStreamWrapper.java @@ -21,101 +21,83 @@ import com.sun.star.io.XOutputStream; public class XOutputStreamWrapper extends OutputStream { - private XOutputStream m_xOutputStream; - public XOutputStreamWrapper(XOutputStream xOs ) { - this.m_xOutputStream = xOs; + private XOutputStream m_xOutputStream; + public XOutputStreamWrapper(XOutputStream xOs) { + this.m_xOutputStream = xOs; + } + @Override + public void write(int b) + throws java.io.IOException { + if (m_xOutputStream == null) { + throw new java.io.IOException("Stream is null"); + } + + byte[] bytes = new byte[1]; + bytes[0] = (byte) b; + + try { + m_xOutputStream.writeBytes(bytes); + } catch (com.sun.star.io.IOException ioe) { + throw new java.io.IOException(ioe.getMessage()); + } + } + @Override + public void write(byte[] b) + throws java.io.IOException { + + if (m_xOutputStream == null) { + throw new java.io.IOException("Stream is null"); + } + + try { + m_xOutputStream.writeBytes(b); + } catch (com.sun.star.io.IOException ioe) { + throw new java.io.IOException(ioe.getMessage()); } - @Override - public void write(int b) - throws java.io.IOException - { - if ( m_xOutputStream == null ) - { - throw new java.io.IOException("Stream is null"); - } - byte[] bytes = new byte[1]; - bytes[0] = (byte) b; - try - { - m_xOutputStream.writeBytes( bytes ); - } - catch ( com.sun.star.io.IOException ioe ) - { - throw new java.io.IOException(ioe.getMessage()); - } + } + @Override + 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"); } - @Override - public void write(byte[] b) - throws java.io.IOException - { - if ( m_xOutputStream == null ) - { - throw new java.io.IOException( "Stream is null" ); - } - try - { - m_xOutputStream.writeBytes( b ); - } - catch ( com.sun.star.io.IOException ioe ) - { - throw new java.io.IOException(ioe.getMessage()); - } + byte[] bytes = new byte[len]; + System.arraycopy(b, off, bytes, 0, len); + + try { + m_xOutputStream.writeBytes(bytes); + } catch (com.sun.star.io.IOException ioe) { + throw new java.io.IOException(ioe.getMessage()); } - @Override - 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" ); - } - byte[] bytes = new byte[len]; - System.arraycopy(b, off, bytes, 0, len); - try - { - m_xOutputStream.writeBytes(bytes); - } - catch ( com.sun.star.io.IOException ioe ) - { - throw new java.io.IOException(ioe.getMessage()); - } + } + + @Override + public void flush() + throws java.io.IOException { + if (m_xOutputStream == null) { + throw new java.io.IOException("Stream is null"); } - @Override - public void flush() - throws java.io.IOException - { - if ( m_xOutputStream == null ) - { - throw new java.io.IOException( "Stream is null" ); - } - try - { - m_xOutputStream.flush(); - } - catch ( com.sun.star.io.IOException ioe ) - { - throw new java.io.IOException(ioe.getMessage()); - } + try { + m_xOutputStream.flush(); + } catch (com.sun.star.io.IOException ioe) { + throw new java.io.IOException(ioe.getMessage()); } - @Override - public void close() - throws java.io.IOException - { - if ( m_xOutputStream == null ) - { - throw new java.io.IOException( "Stream is null" ); - } - try - { - m_xOutputStream.closeOutput(); - } - catch ( com.sun.star.io.IOException ioe ) - { - throw new java.io.IOException(ioe.getMessage()); - } + } + @Override + public void close() + throws java.io.IOException { + if (m_xOutputStream == null) { + throw new java.io.IOException("Stream is null"); } + try { + m_xOutputStream.closeOutput(); + } catch (com.sun.star.io.IOException ioe) { + throw new java.io.IOException(ioe.getMessage()); + } } +} + 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 c936aacfae07..aed57aee66f7 100644 --- a/scripting/java/com/sun/star/script/framework/io/XStorageHelper.java +++ b/scripting/java/com/sun/star/script/framework/io/XStorageHelper.java @@ -50,182 +50,158 @@ import java.util.*; import java.io.*; -public class XStorageHelper implements XEventListener -{ +public class XStorageHelper implements XEventListener { XStorage[] xStorages; XStream xStream; XInputStream xIs = null; XOutputStream xOs = null; - static Map modelMap = new HashMap(); + static Map modelMap = new HashMap(); XModel xModel = null; private static XStorageHelper listener = new XStorageHelper(); private XStorageHelper() {} - public XStorageHelper( String path, int mode, boolean create ) throws IOException - { + public XStorageHelper(String path, int mode, + boolean create) throws IOException { String modelUrl = null; - int indexOfScriptsDir = path.lastIndexOf( "Scripts" ); - if ( indexOfScriptsDir > -1 ) - { - modelUrl = path.substring( 0, indexOfScriptsDir - 1 ); - path = path.substring( indexOfScriptsDir, path.length()); + int indexOfScriptsDir = path.lastIndexOf("Scripts"); + + if (indexOfScriptsDir > -1) { + modelUrl = path.substring(0, indexOfScriptsDir - 1); + path = path.substring(indexOfScriptsDir, path.length()); } LogUtils.DEBUG("XStorageHelper ctor, path: " + path); - this.xModel = getModelForURL( modelUrl ); + this.xModel = getModelForURL(modelUrl); - try - { + try { StringTokenizer tokens = new StringTokenizer(path, "/"); - if (tokens.countTokens() == 0) - { - throw new IOException("Invalid path"); + if (tokens.countTokens() == 0) { + throw new IOException("Invalid path"); } + XDocumentSubStorageSupplier xDocumentSubStorageSupplier = UnoRuntime.queryInterface( - XDocumentSubStorageSupplier.class, xModel); + XDocumentSubStorageSupplier.class, xModel); xStorages = new XStorage[tokens.countTokens() ]; - LogUtils.DEBUG("XStorageHelper ctor, path chunks length: " + xStorages.length ); + LogUtils.DEBUG("XStorageHelper ctor, path chunks length: " + xStorages.length); - for ( int i = 0; i < xStorages.length; i++ ) - { - LogUtils.DEBUG("XStorageHelper, processing index " + i ); + for (int i = 0; i < xStorages.length; i++) { + LogUtils.DEBUG("XStorageHelper, processing index " + i); String name = tokens.nextToken(); LogUtils.DEBUG("XStorageHelper, getting: " + name); XStorage storage = null; - if ( i == 0 ) - { - storage = xDocumentSubStorageSupplier.getDocumentSubStorage( name, mode ); - if ( storage == null ) - { - LogUtils.DEBUG("** boo hoo Storage is null " ); + + if (i == 0) { + storage = xDocumentSubStorageSupplier.getDocumentSubStorage(name, mode); + + if (storage == null) { + LogUtils.DEBUG("** boo hoo Storage is null "); } - XPropertySet xProps = UnoRuntime.queryInterface(XPropertySet.class,storage ); - if ( xProps != null ) - { - String mediaType = AnyConverter.toString( xProps.getPropertyValue( "MediaType" ) ); - LogUtils.DEBUG("***** media type is " + mediaType ); - if ( !mediaType.equals("scripts") ) - { - xProps.setPropertyValue("MediaType","scripts"); + + XPropertySet xProps = UnoRuntime.queryInterface(XPropertySet.class, storage); + + if (xProps != null) { + String mediaType = AnyConverter.toString(xProps.getPropertyValue("MediaType")); + LogUtils.DEBUG("***** media type is " + mediaType); + + if (!mediaType.equals("scripts")) { + xProps.setPropertyValue("MediaType", "scripts"); } } - } - else - { - XNameAccess xNameAccess = UnoRuntime.queryInterface(XNameAccess.class, xStorages[i-1]); - if (xNameAccess == null ) - { + } else { + XNameAccess xNameAccess = UnoRuntime.queryInterface(XNameAccess.class, + xStorages[i - 1]); + + if (xNameAccess == null) { disposeObject(); throw new IOException("No name access " + name); - } - else if ( !xNameAccess.hasByName(name) || !xStorages[i-1].isStorageElement(name) ) - { - if ( !create ) - { + } else if (!xNameAccess.hasByName(name) + || !xStorages[i - 1].isStorageElement(name)) { + if (!create) { disposeObject(); throw new IOException("No subdir: " + name); - } - else - { + } else { // attempt to create new storage - LogUtils.DEBUG("Attempt to create new storage for " + name ); + LogUtils.DEBUG("Attempt to create new storage for " + name); } } - storage = xStorages[i-1].openStorageElement( - name, mode ); + storage = xStorages[i - 1].openStorageElement( + name, mode); } - if ( storage == null ) - { + + if (storage == null) { disposeObject(); throw new IOException("storage not found: " + name); } + xStorages[ i ] = storage; } - } - catch ( com.sun.star.io.IOException ioe) - { + } catch (com.sun.star.io.IOException ioe) { disposeObject(); - } - catch (com.sun.star.uno.Exception e) - { + } catch (com.sun.star.uno.Exception e) { disposeObject(); throw new IOException(e.getMessage()); } } - public synchronized static void addNewModel( XModel model ) - { + public synchronized static void addNewModel(XModel model) { // TODO needs to cater for model for untitled document - modelMap.put( PathUtils.getOidForModel( model ), model ); + modelMap.put(PathUtils.getOidForModel(model), model); XComponent xComp = UnoRuntime.queryInterface(XComponent.class, model); - if ( xComp != null ) - { - try - { - xComp.addEventListener( listener ); - } - catch ( Exception e ) - { + if (xComp != null) { + try { + xComp.addEventListener(listener); + } catch (Exception e) { // What TODO here ? - LogUtils.DEBUG( LogUtils.getTrace( e ) ); + LogUtils.DEBUG(LogUtils.getTrace(e)); } } } - public void disposing( EventObject Source ) - { - XModel model = UnoRuntime.queryInterface(XModel.class,Source.Source ); + public void disposing(EventObject Source) { + XModel model = UnoRuntime.queryInterface(XModel.class, Source.Source); - if ( model != null ) - { - LogUtils.DEBUG(" Disposing doc " + model.getURL() ); - modelMap.remove( model ); + if (model != null) { + LogUtils.DEBUG(" Disposing doc " + model.getURL()); + modelMap.remove(model); } } - public XStorage getStorage() - { + public XStorage getStorage() { return xStorages[ xStorages.length - 1 ]; } - public XModel getModel() - { + public XModel getModel() { return xModel; } - public void disposeObject() - { - disposeObject( false ); + public void disposeObject() { + disposeObject(false); } - public void disposeObject( boolean shouldCommit ) - { + public void disposeObject(boolean shouldCommit) { LogUtils.DEBUG("In disposeObject"); - for ( int i = xStorages.length -1 ; i > -1; i-- ) - { - LogUtils.DEBUG("In disposeObject disposing storage " + i ); - try - { + for (int i = xStorages.length - 1 ; i > -1; i--) { + LogUtils.DEBUG("In disposeObject disposing storage " + i); + + try { XStorage xStorage = xStorages[i]; - if ( shouldCommit ) - { + + if (shouldCommit) { commit(xStorage); } + disposeObject(xStorage); - LogUtils.DEBUG("In disposeObject disposed storage " + i ); - } - catch( Exception ignore ) - { - LogUtils.DEBUG("Exception disposing storage " + i ); + LogUtils.DEBUG("In disposeObject disposed storage " + i); + } catch (Exception ignore) { + LogUtils.DEBUG("Exception disposing storage " + i); } } } - static public void disposeObject( XInterface xInterface ) - { + static public void disposeObject(XInterface xInterface) { if (xInterface == null) { return; } @@ -235,28 +211,25 @@ public class XStorageHelper implements XEventListener if (xComponent == null) { return; } + xComponent.dispose(); } - static public void commit( XInterface xInterface ) - { - XTransactedObject xTrans = UnoRuntime.queryInterface(XTransactedObject.class, xInterface); - if ( xTrans != null ) - { - try - { + static public void commit(XInterface xInterface) { + XTransactedObject xTrans = UnoRuntime.queryInterface(XTransactedObject.class, + xInterface); + + if (xTrans != null) { + try { xTrans.commit(); - } - catch ( Exception e ) - { - LogUtils.DEBUG("Something went bellyup exception: " + e ); + } catch (Exception e) { + LogUtils.DEBUG("Something went bellyup exception: " + e); } } } - public XModel getModelForURL( String url ) - { - //TODO does not cater for untitled documents - return modelMap.get( url ); + public XModel getModelForURL(String url) { + //TODO does not cater for untitled documents + return modelMap.get(url); } } 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 0344db864214..e6ed7ff61dbe 100644 --- a/scripting/java/com/sun/star/script/framework/log/LogUtils.java +++ b/scripting/java/com/sun/star/script/framework/log/LogUtils.java @@ -25,13 +25,11 @@ public class LogUtils { private static boolean m_bDebugEnabled = false; - static - { + static { String debugFlag = System.getProperties().getProperty("ScriptJavaRuntimeDebug"); - if (debugFlag != null && debugFlag.length() > 0) - { + if (debugFlag != null && debugFlag.length() > 0) { m_bDebugEnabled = debugFlag.equalsIgnoreCase("true"); } } @@ -45,42 +43,34 @@ public class LogUtils { * * @param msg message to be displayed */ - public static void DEBUG(String msg) - { - if (m_bDebugEnabled) - { + public static void DEBUG(String msg) { + if (m_bDebugEnabled) { System.out.println(msg); } } - public static String getTrace( Exception e ) - { + public static String getTrace(Exception e) { ByteArrayOutputStream baos = null; PrintStream ps = null; String result = ""; - try - { - baos = new ByteArrayOutputStream( ); - ps = new PrintStream( baos ); - e.printStackTrace( ps ); - } - finally - { - try - { - if ( baos != null ) - { + + try { + baos = new ByteArrayOutputStream(); + ps = new PrintStream(baos); + e.printStackTrace(ps); + } finally { + try { + if (baos != null) { baos.close(); } - if ( ps != null ) - { + + if (ps != null) { ps.close(); } - } - catch ( Exception excp ) - { + } catch (Exception excp) { } } + return result; } } 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 823f2ff731e7..73f3f9c38fd9 100644 --- a/scripting/java/com/sun/star/script/framework/provider/ClassLoaderFactory.java +++ b/scripting/java/com/sun/star/script/framework/provider/ClassLoaderFactory.java @@ -26,24 +26,23 @@ import com.sun.star.script.framework.container.ScriptMetaData; /** * Class Loader Factory */ -public class ClassLoaderFactory -{ +public class ClassLoaderFactory { private ClassLoaderFactory() {} - public static ClassLoader getURLClassLoader( ScriptMetaData scriptData ) - { + public static ClassLoader getURLClassLoader(ScriptMetaData scriptData) { ClassLoader parent = scriptData.getClass().getClassLoader(); URL[] classPath = scriptData.getClassPath(); - LogUtils.DEBUG("Classpath has length " + classPath.length ); - for ( int i=0; i < classPath.length; i++ ) - { - LogUtils.DEBUG("ClassPath " + i + "} is " + classPath[ i ].toString() ); + LogUtils.DEBUG("Classpath has length " + classPath.length); + + for (int i = 0; i < classPath.length; i++) { + LogUtils.DEBUG("ClassPath " + i + "} is " + classPath[ i ].toString()); } - return getURLClassLoader( parent, classPath ); + + return getURLClassLoader(parent, classPath); } - private static ClassLoader getURLClassLoader( ClassLoader parent, URL[] classpath) - { - return new URLClassLoader( classpath, parent); + private static ClassLoader getURLClassLoader(ClassLoader parent, + URL[] classpath) { + return new URLClassLoader(classpath, parent); } } 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 994a62700db0..5755e8cd6a28 100644 --- a/scripting/java/com/sun/star/script/framework/provider/EditorScriptContext.java +++ b/scripting/java/com/sun/star/script/framework/provider/EditorScriptContext.java @@ -25,13 +25,11 @@ import com.sun.star.document.XScriptInvocationContext; import com.sun.star.script.provider.XScriptContext; -public class EditorScriptContext implements XScriptContext -{ +public class EditorScriptContext implements XScriptContext { private XDesktop m_xDeskTop; private XComponentContext m_xComponentContext; - public EditorScriptContext( XComponentContext xmComponentContext, - XDesktop xDesktop ) - { + public EditorScriptContext(XComponentContext xmComponentContext, + XDesktop xDesktop) { this.m_xComponentContext = xmComponentContext; this.m_xDeskTop = xDesktop; } @@ -41,18 +39,16 @@ public class EditorScriptContext implements XScriptContext @return XModel interface */ - public XModel getDocument() - { - XModel xModel = UnoRuntime.queryInterface( XModel.class, - m_xDeskTop.getCurrentComponent() ); + public XModel getDocument() { + XModel xModel = UnoRuntime.queryInterface(XModel.class, + m_xDeskTop.getCurrentComponent()); return xModel; } - public XScriptInvocationContext getInvocationContext() - { + public XScriptInvocationContext getInvocationContext() { XScriptInvocationContext xContext = UnoRuntime.queryInterface( - XScriptInvocationContext.class, getDocument() ); + XScriptInvocationContext.class, getDocument()); return xContext; } @@ -61,8 +57,7 @@ public class EditorScriptContext implements XScriptContext @return XDesktop interface */ - public XDesktop getDesktop() - { + public XDesktop getDesktop() { return m_xDeskTop; } @@ -71,9 +66,8 @@ public class EditorScriptContext implements XScriptContext @return XComponentContext interface */ - public XComponentContext getComponentContext() - { - return m_xComponentContext; + public XComponentContext getComponentContext() { + return m_xComponentContext; } } 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 ea412fc6b678..c9c103256a39 100644 --- a/scripting/java/com/sun/star/script/framework/provider/NoSuitableClassLoaderException.java +++ b/scripting/java/com/sun/star/script/framework/provider/NoSuitableClassLoaderException.java @@ -18,14 +18,12 @@ package com.sun.star.script.framework.provider; -public class NoSuitableClassLoaderException extends Exception -{ +public class NoSuitableClassLoaderException extends Exception { /** * Constructs an NoSuitableClassLoaderException with null * as its error detail message. */ - public NoSuitableClassLoaderException() - { + public NoSuitableClassLoaderException() { super(); } /** @@ -36,8 +34,7 @@ public class NoSuitableClassLoaderException extends Exception * * @param s the detail message. */ - public NoSuitableClassLoaderException(String s) - { + public NoSuitableClassLoaderException(String s) { super(s); } 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 1bd7bd28f657..3cb88c929d2a 100644 --- a/scripting/java/com/sun/star/script/framework/provider/PathUtils.java +++ b/scripting/java/com/sun/star/script/framework/provider/PathUtils.java @@ -38,46 +38,41 @@ public class PathUtils { BOOTSTRAP_NAME = m_windows ? "bootstrap.ini" : "bootstraprc"; } - public static String getOidForModel( XModel xModel ) - { + public static String getOidForModel(XModel xModel) { String oid = ""; - if ( xModel != null ) - { - try - { - Method getOid = IQueryInterface.class.getMethod("getOid", (java.lang.Class[])null); - if ( getOid != null ) - { - oid = (String)getOid.invoke( xModel, new Object[0] ); + + if (xModel != null) { + try { + Method getOid = IQueryInterface.class.getMethod("getOid", + (java.lang.Class[])null); + + if (getOid != null) { + oid = (String)getOid.invoke(xModel, new Object[0]); } - } - catch ( Exception ignore ) - { + } catch (Exception ignore) { } } + return oid; } - static public String make_url( String baseUrl, String url ) - { - StringBuilder buff = new StringBuilder( baseUrl.length() + url.length() ); - buff.append( baseUrl ); - StringTokenizer t = new StringTokenizer( url, "/"); - while ( t.hasMoreElements() ) - { - if ( buff.charAt( buff.length() - 1 ) != '/' ) - { - buff.append('/'); - } - try - { - buff.append( java.net.URLEncoder.encode( (String)t.nextElement(), "UTF-8" ) ); - } - catch (java.io.UnsupportedEncodingException e) - { - e.printStackTrace(); - } + static public String make_url(String baseUrl, String url) { + StringBuilder buff = new StringBuilder(baseUrl.length() + url.length()); + buff.append(baseUrl); + StringTokenizer t = new StringTokenizer(url, "/"); + + while (t.hasMoreElements()) { + if (buff.charAt(buff.length() - 1) != '/') { + buff.append('/'); + } + + try { + buff.append(java.net.URLEncoder.encode((String)t.nextElement(), "UTF-8")); + } catch (java.io.UnsupportedEncodingException e) { + e.printStackTrace(); + } } + return buff.toString(); } 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 9d922cf30c5a..546755e9e93a 100644 --- a/scripting/java/com/sun/star/script/framework/provider/ScriptContext.java +++ b/scripting/java/com/sun/star/script/framework/provider/ScriptContext.java @@ -31,8 +31,7 @@ import com.sun.star.script.provider.XScriptContext; import com.sun.star.script.framework.log.LogUtils; -public class ScriptContext extends PropertySet implements XScriptContext -{ +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"; @@ -47,51 +46,50 @@ 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"); + 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"); - 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"); + registerProperty(HM_DOC_REF, new Type(XModel.class), + (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"); } - public static XScriptContext createContext( XModel xModel, XScriptInvocationContext xInvocContext, - XComponentContext xCtxt, XMultiComponentFactory xMCF) - { + 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); + "com.sun.star.frame.Desktop", xCtxt); XDesktop xDesktop = UnoRuntime.queryInterface(XDesktop.class, xInterface); - if ( xModel != null ) - { + + if (xModel != null) { sc = new ScriptContext(xCtxt, xDesktop, xModel, xInvocContext); - } - else - { - sc = new EditorScriptContext(xCtxt, xDesktop ); + } else { + sc = new EditorScriptContext(xCtxt, xDesktop); } + } catch (Exception e) { + LogUtils.DEBUG(LogUtils.getTrace(e)); } - catch ( Exception e ) { - LogUtils.DEBUG( LogUtils.getTrace( e ) ); - } + return sc; } @@ -101,13 +99,11 @@ public class ScriptContext extends PropertySet implements XScriptContext @return XModel interface */ - public XModel getDocument() - { + public XModel getDocument() { return m_xModel; } - public XScriptInvocationContext getInvocationContext() - { + public XScriptInvocationContext getInvocationContext() { return m_xInvocationContext; } @@ -116,8 +112,7 @@ public class ScriptContext extends PropertySet implements XScriptContext @return XDesktop interface */ - public XDesktop getDesktop() - { + public XDesktop getDesktop() { return m_xDeskTop; } @@ -126,9 +121,8 @@ public class ScriptContext extends PropertySet implements XScriptContext @return XComponentContext interface */ - public XComponentContext getComponentContext() - { - return m_xComponentContext; + public XComponentContext getComponentContext() { + return m_xComponentContext; } } 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 834108bc62ba..8ae3b510fdf2 100644 --- a/scripting/java/com/sun/star/script/framework/provider/ScriptEditor.java +++ b/scripting/java/com/sun/star/script/framework/provider/ScriptEditor.java @@ -21,10 +21,9 @@ package com.sun.star.script.framework.provider; import com.sun.star.script.provider.XScriptContext; import com.sun.star.script.framework.container.ScriptMetaData; -public interface ScriptEditor -{ +public interface ScriptEditor { Object execute() throws Exception; - void indicateErrorLine( int lineNum ); + void indicateErrorLine(int lineNum); void edit(XScriptContext context, ScriptMetaData entry); String getTemplate(); String getExtension(); 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 3ee02ecb8dc5..3077ae6da3ec 100644 --- a/scripting/java/com/sun/star/script/framework/provider/ScriptProvider.java +++ b/scripting/java/com/sun/star/script/framework/provider/ScriptProvider.java @@ -80,8 +80,7 @@ import com.sun.star.uno.TypeClass; public abstract class ScriptProvider implements XScriptProvider, XBrowseNode, XPropertySet, XInvocation, - XInitialization, XTypeProvider, XServiceInfo, XNameContainer -{ + XInitialization, XTypeProvider, XServiceInfo, XNameContainer { private final String[] __serviceNames = { "com.sun.star.script.provider.ScriptProviderFor", "com.sun.star.script.provider.LanguageScriptProvider" @@ -100,178 +99,165 @@ 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 + // TODO should this be implemented in this class private XBrowseNode m_xBrowseNodeProxy; private XScriptContext m_xScriptContext; - public ScriptProvider( XComponentContext ctx, String language ) - { + public ScriptProvider(XComponentContext ctx, String language) { this.language = language; __serviceNames[0] += language; - LogUtils.DEBUG( "ScriptProvider: constructor - start. " + language ); + LogUtils.DEBUG("ScriptProvider: constructor - start. " + language); m_xContext = ctx; // Initialize DialogFactory class in case dialogs are required DialogFactory.createDialogFactory(m_xContext); - try - { + try { m_xMultiComponentFactory = m_xContext.getServiceManager(); - if ( m_xMultiComponentFactory == null ) - { - throw new Exception( "Error could not obtain a " + - "multicomponent factory - rethrowing Exception." ); + if (m_xMultiComponentFactory == null) { + throw new Exception("Error could not obtain a " + + "multicomponent factory - rethrowing Exception."); } Object serviceObj = m_xContext.getValueByName( - "/singletons/com.sun.star.util.theMacroExpander"); + "/singletons/com.sun.star.util.theMacroExpander"); XMacroExpander me = (XMacroExpander) AnyConverter.toObject( - new Type(XMacroExpander.class), serviceObj); + new Type(XMacroExpander.class), serviceObj); XMLParserFactory.setOfficeDTDURL(me.expandMacros( - "$BRAND_BASE_DIR/$BRAND_SHARE_SUBDIR/dtd/officedocument/1_0/")); + "$BRAND_BASE_DIR/$BRAND_SHARE_SUBDIR/dtd/officedocument/1_0/")); - } - catch ( Exception e ) - { - LogUtils.DEBUG( LogUtils.getTrace( e ) ); + } catch (Exception e) { + LogUtils.DEBUG(LogUtils.getTrace(e)); com.sun.star.uno.RuntimeException e2 = new com.sun.star.uno.RuntimeException( - "Error constructing ScriptProvider: " + e ); - e2.initCause( e ); + "Error constructing ScriptProvider: " + e); + e2.initCause(e); throw e2; } - LogUtils.DEBUG( "ScriptProvider: constructor - finished." ); + LogUtils.DEBUG("ScriptProvider: constructor - finished."); } - synchronized public XScriptContext getScriptingContext() - { - if ( m_xScriptContext == null ) - { - m_xScriptContext = ScriptContext.createContext( m_xModel, m_xInvocContext, m_xContext, m_xMultiComponentFactory ); + synchronized public XScriptContext getScriptingContext() { + if (m_xScriptContext == null) { + m_xScriptContext = ScriptContext.createContext(m_xModel, m_xInvocContext, + m_xContext, m_xMultiComponentFactory); } + return m_xScriptContext; } - public void initialize( Object[] aArguments ) - throws com.sun.star.uno.Exception - { - LogUtils.DEBUG( "entering XInit for language " + language); + + public void initialize(Object[] aArguments) + throws com.sun.star.uno.Exception { + LogUtils.DEBUG("entering XInit for language " + language); boolean isPkgProvider = false; - if( aArguments.length == 1 ) - { + + if (aArguments.length == 1) { String contextUrl = null; - if ( AnyConverter.getType(aArguments[0]).getTypeClass().equals(TypeClass.INTERFACE) ) - { + + if (AnyConverter.getType(aArguments[0]).getTypeClass().equals( + TypeClass.INTERFACE)) { // try whether it denotes a XScriptInvocationContext m_xInvocContext = UnoRuntime.queryInterface( - XScriptInvocationContext.class, aArguments[0]); - if ( m_xInvocContext != null ) - { + 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() ); - } - else - { + 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 ) - { + + if (m_xModel == null) { throw new com.sun.star.uno.Exception( - "ScriptProvider argument must be either a string, a valid XScriptInvocationContext, " + + "ScriptProvider argument must be either a string, a valid XScriptInvocationContext, " + + "or an XModel", this); } - contextUrl = getDocUrlFromModel( m_xModel ); - m_container = new ParcelContainer( m_xContext, contextUrl, language ); - } - else if (AnyConverter.isString(aArguments[0])) - { + 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 ); + LogUtils.DEBUG("creating Application, path: " + originalContextURL); contextUrl = originalContextURL; + // TODO no support for packages in documents yet - if ( originalContextURL.startsWith( "vnd.sun.star.tdoc" ) ) - { - m_container = new ParcelContainer( m_xContext, contextUrl, language ); - m_xModel = getModelFromDocUrl( originalContextURL ); - } - else - { + if (originalContextURL.startsWith("vnd.sun.star.tdoc")) { + m_container = new ParcelContainer(m_xContext, contextUrl, language); + m_xModel = getModelFromDocUrl(originalContextURL); + } else { String extensionDb = null; String extensionRepository = null; - if ( originalContextURL.startsWith( "bundled" ) ) - { + + 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" ) ) - { + } 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"; + } 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"; extensionRepository = "user"; } - if ( originalContextURL.endsWith( "uno_packages") ) - { + if (originalContextURL.endsWith("uno_packages")) { isPkgProvider = true; + if (!originalContextURL.equals(contextUrl) - && !extensionRepository.equals("bundled")) - { + && !extensionRepository.equals("bundled")) { contextUrl = PathUtils.make_url(contextUrl, "uno_packages"); } } - if ( isPkgProvider ) - { - m_container = new UnoPkgContainer( m_xContext, contextUrl, extensionDb, extensionRepository, language ); - } - else - { - m_container = new ParcelContainer( m_xContext, contextUrl, language ); + if (isPkgProvider) { + m_container = new UnoPkgContainer(m_xContext, contextUrl, extensionDb, + extensionRepository, language); + } else { + m_container = new ParcelContainer(m_xContext, contextUrl, language); } } - } - else - { + } else { throw new com.sun.star.uno.RuntimeException( "ScriptProvider created with invalid argument"); } - LogUtils.DEBUG("Modified Application path is: " + contextUrl ); - LogUtils.DEBUG("isPkgProvider is: " + isPkgProvider ); + LogUtils.DEBUG("Modified Application path is: " + contextUrl); + LogUtils.DEBUG("isPkgProvider is: " + isPkgProvider); // TODO should all be done in this class instead of // deleagation???? - 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); - } - else - { + 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); + } else { // this is ok, for example when executing a script from the // command line - LogUtils.DEBUG( "ScriptProviderFor" + language + - " initialized without a context"); + LogUtils.DEBUG("ScriptProviderFor" + language + + " initialized without a context"); } - LogUtils.DEBUG( "leaving XInit" ); + + LogUtils.DEBUG("leaving XInit"); } /** @@ -279,17 +265,16 @@ public abstract class ScriptProvider * * @return The types value */ - public com.sun.star.uno.Type[] getTypes() - { + public com.sun.star.uno.Type[] getTypes() { Type[] retValue = new Type[ 8 ]; - retValue[ 0 ] = new Type( XScriptProvider.class ); - retValue[ 1 ] = new Type( XBrowseNode.class ); - retValue[ 2 ] = new Type( XInitialization.class ); - retValue[ 3 ] = new Type( XTypeProvider.class ); - retValue[ 4 ] = new Type( XServiceInfo.class ); - retValue[ 5 ] = new Type( XPropertySet.class ); - retValue[ 6 ] = new Type( XInvocation.class ); - retValue[ 7 ] = new Type( com.sun.star.container.XNameContainer.class ); + retValue[ 0 ] = new Type(XScriptProvider.class); + retValue[ 1 ] = new Type(XBrowseNode.class); + retValue[ 2 ] = new Type(XInitialization.class); + retValue[ 3 ] = new Type(XTypeProvider.class); + retValue[ 4 ] = new Type(XServiceInfo.class); + retValue[ 5 ] = new Type(XPropertySet.class); + retValue[ 6 ] = new Type(XInvocation.class); + retValue[ 7 ] = new Type(com.sun.star.container.XNameContainer.class); return retValue; } @@ -298,8 +283,7 @@ public abstract class ScriptProvider * * @return The implementationId value */ - public byte[] getImplementationId() - { + public byte[] getImplementationId() { return new byte[0]; } @@ -308,8 +292,7 @@ public abstract class ScriptProvider * * @return The implementationName value */ - public String getImplementationName() - { + public String getImplementationName() { return getClass().getName(); } @@ -319,15 +302,13 @@ public abstract class ScriptProvider * @param serviceName Description of the Parameter * @return Description of the Return Value */ - public boolean supportsService( String serviceName ) - { - for ( int index = __serviceNames.length; index-- > 0; ) - { - if ( serviceName.equals( __serviceNames[ index ] ) ) - { + public boolean supportsService(String serviceName) { + for (int index = __serviceNames.length; index-- > 0;) { + if (serviceName.equals(__serviceNames[ index ])) { return true; } } + return false; } @@ -336,16 +317,15 @@ public abstract class ScriptProvider * * @return The supportedServiceNames value */ - public String[] getSupportedServiceNames() - { + public String[] getSupportedServiceNames() { 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 @@ -358,55 +338,51 @@ public abstract class ScriptProvider // This method is used to get the ScriptEditor for this ScriptProvider public abstract ScriptEditor getScriptEditor(); - public ScriptMetaData getScriptData( /*IN*/String scriptURI ) throws ScriptFrameworkErrorException + public ScriptMetaData getScriptData(/*IN*/String scriptURI) throws + ScriptFrameworkErrorException { - try - { - ParsedScriptUri details = m_container.parseScriptUri( scriptURI ); - try - { + try { + ParsedScriptUri details = m_container.parseScriptUri(scriptURI); + + try { ScriptMetaData scriptData = m_container.findScript(details); - if (scriptData == null) - { + + if (scriptData == null) { throw new ScriptFrameworkErrorException(details.function + " does not exist", - null, details.function, language, ScriptFrameworkErrorType.NO_SUCH_SCRIPT); + null, details.function, language, ScriptFrameworkErrorType.NO_SUCH_SCRIPT); } + return scriptData; - } - catch (com.sun.star.container.NoSuchElementException nse) - { + } catch (com.sun.star.container.NoSuchElementException nse) { ScriptFrameworkErrorException e2 - = new ScriptFrameworkErrorException( - nse.getMessage(), null, details.function, language, - ScriptFrameworkErrorType.NO_SUCH_SCRIPT); + = new ScriptFrameworkErrorException( + nse.getMessage(), null, details.function, language, + ScriptFrameworkErrorType.NO_SUCH_SCRIPT); e2.initCause(nse); throw e2; - } - catch (com.sun.star.lang.WrappedTargetException wta) - { + } catch (com.sun.star.lang.WrappedTargetException wta) { // TODO specify the correct error Type Exception wrapped = (Exception) wta.TargetException; String message = wta.getMessage(); - if (wrapped != null) - { + + if (wrapped != null) { message = wrapped.getMessage(); } + ScriptFrameworkErrorException e2 - = new ScriptFrameworkErrorException( - message, null, details.function, language, - ScriptFrameworkErrorType.UNKNOWN); + = new ScriptFrameworkErrorException( + message, null, details.function, language, + ScriptFrameworkErrorType.UNKNOWN); e2.initCause(wta); throw e2; } - } - catch (com.sun.star.lang.IllegalArgumentException ila) - { + } catch (com.sun.star.lang.IllegalArgumentException ila) { // TODO specify the correct error Type ScriptFrameworkErrorException e2 - = new ScriptFrameworkErrorException( - ila.getMessage(), null, scriptURI, language, - ScriptFrameworkErrorType.UNKNOWN); + = new ScriptFrameworkErrorException( + ila.getMessage(), null, scriptURI, language, + ScriptFrameworkErrorType.UNKNOWN); e2.initCause(ila); throw e2; } @@ -414,39 +390,34 @@ public abstract class ScriptProvider // Implementation of XBrowseNode interface - public String getName() - { + public String getName() { return language; } - public XBrowseNode[] getChildNodes() - { - if ( m_xBrowseNodeProxy == null ) - { + public XBrowseNode[] getChildNodes() { + if (m_xBrowseNodeProxy == null) { LogUtils.DEBUG("No Nodes available "); return new XBrowseNode[0]; } + return m_xBrowseNodeProxy .getChildNodes(); } - public boolean hasChildNodes() - { - if ( m_xBrowseNodeProxy == null ) - { + public boolean hasChildNodes() { + if (m_xBrowseNodeProxy == null) { LogUtils.DEBUG("No Nodes available "); return false; } + return m_xBrowseNodeProxy.hasChildNodes(); } - public short getType() - { + public short getType() { return BrowseNodeTypes.CONTAINER; } @Override - public String toString() - { + public String toString() { return getName(); } @@ -457,25 +428,22 @@ public abstract class ScriptProvider public Object invoke(String aFunctionName, Object[] aParams, short[][] aOutParamIndex, Object[][] aOutParam) - throws com.sun.star.lang.IllegalArgumentException, - com.sun.star.script.CannotConvertException, - com.sun.star.reflection.InvocationTargetException - { + throws com.sun.star.lang.IllegalArgumentException, + com.sun.star.script.CannotConvertException, + com.sun.star.reflection.InvocationTargetException { return m_xInvocationProxy.invoke( - aFunctionName, aParams, aOutParamIndex, aOutParam); + aFunctionName, aParams, aOutParamIndex, aOutParam); } public void setValue(String aPropertyName, Object aValue) - throws com.sun.star.beans.UnknownPropertyException, - com.sun.star.script.CannotConvertException, - com.sun.star.reflection.InvocationTargetException - { + 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 - { + throws com.sun.star.beans.UnknownPropertyException { return m_xInvocationProxy.getValue(aPropertyName); } @@ -487,203 +455,195 @@ public abstract class ScriptProvider return m_xInvocationProxy.hasProperty(aName); } - public XPropertySetInfo getPropertySetInfo() - { + public XPropertySetInfo getPropertySetInfo() { return m_xPropertySetProxy.getPropertySetInfo(); } 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 - { + 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, - com.sun.star.lang.WrappedTargetException - { + 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, - com.sun.star.lang.WrappedTargetException - { + 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, - com.sun.star.lang.WrappedTargetException - { + 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, - com.sun.star.lang.WrappedTargetException - { + 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, - com.sun.star.lang.WrappedTargetException - { + 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 - { + 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" ); + "getByName not implemented"); } - public String[] getElementNames() - { + public String[] getElementNames() { // TODO needs implementing? throw new com.sun.star.uno.RuntimeException( - "getElementNames not implemented" ); + "getElementNames not implemented"); } // Performs the getRegStatus functionality for the PkgMgr - public boolean hasByName( String aName ) { - return ((UnoPkgContainer)m_container).hasRegisteredUnoPkgContainer( aName ); + public boolean hasByName(String aName) { + return ((UnoPkgContainer)m_container).hasRegisteredUnoPkgContainer(aName); } - public com.sun.star.uno.Type getElementType() - { + public com.sun.star.uno.Type getElementType() { // TODO at the moment this returns void indicating // type is unknown should indicate XPackage ? do we implement XPackage return new Type(); } - public boolean hasElements() - { + public boolean hasElements() { // TODO needs implementing? throw new com.sun.star.uno.RuntimeException( - "hasElements not implemented" ); + "hasElements not implemented"); } - 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 - { + 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 ) - { + if (true) { throw new com.sun.star.uno.RuntimeException( - "replaceByName not implemented" ); + "replaceByName not implemented"); } } - 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 ); - XPackage newPackage = UnoRuntime.queryInterface( XPackage.class, aElement ); - if ( aName.length() == 0 ) - { - throw new com.sun.star.lang.IllegalArgumentException( "Empty name" ); + 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); + XPackage newPackage = UnoRuntime.queryInterface(XPackage.class, aElement); + + if (aName.length() == 0) { + throw new com.sun.star.lang.IllegalArgumentException("Empty name"); } - if ( newPackage == null ) - { - throw new com.sun.star.lang.IllegalArgumentException( "No package supplied" ); + + if (newPackage == null) { + throw new com.sun.star.lang.IllegalArgumentException("No package supplied"); } - ((UnoPkgContainer)m_container).processUnoPackage( newPackage, language ); + ((UnoPkgContainer)m_container).processUnoPackage(newPackage, language); } // de-register for library only !! - 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 ); - if ( c != null ) - { + 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); + + if (c != null) { String libName; - if (Name.endsWith("/")) - { - String tmp = Name.substring( 0, Name.lastIndexOf('/') ); - libName = tmp.substring( tmp.lastIndexOf('/') + 1 ); - } - else - { - libName = Name.substring( Name.lastIndexOf('/') + 1 ); - } - LogUtils.DEBUG("Deregistering library " + libName ); - if ( c.removeParcel( libName ) ) - { - ((UnoPkgContainer)m_container).deRegisterPackageContainer( Name ); + + if (Name.endsWith("/")) { + String tmp = Name.substring(0, Name.lastIndexOf('/')); + libName = tmp.substring(tmp.lastIndexOf('/') + 1); + } else { + libName = Name.substring(Name.lastIndexOf('/') + 1); } - else - { - throw new com.sun.star.container.NoSuchElementException( libName + " cannot be removed from container." ); + + LogUtils.DEBUG("Deregistering library " + libName); + + if (c.removeParcel(libName)) { + ((UnoPkgContainer)m_container).deRegisterPackageContainer(Name); + } else { + throw new com.sun.star.container.NoSuchElementException( + libName + " cannot be removed from container."); } + } else { + throw new com.sun.star.container.NoSuchElementException( + Name + " doesn't exist for " + language); } - else - { - throw new com.sun.star.container.NoSuchElementException( Name + " doesn't exist for " + language ); - } + // TODO see if we want to remove the ParcelContainer is no Parcels/Libraries left } - private String getDocUrlFromModel( XModel document ) - { + private String getDocUrlFromModel(XModel document) { XTransientDocumentsDocumentContentFactory factory = null; - try - { + + try { factory = UnoRuntime.queryInterface( - XTransientDocumentsDocumentContentFactory.class, - m_xMultiComponentFactory.createInstanceWithContext( - "com.sun.star.frame.TransientDocumentsDocumentContentFactory", - m_xContext - ) - ); - } - catch (Exception ex) - { + XTransientDocumentsDocumentContentFactory.class, + m_xMultiComponentFactory.createInstanceWithContext( + "com.sun.star.frame.TransientDocumentsDocumentContentFactory", + m_xContext + ) + ); + } catch (Exception ex) { } - if ( factory == null ) - throw new com.sun.star.uno.RuntimeException( "ScriptProvider: unable to create a TDOC context factory.", this ); + if (factory == null) + throw new com.sun.star.uno.RuntimeException("ScriptProvider: unable to create a TDOC context factory.", + this); - try - { - XContent content = factory.createDocumentContent( document ); + try { + XContent content = factory.createDocumentContent(document); return content.getIdentifier().getContentIdentifier(); - } - catch (com.sun.star.lang.IllegalArgumentException ex) - { + } catch (com.sun.star.lang.IllegalArgumentException ex) { } LogUtils.DEBUG("unable to determine the model's TDOC URL"); return ""; } - private XModel getModelFromDocUrl( String docUrl ) - { - LogUtils.DEBUG("getModelFromDocUrl - searching for match for ->" + docUrl + "<-" ); + private XModel getModelFromDocUrl(String docUrl) { + LogUtils.DEBUG("getModelFromDocUrl - searching for match for ->" + docUrl + + "<-"); XModel xModel = null; - try - { - XUniversalContentBroker ucb = UniversalContentBroker.create( m_xContext ); - XContentIdentifier xCntId = ucb.createContentIdentifier( docUrl ); + try { + XUniversalContentBroker ucb = UniversalContentBroker.create(m_xContext); + + XContentIdentifier xCntId = ucb.createContentIdentifier(docUrl); - XContent xCnt = ucb.queryContent( xCntId ); + 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() }; @@ -697,19 +657,18 @@ public abstract class ScriptProvider command.Argument = pArgs; com.sun.star.ucb.XCommandEnvironment env = null ; - Object result = xCmd.execute( command, 0, env ) ; + 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 ); + xModel = UnoRuntime.queryInterface(XModel.class, + values.getObject(1, null)); + } catch (Exception ignore) { + LogUtils.DEBUG("Failed to get model exception " + ignore); } + return xModel; } 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 74e95546af35..1a0e2ff4f14d 100644 --- a/scripting/java/com/sun/star/script/framework/provider/SwingInvocation.java +++ b/scripting/java/com/sun/star/script/framework/provider/SwingInvocation.java @@ -28,8 +28,10 @@ public final class SwingInvocation { public static void invoke(final Runnable doRun) { new Thread("SwingInvocation") { @Override - public void run() { SwingUtilities.invokeLater(doRun); } - }.start(); + public void run() { + SwingUtilities.invokeLater(doRun); + } + } .start(); } private SwingInvocation() {} 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 bd8f01c9193a..f1f8e09561cb 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 @@ -55,14 +55,13 @@ public class PlainSourceView extends JScrollPane so we don't get a storm of DocumentEvents during loading */ ta.getDocument().removeDocumentListener(this); - if (!isModified) - { + if (!isModified) { int pos = ta.getCaretPosition(); ta.setText(model.getText()); + try { ta.setCaretPosition(pos); - } - catch (IllegalArgumentException iae) { + } catch (IllegalArgumentException iae) { // do nothing and allow JTextArea to set it's own position } } @@ -72,8 +71,7 @@ public class PlainSourceView extends JScrollPane int line = ta.getLineStartOffset(model.getCurrentPosition()); Rectangle rect = ta.modelToView(line); ta.scrollRectToVisible(rect); - } - catch (Exception e) { + } catch (Exception e) { // couldn't scroll to line, do nothing } @@ -164,6 +162,7 @@ class GlyphGutter extends JComponent { int lineCount = textArea.getLineCount() + 1; String dummy = Integer.toString(lineCount); + if (dummy.length() < 2) { dummy = DUMMY_STRING; } @@ -195,6 +194,7 @@ class GlyphGutter extends JComponent { int startLine = clip.y / h; int endLine = (clip.y + clip.height) / h + 1; int width = getWidth(); + if (endLine > lineCount) { endLine = lineCount; } @@ -221,12 +221,15 @@ class GlyphGutter extends JComponent { int dy = y; arrow.addPoint(dx, dy + 3); arrow.addPoint(dx + 5, dy + 3); + for (x = dx + 5; x <= dx + 10; x++, y++) { arrow.addPoint(x, y); } + for (x = dx + 9; x >= dx + 5; x--, y++) { arrow.addPoint(x, y); } + arrow.addPoint(dx + 5, dy + 7); arrow.addPoint(dx, dy + 7); 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 c0cfd1f6a3f0..5991d2285e42 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 @@ -43,8 +43,7 @@ import com.sun.star.script.framework.container.ScriptMetaData; import com.sun.star.script.framework.provider.ClassLoaderFactory; public class ScriptEditorForBeanShell - implements ScriptEditor, ActionListener -{ + implements ScriptEditor, ActionListener { private JFrame frame; private String filename; @@ -59,7 +58,8 @@ public class ScriptEditorForBeanShell private static ScriptEditorForBeanShell theScriptEditorForBeanShell; // global list of ScriptEditors, key is URL of file being edited - private static Map BEING_EDITED = new HashMap(); + private static Map BEING_EDITED = new + HashMap(); // template for new BeanShell scripts private static String BSHTEMPLATE; @@ -74,6 +74,7 @@ public class ScriptEditorForBeanShell StringBuilder buf = new StringBuilder(); byte[] b = new byte[1024]; int len; + while ((len = in.read(b)) != -1) { buf.append(new String(b, 0, len)); } @@ -81,11 +82,9 @@ public class ScriptEditorForBeanShell in.close(); BSHTEMPLATE = buf.toString(); - } - catch (IOException ioe) { + } catch (IOException ioe) { BSHTEMPLATE = "// BeanShell script"; - } - catch (Exception e) { + } catch (Exception e) { BSHTEMPLATE = "// BeanShell script"; } } @@ -93,13 +92,13 @@ public class ScriptEditorForBeanShell /** * Returns the global ScriptEditorForBeanShell instance. */ - public static synchronized ScriptEditorForBeanShell getEditor() - { - if (theScriptEditorForBeanShell == null) - { + + public static synchronized ScriptEditorForBeanShell getEditor() { + if (theScriptEditorForBeanShell == null) { theScriptEditorForBeanShell = new ScriptEditorForBeanShell(); } + return theScriptEditorForBeanShell; } @@ -111,8 +110,7 @@ public class ScriptEditorForBeanShell * @return The ScriptEditorForBeanShell associated with * the given URL if one exists, otherwise null. */ - public static ScriptEditorForBeanShell getEditor(URL url) - { + public static ScriptEditorForBeanShell getEditor(URL url) { synchronized (BEING_EDITED) { return BEING_EDITED.get(url); } @@ -122,8 +120,7 @@ public class ScriptEditorForBeanShell * Returns whether or not the script source being edited in this * ScriptEditorForBeanShell has been modified */ - public boolean isModified() - { + public boolean isModified() { return view.isModified(); } @@ -132,8 +129,7 @@ public class ScriptEditorForBeanShell * * @return The text displayed in this ScriptEditorForBeanShell */ - public String getText() - { + public String getText() { return view.getText(); } @@ -160,9 +156,8 @@ public class ScriptEditorForBeanShell * Indicates the line where error occurred * */ - public void indicateErrorLine( int lineNum ) - { - model.indicateErrorLine( lineNum ); + public void indicateErrorLine(int lineNum) { + model.indicateErrorLine(lineNum); } /** * Executes the script edited by the editor @@ -170,7 +165,7 @@ public class ScriptEditorForBeanShell */ public Object execute() throws Exception { frame.toFront(); - return model.execute( context, cl ); + return model.execute(context, cl); } /** * Opens an editor window for the specified ScriptMetaData. @@ -181,41 +176,44 @@ public class ScriptEditorForBeanShell * @param entry The metadata describing the script */ public void edit(final XScriptContext context, ScriptMetaData entry) { - if (entry != null ) { + if (entry != null) { try { ClassLoader cl = null; + try { - cl = ClassLoaderFactory.getURLClassLoader( entry ); - } - catch (Exception ignore) // TODO re-examine error handling - { + cl = ClassLoaderFactory.getURLClassLoader(entry); + } catch (Exception ignore) { // TODO re-examine error handling } + final ClassLoader theCl = cl; String sUrl = entry.getParcelLocation(); - if ( !sUrl.endsWith( "/" ) ) - { + + if (!sUrl.endsWith("/")) { sUrl += "/"; } + sUrl += entry.getLanguageName(); final URL url = entry.getSourceURL(); SwingInvocation.invoke( - new Runnable() { - public void run() { - ScriptEditorForBeanShell editor; - synchronized (BEING_EDITED) { - editor = BEING_EDITED.get(url); - if (editor == null) { - editor = new ScriptEditorForBeanShell( - context, theCl, url); - BEING_EDITED.put(url, editor); - } + new Runnable() { + public void run() { + ScriptEditorForBeanShell editor; + + synchronized (BEING_EDITED) { + editor = BEING_EDITED.get(url); + + if (editor == null) { + editor = new ScriptEditorForBeanShell( + context, theCl, url); + BEING_EDITED.put(url, editor); } - editor.frame.toFront(); } - }); - } - catch (IOException ioe) { - showErrorMessage( "Error loading file: " + ioe.getMessage() ); + + editor.frame.toFront(); + } + }); + } catch (IOException ioe) { + showErrorMessage("Error loading file: " + ioe.getMessage()); } } } @@ -224,16 +222,16 @@ public class ScriptEditorForBeanShell } private ScriptEditorForBeanShell(XScriptContext context, ClassLoader cl, - URL url) - { + URL url) { this.context = context; this.scriptURL = url; this.model = new ScriptSourceModel(url); this.filename = url.getFile(); this.cl = cl; + try { Class c = Class.forName( - "org.openoffice.netbeans.editor.NetBeansSourceView"); + "org.openoffice.netbeans.editor.NetBeansSourceView"); Class[] types = new Class[] { ScriptSourceModel.class }; @@ -242,15 +240,12 @@ public class ScriptEditorForBeanShell if (ctor != null) { Object[] args = new Object[] { this.model }; this.view = (ScriptSourceView) ctor.newInstance(args); - } - else { + } else { this.view = new PlainSourceView(model); } - } - catch (java.lang.Error err) { + } catch (java.lang.Error err) { this.view = new PlainSourceView(model); - } - catch (Exception e) { + } catch (Exception e) { this.view = new PlainSourceView(model); } @@ -261,7 +256,7 @@ public class ScriptEditorForBeanShell private void showErrorMessage(String message) { JOptionPane.showMessageDialog(frame, message, - "Error", JOptionPane.ERROR_MESSAGE); + "Error", JOptionPane.ERROR_MESSAGE); } private void initUI() { @@ -269,13 +264,12 @@ public class ScriptEditorForBeanShell frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); frame.addWindowListener( - new WindowAdapter() - { - @Override - public void windowClosing(WindowEvent e) { - doClose(); - } + new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + doClose(); } + } ); String[] labels = {"Run", "Clear", "Save", "Close"}; @@ -286,6 +280,7 @@ public class ScriptEditorForBeanShell JButton b = new JButton(label); b.addActionListener(this); p.add(b); + if (label.equals("Save") && filename == null) { b.setEnabled(false); } @@ -301,23 +296,21 @@ 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) - { + if (result == JOptionPane.CANCEL_OPTION) { // don't close the window, just return return; - } - else if (result == JOptionPane.YES_OPTION) - { + } else if (result == JOptionPane.YES_OPTION) { boolean saveSuccess = saveTextArea(); - if (!saveSuccess) - { + + if (!saveSuccess) { return; } } } + frame.dispose(); shutdown(); } @@ -330,43 +323,40 @@ public class ScriptEditorForBeanShell } OutputStream fos = null; + try { String s = view.getText(); fos = scriptURL.openConnection().getOutputStream(); - if ( fos != null) { + + if (fos != null) { fos.write(s.getBytes()); - } - else - { + } else { showErrorMessage( - "Error saving script: Could not open stream for file" ); + "Error saving script: Could not open stream for file"); result = false; } + view.setModified(false); - } - catch (IOException ioe) { - showErrorMessage( "Error saving script: " + ioe.getMessage() ); - result = false; - } - catch (Exception e) { - showErrorMessage( "Error saving script: " + e.getMessage() ); - result = false; - } - finally { + } catch (IOException ioe) { + showErrorMessage("Error saving script: " + ioe.getMessage()); + result = false; + } catch (Exception e) { + showErrorMessage("Error saving script: " + e.getMessage()); + result = false; + } finally { if (fos != null) { try { fos.flush(); fos.close(); - } - catch (IOException ignore) { + } catch (IOException ignore) { } } } + return result; } - private void shutdown() - { + private void shutdown() { synchronized (BEING_EDITED) { BEING_EDITED.remove(scriptURL); } @@ -374,21 +364,16 @@ public class ScriptEditorForBeanShell public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("Run")) { - try - { + try { execute(); - } - catch (Exception invokeException ) { + } catch (Exception invokeException) { showErrorMessage(invokeException.getMessage()); } - } - else if (e.getActionCommand().equals("Close")) { + } else if (e.getActionCommand().equals("Close")) { doClose(); - } - else if (e.getActionCommand().equals("Save")) { + } else if (e.getActionCommand().equals("Save")) { saveTextArea(); - } - else if (e.getActionCommand().equals("Clear")) { + } else if (e.getActionCommand().equals("Clear")) { view.clear(); } } 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 da534d602d57..1f56cbe325d4 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 @@ -47,42 +47,36 @@ import com.sun.star.script.framework.provider.*; import com.sun.star.script.framework.log.*; import com.sun.star.script.framework.container.ScriptMetaData; -public class ScriptProviderForBeanShell -{ - public static class ScriptProviderForBeanShell_2 extends ScriptProvider - { - public ScriptProviderForBeanShell_2(XComponentContext ctx) - { - super (ctx, "BeanShell"); +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 - { - ScriptMetaData scriptData = getScriptData( scriptURI ); - try - { - ScriptImpl script = new ScriptImpl( m_xContext, scriptData, m_xModel, m_xInvocContext ); + 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); 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 ); + } catch (com.sun.star.uno.RuntimeException re) { + throw new ScriptFrameworkErrorException("Failed to create script object: " + + re.getMessage(), + null, scriptData.getLanguageName(), language, ScriptFrameworkErrorType.UNKNOWN); } } @Override - public boolean hasScriptEditor() - { + public boolean hasScriptEditor() { return true; } @Override - public ScriptEditor getScriptEditor() - { + public ScriptEditor getScriptEditor() { return ScriptEditorForBeanShell.getEditor(); } } @@ -99,263 +93,249 @@ public class ScriptProviderForBeanShell * the component * @see com.sun.star.comp.loader.JavaLoader */ - public static XSingleServiceFactory __getServiceFactory( String implName, + public static XSingleServiceFactory __getServiceFactory(String implName, XMultiServiceFactory multiFactory, - XRegistryKey regKey ) - { + XRegistryKey regKey) { XSingleServiceFactory xSingleServiceFactory = null; - if ( implName.equals( ScriptProviderForBeanShell.ScriptProviderForBeanShell_2.class.getName() ) ) - { + if (implName.equals( + ScriptProviderForBeanShell.ScriptProviderForBeanShell_2.class.getName())) { xSingleServiceFactory = FactoryHelper.getServiceFactory( - ScriptProviderForBeanShell.ScriptProviderForBeanShell_2.class, - "com.sun.star.script.provider.ScriptProviderForBeanShell", - multiFactory, - regKey ); + ScriptProviderForBeanShell.ScriptProviderForBeanShell_2.class, + "com.sun.star.script.provider.ScriptProviderForBeanShell", + multiFactory, + regKey); } return xSingleServiceFactory; } } -class ScriptImpl implements XScript -{ +class ScriptImpl implements XScript { private ScriptMetaData metaData; private XComponentContext m_xContext; private XMultiComponentFactory m_xMultiComponentFactory; private XModel m_xModel; private XScriptInvocationContext m_xInvocContext; - ScriptImpl( XComponentContext ctx, ScriptMetaData metaData, XModel xModel, - XScriptInvocationContext xContext ) throws com.sun.star.uno.RuntimeException - { + ScriptImpl(XComponentContext ctx, ScriptMetaData metaData, XModel xModel, + XScriptInvocationContext xContext) throws com.sun.star.uno.RuntimeException { this.metaData = metaData; this.m_xContext = ctx; this.m_xModel = xModel; this.m_xInvocContext = xContext; - try - { + try { this.m_xMultiComponentFactory = m_xContext.getServiceManager(); - } - catch ( Exception e ) - { - LogUtils.DEBUG( LogUtils.getTrace( e ) ); + } catch (Exception e) { + LogUtils.DEBUG(LogUtils.getTrace(e)); throw new com.sun.star.uno.RuntimeException( "Error constructing ScriptImpl [beanshell]: " - + e.getMessage() ); + + e.getMessage()); } - LogUtils.DEBUG("ScriptImpl [beanshell] script data = " + metaData ); + LogUtils.DEBUG("ScriptImpl [beanshell] script data = " + metaData); } - /** - * documentStorageID and document reference - * for use in script name resolving - * - * @param aParams All parameters; pure, out params are - * undefined in sequence, i.e., the value - * has to be ignored by the callee - * - * @param aOutParamIndex Out indices - * - * @param aOutParam Out parameters - * - * @return The value returned from the function - * being invoked - * - * @throws IllegalArgumentException If there is no matching script name - * - * @throws InvocationTargetException If the running script throws - * an exception this information - * is captured and rethrown as - * this exception type. - */ - - public Object invoke( /*IN*/Object[] aParams, - /*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; - try { - cl = ClassLoaderFactory.getURLClassLoader( metaData ); - sourceUrl = metaData.getSourceURL(); - } - catch ( java.net.MalformedURLException mfu ) - { - // Framework error - throw new ScriptFrameworkErrorException( - mfu.getMessage(), null, - metaData.getLanguageName(), metaData.getLanguage(), - ScriptFrameworkErrorType.MALFORMED_URL ); - } - // Set class loader to be used for class files - // and jar files - Thread.currentThread().setContextClassLoader(cl); - Interpreter interpreter = new Interpreter(); - - interpreter.getNameSpace().clear(); - // Set class loader to be used by interpreter - // to look for classes by source e.g. interpreter - // will use this classloader to search classpath - // for source file ( bla.java ) on import or reference - interpreter.setClassLoader(cl); - try { - interpreter.set("XSCRIPTCONTEXT", - ScriptContext.createContext(m_xModel, m_xInvocContext, - m_xContext, m_xMultiComponentFactory)); - - interpreter.set("ARGUMENTS", aParams); - } - catch (bsh.EvalError e) { - // Framework error setting up context - throw new ScriptFrameworkErrorException( - e.getMessage(), null, - metaData.getLanguageName(), metaData.getLanguage(), - ScriptFrameworkErrorType.UNKNOWN ); - } - - try { - Object result; + /** + * documentStorageID and document reference + * for use in script name resolving + * + * @param aParams All parameters; pure, out params are + * undefined in sequence, i.e., the value + * has to be ignored by the callee + * + * @param aOutParamIndex Out indices + * + * @param aOutParam Out parameters + * + * @return The value returned from the function + * being invoked + * + * @throws IllegalArgumentException If there is no matching script name + * + * @throws InvocationTargetException If the running script throws + * an exception this information + * is captured and rethrown as + * this exception type. + */ - ScriptEditorForBeanShell editor = - ScriptEditorForBeanShell.getEditor( - sourceUrl ); + public Object invoke(/*IN*/Object[] aParams, + /*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; + + try { + cl = ClassLoaderFactory.getURLClassLoader(metaData); + sourceUrl = metaData.getSourceURL(); + } catch (java.net.MalformedURLException mfu) { + // Framework error + throw new ScriptFrameworkErrorException( + mfu.getMessage(), null, + metaData.getLanguageName(), metaData.getLanguage(), + ScriptFrameworkErrorType.MALFORMED_URL); + } - if ( editor != null ) - { - result = editor.execute(); + // Set class loader to be used for class files + // and jar files + Thread.currentThread().setContextClassLoader(cl); + Interpreter interpreter = new Interpreter(); + + interpreter.getNameSpace().clear(); + // Set class loader to be used by interpreter + // to look for classes by source e.g. interpreter + // will use this classloader to search classpath + // for source file ( bla.java ) on import or reference + interpreter.setClassLoader(cl); + + try { + interpreter.set("XSCRIPTCONTEXT", + ScriptContext.createContext(m_xModel, m_xInvocContext, + m_xContext, m_xMultiComponentFactory)); + + interpreter.set("ARGUMENTS", aParams); + } catch (bsh.EvalError e) { + // Framework error setting up context + throw new ScriptFrameworkErrorException( + e.getMessage(), null, + metaData.getLanguageName(), metaData.getLanguage(), + ScriptFrameworkErrorType.UNKNOWN); + } - if (result == null) - { - return new Any(new Type(), null); - } - return result; - } + try { + Object result; - metaData.loadSource(); - String source = metaData.getSource(); + ScriptEditorForBeanShell editor = + ScriptEditorForBeanShell.getEditor( + sourceUrl); - if ( source == null || source.length() == 0 ) - { - throw new ScriptFrameworkErrorException( - "Failed to read script", null, - metaData.getLanguageName(), metaData.getLanguage(), - ScriptFrameworkErrorType.NO_SUCH_SCRIPT ); - } - result = interpreter.eval( source ); + if (editor != null) { + result = editor.execute(); - if (result == null) - { + if (result == null) { return new Any(new Type(), null); } + return result; } - catch ( bsh.ParseException pe ) - { - 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() ) ); - } - catch ( bsh.EvalError ex ) - { - throw new InvocationTargetException( "Beanshell error for " + metaData.getLanguageName(), null, processBshException( ex, metaData.getLanguageName() ) ); - } - catch ( Exception e ) - { + + metaData.loadSource(); + String source = metaData.getSource(); + + if (source == null || source.length() == 0) { throw new ScriptFrameworkErrorException( "Failed to read script", null, metaData.getLanguageName(), metaData.getLanguage(), - ScriptFrameworkErrorType.UNKNOWN ); + ScriptFrameworkErrorType.NO_SUCH_SCRIPT); + } + + result = interpreter.eval(source); + + if (result == null) { + return new Any(new Type(), null); } + + return result; + } catch (bsh.ParseException pe) { + 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())); + } catch (bsh.EvalError ex) { + 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); } - private void raiseEditor( int lineNum ) - { - try - { - URL sourceUrl = metaData.getSourceURL(); - ScriptEditorForBeanShell editor = ScriptEditorForBeanShell.getEditor( sourceUrl ); - if ( editor == null ) - { - editor = ScriptEditorForBeanShell.getEditor(); - editor.edit( - ScriptContext.createContext(m_xModel, m_xInvocContext, - m_xContext, m_xMultiComponentFactory), metaData ); - editor = ScriptEditorForBeanShell.getEditor( sourceUrl ); - } - if ( editor != null ) - { - editor.indicateErrorLine( lineNum ); - } + } + private void raiseEditor(int lineNum) { + try { + URL sourceUrl = metaData.getSourceURL(); + ScriptEditorForBeanShell editor = ScriptEditorForBeanShell.getEditor(sourceUrl); + + if (editor == null) { + editor = ScriptEditorForBeanShell.getEditor(); + editor.edit( + ScriptContext.createContext(m_xModel, m_xInvocContext, + m_xContext, m_xMultiComponentFactory), metaData); + editor = ScriptEditorForBeanShell.getEditor(sourceUrl); } - catch( Exception ignore ) - { + + if (editor != null) { + editor.indicateErrorLine(lineNum); } + } catch (Exception ignore) { } + } - private ScriptErrorRaisedException processBshException( bsh.EvalError e, String script ) - { - LogUtils.DEBUG("Beanshell error RAW message " + e.getMessage()); - String message = e.getMessage(); - int usefulInfoIndex = message.lastIndexOf("\' :" ); - int lineNum = e.getErrorLineNumber(); + private ScriptErrorRaisedException processBshException(bsh.EvalError e, + String script) { + LogUtils.DEBUG("Beanshell error RAW message " + e.getMessage()); + String message = e.getMessage(); + int usefulInfoIndex = message.lastIndexOf("\' :"); + int lineNum = e.getErrorLineNumber(); + + raiseEditor(lineNum); + + if (usefulInfoIndex > -1) { + message = message.substring(usefulInfoIndex + 2); + } - raiseEditor( lineNum ); + if (e instanceof bsh.TargetError) { + LogUtils.DEBUG("got instance of TargetError"); - if ( usefulInfoIndex > -1 ) - { - message = message.substring( usefulInfoIndex + 2 ); + if (usefulInfoIndex == -1) { + message = ((bsh.TargetError)e).getTarget().getMessage(); } - if ( e instanceof bsh.TargetError ) - { - LogUtils.DEBUG("got instance of TargetError"); - if ( usefulInfoIndex == -1 ) - { - message = ( ( bsh.TargetError)e ).getTarget().getMessage(); - } - String wrappedException = ""; - String full = e.toString(); - int index = full.indexOf( "Target exception:" ); - if ( index > -1 ) - { - String toParse = full.substring( index ); - LogUtils.DEBUG("About to parse " + toParse ); - StringTokenizer tokenizer = new StringTokenizer( full.substring( index ),":" ); - if ( tokenizer.countTokens() > 2 ) - { - LogUtils.DEBUG("First token = " + (String)tokenizer.nextElement()); - wrappedException = (String)tokenizer.nextElement(); - LogUtils.DEBUG("wrapped exception = = " + wrappedException ); - } + + String wrappedException = ""; + String full = e.toString(); + int index = full.indexOf("Target exception:"); + + if (index > -1) { + String toParse = full.substring(index); + LogUtils.DEBUG("About to parse " + toParse); + StringTokenizer tokenizer = new StringTokenizer(full.substring(index), ":"); + + if (tokenizer.countTokens() > 2) { + LogUtils.DEBUG("First token = " + (String)tokenizer.nextElement()); + wrappedException = (String)tokenizer.nextElement(); + LogUtils.DEBUG("wrapped exception = = " + wrappedException); } - 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 ); } + + 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); } + } } 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 ef4719ef1a7d..9954c6b550c9 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 @@ -30,7 +30,7 @@ public class ScriptSourceModel { private URL file = null; private ScriptSourceView view = null; - public ScriptSourceModel(URL file ) { + public ScriptSourceModel(URL file) { this.file = file; } @@ -40,14 +40,14 @@ public class ScriptSourceModel { byte[] contents = new byte[1024]; int len; + while ((len = in.read(contents, 0, 1024)) != -1) { buf.append(new String(contents, 0, len)); } try { in.close(); - } - catch (IOException ignore) { + } catch (IOException ignore) { } return buf.toString(); @@ -58,8 +58,7 @@ public class ScriptSourceModel { try { result = load(); - } - catch (IOException ioe) { + } catch (IOException ioe) { // do nothing, empty string will be returned } @@ -74,52 +73,51 @@ public class ScriptSourceModel { this.view = view; } - public Object execute(final XScriptContext context, ClassLoader cl ) - throws Exception - { - if ( cl != null ) - { - // sets this threads class loader - // hopefully any threads spawned by this - // will inherit this cl - // this enables any class files imported - // from the interpreter to be loaded - // note: setting the classloader on the - // interpreter has a slightly different - // meaning in that the classloader for - // the interpreter seems only to look for - // source files ( bla.java ) in the classpath - Thread.currentThread().setContextClassLoader(cl); - } - bsh.Interpreter interpreter = new bsh.Interpreter(); - if ( cl != null ) - { - // additionally set class loader on the interpreter - // to allow it to load java classes defined in source - // files e.g. bla.java - interpreter.getNameSpace().clear(); - } - - - // reset position - currentPosition = -1; - view.update(); - - interpreter.set("XSCRIPTCONTEXT", context); - interpreter.set("ARGUMENTS", new Object[0]); - - Object result; - if (view.isModified()) { - result = interpreter.eval(view.getText()); - } - else { - result = interpreter.eval(getText()); - } + public Object execute(final XScriptContext context, ClassLoader cl) + throws Exception { + if (cl != null) { + // sets this threads class loader + // hopefully any threads spawned by this + // will inherit this cl + // this enables any class files imported + // from the interpreter to be loaded + // note: setting the classloader on the + // interpreter has a slightly different + // meaning in that the classloader for + // the interpreter seems only to look for + // source files ( bla.java ) in the classpath + Thread.currentThread().setContextClassLoader(cl); + } + + bsh.Interpreter interpreter = new bsh.Interpreter(); + + if (cl != null) { + // additionally set class loader on the interpreter + // to allow it to load java classes defined in source + // files e.g. bla.java + interpreter.getNameSpace().clear(); + } + + + // reset position + currentPosition = -1; + view.update(); + + interpreter.set("XSCRIPTCONTEXT", context); + interpreter.set("ARGUMENTS", new Object[0]); + + Object result; + + if (view.isModified()) { + result = interpreter.eval(view.getText()); + } else { + result = interpreter.eval(getText()); + } + return result; } - public void indicateErrorLine( int lineNum ) - { - System.out.println("Beanshell indicateErrorLine " + lineNum ); + public void indicateErrorLine(int lineNum) { + System.out.println("Beanshell indicateErrorLine " + lineNum); currentPosition = lineNum - 1; view.update(); } 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 af35e3e4c233..ab5103070210 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 @@ -32,7 +32,7 @@ public interface Resolver { * @param c A Class * @return The ScriptProxy value */ - ScriptProxy getProxy( ScriptDescriptor sd, Class c ) + ScriptProxy getProxy(ScriptDescriptor sd, Class c) throws NoSuchMethodException; } 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 66d25aa6ccdd..cd2e417695b6 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 @@ -26,13 +26,12 @@ import java.util.StringTokenizer; * The ScriptDescriptor object is used to store the search * criteria that should be used for finding a particular script */ -public class ScriptDescriptor -{ +public class ScriptDescriptor { private String m_name; private String m_methodName; private String m_className; private List m_classpath; - private ArrayList> m_argumentTypes = new ArrayList>( 11 ); + private ArrayList> m_argumentTypes = new ArrayList>(11); /** * Constructs a ScriptDescriptor for the given name @@ -40,19 +39,17 @@ public class ScriptDescriptor * @param name Script Name * @exception IllegalArgumentException if the given name does not contain a "." */ - public ScriptDescriptor( String name ) - throws IllegalArgumentException - { - int idx = name.lastIndexOf( '.' ); - - if ( idx == -1 ) - { - throw new IllegalArgumentException( "Invalid method name" ); + public ScriptDescriptor(String name) + throws IllegalArgumentException { + int idx = name.lastIndexOf('.'); + + if (idx == -1) { + throw new IllegalArgumentException("Invalid method name"); } this.m_name = name; - this.m_methodName = name.substring( idx + 1 ); - this.m_className = name.substring( 0, idx ); + this.m_methodName = name.substring(idx + 1); + this.m_className = name.substring(0, idx); } /** @@ -60,8 +57,7 @@ public class ScriptDescriptor * * @return The Script Name value */ - public String getName() - { + public String getName() { return m_name; } @@ -70,8 +66,7 @@ public class ScriptDescriptor * * @return The Script Name value */ - public String getClassName() - { + public String getClassName() { return m_className; } @@ -81,8 +76,7 @@ public class ScriptDescriptor * * @return The methodName value */ - public String getMethodName() - { + public String getMethodName() { return m_methodName; } @@ -92,12 +86,11 @@ public class ScriptDescriptor * * @param classpath The new classpath value */ - public void setClasspath( String classpath ) - { - StringTokenizer stk = new StringTokenizer( classpath, ":" ); - while( stk.hasMoreElements() ) - { - this.m_classpath.add( (String) stk.nextElement() ); + public void setClasspath(String classpath) { + StringTokenizer stk = new StringTokenizer(classpath, ":"); + + while (stk.hasMoreElements()) { + this.m_classpath.add((String) stk.nextElement()); } } @@ -106,8 +99,7 @@ public class ScriptDescriptor * * @param classpath The new classpath value */ - public void setClasspath( List classpath ) - { + public void setClasspath(List classpath) { this.m_classpath = classpath; } @@ -117,8 +109,7 @@ public class ScriptDescriptor * * @return The classpath value */ - public List getClasspath() - { + public List getClasspath() { return m_classpath; } @@ -129,9 +120,9 @@ public class ScriptDescriptor * * @param clazz The feature to be added to the ArgumentType attribute */ - public synchronized void addArgumentType( Class clazz ) - { - m_argumentTypes.add( clazz ); + + public synchronized void addArgumentType(Class clazz) { + m_argumentTypes.add(clazz); } @@ -146,11 +137,11 @@ public class ScriptDescriptor * * @return The argumentTypes value */ + public synchronized Class[] - getArgumentTypes() - { - if ( m_argumentTypes.size() > 0 ) - return m_argumentTypes.toArray( new Class[ m_argumentTypes.size() ] ); + getArgumentTypes() { + if (m_argumentTypes.size() > 0) + return m_argumentTypes.toArray(new Class[ m_argumentTypes.size() ]); else return null; } @@ -163,24 +154,22 @@ public class ScriptDescriptor * @return The scriptName including the parameters. */ @Override - public String toString() - { - StringBuilder description = new StringBuilder( m_name ); + public String toString() { + StringBuilder description = new StringBuilder(m_name); Class[] types = getArgumentTypes(); - description.append( " (" ); + description.append(" ("); - if ( types != null ) - { - for ( int i = 0; i < types.length - 1; i++ ) - { - description.append( types[ i ].getName() ); - description.append( ", " ); + if (types != null) { + for (int i = 0; i < types.length - 1; i++) { + description.append(types[ i ].getName()); + description.append(", "); } - description.append( types[ types.length - 1 ].getName() ); + description.append(types[ types.length - 1 ].getName()); } - description.append( ")" ); + + description.append(")"); return description.toString(); } 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 9bac3b7e0e40..b09c530b570d 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 @@ -41,50 +41,43 @@ import com.sun.star.script.framework.container.ScriptMetaData; import com.sun.star.script.framework.provider.*; import com.sun.star.script.framework.log.LogUtils; -public class ScriptProviderForJava -{ - public static class _ScriptProviderForJava extends ScriptProvider - { +public class ScriptProviderForJava { + public static class _ScriptProviderForJava extends ScriptProvider { private Resolver m_resolutionPolicy = new StrictResolver(); - public _ScriptProviderForJava( XComponentContext ctx ) - { - super (ctx, "Java"); + public _ScriptProviderForJava(XComponentContext ctx) { + super(ctx, "Java"); } @Override - 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 ); + 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); return script; - } - catch ( com.sun.star.uno.RuntimeException re ) - { + } catch (com.sun.star.uno.RuntimeException re) { ScriptFrameworkErrorException e2 = new ScriptFrameworkErrorException( - "Failed to create script object: " + re, - null, scriptData.getLanguageName(), language, - ScriptFrameworkErrorType.UNKNOWN ); - e2.initCause( re ); + "Failed to create script object: " + re, + null, scriptData.getLanguageName(), language, + ScriptFrameworkErrorType.UNKNOWN); + e2.initCause(re); throw e2; } } @Override - public boolean hasScriptEditor() - { + public boolean hasScriptEditor() { return false; } @Override - public ScriptEditor getScriptEditor() - { + public ScriptEditor getScriptEditor() { return null; } } @@ -101,245 +94,223 @@ public class ScriptProviderForJava * the component * @see com.sun.star.comp.loader.JavaLoader */ - public static XSingleServiceFactory __getServiceFactory( String implName, + public static XSingleServiceFactory __getServiceFactory(String implName, XMultiServiceFactory multiFactory, - XRegistryKey regKey ) - { + 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 ); + if (implName.equals( + ScriptProviderForJava._ScriptProviderForJava.class.getName())) { + xSingleServiceFactory = FactoryHelper.getServiceFactory( + ScriptProviderForJava._ScriptProviderForJava.class, + "com.sun.star.script.provider.ScriptProviderForJava", + multiFactory, + regKey); } return xSingleServiceFactory; } } -class ScriptImpl implements XScript -{ +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 - { + 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; this.m_xInvocContext = xInvocContext; this.m_resolutionPolicy = resolver; - try - { + + try { this.m_xMultiComponentFactory = m_xContext.getServiceManager(); - } - catch ( Exception e ) - { - LogUtils.DEBUG( LogUtils.getTrace( e ) ); + } catch (Exception e) { + LogUtils.DEBUG(LogUtils.getTrace(e)); com.sun.star.uno.RuntimeException e2 = new com.sun.star.uno.RuntimeException( - "Error constructing ScriptProvider: " + e ); - e2.initCause( e ); + "Error constructing ScriptProvider: " + e); + e2.initCause(e); throw e2; } - LogUtils.DEBUG("ScriptImpl [java] script data = " + metaData ); + LogUtils.DEBUG("ScriptImpl [java] script data = " + metaData); } - /** - * Invoke - * - * - * @param params All parameters; pure, out params are undefined in - * sequence, i.e., the value has to be ignored by the callee - * @param aOutParamIndex Out indices - * @param aOutParam Out parameters - * @return The value returned from the function being invoked - * @throws IllegalArgumentException If there is no matching script name - * @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, com.sun.star.reflection.InvocationTargetException - { - LogUtils.DEBUG( "** ScriptProviderForJava::invoke: Starting..." ); - - // Initialise the out parameters - not used at the moment - aOutParamIndex[0] = new short[0]; - aOutParam[0] = new Object[0]; - - Map languageProps = metaData.getLanguageProperties(); - - ScriptDescriptor scriptDesc = - new ScriptDescriptor( metaData.getLanguageName() ); - - ClassLoader scriptLoader = null; + /** + * Invoke + * + * + * @param params All parameters; pure, out params are undefined in + * sequence, i.e., the value has to be ignored by the callee + * @param aOutParamIndex Out indices + * @param aOutParam Out parameters + * @return The value returned from the function being invoked + * @throws IllegalArgumentException If there is no matching script name + * @throws com.sun.star.reflection.InvocationTargetException If the running script throws an exception + * this information is captured and rethrown as this exception type. + */ - try { - LogUtils.DEBUG( "Classloader starting..." ); - scriptLoader = ClassLoaderFactory.getURLClassLoader( - metaData ); - LogUtils.DEBUG( "Classloader finished..." ); - } - catch (ArrayStoreException e ) - { - // Framework error - ScriptFrameworkErrorException e2 = - new ScriptFrameworkErrorException( - e.toString(), null, - metaData.getLanguageName(), metaData.getLanguage(), - ScriptFrameworkErrorType.UNKNOWN ); - e2.initCause( e ); - throw e2; - } + public Object invoke( + /*IN*/Object[] params, + /*OUT*/short[][] aOutParamIndex, + /*OUT*/Object[][] aOutParam) + + throws ScriptFrameworkErrorException, + com.sun.star.reflection.InvocationTargetException { + LogUtils.DEBUG("** ScriptProviderForJava::invoke: Starting..."); + + // Initialise the out parameters - not used at the moment + aOutParamIndex[0] = new short[0]; + aOutParam[0] = new Object[0]; + + Map languageProps = metaData.getLanguageProperties(); + + ScriptDescriptor scriptDesc = + new ScriptDescriptor(metaData.getLanguageName()); + + ClassLoader scriptLoader = null; + + try { + LogUtils.DEBUG("Classloader starting..."); + scriptLoader = ClassLoaderFactory.getURLClassLoader( + metaData); + LogUtils.DEBUG("Classloader finished..."); + } catch (ArrayStoreException e) { + // Framework error + ScriptFrameworkErrorException e2 = + new ScriptFrameworkErrorException( + e.toString(), null, + metaData.getLanguageName(), metaData.getLanguage(), + ScriptFrameworkErrorType.UNKNOWN); + e2.initCause(e); + throw e2; + } - ArrayList invocationArgList = new ArrayList(); - Object[] invocationArgs = null; + ArrayList invocationArgList = new ArrayList(); + Object[] invocationArgs = null; - LogUtils.DEBUG( "Parameter Mapping..." ); + LogUtils.DEBUG("Parameter Mapping..."); - // Setup Context Object - XScriptContext xSc = ScriptContext.createContext(m_xModel, m_xInvocContext, - m_xContext, m_xMultiComponentFactory); - scriptDesc.addArgumentType( XScriptContext.class ); - invocationArgList.add( xSc ); + // Setup Context Object + XScriptContext xSc = ScriptContext.createContext(m_xModel, m_xInvocContext, + m_xContext, m_xMultiComponentFactory); + scriptDesc.addArgumentType(XScriptContext.class); + invocationArgList.add(xSc); - for ( int i = 0; i < params.length; i++ ) - { - scriptDesc.addArgumentType( params[ i ].getClass() ); - invocationArgList.add( params[ i ] ); - } + for (int i = 0; i < params.length; i++) { + scriptDesc.addArgumentType(params[ i ].getClass()); + invocationArgList.add(params[ i ]); + } - if ( !invocationArgList.isEmpty() ) - { - invocationArgs = invocationArgList.toArray(); - } + if (!invocationArgList.isEmpty()) { + 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"); - - try - { - LogUtils.DEBUG( "class loaded ... " ); - script = m_resolutionPolicy.getProxy( scriptDesc, c ); - LogUtils.DEBUG( "script resolved ... " ); - } - catch( NoSuchMethodException e ) - { - // Framework error - 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 ); - e2.initCause( e ); - throw e2; - } + LogUtils.DEBUG("ScriptProxy starting... "); + ScriptProxy script = null; - LogUtils.DEBUG( "Starting Invoke on Proxy ..." ); - Object result = null; + try { + String className = metaData.getLanguageName().substring(0, + metaData.getLanguageName().lastIndexOf('.')); + LogUtils.DEBUG("About to load Class " + className + " starting... "); - try - { - long start = new java.util.Date().getTime(); - result = script.invoke( invocationArgs ); - long end = new java.util.Date().getTime(); + long start = new java.util.Date().getTime(); + Class c = scriptLoader.loadClass(className); + long end = new java.util.Date().getTime(); - 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 ); - e2.initCause( iae ); - throw e2; - } - catch ( java.lang.IllegalAccessException ia ) - { + LogUtils.DEBUG("loadClass took: " + String.valueOf(end - start) + + "milliseconds"); + + try { + LogUtils.DEBUG("class loaded ... "); + script = m_resolutionPolicy.getProxy(scriptDesc, c); + LogUtils.DEBUG("script resolved ... "); + } catch (NoSuchMethodException e) { + // Framework error ScriptFrameworkErrorException e2 = new ScriptFrameworkErrorException( - ia.toString(), null, - metaData.getLanguageName(), metaData.getLanguage(), - ScriptFrameworkErrorType.UNKNOWN ); - e2.initCause( ia ); + e.toString(), null, + metaData.getLanguageName(), metaData.getLanguage(), + ScriptFrameworkErrorType.NO_SUCH_SCRIPT); + e2.initCause(e); throw e2; } - catch ( java.lang.reflect.InvocationTargetException ite ) - { - Throwable targetException = ite.getTargetException(); - ScriptExceptionRaisedException se = - 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() ); - se.lineNum = -1; - se.scriptName = metaData.getLanguageName(); - se.language = "Java"; - se.exceptionType = unknown.getClass().getName(); - throw new com.sun.star.reflection.InvocationTargetException( - "Scripting Framework error executing script ", null, se ); - } - if ( result == null ) - { - LogUtils.DEBUG( "Got Nothing Back" ); - // in the case where there is no return type - Any voidAny = new Any(new Type(), null); - result = voidAny; - } - else - { - LogUtils.DEBUG( "Got object " + result ); - } - return result; + } catch (ClassNotFoundException e) { + // Framework error + ScriptFrameworkErrorException e2 = + new ScriptFrameworkErrorException( + e.toString(), null, + metaData.getLanguageName(), metaData.getLanguage(), + ScriptFrameworkErrorType.NO_SUCH_SCRIPT); + e2.initCause(e); + throw e2; + } + + LogUtils.DEBUG("Starting Invoke on Proxy ..."); + Object result = null; + + try { + 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"); + } catch (java.lang.IllegalArgumentException iae) { + 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); + e2.initCause(ia); + throw e2; + } catch (java.lang.reflect.InvocationTargetException ite) { + Throwable targetException = ite.getTargetException(); + ScriptExceptionRaisedException se = + 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()); + se.lineNum = -1; + se.scriptName = metaData.getLanguageName(); + se.language = "Java"; + se.exceptionType = unknown.getClass().getName(); + throw new com.sun.star.reflection.InvocationTargetException( + "Scripting Framework error executing script ", null, se); + } + + if (result == null) { + LogUtils.DEBUG("Got Nothing Back"); + // in the case where there is no return type + Any voidAny = new Any(new Type(), null); + result = voidAny; + } else { + LogUtils.DEBUG("Got object " + result); } + + return result; + } } 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 010f160ade94..a9bd27293f54 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 @@ -26,8 +26,7 @@ import java.lang.reflect.InvocationTargetException; * * @see java.lang.reflect.Method */ -public class ScriptProxy -{ +public class ScriptProxy { private Object m_targetObject; private Method m_method; @@ -38,8 +37,7 @@ public class ScriptProxy * * @param method Description of the Parameter */ - public ScriptProxy( Method method ) - { + public ScriptProxy(Method method) { this.m_method = method; } @@ -50,8 +48,7 @@ public class ScriptProxy * * @param obj The new targetObject value */ - public void setTargetObject( Object obj ) - { + public void setTargetObject(Object obj) { m_targetObject = obj; } @@ -67,11 +64,10 @@ public class ScriptProxy * @see java.lang.reflect.Method for the exceptions * that may be thrown */ - public Object invoke( Object[] args ) + public Object invoke(Object[] args) throws IllegalAccessException, InvocationTargetException, - IllegalArgumentException - { - return m_method.invoke( m_targetObject, args ); + IllegalArgumentException { + return m_method.invoke(m_targetObject, args); } } 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 6f1898b43387..4ad0f4d52fa7 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 @@ -28,14 +28,12 @@ import com.sun.star.script.framework.log.LogUtils; * method accepting all of the arguments specified in the ScriptDescriptor * can be found in the Class. */ -public class StrictResolver implements Resolver -{ +public class StrictResolver implements Resolver { /** *Constructor for the StrictResolver object */ - public StrictResolver() - { - LogUtils.DEBUG( this.getClass().getName() + " created" ); + public StrictResolver() { + LogUtils.DEBUG(this.getClass().getName() + " created"); } /** @@ -47,49 +45,40 @@ 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() ); + LogUtils.DEBUG("StrictResolver.getProxy() for: " + sd.toString()); - try - { - m = resolveArguments( sd, c ); - } - catch ( ClassNotFoundException e ) - { - 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() ); + try { + m = resolveArguments(sd, c); + } catch (ClassNotFoundException e) { + 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()); } - ScriptProxy sp = new ScriptProxy( m ); + ScriptProxy sp = new ScriptProxy(m); int modifiers = m.getModifiers(); - if ( !Modifier.isStatic( modifiers ) ) - { + + if (!Modifier.isStatic(modifiers)) { Object o; - try - { + + try { o = c.newInstance(); + } catch (InstantiationException ie) { + throw new NoSuchMethodException("getScriptProxy: Can't instantiate: " + + c.getName()); + } catch (IllegalAccessException iae) { + throw new NoSuchMethodException("getScriptProxy: Can't access: " + + c.getName()); } - catch ( InstantiationException ie ) - { - throw new NoSuchMethodException( "getScriptProxy: Can't instantiate: " + - c.getName() ); - } - catch ( IllegalAccessException iae ) - { - throw new NoSuchMethodException( "getScriptProxy: Can't access: " - + c.getName() ); - } - sp.setTargetObject( o ); + + sp.setTargetObject(o); } return sp; @@ -105,10 +94,9 @@ public class StrictResolver implements Resolver * @exception ClassNotFoundException * @exception NoSuchMethodException */ - private Method resolveArguments( ScriptDescriptor sd, Class c ) - throws ClassNotFoundException, NoSuchMethodException - { - return c.getMethod( sd.getMethodName(), sd.getArgumentTypes() ); + private Method resolveArguments(ScriptDescriptor sd, Class c) + throws ClassNotFoundException, NoSuchMethodException { + return c.getMethod(sd.getMethodName(), sd.getArgumentTypes()); } } 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 cc4c7b3c787f..89ebabd62b82 100644 --- a/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptEditorForJavaScript.java +++ b/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptEditorForJavaScript.java @@ -40,8 +40,7 @@ import java.util.HashMap; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; -public class ScriptEditorForJavaScript implements ScriptEditor -{ +public class ScriptEditorForJavaScript implements ScriptEditor { // global ScriptEditorForJavaScript instance private static ScriptEditorForJavaScript theScriptEditorForJavaScript; @@ -51,7 +50,8 @@ public class ScriptEditorForJavaScript implements ScriptEditor private Main rhinoWindow; private URL scriptURL; // global list of ScriptEditors, key is URL of file being edited - private static Map BEING_EDITED = new HashMap(); + private static Map BEING_EDITED = new + HashMap(); static { try { @@ -62,6 +62,7 @@ public class ScriptEditorForJavaScript implements ScriptEditor StringBuilder buf = new StringBuilder(); byte[] b = new byte[1024]; int len; + while ((len = in.read(b)) != -1) { buf.append(new String(b, 0, len)); } @@ -69,11 +70,9 @@ public class ScriptEditorForJavaScript implements ScriptEditor in.close(); JSTEMPLATE = buf.toString(); - } - catch (IOException ioe) { + } catch (IOException ioe) { JSTEMPLATE = "// JavaScript script"; - } - catch (Exception e) { + } catch (Exception e) { JSTEMPLATE = "// JavaScript script"; } } @@ -81,13 +80,13 @@ public class ScriptEditorForJavaScript implements ScriptEditor /** * Returns the global ScriptEditorForJavaScript instance. */ - public static synchronized ScriptEditorForJavaScript getEditor() - { - if (theScriptEditorForJavaScript == null) - { + + public static synchronized ScriptEditorForJavaScript getEditor() { + if (theScriptEditorForJavaScript == null) { theScriptEditorForJavaScript = new ScriptEditorForJavaScript(); } + return theScriptEditorForJavaScript; } @@ -99,8 +98,7 @@ public class ScriptEditorForJavaScript implements ScriptEditor * @return The ScriptEditorForJavaScript associated with * the given URL if one exists, otherwise null. */ - public static ScriptEditorForJavaScript getEditor(URL url) - { + public static ScriptEditorForJavaScript getEditor(URL url) { synchronized (BEING_EDITED) { return BEING_EDITED.get(url); } @@ -110,9 +108,8 @@ public class ScriptEditorForJavaScript implements ScriptEditor * Returns whether or not the script source being edited in this * ScriptEditorForJavaScript has been modified */ - public boolean isModified() - { - return rhinoWindow.isModified( scriptURL ); + public boolean isModified() { + return rhinoWindow.isModified(scriptURL); } /** @@ -120,9 +117,8 @@ public class ScriptEditorForJavaScript implements ScriptEditor * * @return The text displayed in this ScriptEditorForJavaScript */ - public String getText() - { - return rhinoWindow.getText( scriptURL ); + public String getText() { + return rhinoWindow.getText(scriptURL); } /** @@ -130,8 +126,7 @@ public class ScriptEditorForJavaScript implements ScriptEditor * * @return The url of this ScriptEditorForJavaScript */ - public String getURL() - { + public String getURL() { return scriptURL.toString(); } @@ -140,8 +135,7 @@ public class ScriptEditorForJavaScript implements ScriptEditor * * @return The template text for JavaScript scripts */ - public String getTemplate() - { + public String getTemplate() { return JSTEMPLATE; } @@ -150,8 +144,7 @@ public class ScriptEditorForJavaScript implements ScriptEditor * * @return The default extension for JavaScript scripts */ - public String getExtension() - { + public String getExtension() { return "js"; } @@ -163,36 +156,36 @@ public class ScriptEditorForJavaScript implements ScriptEditor * @param context The context in which to execute the script * @param entry The metadata describing the script */ - public void edit(final XScriptContext context, ScriptMetaData entry) - { + public void edit(final XScriptContext context, ScriptMetaData entry) { try { String sUrl = entry.getParcelLocation(); - if ( !sUrl.endsWith( "/" ) ) - { + + if (!sUrl.endsWith("/")) { sUrl += "/"; } + sUrl += entry.getLanguageName(); final URL url = entry.getSourceURL(); SwingInvocation.invoke( - new Runnable() { - public void run() { - synchronized (BEING_EDITED) { - ScriptEditorForJavaScript editor = - BEING_EDITED.get(url); - if (editor == null) { - editor = new ScriptEditorForJavaScript( - context, url); - BEING_EDITED.put(url, editor); - } + new Runnable() { + public void run() { + synchronized (BEING_EDITED) { + ScriptEditorForJavaScript editor = + BEING_EDITED.get(url); + + if (editor == null) { + editor = new ScriptEditorForJavaScript( + context, url); + BEING_EDITED.put(url, editor); } - assert rhinoWindow != null; - rhinoWindow.showScriptWindow(url); - rhinoWindow.toFront(); } - }); - } - catch ( IOException e ) - { + + assert rhinoWindow != null; + rhinoWindow.showScriptWindow(url); + rhinoWindow.toFront(); + } + }); + } catch (IOException e) { LogUtils.DEBUG("Caught exception: " + e); LogUtils.DEBUG(LogUtils.getTrace(e)); } @@ -200,15 +193,13 @@ public class ScriptEditorForJavaScript implements ScriptEditor // Ensures that new instances of this class can only be created using // the factory methods - private ScriptEditorForJavaScript() - { + private ScriptEditorForJavaScript() { } - private ScriptEditorForJavaScript(XScriptContext context, URL url) - { + private ScriptEditorForJavaScript(XScriptContext context, URL url) { initUI(); - Scriptable scope = getScope( context ); - this.rhinoWindow.openFile(url, scope, new closeHandler( url ) ); + Scriptable scope = getScope(context); + this.rhinoWindow.openFile(url, scope, new closeHandler(url)); this.scriptURL = url; @@ -219,30 +210,26 @@ public class ScriptEditorForJavaScript implements ScriptEditor * */ - public Object execute() throws Exception - { + public Object execute() throws Exception { rhinoWindow.toFront(); - return this.rhinoWindow.runScriptWindow( scriptURL ); + return this.rhinoWindow.runScriptWindow(scriptURL); } /** * Indicates the line where error occurred * */ - public void indicateErrorLine( int lineNum ) - { + public void indicateErrorLine(int lineNum) { this.rhinoWindow.toFront(); - this.rhinoWindow.highlighLineInScriptWindow( scriptURL, lineNum ); + this.rhinoWindow.highlighLineInScriptWindow(scriptURL, lineNum); } // This code is based on the main method of the Rhino Debugger Main class // We pass in the XScriptContext in the global scope for script execution private void initUI() { try { - synchronized ( ScriptEditorForJavaScript.class ) - { - if ( this.rhinoWindow != null ) - { + synchronized (ScriptEditorForJavaScript.class) { + if (this.rhinoWindow != null) { return; } @@ -263,7 +250,7 @@ public class ScriptEditorForJavaScript implements ScriptEditor return org.mozilla.javascript.tools.shell.Main.getScope(); } }); - sdb.addWindowListener( new WindowAdapter() { + sdb.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { shutdown(); @@ -272,35 +259,34 @@ public class ScriptEditorForJavaScript implements ScriptEditor this.rhinoWindow = sdb; } } catch (Exception exc) { - LogUtils.DEBUG( LogUtils.getTrace( exc ) ); + LogUtils.DEBUG(LogUtils.getTrace(exc)); } } - private void shutdown() - { + private void shutdown() { // dereference Rhino Debugger window this.rhinoWindow = null; this.scriptURL = null; + // remove all scripts from BEING_EDITED - synchronized( BEING_EDITED ) - { + synchronized (BEING_EDITED) { java.util.Iterator iter = BEING_EDITED.keySet().iterator(); java.util.ArrayList keysToRemove = new java.util.ArrayList(); - while ( iter.hasNext() ) - { + + while (iter.hasNext()) { URL key = iter.next(); - keysToRemove.add( key ); + keysToRemove.add(key); } - for ( int i=0; i", 1, null); - result = Context.toString(result); - return result; } - catch (JavaScriptException jse) { - LogUtils.DEBUG( "Caught JavaScriptException exception for JavaScript type = " + jse.getClass() ); - String message = jse.getMessage(); - Object wrap = jse.getValue(); - LogUtils.DEBUG( "\t message " + message ); - LogUtils.DEBUG( "\t wrapped type " + wrap.getClass() ); - LogUtils.DEBUG( "\t wrapped toString " + wrap.toString() ); - ScriptExceptionRaisedException se = new - ScriptExceptionRaisedException( message ); - se.lineNum = -1; - se.language = "JavaScript"; - se.scriptName = metaData.getLanguageName(); - se.exceptionType = wrap.getClass().getName(); - se.language = metaData.getLanguage(); - LogUtils.DEBUG( "ExceptionRaised exception " ); - LogUtils.DEBUG( "\t message " + se.getMessage() ); - LogUtils.DEBUG( "\t lineNum " + se.lineNum ); - 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 ); + + String source; + + if (editor != null && editor.isModified()) { + LogUtils.DEBUG("GOT A MODIFIED SOURCE"); + source = editor.getText(); + } else { + metaData.loadSource(); + source = metaData.getSource(); + } - catch (Exception ex) { - LogUtils.DEBUG("Caught Exception " + ex ); - LogUtils.DEBUG("rethrowing as ScriptFramework error" ); + + if (source == null || source.length() == 0) { throw new ScriptFrameworkErrorException( - ex.getMessage(), null, + "Failed to read source data for script", null, metaData.getLanguageName(), metaData.getLanguage(), - ScriptFrameworkErrorType.UNKNOWN ); + ScriptFrameworkErrorType.UNKNOWN); } - finally { - if ( ctxt != null ) - { - Context.exit(); - } + + /* Set the context ClassLoader on the current thread to + be our custom ClassLoader. This is the suggested method + for setting up a ClassLoader to be used by the Rhino + interpreter + */ + if (cl != null) { + Thread.currentThread().setContextClassLoader(cl); + } + + // Initialize a Rhino Context object + ctxt = Context.enter(); + + /* The ImporterTopLevel ensures that importClass and + importPackage statements work in Javascript scripts + Make the XScriptContext available as a global variable + to the script + */ + ImporterTopLevel scope = new ImporterTopLevel(ctxt); + + 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, "", 1, null); + result = Context.toString(result); + return result; + } catch (JavaScriptException jse) { + LogUtils.DEBUG("Caught JavaScriptException exception for JavaScript type = " + + jse.getClass()); + String message = jse.getMessage(); + Object wrap = jse.getValue(); + LogUtils.DEBUG("\t message " + message); + LogUtils.DEBUG("\t wrapped type " + wrap.getClass()); + LogUtils.DEBUG("\t wrapped toString " + wrap.toString()); + ScriptExceptionRaisedException se = new + ScriptExceptionRaisedException(message); + se.lineNum = -1; + se.language = "JavaScript"; + se.scriptName = metaData.getLanguageName(); + se.exceptionType = wrap.getClass().getName(); + se.language = metaData.getLanguage(); + LogUtils.DEBUG("ExceptionRaised exception "); + LogUtils.DEBUG("\t message " + se.getMessage()); + LogUtils.DEBUG("\t lineNum " + se.lineNum); + 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); + } 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); + } finally { + if (ctxt != null) { + Context.exit(); } } + } - private void raiseEditor( int lineNum ) - { - try - { - URL sourceUrl = metaData.getSourceURL(); - ScriptEditorForJavaScript editor = ScriptEditorForJavaScript.getEditor( sourceUrl ); - if ( editor == null ) - { - editor = ScriptEditorForJavaScript.getEditor(); - editor.edit( - ScriptContext.createContext(m_xModel, m_xInvocContext, - m_xContext, m_xMultiComponentFactory), metaData ); - editor = ScriptEditorForJavaScript.getEditor( sourceUrl ); - } - if ( editor != null ) - { - System.out.println("** Have raised IDE for JavaScript, calling indicateErrorLine for line " + lineNum ); - editor.indicateErrorLine( lineNum ); - } + private void raiseEditor(int lineNum) { + try { + URL sourceUrl = metaData.getSourceURL(); + ScriptEditorForJavaScript editor = ScriptEditorForJavaScript.getEditor( + sourceUrl); + + if (editor == null) { + editor = ScriptEditorForJavaScript.getEditor(); + editor.edit( + ScriptContext.createContext(m_xModel, m_xInvocContext, + m_xContext, m_xMultiComponentFactory), metaData); + editor = ScriptEditorForJavaScript.getEditor(sourceUrl); } - catch( Exception ignore ) - { + + if (editor != null) { + System.out.println("** Have raised IDE for JavaScript, calling indicateErrorLine for line " + + lineNum); + editor.indicateErrorLine(lineNum); } + } catch (Exception ignore) { } + } } diff --git a/scripting/java/org/openoffice/idesupport/CommandLineTools.java b/scripting/java/org/openoffice/idesupport/CommandLineTools.java index c47e2457c121..8fa9269ca361 100644 --- a/scripting/java/org/openoffice/idesupport/CommandLineTools.java +++ b/scripting/java/org/openoffice/idesupport/CommandLineTools.java @@ -43,28 +43,25 @@ public class CommandLineTools { // Get the URL for the Office DTD directory and pass it to the // XMLParserFactory so that Office xml files can be parsed - if (officePath == null) - { + if (officePath == null) { try { SVersionRCFile sv = SVersionRCFile.createInstance(); - if (sv.getDefaultVersion() != null) - { + + if (sv.getDefaultVersion() != null) { officePath = sv.getDefaultVersion().getPath(); } - } - catch (IOException ioe) { + } catch (IOException ioe) { System.err.println("Error getting Office directory"); } } - if (officePath == null) - { + if (officePath == null) { driver.fatalUsage("Error: Office Installation path not set"); } File officeDir = new File(officePath); - if (!officeDir.exists() || !officeDir.isDirectory()) - { + + if (!officeDir.exists() || !officeDir.isDirectory()) { driver.fatalUsage( "Error: Office Installation path not valid: " + officePath); } @@ -78,8 +75,7 @@ public class CommandLineTools { else { try { command.execute(); - } - catch (Exception e) { + } catch (Exception e) { driver.fatal("Error: " + e.getMessage()); } } @@ -91,17 +87,17 @@ public class CommandLineTools { private void printUsage() { System.out.println("java " + getClass().getName() + " -h " + - "prints this message"); + "prints this message"); System.out.println("java " + getClass().getName() + - " [-o Path to Office Installation] " + - "-d