Kaydet (Commit) e41597ea authored tarafından Robert Antoni Buj i Gelonch's avatar Robert Antoni Buj i Gelonch Kaydeden (comit) David Tardon

scripting: line break (code formatting)

Change-Id: Ib1a8d7e4bdaad2f4eae822d9af280fd5b6f9dd7b
Reviewed-on: https://gerrit.libreoffice.org/11794Reviewed-by: 's avatarDavid Tardon <dtardon@redhat.com>
Tested-by: 's avatarDavid Tardon <dtardon@redhat.com>
üst b1d48f0d
......@@ -39,6 +39,7 @@ import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
public class DialogFactory {
private static DialogFactory factory;
private XComponentContext xComponentContext;
......@@ -58,8 +59,7 @@ public class DialogFactory {
}
}
public static DialogFactory getDialogFactory()
throws java.lang.Exception {
public static DialogFactory getDialogFactory() throws java.lang.Exception {
if (factory == null) {
throw new java.lang.Exception("DialogFactory not initialized");
}
......@@ -67,8 +67,6 @@ public class DialogFactory {
return factory;
}
public String showInputDialog(String title, String prompt) {
final XDialog xDialog;
......@@ -79,19 +77,22 @@ public class DialogFactory {
}
// add an action listener to the button controls
XControlContainer controls = UnoRuntime.queryInterface(XControlContainer.class,
xDialog);
XControlContainer controls =
UnoRuntime.queryInterface(XControlContainer.class, xDialog);
XButton okButton =
UnoRuntime.queryInterface(XButton.class, controls.getControl("Ok"));
XButton okButton = UnoRuntime.queryInterface(
XButton.class, controls.getControl("Ok"));
okButton.setActionCommand("Ok");
XButton cancelButton = UnoRuntime.queryInterface(
XButton.class, controls.getControl("Cancel"));
XButton cancelButton =
UnoRuntime.queryInterface(XButton.class, controls.getControl("Cancel"));
cancelButton.setActionCommand("Cancel");
final XTextComponent textField = UnoRuntime.queryInterface(
XTextComponent.class, controls.getControl("NameField"));
final XTextComponent textField =
UnoRuntime.queryInterface(XTextComponent.class,
controls.getControl("NameField"));
final ResultHolder resultHolder = new ResultHolder();
......@@ -120,8 +121,9 @@ public class DialogFactory {
return (String)resultHolder.getResult();
}
private void setDimensions(Object o, int x, int y, int width, int height)
throws com.sun.star.uno.Exception {
private void setDimensions(Object o, int x, int y, int width, int height) throws
com.sun.star.uno.Exception {
XPropertySet props = UnoRuntime.queryInterface(XPropertySet.class, o);
props.setPropertyValue("PositionX", Integer.valueOf(x));
......@@ -130,8 +132,9 @@ public class DialogFactory {
props.setPropertyValue("Width", Integer.valueOf(width));
}
private XDialog createInputDialog(String title, String prompt)
throws com.sun.star.uno.Exception {
private XDialog createInputDialog(String title, String prompt) throws
com.sun.star.uno.Exception {
if (title == null || title.length() == 0) {
title = "Scripting Framework";
}
......@@ -146,18 +149,19 @@ public class DialogFactory {
// create the dialog model and set the properties
Object dialogModel = xMultiComponentFactory.createInstanceWithContext(
"com.sun.star.awt.UnoControlDialogModel", xComponentContext);
"com.sun.star.awt.UnoControlDialogModel",
xComponentContext);
setDimensions(dialogModel, 100, 100, 157, 58);
XPropertySet props = UnoRuntime.queryInterface(
XPropertySet.class, dialogModel);
XPropertySet props =
UnoRuntime.queryInterface(XPropertySet.class, dialogModel);
props.setPropertyValue("Title", title);
// get the service manager from the dialog model
XMultiServiceFactory xMultiServiceFactory =
UnoRuntime.queryInterface(
XMultiServiceFactory.class, dialogModel);
UnoRuntime.queryInterface(XMultiServiceFactory.class, dialogModel);
// create the label model and set the properties
Object label = xMultiServiceFactory.createInstance(
......@@ -165,8 +169,9 @@ public class DialogFactory {
setDimensions(label, 15, 5, 134, 12);
XPropertySet labelProps = UnoRuntime.queryInterface(
XPropertySet.class, label);
XPropertySet labelProps =
UnoRuntime.queryInterface(XPropertySet.class, label);
labelProps.setPropertyValue("Name", "PromptLabel");
labelProps.setPropertyValue("Label", prompt);
......@@ -176,8 +181,9 @@ public class DialogFactory {
setDimensions(edit, 15, 18, 134, 12);
XPropertySet editProps = UnoRuntime.queryInterface(
XPropertySet.class, edit);
XPropertySet editProps =
UnoRuntime.queryInterface(XPropertySet.class, edit);
editProps.setPropertyValue("Name", "NameField");
// create the OK button
......@@ -186,8 +192,9 @@ public class DialogFactory {
setDimensions(okButtonModel, 40, 39, 38, 15);
XPropertySet buttonProps = UnoRuntime.queryInterface(
XPropertySet.class, okButtonModel);
XPropertySet buttonProps =
UnoRuntime.queryInterface(XPropertySet.class, okButtonModel);
buttonProps.setPropertyValue("Name", "Ok");
buttonProps.setPropertyValue("Label", "Ok");
......@@ -197,14 +204,15 @@ public class DialogFactory {
setDimensions(cancelButtonModel, 83, 39, 38, 15);
buttonProps = UnoRuntime.queryInterface(
XPropertySet.class, cancelButtonModel);
buttonProps =
UnoRuntime.queryInterface(XPropertySet.class, cancelButtonModel);
buttonProps.setPropertyValue("Name", "Cancel");
buttonProps.setPropertyValue("Label", "Cancel");
// insert the control models into the dialog model
XNameContainer xNameCont = UnoRuntime.queryInterface(XNameContainer.class,
dialogModel);
XNameContainer xNameCont =
UnoRuntime.queryInterface(XNameContainer.class, dialogModel);
xNameCont.insertByName("PromptLabel", label);
xNameCont.insertByName("NameField", edit);
......@@ -213,21 +221,23 @@ public class DialogFactory {
// create the dialog control and set the model
Object dialog = xMultiComponentFactory.createInstanceWithContext(
"com.sun.star.awt.UnoControlDialog", xComponentContext);
XControl xControl = UnoRuntime.queryInterface(
XControl.class, dialog);
"com.sun.star.awt.UnoControlDialog",
xComponentContext);
XControl xControl = UnoRuntime.queryInterface(XControl.class, dialog);
XControlModel xControlModel =
UnoRuntime.queryInterface(XControlModel.class, dialogModel);
XControlModel xControlModel = UnoRuntime.queryInterface(XControlModel.class,
dialogModel);
xControl.setModel(xControlModel);
// create a peer
Object toolkit = xMultiComponentFactory.createInstanceWithContext(
"com.sun.star.awt.ExtToolkit", xComponentContext);
XToolkit xToolkit = UnoRuntime.queryInterface(
XToolkit.class, toolkit);
XWindow xWindow = UnoRuntime.queryInterface(
XWindow.class, xControl);
"com.sun.star.awt.ExtToolkit",
xComponentContext);
XToolkit xToolkit = UnoRuntime.queryInterface(XToolkit.class, toolkit);
XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, xControl);
xWindow.setVisible(false);
xControl.createPeer(xToolkit, null);
......@@ -235,6 +245,7 @@ public class DialogFactory {
}
private static class ResultHolder {
private Object result = null;
public Object getResult() {
......@@ -245,4 +256,4 @@ public class DialogFactory {
this.result = result;
}
}
}
}
\ No newline at end of file
......@@ -48,19 +48,17 @@ import java.util.HashMap;
import javax.swing.JOptionPane;
public class ParcelBrowseNode extends PropertySet
implements XBrowseNode, XInvocation {
public class ParcelBrowseNode extends PropertySet implements
XBrowseNode, XInvocation {
private ScriptProvider provider;
private Collection<XBrowseNode> browsenodes;
private ParcelContainer container;
private Parcel parcel;
public ParcelBrowseNode(ScriptProvider provider, ParcelContainer container,
String parcelName) {
this.provider = provider;
this.container = container;
......@@ -68,30 +66,28 @@ public class ParcelBrowseNode extends PropertySet
try {
this.parcel = (Parcel)this.container.getByName(parcelName);
} catch (Exception e) {
LogUtils.DEBUG("** Exception: " + e);
LogUtils.DEBUG(" ** Failed to get parcel named " +
parcelName + " from container");
LogUtils.DEBUG(" ** Failed to get parcel named " + parcelName +
" from container");
}
registerProperty("Deletable", new Type(boolean.class),
(short)0, "deletable");
registerProperty("Editable", new Type(boolean.class),
(short)0, "editable");
registerProperty("Creatable", new Type(boolean.class),
(short)0, "creatable");
registerProperty("Renamable", new Type(boolean.class),
(short)0, "renamable");
registerProperty("Deletable", new Type(boolean.class), (short)0, "deletable");
registerProperty("Editable", new Type(boolean.class), (short)0, "editable");
registerProperty("Creatable", new Type(boolean.class), (short)0, "creatable");
registerProperty("Renamable", new Type(boolean.class), (short)0, "renamable");
String parcelDirUrl = parcel.getPathToParcel();
XComponentContext xCtx = provider.getScriptingContext().getComponentContext();
XMultiComponentFactory xFac = xCtx.getServiceManager();
try {
XSimpleFileAccess xSFA = UnoRuntime.queryInterface(XSimpleFileAccess.class,
xFac.createInstanceWithContext(
"com.sun.star.ucb.SimpleFileAccess",
xCtx));
XSimpleFileAccess xSFA =
UnoRuntime.queryInterface(XSimpleFileAccess.class,
xFac.createInstanceWithContext(
"com.sun.star.ucb.SimpleFileAccess",
xCtx));
} catch (com.sun.star.uno.Exception e) {
// TODO propagate potential errors
LogUtils.DEBUG("Caught exception creating ParcelBrowseNode " + e);
......@@ -150,11 +146,13 @@ public class ParcelBrowseNode extends PropertySet
}
public Object invoke(String aFunctionName, Object[] aParams,
short[][] aOutParamIndex, Object[][] aOutParam)
throws com.sun.star.lang.IllegalArgumentException,
short[][] aOutParamIndex, Object[][] aOutParam) throws
com.sun.star.lang.IllegalArgumentException,
com.sun.star.script.CannotConvertException,
com.sun.star.reflection.InvocationTargetException {
LogUtils.DEBUG("ParcelBrowseNode invoke for " + aFunctionName);
// Initialise the out parameters - not used but prevents error in
// UNO bridge
aOutParamIndex[0] = new short[0];
......@@ -166,21 +164,22 @@ public class ParcelBrowseNode extends PropertySet
try {
String newName;
if (aParams == null || aParams.length < 1 ||
!AnyConverter.isString(aParams[0])) {
if (aParams == null || aParams.length < 1
|| !AnyConverter.isString(aParams[0])) {
String prompt = "Enter name for new Script";
String title = "Create Script";
// try to get a DialogFactory instance, if it fails
// just use a Swing JOptionPane to prompt for the name
try {
DialogFactory dialogFactory =
DialogFactory.getDialogFactory();
DialogFactory dialogFactory = DialogFactory.getDialogFactory();
newName = dialogFactory.showInputDialog(title, prompt);
} catch (Exception e) {
newName = JOptionPane.showInputDialog(null, prompt, title,
JOptionPane.QUESTION_MESSAGE);
}
} else {
newName = AnyConverter.toString(aParams[0]);
......@@ -190,7 +189,10 @@ public class ParcelBrowseNode extends PropertySet
result = new Any(new Type(Boolean.class), Boolean.FALSE);
} else {
String source = provider.getScriptEditor().getTemplate();
String languageName = newName + "." + provider.getScriptEditor().getExtension();
String languageName =
newName + "." + provider.getScriptEditor().getExtension();
String language = container.getLanguage();
ScriptEntry entry = new ScriptEntry(language, languageName, "",
......@@ -200,7 +202,8 @@ public class ParcelBrowseNode extends PropertySet
ScriptMetaData data = new ScriptMetaData(parcel, entry, source);
parcel.insertByName(languageName, data);
ScriptBrowseNode sbn = new ScriptBrowseNode(provider, parcel, languageName);
ScriptBrowseNode sbn =
new ScriptBrowseNode(provider, parcel, languageName);
if (browsenodes == null) {
LogUtils.DEBUG("browsenodes null!!");
......@@ -208,14 +211,12 @@ public class ParcelBrowseNode extends PropertySet
}
browsenodes.add(sbn);
result = new Any(new Type(XBrowseNode.class), sbn);
}
} catch (Exception e) {
LogUtils.DEBUG("ParcelBrowseNode[create] failed with: " + e);
LogUtils.DEBUG(LogUtils.getTrace(e));
result = new Any(new Type(Boolean.class), Boolean.FALSE);
}
} else if (aFunctionName.equals("Deletable")) {
try {
......@@ -228,6 +229,7 @@ public class ParcelBrowseNode extends PropertySet
result = new Any(new Type(Boolean.class), Boolean.FALSE);
}
} else if (aFunctionName.equals("Renamable")) {
String newName = null;
try {
......@@ -240,13 +242,13 @@ public class ParcelBrowseNode extends PropertySet
// try to get a DialogFactory instance, if it fails
// just use a Swing JOptionPane to prompt for the name
try {
DialogFactory dialogFactory =
DialogFactory.getDialogFactory();
DialogFactory dialogFactory = DialogFactory.getDialogFactory();
newName = dialogFactory.showInputDialog(title, prompt);
} catch (Exception e) {
newName = JOptionPane.showInputDialog(null, prompt, title,
JOptionPane.QUESTION_MESSAGE);
}
} else {
newName = AnyConverter.toString(aParams[0]);
......@@ -259,8 +261,8 @@ public class ParcelBrowseNode extends PropertySet
getChildNodes();
}
ScriptBrowseNode[] childNodes = browsenodes.toArray(new
ScriptBrowseNode[browsenodes.size()]);
ScriptBrowseNode[] childNodes =
browsenodes.toArray(new ScriptBrowseNode[browsenodes.size()]);
for (int index = 0; index < childNodes.length; index++) {
childNodes[ index ].updateURI(p);
......@@ -280,14 +282,14 @@ public class ParcelBrowseNode extends PropertySet
return result;
}
public void setValue(String aPropertyName, Object aValue)
throws com.sun.star.beans.UnknownPropertyException,
public void setValue(String aPropertyName, Object aValue) throws
com.sun.star.beans.UnknownPropertyException,
com.sun.star.script.CannotConvertException,
com.sun.star.reflection.InvocationTargetException {
}
public Object getValue(String aPropertyName)
throws com.sun.star.beans.UnknownPropertyException {
public Object getValue(String aPropertyName) throws
com.sun.star.beans.UnknownPropertyException {
return null;
}
......@@ -298,4 +300,4 @@ public class ParcelBrowseNode extends PropertySet
public boolean hasProperty(String aName) {
return false;
}
}
}
\ No newline at end of file
......@@ -24,12 +24,13 @@ import com.sun.star.script.framework.provider.ScriptProvider;
import com.sun.star.uno.XComponentContext;
public class PkgProviderBrowseNode extends ProviderBrowseNode {
public PkgProviderBrowseNode(ScriptProvider provider, ParcelContainer container,
XComponentContext xCtx) {
super(provider, container, xCtx);
LogUtils.DEBUG("*** PkgProviderBrowseNode ctor container name = " +
container.getName());
LogUtils.DEBUG("*** PkgProviderBrowseNode ctor container path = " +
......@@ -38,8 +39,7 @@ public class PkgProviderBrowseNode extends ProviderBrowseNode {
container.getElementNames().length);
}
@Override
public String getName() {
@Override public String getName() {
return (container != null) ? container.getName() : "Unknown";
}
......
......@@ -44,37 +44,32 @@ import java.util.Collection;
import javax.swing.JOptionPane;
public class ProviderBrowseNode extends PropertySet
implements XBrowseNode, XInvocation {
public class ProviderBrowseNode extends PropertySet implements
XBrowseNode, XInvocation {
private ScriptProvider provider;
private Collection<XBrowseNode> browsenodes;
private String name;
protected ParcelContainer container;
private XComponentContext m_xCtx;
public ProviderBrowseNode(ScriptProvider provider, ParcelContainer container,
XComponentContext xCtx) {
LogUtils.DEBUG("*** ProviderBrowseNode ctor");
this.container = container;
this.name = this.container.getLanguage();
this.provider = provider;
this.m_xCtx = xCtx;
registerProperty("Deletable", new Type(boolean.class),
(short)0, "deletable");
registerProperty("Creatable", new Type(boolean.class),
(short)0, "creatable");
registerProperty("Editable", new Type(boolean.class),
(short)0, "editable");
registerProperty("Deletable", new Type(boolean.class), (short)0, "deletable");
registerProperty("Creatable", new Type(boolean.class), (short)0, "creatable");
registerProperty("Editable", new Type(boolean.class), (short)0, "editable");
XSimpleFileAccess xSFA = null;
XMultiComponentFactory xFac = m_xCtx.getServiceManager();
try {
xSFA = UnoRuntime.queryInterface(XSimpleFileAccess.class,
xFac.createInstanceWithContext(
"com.sun.star.ucb.SimpleFileAccess",
......@@ -84,7 +79,6 @@ public class ProviderBrowseNode extends PropertySet
catch (com.sun.star.uno.Exception e) {
LogUtils.DEBUG("Caught exception in creation of ProviderBrowseNode ");
LogUtils.DEBUG(LogUtils.getTrace(e));
}
}
......@@ -96,9 +90,11 @@ public class ProviderBrowseNode extends PropertySet
LogUtils.DEBUG("***** ProviderBrowseNode.getChildNodes()");
if (hasChildNodes()) {
// needs initialisation?
LogUtils.DEBUG("** ProviderBrowseNode.getChildNodes(), container is " +
container);
String[] parcels = container.getElementNames();
browsenodes = new ArrayList<XBrowseNode>(parcels.length);
......@@ -113,13 +109,16 @@ public class ProviderBrowseNode extends PropertySet
}
ParcelContainer[] packageContainers = container.getChildContainers();
LogUtils.DEBUG("**** For container named " + container.getName() +
" with root path " + container.getParcelContainerDir() + " has " +
packageContainers.length + " child containers ");
" with root path " + container.getParcelContainerDir() +
" has " + packageContainers.length + " child containers ");
for (ParcelContainer packageContainer : packageContainers) {
XBrowseNode node = new PkgProviderBrowseNode(provider, packageContainer,
m_xCtx);
XBrowseNode node =
new PkgProviderBrowseNode(provider, packageContainer, m_xCtx);
browsenodes.add(node);
}
} else {
......@@ -134,15 +133,13 @@ public class ProviderBrowseNode extends PropertySet
boolean result = true;
if (container == null ||
(!container.hasElements() &&
container.getChildContainers().length == 0)) {
(!container.hasElements() && container.getChildContainers().length == 0)) {
result = false;
}
LogUtils.DEBUG("***** ProviderBrowseNode.hasChildNodes(): " +
"name=" + name +
", path=" + container.getParcelContainerDir() +
", result=" + result);
LogUtils.DEBUG("***** ProviderBrowseNode.hasChildNodes(): " + "name=" + name +
", path=" + container.getParcelContainerDir() + ", result=" + result);
return result;
}
......@@ -162,10 +159,11 @@ public class ProviderBrowseNode extends PropertySet
}
public Object invoke(String aFunctionName, Object[] aParams,
short[][] aOutParamIndex, Object[][] aOutParam)
throws com.sun.star.lang.IllegalArgumentException,
short[][] aOutParamIndex, Object[][] aOutParam) throws
com.sun.star.lang.IllegalArgumentException,
com.sun.star.script.CannotConvertException,
com.sun.star.reflection.InvocationTargetException {
// Initialise the out parameters - not used but prevents error in
// UNO bridge
aOutParamIndex[0] = new short[0];
......@@ -179,19 +177,20 @@ public class ProviderBrowseNode extends PropertySet
if (aParams == null || aParams.length < 1 ||
!AnyConverter.isString(aParams[0])) {
String prompt = "Enter name for new Parcel";
String title = "Create Parcel";
// try to get a DialogFactory instance, if it fails
// just use a Swing JOptionPane to prompt for the name
try {
DialogFactory dialogFactory =
DialogFactory.getDialogFactory();
DialogFactory dialogFactory = DialogFactory.getDialogFactory();
name = dialogFactory.showInputDialog(title, prompt);
} catch (Exception e) {
name = JOptionPane.showInputDialog(null, prompt, title,
JOptionPane.QUESTION_MESSAGE);
}
} else {
name = AnyConverter.toString(aParams[0]);
......@@ -215,8 +214,6 @@ public class ProviderBrowseNode extends PropertySet
}
browsenodes.add(parcel);
result = new Any(new Type(XBrowseNode.class), parcel);
}
}
......@@ -233,14 +230,15 @@ public class ProviderBrowseNode extends PropertySet
return result;
}
public void setValue(String aPropertyName, Object aValue)
throws com.sun.star.beans.UnknownPropertyException,
public void setValue(String aPropertyName, Object aValue) throws
com.sun.star.beans.UnknownPropertyException,
com.sun.star.script.CannotConvertException,
com.sun.star.reflection.InvocationTargetException {
}
public Object getValue(String aPropertyName)
throws com.sun.star.beans.UnknownPropertyException {
public Object getValue(String aPropertyName) throws
com.sun.star.beans.UnknownPropertyException {
return null;
}
......@@ -251,4 +249,4 @@ public class ProviderBrowseNode extends PropertySet
public boolean hasProperty(String aName) {
return false;
}
}
}
\ No newline at end of file
......@@ -41,6 +41,7 @@ public class DeployedUnoPackagesDB {
private Document document = null;
public DeployedUnoPackagesDB() throws IOException {
ByteArrayInputStream bis = null;
try {
......@@ -61,6 +62,7 @@ public class DeployedUnoPackagesDB {
}
public String[] getDeployedPackages(String language) {
ArrayList<String> packageUrls = new ArrayList<String>(4);
Element main = document.getDocumentElement();
Element root = null;
......@@ -87,10 +89,10 @@ public class DeployedUnoPackagesDB {
(len = packages.getLength()) != 0) {
for (int i = 0; i < len; i++) {
Element e = (Element)packages.item(i);
packageUrls.add(e.getAttribute("value"));
}
}
}
......@@ -111,6 +113,7 @@ public class DeployedUnoPackagesDB {
public boolean removePackage(String language, String url) {
Element main = document.getDocumentElement();
Element langNode = null;
int len = 0;
......@@ -153,6 +156,7 @@ public class DeployedUnoPackagesDB {
}
public void addPackage(String language, String url) {
Element main = document.getDocumentElement();
Element langNode = null;
Element pkgNode = null;
......@@ -184,4 +188,4 @@ public class DeployedUnoPackagesDB {
//add to the Top Element
main.appendChild(langNode);
}
}
}
\ No newline at end of file
......@@ -34,18 +34,22 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
public class Parcel implements XNameContainer {
private ParcelDescriptor m_descriptor;
private String name;
protected ParcelContainer parent;
protected XSimpleFileAccess m_xSFA;
public Parcel(XSimpleFileAccess xSFA, ParcelContainer parent,
ParcelDescriptor desc, String parcelName) {
this(parent, desc, parcelName);
this.m_xSFA = xSFA;
}
private Parcel(ParcelContainer parent, ParcelDescriptor desc,
String parcelName) {
this.parent = parent;
this.m_descriptor = desc;
this.name = parcelName;
......@@ -64,9 +68,11 @@ public class Parcel implements XNameContainer {
public String getName() {
return name;
}
public java.lang.Object getByName(String aName) throws
com.sun.star.container.NoSuchElementException,
com.sun.star.lang.WrappedTargetException {
LogUtils.DEBUG("** Parcel.getByName for " + aName);
ScriptEntry thescript = null;
......@@ -100,7 +106,9 @@ public class Parcel implements XNameContainer {
LogUtils.DEBUG("returning date for " + aName);
return data;
}
public String[] getElementNames() {
String[] results = new String[0];
if (m_descriptor != null) {
......@@ -114,6 +122,7 @@ public class Parcel implements XNameContainer {
return results;
}
public boolean hasByName(String aName) {
boolean result = true;
......@@ -144,10 +153,11 @@ public class Parcel implements XNameContainer {
return m_descriptor != null && m_descriptor.getScriptEntries().length > 0;
}
public void replaceByName(String aName,
java.lang.Object aElement) throws com.sun.star.lang.IllegalArgumentException,
public void replaceByName(String aName, java.lang.Object aElement) throws
com.sun.star.lang.IllegalArgumentException,
com.sun.star.container.NoSuchElementException,
com.sun.star.lang.WrappedTargetException {
// TODO check type of aElement
// if not ok, throw IllegalArgument
if (m_descriptor != null) {
......@@ -159,11 +169,10 @@ public class Parcel implements XNameContainer {
// TODO needs to create source file ( if there is one )
//m_descriptor.write();
} else {
throw new com.sun.star.container.NoSuchElementException("No script named " +
aName);
throw new com.sun.star.container.NoSuchElementException(
"No script named " + aName);
}
}
// TO DO should catch specified exceptions
catch (Exception e) {
......@@ -174,9 +183,10 @@ public class Parcel implements XNameContainer {
}
// create
public void insertByName(String aName,
java.lang.Object aElement) throws com.sun.star.lang.IllegalArgumentException,
ElementExistException, com.sun.star.lang.WrappedTargetException {
public void insertByName(String aName, java.lang.Object aElement) throws
com.sun.star.lang.IllegalArgumentException, ElementExistException,
com.sun.star.lang.WrappedTargetException {
// TODO check the type of aElement and throw#
// if not appropriate
try {
......@@ -190,8 +200,8 @@ public class Parcel implements XNameContainer {
LogUtils.DEBUG("Inserting source: " + script.getSource());
if (!script.writeSourceFile()) {
throw new com.sun.star.lang.WrappedTargetException("Failed to create source file "
+ script.getLanguageName());
throw new com.sun.star.lang.WrappedTargetException(
"Failed to create source file " + script.getLanguageName());
}
}
......@@ -203,18 +213,19 @@ public class Parcel implements XNameContainer {
}
}
private void writeParcelDescriptor()
throws com.sun.star.ucb.CommandAbortedException,
com.sun.star.io.IOException,
com.sun.star.uno.Exception, java.io.IOException {
String pathToDescriptor = PathUtils.make_url(
getPathToParcel(), ParcelDescriptor.PARCEL_DESCRIPTOR_NAME);
XSimpleFileAccess2 xSFA2 = UnoRuntime.queryInterface(XSimpleFileAccess2.class,
m_xSFA);
String pathToDescriptor =
PathUtils.make_url(getPathToParcel(), ParcelDescriptor.PARCEL_DESCRIPTOR_NAME);
XSimpleFileAccess2 xSFA2 =
UnoRuntime.queryInterface(XSimpleFileAccess2.class, m_xSFA);
if (xSFA2 != null) {
ByteArrayOutputStream bos = null;
ByteArrayInputStream bis = null;
XInputStreamImpl xis = null;
......@@ -240,23 +251,26 @@ public class Parcel implements XNameContainer {
public void removeByName(String Name) throws
com.sun.star.container.NoSuchElementException,
com.sun.star.lang.WrappedTargetException {
try {
ScriptMetaData script = (ScriptMetaData)getByName(Name);
if (script != null) {
if (!script.removeSourceFile()) {
LogUtils.DEBUG("** Parcel.removeByName Failed to remove script " + Name);
throw new com.sun.star.lang.WrappedTargetException("Failed to remove script " +
Name);
LogUtils.DEBUG("** Parcel.removeByName Failed to remove script "
+ Name);
throw new com.sun.star.lang.WrappedTargetException(
"Failed to remove script " + Name);
}
LogUtils.DEBUG("** Parcel.removeByName have removed script source file " +
Name);
LogUtils.DEBUG("** Parcel.removeByName have removed script source file "
+ Name);
m_descriptor.removeScriptEntry(script);
writeParcelDescriptor();
} else {
throw new com.sun.star.container.NoSuchElementException("No script named " +
Name);
throw new com.sun.star.container.NoSuchElementException(
"No script named " + Name);
}
} catch (Exception e) {
......@@ -265,6 +279,7 @@ public class Parcel implements XNameContainer {
}
}
// rename parcel
public void rename(String name) {
this.name = name;
......@@ -273,6 +288,7 @@ public class Parcel implements XNameContainer {
public ParcelContainer getParent() {
return parent;
}
/**
* Returns the path of this <tt>Parcel</tt>
*
......@@ -283,5 +299,4 @@ public class Parcel implements XNameContainer {
return path;
}
}
}
\ No newline at end of file
......@@ -42,8 +42,8 @@ public class ParcelDescriptor {
PARCEL_DESCRIPTOR_NAME = "parcel-descriptor.xml";
// Collection of all ParcelDescriptor created for files
private static final Map<File, ParcelDescriptor> PARCEL_DESCRIPTOR_MAP = new
HashMap<File, ParcelDescriptor>(5);
private static final Map<File, ParcelDescriptor> PARCEL_DESCRIPTOR_MAP =
new HashMap<File, ParcelDescriptor>(5);
// This is the default contents of a parcel descriptor to be used when
// creating empty descriptors
......@@ -57,10 +57,6 @@ public class ParcelDescriptor {
private String language = null;
private Map<String, String> languagedepprops = new HashMap<String, String>(3);
public ParcelDescriptor() throws IOException {
ByteArrayInputStream bis = null;
......@@ -148,6 +144,7 @@ public class ParcelDescriptor {
}
public ScriptEntry[] getScriptEntries() {
ArrayList<ScriptEntry> scripts = new ArrayList<ScriptEntry>();
NodeList scriptNodes;
int len;
......@@ -217,8 +214,8 @@ public class ParcelDescriptor {
}
}
ScriptEntry entry = new ScriptEntry(language, languagename, "", langProps,
description);
ScriptEntry entry =
new ScriptEntry(language, languagename, "", langProps, description);
scripts.add(entry);
}
......@@ -375,4 +372,4 @@ public class ParcelDescriptor {
//add to the Top Element
main.appendChild(root);
}
}
}
\ No newline at end of file
......@@ -22,5 +22,4 @@ public class ParsedScriptUri {
public String location;
public String function;
public String parcel;
}
}
\ No newline at end of file
......@@ -33,6 +33,7 @@ public class ScriptEntry implements Cloneable {
public ScriptEntry(String language, String languagename,
String location) {
this.language = language;
this.languagename = languagename;
// logical name/ function name concept
......@@ -114,7 +115,9 @@ public class ScriptEntry implements Cloneable {
@Override
public String toString() {
return "\nLogicalName = " + logicalname + "\nLanguageName = " + languagename +
"\nLocation = " + location + "\nLanguaguageProperties = " + languagedepprops;
return "\nLogicalName = " + logicalname +
"\nLanguageName = " + languagename +
"\nLocation = " + location +
"\nLanguaguageProperties = " + languagedepprops;
}
}
}
\ No newline at end of file
......@@ -36,6 +36,7 @@ import java.util.ArrayList;
import java.util.StringTokenizer;
public class ScriptMetaData extends ScriptEntry {
private boolean hasSource = false;
private String locationPlaceHolder = "";
private String source;
......@@ -51,7 +52,6 @@ public class ScriptMetaData extends ScriptEntry {
this.hasSource = true;
this.source = source;
}
}
public boolean hasSource() {
......@@ -71,18 +71,18 @@ public class ScriptMetaData extends ScriptEntry {
}
public String getScriptFullURL() {
String url = "vnd.sun.star.script:" + parent.getName() + "." + getLanguageName()
+
"?" + "language=" + getLanguage() +
"&location=" + getParcelLocation();
String url = "vnd.sun.star.script:" + parent.getName() + "."
+ getLanguageName() + "?" + "language=" + getLanguage()
+ "&location=" + getParcelLocation();
return url;
}
public String getShortFormScriptURL() {
String url = "vnd.sun.star.script:" + parent.getName() + "." + getLanguageName()
+
"?" + "language=" + getLanguage() +
"&location=" + getLocationPlaceHolder();
String url = "vnd.sun.star.script:" + parent.getName() + "."
+ getLanguageName() + "?" + "language=" + getLanguage()
+ "&location=" + getLocationPlaceHolder();
return url;
}
......@@ -93,21 +93,18 @@ public class ScriptMetaData extends ScriptEntry {
"vnd.sun.star.expand:$BRAND_BASE_DIR/$BRAND_SHARE_SUBDIR";
private static final String USER =
"vnd.sun.star.expand:${$BRAND_INI_DIR/" +
PathUtils.BOOTSTRAP_NAME +
"::UserInstallation}/user";
"vnd.sun.star.expand:${$BRAND_INI_DIR/" + PathUtils.BOOTSTRAP_NAME
+ "::UserInstallation}/user";
private static final String UNO_USER_PACKAGES1 =
"vnd.sun.star.expand:$UNO_USER_PACKAGES_CACHE";
private static final String UNO_USER_PACKAGES2 =
USER + "/uno_packages";
private static final String UNO_USER_PACKAGES2 = USER + "/uno_packages";
private static final String UNO_SHARED_PACKAGES1 =
"$UNO_SHARED_PACKAGES_CACHE";
private static final String UNO_SHARED_PACKAGES2 =
SHARE + "/uno_packages";
private static final String UNO_SHARED_PACKAGES2 = SHARE + "/uno_packages";
public static String getLocationPlaceHolder(String url, String pkgname) {
String result = "Unknown";
......@@ -177,7 +174,6 @@ public class ScriptMetaData extends ScriptEntry {
return parent.getPathToParcel();
}
@Override
public String toString() {
return "\nParcelLocation = " + getParcelLocation() + "\nLocationPlaceHolder = "
......@@ -230,8 +226,8 @@ public class ScriptMetaData extends ScriptEntry {
LogUtils.DEBUG(LogUtils.getTrace(e));
return new URL[0];
}
}
private URL createURL(String path) throws java.net.MalformedURLException {
int indexOfColon = path.indexOf(':');
String scheme = path.substring(0, indexOfColon);
......@@ -246,7 +242,9 @@ public class ScriptMetaData extends ScriptEntry {
public void loadSource() {
try {
URL sourceUrl = getSourceURL();
LogUtils.DEBUG("** In load source BUT not loading yet for " + sourceUrl);
LogUtils.DEBUG("** In load source BUT not loading yet for "
+ sourceUrl);
if (sourceUrl != null) {
StringBuilder buf = new StringBuilder();
......@@ -262,7 +260,8 @@ public class ScriptMetaData extends ScriptEntry {
try {
in.close();
} catch (java.io.IOException ignore) {
LogUtils.DEBUG("** Failed to read scriot from url " + ignore.toString());
LogUtils.DEBUG("** Failed to read scriot from url "
+ ignore.toString());
}
source = buf.toString();
......@@ -273,13 +272,15 @@ public class ScriptMetaData extends ScriptEntry {
}
}
protected boolean writeSourceFile() {
String sourceFilePath = parent.getPathToParcel() + "/" + getLanguageName();
boolean result = false;
try {
XSimpleFileAccess2 xSFA2 = UnoRuntime.queryInterface(XSimpleFileAccess2.class,
parent.m_xSFA);
XSimpleFileAccess2 xSFA2 =
UnoRuntime.queryInterface(XSimpleFileAccess2.class, parent.m_xSFA);
if (xSFA2 != null) {
ByteArrayInputStream bis = new ByteArrayInputStream(getSourceBytes());
......@@ -291,13 +292,12 @@ public class ScriptMetaData extends ScriptEntry {
}
// TODO re-examine exception processing should probably throw
// exceptions back to caller
catch (Exception ignore)
{
catch (Exception ignore) {
}
return result;
}
protected boolean removeSourceFile() {
String parcelLocation = parent.getPathToParcel();
String sourceFilePath = parcelLocation + "/" + getLanguageName();
......@@ -320,4 +320,4 @@ public class ScriptMetaData extends ScriptEntry {
LogUtils.DEBUG("Creating script url for " + sUrl);
return createURL(sUrl);
}
}
}
\ No newline at end of file
......@@ -27,4 +27,4 @@ import org.w3c.dom.Document;
public interface XMLParser {
Document parse(InputStream inputStream) throws IOException;
void write(Document doc, OutputStream out) throws IOException;
}
}
\ No newline at end of file
......@@ -48,8 +48,6 @@ public class XMLParserFactory {
return parser;
}
public static void setOfficeDTDURL(String url) {
officedtdurl = url;
}
......@@ -63,11 +61,11 @@ public class XMLParserFactory {
}
public Document parse(InputStream inputStream) throws IOException {
Document result = null;
try {
DocumentBuilder builder = factory.newDocumentBuilder();
InputSource is = new InputSource(inputStream);
if (officedtdurl != null) {
......@@ -87,6 +85,7 @@ public class XMLParserFactory {
}
public void write(Document doc, OutputStream out) throws IOException {
Class<?> clazz = doc.getClass();
String name = clazz.getName();
......@@ -100,8 +99,10 @@ public class XMLParserFactory {
// these DOM implementations are self writing
Method write;
write = clazz.getDeclaredMethod("write",
new Class[] {OutputStream.class});
write.invoke(doc, new Object[] {out});
} else {
// try xerces serialize package using introspection
......@@ -111,47 +112,61 @@ public class XMLParserFactory {
Class<?> formatterClass = null;
try {
serializerClass = Class.forName(
"org.apache.xml.serialize.XMLSerializer", true, cl);
formatterClass = Class.forName(
"org.apache.xml.serialize.OutputFormat", true, cl);
serializerClass =
Class.forName("org.apache.xml.serialize.XMLSerializer",
true, cl);
formatterClass =
Class.forName("org.apache.xml.serialize.OutputFormat",
true, cl);
} catch (ClassNotFoundException cnfe) {
String prefix = "com.sun.org.apache.xml.internal.";
serializerClass = Class.forName(
prefix + "serialize.XMLSerializer" , true, cl);
formatterClass = Class.forName(
prefix + "serialize.OutputFormat", true, cl);
serializerClass =
Class.forName(prefix + "serialize.XMLSerializer",
true, cl);
formatterClass =
Class.forName(prefix + "serialize.OutputFormat",
true, cl);
}
Object serializerObject = serializerClass.newInstance();
Object formatterObject = formatterClass.newInstance();
// improve output readability using the OutputFormat class
Method method = formatterClass.getMethod("setMethod",
new Class[] {String.class});
Method method =
formatterClass.getMethod("setMethod",
new Class[] {String.class});
method.invoke(formatterObject, new Object[] {"xml"});
method = formatterClass.getMethod("setIndenting",
new Class[] {Boolean.TYPE});
method.invoke(formatterObject, new Object[] {Boolean.TRUE});
// now set up an instance of XMLSerializer with our
// OutputStream and serialize our Document
method = serializerClass.getMethod("setOutputByteStream",
new Class[] {OutputStream.class});
method.invoke(serializerObject, new Object[] {out});
method = serializerClass.getMethod("setOutputFormat",
new Class[] {formatterClass});
method.invoke(serializerObject,
new Object[] {formatterObject});
method = serializerClass.getMethod("asDOMSerializer",
new Class[0]);
Object impl = method.invoke(serializerObject,
new Object[0]);
method.invoke(serializerObject, new Object[] {formatterObject});
method = serializerClass.getMethod("asDOMSerializer", new Class[0]);
Object impl = method.invoke(serializerObject, new Object[0]);
method = impl.getClass().getMethod("serialize",
new Class[] {Document.class});
method.invoke(impl, new Object[] {doc});
}
} catch (NoSuchMethodException ex) {
......@@ -163,4 +178,4 @@ public class XMLParserFactory {
}
}
}
}
}
\ No newline at end of file
......@@ -59,8 +59,9 @@ public class UCBStreamHandler extends URLStreamHandler {
@Override
public void parseURL(URL url, String spec, int start, int limit) {
LogUtils.DEBUG("**XUCBStreamHandler, parseURL: " + url + " spec: " + spec +
" start: " + start + " limit: " + limit);
LogUtils.DEBUG("**XUCBStreamHandler, parseURL: " + url + " spec: "
+ spec + " start: " + start + " limit: " + limit);
String file = url.getFile();
......@@ -99,10 +100,13 @@ public class UCBStreamHandler extends URLStreamHandler {
return getFileStreamFromUCB(sUrl);
} else {
String path = sUrl.substring(0, sUrl.lastIndexOf(separator));
String file = sUrl.substring(
sUrl.lastIndexOf(separator) + separator.length());
LogUtils.DEBUG("getInputStream, load of file from another file eg. " + file +
" from " + path);
String file =
sUrl.substring(sUrl.lastIndexOf(separator) + separator.length());
LogUtils.DEBUG("getInputStream, load of file from another file eg. "
+ file + " from " + path);
return getUCBStream(file, path);
}
}
......@@ -121,11 +125,14 @@ public class UCBStreamHandler extends URLStreamHandler {
throw new java.io.IOException("File is read only");
}
LogUtils.DEBUG("getOutputStream, create o/p stream for file eg. " + path);
LogUtils.DEBUG("getOutputStream, create o/p stream for file eg. "
+ path);
// we will only deal with simple file write
XOutputStream xos = m_xSimpleFileAccess.openFileWrite(path);
XTruncate xtrunc = UnoRuntime.queryInterface(XTruncate.class, xos);
XTruncate xtrunc =
UnoRuntime.queryInterface(XTruncate.class, xos);
if (xtrunc != null) {
xtrunc.truncate();
......@@ -135,7 +142,8 @@ public class UCBStreamHandler extends URLStreamHandler {
}
if (os == null) {
throw new IOException("Failed to get OutputStream for " + sUrl);
throw new IOException("Failed to get OutputStream for "
+ sUrl);
}
} catch (com.sun.star.ucb.CommandAbortedException cae) {
LogUtils.DEBUG("caught exception: " + cae.toString() +
......@@ -155,9 +163,8 @@ public class UCBStreamHandler extends URLStreamHandler {
}
}
private InputStream getUCBStream(String file, String path) throws IOException {
private InputStream getUCBStream(String file, String path)
throws IOException {
InputStream is = null;
InputStream result = null;
......@@ -197,10 +204,11 @@ public class UCBStreamHandler extends URLStreamHandler {
return result;
}
private InputStream getFileStreamFromJarStream(String file, InputStream is)
throws IOException {
ZipEntry entry;
private InputStream getFileStreamFromJarStream(String file,
InputStream is) throws
IOException {
ZipEntry entry;
ZipInputStream zis = new ZipInputStream(is);
while (zis.available() != 0) {
......@@ -214,8 +222,8 @@ public class UCBStreamHandler extends URLStreamHandler {
return null;
}
private InputStream getFileStreamFromUCB(String path)
throws IOException {
private InputStream getFileStreamFromUCB(String path) throws IOException {
InputStream result = null;
XInputStream xInputStream = null;
......@@ -258,13 +266,12 @@ public class UCBStreamHandler extends URLStreamHandler {
try {
xInputStream.closeInput();
} catch (Exception e2) {
LogUtils.DEBUG(
"Error closing XInputStream:" + e2.getMessage());
LogUtils.DEBUG("Error closing XInputStream: "
+ e2.getMessage());
}
}
}
return result;
}
}
}
\ No newline at end of file
......@@ -24,7 +24,9 @@ import java.io.IOException;
import java.io.InputStream;
public class XInputStreamImpl implements XInputStream {
private InputStream is;
public XInputStreamImpl(InputStream is) {
this.is = is;
}
......@@ -32,8 +34,8 @@ public class XInputStreamImpl implements XInputStream {
public int readBytes(/*OUT*/byte[][] aData, /*IN*/int nBytesToRead) throws
com.sun.star.io.NotConnectedException,
com.sun.star.io.BufferSizeExceededException, com.sun.star.io.IOException {
aData[ 0 ] = new byte[ nBytesToRead ];
aData[ 0 ] = new byte[ nBytesToRead ];
int totalBytesRead = 0;
try {
......@@ -56,6 +58,7 @@ public class XInputStreamImpl implements XInputStream {
public int readSomeBytes(/*OUT*/byte[][] aData, /*IN*/int nMaxBytesToRead)
throws com.sun.star.io.NotConnectedException,
com.sun.star.io.BufferSizeExceededException, com.sun.star.io.IOException {
int bytesToRead = nMaxBytesToRead;
int availableBytes = available();
......@@ -70,6 +73,7 @@ public class XInputStreamImpl implements XInputStream {
public void skipBytes(/*IN*/int nBytesToSkip) throws
com.sun.star.io.NotConnectedException,
com.sun.star.io.BufferSizeExceededException, com.sun.star.io.IOException {
try {
is.skip(nBytesToSkip);
} catch (IOException e) {
......@@ -77,8 +81,9 @@ public class XInputStreamImpl implements XInputStream {
}
}
public int available() throws com.sun.star.io.NotConnectedException,
com.sun.star.io.IOException {
public int available() throws
com.sun.star.io.NotConnectedException, com.sun.star.io.IOException {
int bytesAvail = 0;
try {
......@@ -90,13 +95,13 @@ public class XInputStreamImpl implements XInputStream {
return bytesAvail;
}
public void closeInput() throws com.sun.star.io.NotConnectedException,
com.sun.star.io.IOException {
public void closeInput() throws
com.sun.star.io.NotConnectedException, com.sun.star.io.IOException {
try {
is.close();
} catch (IOException e) {
throw new com.sun.star.io.IOException(e);
}
}
}
}
\ No newline at end of file
......@@ -22,6 +22,7 @@ import com.sun.star.io.XInputStream;
import java.io.InputStream;
public class XInputStreamWrapper extends InputStream {
private XInputStream m_xInputStream;
public XInputStreamWrapper(XInputStream xInputStream) {
......@@ -85,5 +86,4 @@ public class XInputStreamWrapper extends InputStream {
throw new java.io.IOException(ioe.getMessage());
}
}
}
}
\ No newline at end of file
......@@ -22,13 +22,15 @@ import com.sun.star.io.XOutputStream;
import java.io.OutputStream;
public class XOutputStreamWrapper extends OutputStream {
private XOutputStream m_xOutputStream;
public XOutputStreamWrapper(XOutputStream xOs) {
this.m_xOutputStream = xOs;
}
@Override
public void write(int b)
throws java.io.IOException {
public void write(int b) throws java.io.IOException {
if (m_xOutputStream == null) {
throw new java.io.IOException("Stream is null");
}
......@@ -42,9 +44,9 @@ public class XOutputStreamWrapper extends OutputStream {
throw new java.io.IOException(ioe.getMessage());
}
}
@Override
public void write(byte[] b)
throws java.io.IOException {
public void write(byte[] b) throws java.io.IOException {
if (m_xOutputStream == null) {
throw new java.io.IOException("Stream is null");
......@@ -57,8 +59,7 @@ public class XOutputStreamWrapper extends OutputStream {
}
}
@Override
public void write(byte[] b, int off, int len)
throws java.io.IOException {
public void write(byte[] b, int off, int len) throws java.io.IOException {
if (m_xOutputStream == null) {
throw new java.io.IOException("Stream is null");
}
......@@ -74,8 +75,7 @@ public class XOutputStreamWrapper extends OutputStream {
}
@Override
public void flush()
throws java.io.IOException {
public void flush() throws java.io.IOException {
if (m_xOutputStream == null) {
throw new java.io.IOException("Stream is null");
}
......@@ -86,9 +86,9 @@ public class XOutputStreamWrapper extends OutputStream {
throw new java.io.IOException(ioe.getMessage());
}
}
@Override
public void close()
throws java.io.IOException {
public void close() throws java.io.IOException {
if (m_xOutputStream == null) {
throw new java.io.IOException("Stream is null");
}
......@@ -99,6 +99,4 @@ public class XOutputStreamWrapper extends OutputStream {
throw new java.io.IOException(ioe.getMessage());
}
}
}
}
\ No newline at end of file
......@@ -50,8 +50,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
public class XStorageHelper implements XEventListener {
XStorage[] xStorages;
XStream xStream;
XInputStream xIs = null;
......@@ -61,8 +61,10 @@ public class XStorageHelper implements XEventListener {
private static XStorageHelper listener = new XStorageHelper();
private XStorageHelper() {}
public XStorageHelper(String path, int mode,
boolean create) throws IOException {
String modelUrl = null;
int indexOfScriptsDir = path.lastIndexOf("Scripts");
......@@ -82,10 +84,13 @@ public class XStorageHelper implements XEventListener {
}
XDocumentSubStorageSupplier xDocumentSubStorageSupplier =
UnoRuntime.queryInterface(
XDocumentSubStorageSupplier.class, xModel);
xStorages = new XStorage[tokens.countTokens() ];
LogUtils.DEBUG("XStorageHelper ctor, path chunks length: " + xStorages.length);
UnoRuntime.queryInterface(XDocumentSubStorageSupplier.class,
xModel);
xStorages = new XStorage[tokens.countTokens()];
LogUtils.DEBUG("XStorageHelper ctor, path chunks length: "
+ xStorages.length);
for (int i = 0; i < xStorages.length; i++) {
LogUtils.DEBUG("XStorageHelper, processing index " + i);
......@@ -94,16 +99,20 @@ public class XStorageHelper implements XEventListener {
XStorage storage = null;
if (i == 0) {
storage = xDocumentSubStorageSupplier.getDocumentSubStorage(name, mode);
storage = xDocumentSubStorageSupplier.getDocumentSubStorage(name, mode);
if (storage == null) {
LogUtils.DEBUG("** boo hoo Storage is null ");
}
XPropertySet xProps = UnoRuntime.queryInterface(XPropertySet.class, storage);
XPropertySet xProps =
UnoRuntime.queryInterface(XPropertySet.class, storage);
if (xProps != null) {
String mediaType = AnyConverter.toString(xProps.getPropertyValue("MediaType"));
String mediaType =
AnyConverter.toString(xProps.getPropertyValue("MediaType"));
LogUtils.DEBUG("***** media type is " + mediaType);
if (!mediaType.equals("scripts")) {
......@@ -111,8 +120,9 @@ public class XStorageHelper implements XEventListener {
}
}
} else {
XNameAccess xNameAccess = UnoRuntime.queryInterface(XNameAccess.class,
xStorages[i - 1]);
XNameAccess xNameAccess =
UnoRuntime.queryInterface(XNameAccess.class, xStorages[i - 1]);
if (xNameAccess == null) {
disposeObject();
......@@ -124,7 +134,8 @@ public class XStorageHelper implements XEventListener {
throw new IOException("No subdir: " + name);
} else {
// attempt to create new storage
LogUtils.DEBUG("Attempt to create new storage for " + name);
LogUtils.DEBUG("Attempt to create new storage for "
+ name);
}
}
......@@ -137,7 +148,7 @@ public class XStorageHelper implements XEventListener {
throw new IOException("storage not found: " + name);
}
xStorages[ i ] = storage;
xStorages[i] = storage;
}
} catch (com.sun.star.io.IOException ioe) {
......@@ -171,15 +182,19 @@ public class XStorageHelper implements XEventListener {
modelMap.remove(model);
}
}
public XStorage getStorage() {
return xStorages[ xStorages.length - 1 ];
}
public XModel getModel() {
return xModel;
}
public void disposeObject() {
disposeObject(false);
}
public void disposeObject(boolean shouldCommit) {
LogUtils.DEBUG("In disposeObject");
......@@ -202,12 +217,14 @@ public class XStorageHelper implements XEventListener {
}
}
static public void disposeObject(XInterface xInterface) {
if (xInterface == null) {
return;
}
XComponent xComponent = UnoRuntime.queryInterface(XComponent.class, xInterface);
XComponent xComponent =
UnoRuntime.queryInterface(XComponent.class, xInterface);
if (xComponent == null) {
return;
......@@ -215,9 +232,11 @@ public class XStorageHelper implements XEventListener {
xComponent.dispose();
}
static public void commit(XInterface xInterface) {
XTransactedObject xTrans = UnoRuntime.queryInterface(XTransactedObject.class,
xInterface);
XTransactedObject xTrans =
UnoRuntime.queryInterface(XTransactedObject.class, xInterface);
if (xTrans != null) {
try {
......@@ -232,6 +251,4 @@ public class XStorageHelper implements XEventListener {
//TODO does not cater for untitled documents
return modelMap.get(url);
}
}
}
\ No newline at end of file
......@@ -73,4 +73,4 @@ public class LogUtils {
return result;
}
}
}
\ No newline at end of file
......@@ -28,6 +28,7 @@ import java.net.URLClassLoader;
* Class Loader Factory
*/
public class ClassLoaderFactory {
private ClassLoaderFactory() {}
public static ClassLoader getURLClassLoader(ScriptMetaData scriptData) {
......@@ -41,9 +42,9 @@ public class ClassLoaderFactory {
return getURLClassLoader(parent, classPath);
}
private static ClassLoader getURLClassLoader(ClassLoader parent,
URL[] classpath) {
return new URLClassLoader(classpath, parent);
}
}
}
\ No newline at end of file
......@@ -28,8 +28,10 @@ import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
public class EditorScriptContext implements XScriptContext {
private XDesktop m_xDeskTop;
private XComponentContext m_xComponentContext;
public EditorScriptContext(XComponentContext xmComponentContext,
XDesktop xDesktop) {
this.m_xComponentContext = xmComponentContext;
......@@ -42,15 +44,18 @@ public class EditorScriptContext implements XScriptContext {
@return XModel interface
*/
public XModel getDocument() {
XModel xModel = UnoRuntime.queryInterface(XModel.class,
m_xDeskTop.getCurrentComponent());
XModel xModel =
UnoRuntime.queryInterface(XModel.class, m_xDeskTop.getCurrentComponent());
return xModel;
}
public XScriptInvocationContext getInvocationContext() {
XScriptInvocationContext xContext = UnoRuntime.queryInterface(
XScriptInvocationContext.class, getDocument());
XScriptInvocationContext xContext =
UnoRuntime.queryInterface(XScriptInvocationContext.class, getDocument());
return xContext;
}
......@@ -71,5 +76,4 @@ public class EditorScriptContext implements XScriptContext {
public XComponentContext getComponentContext() {
return m_xComponentContext;
}
}
}
\ No newline at end of file
......@@ -19,6 +19,7 @@
package com.sun.star.script.framework.provider;
public class NoSuitableClassLoaderException extends Exception {
/**
* Constructs an <code>NoSuitableClassLoaderException</code> with <code>null</code>
* as its error detail message.
......@@ -26,6 +27,7 @@ public class NoSuitableClassLoaderException extends Exception {
public NoSuitableClassLoaderException() {
super();
}
/**
* Constructs an <code>NoSuitBaleClassLoaderException</code> with the specified detail
* message. The error message string <code>s</code> can later be
......@@ -37,5 +39,4 @@ public class NoSuitableClassLoaderException extends Exception {
public NoSuitableClassLoaderException(String s) {
super(s);
}
}
}
\ No newline at end of file
......@@ -27,7 +27,6 @@ import java.util.StringTokenizer;
public class PathUtils {
public static String BOOTSTRAP_NAME;
private static boolean m_windows = false;
......@@ -38,13 +37,15 @@ public class PathUtils {
BOOTSTRAP_NAME = m_windows ? "bootstrap.ini" : "bootstraprc";
}
public static String getOidForModel(XModel xModel) {
String oid = "";
if (xModel != null) {
try {
Method getOid = IQueryInterface.class.getMethod("getOid",
(java.lang.Class[])null);
Method getOid =
IQueryInterface.class.getMethod("getOid", (java.lang.Class[])null);
if (getOid != null) {
oid = (String)getOid.invoke(xModel, new Object[0]);
......@@ -56,6 +57,7 @@ public class PathUtils {
return oid;
}
static public String make_url(String baseUrl, String url) {
StringBuilder buff = new StringBuilder(baseUrl.length() + url.length());
buff.append(baseUrl);
......@@ -78,4 +80,4 @@ public class PathUtils {
private PathUtils() {
}
}
}
\ No newline at end of file
......@@ -15,6 +15,7 @@
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
package com.sun.star.script.framework.provider;
import com.sun.star.beans.PropertyAttribute;
......@@ -36,13 +37,13 @@ import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
public class ScriptContext extends PropertySet implements XScriptContext {
private final static String HM_DOC_REF = "DocumentReference";
private final static String HM_DESKTOP = "Desktop";
private final static String HM_COMPONENT_CONTEXT = "ComponentContext";
private final static String DOC_URI = "SCRIPTING_DOC_URI";
private XModel m_xModel = null;
private XScriptInvocationContext m_xInvocationContext = null;
......@@ -50,24 +51,30 @@ public class ScriptContext extends PropertySet implements XScriptContext {
private XComponentContext m_xComponentContext = null;
private ScriptContext(XComponentContext xmComponentContext,
XDesktop xDesktop, XModel xModel, XScriptInvocationContext xInvocContext) {
private ScriptContext(XComponentContext xmComponentContext, XDesktop xDesktop,
XModel xModel, XScriptInvocationContext xInvocContext) {
this.m_xDeskTop = xDesktop;
this.m_xComponentContext = xmComponentContext;
this.m_xModel = xModel;
this.m_xInvocationContext = xInvocContext;
if (m_xModel != null) {
registerProperty(DOC_URI, new Type(String.class),
(short)(PropertyAttribute.MAYBEVOID | PropertyAttribute.TRANSIENT),
"m_sDocURI");
}
registerProperty(HM_DOC_REF, new Type(XModel.class),
(short)(PropertyAttribute.MAYBEVOID | PropertyAttribute.TRANSIENT), "m_xModel");
(short)(PropertyAttribute.MAYBEVOID | PropertyAttribute.TRANSIENT),
"m_xModel");
registerProperty(HM_DESKTOP, new Type(XDesktop.class),
(short)(PropertyAttribute.MAYBEVOID | PropertyAttribute.TRANSIENT),
"m_xDeskTop");
registerProperty(HM_COMPONENT_CONTEXT, new Type(XDesktop.class),
(short)(PropertyAttribute.MAYBEVOID | PropertyAttribute.TRANSIENT),
"m_xComponentContext");
......@@ -76,12 +83,14 @@ public class ScriptContext extends PropertySet implements XScriptContext {
public static XScriptContext createContext(XModel xModel,
XScriptInvocationContext xInvocContext,
XComponentContext xCtxt, XMultiComponentFactory xMCF) {
XScriptContext sc = null;
try {
Object xInterface = xMCF.createInstanceWithContext(
"com.sun.star.frame.Desktop", xCtxt);
Object xInterface =
xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xCtxt);
XDesktop xDesktop = UnoRuntime.queryInterface(XDesktop.class, xInterface);
if (xModel != null) {
......@@ -128,5 +137,4 @@ public class ScriptContext extends PropertySet implements XScriptContext {
public XComponentContext getComponentContext() {
return m_xComponentContext;
}
}
}
\ No newline at end of file
......@@ -27,4 +27,4 @@ public interface ScriptEditor {
void edit(XScriptContext context, ScriptMetaData entry);
String getTemplate();
String getExtension();
}
}
\ No newline at end of file
......@@ -25,6 +25,7 @@ import javax.swing.SwingUtilities;
// (also, the current thread must not wait for that fresh thread to terminate,
// as that would cause a deadlock if this thread is the AppKit thread):
public final class SwingInvocation {
public static void invoke(final Runnable doRun) {
new Thread("SwingInvocation") {
@Override
......@@ -35,4 +36,4 @@ public final class SwingInvocation {
}
private SwingInvocation() {}
}
}
\ No newline at end of file
......@@ -31,8 +31,8 @@ import javax.swing.JTextArea;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
public class PlainSourceView extends JScrollPane
implements ScriptSourceView, DocumentListener {
public class PlainSourceView extends JScrollPane implements
ScriptSourceView, DocumentListener {
private ScriptSourceModel model;
private JTextArea ta;
......@@ -238,4 +238,4 @@ class GlyphGutter extends JComponent {
g.setColor(Color.black);
g.drawPolygon(arrow);
}
}
}
\ No newline at end of file
......@@ -44,8 +44,8 @@ import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class ScriptEditorForBeanShell
implements ScriptEditor, ActionListener {
public class ScriptEditorForBeanShell implements ScriptEditor, ActionListener {
private JFrame frame;
private String filename;
......@@ -60,8 +60,8 @@ public class ScriptEditorForBeanShell
private static ScriptEditorForBeanShell theScriptEditorForBeanShell;
// global list of ScriptEditors, key is URL of file being edited
private static Map<URL, ScriptEditorForBeanShell> BEING_EDITED = new
HashMap<URL, ScriptEditorForBeanShell>();
private static Map<URL, ScriptEditorForBeanShell> BEING_EDITED =
new HashMap<URL, ScriptEditorForBeanShell>();
// template for new BeanShell scripts
private static String BSHTEMPLATE;
......@@ -69,9 +69,7 @@ public class ScriptEditorForBeanShell
// try to load the template for BeanShell scripts
static {
try {
URL url =
ScriptEditorForBeanShell.class.getResource("template.bsh");
URL url = ScriptEditorForBeanShell.class.getResource("template.bsh");
InputStream in = url.openStream();
StringBuilder buf = new StringBuilder();
byte[] b = new byte[1024];
......@@ -153,7 +151,6 @@ public class ScriptEditorForBeanShell
return "bsh";
}
/**
* Indicates the line where error occurred
*
......@@ -161,6 +158,7 @@ public class ScriptEditorForBeanShell
public void indicateErrorLine(int lineNum) {
model.indicateErrorLine(lineNum);
}
/**
* Executes the script edited by the editor
*
......@@ -169,6 +167,7 @@ public class ScriptEditorForBeanShell
frame.toFront();
return model.execute(context, cl);
}
/**
* Opens an editor window for the specified ScriptMetaData.
* If an editor window is already open for that data it will be
......@@ -232,8 +231,9 @@ public class ScriptEditorForBeanShell
this.cl = cl;
try {
Class<?> c = Class.forName(
"org.openoffice.netbeans.editor.NetBeansSourceView");
Class<?> c =
Class.forName("org.openoffice.netbeans.editor.NetBeansSourceView");
Class<?>[] types = new Class[] { ScriptSourceModel.class };
......@@ -297,9 +297,9 @@ public class ScriptEditorForBeanShell
private void doClose() {
if (view.isModified()) {
int result = JOptionPane.showConfirmDialog(frame,
"The script has been modified. " +
"Do you want to save the changes?");
"The script has been modified. Do you want to save the changes?");
if (result == JOptionPane.CANCEL_OPTION) {
// don't close the window, just return
......@@ -379,4 +379,4 @@ public class ScriptEditorForBeanShell
view.clear();
}
}
}
}
\ No newline at end of file
......@@ -116,9 +116,10 @@ public class ScriptSourceModel {
return result;
}
public void indicateErrorLine(int lineNum) {
System.out.println("Beanshell indicateErrorLine " + lineNum);
currentPosition = lineNum - 1;
view.update();
}
}
}
\ No newline at end of file
......@@ -23,4 +23,4 @@ public interface ScriptSourceView {
boolean isModified();
void setModified(boolean value);
String getText();
}
}
\ No newline at end of file
......@@ -15,7 +15,6 @@
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
package com.sun.star.script.framework.provider.java;
/**
......@@ -23,8 +22,8 @@ package com.sun.star.script.framework.provider.java;
* want to implement an algorithm for obtaining a ScriptProxy object
* for a particular ScriptDescriptor and Class
*/
public interface Resolver {
/**
* Returns a ScriptProxy object for the given ScriptDescriptor and Class
*
......@@ -32,7 +31,6 @@ public interface Resolver {
* @param c A Class
* @return The ScriptProxy value
*/
ScriptProxy getProxy(ScriptDescriptor sd, Class<?> c)
throws NoSuchMethodException;
}
ScriptProxy getProxy(ScriptDescriptor sd, Class<?> c) throws
NoSuchMethodException;
}
\ No newline at end of file
......@@ -15,7 +15,6 @@
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
package com.sun.star.script.framework.provider.java;
import java.util.ArrayList;
......@@ -27,6 +26,7 @@ import java.util.StringTokenizer;
* criteria that should be used for finding a particular script
*/
public class ScriptDescriptor {
private String m_name;
private String m_methodName;
private String m_className;
......@@ -39,8 +39,7 @@ public class ScriptDescriptor {
* @param name Script Name
* @exception IllegalArgumentException if the given name does not contain a "."
*/
public ScriptDescriptor(String name)
throws IllegalArgumentException {
public ScriptDescriptor(String name) throws IllegalArgumentException {
int idx = name.lastIndexOf('.');
if (idx == -1) {
......@@ -70,7 +69,6 @@ public class ScriptDescriptor {
return m_className;
}
/**
* Gets the method name of this <code>ScriptDescriptor</code>
*
......@@ -80,7 +78,6 @@ public class ScriptDescriptor {
return m_methodName;
}
/**
* Sets the classpath value stored by this <code>ScriptDescriptor</code>
*
......@@ -103,7 +100,6 @@ public class ScriptDescriptor {
this.m_classpath = classpath;
}
/**
* Gets the classpath value stored by this <code>ScriptDescriptor</code>
*
......@@ -113,7 +109,6 @@ public class ScriptDescriptor {
return m_classpath;
}
/**
* Adds the given <code>Class</code> to the list of argument types stored in
* this ScriptDescriptor
......@@ -125,10 +120,6 @@ public class ScriptDescriptor {
m_argumentTypes.add(clazz);
}
/**
* Gets a list of the types of the arguments stored in this
* <code>ScriptDescriptor</code>
......@@ -138,15 +129,13 @@ public class ScriptDescriptor {
* @return The argumentTypes value
*/
public synchronized Class<?>[]
getArgumentTypes() {
public synchronized Class<?>[] getArgumentTypes() {
if (m_argumentTypes.size() > 0)
return m_argumentTypes.toArray(new Class[ m_argumentTypes.size() ]);
else
return null;
}
/**
* Returns a <code>String</code> representation of this
* <code>ScriptDescriptor</code>
......@@ -173,5 +162,4 @@ public class ScriptDescriptor {
return description.toString();
}
}
}
\ No newline at end of file
......@@ -15,7 +15,6 @@
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
package com.sun.star.script.framework.provider.java;
import java.lang.reflect.InvocationTargetException;
......@@ -27,10 +26,10 @@ import java.lang.reflect.Method;
* @see java.lang.reflect.Method
*/
public class ScriptProxy {
private Object m_targetObject;
private Method m_method;
/**
* Constructs a <code>ScriptProxy</code> object for the given
* <code>Method</code>
......@@ -41,7 +40,6 @@ public class ScriptProxy {
this.m_method = method;
}
/**
* Sets the <code>Object</code> on which the ScriptProxy should invoke
* the method
......@@ -52,7 +50,6 @@ public class ScriptProxy {
m_targetObject = obj;
}
/**
* Invokes the method contained in this <code>ScriptProxy</code>,
* any exceptions resulting from the invocation will be thrown
......@@ -64,10 +61,9 @@ public class ScriptProxy {
* @see java.lang.reflect.Method for the exceptions
* that may be thrown
*/
public Object invoke(Object[] args)
throws IllegalAccessException, InvocationTargetException,
IllegalArgumentException {
public Object invoke(Object[] args) throws
IllegalAccessException, InvocationTargetException, IllegalArgumentException {
return m_method.invoke(m_targetObject, args);
}
}
}
\ No newline at end of file
......@@ -31,6 +31,7 @@ import java.lang.reflect.Modifier;
* can be found in the Class.
*/
public class StrictResolver implements Resolver {
/**
*Constructor for the StrictResolver object
*/
......@@ -47,8 +48,9 @@ public class StrictResolver implements Resolver {
* @param c the Class file in which to search for the method
* @return the ScriptProxy matching the criteria, or null if no match is found
*/
public ScriptProxy getProxy(ScriptDescriptor sd, Class<?> c)
throws NoSuchMethodException {
public ScriptProxy getProxy(ScriptDescriptor sd, Class<?> c) throws
NoSuchMethodException {
Method m = null;
LogUtils.DEBUG("StrictResolver.getProxy() for: " + sd.toString());
......@@ -56,11 +58,13 @@ public class StrictResolver implements Resolver {
try {
m = resolveArguments(sd, c);
} catch (ClassNotFoundException e) {
throw new NoSuchMethodException("StrictResolver.getProxy: Can't find method: "
+ sd.getMethodName() + ":" + e.getMessage());
throw new NoSuchMethodException(
"StrictResolver.getProxy: Can't find method: " + sd.getMethodName()
+ ":" + e.getMessage());
} catch (NoSuchMethodException e) {
throw new NoSuchMethodException("StrictResolver.getProxy: Can't find method: "
+ sd.getMethodName() + ":" + e.getMessage());
throw new NoSuchMethodException(
"StrictResolver.getProxy: Can't find method: " + sd.getMethodName()
+ ":" + e.getMessage());
}
ScriptProxy sp = new ScriptProxy(m);
......@@ -73,11 +77,11 @@ public class StrictResolver implements Resolver {
try {
o = c.newInstance();
} catch (InstantiationException ie) {
throw new NoSuchMethodException("getScriptProxy: Can't instantiate: " +
c.getName());
throw new NoSuchMethodException(
"getScriptProxy: Can't instantiate: " + c.getName());
} catch (IllegalAccessException iae) {
throw new NoSuchMethodException("getScriptProxy: Can't access: "
+ c.getName());
throw new NoSuchMethodException(
"getScriptProxy: Can't access: " + c.getName());
}
sp.setTargetObject(o);
......@@ -86,7 +90,6 @@ public class StrictResolver implements Resolver {
return sp;
}
/**
* Description of the Method
*
......@@ -96,9 +99,9 @@ public class StrictResolver implements Resolver {
* @exception ClassNotFoundException
* @exception NoSuchMethodException
*/
private Method resolveArguments(ScriptDescriptor sd, Class<?> c)
throws ClassNotFoundException, NoSuchMethodException {
private Method resolveArguments(ScriptDescriptor sd, Class<?> c) throws
ClassNotFoundException, NoSuchMethodException {
return c.getMethod(sd.getMethodName(), sd.getArgumentTypes());
}
}
}
\ No newline at end of file
......@@ -41,6 +41,7 @@ import org.mozilla.javascript.tools.debugger.Main;
import org.mozilla.javascript.tools.debugger.ScopeProvider;
public class ScriptEditorForJavaScript implements ScriptEditor {
// global ScriptEditorForJavaScript instance
private static ScriptEditorForJavaScript theScriptEditorForJavaScript;
......@@ -55,9 +56,7 @@ public class ScriptEditorForJavaScript implements ScriptEditor {
static {
try {
URL url =
ScriptEditorForJavaScript.class.getResource("template.js");
URL url = ScriptEditorForJavaScript.class.getResource("template.js");
InputStream in = url.openStream();
StringBuilder buf = new StringBuilder();
byte[] b = new byte[1024];
......@@ -83,8 +82,7 @@ public class ScriptEditorForJavaScript implements ScriptEditor {
public static synchronized ScriptEditorForJavaScript getEditor() {
if (theScriptEditorForJavaScript == null) {
theScriptEditorForJavaScript =
new ScriptEditorForJavaScript();
theScriptEditorForJavaScript = new ScriptEditorForJavaScript();
}
return theScriptEditorForJavaScript;
......@@ -170,12 +168,10 @@ public class ScriptEditorForJavaScript implements ScriptEditor {
new Runnable() {
public void run() {
synchronized (BEING_EDITED) {
ScriptEditorForJavaScript editor =
BEING_EDITED.get(url);
ScriptEditorForJavaScript editor = BEING_EDITED.get(url);
if (editor == null) {
editor = new ScriptEditorForJavaScript(
context, url);
editor = new ScriptEditorForJavaScript(context, url);
BEING_EDITED.put(url, editor);
}
}
......@@ -200,8 +196,6 @@ public class ScriptEditorForJavaScript implements ScriptEditor {
initUI();
Scriptable scope = getScope(context);
this.rhinoWindow.openFile(url, scope, new closeHandler(url));
this.scriptURL = url;
}
......@@ -293,8 +287,7 @@ public class ScriptEditorForJavaScript implements ScriptEditor {
Scriptable jsCtxt = Context.toObject(xsctxt, scope);
scope.put("XSCRIPTCONTEXT", scope, jsCtxt);
Scriptable jsArgs = Context.toObject(
new Object[0], scope);
Scriptable jsArgs = Context.toObject(new Object[0], scope);
scope.put("ARGUMENTS", scope, jsArgs);
Context.exit();
......@@ -302,14 +295,17 @@ public class ScriptEditorForJavaScript implements ScriptEditor {
}
private class closeHandler implements Runnable {
private URL url;
private closeHandler(URL url) {
this.url = url;
}
public void run() {
synchronized (BEING_EDITED) {
BEING_EDITED.remove(this.url);
}
}
}
}
}
\ No newline at end of file
......@@ -52,15 +52,16 @@ import org.mozilla.javascript.JavaScriptException;
import org.mozilla.javascript.Scriptable;
public class ScriptProviderForJavaScript {
public static class ScriptProviderForJavaScript_2 extends ScriptProvider {
public ScriptProviderForJavaScript_2(XComponentContext ctx) {
super(ctx, "JavaScript");
}
@Override
public XScript getScript(/*IN*/String scriptURI)
throws com.sun.star.uno.RuntimeException,
ScriptFrameworkErrorException {
throws com.sun.star.uno.RuntimeException, ScriptFrameworkErrorException {
ScriptMetaData scriptData = null;
try {
......@@ -69,9 +70,9 @@ public class ScriptProviderForJavaScript {
m_xInvocContext);
return script;
} catch (com.sun.star.uno.RuntimeException re) {
throw new ScriptFrameworkErrorException("Failed to create script object: " +
re.getMessage(),
null, scriptData.getLanguageName(), language, ScriptFrameworkErrorType.UNKNOWN);
throw new ScriptFrameworkErrorException(
"Failed to create script object: " + re.getMessage(),
null, scriptData.getLanguageName(), language, ScriptFrameworkErrorType.UNKNOWN);
}
}
......@@ -99,23 +100,27 @@ public class ScriptProviderForJavaScript {
* @see com.sun.star.comp.loader.JavaLoader
*/
public static XSingleServiceFactory __getServiceFactory(String implName,
XMultiServiceFactory multiFactory,
XRegistryKey regKey) {
XMultiServiceFactory multiFactory, XRegistryKey regKey) {
XSingleServiceFactory xSingleServiceFactory = null;
if (implName.equals(
ScriptProviderForJavaScript.ScriptProviderForJavaScript_2.class.getName())) {
xSingleServiceFactory = FactoryHelper.getServiceFactory(
ScriptProviderForJavaScript.ScriptProviderForJavaScript_2.class,
"com.sun.star.script.provider.ScriptProviderForJavaScript",
multiFactory,
regKey);
xSingleServiceFactory =
FactoryHelper.getServiceFactory(
ScriptProviderForJavaScript.ScriptProviderForJavaScript_2.class,
"com.sun.star.script.provider.ScriptProviderForJavaScript",
multiFactory, regKey);
}
return xSingleServiceFactory;
}
}
class ScriptImpl implements XScript {
private ScriptMetaData metaData;
private XComponentContext m_xContext;
private XMultiComponentFactory m_xMultiComponentFactory;
......@@ -125,6 +130,7 @@ class ScriptImpl implements XScript {
ScriptImpl(XComponentContext ctx, ScriptMetaData metaData, XModel xModel,
XScriptInvocationContext xInvocContext) throws
com.sun.star.uno.RuntimeException {
this.metaData = metaData;
this.m_xContext = ctx;
this.m_xModel = xModel;
......@@ -167,19 +173,16 @@ class ScriptImpl implements XScript {
* ScriptErrorRaisedException or
* ScriptExceptionRaisedException
*/
public Object invoke(
/*IN*/Object[] params,
/*OUT*/short[][] aOutParamIndex,
/*OUT*/Object[][] aOutParam)
throws ScriptFrameworkErrorException, InvocationTargetException {
// Initialise the out parameters - not used at the moment
aOutParamIndex[0] = new short[0];
aOutParam[0] = new Object[0];
ClassLoader cl = null;
URL sourceUrl = null;
......@@ -198,9 +201,9 @@ class ScriptImpl implements XScript {
try {
String editorURL = sourceUrl.toString();
Object result = null;
ScriptEditorForJavaScript editor =
ScriptEditorForJavaScript.getEditor(
metaData.getSourceURL());
ScriptEditorForJavaScript.getEditor(metaData.getSourceURL());
if (editor != null) {
editorURL = editor.getURL();
......@@ -252,22 +255,24 @@ class ScriptImpl implements XScript {
*/
ImporterTopLevel scope = new ImporterTopLevel(ctxt);
Scriptable jsCtxt = Context.toObject(
ScriptContext.createContext(
m_xModel, m_xInvocContext, m_xContext,
m_xMultiComponentFactory), scope);
Scriptable jsCtxt =
Context.toObject(
ScriptContext.createContext(
m_xModel, m_xInvocContext, m_xContext,
m_xMultiComponentFactory),
scope);
scope.put("XSCRIPTCONTEXT", scope, jsCtxt);
Scriptable jsArgs = Context.toObject(params, scope);
scope.put("ARGUMENTS", scope, jsArgs);
result = ctxt.evaluateString(scope,
source, "<stdin>", 1, null);
result = ctxt.evaluateString(scope, source, "<stdin>", 1, null);
result = Context.toString(result);
return result;
} catch (JavaScriptException jse) {
LogUtils.DEBUG("Caught JavaScriptException exception for JavaScript type = " +
jse.getClass());
LogUtils.DEBUG("Caught JavaScriptException exception for JavaScript type = "
+ jse.getClass());
String message = jse.getMessage();
Object wrap = jse.getValue();
LogUtils.DEBUG("\t message " + message);
......@@ -286,15 +291,14 @@ class ScriptImpl implements XScript {
LogUtils.DEBUG("\t language " + se.language);
LogUtils.DEBUG("\t scriptName " + se.scriptName);
raiseEditor(se.lineNum);
throw new InvocationTargetException("JavaScript uncaught exception" +
metaData.getLanguageName(), null, se);
throw new InvocationTargetException(
"JavaScript uncaught exception" + metaData.getLanguageName(), null, se);
} catch (Exception ex) {
LogUtils.DEBUG("Caught Exception " + ex);
LogUtils.DEBUG("rethrowing as ScriptFramework error");
throw new ScriptFrameworkErrorException(
ex.getMessage(), null,
metaData.getLanguageName(), metaData.getLanguage(),
ScriptFrameworkErrorType.UNKNOWN);
ex.getMessage(), null, metaData.getLanguageName(),
metaData.getLanguage(), ScriptFrameworkErrorType.UNKNOWN);
} finally {
if (ctxt != null) {
Context.exit();
......@@ -305,14 +309,18 @@ class ScriptImpl implements XScript {
private void raiseEditor(int lineNum) {
try {
URL sourceUrl = metaData.getSourceURL();
ScriptEditorForJavaScript editor = ScriptEditorForJavaScript.getEditor(
sourceUrl);
ScriptEditorForJavaScript editor =
ScriptEditorForJavaScript.getEditor(sourceUrl);
if (editor == null) {
editor = ScriptEditorForJavaScript.getEditor();
editor.edit(
ScriptContext.createContext(m_xModel, m_xInvocContext,
m_xContext, m_xMultiComponentFactory), metaData);
m_xContext, m_xMultiComponentFactory),
metaData);
editor = ScriptEditorForJavaScript.getEditor(sourceUrl);
}
......@@ -324,5 +332,4 @@ class ScriptImpl implements XScript {
} catch (Exception ignore) {
}
}
}
}
\ No newline at end of file
......@@ -216,10 +216,10 @@ public class DeployParcelAction extends CookieAction implements
chooser.setFileFilter(new FileFilter() {
public boolean accept(File file) {
return file.isDirectory() ||
file.getName().endsWith(".sxw") ||
file.getName().endsWith(".sxc") ||
file.getName().endsWith(".sxd") ||
file.getName().endsWith(".sxi");
file.getName().endsWith(".sxw") ||
file.getName().endsWith(".sxc") ||
file.getName().endsWith(".sxd") ||
file.getName().endsWith(".sxi");
}
public String getDescription() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment