[Libreoffice-commits] core.git: scripting/examples scripting/java scripting/workben
Robert Antoni Buj i Gelonch
robert.buj at gmail.com
Thu Oct 2 06:26:20 PDT 2014
scripting/examples/java/HelloWorld/HelloWorld.java | 16
scripting/examples/java/Highlight/HighlightText.java | 89 -
scripting/examples/java/MemoryUsage/MemoryUsage.java | 55
scripting/examples/java/Newsgroup/MimeConfiguration.java | 170 +-
scripting/examples/java/Newsgroup/NewsGroup.java | 12
scripting/examples/java/Newsgroup/OfficeAttachment.java | 228 +--
scripting/examples/java/Newsgroup/PostNewsgroup.java | 560 ++++-----
scripting/examples/java/Newsgroup/Sender.java | 96 -
scripting/examples/java/Newsgroup/StatusWindow.java | 128 --
scripting/examples/java/Newsgroup/SubscribedNewsgroups.java | 267 +---
scripting/examples/java/debugger/DebugRunner.java | 24
scripting/examples/java/debugger/OOBeanShellDebugger.java | 71 -
scripting/examples/java/debugger/OORhinoDebugger.java | 40
scripting/examples/java/selector/ScriptSelector.java | 242 +--
scripting/java/Framework/com/sun/star/script/framework/security/SecurityDialog.java | 460 +++----
scripting/java/com/sun/star/script/framework/browse/DialogFactory.java | 135 --
scripting/java/com/sun/star/script/framework/browse/ParcelBrowseNode.java | 215 +--
scripting/java/com/sun/star/script/framework/browse/PkgProviderBrowseNode.java | 19
scripting/java/com/sun/star/script/framework/browse/ProviderBrowseNode.java | 154 +-
scripting/java/com/sun/star/script/framework/browse/ScriptBrowseNode.java | 187 +--
scripting/java/com/sun/star/script/framework/container/DeployedUnoPackagesDB.java | 99 -
scripting/java/com/sun/star/script/framework/container/Parcel.java | 265 ++--
scripting/java/com/sun/star/script/framework/container/ParcelContainer.java | 616 ++++------
scripting/java/com/sun/star/script/framework/container/ParcelDescriptor.java | 87 -
scripting/java/com/sun/star/script/framework/container/ParsedScriptUri.java | 3
scripting/java/com/sun/star/script/framework/container/ScriptEntry.java | 29
scripting/java/com/sun/star/script/framework/container/ScriptMetaData.java | 317 ++---
scripting/java/com/sun/star/script/framework/container/UnoPkgContainer.java | 418 +++---
scripting/java/com/sun/star/script/framework/container/XMLParserFactory.java | 40
scripting/java/com/sun/star/script/framework/io/UCBStreamHandler.java | 143 +-
scripting/java/com/sun/star/script/framework/io/XInputStreamImpl.java | 78 -
scripting/java/com/sun/star/script/framework/io/XInputStreamWrapper.java | 38
scripting/java/com/sun/star/script/framework/io/XOutputStreamWrapper.java | 156 +-
scripting/java/com/sun/star/script/framework/io/XStorageHelper.java | 207 +--
scripting/java/com/sun/star/script/framework/log/LogUtils.java | 44
scripting/java/com/sun/star/script/framework/provider/ClassLoaderFactory.java | 23
scripting/java/com/sun/star/script/framework/provider/EditorScriptContext.java | 28
scripting/java/com/sun/star/script/framework/provider/NoSuitableClassLoaderException.java | 9
scripting/java/com/sun/star/script/framework/provider/PathUtils.java | 59
scripting/java/com/sun/star/script/framework/provider/ScriptContext.java | 68 -
scripting/java/com/sun/star/script/framework/provider/ScriptEditor.java | 5
scripting/java/com/sun/star/script/framework/provider/ScriptProvider.java | 549 ++++----
scripting/java/com/sun/star/script/framework/provider/SwingInvocation.java | 6
scripting/java/com/sun/star/script/framework/provider/beanshell/PlainSourceView.java | 15
scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java | 179 +-
scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptProviderForBeanShell.java | 442 +++----
scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptSourceModel.java | 96 -
scripting/java/com/sun/star/script/framework/provider/java/Resolver.java | 2
scripting/java/com/sun/star/script/framework/provider/java/ScriptDescriptor.java | 85 -
scripting/java/com/sun/star/script/framework/provider/java/ScriptProviderForJava.java | 417 +++---
scripting/java/com/sun/star/script/framework/provider/java/ScriptProxy.java | 16
scripting/java/com/sun/star/script/framework/provider/java/StrictResolver.java | 72 -
scripting/java/com/sun/star/script/framework/provider/javascript/ScriptEditorForJavaScript.java | 154 +-
scripting/java/com/sun/star/script/framework/provider/javascript/ScriptProviderForJavaScript.java | 417 +++---
scripting/java/org/openoffice/idesupport/CommandLineTools.java | 92 -
scripting/java/org/openoffice/idesupport/ExtensionFinder.java | 7
scripting/java/org/openoffice/idesupport/JavaFinder.java | 71 -
scripting/java/org/openoffice/idesupport/LocalOffice.java | 12
scripting/java/org/openoffice/idesupport/OfficeDocument.java | 38
scripting/java/org/openoffice/idesupport/OfficeInstallation.java | 3
scripting/java/org/openoffice/idesupport/SVersionRCFile.java | 63 -
scripting/java/org/openoffice/idesupport/filter/BinaryOnlyFilter.java | 1
scripting/java/org/openoffice/idesupport/filter/ExceptParcelFilter.java | 4
scripting/java/org/openoffice/idesupport/localoffice/LocalOfficeImpl.java | 52
scripting/java/org/openoffice/idesupport/ui/ConfigurePanel.java | 43
scripting/java/org/openoffice/idesupport/ui/ScriptPanel.java | 10
scripting/java/org/openoffice/idesupport/xml/Manifest.java | 17
scripting/java/org/openoffice/idesupport/zip/ParcelZipper.java | 41
scripting/java/org/openoffice/netbeans/editor/JavaKit.java | 21
scripting/java/org/openoffice/netbeans/editor/NetBeansSourceView.java | 31
scripting/java/org/openoffice/netbeans/modules/office/actions/BuildParcelAction.java | 2
scripting/java/org/openoffice/netbeans/modules/office/actions/ConfigureParcelAction.java | 6
scripting/java/org/openoffice/netbeans/modules/office/actions/DeployParcelAction.java | 33
scripting/java/org/openoffice/netbeans/modules/office/actions/MountDocumentAction.java | 34
scripting/java/org/openoffice/netbeans/modules/office/actions/MountParcelAction.java | 34
scripting/java/org/openoffice/netbeans/modules/office/actions/OfficeDocumentCookie.java | 3
scripting/java/org/openoffice/netbeans/modules/office/actions/OfficeDocumentSupport.java | 25
scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelCookie.java | 3
scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelDescriptorEditorSupport.java | 14
scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelDescriptorParserCookie.java | 3
scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelDescriptorParserSupport.java | 23
scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelFolderCookie.java | 3
scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelFolderSupport.java | 76 -
scripting/java/org/openoffice/netbeans/modules/office/actions/ParcelSupport.java | 56
scripting/java/org/openoffice/netbeans/modules/office/filesystem/OpenOfficeDocFileSystem.java | 546 ++++----
scripting/java/org/openoffice/netbeans/modules/office/filesystem/OpenOfficeDocFileSystemBeanInfo.java | 44
scripting/java/org/openoffice/netbeans/modules/office/loader/OfficeDocumentDataLoader.java | 33
scripting/java/org/openoffice/netbeans/modules/office/loader/OfficeDocumentDataNode.java | 15
scripting/java/org/openoffice/netbeans/modules/office/loader/OfficeDocumentDataObject.java | 3
scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelContentsFolder.java | 36
scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelContentsFolderDataLoader.java | 15
scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDataLoader.java | 23
scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDataNode.java | 10
scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDataObject.java | 3
scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDescriptorDataLoader.java | 25
scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelDescriptorDataObject.java | 5
scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelFolder.java | 208 +--
scripting/java/org/openoffice/netbeans/modules/office/loader/ParcelFolderDataLoader.java | 35
scripting/java/org/openoffice/netbeans/modules/office/nodes/OfficeDocumentChildren.java | 14
scripting/java/org/openoffice/netbeans/modules/office/nodes/ParcelDescriptorChildren.java | 5
scripting/java/org/openoffice/netbeans/modules/office/nodes/ScriptNode.java | 15
scripting/java/org/openoffice/netbeans/modules/office/options/OfficeSettings.java | 3
scripting/java/org/openoffice/netbeans/modules/office/options/OfficeSettingsBeanInfo.java | 57
scripting/java/org/openoffice/netbeans/modules/office/utils/FrameworkJarChecker.java | 48
scripting/java/org/openoffice/netbeans/modules/office/utils/ManifestParser.java | 10
scripting/java/org/openoffice/netbeans/modules/office/utils/NagDialog.java | 22
scripting/java/org/openoffice/netbeans/modules/office/utils/OfficeModule.java | 11
scripting/java/org/openoffice/netbeans/modules/office/utils/PackageRemover.java | 17
scripting/java/org/openoffice/netbeans/modules/office/utils/ZipMounter.java | 24
scripting/java/org/openoffice/netbeans/modules/office/wizard/InstallationPathDescriptor.java | 3
scripting/java/org/openoffice/netbeans/modules/office/wizard/InstallationPathIterator.java | 14
scripting/java/org/openoffice/netbeans/modules/office/wizard/JavaScriptIterator.java | 37
scripting/java/org/openoffice/netbeans/modules/office/wizard/ParcelContentsIterator.java | 25
scripting/java/org/openoffice/netbeans/modules/office/wizard/ParcelPropertiesPanel.java | 1
scripting/java/org/openoffice/netbeans/modules/office/wizard/ParcelPropertiesVisualPanel.java | 17
scripting/java/org/openoffice/netbeans/modules/office/wizard/SelectPathPanel.java | 10
scripting/java/org/openoffice/netbeans/modules/office/wizard/SelectPathVisualPanel.java | 21
scripting/workben/ifc/scripting/ScriptingUtils.java | 17
scripting/workben/ifc/scripting/SecurityDialogUtil.java | 188 +--
scripting/workben/ifc/scripting/_XFunction.java | 29
scripting/workben/ifc/scripting/_XFunctionProvider.java | 3
scripting/workben/ifc/scripting/_XScriptInfo.java | 32
scripting/workben/ifc/scripting/_XScriptInfoAccess.java | 51
scripting/workben/ifc/scripting/_XScriptInvocation.java | 48
scripting/workben/ifc/scripting/_XScriptNameResolver.java | 32
scripting/workben/ifc/scripting/_XScriptSecurity.java | 285 ++--
scripting/workben/ifc/scripting/_XScriptStorageManager.java | 33
scripting/workben/ifc/scripting/_XScriptStorageRefresh.java | 5
scripting/workben/installer/Banner.java | 15
scripting/workben/installer/ExceptionTraceHelper.java | 35
scripting/workben/installer/ExecCmd.java | 149 +-
scripting/workben/installer/FileUpdater.java | 219 +--
scripting/workben/installer/Final.java | 82 -
scripting/workben/installer/IdeFinal.java | 64 -
scripting/workben/installer/IdeUpdater.java | 77 -
scripting/workben/installer/IdeVersion.java | 147 +-
scripting/workben/installer/IdeWelcome.java | 16
scripting/workben/installer/InstUtil.java | 248 ++--
scripting/workben/installer/InstallListener.java | 3
scripting/workben/installer/InstallWizard.java | 235 +--
scripting/workben/installer/InstallationEvent.java | 12
scripting/workben/installer/LogStream.java | 44
scripting/workben/installer/NavPanel.java | 29
scripting/workben/installer/Register.java | 83 -
scripting/workben/installer/Version.java | 122 +
scripting/workben/installer/Welcome.java | 25
scripting/workben/installer/XmlUpdater.java | 238 +--
scripting/workben/installer/ZipData.java | 19
scripting/workben/mod/_scripting/Dispatch.java | 35
scripting/workben/mod/_scripting/Function.java | 27
scripting/workben/mod/_scripting/FunctionProvider.java | 21
scripting/workben/mod/_scripting/ScriptInfo.java | 56
scripting/workben/mod/_scripting/ScriptRuntimeManager.java | 12
scripting/workben/mod/_scripting/ScriptStorage.java | 50
scripting/workben/mod/_scripting/ScriptStorageManager.java | 26
scripting/workben/mod/_scripting/TestDataLoader.java | 11
156 files changed, 6399 insertions(+), 6950 deletions(-)
New commits:
commit 6f42a714399f4d0c46dad95c7c11bcd513c27eaa
Author: Robert Antoni Buj i Gelonch <robert.buj at gmail.com>
Date: Thu Sep 25 19:41:12 2014 +0200
scripting: Format_java_code.sh initial run
Conflicts:
scripting/java/com/sun/star/script/framework/io/UCBStreamHandler.java
Change-Id: I09b94d8c96dfbaf498bd93a0088feb80a9e4afb6
diff --git a/scripting/examples/java/HelloWorld/HelloWorld.java b/scripting/examples/java/HelloWorld/HelloWorld.java
index 3f117a2..1c960da 100644
--- a/scripting/examples/java/HelloWorld/HelloWorld.java
+++ b/scripting/examples/java/HelloWorld/HelloWorld.java
@@ -28,15 +28,15 @@ import com.sun.star.text.XText;
*
*/
public class HelloWorld {
- public static void printHW(XScriptContext xSc) {
+ public static void printHW(XScriptContext xSc) {
- // getting the text document object
- XTextDocument xtextdocument = (XTextDocument) UnoRuntime.queryInterface(
-XTextDocument.class, xSc.getDocument());
- XText xText = xtextdocument.getText();
- XTextRange xTextRange = xText.getEnd();
- xTextRange.setString( "Hello World (in Java)" );
+ // getting the text document object
+ XTextDocument xtextdocument = (XTextDocument) UnoRuntime.queryInterface(
+ XTextDocument.class, xSc.getDocument());
+ XText xText = xtextdocument.getText();
+ XTextRange xTextRange = xText.getEnd();
+ xTextRange.setString("Hello World (in Java)");
- }// printHW
+ }// printHW
}
diff --git a/scripting/examples/java/Highlight/HighlightText.java b/scripting/examples/java/Highlight/HighlightText.java
index 46c6f73..f39ccbf 100644
--- a/scripting/examples/java/Highlight/HighlightText.java
+++ b/scripting/examples/java/Highlight/HighlightText.java
@@ -54,65 +54,63 @@ public class HighlightText implements com.sun.star.awt.XActionListener {
args[0] = context.getDocument();
Object obj;
+
try {
obj = xmcf.createInstanceWithArgumentsAndContext(
- "com.sun.star.awt.DialogProvider", args,
- context.getComponentContext());
- }
- catch (com.sun.star.uno.Exception e) {
+ "com.sun.star.awt.DialogProvider", args,
+ context.getComponentContext());
+ } catch (com.sun.star.uno.Exception e) {
System.err.println("Error getting DialogProvider object");
return;
}
XDialogProvider xDialogProvider = (XDialogProvider)
- UnoRuntime.queryInterface(XDialogProvider.class, obj);
+ UnoRuntime.queryInterface(XDialogProvider.class, obj);
System.err.println("Got DialogProvider, now get dialog");
try {
findDialog = xDialogProvider.createDialog(
- "vnd.sun.star.script:" +
- "ScriptBindingLibrary.Highlight?location=application");
- }
- catch (java.lang.Exception e) {
+ "vnd.sun.star.script:" +
+ "ScriptBindingLibrary.Highlight?location=application");
+ } catch (java.lang.Exception e) {
System.err.println("Got exception on first creating dialog: " +
- e.getMessage());
+ e.getMessage());
}
if (findDialog == null) {
if (!tryLoadingLibrary(xmcf, context, "Dialog") ||
- !tryLoadingLibrary(xmcf, context, "Script"))
- {
+ !tryLoadingLibrary(xmcf, context, "Script")) {
System.err.println("Error loading ScriptBindingLibrary");
return;
}
+
try {
findDialog = xDialogProvider.createDialog(
- "vnd.sun.star.script://" +
- "ScriptBindingLibrary.Highlight?location=application");
- }
- catch (com.sun.star.lang.IllegalArgumentException iae) {
+ "vnd.sun.star.script://" +
+ "ScriptBindingLibrary.Highlight?location=application");
+ } catch (com.sun.star.lang.IllegalArgumentException iae) {
System.err.println("Error loading ScriptBindingLibrary");
return;
}
}
XControlContainer controls = (XControlContainer)
- UnoRuntime.queryInterface(XControlContainer.class, findDialog);
+ UnoRuntime.queryInterface(XControlContainer.class, findDialog);
XButton highlightButton = (XButton) UnoRuntime.queryInterface(
- XButton.class, controls.getControl("HighlightButton"));
+ XButton.class, controls.getControl("HighlightButton"));
highlightButton.setActionCommand("Highlight");
findTextBox = (XTextComponent) UnoRuntime.queryInterface(
- XTextComponent.class, controls.getControl("HighlightTextField"));
+ XTextComponent.class, controls.getControl("HighlightTextField"));
XButton exitButton = (XButton) UnoRuntime.queryInterface(
- XButton.class, controls.getControl("ExitButton"));
+ XButton.class, controls.getControl("ExitButton"));
exitButton.setActionCommand("Exit");
theDocument = (XTextDocument) UnoRuntime.queryInterface(
- XTextDocument.class, context.getDocument());
+ XTextDocument.class, context.getDocument());
highlightButton.addActionListener(this);
exitButton.addActionListener(this);
@@ -124,8 +122,7 @@ public class HighlightText implements com.sun.star.awt.XActionListener {
if (e.ActionCommand.equals("Exit")) {
findDialog.endExecute();
return;
- }
- else if (e.ActionCommand.equals("Highlight")) {
+ } else if (e.ActionCommand.equals("Highlight")) {
searchKey = findTextBox.getText();
// highlight the text in red
@@ -133,7 +130,7 @@ public class HighlightText implements com.sun.star.awt.XActionListener {
int red = cRed.getRGB();
XReplaceable replaceable = (XReplaceable)
- UnoRuntime.queryInterface(XReplaceable.class, theDocument);
+ UnoRuntime.queryInterface(XReplaceable.class, theDocument);
XReplaceDescriptor descriptor =
(XReplaceDescriptor) replaceable.createReplaceDescriptor();
@@ -141,17 +138,17 @@ public class HighlightText implements com.sun.star.awt.XActionListener {
// Gets a XPropertyReplace object for altering the properties
// of the replaced text
XPropertyReplace xPropertyReplace = (XPropertyReplace)
- UnoRuntime.queryInterface(XPropertyReplace.class, descriptor);
+ UnoRuntime.queryInterface(XPropertyReplace.class, descriptor);
// Sets the replaced text property fontweight value to Bold
PropertyValue wv = new PropertyValue("CharWeight", -1,
- new Float(com.sun.star.awt.FontWeight.BOLD),
- com.sun.star.beans.PropertyState.DIRECT_VALUE);
+ new Float(com.sun.star.awt.FontWeight.BOLD),
+ com.sun.star.beans.PropertyState.DIRECT_VALUE);
// Sets the replaced text property color value to RGB parameter
PropertyValue cv = new PropertyValue("CharColor", -1,
- Integer.valueOf(red),
- com.sun.star.beans.PropertyState.DIRECT_VALUE);
+ Integer.valueOf(red),
+ com.sun.star.beans.PropertyState.DIRECT_VALUE);
// Apply the properties
PropertyValue[] props = new PropertyValue[] { cv, wv };
@@ -163,20 +160,16 @@ public class HighlightText implements com.sun.star.awt.XActionListener {
descriptor.setPropertyValue(
"SearchCaseSensitive", Boolean.TRUE);
descriptor.setPropertyValue("SearchWords", Boolean.TRUE);
- }
- catch (com.sun.star.beans.UnknownPropertyException upe) {
+ } catch (com.sun.star.beans.UnknownPropertyException upe) {
System.err.println("Error setting up search properties");
return;
- }
- catch (com.sun.star.beans.PropertyVetoException pve) {
+ } catch (com.sun.star.beans.PropertyVetoException pve) {
System.err.println("Error setting up search properties");
return;
- }
- catch (com.sun.star.lang.WrappedTargetException wte) {
+ } catch (com.sun.star.lang.WrappedTargetException wte) {
System.err.println("Error setting up search properties");
return;
- }
- catch (com.sun.star.lang.IllegalArgumentException iae) {
+ } catch (com.sun.star.lang.IllegalArgumentException iae) {
System.err.println("Error setting up search properties");
return;
}
@@ -189,40 +182,39 @@ public class HighlightText implements com.sun.star.awt.XActionListener {
}
}
- public void disposing(EventObject o)
- {
+ public void disposing(EventObject o) {
// do nothing
}
private boolean tryLoadingLibrary(
- XMultiComponentFactory xmcf, XScriptContext context, String name)
- {
+ XMultiComponentFactory xmcf, XScriptContext context, String name) {
System.err.println("Try to load ScriptBindingLibrary");
try {
Object obj = xmcf.createInstanceWithContext(
- "com.sun.star.script.Application" + name + "LibraryContainer",
- context.getComponentContext());
+ "com.sun.star.script.Application" + name + "LibraryContainer",
+ context.getComponentContext());
XLibraryContainer xLibraryContainer = (XLibraryContainer)
- UnoRuntime.queryInterface(XLibraryContainer.class, obj);
+ UnoRuntime.queryInterface(XLibraryContainer.class, obj);
System.err.println("Got XLibraryContainer");
Object serviceObj = context.getComponentContext().getValueByName(
- "/singletons/com.sun.star.util.theMacroExpander");
+ "/singletons/com.sun.star.util.theMacroExpander");
XMacroExpander xme = (XMacroExpander) AnyConverter.toObject(
- new Type(XMacroExpander.class), serviceObj);
+ new Type(XMacroExpander.class), serviceObj);
String bootstrapName = "bootstraprc";
+
if (System.getProperty("os.name").startsWith("Windows")) {
bootstrapName = "bootstrap.ini";
}
String libURL = xme.expandMacros(
- "$BRAND_BASE_DIR/$BRAND_SHARE_SUBDIR/basic/ScriptBindingLibrary/" +
- name.toLowerCase() + ".xlb/");
+ "$BRAND_BASE_DIR/$BRAND_SHARE_SUBDIR/basic/ScriptBindingLibrary/" +
+ name.toLowerCase() + ".xlb/");
System.err.println("libURL is: " + libURL);
@@ -235,6 +227,7 @@ public class HighlightText implements com.sun.star.awt.XActionListener {
System.err.println("Got an exception loading lib: " + e.getMessage());
return false;
}
+
return true;
}
}
diff --git a/scripting/examples/java/MemoryUsage/MemoryUsage.java b/scripting/examples/java/MemoryUsage/MemoryUsage.java
index 63a643e..a01d2ba 100644
--- a/scripting/examples/java/MemoryUsage/MemoryUsage.java
+++ b/scripting/examples/java/MemoryUsage/MemoryUsage.java
@@ -39,11 +39,9 @@ import com.sun.star.sheet.*;
import com.sun.star.script.provider.XScriptContext;
-public class MemoryUsage
-{
+public class MemoryUsage {
public void updateMemoryUsage(XScriptContext ctxt)
- throws Exception
- {
+ throws Exception {
XSpreadsheet sheet = createSpreadsheet(ctxt);
Runtime runtime = Runtime.getRuntime();
@@ -55,37 +53,35 @@ public class MemoryUsage
byte[] bytes = new byte[len];
addData(sheet, date.toString(),
- runtime.totalMemory(), runtime.freeMemory());
+ runtime.totalMemory(), runtime.freeMemory());
addChart(sheet);
}
private XSpreadsheet createSpreadsheet(XScriptContext ctxt)
- throws Exception
- {
+ throws Exception {
XComponentLoader loader = (XComponentLoader)
- UnoRuntime.queryInterface(
- XComponentLoader.class, ctxt.getDesktop());
+ UnoRuntime.queryInterface(
+ XComponentLoader.class, ctxt.getDesktop());
XComponent comp = loader.loadComponentFromURL(
- "private:factory/scalc", "_blank", 4, new PropertyValue[0]);
+ "private:factory/scalc", "_blank", 4, new PropertyValue[0]);
XSpreadsheetDocument doc = (XSpreadsheetDocument)
- UnoRuntime.queryInterface(XSpreadsheetDocument.class, comp);
+ UnoRuntime.queryInterface(XSpreadsheetDocument.class, comp);
XIndexAccess index = (XIndexAccess)
- UnoRuntime.queryInterface(XIndexAccess.class, doc.getSheets());
+ UnoRuntime.queryInterface(XIndexAccess.class, doc.getSheets());
XSpreadsheet sheet = (XSpreadsheet) AnyConverter.toObject(
- new Type(com.sun.star.sheet.XSpreadsheet.class), index.getByIndex(0));
+ new Type(com.sun.star.sheet.XSpreadsheet.class), index.getByIndex(0));
return sheet;
}
private void addData(
XSpreadsheet sheet, String date, long total, long free)
- throws Exception
- {
+ throws Exception {
sheet.getCellByPosition(0, 0).setFormula("Used");
sheet.getCellByPosition(0, 1).setFormula("Free");
sheet.getCellByPosition(0, 2).setFormula("Total");
@@ -96,8 +92,7 @@ public class MemoryUsage
}
private void addChart(XSpreadsheet sheet)
- throws Exception
- {
+ throws Exception {
Rectangle rect = new Rectangle();
rect.X = 500;
rect.Y = 3000;
@@ -105,13 +100,13 @@ public class MemoryUsage
rect.Height = 8000;
XCellRange range = (XCellRange)
- UnoRuntime.queryInterface(XCellRange.class, sheet);
+ UnoRuntime.queryInterface(XCellRange.class, sheet);
XCellRange myRange =
range.getCellRangeByName("A1:B2");
XCellRangeAddressable rangeAddr = (XCellRangeAddressable)
- UnoRuntime.queryInterface(XCellRangeAddressable.class, myRange);
+ UnoRuntime.queryInterface(XCellRangeAddressable.class, myRange);
CellRangeAddress myAddr = rangeAddr.getRangeAddress();
@@ -119,42 +114,44 @@ public class MemoryUsage
addr[0] = myAddr;
XTableChartsSupplier supp = (XTableChartsSupplier)
- UnoRuntime.queryInterface( XTableChartsSupplier.class, sheet);
+ UnoRuntime.queryInterface(XTableChartsSupplier.class, sheet);
XTableCharts charts = supp.getCharts();
charts.addNewByName("Example", rect, addr, false, true);
- try { Thread.sleep(3000); } catch (InterruptedException e) { }
+ try {
+ Thread.sleep(3000);
+ } catch (InterruptedException e) { }
// get the diagram and Change some of the properties
XNameAccess chartsAccess = (XNameAccess)
- UnoRuntime.queryInterface( XNameAccess.class, charts);
+ UnoRuntime.queryInterface(XNameAccess.class, charts);
XTableChart tchart = (XTableChart)
- UnoRuntime.queryInterface(
- XTableChart.class, chartsAccess.getByName("Example"));
+ UnoRuntime.queryInterface(
+ XTableChart.class, chartsAccess.getByName("Example"));
XEmbeddedObjectSupplier eos = (XEmbeddedObjectSupplier)
- UnoRuntime.queryInterface( XEmbeddedObjectSupplier.class, tchart );
+ UnoRuntime.queryInterface(XEmbeddedObjectSupplier.class, tchart);
XInterface xifc = eos.getEmbeddedObject();
XChartDocument xChart = (XChartDocument)
- UnoRuntime.queryInterface(XChartDocument.class, xifc);
+ UnoRuntime.queryInterface(XChartDocument.class, xifc);
XMultiServiceFactory xDocMSF = (XMultiServiceFactory)
- UnoRuntime.queryInterface(XMultiServiceFactory.class, xChart);
+ UnoRuntime.queryInterface(XMultiServiceFactory.class, xChart);
Object diagObject =
xDocMSF.createInstance("com.sun.star.chart.PieDiagram");
XDiagram xDiagram = (XDiagram)
- UnoRuntime.queryInterface(XDiagram.class, diagObject);
+ UnoRuntime.queryInterface(XDiagram.class, diagObject);
xChart.setDiagram(xDiagram);
XPropertySet propset = (XPropertySet)
- UnoRuntime.queryInterface( XPropertySet.class, xChart.getTitle() );
+ UnoRuntime.queryInterface(XPropertySet.class, xChart.getTitle());
propset.setPropertyValue("String", "JVM Memory Usage");
}
}
diff --git a/scripting/examples/java/Newsgroup/MimeConfiguration.java b/scripting/examples/java/Newsgroup/MimeConfiguration.java
index 03e6c1b..03b9648 100644
--- a/scripting/examples/java/Newsgroup/MimeConfiguration.java
+++ b/scripting/examples/java/Newsgroup/MimeConfiguration.java
@@ -30,33 +30,29 @@ import javax.activation.*;
import java.io.*;
-public class MimeConfiguration
-{
+public class MimeConfiguration {
// Office Installation path
private static String instPath = "";
- public static boolean createFiles( XScriptContext xsc )
- {
- try
- {
+ public static boolean createFiles(XScriptContext xsc) {
+ try {
XComponentContext xcc = xsc.getComponentContext();
XMultiComponentFactory xmf = xcc.getServiceManager();
- Object pathSub = xmf.createInstanceWithContext( "com.sun.star.comp.framework.PathSubstitution", xcc );
- XStringSubstitution stringSub = ( XStringSubstitution ) UnoRuntime.queryInterface( XStringSubstitution.class, pathSub );
- instPath = stringSub.getSubstituteVariableValue( "$(inst)" );
+ Object pathSub =
+ xmf.createInstanceWithContext("com.sun.star.comp.framework.PathSubstitution",
+ xcc);
+ XStringSubstitution stringSub = (XStringSubstitution) UnoRuntime.queryInterface(
+ XStringSubstitution.class, pathSub);
+ instPath = stringSub.getSubstituteVariableValue("$(inst)");
- }
- catch( com.sun.star.beans.UnknownPropertyException upe )
- {
- System.out.println( "com.sun.star.beans.UnknownPropertyException" );
+ } catch (com.sun.star.beans.UnknownPropertyException upe) {
+ System.out.println("com.sun.star.beans.UnknownPropertyException");
upe.printStackTrace();
- }
- catch( com.sun.star.uno.Exception e )
- {
- System.out.println( "com.sun.star.uno.Exception" );
+ } catch (com.sun.star.uno.Exception e) {
+ System.out.println("com.sun.star.uno.Exception");
e.printStackTrace();
}
@@ -70,46 +66,38 @@ public class MimeConfiguration
- private static void writeMailCap()
- {
- String mailcapPath = getConfigDir() + System.getProperty( "file.separator" ) + "mailcap";
+ private static void writeMailCap() {
+ String mailcapPath = getConfigDir() + System.getProperty("file.separator") +
+ "mailcap";
- try
- {
- if( ! new File( java.net.URLDecoder.decode( mailcapPath ) ).exists() )
- {
- File mailcapFile = new File( mailcapPath );
- FileWriter out = new FileWriter( mailcapFile );
+ try {
+ if (! new File(java.net.URLDecoder.decode(mailcapPath)).exists()) {
+ File mailcapFile = new File(mailcapPath);
+ FileWriter out = new FileWriter(mailcapFile);
String[] lines = getMailcapText();
- for( int i=0; i<lines.length; i++ )
- {
- out.write( lines[i], 0, lines[i].length() );
+
+ for (int i = 0; i < lines.length; i++) {
+ out.write(lines[i], 0, lines[i].length());
}
+
out.close();
- }
- else
- {
- }
+ } else {
+ }
// use prog dir, if not there then java.io to create/write new file
- MailcapCommandMap map = new MailcapCommandMap( mailcapPath );
- CommandMap.setDefaultCommandMap ( map );
- }
- catch( IOException ioe )
- {
+ MailcapCommandMap map = new MailcapCommandMap(mailcapPath);
+ CommandMap.setDefaultCommandMap(map);
+ } catch (IOException ioe) {
ioe.printStackTrace();
- }
- catch( Exception e )
- {
+ } catch (Exception e) {
e.printStackTrace();
}
}
- private static String[] getMailcapText()
- {
+ private static String[] getMailcapText() {
String[] mailcapText = {
"#\n",
"# Default mailcap file for the JavaMail System.\n",
@@ -130,43 +118,35 @@ public class MimeConfiguration
- private static void writeMimeTypes()
- {
- String mimetypesPath = getConfigDir() + System.getProperty( "file.separator" ) + "mimetypes.default";
+ private static void writeMimeTypes() {
+ String mimetypesPath = getConfigDir() + System.getProperty("file.separator") +
+ "mimetypes.default";
- try
- {
- if( ! new File( java.net.URLDecoder.decode( mimetypesPath ) ).exists() )
- {
- File mimetypesFile = new File( mimetypesPath );
- FileWriter out = new FileWriter( mimetypesFile );
+ try {
+ if (! new File(java.net.URLDecoder.decode(mimetypesPath)).exists()) {
+ File mimetypesFile = new File(mimetypesPath);
+ FileWriter out = new FileWriter(mimetypesFile);
String[] lines = getMimeTypesText();
- for( int i=0; i<lines.length; i++ )
- {
- out.write( lines[i], 0, lines[i].length() );
+
+ for (int i = 0; i < lines.length; i++) {
+ out.write(lines[i], 0, lines[i].length());
}
+
out.close();
- }
- else
- {
- }
+ } else {
+ }
- MimetypesFileTypeMap mimeTypes = new MimetypesFileTypeMap( mimetypesPath );
- FileTypeMap.setDefaultFileTypeMap( mimeTypes );
- }
- catch( IOException ioe )
- {
+ MimetypesFileTypeMap mimeTypes = new MimetypesFileTypeMap(mimetypesPath);
+ FileTypeMap.setDefaultFileTypeMap(mimeTypes);
+ } catch (IOException ioe) {
ioe.printStackTrace();
- }
- catch( Exception e )
- {
+ } catch (Exception e) {
e.printStackTrace();
}
}
- private static String[] getMimeTypesText()
- {
+ private static String[] getMimeTypesText() {
String[] mimesText = {
"#\n",
"# A simple, old format, mime.types file\n",
@@ -198,36 +178,32 @@ public class MimeConfiguration
}
- private static String getConfigDir()
- {
+ private static String getConfigDir() {
// mailcap file must be written to the Office user/config directory
- // instPath is a URL, needs to be converted to a system pathname
- String config = instPath + "/user/config";
- String configNonURL = "";
-
- if( System.getProperty( "os.name" ).indexOf( "Windows" ) != -1 )
- {
- // Windows
- // removes "file:///"
- int start = 8;
- configNonURL = config.substring( start, config.length() );
- // Convert forward to back-slashes
- while( configNonURL.indexOf( "/" ) != -1 )
- {
- int fSlash = configNonURL.indexOf( "/" );
- String firstPart = configNonURL.substring( 0, fSlash );
- String secondPart = configNonURL.substring( fSlash + 1, configNonURL.length() );
- configNonURL = firstPart + "\\" + secondPart;
- }
- }
- else
- {
- // Unix/Linux
- // removes "file://"
- int start = 7;
- configNonURL = config.substring( start, config.length() );
- }
+ // instPath is a URL, needs to be converted to a system pathname
+ String config = instPath + "/user/config";
+ String configNonURL = "";
+
+ if (System.getProperty("os.name").indexOf("Windows") != -1) {
+ // Windows
+ // removes "file:///"
+ int start = 8;
+ configNonURL = config.substring(start, config.length());
+
+ // Convert forward to back-slashes
+ while (configNonURL.indexOf("/") != -1) {
+ int fSlash = configNonURL.indexOf("/");
+ String firstPart = configNonURL.substring(0, fSlash);
+ String secondPart = configNonURL.substring(fSlash + 1, configNonURL.length());
+ configNonURL = firstPart + "\\" + secondPart;
+ }
+ } else {
+ // Unix/Linux
+ // removes "file://"
+ int start = 7;
+ configNonURL = config.substring(start, config.length());
+ }
return configNonURL;
}
diff --git a/scripting/examples/java/Newsgroup/NewsGroup.java b/scripting/examples/java/Newsgroup/NewsGroup.java
index 6042dbe..4c1708a 100644
--- a/scripting/examples/java/Newsgroup/NewsGroup.java
+++ b/scripting/examples/java/Newsgroup/NewsGroup.java
@@ -18,25 +18,21 @@
package org.libreoffice.example.java_scripts;
-public class NewsGroup
-{
+public class NewsGroup {
private String hostname = "";
private String newsgroupName = "";
- public NewsGroup( String host, String group )
- {
+ public NewsGroup(String host, String group) {
hostname = host;
newsgroupName = group;
}
- public String getHostName()
- {
+ public String getHostName() {
return hostname;
}
- public String getNewsgroupName()
- {
+ public String getNewsgroupName() {
return newsgroupName;
}
diff --git a/scripting/examples/java/Newsgroup/OfficeAttachment.java b/scripting/examples/java/Newsgroup/OfficeAttachment.java
index 8a008ae..75c0f4d 100644
--- a/scripting/examples/java/Newsgroup/OfficeAttachment.java
+++ b/scripting/examples/java/Newsgroup/OfficeAttachment.java
@@ -31,8 +31,7 @@ import com.sun.star.script.framework.runtime.XScriptContext;
// for debug only
import javax.swing.JOptionPane;
-public class OfficeAttachment
-{
+public class OfficeAttachment {
private StatusWindow status = null;
private XStorable storedDoc = null;
@@ -45,137 +44,124 @@ public class OfficeAttachment
private String attachmentName = "";
private String statusLine = "";
- public OfficeAttachment( XScriptContext xsc, StatusWindow sw, boolean html, boolean office )
- {
+ public OfficeAttachment(XScriptContext xsc, StatusWindow sw, boolean html,
+ boolean office) {
status = sw;
isHtmlDoc = html;
isOfficeDoc = office;
- templocationSystem = templocationURL = System.getProperty( "user.home" );
- if( System.getProperty( "os.name" ).indexOf( "Windows" ) != -1 )
- {
- while( templocationURL.indexOf( "\\" ) != -1 )
- {
- int sepPos = templocationURL.indexOf( "\\" );
- String firstPart = templocationURL.substring( 0, sepPos );
- String lastPart = templocationURL.substring( sepPos + 1, templocationURL.length() );
+ templocationSystem = templocationURL = System.getProperty("user.home");
+
+ if (System.getProperty("os.name").indexOf("Windows") != -1) {
+ while (templocationURL.indexOf("\\") != -1) {
+ int sepPos = templocationURL.indexOf("\\");
+ String firstPart = templocationURL.substring(0, sepPos);
+ String lastPart = templocationURL.substring(sepPos + 1,
+ templocationURL.length());
templocationURL = firstPart + "/" + lastPart;
}
}
- try
- {
+ try {
statusLine = "Querying Office for current document";
- status.setStatus( 1, statusLine );
+ status.setStatus(1, statusLine);
XScriptContext scriptcontext = xsc;
XModel xmodel = scriptcontext.getDocument();
storedDoc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xmodel);
// find document name from storedDoc
attachmentName = storedDoc.getLocation();
- }
- catch( Exception e )
- {
+ } catch (Exception e) {
//UNO error
- status.setStatus( 1, "Error: " + statusLine );
+ status.setStatus(1, "Error: " + statusLine);
}
- if( attachmentName.equalsIgnoreCase( "" ) )
- {
+ if (attachmentName.equalsIgnoreCase("")) {
attachmentName = "Attachment";
- }
- else
- {
- int lastSep = attachmentName.lastIndexOf( "/" );
- attachmentName = attachmentName.substring( lastSep + 1, attachmentName.length() );
- int dot = attachmentName.indexOf( "." );
- attachmentName = attachmentName.substring( 0, dot );
+ } else {
+ int lastSep = attachmentName.lastIndexOf("/");
+ attachmentName = attachmentName.substring(lastSep + 1, attachmentName.length());
+ int dot = attachmentName.indexOf(".");
+ attachmentName = attachmentName.substring(0, dot);
}
}
- public boolean createTempDocs()
- {
+ public boolean createTempDocs() {
String filenameURL = "file:///" + templocationURL + "/" + attachmentName;
- try
- {
- if( isHtmlDoc )
- {
+
+ try {
+ if (isHtmlDoc) {
statusLine = "Saving doc in HTML format";
- status.setStatus( 4, statusLine );
- PropertyValue[] propertyvalue_html = new PropertyValue[2];
- propertyvalue_html[0] = new PropertyValue();
- propertyvalue_html[0].Name = "Overwrite";
- propertyvalue_html[0].Value = Boolean.TRUE;
- propertyvalue_html[1] = new PropertyValue();
- propertyvalue_html[1].Name = ("FilterName");
- propertyvalue_html[1].Value = "swriter: HTML (StarWriter)";
- storedDoc.storeAsURL( filenameURL + ".html", propertyvalue_html);
-
- File homedir = new File( templocationSystem );
+ status.setStatus(4, statusLine);
+ PropertyValue[] propertyvalue_html = new PropertyValue[2];
+ propertyvalue_html[0] = new PropertyValue();
+ propertyvalue_html[0].Name = "Overwrite";
+ propertyvalue_html[0].Value = Boolean.TRUE;
+ propertyvalue_html[1] = new PropertyValue();
+ propertyvalue_html[1].Name = ("FilterName");
+ propertyvalue_html[1].Value = "swriter: HTML (StarWriter)";
+ storedDoc.storeAsURL(filenameURL + ".html", propertyvalue_html);
+
+ File homedir = new File(templocationSystem);
File homefiles[] = homedir.listFiles();
String file = "";
- for(int i=0; i < homefiles.length; i++ )
- {
- if( homefiles[i].getName().equals( attachmentName + ".html" ) )
- {
+
+ for (int i = 0; i < homefiles.length; i++) {
+ if (homefiles[i].getName().equals(attachmentName + ".html")) {
file = homefiles[i].getAbsolutePath();
}
}
- htmlFile = new File( file );
+
+ htmlFile = new File(file);
}
- if( isOfficeDoc )
- {
+ if (isOfficeDoc) {
statusLine = "Saving doc in .sxw format";
- status.setStatus( 4, statusLine );
+ status.setStatus(4, statusLine);
PropertyValue[] propertyvalue_sxw = new PropertyValue[2];
- propertyvalue_sxw[0] = new PropertyValue();
- propertyvalue_sxw[0].Name = "Overwrite";
- propertyvalue_sxw[0].Value = Boolean.TRUE;
- propertyvalue_sxw[1] = new PropertyValue();
- propertyvalue_sxw[1].Name = "Overwrite";
- propertyvalue_sxw[1].Value = Boolean.TRUE;
- storedDoc.storeAsURL( filenameURL + ".sxw", propertyvalue_sxw);
+ propertyvalue_sxw[0] = new PropertyValue();
+ propertyvalue_sxw[0].Name = "Overwrite";
+ propertyvalue_sxw[0].Value = Boolean.TRUE;
+ propertyvalue_sxw[1] = new PropertyValue();
+ propertyvalue_sxw[1].Name = "Overwrite";
+ propertyvalue_sxw[1].Value = Boolean.TRUE;
+ storedDoc.storeAsURL(filenameURL + ".sxw", propertyvalue_sxw);
- File homedir = new File( templocationSystem );
+ File homedir = new File(templocationSystem);
- File homefiles[] = homedir.listFiles();
+ File homefiles[] = homedir.listFiles();
String file = "";
- for(int i=0; i < homefiles.length; i++ )
- {
- if( homefiles[i].getName().equals( attachmentName + ".sxw" ) )
- {
+
+ for (int i = 0; i < homefiles.length; i++) {
+ if (homefiles[i].getName().equals(attachmentName + ".sxw")) {
file = homefiles[i].getAbsolutePath();
- }
- }
- officeFile = new File( file );
+ }
+ }
+
+ officeFile = new File(file);
}
- }
- catch( SecurityException se )
- {
- status.setStatus( 4, "Error: " + statusLine );
- System.out.println( "Security error while saving temporary Document(s). Check file permissions in home directory." );
+ } catch (SecurityException se) {
+ status.setStatus(4, "Error: " + statusLine);
+ System.out.println("Security error while saving temporary Document(s). Check file permissions in home directory.");
se.printStackTrace();
htmlFile = null;
officeFile = null;
return false;
- }
- catch( Exception e )
- {
- status.setStatus( 4, "Error: " + statusLine );
- System.out.println( "Error saving temporary Document(s)" );
+ } catch (Exception e) {
+ status.setStatus(4, "Error: " + statusLine);
+ System.out.println("Error saving temporary Document(s)");
e.printStackTrace();
htmlFile = null;
officeFile = null;
return false;
}
+
return true;
}
- public boolean removeTempDocs()
- {
+ public boolean removeTempDocs() {
/*
if( !htmlFile.exists() && !officeFile.exists() )
{
@@ -184,89 +170,65 @@ public class OfficeAttachment
*/
statusLine = "Removing temp docs";
- status.setStatus( 13, statusLine );
+ status.setStatus(13, statusLine);
- try
- {
- if( isOfficeDoc && isHtmlDoc )
- {
+ try {
+ if (isOfficeDoc && isHtmlDoc) {
htmlFile.delete();
officeFile.delete();
- }
- else
- {
- if( isOfficeDoc )
- {
+ } else {
+ if (isOfficeDoc) {
officeFile.delete();
- }
- else
- {
+ } else {
htmlFile.delete();
}
}
- }
- catch( SecurityException se )
- {
- status.setStatus( 13, "Error: " + statusLine );
- System.out.println( "Security Error while deleting temporary Document(s). Check file permissions in home directory." );
+ } catch (SecurityException se) {
+ status.setStatus(13, "Error: " + statusLine);
+ System.out.println("Security Error while deleting temporary Document(s). Check file permissions in home directory.");
se.printStackTrace();
return false;
}
+
return true;
}
- public void cleanUpOnError()
- {
- try
- {
- if( isOfficeDoc && isHtmlDoc )
- {
+ public void cleanUpOnError() {
+ try {
+ if (isOfficeDoc && isHtmlDoc) {
htmlFile.delete();
officeFile.delete();
- }
- else
- {
- if( isOfficeDoc )
- {
+ } else {
+ if (isOfficeDoc) {
officeFile.delete();
- }
- else
- {
+ } else {
htmlFile.delete();
}
}
- }
- catch( SecurityException se )
- {
- System.out.println( "Security Error while deleting temporary Document(s). Check file permissions in home directory." );
+ } catch (SecurityException se) {
+ System.out.println("Security Error while deleting temporary Document(s). Check file permissions in home directory.");
se.printStackTrace();
}
}
- public File[] getAttachments()
- {
+ public File[] getAttachments() {
statusLine = "Retrieving temp docs";
- status.setStatus( 8, statusLine );
+ status.setStatus(8, statusLine);
File attachments[] = null;
- if( isOfficeDoc && isHtmlDoc )
- {
+
+ if (isOfficeDoc && isHtmlDoc) {
attachments = new File[2];
attachments[0] = htmlFile;
attachments[1] = officeFile;
- }
- else
- {
- if( isOfficeDoc )
- {
+ } else {
+ if (isOfficeDoc) {
attachments = new File[1];
attachments[0] = officeFile;
- }
- else
- {
+ } else {
attachments = new File[1];
attachments[0] = htmlFile;
}
@@ -276,14 +238,12 @@ public class OfficeAttachment
}
- public boolean isHtmlAttachment()
- {
+ public boolean isHtmlAttachment() {
return isHtmlDoc;
}
- public boolean isOfficeAttachment()
- {
+ public boolean isOfficeAttachment() {
return isOfficeDoc;
}
diff --git a/scripting/examples/java/Newsgroup/PostNewsgroup.java b/scripting/examples/java/Newsgroup/PostNewsgroup.java
index 83e90ad..f8320f4 100644
--- a/scripting/examples/java/Newsgroup/PostNewsgroup.java
+++ b/scripting/examples/java/Newsgroup/PostNewsgroup.java
@@ -26,8 +26,7 @@ import java.util.Vector;
import com.sun.star.script.framework.runtime.XScriptContext;
-public class PostNewsgroup extends JFrame
-{
+public class PostNewsgroup extends JFrame {
// Post to newsgroup objects
private NewsGroup[] subscribedNewsgroups = null;
@@ -63,40 +62,37 @@ public class PostNewsgroup extends JFrame
private final String replyText = "Email address to reply to";
private final String subjectText = "Subject title for the mail";
private final String commentText = "Additional comment on mail";
- private final String officeHtmlText = "Post as both Office and HTML attachments";
+ private final String officeHtmlText =
+ "Post as both Office and HTML attachments";
private final String officeText = "Post as Office attachment only";
private final String htmlText = "Post as HTML attachment only";
private final String postText = "Post to newsgroup";
private final String cancelText = "Cancel post to newsgroup";
- public void post( XScriptContext xsc )
- {
+ public void post(XScriptContext xsc) {
xscriptcontext = xsc;
window = this;
// create mailcap and mimetypes files (fix for classloader problem)
- MimeConfiguration.createFiles( xscriptcontext );
+ MimeConfiguration.createFiles(xscriptcontext);
- this.setTitle( "Post Document To Newsgroup" );
- this.setLocation( FRAMEX, FRAMEY );
+ this.setTitle("Post Document To Newsgroup");
+ this.setLocation(FRAMEX, FRAMEY);
- this.addFocusListener( new FocusAdapter()
- {
- public void focusGained( FocusEvent event )
- {
- System.out.println( "Focus gained" );
- window.update( window.getGraphics() );
+ this.addFocusListener(new FocusAdapter() {
+ public void focusGained(FocusEvent event) {
+ System.out.println("Focus gained");
+ window.update(window.getGraphics());
}
- public void focusLost( FocusEvent event )
- {
- System.out.println( "Focus lost" );
- }
+ public void focusLost(FocusEvent event) {
+ System.out.println("Focus lost");
+ }
});
Container container = getContentPane();
- container.setLayout( new GridBagLayout() );;
+ container.setLayout(new GridBagLayout());;
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.BOTH;
@@ -109,204 +105,200 @@ public class PostNewsgroup extends JFrame
constraints.gridy = 0;
constraints.gridwidth = 1;
constraints.gridheight = 3;
- constraints.insets = new Insets( 15, 15, 5, 5 );
- container.add( labelPanel, constraints );
+ constraints.insets = new Insets(15, 15, 5, 5);
+ container.add(labelPanel, constraints);
constraints.gridx = 1;
constraints.gridy = 0;
constraints.gridwidth = 4;
constraints.gridheight = 3;
- constraints.insets = new Insets( 15, 5, 5, 15 );
- container.add( textPanel, constraints );
+ constraints.insets = new Insets(15, 5, 5, 15);
+ container.add(textPanel, constraints);
constraints.gridx = 0;
constraints.gridy = 3;
constraints.gridwidth = 5;
constraints.gridheight = 1;
- constraints.insets = new Insets( 5, 15, 5, 15 );
- container.add( optionPanel, constraints );
+ constraints.insets = new Insets(5, 15, 5, 15);
+ container.add(optionPanel, constraints);
constraints.gridx = 0;
constraints.gridy = 4;
constraints.gridwidth = 5;
constraints.gridheight = 1;
- constraints.insets = new Insets( 5, 5, 5, 5 );
- container.add( buttonPanel, constraints );
+ constraints.insets = new Insets(5, 5, 5, 5);
+ container.add(buttonPanel, constraints);
this.pack();
- this.setResizable( false );
- this.setVisible( true );
+ this.setResizable(false);
+ this.setVisible(true);
}
- private JPanel constructLabelPanel()
- {
- JLabel newsgroupLabel = new JLabel( "Newsgroup:" );
- JLabel hostLabel = new JLabel( "Host:" );
- JLabel replyLabel = new JLabel( "Reply:" );
- JLabel subjectLabel = new JLabel( "Subject:" );
- JLabel commentLabel = new JLabel( "Comment:" );
+ private JPanel constructLabelPanel() {
+ JLabel newsgroupLabel = new JLabel("Newsgroup:");
+ JLabel hostLabel = new JLabel("Host:");
+ JLabel replyLabel = new JLabel("Reply:");
+ JLabel subjectLabel = new JLabel("Subject:");
+ JLabel commentLabel = new JLabel("Comment:");
- newsgroupLabel.setToolTipText( newsgroupText );
- hostLabel.setToolTipText( hostText );
- replyLabel.setToolTipText( replyText );
- subjectLabel.setToolTipText( subjectText );
- commentLabel.setToolTipText( commentText );
+ newsgroupLabel.setToolTipText(newsgroupText);
+ hostLabel.setToolTipText(hostText);
+ replyLabel.setToolTipText(replyText);
+ subjectLabel.setToolTipText(subjectText);
+ commentLabel.setToolTipText(commentText);
JPanel newsgroupPanel = new JPanel();
- newsgroupPanel.setLayout( new BorderLayout() );
- newsgroupPanel.add( newsgroupLabel, "West" );
+ newsgroupPanel.setLayout(new BorderLayout());
+ newsgroupPanel.add(newsgroupLabel, "West");
JPanel hostPanel = new JPanel();
- hostPanel.setLayout( new BorderLayout() );
- hostPanel.add( hostLabel, "West" );
+ hostPanel.setLayout(new BorderLayout());
+ hostPanel.add(hostLabel, "West");
JPanel replyPanel = new JPanel();
- replyPanel.setLayout( new BorderLayout() );
- replyPanel.add( replyLabel, "West" );
+ replyPanel.setLayout(new BorderLayout());
+ replyPanel.add(replyLabel, "West");
JPanel subjectPanel = new JPanel();
- subjectPanel.setLayout( new BorderLayout() );
- subjectPanel.add( subjectLabel, "West" );
+ subjectPanel.setLayout(new BorderLayout());
+ subjectPanel.add(subjectLabel, "West");
JPanel commentPanel = new JPanel();
- commentPanel.setLayout( new BorderLayout() );
- commentPanel.add( commentLabel, "West" );
+ commentPanel.setLayout(new BorderLayout());
+ commentPanel.add(commentLabel, "West");
JPanel emptyPanel = new JPanel();
final int labelWidth = 80;
- newsgroupPanel.setPreferredSize( new Dimension( labelWidth, TEXTBOXHEIGHT ) );
- hostPanel.setPreferredSize( new Dimension( labelWidth, TEXTBOXHEIGHT ) );
- replyPanel.setPreferredSize( new Dimension( labelWidth, TEXTBOXHEIGHT ) );
- subjectPanel.setPreferredSize( new Dimension( labelWidth, TEXTBOXHEIGHT ) );
- commentPanel.setPreferredSize( new Dimension( labelWidth, TEXTBOXHEIGHT ) );
+ newsgroupPanel.setPreferredSize(new Dimension(labelWidth, TEXTBOXHEIGHT));
+ hostPanel.setPreferredSize(new Dimension(labelWidth, TEXTBOXHEIGHT));
+ replyPanel.setPreferredSize(new Dimension(labelWidth, TEXTBOXHEIGHT));
+ subjectPanel.setPreferredSize(new Dimension(labelWidth, TEXTBOXHEIGHT));
+ commentPanel.setPreferredSize(new Dimension(labelWidth, TEXTBOXHEIGHT));
JPanel panel = new JPanel();
- panel.setLayout( new GridBagLayout() );
+ panel.setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.BOTH;
- constraints.insets = new Insets( 5, 5, 5, 5 );
+ constraints.insets = new Insets(5, 5, 5, 5);
constraints.gridx = 0;
constraints.gridy = 0;
constraints.gridwidth = 1;
constraints.gridheight = 1;
constraints.weightx = constraints.weighty = 0.0;
- panel.add( newsgroupPanel, constraints );
+ panel.add(newsgroupPanel, constraints);
constraints.gridx = 0;
constraints.gridy = 1;
constraints.gridwidth = 1;
constraints.gridheight = 1;
- panel.add( hostPanel, constraints );
+ panel.add(hostPanel, constraints);
constraints.gridx = 0;
constraints.gridy = 2;
constraints.gridwidth = 1;
constraints.gridheight = 1;
- panel.add( replyPanel, constraints );
+ panel.add(replyPanel, constraints);
constraints.gridx = 0;
constraints.gridy = 3;
constraints.gridwidth = 1;
constraints.gridheight = 1;
- panel.add( subjectPanel, constraints );
+ panel.add(subjectPanel, constraints);
constraints.gridx = 0;
constraints.gridy = 4;
constraints.gridwidth = 1;
constraints.gridheight = 1;
- panel.add( commentPanel, constraints );
+ panel.add(commentPanel, constraints);
constraints.gridx = 0;
constraints.gridy = 5;
constraints.gridwidth = 1;
constraints.gridheight = 1;
constraints.weightx = constraints.weighty = 1.0;
- panel.add( emptyPanel, constraints );
+ panel.add(emptyPanel, constraints);
return panel;
}
- private JPanel constructTextPanel()
- {
+ private JPanel constructTextPanel() {
hostTextField = new JTextField();
- hostTextField.setPreferredSize( new Dimension( TEXTBOXWIDTH, TEXTBOXHEIGHT ) );
- hostTextField.setToolTipText( hostText );
- hostTextField.setBorder( new EtchedBorder() );
+ hostTextField.setPreferredSize(new Dimension(TEXTBOXWIDTH, TEXTBOXHEIGHT));
+ hostTextField.setToolTipText(hostText);
+ hostTextField.setBorder(new EtchedBorder());
//optionPanel.setBorder( new TitledBorder( new EtchedBorder(), "Document Format" ) );
newsgroupComboBox = getNewsgroupCombo();
replyTextField = new JTextField();
- replyTextField.setPreferredSize( new Dimension( TEXTBOXWIDTH, TEXTBOXHEIGHT ) );
- replyTextField.setToolTipText( replyText );
- replyTextField.setBorder( new EtchedBorder() );
+ replyTextField.setPreferredSize(new Dimension(TEXTBOXWIDTH, TEXTBOXHEIGHT));
+ replyTextField.setToolTipText(replyText);
+ replyTextField.setBorder(new EtchedBorder());
subjectTextField = new JTextField();
- subjectTextField.setPreferredSize( new Dimension( TEXTBOXWIDTH, TEXTBOXHEIGHT ) );
- subjectTextField.setToolTipText( subjectText );
- subjectTextField.setBorder( new EtchedBorder() );
+ subjectTextField.setPreferredSize(new Dimension(TEXTBOXWIDTH, TEXTBOXHEIGHT));
+ subjectTextField.setToolTipText(subjectText);
+ subjectTextField.setBorder(new EtchedBorder());
commentTextArea = new JTextArea();
- commentTextArea.setPreferredSize( new Dimension( TEXTBOXWIDTH, TEXTAREAHEIGHT ) );
- commentTextArea.setToolTipText( commentText );
- commentTextArea.setBorder( new EtchedBorder() );
+ commentTextArea.setPreferredSize(new Dimension(TEXTBOXWIDTH, TEXTAREAHEIGHT));
+ commentTextArea.setToolTipText(commentText);
+ commentTextArea.setBorder(new EtchedBorder());
JPanel panel = new JPanel();
- panel.setLayout( new GridBagLayout() );
+ panel.setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.BOTH;
- constraints.insets = new Insets( 5, 5, 5, 5 );
+ constraints.insets = new Insets(5, 5, 5, 5);
constraints.gridx = 0;
constraints.gridy = 0;
constraints.gridwidth = 1;
constraints.gridheight = 1;
- panel.add( newsgroupComboBox, constraints );
+ panel.add(newsgroupComboBox, constraints);
constraints.gridx = 0;
constraints.gridy = 1;
constraints.gridwidth = 1;
constraints.gridheight = 1;
- panel.add( hostTextField, constraints );
+ panel.add(hostTextField, constraints);
constraints.gridx = 0;
constraints.gridy = 2;
constraints.gridwidth = 1;
constraints.gridheight = 1;
- panel.add( replyTextField, constraints );
+ panel.add(replyTextField, constraints);
constraints.gridx = 0;
constraints.gridy = 3;
constraints.gridwidth = 1;
constraints.gridheight = 1;
- panel.add( subjectTextField, constraints );
+ panel.add(subjectTextField, constraints);
constraints.gridx = 0;
constraints.gridy = 4;
constraints.gridwidth = 1;
constraints.gridheight = 2;
- panel.add( commentTextArea, constraints );
+ panel.add(commentTextArea, constraints);
return panel;
}
- private JComboBox getNewsgroupCombo()
- {
+ private JComboBox getNewsgroupCombo() {
newsgroupComboBox = new JComboBox();
//newsgroupComboBox.setBorder( new EtchedBorder() );
- newsgroupComboBox.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
+ newsgroupComboBox.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
// when newsgroup is selected
- if( subscribedNewsgroups != null )
- {
+ if (subscribedNewsgroups != null) {
int position = newsgroupComboBox.getSelectedIndex();
- if( position != -1 )
- {
- hostTextField.setText( subscribedNewsgroups[ position ].getHostName() );
- newsgroupComboBox.setToolTipText( "Newsgroup name: " + subscribedNewsgroups[ position ].getNewsgroupName() + " (Host name: " + subscribedNewsgroups[ position ].getHostName() + ")" );
+
+ if (position != -1) {
+ hostTextField.setText(subscribedNewsgroups[ position ].getHostName());
+ newsgroupComboBox.setToolTipText("Newsgroup name: " +
+ subscribedNewsgroups[ position ].getNewsgroupName() + " (Host name: " +
+ subscribedNewsgroups[ position ].getHostName() + ")");
}
}
}
@@ -319,310 +311,318 @@ public class PostNewsgroup extends JFrame
// Test for no .mozilla or no subscribed newsgroups
// subscribedNewsgroups = null;
- if( subscribedNewsgroups == null )
- {
- JOptionPane.showMessageDialog( window, "No subscribed newsgroups found in mozilla/netscape profile \nPlease enter newsgroup and host name",
- "Newsgroups Information", JOptionPane.INFORMATION_MESSAGE );
- }
- else
- {
+ if (subscribedNewsgroups == null) {
+ JOptionPane.showMessageDialog(window,
+ "No subscribed newsgroups found in mozilla/netscape profile \nPlease enter newsgroup and host name",
+ "Newsgroups Information", JOptionPane.INFORMATION_MESSAGE);
+ } else {
// Copy all newsgroups into a vector for comparison
// Alter entries (to include host name) if duplication is found
- ArrayList vector = new ArrayList( subscribedNewsgroups.length );
- for(int i=0; i < subscribedNewsgroups.length; i++ )
- {
- vector.add( subscribedNewsgroups[i].getNewsgroupName() );
+ ArrayList vector = new ArrayList(subscribedNewsgroups.length);
+
+ for (int i = 0; i < subscribedNewsgroups.length; i++) {
+ vector.add(subscribedNewsgroups[i].getNewsgroupName());
}
+
// Compare and alter
- for(int i=0; i < subscribedNewsgroups.length; i++ )
- {
+ for (int i = 0; i < subscribedNewsgroups.length; i++) {
// check if combo box already has a newsgroup with same name
// then add host name to differentiate
- for(int j=0; j < subscribedNewsgroups.length; j++ )
- {
- if( j != i && subscribedNewsgroups[j].getNewsgroupName().equalsIgnoreCase( subscribedNewsgroups[i].getNewsgroupName() ) )
- {
- vector.set( j, subscribedNewsgroups[j].getNewsgroupName() + " (" + subscribedNewsgroups[j].getHostName() + ")" );
- vector.set( i, subscribedNewsgroups[i].getNewsgroupName() + " (" + subscribedNewsgroups[i].getHostName() + ")" );
+ for (int j = 0; j < subscribedNewsgroups.length; j++) {
+ if (j != i
+ && subscribedNewsgroups[j].getNewsgroupName().equalsIgnoreCase(
+ subscribedNewsgroups[i].getNewsgroupName())) {
+ vector.set(j, subscribedNewsgroups[j].getNewsgroupName() + " (" +
+ subscribedNewsgroups[j].getHostName() + ")");
+ vector.set(i, subscribedNewsgroups[i].getNewsgroupName() + " (" +
+ subscribedNewsgroups[i].getHostName() + ")");
}
}
}
+
// Copy converted newsgroups from vector to combo box
- for(int i=0; i < subscribedNewsgroups.length; i++ )
- {
- newsgroupComboBox.addItem( vector.elementAt(i) );
+ for (int i = 0; i < subscribedNewsgroups.length; i++) {
+ newsgroupComboBox.addItem(vector.elementAt(i));
}
}// else
- newsgroupComboBox.setPreferredSize( new Dimension( TEXTBOXWIDTH, TEXTBOXHEIGHT ) );
- newsgroupComboBox.setEditable( true );
+ newsgroupComboBox.setPreferredSize(new Dimension(TEXTBOXWIDTH, TEXTBOXHEIGHT));
+ newsgroupComboBox.setEditable(true);
return newsgroupComboBox;
}
- private JPanel constructOptionPanel()
- {
- officeHtmlButton = new JRadioButton( "Office and HTML", true );
- officeHtmlButton.setToolTipText( officeHtmlText );
+ private JPanel constructOptionPanel() {
+ officeHtmlButton = new JRadioButton("Office and HTML", true);
+ officeHtmlButton.setToolTipText(officeHtmlText);
- officeButton = new JRadioButton( "Office" );
- officeButton.setToolTipText( officeText );
+ officeButton = new JRadioButton("Office");
+ officeButton.setToolTipText(officeText);
- htmlButton = new JRadioButton( "HTML" );
- htmlButton.setToolTipText( htmlText );
+ htmlButton = new JRadioButton("HTML");
+ htmlButton.setToolTipText(htmlText);
JRadioButton[] rbuttons = { officeHtmlButton, officeButton, htmlButton };
ButtonGroup radioButtonGroup = new ButtonGroup();
- for( int i=0; i < rbuttons.length; i++ )
- {
- radioButtonGroup.add( rbuttons[i] );
+
+ for (int i = 0; i < rbuttons.length; i++) {
+ radioButtonGroup.add(rbuttons[i]);
}
JPanel optionPanel = new JPanel();
- optionPanel.setBorder( new TitledBorder( new EtchedBorder(), "Document Format" ) );
- optionPanel.setLayout( new GridBagLayout() );
+ optionPanel.setBorder(new TitledBorder(new EtchedBorder(), "Document Format"));
+ optionPanel.setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.BOTH;
constraints.gridx = 0;
- constraints.gridy = 0;
- constraints.gridwidth = 1;
- constraints.gridheight = 1;
- constraints.insets = new Insets( 5, 5, 5, 30 );
- optionPanel.add( officeHtmlButton, constraints );
+ constraints.gridy = 0;
+ constraints.gridwidth = 1;
+ constraints.gridheight = 1;
+ constraints.insets = new Insets(5, 5, 5, 30);
+ optionPanel.add(officeHtmlButton, constraints);
constraints.gridx = 1;
- constraints.gridy = 0;
- constraints.gridwidth = 1;
- constraints.gridheight = 1;
- constraints.insets = new Insets( 5, 20, 5, 30 );
- optionPanel.add( officeButton, constraints );
+ constraints.gridy = 0;
+ constraints.gridwidth = 1;
+ constraints.gridheight = 1;
+ constraints.insets = new Insets(5, 20, 5, 30);
+ optionPanel.add(officeButton, constraints);
constraints.gridx = 2;
- constraints.gridy = 0;
- constraints.gridwidth = 1;
- constraints.gridheight = 1;
- constraints.insets = new Insets( 5, 20, 5, 5 );
- optionPanel.add( htmlButton, constraints );
+ constraints.gridy = 0;
+ constraints.gridwidth = 1;
+ constraints.gridheight = 1;
+ constraints.insets = new Insets(5, 20, 5, 5);
+ optionPanel.add(htmlButton, constraints);
- return optionPanel;
+ return optionPanel;
}
- public boolean sendingActions()
- {
- // posting actions
- // Validate the data
- if( isValidData() )
- {
- // Create status window
- StatusWindow statusWindow = new StatusWindow( window, "Posting to Newsgroup", FRAMEX, FRAMEY );
-
- statusWindow.setVisible( true );
- statusLine = "Ready to send...";
- statusWindow.setStatus( 0, statusLine );
-
- // Get the boolean values for HTML/Office document
- // params: ( XScriptContext, StatusWindow, html document, office document )
-
- boolean html = false;
- boolean office = false;
- if( officeHtmlButton.isSelected() ) { html = true; office = true; }
- if( officeButton.isSelected() ) { office = true; html = false; }
- if( htmlButton.isSelected() ) { html = true; office = false; }
-
- OfficeAttachment officeAttach = new OfficeAttachment( xscriptcontext, statusWindow, html, office );
-
- statusLine = "Getting user input";
- statusWindow.setStatus( 2, statusLine );
- // Get replyto, subject, comment from textboxes
- String replyto = replyTextField.getText();
- String subject = subjectTextField.getText();
- String comment = commentTextArea.getText();
-
- // Get newsgroup from combo box (corresponding position)
- String host = "";
- String group = "";
- int position = newsgroupComboBox.getSelectedIndex();
- if( subscribedNewsgroups == null || position == -1 )
- {
- host = hostTextField.getText();
- group = newsgroupComboBox.getSelectedItem().toString();
- }
- else
- {
- host = subscribedNewsgroups[ position ].getHostName();
- group = subscribedNewsgroups[ position ].getNewsgroupName();
- }
+ public boolean sendingActions() {
+ // posting actions
+ // Validate the data
+ if (isValidData()) {
+ // Create status window
+ StatusWindow statusWindow = new StatusWindow(window, "Posting to Newsgroup",
+ FRAMEX, FRAMEY);
- statusLine = "Creating sender object";
- statusWindow.setStatus( 3, statusLine );
- Sender sender = new Sender( statusWindow, officeAttach, replyto, subject, comment, host, group );
- if( !sender.sendMail() )
- {
- statusWindow.enableCancelButton( true );
- officeAttach.cleanUpOnError();
- return false;
- }
+ statusWindow.setVisible(true);
+ statusLine = "Ready to send...";
+ statusWindow.setStatus(0, statusLine);
+
+ // Get the boolean values for HTML/Office document
+ // params: ( XScriptContext, StatusWindow, html document, office document )
+
+ boolean html = false;
+ boolean office = false;
- statusLine = "Send is complete";
- statusWindow.setStatus( 14, statusLine );
+ if (officeHtmlButton.isSelected()) {
+ html = true;
+ office = true;
}
- else
- {
+
+ if (officeButton.isSelected()) {
+ office = true;
+ html = false;
+ }
+
+ if (htmlButton.isSelected()) {
+ html = true;
+ office = false;
+ }
+
+ OfficeAttachment officeAttach = new OfficeAttachment(xscriptcontext,
+ statusWindow, html, office);
+
+ statusLine = "Getting user input";
+ statusWindow.setStatus(2, statusLine);
+ // Get replyto, subject, comment from textboxes
+ String replyto = replyTextField.getText();
+ String subject = subjectTextField.getText();
+ String comment = commentTextArea.getText();
+
+ // Get newsgroup from combo box (corresponding position)
+ String host = "";
+ String group = "";
+ int position = newsgroupComboBox.getSelectedIndex();
+
+ if (subscribedNewsgroups == null || position == -1) {
+ host = hostTextField.getText();
+ group = newsgroupComboBox.getSelectedItem().toString();
+ } else {
+ host = subscribedNewsgroups[ position ].getHostName();
+ group = subscribedNewsgroups[ position ].getNewsgroupName();
+ }
+
+ statusLine = "Creating sender object";
+ statusWindow.setStatus(3, statusLine);
+ Sender sender = new Sender(statusWindow, officeAttach, replyto, subject,
+ comment, host, group);
+
+ if (!sender.sendMail()) {
+ statusWindow.enableCancelButton(true);
+ officeAttach.cleanUpOnError();
return false;
}
- return true;
+
+ statusLine = "Send is complete";
+ statusWindow.setStatus(14, statusLine);
+ } else {
+ return false;
+ }
+
+ return true;
}
- private JPanel constructButtonPanel()
- {
+ private JPanel constructButtonPanel() {
Action postAction = new AbstractAction() {
- public void actionPerformed( ActionEvent event ) {
+ public void actionPerformed(ActionEvent event) {
// posting actions
sendingActions();
}// actionPerformed
};
Action cancelAction = new AbstractAction() {
- public void actionPerformed( ActionEvent event ) {
- // cancelling actions
+ public void actionPerformed(ActionEvent event) {
+ // cancelling actions
window.dispose();
- }
- };
+ }
+ };
postButton = new JButton();
- postButton.setAction( postAction );
- postButton.setToolTipText( postText );
- postButton.setText( "Post" );
- postButton.setPreferredSize( new Dimension( BUTTONWIDTH + 20, BUTTONHEIGHT ) );
+ postButton.setAction(postAction);
+ postButton.setToolTipText(postText);
+ postButton.setText("Post");
+ postButton.setPreferredSize(new Dimension(BUTTONWIDTH + 20, BUTTONHEIGHT));
cancelButton = new JButton();
- cancelButton.setAction( cancelAction );
- cancelButton.setToolTipText( cancelText );
- cancelButton.setText( "Cancel" );
- cancelButton.setPreferredSize( new Dimension( BUTTONWIDTH + 20, BUTTONHEIGHT ) );
+ cancelButton.setAction(cancelAction);
+ cancelButton.setToolTipText(cancelText);
+ cancelButton.setText("Cancel");
+ cancelButton.setPreferredSize(new Dimension(BUTTONWIDTH + 20, BUTTONHEIGHT));
- JSeparator sep = new JSeparator( SwingConstants.HORIZONTAL );
+ JSeparator sep = new JSeparator(SwingConstants.HORIZONTAL);
JPanel buttonPanel = new JPanel();
- buttonPanel.setLayout( new GridBagLayout() );
+ buttonPanel.setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.BOTH;
- constraints.insets = new Insets( 5, 5, 5, 5 );
+ constraints.insets = new Insets(5, 5, 5, 5);
JPanel emptyPanel1 = new JPanel();
- emptyPanel1.setPreferredSize( new Dimension( BUTTONWIDTH, BUTTONHEIGHT ) );
+ emptyPanel1.setPreferredSize(new Dimension(BUTTONWIDTH, BUTTONHEIGHT));
JPanel emptyPanel2 = new JPanel();
- emptyPanel2.setPreferredSize( new Dimension( BUTTONWIDTH, BUTTONHEIGHT ) );
+ emptyPanel2.setPreferredSize(new Dimension(BUTTONWIDTH, BUTTONHEIGHT));
constraints.gridx = 0;
- constraints.gridy = 0;
- constraints.gridwidth = 4;
- constraints.gridheight = 1;
- buttonPanel.add( sep, constraints );
+ constraints.gridy = 0;
+ constraints.gridwidth = 4;
+ constraints.gridheight = 1;
+ buttonPanel.add(sep, constraints);
constraints.gridx = 0;
- constraints.gridy = 1;
- constraints.gridwidth = 1;
- constraints.gridheight = 1;
- buttonPanel.add( emptyPanel1, constraints );
+ constraints.gridy = 1;
+ constraints.gridwidth = 1;
+ constraints.gridheight = 1;
+ buttonPanel.add(emptyPanel1, constraints);
- constraints.gridx = 1;
- constraints.gridy = 1;
- constraints.gridwidth = 1;
- constraints.gridheight = 1;
- buttonPanel.add( emptyPanel2, constraints );
+ constraints.gridx = 1;
+ constraints.gridy = 1;
+ constraints.gridwidth = 1;
+ constraints.gridheight = 1;
+ buttonPanel.add(emptyPanel2, constraints);
constraints.gridx = 2;
constraints.gridy = 1;
constraints.gridwidth = 1;
constraints.gridheight = 1;
- buttonPanel.add( postButton, constraints );
+ buttonPanel.add(postButton, constraints);
constraints.gridx = 3;
constraints.gridy = 1;
constraints.gridwidth = 1;
constraints.gridheight = 1;
- constraints.insets = new Insets( 5, 5, 5, 0 );
- buttonPanel.add( cancelButton, constraints );
+ constraints.insets = new Insets(5, 5, 5, 0);
+ buttonPanel.add(cancelButton, constraints);
- return buttonPanel;
+ return buttonPanel;
}
- public void enableButtons( boolean enable )
- {
- if( enable )
- {
- postButton.setEnabled( true );
- cancelButton.setEnabled( true );
- }
- else
- {
- postButton.setEnabled( false );
- cancelButton.setEnabled( false );
+ public void enableButtons(boolean enable) {
+ if (enable) {
+ postButton.setEnabled(true);
+ cancelButton.setEnabled(true);
+ } else {
+ postButton.setEnabled(false);
+ cancelButton.setEnabled(false);
}
}
- private boolean isValidData()
- {
+ private boolean isValidData() {
// newsgroupComboBox must not be blank (format? dots and whitespace)
String newsgroupString = "";
int position = newsgroupComboBox.getSelectedIndex();
- if( subscribedNewsgroups == null || position == -1 )
- {
+
+ if (subscribedNewsgroups == null || position == -1) {
newsgroupString = newsgroupComboBox.getSelectedItem().toString();
- }
- else
- {
+ } else {
newsgroupString = subscribedNewsgroups[ position ].getNewsgroupName();
}
- if( newsgroupString.length() == 0 )
- {
+
+ if (newsgroupString.length() == 0) {
newsgroupComboBox.requestFocus();
- JOptionPane.showMessageDialog( window, "Please enter a newsgroup name", "Input Error", JOptionPane.ERROR_MESSAGE );
+ JOptionPane.showMessageDialog(window, "Please enter a newsgroup name",
+ "Input Error", JOptionPane.ERROR_MESSAGE);
return false;
}
// hostTextField must not be blank (format?)
String hostString = hostTextField.getText();
- if( hostString.length() == 0 )
- {
+
+ if (hostString.length() == 0) {
hostTextField.requestFocus();
- JOptionPane.showMessageDialog( window, "Please enter a hostname", "Input Error", JOptionPane.ERROR_MESSAGE );
- return false;
- }
+ JOptionPane.showMessageDialog(window, "Please enter a hostname", "Input Error",
+ JOptionPane.ERROR_MESSAGE);
+ return false;
+ }
// replyTextField must have <string>@<string>.<string>
// (string at least 2 chars long)
// consider <s>.<s>@<s>.<s>.<s> format? (array of dot positons?)
String replyString = replyTextField.getText();
- int atPos = replyString.indexOf( "@" );
- int dotPos = replyString.lastIndexOf( "." );
+ int atPos = replyString.indexOf("@");
+ int dotPos = replyString.lastIndexOf(".");
int length = replyString.length();
- if( length == 0 || atPos == -1 || dotPos == -1 || atPos < 2 || dotPos < atPos || dotPos + 2 == length || atPos + 2 == dotPos || atPos != replyString.lastIndexOf( "@" ) || replyString.indexOf(" ") != -1 )
- {
+
+ if (length == 0 || atPos == -1 || dotPos == -1 || atPos < 2 || dotPos < atPos
+ || dotPos + 2 == length || atPos + 2 == dotPos
+ || atPos != replyString.lastIndexOf("@") || replyString.indexOf(" ") != -1) {
replyTextField.requestFocus();
- JOptionPane.showMessageDialog( window, "Please enter a valid reply to email address", "Input Error", JOptionPane.ERROR_MESSAGE );
+ JOptionPane.showMessageDialog(window,
+ "Please enter a valid reply to email address", "Input Error",
+ JOptionPane.ERROR_MESSAGE);
return false;
}
// subjectTextField must not be blank?
String subjectString = subjectTextField.getText();
- if( subjectString.length() == 0 )
- {
+
+ if (subjectString.length() == 0) {
subjectTextField.requestFocus();
- JOptionPane.showMessageDialog( window, "Please enter subject title", "Input Error", JOptionPane.ERROR_MESSAGE );
+ JOptionPane.showMessageDialog(window, "Please enter subject title",
+ "Input Error", JOptionPane.ERROR_MESSAGE);
return false;
}
diff --git a/scripting/examples/java/Newsgroup/Sender.java b/scripting/examples/java/Newsgroup/Sender.java
index efa3ed4..00b3db8 100644
--- a/scripting/examples/java/Newsgroup/Sender.java
+++ b/scripting/examples/java/Newsgroup/Sender.java
@@ -26,116 +26,112 @@ import java.io.*;
import javax.activation.*;
-public class Sender
-{
+public class Sender {
// Constructor params:
private StatusWindow status = null;
private OfficeAttachment attachments = null;
private String replyto = "";
- private String subject = "";
- private String comment = "";
- private String hostname = "";
- private String newsgroup = "";
+ private String subject = "";
+ private String comment = "";
+ private String hostname = "";
+ private String newsgroup = "";
private String statusLine = "";
- public Sender( StatusWindow sw, OfficeAttachment attach, String reply,
- String sub, String com, String host, String group )
- {
+ public Sender(StatusWindow sw, OfficeAttachment attach, String reply,
+ String sub, String com, String host, String group) {
status = sw;
attachments = attach;
- replyto = reply;
- subject = sub;
- comment = com;
- hostname = host;
- newsgroup = group;
+ replyto = reply;
+ subject = sub;
+ comment = com;
+ hostname = host;
+ newsgroup = group;
}
- public boolean sendMail()
- {
+ public boolean sendMail() {
int statusPos = 5;
- try
- {
+
+ try {
attachments.createTempDocs();
// Property for any information
Properties props = new Properties();
// Create unique session (null is unused authenticator info)
statusLine = "Creating unique session";
- status.setStatus( statusPos, statusLine ); // 5
- Session session = Session.getInstance( props, null );
+ status.setStatus(statusPos, statusLine); // 5
+ Session session = Session.getInstance(props, null);
// Create message
statusPos++; // 6
statusLine = "Creating message";
- status.setStatus( statusPos, statusLine );
- MimeMessage message = new MimeMessage( session );
- message.setFrom( new InternetAddress( replyto ) );
- message.setSubject( subject );
- message.setText( comment );
- message.addHeader( "Newsgroups", newsgroup );
+ status.setStatus(statusPos, statusLine);
+ MimeMessage message = new MimeMessage(session);
+ message.setFrom(new InternetAddress(replyto));
+ message.setSubject(subject);
+ message.setText(comment);
+ message.addHeader("Newsgroups", newsgroup);
// Buildup bodypart with text and attachments
Multipart multipart = new MimeMultipart();
BodyPart messageBodyPart = new MimeBodyPart();
- messageBodyPart.setText( comment );
- multipart.addBodyPart( messageBodyPart );
+ messageBodyPart.setText(comment);
+ multipart.addBodyPart(messageBodyPart);
statusPos++; // 7
statusLine = "Adding attachment(s)";
- status.setStatus( statusPos, statusLine );
+ status.setStatus(statusPos, statusLine);
File attachs[] = attachments.getAttachments();
- for(int i=0; i < attachs.length; i++ )
- {
+
+ for (int i = 0; i < attachs.length; i++) {
messageBodyPart = new MimeBodyPart();
- DataSource filesource = new FileDataSource( attachs[i] );
- messageBodyPart.setDataHandler( new DataHandler( filesource ));
- messageBodyPart.setFileName( attachs[i].getName() );
- multipart.addBodyPart( messageBodyPart );
+ DataSource filesource = new FileDataSource(attachs[i]);
+ messageBodyPart.setDataHandler(new DataHandler(filesource));
+ messageBodyPart.setFileName(attachs[i].getName());
+ multipart.addBodyPart(messageBodyPart);
}
// Add multipart to mail
- message.setContent( multipart );
+ message.setContent(multipart);
// Create and send NNTP transport
statusPos += 2; // 9
statusLine = "Creating NNTP transport";
- status.setStatus( statusPos, statusLine );
- Transport transport = new NNTPTransport( session, new URLName( "news:" + newsgroup ));
+ status.setStatus(statusPos, statusLine);
+ Transport transport = new NNTPTransport(session,
+ new URLName("news:" + newsgroup));
// Null parameters are for user name and password
statusPos++; // 10
statusLine = "Connecting to mail server";
- status.setStatus( statusPos, statusLine );
- transport.connect( hostname, null, null );
+ status.setStatus(statusPos, statusLine);
+ transport.connect(hostname, null, null);
statusPos++; // 11
statusLine = "Sending message";
- status.setStatus( statusPos, statusLine );
- transport.sendMessage( message, message.getAllRecipients() );
+ status.setStatus(statusPos, statusLine);
+ transport.sendMessage(message, message.getAllRecipients());
statusPos++; // 12
statusLine = "Closing transport";
- status.setStatus( statusPos, statusLine );
+ status.setStatus(statusPos, statusLine);
transport.close();
// Clean up when finished
attachments.removeTempDocs();
return true;
- }
- catch( MessagingException me )
- {
- if( statusPos == 10 )
- {
+ } catch (MessagingException me) {
+ if (statusPos == 10) {
statusLine = "Error connecting (User authentication?)";
}
- status.setStatus( statusPos, statusLine );
- System.out.println( "Error sending message: ");
+
+ status.setStatus(statusPos, statusLine);
+ System.out.println("Error sending message: ");
me.printStackTrace();
return false;
}
diff --git a/scripting/examples/java/Newsgroup/StatusWindow.java b/scripting/examples/java/Newsgroup/StatusWindow.java
index b95fb3a..7b37c8f 100644
--- a/scripting/examples/java/Newsgroup/StatusWindow.java
+++ b/scripting/examples/java/Newsgroup/StatusWindow.java
@@ -23,8 +23,7 @@ import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
-public class StatusWindow extends JFrame
-{
+public class StatusWindow extends JFrame {
private JProgressBar progressBar = null;
private JTextField statusLabel = null;
@@ -36,62 +35,59 @@ public class StatusWindow extends JFrame
private final int MINPROGRESS = 0;
- public StatusWindow( PostNewsgroup mw, String title, int parentX, int parentY )
- {
- this.setTitle( title );
- this.setLocation( parentX + 100, parentY + 100 );
+ public StatusWindow(PostNewsgroup mw, String title, int parentX, int parentY) {
+ this.setTitle(title);
+ this.setLocation(parentX + 100, parentY + 100);
statusWindow = this;
mainWindow = mw;
- mainWindow.enableButtons( false );
+ mainWindow.enableButtons(false);
- statusWindow.addWindowListener( new WindowAdapter()
- {
- public void windowClosing( WindowEvent event ) {
- mainWindow.enableButtons( true );
+ statusWindow.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent event) {
+ mainWindow.enableButtons(true);
}
});
progressBar = new JProgressBar();
- progressBar.setStringPainted( true );
- progressBar.setMaximum( MAXPROGRESS );
- progressBar.setMinimum( MINPROGRESS );
- progressBar.setSize( 30, 400 );
+ progressBar.setStringPainted(true);
+ progressBar.setMaximum(MAXPROGRESS);
+ progressBar.setMinimum(MINPROGRESS);
+ progressBar.setSize(30, 400);
- JLabel progLabel = new JLabel( "Progress:" );
+ JLabel progLabel = new JLabel("Progress:");
JPanel progressPanel = new JPanel();
- progressPanel.setLayout( new BorderLayout( 10, 0 ) );
- progressPanel.add( progLabel, "West" );
- progressPanel.add( progressBar, "East" );
+ progressPanel.setLayout(new BorderLayout(10, 0));
+ progressPanel.add(progLabel, "West");
+ progressPanel.add(progressBar, "East");
statusLabel = new JTextField();
- statusLabel.setColumns( 25 );
- statusLabel.setEditable( false );
- statusLabel.setBorder( null );
+ statusLabel.setColumns(25);
+ statusLabel.setEditable(false);
+ statusLabel.setBorder(null);
JPanel statusPanel = new JPanel();
- statusPanel.setLayout( new BorderLayout() );
- statusPanel.add( statusLabel, "West" );
-
- cancelButton = new JButton( "Cancel" );
- cancelButton.setSize( 30, 100 );
- cancelButton.setEnabled( false );
- cancelButton.addActionListener( new ActionListener()
- {
- public void actionPerformed( ActionEvent event ) {
- // cancelling actions
- mainWindow.enableButtons( true );
+ statusPanel.setLayout(new BorderLayout());
+ statusPanel.add(statusLabel, "West");
+
+ cancelButton = new JButton("Cancel");
+ cancelButton.setSize(30, 100);
+ cancelButton.setEnabled(false);
+ cancelButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ // cancelling actions
+ mainWindow.enableButtons(true);
statusWindow.dispose();
- }
- });
+ }
+ });
JPanel buttonPanel = new JPanel();
- buttonPanel.setLayout( new BorderLayout( 0, 5 ) );
- buttonPanel.add( cancelButton, "East" );
- buttonPanel.add( new JSeparator( SwingConstants.HORIZONTAL ), "North" );
+ buttonPanel.setLayout(new BorderLayout(0, 5));
+ buttonPanel.add(cancelButton, "East");
+ buttonPanel.add(new JSeparator(SwingConstants.HORIZONTAL), "North");
Container container = getContentPane();
- container.setLayout( new GridBagLayout() );
+ container.setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.BOTH;
@@ -99,55 +95,51 @@ public class StatusWindow extends JFrame
constraints.gridy = 0;
constraints.gridwidth = 1;
constraints.gridheight = 1;
- constraints.insets = new Insets( 15, 15, 10, 15 );
- container.add( progressPanel, constraints );
+ constraints.insets = new Insets(15, 15, 10, 15);
+ container.add(progressPanel, constraints);
constraints.gridx = 0;
constraints.gridy = 1;
constraints.gridwidth = 1;
constraints.gridheight = 1;
- constraints.insets = new Insets( 10, 15, 10, 15 );
- container.add( statusPanel, constraints );
+ constraints.insets = new Insets(10, 15, 10, 15);
+ container.add(statusPanel, constraints);
constraints.gridx = 0;
constraints.gridy = 2;
constraints.gridwidth = 1;
constraints.gridheight = 1;
- constraints.insets = new Insets( 10, 15, 5, 15 );
- container.add( buttonPanel, constraints );
+ constraints.insets = new Insets(10, 15, 5, 15);
+ container.add(buttonPanel, constraints);
this.pack();
- this.setResizable( false );
+ this.setResizable(false);
}
- public void setStatus( int progress, String status )
- {
- progressBar.setValue( progress );
- statusLabel.setText( status );
- statusLabel.setToolTipText( status );
- if( progress == MAXPROGRESS )
- {
- cancelButton.setEnabled( true );
- cancelButton.setText( "Close" );
+ public void setStatus(int progress, String status) {
+ progressBar.setValue(progress);
+ statusLabel.setText(status);
+ statusLabel.setToolTipText(status);
+
+ if (progress == MAXPROGRESS) {
+ cancelButton.setEnabled(true);
+ cancelButton.setText("Close");
}
- update( getGraphics() );
- mainWindow.update( mainWindow.getGraphics() );
+
+ update(getGraphics());
+ mainWindow.update(mainWindow.getGraphics());
}
- public void enableCancelButton( boolean enable )
- {
- if( enable )
- {
- cancelButton.setEnabled( true );
- cancelButton.setText( "Finish" );
- }
- else
- {
- cancelButton.setEnabled( false );
- cancelButton.setText( "Cancel" );
+ public void enableCancelButton(boolean enable) {
+ if (enable) {
+ cancelButton.setEnabled(true);
+ cancelButton.setText("Finish");
+ } else {
+ cancelButton.setEnabled(false);
+ cancelButton.setText("Cancel");
}
}
diff --git a/scripting/examples/java/Newsgroup/SubscribedNewsgroups.java b/scripting/examples/java/Newsgroup/SubscribedNewsgroups.java
index a4f230b..eb135a3 100644
--- a/scripting/examples/java/Newsgroup/SubscribedNewsgroups.java
+++ b/scripting/examples/java/Newsgroup/SubscribedNewsgroups.java
@@ -28,21 +28,18 @@ public class SubscribedNewsgroups {
private static NewsGroup[] allSubscribed = null;
private static boolean windows = false;
- public static void main( String[] args ) {
+ public static void main(String[] args) {
// Test the class
SubscribedNewsgroups subscribed = new SubscribedNewsgroups();
NewsGroup allGroups[] = subscribed.getNewsGroups();
- if( allGroups == null )
- {
+ if (allGroups == null) {
System.out.println("Could not find subscribed newsgroups from mozilla/netscape mailrc files");
- }
- else
- {
- for( int i=0; i < allGroups.length; i++ )
- {
- System.out.println( "Hostname is: " + allGroups[i].getHostName() + " Newsgroup is: " + allGroups[i].getNewsgroupName() );
+ } else {
+ for (int i = 0; i < allGroups.length; i++) {
+ System.out.println("Hostname is: " + allGroups[i].getHostName() +
+ " Newsgroup is: " + allGroups[i].getNewsgroupName());
}
}
}
@@ -51,84 +48,87 @@ public class SubscribedNewsgroups {
// Only public method of the class
// Returns and array of unique NewsGroup objects
- public NewsGroup[] getNewsGroups()
- {
+ public NewsGroup[] getNewsGroups() {
windows = false;
- if( System.getProperty( "os.name" ).indexOf( "Windows" ) != -1 )
- {
+
+ if (System.getProperty("os.name").indexOf("Windows") != -1) {
windows = true;
}
String mozillaHome = "";
- if( windows )
- {
- mozillaHome = System.getProperty( "user.home" ) + System.getProperty( "file.separator" ) + "Application Data" + System.getProperty( "file.separator" ) + "Mozilla" + System.getProperty( "file.separator" ) + "Profiles";
- }
- else
- {
- mozillaHome = System.getProperty( "user.home" ) + System.getProperty( "file.separator" ) + ".mozilla";
+
+ if (windows) {
+ mozillaHome = System.getProperty("user.home") +
+ System.getProperty("file.separator") + "Application Data" +
+ System.getProperty("file.separator") + "Mozilla" +
+ System.getProperty("file.separator") + "Profiles";
+ } else {
+ mozillaHome = System.getProperty("user.home") +
+ System.getProperty("file.separator") + ".mozilla";
}
- if( !new File( mozillaHome ).isDirectory() )
- {
+
+ if (!new File(mozillaHome).isDirectory()) {
return null;
}
// Get all the profiles belonging to the user
- File profiles[] = findProfiles( new File ( mozillaHome ) );
- if( profiles.length < 1 )
- {
+ File profiles[] = findProfiles(new File(mozillaHome));
+
+ if (profiles.length < 1) {
return null;
}
// Get the News directory for each profile
File allNewsDirs[] = new File[ profiles.length ];
- for( int i=0; i < profiles.length; i++ ) {
- File newsDir = findNewsDir( profiles[i] );
+
+ for (int i = 0; i < profiles.length; i++) {
+ File newsDir = findNewsDir(profiles[i]);
allNewsDirs[i] = newsDir;
}
+
// Check that at least one News directory exists and remove nulls
boolean newsFound = false;
- for( int i=0; i < allNewsDirs.length; i++ ) {
- if( allNewsDirs[i] != null ) {
+
+ for (int i = 0; i < allNewsDirs.length; i++) {
+ if (allNewsDirs[i] != null) {
newsFound = true;
break;
}
}
- if( !newsFound )
- {
+
+ if (!newsFound) {
return null;
}
// Get all the mailrc files for each News directory
- File allMailrcs[] = findMailrcFiles( allNewsDirs );
- if( allMailrcs == null )
- {
+ File allMailrcs[] = findMailrcFiles(allNewsDirs);
+
+ if (allMailrcs == null) {
return null;
}
ArrayList<NewsGroup> subscribed = new ArrayList<NewsGroup>();
+
// Get the newsgroups in each mailrc file
- for( int i=0; i < allMailrcs.length; i++ )
- {
+ for (int i = 0; i < allMailrcs.length; i++) {
File mailrc = (File) allMailrcs[i];
- NewsGroup newsgroup[] = findNewsgroups( mailrc );
+ NewsGroup newsgroup[] = findNewsgroups(mailrc);
+
//if the Newsgroup has not already been added to the list
- for( int j=0; j < newsgroup.length; j++ )
- {
+ for (int j = 0; j < newsgroup.length; j++) {
// if newsgroup is unique then add to the list
- if( !listed( newsgroup[j], subscribed ) )
- {
- subscribed.addElement( newsgroup[j] );
+ if (!listed(newsgroup[j], subscribed)) {
+ subscribed.addElement(newsgroup[j]);
}
}
}
// Copy all unique Newsgroups into the global array
allSubscribed = new NewsGroup[ subscribed.size() ];
- subscribed.toArray( allSubscribed );
+ subscribed.toArray(allSubscribed);
+
// Test that at least one subscribed newsgroup has been found
- if( allSubscribed.length < 1 )
- {
+ if (allSubscribed.length < 1) {
return null;
}
@@ -139,16 +139,17 @@ public class SubscribedNewsgroups {
// Tests if the NewsGroup object has already been listed by another mailrc file
- private static boolean listed( NewsGroup newsgroup, ArrayList<NewsGroup> uniqueSubscription )
- {
- for(int i=0; i < uniqueSubscription.size(); i++)
- {
+ private static boolean listed(NewsGroup newsgroup,
+ ArrayList<NewsGroup> uniqueSubscription) {
+ for (int i = 0; i < uniqueSubscription.size(); i++) {
NewsGroup tempGroup = uniqueSubscription.elementAt(i);
+
// Test for duplication
- if(newsgroup.getHostName().equalsIgnoreCase( tempGroup.getHostName()) &&
- newsgroup.getNewsgroupName().equalsIgnoreCase( tempGroup.getNewsgroupName() ) )
+ if (newsgroup.getHostName().equalsIgnoreCase(tempGroup.getHostName()) &&
+ newsgroup.getNewsgroupName().equalsIgnoreCase(tempGroup.getNewsgroupName()))
return true;
}
+
return false;
}
@@ -156,8 +157,7 @@ public class SubscribedNewsgroups {
// Finds all the NewsGroups in an individual mailrc file
- private static NewsGroup[] findNewsgroups(File mailrcfile )
- {
+ private static NewsGroup[] findNewsgroups(File mailrcfile) {
String hostname = "";
String newsgroup = "";
@@ -168,46 +168,45 @@ public class SubscribedNewsgroups {
//If the newsgroup is not already contained in the global NewsGroup[] array then add it
String filename = mailrcfile.getPath();
- if( windows )
- {
+
+ if (windows) {
// Windows format "staroffice-news.germany.sun.com.rc"
int hostNameStart = filename.lastIndexOf("\\") + 1;
int hostNameEnd = filename.indexOf(".rc");
- hostname = filename.substring( hostNameStart, hostNameEnd );
- }
- else
- {
+ hostname = filename.substring(hostNameStart, hostNameEnd);
+ } else {
// Unix/Linux format "newsrc-staroffice-news.germany.sun.com"
int hostNameStart = filename.lastIndexOf("newsrc-") + 7;
- hostname = filename.substring( hostNameStart, filename.length() );
+ hostname = filename.substring(hostNameStart, filename.length());
}
// Assumes the content format in Window is the same as Unix/Linux (unknown at the moment)
// i.e. a list of newsgroups each ending with a ":"
LineNumberReader in = null;
+
try {
- in = new LineNumberReader( new FileReader( mailrcfile ) );
+ in = new LineNumberReader(new FileReader(mailrcfile));
ArrayList groups = new ArrayList();
String inString = "";
int line = 0;
- while( inString != null )
- {
- in.setLineNumber( line );
+
... etc. - the rest is truncated
More information about the Libreoffice-commits
mailing list