scripting: Format_java_code.sh initial run

Conflicts:
	scripting/java/com/sun/star/script/framework/io/UCBStreamHandler.java

Change-Id: I09b94d8c96dfbaf498bd93a0088feb80a9e4afb6
This commit is contained in:
Robert Antoni Buj i Gelonch
2014-09-25 19:41:12 +02:00
committed by David Tardon
parent 36d24bced0
commit 6f42a71439
156 changed files with 6399 additions and 6950 deletions

View File

@@ -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;
}
}

View File

@@ -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<XBrowseNode> 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<XBrowseNode>( names.length );
browsenodes = new ArrayList<XBrowseNode>(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<String,String>() );
ScriptEntry entry = new ScriptEntry(language, languageName, "",
new HashMap<String, String>());
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<XBrowseNode>(4);
if (browsenodes == null) {
LogUtils.DEBUG("browsenodes null!!");
browsenodes = new ArrayList<XBrowseNode>(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;
}

View File

@@ -25,14 +25,17 @@ import com.sun.star.script.framework.log.*;
import com.sun.star.script.framework.container.*;
public class PkgProviderBrowseNode extends ProviderBrowseNode
{
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 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

View File

@@ -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<XBrowseNode> 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<XBrowseNode>( parcels.length );
browsenodes = new ArrayList<XBrowseNode>(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<XBrowseNode>( 5 );
if (browsenodes == null) {
browsenodes = new ArrayList<XBrowseNode>(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;
}

View File

@@ -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<String,String>() );
language, languageName, "", new HashMap<String, String>());
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;
}