summaryrefslogtreecommitdiff
path: root/odk/examples/DevelopersGuide/OfficeDev
diff options
context:
space:
mode:
Diffstat (limited to 'odk/examples/DevelopersGuide/OfficeDev')
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Clipboard/Clipboard.java235
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Clipboard/ClipboardListener.java61
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Clipboard/ClipboardOwner.java66
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Clipboard/Makefile105
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Clipboard/TextTransferable.java91
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/ContextMenuInterceptor.java262
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/CustomizeView.java304
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Desk.java102
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/DocumentView.java436
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/FunctionHelper.java1066
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/IOnewayLink.java76
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/IShutdownListener.java53
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Install.txt10
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Interceptor.java678
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/JavaWindowPeerFake.java113
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Makefile134
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/NativeView.java188
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/OfficeConnect.java211
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/OnewayExecutor.java246
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/StatusListener.java484
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/StatusView.java272
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/ViewContainer.java275
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/unix/Makefile79
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/unix/nativeview.c117
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/unix/nativeview.h69
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/windows/Makefile87
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/windows/nativeview.c184
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/windows/nativeview.h69
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DisableCommands/DisableCommandsTest.java417
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DisableCommands/Makefile98
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/AsciiReplaceFilter.java739
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/FilterOptions.java236
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/Makefile144
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/TypeDetection.xcu29
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/FlatXmlTypeDetection.xcu71
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/Makefile156
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/fdcomp.cxx115
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/filterdetect.cxx260
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/filterdetect.hxx124
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/FlatXml.cxx379
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/FlatXmlFilter_cpp.uno.xml59
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/FlatXmlFilter_cpp.xcu86
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/Makefile154
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/FlatXml.java279
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/FlatXmlFilter_java.xcu86
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/Makefile147
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Linguistic/LinguisticExamples.java374
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Linguistic/Makefile243
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Linguistic/OneInstanceFactory.java161
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Linguistic/PropChgHelper.java200
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Linguistic/PropChgHelper_Hyph.java92
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Linguistic/PropChgHelper_Spell.java116
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleHyphenator.java554
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleSpellChecker.java497
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleThesaurus.java334
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Linguistic/XHyphenatedWord_impl.java103
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Linguistic/XMeaning_impl.java75
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Linguistic/XPossibleHyphens_impl.java95
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Linguistic/XSpellAlternatives_impl.java98
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Makefile112
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/MenuElement.java62
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Number_Formats.java259
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/OfficeConnect.java190
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/PathSettings/Makefile98
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/PathSettings/PathSettingsTest.java174
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/PathSubstitution/Makefile98
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/PathSubstitution/PathSubstitutionTest.java125
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/TerminationTest/Makefile103
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/TerminationTest/TerminateListener.java66
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/TerminationTest/TerminationTest.java107
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/makefile.mk184
71 files changed, 14172 insertions, 0 deletions
diff --git a/odk/examples/DevelopersGuide/OfficeDev/Clipboard/Clipboard.java b/odk/examples/DevelopersGuide/OfficeDev/Clipboard/Clipboard.java
new file mode 100644
index 000000000000..edf61a2c8a94
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Clipboard/Clipboard.java
@@ -0,0 +1,235 @@
+/*************************************************************************
+ *
+ * $RCSfile: Clipboard.java,v $
+ *
+ * $Revision: 1.5 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:36:21 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.frame.XComponentLoader;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.datatransfer.DataFlavor;
+import com.sun.star.datatransfer.UnsupportedFlavorException;
+import com.sun.star.datatransfer.XTransferable;
+import com.sun.star.datatransfer.clipboard.XClipboard;
+import com.sun.star.datatransfer.clipboard.XClipboardNotifier;
+import com.sun.star.text.XTextDocument;
+import com.sun.star.uno.AnyConverter;
+
+//-------------------------------------------------
+// Demonstrates the usage of the clipboard service
+//-------------------------------------------------
+
+public class Clipboard
+{
+ public static void main(String[] args)
+ {
+ try
+ {
+ // get the remote office context. If necessary a new office
+ // process is started
+ XComponentContext xOfficeContext =
+ com.sun.star.comp.helper.Bootstrap.bootstrap();
+ System.out.println("Connected to a running office ...");
+ // get the service manager from the office context
+ XMultiComponentFactory xServiceManager =
+ xOfficeContext.getServiceManager();
+
+ // create a new test document
+ Object oDesktop = xServiceManager.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xOfficeContext);
+
+ XComponentLoader xCompLoader =(XComponentLoader)
+ UnoRuntime.queryInterface(XComponentLoader.class, oDesktop);
+
+ com.sun.star.lang.XComponent xComponent =
+ xCompLoader.loadComponentFromURL("private:factory/swriter",
+ "_blank", 0, new com.sun.star.beans.PropertyValue[0]);
+ {
+ XTextDocument xDoc =(XTextDocument)
+ UnoRuntime.queryInterface(XTextDocument.class, xComponent);
+ xDoc.getText().setString("In the first step, paste the current content of the clipboard in the document!\nThe text \"Hello world!\" shall be insert at the current cursor position below.\n\nIn the second step, please select some words and put it into the clipboard! ...\n\nCurrent clipboard content = ");
+
+ // ensure that the document content is optimal visible
+ com.sun.star.frame.XModel xModel =
+ (com.sun.star.frame.XModel)UnoRuntime.queryInterface(
+ com.sun.star.frame.XModel.class, xDoc);
+ // get the frame for later usage
+ com.sun.star.frame.XFrame xFrame =
+ xModel.getCurrentController().getFrame();
+
+ com.sun.star.view.XViewSettingsSupplier xViewSettings =
+ (com.sun.star.view.XViewSettingsSupplier)UnoRuntime.queryInterface(
+ com.sun.star.view.XViewSettingsSupplier.class,
+ xModel.getCurrentController());
+ xViewSettings.getViewSettings().setPropertyValue(
+ "ZoomType", new Short((short)0));
+ }
+ // test document will be closed later
+
+ Object oClipboard = xServiceManager.createInstanceWithContext(
+ "com.sun.star.datatransfer.clipboard.SystemClipboard",
+ xOfficeContext);
+
+ XClipboard xClipboard = (XClipboard)
+ UnoRuntime.queryInterface(XClipboard.class, oClipboard);
+
+ //---------------------------------------------------
+ // registering as clipboard listener
+ //---------------------------------------------------
+
+ XClipboardNotifier xClipNotifier = (XClipboardNotifier)
+ UnoRuntime.queryInterface(XClipboardNotifier.class, oClipboard);
+
+ ClipboardListener aClipListener= new ClipboardListener();
+
+ xClipNotifier.addClipboardListener(aClipListener);
+
+ // Read ClipBoard
+ readClipBoard(xClipboard);
+
+ //---------------------------------------------------
+ // becoming a clipboard owner
+ //---------------------------------------------------
+
+ System.out.println("Becoming a clipboard owner...");
+ System.out.println("");
+
+ ClipboardOwner aClipOwner = new ClipboardOwner();
+ xClipboard.setContents(new TextTransferable("Hello World!"), aClipOwner);
+ int iFirst = 0;
+
+ while (aClipOwner.isClipboardOwner())
+ {
+ if (iFirst != 2) {
+ if (iFirst == 1) {
+ System.out.println("Change clipboard ownership by putting something into the clipboard!\n");
+ System.out.print("Still clipboard owner...");
+ } else {
+ System.out.println("Still clipboard owner...");
+ }
+ ++iFirst;
+ } else {
+ System.out.print(".");
+ }
+ Thread.sleep(1000);
+ }
+
+ // Read ClipBoard again
+ readClipBoard(xClipboard);
+
+ //---------------------------------------------------
+ // unregistering as clipboard listener
+ //---------------------------------------------------
+ xClipNotifier.removeClipboardListener(aClipListener);
+
+ // close test document
+ com.sun.star.util.XCloseable xCloseable = (com.sun.star.util.XCloseable)
+ UnoRuntime.queryInterface(com.sun.star.util.XCloseable.class,
+ xComponent );
+
+ if (xCloseable != null ) {
+ xCloseable.close(false);
+ } else
+ {
+ xComponent.dispose();
+ }
+
+ System.exit(0);
+ }
+ catch( Exception ex )
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ public static void readClipBoard(XClipboard xClipboard)
+ throws java.lang.Exception
+ {
+ //---------------------------------------------------
+ // get a list of formats currently on the clipboard
+ //---------------------------------------------------
+
+ XTransferable xTransferable = xClipboard.getContents();
+
+ DataFlavor[] aDflvArr = xTransferable.getTransferDataFlavors();
+
+ // print all available formats
+
+ System.out.println("Reading the clipboard...");
+ System.out.println("Available clipboard formats:");
+
+ DataFlavor aUniFlv = null;
+
+ for (int i=0;i<aDflvArr.length;i++)
+ {
+ System.out.println( "MimeType: " +
+ aDflvArr[i].MimeType +
+ " HumanPresentableName: " +
+ aDflvArr[i].HumanPresentableName );
+
+ // if there is the format unicode text on the clipboard save the
+ // corresponding DataFlavor so that we can later output the string
+
+ if ( aDflvArr[i].MimeType.equals("text/plain;charset=utf-16") )
+ {
+ aUniFlv = aDflvArr[i];
+ }
+ }
+
+ System.out.println("");
+
+ try
+ {
+ if (aUniFlv != null)
+ {
+ System.out.print("Unicode text on the clipboard ...\nYour selected text \"");
+ Object aData = xTransferable.getTransferData(aUniFlv);
+ System.out.println(AnyConverter.toString(aData)
+ + "\" is now in the clipboard.\n");
+ }
+ }
+ catch( UnsupportedFlavorException ex )
+ {
+ System.err.println( "Requested format is not available on the clipboard!" );
+ ex.printStackTrace();
+ }
+ }
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/Clipboard/ClipboardListener.java b/odk/examples/DevelopersGuide/OfficeDev/Clipboard/ClipboardListener.java
new file mode 100644
index 000000000000..20de20ba446c
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Clipboard/ClipboardListener.java
@@ -0,0 +1,61 @@
+/*************************************************************************
+ *
+ * $RCSfile: ClipboardListener.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:36:34 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.lang.EventObject;
+import com.sun.star.datatransfer.clipboard.ClipboardEvent;
+import com.sun.star.datatransfer.clipboard.XClipboardListener;
+
+//-----------------------------
+// A simple clipboard listener
+//-----------------------------
+
+public class ClipboardListener implements XClipboardListener
+{
+ public void disposing(EventObject event)
+ {
+ }
+
+ public void changedContents(ClipboardEvent event)
+ {
+ System.out.println("");
+ System.out.println("Clipboard content has changed!");
+ System.out.println("");
+ }
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/Clipboard/ClipboardOwner.java b/odk/examples/DevelopersGuide/OfficeDev/Clipboard/ClipboardOwner.java
new file mode 100644
index 000000000000..79c9c67c42db
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Clipboard/ClipboardOwner.java
@@ -0,0 +1,66 @@
+/*************************************************************************
+ *
+ * $RCSfile: ClipboardOwner.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:36:46 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.datatransfer.XTransferable;
+import com.sun.star.datatransfer.clipboard.XClipboard;
+import com.sun.star.datatransfer.clipboard.XClipboardOwner;
+
+//--------------------------
+// A simple clipboard owner
+//--------------------------
+
+public class ClipboardOwner implements XClipboardOwner
+{
+ public void lostOwnership( XClipboard xClipboard, XTransferable xTransferable )
+ {
+ System.out.println("");
+ System.out.println( "Lost clipboard ownership..." );
+ System.out.println("");
+
+ isowner = false;
+ }
+
+ public boolean isClipboardOwner()
+ {
+ return isowner;
+ }
+
+ private boolean isowner = true;
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/Clipboard/Makefile b/odk/examples/DevelopersGuide/OfficeDev/Clipboard/Makefile
new file mode 100644
index 000000000000..ff4d2a5b9a7e
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Clipboard/Makefile
@@ -0,0 +1,105 @@
+#*************************************************************************
+#
+# $RCSfile: Makefile,v $
+#
+# $Revision: 1.6 $
+#
+# last change: $Author: rt $ $Date: 2005-03-29 12:11:06 $
+#
+# The Contents of this file are made available subject to the terms of
+# the BSD license.
+#
+# Copyright (c) 2003 by Sun Microsystems, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+#**************************************************************************
+
+# Builds the OfficeDevClipboard example of the Developers Guide.
+
+PRJ=../../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+include $(SETTINGS)/dk.mk
+
+# Define non-platform/compiler specific settings
+EXAMPLE_NAME=OfficeDevClipboardExample
+OUT_APP_CLASS = $(OUT_CLASS)/$(EXAMPLE_NAME)
+
+APP1_NAME=Clipboard
+APP1_JAR=$(OUT_APP_CLASS)/$(APP1_NAME).jar
+
+APP1_JAVAFILES = \
+ Clipboard.java \
+ ClipboardListener.java \
+ ClipboardOwner.java \
+ TextTransferable.java
+
+APP1_CLASSFILES = $(patsubst %.java,$(OUT_APP_CLASS)/%.class,$(APP1_JAVAFILES))
+APP1_CLASSNAMES = $(patsubst %.java,%.class,$(APP1_JAVAFILES))
+
+SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
+ $(PATH_SEPARATOR)$(OUT_APP_CLASS))
+
+
+# Targets
+.PHONY: ALL
+ALL : $(EXAMPLE_NAME)
+
+include $(SETTINGS)/stdtarget.mk
+
+$(APP1_CLASSFILES) : $(APP1_JAVAFILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_APP_CLASS) $^
+
+$(OUT_APP_CLASS)/%.mf :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo Main-Class: com.sun.star.lib.loader.Loader> $@
+ $(ECHOLINE)>> $@
+ @echo Name: com/sun/star/lib/loader/Loader.class>> $@
+ @echo Application-Class: $*>> $@
+
+$(APP1_JAR) : $(OUT_APP_CLASS)/$(APP1_NAME).mf $(APP1_CLASSFILES)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ +cd $(subst /,$(PS),$(OUT_APP_CLASS)) && $(SDK_JAR) cvfm $(@F) $(basename $(@F)).mf $(APP1_CLASSNAMES)
+ +$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES)
+
+$(EXAMPLE_NAME) : $(APP1_JAR)
+ @echo --------------------------------------------------------------------------------
+ @echo Please use the following command to execute the example!
+ @echo -
+ @echo $(MAKE) $(APP1_NAME).run
+ @echo --------------------------------------------------------------------------------
+
+%.run: $(OUT_APP_CLASS)/%.jar
+ $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $<
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_CLASS))
diff --git a/odk/examples/DevelopersGuide/OfficeDev/Clipboard/TextTransferable.java b/odk/examples/DevelopersGuide/OfficeDev/Clipboard/TextTransferable.java
new file mode 100644
index 000000000000..ad32af304b1d
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Clipboard/TextTransferable.java
@@ -0,0 +1,91 @@
+/*************************************************************************
+ *
+ * $RCSfile: TextTransferable.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:37:11 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.datatransfer.DataFlavor;
+import com.sun.star.datatransfer.UnsupportedFlavorException;
+import com.sun.star.datatransfer.XTransferable;
+import com.sun.star.uno.Type;
+
+//---------------------------------------
+// A simple transferable containing only
+// one format, unicode text
+//---------------------------------------
+
+public class TextTransferable implements XTransferable
+{
+ public TextTransferable(String aText)
+ {
+ text = aText;
+ }
+
+ // XTransferable methods
+
+ public Object getTransferData(DataFlavor aFlavor) throws UnsupportedFlavorException
+ {
+ if ( !aFlavor.MimeType.equalsIgnoreCase( UNICODE_CONTENT_TYPE ) )
+ throw new UnsupportedFlavorException();
+
+ return text;
+ }
+
+ public DataFlavor[] getTransferDataFlavors()
+ {
+ DataFlavor[] adf = new DataFlavor[1];
+
+ DataFlavor uniflv = new DataFlavor(
+ UNICODE_CONTENT_TYPE,
+ "Unicode Text",
+ new Type(String.class) );
+
+ adf[0] = uniflv;
+
+ return adf;
+ }
+
+ public boolean isDataFlavorSupported(DataFlavor aFlavor)
+ {
+ return aFlavor.MimeType.equalsIgnoreCase(UNICODE_CONTENT_TYPE);
+ }
+
+// members
+
+ private final String text;
+ private final String UNICODE_CONTENT_TYPE = "text/plain;charset=utf-16";
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/ContextMenuInterceptor.java b/odk/examples/DevelopersGuide/OfficeDev/ContextMenuInterceptor.java
new file mode 100644
index 000000000000..bbd702baa35b
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/ContextMenuInterceptor.java
@@ -0,0 +1,262 @@
+/*************************************************************************
+ *
+ * $RCSfile: ContextMenuInterceptor.java,v $
+ *
+ * $Revision: 1.7 $
+ *
+ * last change: $Author: vg $ $Date: 2006-03-15 09:28:21 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.ui.ActionTriggerSeparatorType;
+import com.sun.star.ui.ContextMenuInterceptorAction;
+import com.sun.star.ui.XContextMenuInterceptor;
+import com.sun.star.uno.UnoRuntime;
+
+public class ContextMenuInterceptor implements XContextMenuInterceptor {
+
+ /**
+ *Description of the Method
+ *
+ *@param args Description of Parameter
+ *@since
+ */
+ public static void main(String args[])
+ {
+ try {
+ OfficeConnect aConnect = OfficeConnect.createConnection();
+
+ com.sun.star.frame.XDesktop xDesktop =
+ (com.sun.star.frame.XDesktop)aConnect.createRemoteInstance(
+ com.sun.star.frame.XDesktop.class,"com.sun.star.frame.Desktop");
+
+ // create a new test document
+ com.sun.star.frame.XComponentLoader xCompLoader =
+ (com.sun.star.frame.XComponentLoader)UnoRuntime.queryInterface(
+ com.sun.star.frame.XComponentLoader.class, xDesktop);
+
+ com.sun.star.lang.XComponent xComponent =
+ xCompLoader.loadComponentFromURL("private:factory/swriter",
+ "_blank", 0, new com.sun.star.beans.PropertyValue[0]);
+
+ // intialize the test document
+ com.sun.star.frame.XFrame xFrame = null;
+ {
+ com.sun.star.text.XTextDocument xDoc =(com.sun.star.text.XTextDocument)
+ UnoRuntime.queryInterface(com.sun.star.text.XTextDocument.class,
+ xComponent);
+
+ String infoMsg = new String("All context menus of the created document frame contains now a 'Help' entry with the submenus 'Content', 'Help Agent' and 'Tips'.\n\nPress 'Return' in the shell to remove the context menu interceptor and finish the example!");
+ xDoc.getText().setString(infoMsg);
+
+ // ensure that the document content is optimal visible
+ com.sun.star.frame.XModel xModel =
+ (com.sun.star.frame.XModel)UnoRuntime.queryInterface(
+ com.sun.star.frame.XModel.class, xDoc);
+ // get the frame for later usage
+ xFrame = xModel.getCurrentController().getFrame();
+
+ com.sun.star.view.XViewSettingsSupplier xViewSettings =
+ (com.sun.star.view.XViewSettingsSupplier)UnoRuntime.queryInterface(
+ com.sun.star.view.XViewSettingsSupplier.class, xModel.getCurrentController());
+ xViewSettings.getViewSettings().setPropertyValue(
+ "ZoomType", new Short((short)0));
+ }
+ // test document will be closed later
+
+ // reuse the frame
+ com.sun.star.frame.XController xController = xFrame.getController();
+ if ( xController != null ) {
+ com.sun.star.ui.XContextMenuInterception xContextMenuInterception =
+ (com.sun.star.ui.XContextMenuInterception)UnoRuntime.queryInterface(
+ com.sun.star.ui.XContextMenuInterception.class, xController );
+ if( xContextMenuInterception != null ) {
+ ContextMenuInterceptor aContextMenuInterceptor = new ContextMenuInterceptor();
+ com.sun.star.ui.XContextMenuInterceptor xContextMenuInterceptor =
+ (com.sun.star.ui.XContextMenuInterceptor)UnoRuntime.queryInterface(
+ com.sun.star.ui.XContextMenuInterceptor.class, aContextMenuInterceptor );
+ xContextMenuInterception.registerContextMenuInterceptor( xContextMenuInterceptor );
+
+ System.out.println( "\n ... all context menus of the created document frame contains now a 'Help' entry with the\n submenus 'Content', 'Help Agent' and 'Tips'.\n\nPress 'Return' to remove the context menu interceptor and finish the example!");
+
+ java.io.BufferedReader reader
+ = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
+ reader.read();
+
+ xContextMenuInterception.releaseContextMenuInterceptor(
+ xContextMenuInterceptor );
+ System.out.println( " ... context menu interceptor removed!" );
+ }
+ }
+
+ // close test document
+ com.sun.star.util.XCloseable xCloseable = (com.sun.star.util.XCloseable)
+ UnoRuntime.queryInterface(com.sun.star.util.XCloseable.class,
+ xComponent );
+
+ if (xCloseable != null ) {
+ xCloseable.close(false);
+ } else
+ {
+ xComponent.dispose();
+ }
+ }
+ catch ( com.sun.star.uno.RuntimeException ex ) {
+ // something strange has happend!
+ System.out.println( " Sample caught exception! " + ex );
+ System.exit(1);
+ }
+ catch ( java.lang.Exception ex ) {
+ // catch java exceptions and do something useful
+ System.out.println( " Sample caught exception! " + ex );
+ System.exit(1);
+ }
+
+ System.out.println(" ... exit!\n");
+ System.exit( 0 );
+ }
+
+ /**
+ *Description of the Method
+ *
+ *@param args Description of Parameter
+ *@since
+ */
+ public ContextMenuInterceptorAction notifyContextMenuExecute(
+ com.sun.star.ui.ContextMenuExecuteEvent aEvent ) throws RuntimeException {
+
+ try {
+
+ // Retrieve context menu container and query for service factory to
+ // create sub menus, menu entries and separators
+ com.sun.star.container.XIndexContainer xContextMenu = aEvent.ActionTriggerContainer;
+ com.sun.star.lang.XMultiServiceFactory xMenuElementFactory =
+ (com.sun.star.lang.XMultiServiceFactory)UnoRuntime.queryInterface(
+ com.sun.star.lang.XMultiServiceFactory.class, xContextMenu );
+ if ( xMenuElementFactory != null ) {
+ // create root menu entry and sub menu
+ com.sun.star.beans.XPropertySet xRootMenuEntry =
+ (XPropertySet)UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class,
+ xMenuElementFactory.createInstance( "com.sun.star.ui.ActionTrigger" ));
+
+ // create a line separator for our new help sub menu
+ com.sun.star.beans.XPropertySet xSeparator =
+ (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class,
+ xMenuElementFactory.createInstance( "com.sun.star.ui.ActionTriggerSeparator" ));
+
+ Short aSeparatorType = new Short( ActionTriggerSeparatorType.LINE );
+ xSeparator.setPropertyValue( "SeparatorType", (Object)aSeparatorType );
+
+ // query sub menu for index container to get access
+ com.sun.star.container.XIndexContainer xSubMenuContainer =
+ (com.sun.star.container.XIndexContainer)UnoRuntime.queryInterface(
+ com.sun.star.container.XIndexContainer.class,
+ xMenuElementFactory.createInstance(
+ "com.sun.star.ui.ActionTriggerContainer" ));
+
+ // intialize root menu entry
+ xRootMenuEntry.setPropertyValue( "Text", new String( "Help" ));
+ xRootMenuEntry.setPropertyValue( "CommandURL", new String( "slot:5410" ));
+ xRootMenuEntry.setPropertyValue( "HelpURL", new String( "5410" ));
+ xRootMenuEntry.setPropertyValue( "SubContainer", (Object)xSubMenuContainer );
+
+ // create menu entries for the new sub menu
+
+ // intialize help/content menu entry
+ XPropertySet xMenuEntry = (XPropertySet)UnoRuntime.queryInterface(
+ XPropertySet.class, xMenuElementFactory.createInstance(
+ "com.sun.star.ui.ActionTrigger" ));
+
+ xMenuEntry.setPropertyValue( "Text", new String( "Content" ));
+ xMenuEntry.setPropertyValue( "CommandURL", new String( "slot:5401" ));
+ xMenuEntry.setPropertyValue( "HelpURL", new String( "5401" ));
+
+ // insert menu entry to sub menu
+ xSubMenuContainer.insertByIndex( 0, (Object)xMenuEntry );
+
+ // intialize help/help agent
+ xMenuEntry = (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class,
+ xMenuElementFactory.createInstance(
+ "com.sun.star.ui.ActionTrigger" ));
+ xMenuEntry.setPropertyValue( "Text", new String( "Help Agent" ));
+ xMenuEntry.setPropertyValue( "CommandURL", new String( "slot:5962" ));
+ xMenuEntry.setPropertyValue( "HelpURL", new String( "5962" ));
+
+ // insert menu entry to sub menu
+ xSubMenuContainer.insertByIndex( 1, (Object)xMenuEntry );
+
+ // intialize help/tips
+ xMenuEntry = (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class,
+ xMenuElementFactory.createInstance(
+ "com.sun.star.ui.ActionTrigger" ));
+ xMenuEntry.setPropertyValue( "Text", new String( "Tips" ));
+ xMenuEntry.setPropertyValue( "CommandURL", new String( "slot:5404" ));
+ xMenuEntry.setPropertyValue( "HelpURL", new String( "5404" ));
+
+ // insert menu entry to sub menu
+ xSubMenuContainer.insertByIndex( 2, (Object)xMenuEntry );
+
+ // add separator into the given context menu
+ xContextMenu.insertByIndex( 0, (Object)xSeparator );
+
+ // add new sub menu into the given context menu
+ xContextMenu.insertByIndex( 0, (Object)xRootMenuEntry );
+
+ // The controller should execute the modified context menu and stop notifying other
+ // interceptors.
+ return com.sun.star.ui.ContextMenuInterceptorAction.EXECUTE_MODIFIED;
+ }
+ }
+ catch ( com.sun.star.beans.UnknownPropertyException ex ) {
+ // do something useful
+ // we used a unknown property
+ }
+ catch ( com.sun.star.lang.IndexOutOfBoundsException ex ) {
+ // do something useful
+ // we used an invalid index for accessing a container
+ }
+ catch ( com.sun.star.uno.Exception ex ) {
+ // something strange has happend!
+ }
+ catch ( java.lang.Exception ex ) {
+ // catch java exceptions and something useful
+ }
+
+ return com.sun.star.ui.ContextMenuInterceptorAction.IGNORED;
+ }
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/CustomizeView.java b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/CustomizeView.java
new file mode 100644
index 000000000000..1ba840286b95
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/CustomizeView.java
@@ -0,0 +1,304 @@
+/*************************************************************************
+ *
+ * $RCSfile: CustomizeView.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:37:25 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+// __________ Imports __________
+
+import com.sun.star.uno.UnoRuntime;
+
+import java.awt.*;
+import javax.swing.*;
+import java.lang.String;
+import java.awt.event.*;
+import java.awt.*;
+
+// __________ Implementation __________
+
+/**
+ * Makes it possible to change some states of currently loaded
+ * document (e.g. enable/disable menubar, toolbar, objectbar)
+ *
+ * @author Andreas Schl&uuml;ns
+ * @created 20.06.2002 09:28
+ */
+public class CustomizeView extends JPanel
+ implements IShutdownListener
+{
+ // ____________________
+ // const
+
+ /**
+ * These const URL's describe feature for toggling some properties of loaded document.
+ * Dispatch it with the corresponding parameter to the frame.
+ */
+ private static final String FEATUREURL_MENUBAR = "slot:6661" ;
+ private static final String FEATUREURL_TOOLBAR = "slot:5909" ;
+ private static final String FEATUREURL_OBJECTBAR = "slot:5905" ;
+
+ private static final String FEATUREPROP_MENUBAR = "MenuBarVisible" ;
+ private static final String FEATUREPROP_TOOLBAR = "ToolBarVisible" ;
+ private static final String FEATUREPROP_OBJECTBAR = "ObjectBarVisible" ;
+
+ private static final String ACTION_MENUBAR = "toogle_menu" ;
+ private static final String ACTION_TOOLBAR = "toogle_toolbar" ;
+ private static final String ACTION_OBJECTBAR = "toogle_objectbar" ;
+
+ private static final String MENUBAR_ON = "menubar on" ;
+ private static final String TOOLBAR_ON = "toolbar on" ;
+ private static final String OBJECTBAR_ON = "objectbar on" ;
+
+ private static final String MENUBAR_OFF = "menubar off" ;
+ private static final String TOOLBAR_OFF = "toolbar off" ;
+ private static final String OBJECTBAR_OFF = "objectbar off" ;
+
+ // ____________________
+ // member
+
+ /**
+ * @member m_cbMenuBar reference to checkbox for toggling menubar
+ * @member m_cbToolBar reference to checkbox for toggling toolbar
+ * @member m_cbObjectBar reference to checkbox for toggling objectbar
+ *
+ * @member m_aMenuBarListener listener for status events of the menu bar
+ * @member m_aToolBarListener listener for status events of the tool bar
+ * @member m_aObjectBarListener listener for status events of the object bar
+ */
+ private JCheckBox m_cbMenuBar ;
+ private JCheckBox m_cbToolBar ;
+ private JCheckBox m_cbObjectBar ;
+
+ private StatusListener m_aMenuBarListener ;
+ private StatusListener m_aToolBarListener ;
+ private StatusListener m_aObjectBarListener;
+
+ // ____________________
+
+ /**
+ * ctor
+ * Create view controls on startup and initialize it.
+ * We don't start listening here. see setFrame()!
+ */
+ CustomizeView()
+ {
+ this.setLayout(new GridLayout(3,0));
+
+ m_cbMenuBar = new JCheckBox(MENUBAR_OFF , false);
+ m_cbToolBar = new JCheckBox(TOOLBAR_OFF , false);
+ m_cbObjectBar = new JCheckBox(OBJECTBAR_OFF, false);
+
+ m_cbMenuBar.setEnabled (false);
+ m_cbToolBar.setEnabled (false);
+ m_cbObjectBar.setEnabled(false);
+
+ m_cbMenuBar.setActionCommand (ACTION_MENUBAR );
+ m_cbToolBar.setActionCommand (ACTION_TOOLBAR );
+ m_cbObjectBar.setActionCommand(ACTION_OBJECTBAR);
+
+ this.add(m_cbMenuBar );
+ this.add(m_cbToolBar );
+ this.add(m_cbObjectBar);
+ }
+
+ // ____________________
+
+ /**
+ * set new frame for this view
+ * We start listening for frame action/status and click events instandly.
+ * If an event occure we use it to synchronize our controls
+ * with states of a (my be) new document view of this frame.
+ *
+ * @param xFrame
+ * the reference to the frame, which provides the
+ * possibility to get the required status informations
+ *
+ * Attention: We don't accept new frames here.
+ * We get one after startup and work with him.
+ * That's it!
+ */
+ public void setFrame(com.sun.star.frame.XFrame xFrame)
+ {
+ if (xFrame==null)
+ return;
+
+ // be listener for click events
+ // They will toogle the UI controls.
+ ClickListener aMenuBarHandler = new ClickListener(FEATUREURL_MENUBAR ,FEATUREPROP_MENUBAR ,xFrame);
+ ClickListener aToolBarHandler = new ClickListener(FEATUREURL_TOOLBAR ,FEATUREPROP_TOOLBAR ,xFrame);
+ ClickListener aObjectBarHandler = new ClickListener(FEATUREURL_OBJECTBAR,FEATUREPROP_OBJECTBAR,xFrame);
+
+ m_cbMenuBar.addActionListener (aMenuBarHandler );
+ m_cbToolBar.addActionListener (aToolBarHandler );
+ m_cbObjectBar.addActionListener(aObjectBarHandler);
+
+ // be frame action listener
+ // The callback will update listener connections
+ // for status updates automaticly!
+ m_aMenuBarListener = new StatusListener(m_cbMenuBar ,MENUBAR_ON ,MENUBAR_OFF ,xFrame, FEATUREURL_MENUBAR );
+ m_aToolBarListener = new StatusListener(m_cbToolBar ,TOOLBAR_ON ,TOOLBAR_OFF ,xFrame, FEATUREURL_TOOLBAR );
+ m_aObjectBarListener = new StatusListener(m_cbObjectBar,OBJECTBAR_ON,OBJECTBAR_OFF,xFrame, FEATUREURL_OBJECTBAR);
+
+ m_aMenuBarListener.startListening();
+ m_aToolBarListener.startListening();
+ m_aObjectBarListener.startListening();
+ }
+
+ // ____________________
+
+ /**
+ * react for click events of the used check boxes
+ * We use our internal set dispatch objects to
+ * call it. This calls toogle the menu/object- or toolbar.
+ * Note: Because we are listener status events too - hopefully
+ * we get a notification, if toogling was successfully or not.
+ * We use this information to update our check boxes again.
+ * But such update doesn't force (hopefully) an action event. Otherwhise
+ * we can produce a never ending recursion!
+ *
+ * @param aEvent
+ * describes the used check box and his current state
+ * we can use to dispatch the right URL to the office
+ */
+ class ClickListener implements ActionListener,
+ com.sun.star.lang.XEventListener
+ {
+ /// URL, to toogle the requested UI item
+ String m_sURL;
+ /// name of the property which must be used in combination with the URL
+ String m_sProp;
+ /// we must use this frame to dispatch a request
+ com.sun.star.frame.XFrame m_xFrame;
+
+ //_____________________
+
+ /**
+ * ctor
+ * It initialize an instance of this clas only.
+ */
+ ClickListener( String sURL ,
+ String sProp ,
+ com.sun.star.frame.XFrame xFrame )
+ {
+ m_sURL = sURL ;
+ m_sProp = sProp ;
+ m_xFrame = xFrame;
+ }
+
+ //_____________________
+
+ /**
+ * callback for action events
+ * Such events occure if somehwere click the
+ * JCheckBox control on which we are registered.
+ * Such events doesn't occure if we set it programmaticly
+ * (e.g. if we get status events to -> see class StatusListener too)
+ *
+ * @param aEvent
+ * describes the check box and his state
+ * we can use to toogle the requested office
+ * ressource.
+ */
+ public void actionPerformed(ActionEvent aEvent)
+ {
+ synchronized(this)
+ {
+ if (m_xFrame==null)
+ return;
+ }
+
+ // define parameters for following dispatch
+ boolean bState = ((JCheckBox)aEvent.getSource()).isSelected();
+
+ // prepare the dispatch
+ com.sun.star.util.URL aURL = FunctionHelper.parseURL(m_sURL);
+ if (aURL==null)
+ return;
+
+ com.sun.star.beans.PropertyValue[] lProperties = new com.sun.star.beans.PropertyValue[1];
+ lProperties[0] = new com.sun.star.beans.PropertyValue();
+ lProperties[0].Name = m_sProp;
+ lProperties[0].Value = new Boolean(bState);
+
+ // execute (dispatch) it into the frame
+ if (m_xFrame==null)
+ return;
+ FunctionHelper.execute(m_xFrame,aURL,lProperties,null);
+ }
+
+ // ____________________
+
+ /**
+ * callback for disposing events
+ * Internaly we save a reference to an office frame.
+ * Of course he can die and inform us then. We should react
+ * and forget his reference.
+ *
+ * @param aEvent
+ * describes the source which fire this event
+ * Must be our internal saved frame. Otherwhise
+ * somewhere know us without a registration ...
+ */
+ public void disposing(com.sun.star.lang.EventObject aEvent)
+ {
+ synchronized(this)
+ {
+ m_xFrame = null;
+ }
+ }
+ }
+
+ // ____________________
+
+ /**
+ * If this java application shutdown - we must cancel all current existing
+ * listener connections. Otherwhise the office will run into some
+ * DisposedExceptions if it tries to use these forgotten listener references.
+ * And of course it can die doing that.
+ * We are registered at a central object to be informed if the VM will exit.
+ * So we can react.
+ */
+ public void shutdown()
+ {
+ m_aMenuBarListener.shutdown();
+ m_aToolBarListener.shutdown();
+ m_aObjectBarListener.shutdown();
+
+ m_aMenuBarListener = null;
+ m_aToolBarListener = null;
+ m_aObjectBarListener = null;
+ }
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Desk.java b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Desk.java
new file mode 100644
index 000000000000..42f47be0c1cd
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Desk.java
@@ -0,0 +1,102 @@
+/*************************************************************************
+ *
+ * $RCSfile: Desk.java,v $
+ *
+ * $Revision: 1.5 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:37:37 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+// __________ Imports __________
+
+import com.sun.star.uno.UnoRuntime;
+
+import java.lang.String;
+
+// __________ Implementation __________
+
+/**
+ * TODO
+ *
+ * @author Andreas Schl&uuml;ns
+ * @created 08.02.2002 14:05
+ */
+public class Desk
+{
+ // ____________________
+
+ /**
+ * main
+ * Establish connection to a remote office and starts the demo application.
+ * User can overwrite some of neccessary start options by using command line parameters.
+ *
+ * syntax: Desk [mode={inplace|outplace}] [file=<filename>]
+ *
+ * @param args command line arguments
+ * mode describe using mode of document view {inplace/outplace}
+ * default=inplace
+ * file name of first file which should be open
+ * default="private:factory/swriter" to open empty writer document
+ */
+ public static void main(String[] lArguments)
+ {
+ // Analyze command line parameters.
+ String sMode = new String("inplace");
+ String sFile = new String("private:factory/swriter");
+
+ for(int i=0; i<lArguments.length; ++i)
+ {
+ lArguments[i] = lArguments[i].toLowerCase();
+ if(lArguments[i].startsWith("mode=")==true)
+ sMode = lArguments[i].substring(5);
+ else
+ if(lArguments[i].startsWith("file=")==true)
+ sFile = lArguments[i].substring(5);
+ }
+
+ ViewContainer.mbInplace = (sMode.compareTo("inplace")==0);
+
+ // Connect to remote office.
+ OfficeConnect.createConnection();
+
+ // Create first document view.
+ // This one will register himself at the global
+ // ViewContainer. Further views will be open
+ // automaticly started from this first one.
+ DocumentView aView = new DocumentView();
+ aView.setVisible(true);
+ aView.createFrame();
+ aView.load(sFile);
+ }
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/DocumentView.java b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/DocumentView.java
new file mode 100644
index 000000000000..e0c7b2578898
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/DocumentView.java
@@ -0,0 +1,436 @@
+/*************************************************************************
+ *
+ * $RCSfile: DocumentView.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:37:50 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+// __________ Imports __________
+
+import com.sun.star.uno.UnoRuntime;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.lang.*;
+import java.net.*;
+import javax.swing.*;
+import javax.swing.border.*;
+import java.awt.AWTEvent;
+import java.awt.event.WindowEvent;
+
+// __________ Implementation __________
+
+/**
+ * This implement a java frame wich contains
+ * an office document, shows some status informations
+ * about that, provides simple functionality on it
+ * (e.g. toggle menubar, save document) and
+ * react for different situations independent
+ * (e.g. closing the document from outside).
+ * Every instance of this class will be a member
+ * inside the global "ViewContainer" of this java
+ * demo application which holds all opened views alive.
+ *
+ * @author Andreas Schl&uuml;ns
+ * @created 06.03.2002 09:38
+ */
+public class DocumentView extends JFrame
+ implements com.sun.star.lang.XEventListener, // react for Frame::disposing()
+ IShutdownListener // react for System.exit()
+{
+ // ____________________
+
+ /**
+ * const
+ * These command strings are used to identify a received action
+ * of buttons on which we listen for action events.
+ */
+ public static final String COMMAND_OPEN = "open" ;
+ public static final String COMMAND_SAVE = "save" ;
+ public static final String COMMAND_EXPORT = "export" ;
+ public static final String COMMAND_EXIT = "exit" ;
+
+ // ____________________
+
+ /**
+ * @member mxFrame office frame which contains the document of this view
+ *
+ * @member maStatusView special panel wich show available status informations of currently loaded document
+ * @member maDocumentView use JNI mechanism to plug an office window into our own java UI container (used for inplace mode only!)
+ * @member maCustomizeView special panel makes it possible to toggle menubar/toolbar or objectbar of loaded document
+ * @member maInterceptor interceptor thread which intercept "new" menu of office frame to open new frames inside this java application
+ *
+ * @member msName unique name of this view (returned by the global ViewContainer during registration)
+ *
+ * @member mbOpen button to open documents
+ * @member mbSave button to save currently loaded document
+ * @member mbExport button to save currently loaded document in HTML format (if it is possible!)
+ * @member mbExit button to exit this demo
+ *
+ * @member maInterception we try to intercept the file->new menu to open new document inside this java application
+ */
+ private com.sun.star.frame.XFrame mxFrame ;
+
+ private StatusView maStatusView ;
+ private NativeView maDocumentView ;
+ private CustomizeView maCustomizeView ;
+ private Interceptor maInterceptor ;
+
+ private String msName ;
+
+ private JButton mbtOpen ;
+ private JButton mbtSave ;
+ private JButton mbtExport ;
+ private JButton mbtExit ;
+
+ private boolean mbDead ;
+
+ // ____________________
+
+ /**
+ * ctor
+ * Create view controls on startup and initialize it with default values.
+ */
+ DocumentView()
+ {
+ this.setSize( new Dimension(800,600) );
+
+ JPanel paMainPanel = (JPanel)this.getContentPane();
+
+ // create and add command buttons to a panel
+ // it will be a sub panel of later layouted UI
+ mbtOpen = new JButton("Open ..." );
+ mbtSave = new JButton("Save" );
+ mbtExport = new JButton("Save as HTML ...");
+ mbtExit = new JButton("Exit" );
+
+ mbtOpen.setEnabled (true );
+ mbtSave.setEnabled (false);
+ mbtExport.setEnabled(false);
+ mbtExit.setEnabled (true );
+
+ mbtOpen.setActionCommand (COMMAND_OPEN );
+ mbtSave.setActionCommand (COMMAND_SAVE );
+ mbtExport.setActionCommand(COMMAND_EXPORT);
+ mbtExit.setActionCommand (COMMAND_EXIT );
+
+ Reactor aListener = new Reactor();
+ mbtOpen.addActionListener (aListener);
+ mbtSave.addActionListener (aListener);
+ mbtExport.addActionListener(aListener);
+ mbtExit.addActionListener (aListener);
+
+ JPanel paCommands = new JPanel( new GridLayout(4,0) );
+ paCommands.add(mbtOpen);
+ paCommands.add(mbtSave);
+ paCommands.add(mbtExport);
+ paCommands.add(mbtExit);
+
+ // create view to show status informations of opened file
+ maStatusView = new StatusView();
+
+ // create view for toggle different bar's of document
+ maCustomizeView = new CustomizeView();
+
+ paCommands.setBorder ( new TitledBorder(BorderFactory.createEtchedBorder(),"Commands") );
+ maStatusView.setBorder ( new TitledBorder(BorderFactory.createEtchedBorder(),"Status Informations") );
+ maCustomizeView.setBorder( new TitledBorder(BorderFactory.createEtchedBorder(),"Customize Document View") );
+
+ // layout the whole UI
+ JPanel paTest = new JPanel(new GridLayout(3,0));
+ paTest.add(paCommands );
+ paTest.add(maStatusView );
+ paTest.add(maCustomizeView);
+ JScrollPane paScroll = new JScrollPane();
+ paScroll.getViewport().add(paTest,null);
+
+ if(ViewContainer.mbInplace==true)
+ {
+ // create view to show opened documents
+ // This special view is neccessary for inplace mode only!
+ maDocumentView = new NativeView();
+
+ JSplitPane paSplit = new JSplitPane();
+ paSplit.setOneTouchExpandable( true );
+
+ paSplit.setLeftComponent (maDocumentView);
+ paSplit.setRightComponent(paScroll );
+
+ paMainPanel.add(paSplit);
+ }
+ else
+ {
+ paMainPanel.add(paScroll);
+ }
+
+ // Register this new view on our global view container.
+ msName = FunctionHelper.getUniqueFrameName();
+ this.setTitle(msName);
+ ViewContainer.getGlobalContainer().addView(this);
+ ViewContainer.getGlobalContainer().addListener(this);
+ // be listener for closing the application
+ this.enableEvents(AWTEvent.WINDOW_EVENT_MASK);
+ }
+
+ // ____________________
+
+ /**
+ * Create the view frame for showing the office documents on demand.
+ * Dependend from given command line parameter we create
+ * an office XFrame and initialize it with a window. This
+ * window can be a pure toolkit window (means toolkit of office!)
+ * or a plugged java canvas - office window combination.
+ */
+ public void createFrame()
+ {
+ // create view frame (as a XFrame!) here
+ // Look for right view mode setted by user command line parameter.
+ // First try to get a new unambigous frame name from our global ViewContainer.
+ if(ViewContainer.mbInplace==true)
+ {
+ // inplace document view can't be initialized without a visible parent window hierarchy!
+ // So make shure that we are visible in every case!
+ this.setVisible(true);
+ mxFrame = FunctionHelper.createViewFrame(msName,maDocumentView);
+ }
+ else
+ mxFrame = FunctionHelper.createViewFrame(msName,null);
+
+ if(mxFrame!=null)
+ {
+ // start interception
+ maInterceptor = new Interceptor(mxFrame);
+ maInterceptor.startListening();
+
+ // start listening for status events and actualization
+ // of our status view
+ // (of course for our CustomizeView too)
+ maStatusView.setFrame (mxFrame);
+ maCustomizeView.setFrame(mxFrame);
+
+ // be listener for closing the remote target view frame
+ com.sun.star.lang.XComponent xBroadcaster = (com.sun.star.lang.XComponent)UnoRuntime.queryInterface(
+ com.sun.star.lang.XComponent.class,
+ mxFrame);
+
+ if(xBroadcaster!=null)
+ xBroadcaster.addEventListener(this);
+ }
+ }
+
+ // ____________________
+
+ /**
+ * Different ways to load any URL from outside (may be by the command line)
+ * into this document view or to save it.
+ */
+ public void load(String sURL)
+ {
+ load(sURL,new com.sun.star.beans.PropertyValue[0]);
+ }
+
+ // ____________________
+
+ public void load(String sURL, com.sun.star.beans.PropertyValue[] lArguments)
+ {
+ com.sun.star.lang.XComponent xDocument = FunctionHelper.loadDocument(mxFrame,sURL,lArguments);
+ if(xDocument!=null)
+ {
+ mbtSave.setEnabled (true);
+ mbtExport.setEnabled(true);
+ }
+ else
+ {
+ mbtSave.setEnabled (false);
+ mbtExport.setEnabled(false);
+ }
+ }
+
+ // ____________________
+
+ public void save()
+ {
+ com.sun.star.frame.XController xController = mxFrame.getController();
+ if (xController==null)
+ return;
+ com.sun.star.frame.XModel xDocument = xController.getModel();
+ if (xDocument==null)
+ return;
+ FunctionHelper.saveDocument(xDocument);
+ }
+
+ // ____________________
+
+ public void exportHTML(String sURL)
+ {
+ com.sun.star.frame.XController xController = mxFrame.getController();
+ if (xController==null)
+ return;
+ com.sun.star.frame.XModel xDocument = xController.getModel();
+ if (xDocument==null)
+ return;
+ FunctionHelper.saveAsHTML(xDocument,sURL);
+ }
+
+ // ____________________
+
+ /**
+ * Overridden so we can react for window closing of this view.
+ */
+ protected void processWindowEvent(WindowEvent aEvent)
+ {
+ if (aEvent.getID()!=WindowEvent.WINDOW_CLOSING)
+ {
+ super.processWindowEvent(aEvent);
+ }
+ else
+ if (FunctionHelper.closeFrame(mxFrame))
+ {
+ mxFrame = null;
+ shutdown();
+ super.processWindowEvent(aEvent);
+ }
+ }
+
+ // ____________________
+
+ /**
+ * Here we can react for System.exit() normaly.
+ * But we use it for disposing() or windowClosing() too.
+ */
+ public void shutdown()
+ {
+ if (mbDead)
+ return;
+ mbDead=true;
+
+ // force these sub view to release her remote
+ // refrences too!
+ maStatusView.shutdown();
+ maCustomizeView.shutdown();
+
+ maStatusView = null;
+ maCustomizeView = null;
+
+ // disable all interceptions
+ maInterceptor.shutdown();
+ maInterceptor = null;
+
+ // close the frame and his document
+ // Relaesing of our listener connections for disposing()
+ // will be forced automaticly then. Because the frame
+ // will call us back ...
+ if (mxFrame!=null)
+ FunctionHelper.closeFrame(mxFrame);
+
+ // deregister this view in the global container
+ // Normaly we should die afterwards by garbage collection ...
+ // In cease this was the last view - it force a system.exit().
+ // But then we are no longer a member of the global container
+ // of possible shutdown listener ... and this method should be
+ // called again.
+ ViewContainer.getGlobalContainer().removeView(this);
+ }
+
+ // ____________________
+
+ /**
+ * callback from our internal saved frame
+ * which wish to die. Its not neccessary to remove listener connections
+ * here. Because the broadcaster do it automaticly.
+ * We have to release all references to him only.
+ *
+ * @param aSource
+ * describe the broadcaster of this event
+ * Must be our internal saved frame.
+ */
+ public void disposing(com.sun.star.lang.EventObject aSource)
+ {
+ mxFrame = null;
+ }
+
+ // ____________________
+
+ /**
+ * This inner class is used to react for events of our own UI controls.
+ * So we can start different actions then.
+ */
+ private class Reactor implements ActionListener
+ {
+ // ____________________
+
+ /**
+ * This method react for pressed buttons or selected check boxes.
+ */
+ public void actionPerformed(ActionEvent aEvent)
+ {
+ String sCommand = aEvent.getActionCommand();
+ //-----------------------------
+ // open any file from disk
+ if( sCommand.compareTo(COMMAND_OPEN) == 0 )
+ {
+ String sURL = FunctionHelper.askUserForFileURL(DocumentView.this,true);
+ if(sURL!=null)
+ DocumentView.this.load(sURL);
+ }
+ else
+ //-----------------------------
+ // save current document
+ if( sCommand.compareTo(COMMAND_SAVE) == 0 )
+ {
+ DocumentView.this.save();
+ }
+ else
+ //-----------------------------
+ // export current document to html
+ if( sCommand.compareTo(COMMAND_EXPORT) == 0 )
+ {
+ String sURL = FunctionHelper.askUserForFileURL(DocumentView.this,false);
+ if(sURL!=null)
+ DocumentView.this.exportHTML(sURL);
+ }
+ else
+ //-----------------------------
+ // exit application
+ if( sCommand.compareTo(COMMAND_EXIT) == 0 )
+ {
+ // This will force deleting of this and
+ // all other currently opened views automaticly!
+ System.exit(0);
+ }
+ }
+ }
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/FunctionHelper.java b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/FunctionHelper.java
new file mode 100644
index 000000000000..6f0454c79fba
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/FunctionHelper.java
@@ -0,0 +1,1066 @@
+/*************************************************************************
+ *
+ * $RCSfile: FunctionHelper.java,v $
+ *
+ * $Revision: 1.5 $
+ *
+ * last change: $Author: kz $ $Date: 2005-03-01 12:09:15 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+// __________ Imports __________
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.AnyConverter;
+
+import java.lang.*;
+import java.awt.*;
+import javax.swing.*;
+import java.io.*;
+import java.net.*;
+
+// __________ Implementation __________
+
+/**
+ * Is a collection of basic features.
+ * This helper shows different functionality of framework api
+ * in an example manner. You can use the follow ones:
+ * (1) parse URL's
+ * (2) create frames (inside/outside a java application)
+ * (3) dispatches (with[out] notifications)
+ * (4) loading/saving documents
+ * (5) convert documents to HTML (if possible)
+ * (6) close documents (and her frames) correctly
+ *
+ * There exist some other helper functionality too, which
+ * doesn't use or demonstrate the office api:
+ * (a) getting file names by using a file chosser
+ *
+ * @author Andreas Schl&uuml;ns
+ * @created 28.02.2002 15:31
+ */
+public class FunctionHelper
+{
+ // ____________________
+
+ /**
+ * This convert an URL (formated as a string) to a struct com.sun.star.util.URL.
+ * It use a special service to do that: the URLTransformer.
+ * Because some API calls need it and it's not allowed to set "Complete"
+ * part of the util struct only. The URL must be parsed.
+ *
+ * @param sURL
+ * URL for parsing in string notation
+ *
+ * @return [com.sun.star.util.URL]
+ * URL in UNO struct notation
+ */
+ public static com.sun.star.util.URL parseURL(String sURL)
+ {
+ com.sun.star.util.URL aURL = null;
+
+ if (sURL==null || sURL.equals(""))
+ {
+ System.out.println("wrong using of URL parser");
+ return null;
+ }
+
+ try
+ {
+ com.sun.star.uno.XComponentContext xOfficeCtx =
+ OfficeConnect.getOfficeContext();
+
+ // Create special service for parsing of given URL.
+ com.sun.star.util.XURLTransformer xParser =
+ (com.sun.star.util.XURLTransformer)UnoRuntime.queryInterface(
+ com.sun.star.util.XURLTransformer.class,
+ xOfficeCtx.getServiceManager().createInstanceWithContext(
+ "com.sun.star.util.URLTransformer", xOfficeCtx));
+
+ // Because it's an in/out parameter we must use an array of URL objects.
+ com.sun.star.util.URL[] aParseURL = new com.sun.star.util.URL[1];
+ aParseURL[0] = new com.sun.star.util.URL();
+ aParseURL[0].Complete = sURL;
+
+ // Parse the URL
+ xParser.parseStrict(aParseURL);
+
+ aURL = aParseURL[0];
+ }
+ catch(com.sun.star.uno.RuntimeException exRuntime)
+ {
+ // Any UNO method of this scope can throw this exception.
+ // Reset the return value only.
+ aURL = null;
+ }
+ catch(com.sun.star.uno.Exception exUno)
+ {
+ // "createInstance()" method of used service manager can throw it.
+ // Then it wasn't possible to get the URL transformer.
+ // Return default instead of realy parsed URL.
+ aURL = null;
+ }
+
+ return aURL;
+ }
+
+ // ____________________
+
+ /**
+ * create a new empty target frame
+ * Attention: Currently we must use special service com.sun.star.frame.Task instead of Frame.
+ * Because desktop environment accept this special frame type only as direct children.
+ * Note - This service will be deprecated and must be replaces by com.sun.star.frame.Frame in
+ * further versions. To feature prove we use both service names. If for new versions
+ * the deprecated one not exist we get an empty frame, we can try to use the new service.
+ *
+ * @param xSMGR
+ * we nee the remote service manager to create this task/frame service
+ *
+ * @return [com.sun.star.frame.XFrame]
+ * the new created frame reference in case of success or null otherwhise
+ */
+ private static com.sun.star.frame.XFrame impl_createEmptyFrame(
+ com.sun.star.uno.XComponentContext xCtx )
+ {
+ com.sun.star.frame.XFrame xFrame = null;
+
+ try{
+ xFrame = (com.sun.star.frame.XFrame)UnoRuntime.queryInterface(
+ com.sun.star.frame.XFrame.class,
+ xCtx.getServiceManager().createInstanceWithContext(
+ "com.sun.star.frame.Task", xCtx));
+ } catch(com.sun.star.uno.Exception ex1) {}
+
+ if (xFrame==null)
+ {
+ try{
+ xFrame = (com.sun.star.frame.XFrame)UnoRuntime.queryInterface(
+ com.sun.star.frame.XFrame.class,
+ xCtx.getServiceManager().createInstanceWithContext(
+ "com.sun.star.frame.Frame", xCtx));
+ } catch(com.sun.star.uno.Exception ex2) {}
+ }
+
+ return xFrame;
+ }
+
+ // ____________________
+
+ /**
+ * create a new window which can be used as container window of an office frame
+ * We know two modes for creation:
+ * - the office window will be a child of one of our java windows
+ * - the office will be a normal system window outside this java application
+ * This behaviour will be regulated by the second parameter of this operation.
+ * If a parentview is given the first mode will be activated - otherwhise
+ * the second one.
+ *
+ * Note: First mode (creation of a child window) can be reached by two different
+ * ways.
+ * - pack the required window handle of our java window inside an UNO object
+ * to transport it to the remote office toolkit and get a child office
+ * window.
+ * This is the old way. It's better to use the second one - but to be
+ * future prove this old one should be tried too.
+ * - it's possible to pass the native window handle directly to the toolkit.
+ * A special interface method was enabled to accept that.
+ *
+ * The right way to create an office window should be then:
+ * - try to use second creation mode (directly using of the window handle)
+ * - if it failed ... use the old way by packing the handle inside an object
+ *
+ * @param xSMGR
+ * we need a service manager to be able to create remote office
+ * services
+ *
+ * @param aParentView
+ * the java window as parent for the office window if an inplace office
+ * is required. If it is set to null the created office window will be
+ * a normal system window outside of our java application.
+ *
+ * @return [com.sun.star.awt.XWindow]
+ * The new created office window which can be used to set it as
+ * a ContainerWindow on an empty office frame.
+ */
+ private static com.sun.star.awt.XWindow impl_createWindow(
+ com.sun.star.uno.XComponentContext xCtx, NativeView aParentView )
+ {
+ com.sun.star.awt.XWindow xWindow = null;
+ com.sun.star.awt.XWindowPeer xPeer = null;
+ com.sun.star.awt.XToolkit xToolkit = null;
+
+ // get access to toolkit of remote office to create the container window of
+ // new target frame
+ try{
+ xToolkit = (com.sun.star.awt.XToolkit)UnoRuntime.queryInterface(
+ com.sun.star.awt.XToolkit.class,
+ xCtx.getServiceManager().createInstanceWithContext(
+ "com.sun.star.awt.Toolkit", xCtx));
+ }
+ catch(com.sun.star.uno.Exception ex)
+ {
+ return null;
+ }
+
+ // mode 1) create an external system window
+ if (aParentView==null)
+ {
+ // Describe the properties of the container window.
+ com.sun.star.awt.WindowDescriptor aDescriptor =
+ new com.sun.star.awt.WindowDescriptor();
+ aDescriptor.Type = com.sun.star.awt.WindowClass.TOP;
+ aDescriptor.WindowServiceName = "window";
+ aDescriptor.ParentIndex = -1;
+ aDescriptor.Parent = null;
+ aDescriptor.Bounds = new com.sun.star.awt.Rectangle(0,0,0,0);
+ aDescriptor.WindowAttributes = com.sun.star.awt.WindowAttribute.BORDER |
+ com.sun.star.awt.WindowAttribute.MOVEABLE |
+ com.sun.star.awt.WindowAttribute.SIZEABLE |
+ com.sun.star.awt.WindowAttribute.CLOSEABLE;
+
+ try{
+ xPeer = xToolkit.createWindow( aDescriptor );
+ } catch(com.sun.star.lang.IllegalArgumentException exIllegal) {}
+ }
+ // mode 2) create an internal office window as child of our given java
+ // parent window
+ else
+ {
+ // try new version of creation first: directly using of the window
+ // handle. The old implementation of the corresponding toolkit method
+ // requires a process ID. If this id isn't the right one a null object
+ // is returned. But normaly nobody outside the office knows this id.
+ // New version of this method ignore the id parameter and creation will
+ // work.
+ // Note: You must be shure if your window handle can be realy used by
+ // the remote office. Means if this java client and the remote office
+ // use the same display!
+ com.sun.star.awt.XSystemChildFactory xChildFactory =
+ (com.sun.star.awt.XSystemChildFactory)UnoRuntime.queryInterface(
+ com.sun.star.awt.XSystemChildFactory.class, xToolkit);
+
+ try
+ {
+ Integer nHandle = aParentView.getHWND();
+ short nSystem = (short)aParentView.getNativeWindowSystemType();
+ byte[] lProcID = new byte[0];
+
+ xPeer = xChildFactory.createSystemChild((Object)nHandle,
+ lProcID, nSystem);
+
+ if (xPeer==null)
+ {
+ // mode 3) OK - new version doesn't work. It requires the
+ // process id which we doesn't have.
+ // So we must use the old way to get the right window peer.
+ // Pack the handle inside a wrapper object.
+ JavaWindowPeerFake aWrapper = new
+ JavaWindowPeerFake(aParentView);
+
+ com.sun.star.awt.XWindowPeer xParentPeer =
+ (com.sun.star.awt.XWindowPeer)UnoRuntime.queryInterface(
+ com.sun.star.awt.XWindowPeer.class, aWrapper);
+
+ com.sun.star.awt.WindowDescriptor aDescriptor =
+ new com.sun.star.awt.WindowDescriptor();
+ aDescriptor.Type = com.sun.star.awt.WindowClass.TOP;
+ aDescriptor.WindowServiceName = "workwindow";
+ aDescriptor.ParentIndex = 1;
+ aDescriptor.Parent = xParentPeer;
+ aDescriptor.Bounds = new com.sun.star.awt.Rectangle(0,0,0,0);
+ if (nSystem == com.sun.star.lang.SystemDependent.SYSTEM_WIN32)
+ aDescriptor.WindowAttributes =
+ com.sun.star.awt.WindowAttribute.SHOW;
+ else
+ aDescriptor.WindowAttributes =
+ com.sun.star.awt.WindowAttribute.SYSTEMDEPENDENT;
+
+ try{
+ xPeer = xToolkit.createWindow( aDescriptor );
+ } catch(com.sun.star.lang.IllegalArgumentException exIllegal) {}
+ }
+ }
+ catch(java.lang.RuntimeException exJRun)
+ {
+ // This exception is thrown by the native JNI code if it try to get
+ // the systemw window handle. A possible reason can be an invisible
+ // java window. In this case it should be enough to set return
+ // values to null. All other ressources (which was created before)
+ // will be freed automaticly if scope wil be leaved.
+ System.out.println("May be the NativeView object wasn't realy visible at calling time of getNativeWindow()?");
+ xPeer = null;
+ xWindow = null;
+ }
+ }
+
+ // It doesn't matter which way was used to get the window peer.
+ // Cast it to the right return interface and return it.
+ xWindow = (com.sun.star.awt.XWindow)UnoRuntime.queryInterface(
+ com.sun.star.awt.XWindow.class,
+ xPeer);
+
+ return xWindow;
+ }
+
+ // ____________________
+
+ /**
+ * This method create a new empty child frame on desktop instance of remote office.
+ * It use a special JNI functionality to pass the office XWindow over a java window.
+ * This java window can be inserted into another java window container for complex layouting.
+ * If this parent java window isn't used, a top level system window will be created.
+ * The the resulting office frame isn't plugged into this java application.
+ *
+ * @param sName
+ * name to set it on the new created frame
+ *
+ * @param aParentView
+ * java window which should be used as parent window of new created office frame window
+ * May be set to null.
+ *
+ * @return [com.sun.star.frame.XFrame]
+ * reference to the new created frame for success or null if it failed
+ */
+ public static com.sun.star.frame.XFrame createViewFrame(String sName, NativeView aParentView)
+ {
+ com.sun.star.frame.XFrame xFrame = null;
+
+ try
+ {
+ com.sun.star.uno.XComponentContext xCtx =
+ OfficeConnect.getOfficeContext();
+
+ // create an empty office frame first
+ xFrame = impl_createEmptyFrame(xCtx);
+
+ // create an office window then
+ // Depending from the given parameter aParentView it will be a child or a top level
+ // system window. (see impl method for further informations)
+ // But before we call this helper - prepare the possible parent window: show it.
+ // JNI calls to get system window handle of java window can't work without that!
+ if (aParentView!=null)
+ aParentView.setVisible(true);
+ com.sun.star.awt.XWindow xWindow = impl_createWindow(xCtx, aParentView);
+
+ // pass the window the frame as his new container window.
+ // It's neccessary to do it first - before you call anything else there.
+ // Otherwhise the frame throws some exceptions for "uninitialized state".
+ xFrame.initialize( xWindow );
+
+ // Insert the new frame in desktop hierarchy.
+ // Use XFrames interface to do so. It provides access to the child frame container of that instance.
+ com.sun.star.frame.XFramesSupplier xTreeRoot = (com.sun.star.frame.XFramesSupplier)UnoRuntime.queryInterface(
+ com.sun.star.frame.XFramesSupplier.class,
+ xCtx.getServiceManager().createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xCtx));
+ com.sun.star.frame.XFrames xChildContainer = xTreeRoot.getFrames();
+ xChildContainer.append(xFrame);
+
+ // Make some further initializations on frame and window.
+ xWindow.setVisible(true);
+ xFrame.setName(sName);
+ }
+ catch(com.sun.star.uno.RuntimeException exRuntime)
+ {
+ // Any UNO method of this scope can throw this exception.
+ // So the frame can be already created and he must be freed
+ // correctly. May be he was inserted into the desktop tree too ...
+ if(xFrame!=null)
+ {
+ // Try to dispose the frame. He should deregister himself at the desktop object
+ // and free all internal used ressources (e.g. the container window) automaticly.
+ // It's possible to do that here - because frame has no component inside yet.
+ // So nobody can disagree with that.
+ // After the dispose() call forget all references to this frame and let him die.
+ // If a new exception will occure ... no generell solution exist then.
+ // Nobody can guarantee if next call will work or not.
+ com.sun.star.lang.XComponent xComponent = (com.sun.star.lang.XComponent)UnoRuntime.queryInterface(
+ com.sun.star.lang.XComponent.class,
+ xFrame);
+ xComponent.dispose();
+ xComponent = null;
+ xFrame = null;
+ }
+ }
+ catch(com.sun.star.uno.Exception exUno)
+ {
+ // "createInstance()" method of used service manager can throw it.
+ // If it occured during creation of desktop service the frame already was created.
+ // Free it by decresing his refcount. Changes on the desktop tree couldn't exist.
+ // Without the desktop service that wasn't possible. So no further rollbacks must follow.
+ if(xFrame!=null)
+ {
+ com.sun.star.lang.XComponent xComponent = (com.sun.star.lang.XComponent)UnoRuntime.queryInterface(
+ com.sun.star.lang.XComponent.class,
+ xFrame);
+ xComponent.dispose();
+ xComponent = null;
+ xFrame = null;
+ }
+ }
+
+ return xFrame;
+ }
+
+ // ____________________
+
+ /**
+ * Dispatch an URL to given frame.
+ * Caller can register himself for following status events for dispatched
+ * URL too. But nobody guarantee that such notifications will occure.
+ * (see dispatchWithNotification() if you interest on that)
+ * The returned dispatch object should be hold alive by caller
+ * till he deosn't need it any longer. Otherwise the dispatcher can(!)
+ * die by decreasing his refcount.
+ *
+ * @param xFrame frame wich should be the target of this dispatch
+ * @param aURL full parsed and converted office URL for dispatch
+ * @param lProperties optional arguments for dispatch
+ * @param xListener optional listener which is registered automaticly for status events
+ * (Note: Deregistration is part of this listener himself!)
+ *
+ * @return [XDispatch] It's the used dispatch object and can be used for deregistration of an optional listener.
+ * Otherwhise caller can ignore it.
+ */
+ public static com.sun.star.frame.XDispatch execute(com.sun.star.frame.XFrame xFrame ,
+ com.sun.star.util.URL aURL ,
+ com.sun.star.beans.PropertyValue[] lProperties,
+ com.sun.star.frame.XStatusListener xListener )
+ {
+ com.sun.star.frame.XDispatch xDispatcher = null;
+
+ try
+ {
+ // Query the frame for right interface which provides access to all available dispatch objects.
+ com.sun.star.frame.XDispatchProvider xProvider = (com.sun.star.frame.XDispatchProvider)UnoRuntime.queryInterface(
+ com.sun.star.frame.XDispatchProvider.class,
+ xFrame);
+
+ // Ask himn for right dispatch object for given URL.
+ // Force given frame as target for following dispatch by using "".
+ // It means the same like "_self".
+ xDispatcher = xProvider.queryDispatch(aURL,"",0);
+
+ // Dispatch the URL into the frame.
+ if(xDispatcher!=null)
+ {
+ if(xListener!=null)
+ xDispatcher.addStatusListener(xListener,aURL);
+
+ xDispatcher.dispatch(aURL,lProperties);
+ }
+ }
+ catch(com.sun.star.uno.RuntimeException exUno)
+ {
+ // Any UNO method of this scope can throw this exception.
+ // But there will be nothing to do then - because
+ // we haven't changed anything inside the remote objects
+ // except method "addStatusListener().
+ // But in this case the source of this exception has to
+ // rollback all his operations. There is no chance to
+ // make anything right then.
+ // Reset the return value to a default - that's it.
+ exUno.printStackTrace();
+ xDispatcher = null;
+ }
+
+ return xDispatcher;
+ }
+
+ // ____________________
+
+ /**
+ * Dispatch an URL to given frame.
+ * Caller can register himself for following result events for dispatched
+ * URL too. Notifications are guaranteed (instead of dispatch())
+ * Returning of the dispatch object isn't neccessary.
+ * Nobody must hold it alive longer the dispatch needs.
+ *
+ * @param xFrame frame wich should be the target of this dispatch
+ * @param aURL full parsed and converted office URL for dispatch
+ * @param lProperties optional arguments for dispatch
+ * @param xListener optional listener which is registered automaticly for status events
+ * (Note: Deregistration is not supported. Dispatcher does it automaticly.)
+ */
+ public static void executeWithNotification(com.sun.star.frame.XFrame xFrame ,
+ com.sun.star.util.URL aURL ,
+ com.sun.star.beans.PropertyValue[] lProperties,
+ com.sun.star.frame.XDispatchResultListener xListener )
+ {
+ try
+ {
+ // Query the frame for right interface which provides access to all available dispatch objects.
+ com.sun.star.frame.XDispatchProvider xProvider = (com.sun.star.frame.XDispatchProvider)UnoRuntime.queryInterface(
+ com.sun.star.frame.XDispatchProvider.class,
+ xFrame);
+
+ // Ask himn for right dispatch object for given URL.
+ // Force THIS frame as target for following dispatch.
+ // Attention: The interface XNotifyingDispatch is an optional one!
+ com.sun.star.frame.XDispatch xDispatcher = xProvider.queryDispatch(aURL,"",0);
+ com.sun.star.frame.XNotifyingDispatch xNotifyingDispatcher = (com.sun.star.frame.XNotifyingDispatch)UnoRuntime.queryInterface(
+ com.sun.star.frame.XNotifyingDispatch.class,
+ xDispatcher);
+
+ // Dispatch the URL.
+ if(xNotifyingDispatcher!=null)
+ xNotifyingDispatcher.dispatchWithNotification(aURL,lProperties,xListener);
+ }
+ catch(com.sun.star.uno.RuntimeException exUno)
+ {
+ // Any UNO method of this scope can throw this exception.
+ // But there is nothing we can do then.
+ exUno.printStackTrace();
+ }
+ }
+
+ // ____________________
+
+ /**
+ * Load document specified by an URL into given frame synchronously.
+ * The result of this operation will be the loaded document for success
+ * or null if loading failed.
+ *
+ * @param xFrame frame wich should be the target of this load call
+ * @param sURL unparsed URL for loading
+ * @param lProperties optional arguments
+ *
+ * @return [XComponent] the loaded document for success or null if it's failed
+ */
+ public static com.sun.star.lang.XComponent loadDocument(
+ com.sun.star.frame.XFrame xFrame, String sURL,
+ com.sun.star.beans.PropertyValue[] lProperties)
+ {
+ com.sun.star.lang.XComponent xDocument = null;
+ String sOldName = null;
+
+ try
+ {
+ com.sun.star.uno.XComponentContext xCtx =
+ OfficeConnect.getOfficeContext();
+
+ // First prepare frame for loading
+ // We must adress it inside the frame tree without any complications.
+ // So we set an unambigous (we hope it) name and use it later.
+ // Don't forget to reset original name after that.
+ sOldName = xFrame.getName();
+ String sTarget = "odk_officedev_desk";
+ xFrame.setName(sTarget);
+
+ // Get access to the global component loader of the office
+ // for synchronous loading the document.
+ com.sun.star.frame.XComponentLoader xLoader =
+ (com.sun.star.frame.XComponentLoader)UnoRuntime.queryInterface(
+ com.sun.star.frame.XComponentLoader.class,
+ xCtx.getServiceManager().createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xCtx));
+
+ // Load the document into the target frame by using his name and
+ // special search flags.
+ xDocument = xLoader.loadComponentFromURL(
+ sURL,
+ sTarget,
+ com.sun.star.frame.FrameSearchFlag.CHILDREN,
+ lProperties);
+
+ // dont forget to restore old frame name ...
+ xFrame.setName(sOldName);
+ }
+ catch(com.sun.star.io.IOException exIO)
+ {
+ // Can be thrown by "loadComponentFromURL()" call.
+ // The only thing we should do then is to reset changed frame name!
+ exIO.printStackTrace();
+ xDocument = null;
+ if(sOldName!=null)
+ xFrame.setName(sOldName);
+ }
+ catch(com.sun.star.lang.IllegalArgumentException exIllegal)
+ {
+ // Can be thrown by "loadComponentFromURL()" call.
+ // The only thing we should do then is to reset changed frame name!
+ exIllegal.printStackTrace();
+ xDocument = null;
+ if(sOldName!=null)
+ xFrame.setName(sOldName);
+ }
+ catch(com.sun.star.uno.RuntimeException exRuntime)
+ {
+ // Any UNO method of this scope can throw this exception.
+ // The only thing we can try(!) is to reset changed frame name.
+ exRuntime.printStackTrace();
+ xDocument = null;
+ if(sOldName!=null)
+ xFrame.setName(sOldName);
+ }
+ catch(com.sun.star.uno.Exception exUno)
+ {
+ // "createInstance()" method of used service manager can throw it.
+ // The only thing we should do then is to reset changed frame name!
+ exUno.printStackTrace();
+ xDocument = null;
+ if(sOldName!=null)
+ xFrame.setName(sOldName);
+ }
+
+ return xDocument;
+ }
+
+ // ____________________
+
+ /**
+ * Save currently loaded document of given frame.
+ *
+ * @param xDocument document for saving changes
+ */
+ public static void saveDocument(com.sun.star.lang.XComponent xDocument)
+ {
+ try
+ {
+ // Check for supported model functionality.
+ // Normaly the application documents (text, spreadsheet ...) do so
+ // but some other ones (e.g. db components) doesn't do that.
+ // They can't be save then.
+ com.sun.star.frame.XModel xModel = (com.sun.star.frame.XModel)UnoRuntime.queryInterface(
+ com.sun.star.frame.XModel.class,
+ xDocument);
+ if(xModel!=null)
+ {
+ // Check for modifications => break save process if there is nothing to do.
+ com.sun.star.util.XModifiable xModified = (com.sun.star.util.XModifiable)UnoRuntime.queryInterface(
+ com.sun.star.util.XModifiable.class,
+ xModel);
+ if(xModified.isModified()==true)
+ {
+ com.sun.star.frame.XStorable xStore = (com.sun.star.frame.XStorable)UnoRuntime.queryInterface(
+ com.sun.star.frame.XStorable.class,
+ xModel);
+
+ xStore.store();
+ }
+ }
+ }
+ catch(com.sun.star.io.IOException exIO)
+ {
+ // Can be thrown by "store()" call.
+ // But there is nothing we can do then.
+ exIO.printStackTrace();
+ }
+ catch(com.sun.star.uno.RuntimeException exUno)
+ {
+ // Any UNO method of this scope can throw this exception.
+ // But there is nothing we can do then.
+ exUno.printStackTrace();
+ }
+ }
+
+ // ____________________
+
+ /**
+ * It try to export given document in HTML format.
+ * Current document will be converted to HTML and moved to new place on disk.
+ * A "new" file will be created by given URL (may be overwritten
+ * if it already exist). Right filter will be used automaticly if factory of
+ * this document support it. If no valid filter can be found for export,
+ * nothing will be done here.
+ *
+ * @param xDocument document which should be exported
+ * @param sURL target URL for converted document
+ */
+ public static void saveAsHTML(com.sun.star.lang.XComponent xDocument,
+ String sURL )
+ {
+ try
+ {
+ // First detect factory of this document.
+ // Ask for the supported service name of this document.
+ // If information is available it can be used to find out wich
+ // filter exist for HTML export. Normaly this filter should be searched
+ // inside the filter configuration but this little demo doesn't do so.
+ // (see service com.sun.star.document.FilterFactory for further
+ // informations too)
+ // Well known filter names are used directly. They must exist in current
+ // office installation. Otherwise this code will fail. But to prevent
+ // this code against missing filters it check for existing state of it.
+ com.sun.star.lang.XServiceInfo xInfo = (com.sun.star.lang.XServiceInfo)
+ UnoRuntime.queryInterface(com.sun.star.lang.XServiceInfo.class,
+ xDocument);
+
+ if(xInfo!=null)
+ {
+ // Find out possible filter name.
+ String sFilter = null;
+ if(xInfo.supportsService("com.sun.star.text.TextDocument")==true)
+ sFilter = new String("HTML (StarWriter)");
+ else
+ if(xInfo.supportsService("com.sun.star.text.WebDocument")==true)
+ sFilter = new String("HTML");
+ else
+ if(xInfo.supportsService("com.sun.star.sheet.SpreadsheetDocument")==true)
+ sFilter = new String("HTML (StarCalc)");
+
+ // Check for existing state of this filter.
+ if(sFilter!=null)
+ {
+ com.sun.star.uno.XComponentContext xCtx =
+ OfficeConnect.getOfficeContext();
+
+ com.sun.star.container.XNameAccess xFilterContainer =
+ (com.sun.star.container.XNameAccess)
+ UnoRuntime.queryInterface(
+ com.sun.star.container.XNameAccess.class,
+ xCtx.getServiceManager().createInstanceWithContext(
+ "com.sun.star.document.FilterFactory", xCtx));
+
+ if(xFilterContainer.hasByName(sFilter)==false)
+ sFilter=null;
+ }
+
+ // Use this filter for export.
+ if(sFilter!=null)
+ {
+ // Export can be forced by saving the document and using a
+ // special filter name which can write needed format. Build
+ // neccessary argument list now.
+ // Use special flag "Overwrite" too, to prevent operation
+ // against possible exceptions, if file already exist.
+ com.sun.star.beans.PropertyValue[] lProperties =
+ new com.sun.star.beans.PropertyValue[2];
+ lProperties[0] = new com.sun.star.beans.PropertyValue();
+ lProperties[0].Name = "FilterName";
+ lProperties[0].Value = sFilter;
+ lProperties[1] = new com.sun.star.beans.PropertyValue();
+ lProperties[1].Name = "Overwrite";
+ lProperties[1].Value = Boolean.TRUE;
+
+ com.sun.star.frame.XStorable xStore =
+ (com.sun.star.frame.XStorable)UnoRuntime.queryInterface(
+ com.sun.star.frame.XStorable.class, xDocument);
+
+ xStore.storeAsURL(sURL,lProperties);
+ }
+ }
+ }
+ catch(com.sun.star.io.IOException exIO)
+ {
+ // Can be thrown by "store()" call.
+ // Do nothing then. Saving failed - that's it.
+ exIO.printStackTrace();
+ }
+ catch(com.sun.star.uno.RuntimeException exRuntime)
+ {
+ // Can be thrown by any uno call.
+ // Do nothing here. Saving failed - that's it.
+ exRuntime.printStackTrace();
+ }
+ catch(com.sun.star.uno.Exception exUno)
+ {
+ // Can be thrown by "createInstance()" call of service manager.
+ // Do nothing here. Saving failed - that's it.
+ exUno.printStackTrace();
+ }
+ }
+
+ // ____________________
+
+ /**
+ * Try to close the document without any saving of modifications.
+ * We can try it only! Controller and/or model of this document
+ * can disagree with that. But mostly they doesn't do so.
+ *
+ * @param xDocument document which should be clcosed
+ */
+ public static void closeDocument(com.sun.star.lang.XComponent xDocument)
+ {
+ try
+ {
+ // Check supported functionality of the document (model or controller).
+ com.sun.star.frame.XModel xModel =
+ (com.sun.star.frame.XModel)UnoRuntime.queryInterface(
+ com.sun.star.frame.XModel.class, xDocument);
+
+ if(xModel!=null)
+ {
+ // It's a full featured office document.
+ // Reset the modify state of it and close it.
+ // Note: Model can disgree by throwing a veto exception.
+ com.sun.star.util.XModifiable xModify =
+ (com.sun.star.util.XModifiable)UnoRuntime.queryInterface(
+ com.sun.star.util.XModifiable.class, xModel);
+
+ xModify.setModified(false);
+ xDocument.dispose();
+ }
+ else
+ {
+ // It's a document which supports a controller .. or may by a pure
+ // window only. If it's at least a controller - we can try to
+ // suspend him. But - he can disagree with that!
+ com.sun.star.frame.XController xController =
+ (com.sun.star.frame.XController)UnoRuntime.queryInterface(
+ com.sun.star.frame.XController.class, xDocument);
+
+ if(xController!=null)
+ {
+ if(xController.suspend(true)==true)
+ {
+ // Note: Don't dispose the controller - destroy the frame
+ // to make it right!
+ com.sun.star.frame.XFrame xFrame = xController.getFrame();
+ xFrame.dispose();
+ }
+ }
+ }
+ }
+ catch(com.sun.star.beans.PropertyVetoException exVeto)
+ {
+ // Can be thrown by "setModified()" call on model.
+ // He disagree with our request.
+ // But there is nothing to do then. Following "dispose()" call wasn't
+ // never called (because we catch it before). Closing failed -that's it.
+ exVeto.printStackTrace();
+ }
+ catch(com.sun.star.lang.DisposedException exDisposed)
+ {
+ // If an UNO object was already disposed before - he throw this special
+ // runtime exception. Of course every UNO call must be look for that -
+ // but it's a question of error handling.
+ // For demonstration this exception is handled here.
+ exDisposed.printStackTrace();
+ }
+ catch(com.sun.star.uno.RuntimeException exRuntime)
+ {
+ // Every uno call can throw that.
+ // Do nothing - closing failed - that's it.
+ exRuntime.printStackTrace();
+ }
+ }
+
+ // ____________________
+
+ /**
+ * Try to close the frame instead of the document.
+ * It shows the possible interface to do so.
+ *
+ * @param xFrame
+ * frame which should be clcosed
+ *
+ * @return <TRUE/> in case frame could be closed
+ * <FALSE/> otherwise
+ */
+ public static boolean closeFrame(com.sun.star.frame.XFrame xFrame)
+ {
+ boolean bClosed = false;
+
+ try
+ {
+ // first try the new way: use new interface XCloseable
+ // It replace the deprecated XTask::close() and should be preferred ...
+ // if it can be queried.
+ com.sun.star.util.XCloseable xCloseable =
+ (com.sun.star.util.XCloseable)UnoRuntime.queryInterface(
+ com.sun.star.util.XCloseable.class, xFrame);
+ if (xCloseable!=null)
+ {
+ // We deliver the owner ship of this frame not to the (possible)
+ // source which throw a CloseVetoException. We whishto have it
+ // under our own control.
+ try
+ {
+ xCloseable.close(false);
+ bClosed = true;
+ }
+ catch( com.sun.star.util.CloseVetoException exVeto )
+ {
+ bClosed = false;
+ }
+ }
+ else
+ {
+ // OK: the new way isn't possible. Try the old one.
+ com.sun.star.frame.XTask xTask = (com.sun.star.frame.XTask)
+ UnoRuntime.queryInterface(com.sun.star.frame.XTask.class,
+ xFrame);
+ if (xTask!=null)
+ {
+ // return value doesn't interest here. Because
+ // we forget this task ...
+ bClosed = xTask.close();
+ }
+ }
+ }
+ catch (com.sun.star.lang.DisposedException exDisposed)
+ {
+ // Of course - this task can be already dead - means disposed.
+ // But for us it's not important. Because we tried to close it too.
+ // And "already disposed" or "closed" should be the same ...
+ bClosed = true;
+ }
+
+ return bClosed;
+ }
+
+ // ____________________
+
+ /**
+ * Try to find an unique frame name, which isn't currently used inside
+ * remote office instance. Because we create top level frames
+ * only, it's enough to check the names of existing child frames on the
+ * desktop only.
+ *
+ * @return [String]
+ * should represent an unique frame name, which currently isn't
+ * used inside the remote office frame tree
+ * (Couldn't guaranteed for a real multithreaded environment.
+ * But we try it ...)
+ */
+ private static final String BASEFRAMENAME = "Desk View ";
+
+ public static String getUniqueFrameName()
+ {
+ String sName = null;
+
+ com.sun.star.uno.XComponentContext xCtx = OfficeConnect.getOfficeContext();
+
+ try
+ {
+ com.sun.star.frame.XFramesSupplier xSupplier =
+ (com.sun.star.frame.XFramesSupplier)UnoRuntime.queryInterface(
+ com.sun.star.frame.XFramesSupplier.class,
+ xCtx.getServiceManager().createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xCtx));
+
+ com.sun.star.container.XIndexAccess xContainer =
+ (com.sun.star.container.XIndexAccess)UnoRuntime.queryInterface(
+ com.sun.star.container.XIndexAccess.class,
+ xSupplier.getFrames());
+
+ int nCount = xContainer.getCount();
+ for (int i=0; i<nCount; ++i )
+ {
+ com.sun.star.frame.XFrame xFrame = (com.sun.star.frame.XFrame)AnyConverter.toObject(new com.sun.star.uno.Type(com.sun.star.frame.XFrame.class), xContainer.getByIndex(i));
+ sName = new String(BASEFRAMENAME+mnViewCount);
+ while(sName.compareTo(xFrame.getName())==0)
+ {
+ ++mnViewCount;
+ sName = new String(BASEFRAMENAME+mnViewCount);
+ }
+ }
+ }
+ catch(com.sun.star.uno.Exception exCreateFailed)
+ {
+ sName = new String(BASEFRAMENAME);
+ }
+
+ if (sName==null)
+ {
+ System.out.println("invalid name!");
+ sName = new String(BASEFRAMENAME);
+ }
+
+ return sName;
+ }
+
+ // ____________________
+
+ /**
+ * helper to get a file URL selected by user
+ * This method doesn't show any API concepts ...
+ * but is neccessary rof this demo application.
+ *
+ * @param aParent parent window of this dialog
+ * @param bOpen If it is set to true =>
+ * dialog is opend in "file open" mode -
+ * otherwise in "file save" mode.
+ */
+ public static String askUserForFileURL(Component aParent,boolean bOpen)
+ {
+ String sFileURL = null;
+ int nDecision = JFileChooser.CANCEL_OPTION;
+ JFileChooser aChooser = null;
+
+ // set last visited directory on new file chosser
+ // (if this information is available)
+ if( maLastDir==null )
+ aChooser = new JFileChooser();
+ else
+ aChooser = new JFileChooser(maLastDir);
+
+ // decide between file open/save dialog
+ if( bOpen==true )
+ nDecision = aChooser.showOpenDialog(aParent);
+ else
+ nDecision = aChooser.showSaveDialog(aParent);
+
+ // react for "OK" result only
+ if(nDecision == JFileChooser.APPROVE_OPTION)
+ {
+ // save current directory as last visited one
+ maLastDir = aChooser.getCurrentDirectory();
+ // get file URL from the dialog
+ try
+ {
+ sFileURL = aChooser.getSelectedFile().toURL().toExternalForm();
+ }
+ catch( MalformedURLException ex )
+ {
+ ex.printStackTrace();
+ sFileURL = null;
+ }
+ // problem of java: file URL's are coded with 1 slash instead of 3 ones!
+ // => correct this problem first, otherwise office can't use these URL's
+ if(
+ ( sFileURL !=null ) &&
+ ( sFileURL.startsWith("file:/") ==true ) &&
+ ( sFileURL.startsWith("file://")==false )
+ )
+ {
+ StringBuffer sWorkBuffer = new StringBuffer(sFileURL);
+ sWorkBuffer.insert(6,"//");
+ sFileURL = sWorkBuffer.toString();
+ }
+ }
+
+ return sFileURL;
+ }
+
+ // ____________________
+
+ /**
+ * @member maLastDir save the last visited directory of used file open/save dialog
+ * @member mnViewCount we try to set unique names on every frame we create (that's why we must count it)
+ */
+ private static File maLastDir = null;
+ private static int mnViewCount = 0 ;
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/IOnewayLink.java b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/IOnewayLink.java
new file mode 100644
index 000000000000..d3fce206b3bb
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/IOnewayLink.java
@@ -0,0 +1,76 @@
+/*************************************************************************
+ *
+ * $RCSfile: IOnewayLink.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:38:16 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import java.util.Vector;
+
+// __________ Implementation __________
+
+/**
+ * We need a generic interface to forward any oneway uno interface method
+ * by using threads to the original object. Reason:
+ * It's not allowed to call synchronoues back to the office if a java object
+ * was called in a oneway declared interface method. Then it must be
+ * executed asynchronoues. To do so - a thread can be created which use this
+ * interface. It get the object, which whis to be called back and the type and
+ * parameter of the original request.
+ *
+ * @author Andreas Schl&uuml;ns
+ * @created 17.07.2002 08:09
+ */
+public interface IOnewayLink
+{
+ // _______________________________
+
+ /**
+ * @param nRequest
+ * The two user of this callback can define an unique number,
+ * which identify the type of original interface method. So the called
+ * interface object can decide, which action will be neccessary.
+ *
+ * @param lParams
+ * If the original method used parameters, they will be coded here in
+ * a generic way. Only the called interface object know (it depends
+ * from the original request - see nRequest too), how this list must
+ * be interpreted.
+ * Note: Atomic types (e.g. int, long) will be transported as objects
+ * too (Integer, Long)!
+ */
+ public abstract void execOneway( int nRequest, Vector lParams );
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/IShutdownListener.java b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/IShutdownListener.java
new file mode 100644
index 000000000000..71bd0b4b3cff
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/IShutdownListener.java
@@ -0,0 +1,53 @@
+/*************************************************************************
+ *
+ * $RCSfile: IShutdownListener.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:38:31 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+// __________ Implementation __________
+
+/**
+ * Listener interface to get information about application shutdown
+ * if java virtual machine dies.
+ *
+ * @author Andreas Schl&uuml;ns
+ * @created 03.05.2002 13:51
+ */
+public interface IShutdownListener
+{
+ public abstract void shutdown();
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Install.txt b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Install.txt
new file mode 100644
index 000000000000..fc7c95afbb98
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Install.txt
@@ -0,0 +1,10 @@
+(1) goto "./nativelib/<platform>" directory and build it
+(2) build this directory
+(3) expand your class path to include all jar files of an office installation
+ (means all files in path "<officeinst>/program/classes")
+(4) goto "api/<platform>/class"
+(5) copy from an existing java installation the runtime library "jawt" (e.g. jawt.dll for windows)
+ into this directory
+(6) copy "api/<platform>/bin/nativelib.dll" (for windows) to "api/<platform>/class"
+(7) start an office : "soffice -accept=socket,host=localhost,port=2083;urp;"
+(8) goto "api/<platform>/class" and start java applet: "java -jar desktop.jar"
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Interceptor.java b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Interceptor.java
new file mode 100644
index 000000000000..5865c65c2463
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Interceptor.java
@@ -0,0 +1,678 @@
+/*************************************************************************
+ *
+ * $RCSfile: Interceptor.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:38:44 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+// __________ Imports __________
+
+import com.sun.star.uno.UnoRuntime;
+
+import java.lang.*;
+import javax.swing.*;
+import java.util.Vector;
+
+// __________ Implementation __________
+
+/**
+ * This class can be used to intercept dispatched URL's
+ * on any frame used in this demo application.
+ * It intercept all URL's wich try to create a new empty frame.
+ * (e.g. "private:factory/swriter")
+ * Nobody can guarantee that this interception will be realy used -
+ * because another interceptor (registered at a later time then this one!)
+ * will be called before this one.
+ * Implementation is executed inside a new thread to prevent application
+ * against possible deadlocks. This deadlocks can occure if
+ * synchronous/asynchronous ... normal ones and oneway calls are mixed.
+ * Notifications of listener will be oneway mostly - her reactions can
+ * be synchronous then. => deadlocks are possible
+ *
+ * @author Andreas Schl&uuml;ns
+ * @created 06.03.2002 09:38
+ */
+public class Interceptor implements com.sun.star.frame.XFrameActionListener,
+ com.sun.star.frame.XDispatchProviderInterceptor,
+ com.sun.star.frame.XDispatchProvider,
+ com.sun.star.frame.XDispatch,
+ com.sun.star.frame.XInterceptorInfo,
+ IShutdownListener,
+ IOnewayLink
+{
+ // ____________________
+
+ /**
+ * const
+ * All these URL's are intercepted by this implementation.
+ */
+ private static final String[] INTERCEPTED_URLS = { "private:factory/*" ,
+ ".uno:SaveAs" ,
+ "slot:5300" ,
+ ".uno:Quit" };
+
+ // ____________________
+
+ /**
+ * @member m_xMaster use this interceptor if he doesn't handle queried dispatch request
+ * @member m_xSlave we can forward all unhandled requests to this slave interceptor
+ * @member m_xFrame intercepted frame
+ * @member m_bDead there exist more then one way to finish an object of this class - we must know it sometimes
+ */
+ private com.sun.star.frame.XDispatchProvider m_xMaster ;
+ private com.sun.star.frame.XDispatchProvider m_xSlave ;
+ private com.sun.star.frame.XFrame m_xFrame ;
+ private boolean m_bIsActionListener ;
+ private boolean m_bIsRegistered ;
+ private boolean m_bDead ;
+
+ // ____________________
+
+ /**
+ * ctor
+ * Initialize the new interceptor. Given frame reference can be used to
+ * register this interceptor on it automaticly later.
+ *
+ * @seealso startListening()
+ *
+ * @param xFrame
+ * this interceptor will register himself at this frame to intercept dispatched URLs
+ */
+ Interceptor(/*IN*/ com.sun.star.frame.XFrame xFrame)
+ {
+ m_xFrame = xFrame ;
+ m_xSlave = null ;
+ m_xMaster = null ;
+ m_bIsRegistered = false ;
+ m_bIsActionListener = false ;
+ m_bDead = false ;
+ }
+
+ //_____________________
+
+ /**
+ * start working as frame action listener realy.
+ * We will be frame action listener here. In case
+ * we get a frame action which indicates, that we should
+ * update our interception. Because such using of an interecptor
+ * isn't guaranteed - in case a newer one was registered ...
+ */
+ public void startListening()
+ {
+ com.sun.star.frame.XFrame xFrame = null;
+ synchronized(this)
+ {
+ if (m_bDead)
+ return;
+ if (m_xFrame==null)
+ return;
+ if (m_bIsActionListener==true)
+ return;
+ xFrame = m_xFrame;
+ }
+ m_xFrame.addFrameActionListener(this);
+ synchronized(this)
+ {
+ m_bIsActionListener=true;
+ }
+ }
+
+ //_____________________
+
+ /**
+ * In case we got an oneway listener callback - we had to use the office
+ * asynchronous then. This method is the callback from the started thread
+ * (started inside the original oneway method). We found all parameters of
+ * the original request packed inside a vector. Here we unpack it and
+ * call the right internal helper method, which implements the right
+ * funtionality.
+ *
+ * @seealso frameAction()
+ * @seealso dispatch()
+ *
+ * @param nRequest
+ * indicates, which was the original request (identifies the
+ * original called method)
+ *
+ * @param lParams
+ * the vector with all packed parameters of the original request
+ */
+ public void execOneway(/*IN*/ int nRequest,/*IN*/ Vector lParams )
+ {
+ synchronized(this)
+ {
+ if (m_bDead)
+ return;
+ }
+
+ // was it frameAction()?
+ if (nRequest==OnewayExecutor.REQUEST_FRAMEACTION)
+ {
+ com.sun.star.frame.FrameActionEvent[] lOutAction = new com.sun.star.frame.FrameActionEvent[1];
+ Vector[] lInParams = new Vector[1];
+ lInParams[0] = lParams;
+
+ OnewayExecutor.codeFrameAction( OnewayExecutor.DECODE_PARAMS ,
+ lInParams ,
+ lOutAction );
+ impl_frameAction(lOutAction[0]);
+ }
+ else
+ // was it dispatch()?
+ if (nRequest==OnewayExecutor.REQUEST_DISPATCH)
+ {
+ com.sun.star.util.URL[] lOutURL = new com.sun.star.util.URL[1];
+ com.sun.star.beans.PropertyValue[][] lOutProps = new com.sun.star.beans.PropertyValue[1][];
+ Vector[] lInParams = new Vector[1];
+ lInParams[0] = lParams;
+
+ OnewayExecutor.codeDispatch( OnewayExecutor.DECODE_PARAMS ,
+ lInParams ,
+ lOutURL ,
+ lOutProps );
+ impl_dispatch(lOutURL[0],lOutProps[0]);
+ }
+ }
+
+ // ____________________
+
+ /**
+ * call back for frame action events
+ * We use it to update our interception. Because if a new component was loaded into
+ * the frame or another interceptor was registered, we should refresh our connection
+ * to the frame. Otherwhise we can't guarantee full functionality here.
+ *
+ * Note: Don't react synchronous in an asynchronous listener callback. So use a thread
+ * here to update anything.
+ *
+ * @seealso impl_frameAction()
+ *
+ * @param aEvent
+ * describes the action
+ */
+ public /*ONEWAY*/ void frameAction(/*IN*/ com.sun.star.frame.FrameActionEvent aEvent)
+ {
+ synchronized(this)
+ {
+ if (m_bDead)
+ return;
+ }
+
+ boolean bHandle = false;
+ switch(aEvent.Action.getValue())
+ {
+ case com.sun.star.frame.FrameAction.COMPONENT_ATTACHED_value : bHandle=true; break;
+ case com.sun.star.frame.FrameAction.COMPONENT_DETACHING_value : bHandle=true; break;
+ case com.sun.star.frame.FrameAction.COMPONENT_REATTACHED_value : bHandle=true; break;
+ // Don't react for CONTEXT_CHANGED here. Ok it indicates, that may another interceptor
+ // was registered at the frame ... but if we register ourself there - we get a context
+ // changed too :-( Best way to produce a never ending recursion ...
+ // May be that somewhere find a safe mechanism to detect own produced frame action events
+ // and ignore it.
+ case com.sun.star.frame.FrameAction.CONTEXT_CHANGED_value :
+ System.out.println("Time to update interception ... but may it will start a recursion. So I let it :-(");
+ bHandle=false;
+ break;
+ }
+
+ // ignore some events
+ if (! bHandle)
+ return;
+
+ // pack the event and start thread - which call us back later
+ Vector[] lOutParams = new Vector[1];
+ com.sun.star.frame.FrameActionEvent[] lInAction = new com.sun.star.frame.FrameActionEvent[1];
+ lInAction[0] = aEvent;
+
+ OnewayExecutor.codeFrameAction( OnewayExecutor.ENCODE_PARAMS ,
+ lOutParams ,
+ lInAction );
+ OnewayExecutor aExecutor = new OnewayExecutor( (IOnewayLink)this ,
+ OnewayExecutor.REQUEST_FRAMEACTION ,
+ lOutParams[0] );
+ aExecutor.start();
+ }
+
+ // ____________________
+
+ /**
+ * Indicates using of us as an interceptor.
+ * Now we have to react for the requests, we are registered.
+ * That means: load new empty documents - triggered by the new menu of the office.
+ * Because it's oneway - use thread for loading!
+ *
+ * @seealso impl_dispatch()
+ *
+ * @param aURL
+ * describes the document, which should be loaded
+ *
+ * @param lArguments
+ * optional parameters for loading
+ */
+ public /*ONEWAY*/ void dispatch(/*IN*/ com.sun.star.util.URL aURL,/*IN*/ com.sun.star.beans.PropertyValue[] lArguments)
+ {
+ synchronized(this)
+ {
+ if (m_bDead)
+ return;
+ }
+
+ Vector[] lOutParams = new Vector[1];
+ com.sun.star.util.URL[] lInURL = new com.sun.star.util.URL[1];
+ com.sun.star.beans.PropertyValue[][] lInArguments = new com.sun.star.beans.PropertyValue[1][];
+ lInURL[0] = aURL ;
+ lInArguments[0] = lArguments;
+
+ OnewayExecutor.codeDispatch( OnewayExecutor.ENCODE_PARAMS ,
+ lOutParams ,
+ lInURL ,
+ lInArguments );
+ OnewayExecutor aExecutor = new OnewayExecutor( (IOnewayLink)this ,
+ OnewayExecutor.REQUEST_DISPATCH ,
+ lOutParams[0] );
+ aExecutor.start();
+ }
+
+
+ //_____________________
+
+ /**
+ * Internal call back for frame action events, triggered by the used
+ * OnewayExecutor thread we started in frameAction().
+ * We use it to update our interception on the internal saved frame.
+ *
+ * @param aEvent
+ * describes the action
+ */
+ public void impl_frameAction(/*IN*/ com.sun.star.frame.FrameActionEvent aEvent)
+ {
+ synchronized(this)
+ {
+ if (m_bDead)
+ return;
+ }
+
+ // deregistration will be done everytime ...
+ // But may it's not neccessary to establish a new registration!
+ // Don't look for ignoring actions - it was done already inside original frameAction() call!
+ boolean bRegister = false;
+
+ // analyze the event and decide which reaction is usefull
+ switch(aEvent.Action.getValue())
+ {
+ case com.sun.star.frame.FrameAction.COMPONENT_ATTACHED_value : bRegister = true ; break;
+ case com.sun.star.frame.FrameAction.COMPONENT_REATTACHED_value : bRegister = true ; break;
+ case com.sun.star.frame.FrameAction.COMPONENT_DETACHING_value : bRegister = false; break;
+ }
+
+ com.sun.star.frame.XFrame xFrame = null ;
+ boolean bIsRegistered = false;
+ synchronized(this)
+ {
+ bIsRegistered = m_bIsRegistered;
+ m_bIsRegistered = false;
+ xFrame = m_xFrame;
+ }
+
+ com.sun.star.frame.XDispatchProviderInterception xRegistration = (com.sun.star.frame.XDispatchProviderInterception)UnoRuntime.queryInterface(
+ com.sun.star.frame.XDispatchProviderInterception.class,
+ xFrame);
+
+ if(xRegistration==null)
+ return;
+
+ if (bIsRegistered)
+ xRegistration.releaseDispatchProviderInterceptor(this);
+
+ if (! bRegister)
+ return;
+
+ xRegistration.registerDispatchProviderInterceptor(this);
+ synchronized(this)
+ {
+ m_bIsRegistered = true;
+ }
+ }
+
+ // ____________________
+
+ /**
+ * Implementation of interface XDispatchProviderInterceptor
+ * These functions are used to build a list of interceptor objects
+ * connected in both ways.
+ * Searching for a right interceptor is made by forwarding any request
+ * from toppest master to lowest slave of this hierarchy.
+ * If an interceptor whish to handle the request he can break that
+ * and return himself as a dispatcher.
+ */
+ public com.sun.star.frame.XDispatchProvider getSlaveDispatchProvider()
+ {
+ synchronized(this)
+ {
+ return m_xSlave;
+ }
+ }
+
+ // ____________________
+
+ public void setSlaveDispatchProvider(com.sun.star.frame.XDispatchProvider xSlave)
+ {
+ synchronized(this)
+ {
+ m_xSlave = xSlave;
+ }
+ }
+
+ // ____________________
+
+ public com.sun.star.frame.XDispatchProvider getMasterDispatchProvider()
+ {
+ synchronized(this)
+ {
+ return m_xMaster;
+ }
+ }
+
+ // ____________________
+
+ public void setMasterDispatchProvider(com.sun.star.frame.XDispatchProvider xMaster)
+ {
+ synchronized(this)
+ {
+ m_xMaster = xMaster;
+ }
+ }
+
+ // ____________________
+
+ /**
+ * Implementation of interface XDispatchProvider
+ * These functions are called from our master if he willn't handle the outstanding request.
+ * Given parameter should be checked if they are right for us. If it's true, the returned
+ * dispatcher should be this implementation himself; otherwise call should be forwarded
+ * to the slave.
+ *
+ * @param aURL
+ * describes the request, which should be handled
+ *
+ * @param sTarget
+ * specifies the target frame for this request
+ *
+ * @param nSearchFlags
+ * optional search flags, if sTarget isn't a special one
+ *
+ * @return [XDispatch]
+ * a dispatch object, which can handle the given URL
+ * May be NULL!
+ */
+ public com.sun.star.frame.XDispatch queryDispatch(/*IN*/ com.sun.star.util.URL aURL,/*IN*/ String sTarget,/*IN*/ int nSearchFlags)
+ {
+ synchronized(this)
+ {
+ if (m_bDead)
+ return null;
+ }
+
+ // intercept loading empty documents into new created frames
+ if(
+ (sTarget.compareTo ("_blank" ) == 0 ) &&
+ (aURL.Complete.startsWith("private:factory") == true)
+ )
+ {
+ System.out.println("intercept private:factory");
+ return this;
+ }
+
+ // intercept opening the SaveAs dialog
+ if (aURL.Complete.startsWith(".uno:SaveAs") == true)
+ {
+ System.out.println("intercept SaveAs by returning null!");
+ return null;
+ }
+
+ // intercept "File->Exit" inside the menu
+ if (
+ (aURL.Complete.startsWith("slot:5300") == true) ||
+ (aURL.Complete.startsWith(".uno:Quit") == true)
+ )
+ {
+ System.out.println("intercept File->Exit");
+ return this;
+ }
+
+ synchronized(this)
+ {
+ if (m_xSlave!=null)
+ return m_xSlave.queryDispatch(aURL, sTarget, nSearchFlags);
+ }
+
+ return null;
+ }
+
+ // ____________________
+
+ public com.sun.star.frame.XDispatch[] queryDispatches(/*IN*/ com.sun.star.frame.DispatchDescriptor[] lDescriptor)
+ {
+ synchronized(this)
+ {
+ if (m_bDead)
+ return null;
+ }
+ // Resolve any request seperatly by using own "dispatch()" method.
+ // Note: Don't pack return list if "null" objects occure!
+ int nCount = lDescriptor.length;
+ com.sun.star.frame.XDispatch[] lDispatcher = new com.sun.star.frame.XDispatch[nCount];
+ for(int i=0; i<nCount; ++i)
+ {
+ lDispatcher[i] = queryDispatch(lDescriptor[i].FeatureURL ,
+ lDescriptor[i].FrameName ,
+ lDescriptor[i].SearchFlags);
+ }
+ return lDispatcher;
+ }
+
+ // ____________________
+
+ /**
+ * This method is called if this interceptor "wins the request".
+ * We intercepted creation of new frames and loading of empty documents.
+ * Do it now.
+ *
+ * @param aURL
+ * describes the document
+ *
+ * @param lArguments
+ * optional arguments for loading
+ */
+ public void impl_dispatch(/*IN*/ com.sun.star.util.URL aURL,/*IN*/ com.sun.star.beans.PropertyValue[] lArguments)
+ {
+ synchronized(this)
+ {
+ if (m_bDead)
+ return;
+ }
+
+ if (
+ (aURL.Complete.startsWith("slot:5300") == true) ||
+ (aURL.Complete.startsWith(".uno:Quit") == true)
+ )
+ {
+ System.exit(0);
+ }
+ else
+ if (aURL.Complete.startsWith("private:factory") == true)
+ {
+ // Create view frame for showing loaded documents on demand.
+ // The visible state is neccessary for JNI functionality to get the HWND and plug office
+ // inside a java window hierarchy!
+ DocumentView aNewView = new DocumentView();
+ aNewView.setVisible(true);
+ aNewView.createFrame();
+ aNewView.load(aURL.Complete,lArguments);
+ }
+ }
+
+ // ____________________
+
+ /**
+ * Notification of status listener isn't guaranteed (instead of listener on XNotifyingDispatch interface).
+ * So this interceptor doesn't support that realy ...
+ */
+ public /*ONEWAY*/ void addStatusListener(/*IN*/ com.sun.star.frame.XStatusListener xListener,/*IN*/ com.sun.star.util.URL aURL)
+ {
+/* if (aURL.Complete.startsWith(".uno:SaveAs")==true)
+ {
+ com.sun.star.frame.FeatureStateEvent aEvent = new com.sun.star.frame.FeatureStateEvent(
+ this,
+ aURL,
+ "",
+ false,
+ false,
+ null);
+ if (xListener!=null)
+ {
+ System.out.println("interceptor disable SavAs by listener notify");
+ xListener.statusChanged(aEvent);
+ }
+ }*/
+ }
+
+ // ____________________
+
+ public /*ONEWAY*/ void removeStatusListener(/*IN*/ com.sun.star.frame.XStatusListener xListener,/*IN*/ com.sun.star.util.URL aURL)
+ {
+ }
+
+ // ____________________
+
+ /**
+ * Implements (optional!) optimization for interceptor mechanism.
+ * Any interceptor which provides this special interface is called automaticly
+ * at registration time on this method. Returned URL's will be used to
+ * call this interceptor directly without calling his masters before, IF(!)
+ * following rules will be true:
+ * (1) every master supports this optional interface too
+ * (2) nobody of these masters whish to intercept same URL then this one
+ * This interceptor whish to intercept creation of new documents.
+ */
+ public String[] getInterceptedURLs()
+ {
+ return INTERCEPTED_URLS;
+ }
+
+ // ____________________
+
+ /**
+ * This class listen on the intercepted frame to free all used ressources on closing.
+ * We forget the reference to the frame only here. Deregistration
+ * isn't neccessary here - because this frame dies and wish to forgoten.
+ *
+ * @param aSource
+ * must be our internal saved frame, on which we listen for frame action events
+ */
+ public /*ONEAY*/ void disposing(/*IN*/ com.sun.star.lang.EventObject aSource)
+ {
+ synchronized(this)
+ {
+ if (m_bDead)
+ return;
+ if (m_xFrame!=null && UnoRuntime.areSame(aSource.Source,m_xFrame))
+ {
+ m_bIsActionListener = false;
+ m_xFrame = null ;
+ }
+ }
+ shutdown();
+ }
+
+ // ____________________
+
+ /**
+ * If this java application shutdown - we must cancel all current existing
+ * listener connections. Otherwhise the office will run into some
+ * DisposedExceptions if it tries to use these forgotten listener references.
+ * And of course it can die doing that.
+ * We are registered at a central object to be informed if the VM will exit.
+ * So we can react.
+ */
+ public void shutdown()
+ {
+ com.sun.star.frame.XFrame xFrame = null ;
+ boolean bIsRegistered = false;
+ boolean bIsActionListener = false;
+ synchronized(this)
+ {
+ // don't react a second time here!
+ if (m_bDead)
+ return;
+ m_bDead = true;
+
+ bIsRegistered = m_bIsRegistered;
+ m_bIsRegistered = false;
+
+ bIsActionListener = m_bIsActionListener;
+ m_bIsActionListener = false;
+
+ xFrame = m_xFrame;
+ m_xFrame = null;
+ }
+
+ // it's a good idead to cancel listening for frame action events
+ // before(!) we deregister us as an interceptor.
+ // Because registration and deregistratio nof interceptor objects
+ // will force sending of frame action events ...!
+ if (bIsActionListener)
+ xFrame.removeFrameActionListener(this);
+
+ if (bIsRegistered)
+ {
+ com.sun.star.frame.XDispatchProviderInterception xRegistration = (com.sun.star.frame.XDispatchProviderInterception)UnoRuntime.queryInterface(
+ com.sun.star.frame.XDispatchProviderInterception.class,
+ xFrame);
+
+ if(xRegistration!=null)
+ xRegistration.releaseDispatchProviderInterceptor(this);
+ }
+
+ xFrame = null;
+
+ synchronized(this)
+ {
+ m_xMaster = null;
+ m_xSlave = null;
+ }
+ }
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/JavaWindowPeerFake.java b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/JavaWindowPeerFake.java
new file mode 100644
index 000000000000..bbaa451f3d67
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/JavaWindowPeerFake.java
@@ -0,0 +1,113 @@
+/*************************************************************************
+ *
+ * $RCSfile: JavaWindowPeerFake.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:38:57 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import java.awt.*;
+
+
+/** <p>Class to pass the system window handle to the OpenOffice.org toolkit.</p>
+ */
+class JavaWindowPeerFake implements com.sun.star.awt.XSystemDependentWindowPeer,
+ com.sun.star.awt.XWindowPeer
+{
+ NativeView maView;
+
+ public JavaWindowPeerFake(NativeView aNative)
+ {
+ maView = aNative;
+ }
+
+ // ____________________
+ /**
+ * Implementation of XSystemDependentWindowPeer (that's all we really need).
+ * This method is called back from the Office toolkit to retrieve the system data.
+ */
+ public java.lang.Object getWindowHandle(byte[] aProcessId, short aSystem)
+ throws com.sun.star.uno.RuntimeException
+ {
+ Object aReturn = null;
+ if(aSystem==maView.maSystem)
+ aReturn = (Object)maView.maHandle;
+ return aReturn;
+ }
+
+ /** not really neaded.
+ */
+ public com.sun.star.awt.XToolkit getToolkit()
+ throws com.sun.star.uno.RuntimeException
+ {
+ return null;
+ }
+
+ public void setPointer(com.sun.star.awt.XPointer xPointer)
+ throws com.sun.star.uno.RuntimeException
+ {
+ }
+
+ public void setBackground(int nColor)
+ throws com.sun.star.uno.RuntimeException
+ {
+ }
+
+ public void invalidate(short nFlags)
+ throws com.sun.star.uno.RuntimeException
+ {
+ }
+
+ public void invalidateRect(com.sun.star.awt.Rectangle aRect,short nFlags)
+ throws com.sun.star.uno.RuntimeException
+ {
+ }
+
+ public void dispose()
+ throws com.sun.star.uno.RuntimeException
+ {
+ }
+
+ public void addEventListener(com.sun.star.lang.XEventListener xListener)
+ throws com.sun.star.uno.RuntimeException
+ {
+ }
+
+ public void removeEventListener(com.sun.star.lang.XEventListener xListener)
+ throws com.sun.star.uno.RuntimeException
+ {
+ }
+}
+
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Makefile b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Makefile
new file mode 100644
index 000000000000..5faa381b140a
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Makefile
@@ -0,0 +1,134 @@
+#*************************************************************************
+#
+# $RCSfile: Makefile,v $
+#
+# $Revision: 1.6 $
+#
+# last change: $Author: rt $ $Date: 2005-03-29 12:11:20 $
+#
+# The Contents of this file are made available subject to the terms of
+# the BSD license.
+#
+# Copyright (c) 2003 by Sun Microsystems, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+#**************************************************************************
+
+# Builds the OfficeDevDestopEnvironment example of the Developers Guide.
+
+PRJ=../../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+include $(SETTINGS)/dk.mk
+
+# Define non-platform/compiler specific settings
+EXAMPLE_NAME=OfficeDevDesktopEnv
+OUT_APP_CLASS = $(OUT_CLASS)/$(EXAMPLE_NAME)
+
+APP1_NAME=DesktopExample
+APP1_JAR=$(OUT_APP_CLASS)/$(APP1_NAME).jar
+
+APP1_JAVAFILES = \
+ CustomizeView.java \
+ Desk.java \
+ DocumentView.java \
+ FunctionHelper.java \
+ Interceptor.java \
+ IOnewayLink.java \
+ IShutdownListener.java \
+ JavaWindowPeerFake.java \
+ NativeView.java \
+ OfficeConnect.java \
+ OnewayExecutor.java \
+ StatusListener.java \
+ StatusView.java \
+ ViewContainer.java
+
+APP1_CLASSFILES = $(patsubst %.java,$(OUT_APP_CLASS)/%.class,$(APP1_JAVAFILES))
+APP1_CLASSNAMES = $(patsubst %.java,%.class,$(APP1_JAVAFILES)) \
+ CustomizeView$(QUOTE)$$ClickListener.class \
+ DocumentView$(QUOTE)$$1.class \
+ DocumentView$(QUOTE)$$Reactor.class
+
+
+SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
+ $(PATH_SEPARATOR)$(OUT_APP_CLASS))
+
+ifeq "$(OS)" "WIN"
+SUBDIR= nativelib/windows
+else
+SUBDIR= nativelib/unix
+endif
+
+# Targets
+.PHONY: ALL
+ALL : $(SUBDIR) \
+ $(EXAMPLE_NAME)
+
+include $(SETTINGS)/stdtarget.mk
+
+.PHONY : $(SUBDIR)
+$(SUBDIR) :
+ $(MAKE) -C $@
+
+$(APP1_CLASSFILES) : $(APP1_JAVAFILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_APP_CLASS) $(APP1_JAVAFILES)
+
+$(OUT_APP_CLASS)/$(APP1_NAME).mf :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo Main-Class: com.sun.star.lib.loader.Loader> $@
+ $(ECHOLINE)>> $@
+ @echo Name: com/sun/star/lib/loader/Loader.class>> $@
+ @echo Application-Class: Desk>> $@
+
+$(APP1_JAR) : $(OUT_APP_CLASS)/$(APP1_NAME).mf $(APP1_CLASSFILES)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ +cd $(subst /,$(PS),$(OUT_APP_CLASS)) && $(SDK_JAR) cvfm $(@F) $(basename $(@F)).mf $(APP1_CLASSNAMES)
+ +$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES)
+
+$(EXAMPLE_NAME) : $(APP1_JAR)
+ @echo --------------------------------------------------------------------------------
+ @echo Please use the following command to execute the example!
+ @echo -
+ @echo $(MAKE) DesktopExample.run
+ @echo ------
+ @echo If you want to run the $(JAR1_JAR) file please set your
+ @echo CLASSPATH = $(SDK_CLASSPATH)
+ @echo Start the example with jar -jar $(JAR1_JAR)
+ @echo --------------------------------------------------------------------------------
+
+%.run: $(OUT_APP_CLASS)/%.jar
+ $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $<
+
+.PHONY: clean
+clean :
+ $(MAKE) -C $(SUBDIR) clean
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_CLASS))
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/NativeView.java b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/NativeView.java
new file mode 100644
index 000000000000..b9853f9037d5
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/NativeView.java
@@ -0,0 +1,188 @@
+/*************************************************************************
+ *
+ * $RCSfile: NativeView.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:39:23 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+// __________ Imports __________
+
+import java.awt.*;
+import java.lang.*;
+import java.awt.event.*;
+
+// __________ Implementation __________
+
+/**
+ * Class to pass the system window handle to the OpenOffice.org toolkit.
+ * It use special JNI methods to get the system handle of used java window.
+ *
+ * Attention!
+ * Use JNI functions on already visible canvas objects only!
+ * Otherwise they can make some trouble.
+ *
+ * @author Andreas Schl&uuml;ns
+ * @created 22.02.2002 08:47
+ */
+
+public class NativeView extends java.awt.Canvas
+{
+ // ____________________
+
+ /**
+ * ctor
+ * Does nothing realy.
+ * We can use our JNI mechanism for an already visible
+ * canvas only. So we overload the method for showing ("setVisible()")
+ * and make our intialization there. BUt we try to show an empty clean
+ * window till there.
+ */
+ public NativeView()
+ {
+ maHandle = null;
+ maSystem = 0;
+ this.setBackground(Color.white);
+ }
+
+ // ____________________
+
+ /**
+ * Overload this method to make neccessary initializations here.
+ * (e.g. get the window handle and neccessary system informations)
+ *
+ * Why here?
+ * Because the handle seams to be available for already visible windows
+ * only. So it's the best place to get it. Special helper method
+ * can be called more then ones - but call native code one times only
+ * and safe the handle and the system type on our members maHandle/maSystem!
+ */
+ public void setVisible(boolean bState)
+ {
+ getHWND();
+ }
+
+ // ____________________
+
+ /**
+ * to guarantee right resize handling inside a swing container
+ * (e.g. JSplitPane) we must provide some informations about our
+ * prefered/minimum and maximum size.
+ */
+ public Dimension getPreferredSize()
+ {
+ return new Dimension(500,300);
+ }
+
+ public Dimension getMaximumSize()
+ {
+ return new Dimension(1024,768);
+ }
+
+ public Dimension getMinimumSize()
+ {
+ return new Dimension(100,100);
+ }
+
+ // ____________________
+
+ /**
+ * overload paint routine to show provide against
+ * repaint errors if no office view is realy plugged
+ * into this canvas.
+ * If handle is present - we shouldn't paint anything further.
+ * May the remote window is already plugged. In such case we
+ * shouldn't paint it over.
+ */
+ public void paint(Graphics aGraphic)
+ {
+ if(maHandle==null)
+ {
+ Dimension aSize = getSize();
+ aGraphic.clearRect(0,0,aSize.width,aSize.height);
+ }
+ }
+
+ // ____________________
+
+ /**
+ * JNI interface of this class
+ * These two methods are implemented by using JNI mechanismen.
+ * The will be used to get the platform dependent window handle
+ * of a java awt canvas. This handle can be used to create an office
+ * window as direct child of it. So it's possible to plug Office
+ * windows in a java UI container.
+ *
+ * Note:
+ * Native code for windows register special function pointer to handle
+ * window messages ... But if it doesn't check for an already registered
+ * instance of this handler it will do it twice and produce a stack overflow
+ * because such method call herself in a never ending loop ...
+ * So we try to use the JNI code one times only and safe already getted
+ * informations inside this class.
+ */
+ public native int getNativeWindowSystemType();
+ private native long getNativeWindow(); // private! => use getHWND() with cache mechanism!
+
+ public Integer getHWND()
+ {
+ if(maHandle==null)
+ {
+ maHandle = new Integer((int)getNativeWindow());
+ maSystem = getNativeWindowSystemType();
+ }
+ return maHandle;
+ }
+
+ // ____________________
+
+ /**
+ * for using of the JNI methods it's neccessary to load
+ * system library which exports it.
+ */
+ static
+ {
+ System.loadLibrary("nativeview");
+ }
+
+ // ____________________
+
+ /**
+ * @member maHandle system window handle
+ * @member maSystem info about currently used platform
+ */
+ public Integer maHandle ;
+ public int maSystem ;
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/OfficeConnect.java b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/OfficeConnect.java
new file mode 100644
index 000000000000..76007310dc89
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/OfficeConnect.java
@@ -0,0 +1,211 @@
+/*************************************************************************
+ *
+ * $RCSfile: OfficeConnect.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:39:37 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+// __________ Imports __________
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.Any;
+
+import java.lang.String;
+
+
+// __________ Implementation __________
+
+/**
+ * support ONE singleton uno connection to an running office installation!
+ * Can be used to open/use/close connection to uno environment of an office. If
+ * necessary a new office instance is started.
+ * ctor isn't available from outside. You should call static function
+ * "getConnection()" to open or use internal set connection which is created one
+ * times only.
+ *
+ * @author Andreas Schl&uuml;ns
+ * @created 7. Februar 2002
+ * @modified 05.02.2002 12:10
+ */
+public class OfficeConnect
+{
+ // ____________________
+
+ /**
+ * At first call we create static connection object and open connection to an
+ * office - anew offic einstance is started if necessary
+ * Then - and for all further requests we return these static connection member.
+ */
+ public static synchronized void createConnection()
+ {
+ if (maConnection == null)
+ maConnection = new OfficeConnect();
+ }
+
+ // ____________________
+
+ /**
+ * close connection to remote office if it exist
+ */
+ public static synchronized void disconnect()
+ {
+ if(maConnection!=null)
+ {
+ mxServiceManager=null;
+ mxOfficeContext=null;
+ maConnection=null;
+ }
+ }
+
+ // ____________________
+
+ /**
+ * ctor
+ * We try to open the connection in our ctor ... transparently for user.
+ * After it was successfully you will find an internal set member
+ * m_xRemoteContext wich means remote component context of the connected office.
+ * The context can be used to get the remote service manager from the office.
+ * We made it private to support singleton pattern of these implementation.
+ * see getConnection() for further informations
+ */
+ private OfficeConnect()
+ {
+ try
+ {
+ // get the remote office context. If necessary a new office
+ // process is started
+ mxOfficeContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+ System.out.println("Connected to a running office ...");
+ mxServiceManager = mxOfficeContext.getServiceManager();
+ }
+ catch (java.lang.Exception ex)
+ {
+ System.err.println("connection failed" + ex);
+ ex.printStackTrace(System.out);
+ System.exit(1);
+
+ }
+ }
+
+ // ____________________
+
+ /**
+ * create uno components inside remote office process
+ * After connection of these proccess to a running office we have access to
+ * remote service manager of it.
+ * So we can use it to create all existing services. Use this method to create
+ * components by name and get her interface. Casting of it to right target
+ * interface is part of your implementation.
+ *
+ * @param aType describe class type of created service
+ * Returned object can be casted directly to this one.
+ * Uno query was done by this method automaticly.
+ * @param sServiceSpecifier name of service which should be created
+ * @return the new created service object
+ */
+ public static synchronized Object createRemoteInstance(
+ Class aType, String sServiceSpecifier)
+ {
+ Object aResult = null;
+ try
+ {
+ aResult = UnoRuntime.queryInterface(aType,
+ mxServiceManager.createInstanceWithContext(
+ sServiceSpecifier, mxOfficeContext));
+ }
+ catch (com.sun.star.uno.Exception ex)
+ {
+ System.err.println("Couldn't create Service of type "
+ + sServiceSpecifier + ": " + ex);
+ System.exit(0);
+ }
+ return aResult;
+ }
+
+ // ____________________
+
+ /**
+ * same as "createRemoteInstance()" but supports additional parameter for
+ * initializing created object
+ *
+ * @param lArguments optional arguments
+ * They are used to initialize new created service.
+ * @param aType Description of Parameter
+ * @param sServiceSpecifier Description of Parameter
+ * @return the new create service object
+ */
+ public static synchronized Object createRemoteInstanceWithArguments(
+ Class aType, String sServiceSpecifier, Any[] lArguments)
+ {
+ Object aResult = null;
+ try
+ {
+ aResult = UnoRuntime.queryInterface(aType,
+ mxServiceManager.createInstanceWithArgumentsAndContext(
+ sServiceSpecifier, lArguments, mxOfficeContext));
+ }
+ catch (com.sun.star.uno.Exception ex)
+ {
+ System.err.println("Couldn't create Service of type "
+ + sServiceSpecifier + ": " + ex);
+ System.exit(0);
+ }
+ return aResult;
+ }
+
+ // ____________________
+
+ /**
+ * returns remote component context of the connected office
+ */
+ public static synchronized com.sun.star.uno.XComponentContext getOfficeContext()
+ {
+ return mxOfficeContext;
+ }
+
+ // ____________________
+
+ /**
+ * member
+ */
+ // singleton connection instance
+ private static OfficeConnect maConnection;
+
+ // reference to the office component context
+ private static com.sun.star.uno.XComponentContext mxOfficeContext;
+ // reference to remote service manager of singleton connection object
+ private static com.sun.star.lang.XMultiComponentFactory mxServiceManager;
+}
+
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/OnewayExecutor.java b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/OnewayExecutor.java
new file mode 100644
index 000000000000..7bef81f5f7fd
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/OnewayExecutor.java
@@ -0,0 +1,246 @@
+/*************************************************************************
+ *
+ * $RCSfile: OnewayExecutor.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:39:52 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import java.util.Vector;
+
+// __________ Implementation __________
+
+/**
+ * It's not allowed to call synchronoues back inside an oneway interface call.
+ * (see IOnewayLink too). So we start a thread (implemented by this class), which
+ * gets all neccessary parameters from the original called object and
+ * call it back later inside his run() method. So the execution of such oneway call
+ * will be asynchronous. It works in a generic way and can be used or any type
+ * of oneway request. Because the source and the target of this call-link knows,
+ * which method was used and which parameters must be handled.
+ *
+ * @author Andreas Schl&uuml;ns
+ * @created 17.07.2002 08:18
+ */
+class OnewayExecutor extends Thread
+{
+ // _______________________________
+
+ /**
+ * const
+ * We define some request for some well known oneway interface
+ * calls here too. So they mustn't be declared more then ones.
+ * Of course it's not necessary to use it ... but why not :-)
+ */
+
+ public static final int REQUEST_FRAMEACTION = 1 ;
+ public static final int REQUEST_STATUSCHANGED = 2 ;
+ public static final int REQUEST_ADDSTATUSLISTENER = 3 ;
+ public static final int REQUEST_REMOVESTATUSLISTENER = 4 ;
+ public static final int REQUEST_DISPATCH = 5 ;
+
+ public static final boolean ENCODE_PARAMS = true ;
+ public static final boolean DECODE_PARAMS = false ;
+
+ // _______________________________
+
+ /**
+ * @member m_rLink the object, which wish to be called back by this thread
+ * @member m_nRequest describes the type of the original request (means the
+ * called oneyway method)
+ * @member m_lParams list of parameters of the original request
+ */
+ private IOnewayLink m_rLink ;
+ private int m_nRequest ;
+ private Vector m_lParams ;
+
+ // _______________________________
+
+ /**
+ * ctor
+ * It's initialize this thread with all neccessary parameters.
+ * It gets the object, which wish to be called back and the type
+ * and parameters of the original request.
+ *
+ * @param nRequest
+ * The two user of this callback can define an unique number,
+ * which identify the type of original interface method.
+ * So the called interface object can decide, which action will be
+ * neccessary.
+ *
+ * @param lParams
+ * If the original method used parameters, they will be coded here in
+ * a generic way. Only the called interface object know (it depends
+ * from the original request - see nRequest too), how this list must
+ * be interpreted.
+ * Note: Atomic types (e.g. int, long) will be transported as objects
+ * too (Integer, Long)!
+ */
+ public OnewayExecutor( IOnewayLink rLink ,
+ int nRequest ,
+ Vector lParams )
+ {
+ m_rLink = rLink ;
+ m_nRequest = nRequest;
+ m_lParams = lParams ;
+
+ if (m_rLink==null)
+ System.out.println("ctor ... m_rLink == null");
+ if (m_lParams==null)
+ System.out.println("ctor ... m_lParams == null");
+ }
+
+ // _______________________________
+
+ /**
+ * implements the thread function
+ * Here we call the internal set link object back and
+ * give him all neccessary parameters.
+ * After that we die by ouerself ...
+ */
+ public void run()
+ {
+ if (m_rLink==null)
+ System.out.println("run ... m_rLink == null");
+ if (m_lParams==null)
+ System.out.println("run ... m_lParams == null");
+
+ if (m_rLink!=null)
+ m_rLink.execOneway( m_nRequest, m_lParams );
+ }
+
+ // _______________________________
+
+ /**
+ * static helper!
+ * To make convertion of the generic parameter list to the original
+ * one easier - you can use this helper methods. They know how suchlist
+ * must be coded. It's not a must to use it - but you can ...
+ */
+ public static void codeFrameAction(
+ boolean bEncode, Vector[] lParams,
+ com.sun.star.frame.FrameActionEvent[] aAction)
+ {
+ if (bEncode)
+ {
+ lParams[0] = new Vector(1);
+ lParams[0].add( (Object)(aAction[0]) );
+ }
+ else
+ {
+ aAction[0] = (com.sun.star.frame.FrameActionEvent)
+ (lParams[0].elementAt(0));
+ }
+ }
+
+ // _______________________________
+
+ public static void codeStatusChanged(
+ boolean bEncode, Vector[] lParams,
+ com.sun.star.frame.FeatureStateEvent[] aStatus)
+ {
+ if (bEncode)
+ {
+ lParams[0] = new Vector(1);
+ lParams[0].add( (Object)aStatus[0] );
+ }
+ else
+ {
+ aStatus[0] = (com.sun.star.frame.FeatureStateEvent)
+ (lParams[0].elementAt(0));
+ }
+ }
+
+ // _______________________________
+
+ public static void codeAddOrRemoveStatusListener(
+ boolean bEncode, Vector[] lParams,
+ com.sun.star.frame.XStatusListener[] xListener,
+ com.sun.star.util.URL[] aURL)
+ {
+ if (bEncode)
+ {
+ lParams[0] = new Vector(2);
+ lParams[0].add( (Object)xListener[0] );
+ lParams[0].add( (Object)aURL[0] );
+ }
+ else
+ {
+ xListener[0] = (com.sun.star.frame.XStatusListener)
+ (lParams[0].elementAt(0));
+ aURL[0] = (com.sun.star.util.URL)(lParams[0].elementAt(1));
+ }
+ }
+
+ // _______________________________
+
+ public static void codeDispatch(
+ boolean bEncode, Vector[] lParams,
+ com.sun.star.util.URL[] aURL,
+ com.sun.star.beans.PropertyValue[][] lArgs)
+ {
+ if (bEncode)
+ {
+ int nLength = lArgs.length+1;
+ int nPos = 0;
+ lParams[0] = new Vector(nLength);
+
+ lParams[0].add( (Object)aURL[0] );
+ --nLength;
+
+ while (nLength>0)
+ {
+ lParams[0].add( (Object)lArgs[0][nPos] );
+ --nLength;
+ ++nPos ;
+ }
+ }
+ else
+ {
+ int nLength = lParams[0].size()-1;
+ int nPos = 0;
+
+ lArgs[0] = new com.sun.star.beans.PropertyValue[nLength];
+ aURL[0] = (com.sun.star.util.URL)(lParams[0].elementAt(0));
+
+ while (nPos<nLength)
+ {
+ lArgs[0][nPos] = (com.sun.star.beans.PropertyValue)
+ (lParams[0].elementAt(nPos+1));
+ ++nPos;
+ }
+ }
+ }
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/StatusListener.java b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/StatusListener.java
new file mode 100644
index 000000000000..bf43756226e5
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/StatusListener.java
@@ -0,0 +1,484 @@
+/*************************************************************************
+ *
+ * $RCSfile: StatusListener.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:40:05 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+// __________ Imports __________
+
+import com.sun.star.uno.UnoRuntime;
+
+import java.lang.String;
+import java.awt.Component;
+import javax.swing.JCheckBox;
+import javax.swing.JLabel;
+import java.util.Vector;
+
+// __________ Implementation __________
+
+/**
+ * reacts for status events we listen for
+ * We listen for status events to update our UI.
+ * To know which event must be used for which UI control
+ * we use a special class to do that. Otherwhise we have
+ * to guess it ...
+ *
+ * Further we are frame action listener too.
+ * So we can update our status listener connections and
+ * internal holded dispatch object automaticly.
+ *
+ * Another reason for such extra class for listening:
+ * Most listener callbacks are asynchronoues [oneay] requests.
+ * And it's not allowed to call back synchronously there.
+ * So we must start threads for updating something internaly.
+ *
+ * @author Andreas Schl&uuml;ns
+ * @created 15.07.2002 12:36
+ */
+class StatusListener implements com.sun.star.frame.XStatusListener,
+ com.sun.star.frame.XFrameActionListener,
+ IShutdownListener,
+ IOnewayLink
+{
+ //_____________________
+
+ /**
+ * @member m_rControl reference to the UI control, which should be updated
+ * @member m_sTrueText this text will be shown at the used UI control as description for an enabled status
+ * @member m_sFalseText this text will be shown at the used UI control as description for an disabled status
+ * @member m_xDispatch if we listen for status events, we must hold the dispatch object alive!
+ * @member m_xFrame reference to the frame, which can provide new dispatch objects if it's neccessary to update it
+ * @member m_aURL and of course we must be registered for a special URL
+ * @member m_bIsActionListener indicates if we are currently registered as a listener for frame action events or not
+ * @member m_bIsStatusListener indicates if we are currently registered as a listener for status events or not
+ * @member m_bDead there exist more then one way to finish an object of this class - we must know it sometimes
+ */
+ private Component m_rControl ;
+ private String m_sTrueText ;
+ private String m_sFalseText ;
+ private com.sun.star.frame.XDispatch m_xDispatch ;
+ private com.sun.star.frame.XFrame m_xFrame ;
+ private com.sun.star.util.URL m_aURL ;
+ private boolean m_bIsActionListener;
+ private boolean m_bIsStatusListener;
+ private boolean m_bDead ;
+
+ //_____________________
+
+ /**
+ * ctor
+ * It initialize an instance of this class only.
+ * We sett all neccessary informations on our internal member - that's it
+ */
+ StatusListener( /*IN*/ Component rControl ,
+ /*IN*/ String sTrueText ,
+ /*IN*/ String sFalseText ,
+ /*IN*/ com.sun.star.frame.XFrame xFrame ,
+ /*IN*/ String sURL )
+ {
+ m_rControl = rControl ;
+ m_sTrueText = sTrueText ;
+ m_sFalseText = sFalseText ;
+ m_xFrame = xFrame ;
+ m_bIsStatusListener = false ;
+ m_bIsActionListener = false ;
+ m_bDead = false ;
+ // to be perform - we parse the given URL one times only
+ // and use it till we die ...
+ m_aURL = FunctionHelper.parseURL(sURL);
+ }
+
+ //_____________________
+
+ /**
+ * start working as frame action listener realy.
+ * In case we get such frame action, it indicates that we should
+ * update our internal saved dispatch object on which we listen
+ * for status events. So we can do it automaticly. The outside code
+ * mustn't check such things. We can work with one frame,
+ * till it die. It doesn't matter if he will be used for different
+ * load/save or any other requests. We will be up to date everytime.
+ */
+ public void startListening()
+ {
+ com.sun.star.frame.XFrame xFrame = null;
+ synchronized(this)
+ {
+ if (m_bDead)
+ return;
+ if (m_xFrame==null)
+ return;
+ if (m_bIsActionListener==true)
+ return;
+ xFrame = m_xFrame;
+ }
+ xFrame.addFrameActionListener(this);
+ synchronized(this)
+ {
+ m_bIsActionListener=true;
+ }
+ }
+
+ //_____________________
+
+ /**
+ * In case we got an oneway listener callback - we had to use the office
+ * asynchronous then. This method is the callback from the started thread
+ * (started inside the original oneway method). We found all parameters of
+ * the original request packed inside a vector. Here we unpack it and
+ * call the right internal helper method, which implements the right
+ * funtionality.
+ *
+ * @seealso frameAction()
+ * @seealso statusChanged()
+ *
+ * @param nRequest
+ * indicates, which was the original request (identifies the
+ * original called method)
+ *
+ * @param lParams
+ * the vector with all packed parameters of the original request
+ */
+ public void execOneway(/*IN*/ int nRequest,/*IN*/ Vector lParams )
+ {
+ synchronized(this)
+ {
+ if (m_bDead)
+ return;
+ }
+ // was it frameAction()?
+ if (nRequest==OnewayExecutor.REQUEST_FRAMEACTION)
+ {
+ com.sun.star.frame.FrameActionEvent[] lOutAction = new com.sun.star.frame.FrameActionEvent[1];
+ Vector[] lInParams = new Vector[1];
+ lInParams[0] = lParams;
+
+ OnewayExecutor.codeFrameAction( OnewayExecutor.DECODE_PARAMS ,
+ lInParams ,
+ lOutAction );
+ impl_frameAction(lOutAction[0]);
+ }
+ }
+
+ //_____________________
+
+ /**
+ * This is the callback method for such frame action events, we listen for.
+ * Because it's a oneway method we start a thread as reaction. This thread call
+ * us back and we can do neccessary things there.
+ * But we shouldn't start such action - if it's not realy neccessary.
+ * So we check before, if we are intereested on this event realy.
+ *
+ * @see impl_frameAction()
+ *
+ * @param aEvent
+ * describes the action, which triggered this event
+ */
+ public /*ONEWAY*/ void frameAction(/*IN*/ com.sun.star.frame.FrameActionEvent aEvent)
+ {
+ synchronized(this)
+ {
+ if (m_bDead)
+ return;
+ }
+ boolean bHandle = false;
+ switch(aEvent.Action.getValue())
+ {
+ case com.sun.star.frame.FrameAction.COMPONENT_ATTACHED_value : bHandle=true; break;
+ case com.sun.star.frame.FrameAction.COMPONENT_DETACHING_value : bHandle=true; break;
+ case com.sun.star.frame.FrameAction.COMPONENT_REATTACHED_value : bHandle=true; break;
+ case com.sun.star.frame.FrameAction.CONTEXT_CHANGED_value : bHandle=true; break;
+ }
+
+ if (! bHandle)
+ return;
+
+ Vector[] lOutParams = new Vector[1];
+ com.sun.star.frame.FrameActionEvent[] lInAction = new com.sun.star.frame.FrameActionEvent[1];
+ lInAction[0] = aEvent;
+
+ OnewayExecutor.codeFrameAction( OnewayExecutor.ENCODE_PARAMS ,
+ lOutParams ,
+ lInAction );
+ OnewayExecutor aExecutor = new OnewayExecutor( (IOnewayLink)this ,
+ OnewayExecutor.REQUEST_FRAMEACTION ,
+ lOutParams[0] );
+ aExecutor.start();
+ }
+
+ //_____________________
+
+ /**
+ * This is the callback method for the status we listen for an wish to show it
+ * on our UI control. Of yourse it's a oneway method ... but we doesn't call back
+ * to the office synchronously here. We update our UI only. So we don't leave this
+ * java process. In such case it's not neccessary to use threads to decouple it.
+ * Do it here and now ...
+ *
+ * @param aEvent
+ * describes the status, we can use to update our UI control
+ */
+ public /*ONEWAY*/ void statusChanged(/*IN*/ com.sun.star.frame.FeatureStateEvent aEvent)
+ {
+ synchronized(this)
+ {
+ if (m_bDead)
+ return;
+
+ // enable/dsiable th control.
+ // Means: If the feature isn't available currently - we can't show an status realy here.
+ // Then we should colorize it gray ...
+ m_rControl.setEnabled(aEvent.IsEnabled);
+
+ // Only if status is enabled we can look for his value!
+ if (aEvent.IsEnabled)
+ {
+ // look for the right type ofthe UI control
+ // Following actions depend on it.
+
+ //.............................................................
+ // it's a check box
+ if (m_rControl instanceof JCheckBox)
+ {
+ JCheckBox aBox = (JCheckBox)m_rControl;
+
+ // State must be a boolean value too. Otherwhise must
+ // ignore this event.
+ if ( ! (aEvent.State instanceof Boolean ) )
+ return;
+
+ boolean bState = ((Boolean)(aEvent.State)).booleanValue();
+ aBox.setSelected(bState);
+ if (bState)
+ aBox.setText(m_sTrueText);
+ else
+ aBox.setText(m_sFalseText);
+ }
+ else
+ //.............................................................
+ // it's a label
+ if (m_rControl instanceof JLabel)
+ {
+ JLabel aLabel = (JLabel)m_rControl;
+
+ // Detect type of state value
+ // and set it on internal well known UI control
+ // But do it only, if value realy change.
+ if(aEvent.State instanceof String)
+ {
+ String sState = (String)aEvent.State;
+ aLabel.setText(sState);
+ }
+ else
+ if(aEvent.State instanceof Boolean)
+ {
+ boolean bState = ((Boolean)aEvent.State).booleanValue();
+ if (bState)
+ aLabel.setText(m_sTrueText);
+ else
+ aLabel.setText(m_sFalseText);
+ }
+ else
+ if(aEvent.State instanceof Float)
+ {
+ String sState = ((Float)aEvent.State).toString();
+ aLabel.setText(sState);
+ }
+ }
+ }
+ }
+ }
+
+ //_____________________
+
+ /**
+ * Internal call back for frame action events, triggered by the used
+ * OnewayExecutor thread we started in frameAction().
+ * We use it to update internal saved dispatch object and the corresponding
+ * listener connection for status events.
+ *
+ * @param aEvent
+ * describes the action
+ */
+ public void impl_frameAction(/*IN*/ com.sun.star.frame.FrameActionEvent aEvent)
+ {
+ synchronized(this)
+ {
+ if (m_bDead)
+ return;
+ }
+ // Don't look for ignoring actions - it was done already inside original frameAction() call!
+ // deregistration as status listener will be done here everytime - but registration only, if neccessary!
+ boolean bRegister = false;
+ switch(aEvent.Action.getValue())
+ {
+ case com.sun.star.frame.FrameAction.COMPONENT_ATTACHED_value : bRegister=true ; break;
+ case com.sun.star.frame.FrameAction.COMPONENT_DETACHING_value : bRegister=false; break;
+ case com.sun.star.frame.FrameAction.COMPONENT_REATTACHED_value : bRegister=true ; break;
+ case com.sun.star.frame.FrameAction.CONTEXT_CHANGED_value : bRegister=true ; break;
+ }
+
+ boolean bIsStatusListener = false;
+ com.sun.star.frame.XFrame xFrame = null ;
+ com.sun.star.frame.XDispatch xDispatch = null ;
+ com.sun.star.util.URL aURL = null ;
+ synchronized(this)
+ {
+ bIsStatusListener = m_bIsStatusListener;
+ m_bIsStatusListener = false;
+
+ xDispatch = m_xDispatch;
+ m_xDispatch = null;
+
+ aURL = m_aURL;
+ xFrame = m_xFrame;
+ }
+
+ if (bIsStatusListener)
+ xDispatch.removeStatusListener(this,aURL);
+ xDispatch = null;
+
+ if (! bRegister)
+ return;
+
+ com.sun.star.frame.XDispatchProvider xProvider = (com.sun.star.frame.XDispatchProvider)UnoRuntime.queryInterface(
+ com.sun.star.frame.XDispatchProvider.class,
+ xFrame);
+
+ if (xProvider==null)
+ return;
+
+ xDispatch = xProvider.queryDispatch(aURL,"",0);
+
+ if (xDispatch==null)
+ return;
+
+ xDispatch.addStatusListener(this,aURL);
+ synchronized(this)
+ {
+ m_xDispatch = xDispatch;
+ m_bIsStatusListener = true;
+ }
+ }
+
+ // ____________________
+
+ /**
+ * callback for disposing events
+ * Our dispatch or frame object inform us about his following dead ...
+ * So we must forget his reference. But it's not neccessary to
+ * remove listener connections here. Because the broadcaster
+ * forget us automaticly. The only thing we have to do: release
+ * his reference and let him die!
+ *
+ * @param aEvent
+ * describes the source which fire this event
+ * Must be our internal saved dispatch or frame. Otherwhise
+ * somewhere know us without a registration ...
+ */
+ public /*ONEWAY*/ void disposing(/*IN*/ com.sun.star.lang.EventObject aEvent)
+ {
+ synchronized(this)
+ {
+ if (m_bDead)
+ return;
+ if (m_xFrame!=null && UnoRuntime.areSame(aEvent.Source,m_xFrame))
+ {
+ m_bIsActionListener = false;
+ m_xFrame = null ;
+ }
+ else
+ if (m_xDispatch!=null && UnoRuntime.areSame(aEvent.Source,m_xDispatch))
+ {
+ m_bIsStatusListener = false;
+ m_xDispatch = null ;
+ m_aURL = null ;
+ }
+ }
+ shutdown();
+ }
+
+ // ____________________
+
+ /**
+ * If this java application shutdown - we must cancel all current existing
+ * listener connections. Otherwhise the office will run into some
+ * DisposedExceptions if it tries to use these forgotten listener references.
+ * And of course it can die doing that.
+ * We are registered at a central object to be informed if the VM will exit.
+ * So we can react.
+ */
+ public void shutdown()
+ {
+ boolean bIsActionListener = false;
+ boolean bIsStatusListener = false;
+ com.sun.star.frame.XFrame xFrame = null ;
+ com.sun.star.frame.XDispatch xDispatch = null ;
+ com.sun.star.util.URL aURL = null ;
+ synchronized(this)
+ {
+ // don't react a second time here!
+ if (m_bDead)
+ return;
+ m_bDead = true;
+
+ bIsActionListener = m_bIsActionListener;
+ m_bIsActionListener = false;
+
+ bIsStatusListener = m_bIsStatusListener;
+ m_bIsStatusListener = false;
+
+ xFrame = m_xFrame;
+ m_xFrame = null;
+
+ xDispatch = m_xDispatch;
+ m_xDispatch = null;
+
+ aURL = m_aURL;
+ m_aURL = null;
+ }
+
+ if (bIsStatusListener)
+ xDispatch.removeStatusListener(this,aURL);
+ xDispatch = null ;
+ aURL = null ;
+
+ if (bIsActionListener)
+ xFrame.removeFrameActionListener(this);
+ xFrame = null ;
+ }
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/StatusView.java b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/StatusView.java
new file mode 100644
index 000000000000..01b1dcbebeae
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/StatusView.java
@@ -0,0 +1,272 @@
+/*************************************************************************
+ *
+ * $RCSfile: StatusView.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:40:19 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+// __________ Imports __________
+
+import com.sun.star.uno.UnoRuntime;
+
+import java.awt.*;
+import javax.swing.*;
+import java.lang.String;
+
+// __________ Implementation __________
+
+/**
+ * Implement a view to show status informations
+ * of currently loaded document of a document view.
+ * It use seperate listener threads to get this informations
+ * and actualize it automaticly if frame broadcast changes of
+ * his contained document.
+ * Threads are neccessary to prevent this view against deadlocks.
+ * These deadlocks can occure if a listener will be notified
+ * by the office in an "oneway" method and try to call back
+ * to the office by using a synchronous method.
+ * UNO must guarantee order of all these calls ... and if
+ * the source of arrived event holds a mutex and our synchronous
+ * call needs this mutex too => a deadlock occure.
+ * Why? UNO had created a new thread for our synchronous call
+ * inside the office process and so exist different threads
+ * for this constallation.
+ *
+ * @author Andreas Schl&uuml;ns
+ * @created 20.06.2002 15:08
+ */
+public class StatusView extends JPanel
+ implements IShutdownListener
+{
+ // ____________________
+
+ /**
+ * const
+ * These URL's describe available feature states.
+ */
+ public static final String FEATUREURL_FONT = "slot:10007";
+ public static final String FEATUREURL_SIZE = "slot:10015";
+ public static final String FEATUREURL_BOLD = "slot:10009";
+ public static final String FEATUREURL_ITALIC = "slot:10008";
+ public static final String FEATUREURL_UNDERLINE = "slot:10014";
+
+ // ____________________
+
+ /**
+ * const
+ * These values are used to show current state of showed feature.
+ */
+ public static final String FONT_OFF = "unknown" ;
+ public static final String SIZE_OFF = "0.0" ;
+ public static final String BOLD_OFF = "-" ;
+ public static final String ITALIC_OFF = "-" ;
+ public static final String UNDERLINE_OFF = "-" ;
+
+ public static final String FONT_ON = "" ;
+ public static final String SIZE_ON = "" ;
+ public static final String BOLD_ON = "X" ;
+ public static final String ITALIC_ON = "X" ;
+ public static final String UNDERLINE_ON = "X" ;
+
+ // ____________________
+
+ /**
+ * @member mlaFontValue shows status of font name
+ * @member mlaSizeValue shows status of font size
+ * @member mlaBoldValue shows status of font style bold
+ * @member mlaUnderlineValue shows status of font style underline
+ * @member mlaItalicValue shows status of font style italic
+ *
+ * @member maFontListener threadsafe(!) helper to listen for status event which describe font name
+ * @member maSizeListener threadsafe(!) helper to listen for status event which describe font size
+ * @member maBoldListener threadsafe(!) helper to listen for status event which describe font style bold
+ * @member maUnderlineListener threadsafe(!) helper to listen for status event which describe font style underline
+ * @member maItalicListener threadsafe(!) helper to listen for status event which describe font style italic
+ */
+ private JLabel m_laFontValue ;
+ private JLabel m_laSizeValue ;
+ private JLabel m_laBoldValue ;
+ private JLabel m_laUnderlineValue ;
+ private JLabel m_laItalicValue ;
+
+ private StatusListener m_aFontListener ;
+ private StatusListener m_aSizeListener ;
+ private StatusListener m_aBoldListener ;
+ private StatusListener m_aUnderlineListener ;
+ private StatusListener m_aItalicListener ;
+
+ // ____________________
+
+ /**
+ * ctor
+ * Create view controls on startup and initialize it with default values.
+ * Filling of view items can be done by special set-methods.
+ * We don't start listening here! see setFrame() for that ...
+ */
+ StatusView()
+ {
+ this.setLayout(new GridBagLayout());
+
+ GridBagConstraints aConstraint = new GridBagConstraints();
+ aConstraint.anchor = GridBagConstraints.NORTHWEST;
+ aConstraint.insets = new Insets(2,2,2,2);
+ aConstraint.gridy = 0;
+ aConstraint.gridx = 0;
+
+ JLabel laFont = new JLabel("Font" );
+ JLabel laSize = new JLabel("Size" );
+ JLabel laBold = new JLabel("Bold" );
+ JLabel laUnderline = new JLabel("Underline");
+ JLabel laItalic = new JLabel("Italic" );
+
+ m_laFontValue = new JLabel();
+ m_laSizeValue = new JLabel();
+ m_laBoldValue = new JLabel();
+ m_laUnderlineValue = new JLabel();
+ m_laItalicValue = new JLabel();
+
+ aConstraint.gridx = 0;
+ this.add( laFont, aConstraint );
+ aConstraint.gridx = 1;
+ this.add( m_laFontValue, aConstraint );
+
+ ++aConstraint.gridy;
+
+ aConstraint.gridx = 0;
+ this.add( laSize, aConstraint );
+ aConstraint.gridx = 1;
+ this.add( m_laSizeValue, aConstraint );
+
+ ++aConstraint.gridy;
+
+ aConstraint.gridx = 0;
+ this.add( laSize, aConstraint );
+ aConstraint.gridx = 1;
+ this.add( m_laSizeValue, aConstraint );
+
+ ++aConstraint.gridy;
+
+ aConstraint.gridx = 0;
+ this.add( laBold, aConstraint );
+ aConstraint.gridx = 1;
+ this.add( m_laBoldValue, aConstraint );
+
+ ++aConstraint.gridy;
+
+ aConstraint.gridx = 0;
+ this.add( laUnderline, aConstraint );
+ aConstraint.gridx = 1;
+ this.add( m_laUnderlineValue, aConstraint );
+
+ ++aConstraint.gridy;
+
+ aConstraint.gridx = 0;
+ this.add( laItalic, aConstraint );
+ aConstraint.gridx = 1;
+ this.add( m_laItalicValue, aConstraint );
+
+ m_laFontValue.setEnabled (false);
+ m_laSizeValue.setEnabled (false);
+ m_laBoldValue.setEnabled (false);
+ m_laItalicValue.setEnabled (false);
+ m_laUnderlineValue.setEnabled(false);
+
+ m_laFontValue.setText (FONT_OFF );
+ m_laSizeValue.setText (SIZE_OFF );
+ m_laBoldValue.setText (BOLD_OFF );
+ m_laItalicValue.setText (ITALIC_OFF );
+ m_laUnderlineValue.setText(UNDERLINE_OFF);
+ }
+
+ // ____________________
+
+ /**
+ * Set new frame for this view and start listening for events imedatly.
+ * We create one status listener for every control we whish to update.
+ * And because the environment of the frame can be changed - these
+ * listener refresh himself internaly for frame action events too.
+ * So we register it as such frame action listener only here.
+ * Rest is done automaticly ...
+ *
+ * @param xFrame
+ * will be used as source of possible status events
+ */
+ public void setFrame(com.sun.star.frame.XFrame xFrame)
+ {
+ if (xFrame==null)
+ return;
+
+ // create some listener on given frame for available status events
+ // Created listener instances will register herself on this frame and
+ // show her received informations automaticly on setted UI controls.
+ m_aFontListener = new StatusListener(m_laFontValue ,FONT_ON ,FONT_OFF ,xFrame, FEATUREURL_FONT );
+ m_aSizeListener = new StatusListener(m_laSizeValue ,SIZE_ON ,SIZE_OFF ,xFrame, FEATUREURL_SIZE );
+ m_aBoldListener = new StatusListener(m_laBoldValue ,BOLD_ON ,BOLD_OFF ,xFrame, FEATUREURL_BOLD );
+ m_aItalicListener = new StatusListener(m_laItalicValue ,ITALIC_ON ,ITALIC_OFF ,xFrame, FEATUREURL_ITALIC );
+ m_aUnderlineListener = new StatusListener(m_laUnderlineValue,UNDERLINE_ON,UNDERLINE_OFF,xFrame, FEATUREURL_UNDERLINE);
+
+ m_aFontListener.startListening();
+ m_aSizeListener.startListening();
+ m_aBoldListener.startListening();
+ m_aItalicListener.startListening();
+ m_aUnderlineListener.startListening();
+ }
+
+ // ____________________
+
+ /**
+ * If this java application shutdown - we must cancel all current existing
+ * listener connections. Otherwhise the office will run into some
+ * DisposedExceptions if it tries to use these forgotten listener references.
+ * And of course it can die doing that.
+ * We are registered at a central object to be informed if the VM will exit.
+ * So we can react.
+ */
+ public void shutdown()
+ {
+ m_aFontListener.shutdown();
+ m_aSizeListener.shutdown();
+ m_aBoldListener.shutdown();
+ m_aItalicListener.shutdown();
+ m_aUnderlineListener.shutdown();
+
+ m_aFontListener = null;
+ m_aSizeListener = null;
+ m_aBoldListener = null;
+ m_aItalicListener = null;
+ m_aUnderlineListener = null;
+ }
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/ViewContainer.java b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/ViewContainer.java
new file mode 100644
index 000000000000..a2ff9886516d
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/ViewContainer.java
@@ -0,0 +1,275 @@
+/*************************************************************************
+ *
+ * $RCSfile: ViewContainer.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:40:33 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+// __________ Imports __________
+
+import com.sun.star.uno.UnoRuntime;
+
+import java.lang.*;
+import java.util.*;
+
+// __________ Implementation __________
+
+/**
+ * It's implement a static container which hold
+ * all opened documents and her views alive.
+ * It's possible to register/deregister such views,
+ * to get information about these and it provides
+ * some global functionality - like termination of
+ * this demo application.
+ *
+ * @author Andreas Schl&uuml;ns
+ * @created 01.03.2002 08:42
+ */
+public class ViewContainer extends Thread
+{
+ // ____________________
+
+ /**
+ * provides a singleton view container
+ * Neccessary for terminate(9 functionality to be able
+ * to call Runtime.runFinilization().
+ *
+ * @return a reference to the singleton ViewContainer instance
+ */
+ public static synchronized ViewContainer getGlobalContainer()
+ {
+ if (maSingleton==null)
+ maSingleton=new ViewContainer();
+ return maSingleton;
+ }
+
+ // ____________________
+
+ /**
+ * ctor
+ * It's private - because nobody should create any instance
+ * expect the only global one, which wil be created by ourself!
+ */
+ private ViewContainer()
+ {
+ mlViews = new Vector();
+ mlListener = new Vector();
+ mbShutdownActive = false ;
+ Runtime.getRuntime().addShutdownHook(this);
+ }
+
+ // ____________________
+
+ /**
+ * This register a new view inside this global container
+ * (if it doesnt already exist).
+ *
+ * @param aView view which whish to be registered inside this container
+ */
+ public void addView(Object aView)
+ {
+ synchronized(mlViews)
+ {
+ if(mlViews.contains(aView)==false)
+ mlViews.add(aView);
+ }
+ }
+
+ // ____________________
+
+ /**
+ * This deregister a view from this global container.
+ * Normaly it should be the last reference to the view
+ * and her finalize() method should be called.
+ * If last view will be closed here - we terminate these
+ * java application too. Because there is no further
+ * visible frame anymore.
+ *
+ * @param aView
+ * view object which wish to be deregistered
+ */
+ public void removeView(Object aView)
+ {
+ int nViewCount = 0;
+ synchronized(mlViews)
+ {
+ if(mlViews.contains(aView)==true)
+ mlViews.remove(aView);
+
+ nViewCount = mlViews.size();
+
+ if (nViewCount<1)
+ mlViews = null;
+ }
+ // If this view is a registered shutdown listener on this view container
+ // too, we must call his interface and forget him as possible listener.
+ // It's neccessary to guarantee his dead ...
+ boolean bShutdownView = false;
+ synchronized(mlListener)
+ {
+ bShutdownView = mlListener.contains(aView);
+ if (bShutdownView==true)
+ mlListener.remove(aView);
+ }
+ if (bShutdownView==true)
+ ((IShutdownListener)aView).shutdown();
+
+ // We use a system.exit() to finish the whole application.
+ // And further we have registered THIS instance as a possible shutdown
+ // hook at the runtime class. So our run() method will be called.
+ // Teh our view container should be empty - but
+ // our listener container can include some references.
+ // These objects wich to be informed then and release e.g. some
+ // remote references.
+ if (nViewCount<1)
+ {
+ boolean bNeccessary = false;
+ synchronized(this)
+ {
+ bNeccessary = ! mbShutdownActive;
+ }
+ if (bNeccessary==true)
+ {
+ System.out.println("call exit(0)!");
+ System.exit(0);
+ }
+ }
+ }
+
+ // ____________________
+
+ /**
+ * add/remove listener for possibe shutdown events
+ */
+ public void addListener( IShutdownListener rListener )
+ {
+ synchronized(mlListener)
+ {
+ if ( ! mlListener.contains(rListener) )
+ mlListener.add(rListener);
+ }
+ }
+
+ // ____________________
+
+ public void removeListener( IShutdownListener rListener )
+ {
+ synchronized(mlListener)
+ {
+ if ( mlListener.contains(rListener) )
+ mlListener.remove(rListener);
+ }
+ }
+
+ // ____________________
+
+ /**
+ * Is called from current runtime system of the java machine
+ * on shutdown. We inform all current registered listener and
+ * views. They should deinitialize her internal things then.
+ */
+ public void run()
+ {
+ synchronized(this)
+ {
+ if (mbShutdownActive)
+ return;
+ mbShutdownActive=true;
+ }
+
+ while( true )
+ {
+ IShutdownListener aListener = null;
+ synchronized(mlListener)
+ {
+ try{
+ aListener = (IShutdownListener)mlListener.firstElement();
+ } catch(java.util.NoSuchElementException exEmpty) {}
+ }
+ if (aListener==null)
+ break;
+
+ aListener.shutdown();
+ // May this listener has dergeistered himself.
+ // But if not we must do it for him. Our own
+ // method "removeListener()" ignore requests for
+ // already gone listener objects.
+ removeListener(aListener);
+ }
+
+ if (mlViews!=null)
+ {
+ synchronized(mlViews)
+ {
+ mlViews.clear();
+ mlViews = null;
+ }
+ }
+
+ if (mlListener!=null)
+ {
+ synchronized(mlListener)
+ {
+ mlListener.clear();
+ mlListener = null;
+ }
+ }
+ }
+
+ // ____________________
+
+ /**
+ * @const BASICNAME it's used to create uinque names for all regieterd views
+ */
+ private static final String BASICNAME = "Document View ";
+
+ // ____________________
+
+ /**
+ * @member mbInplace indicates using of inplace office frames instead of outplace ones
+ * @member maSingleton singleton instance of this view container
+ * @member mlViews list of all currently registered document views
+ * @member mlListener list of all currently registered shutdown listener
+ * @member mbShutdownActive if this shutdown hook already was started it's not a good idea to
+ * call System.exit() again for other conditions.
+ * We supress it by using this variable!
+ */
+ public static boolean mbInplace = false ;
+ private static ViewContainer maSingleton = null ;
+ private Vector mlViews ;
+ private Vector mlListener ;
+ private boolean mbShutdownActive ;
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/unix/Makefile b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/unix/Makefile
new file mode 100644
index 000000000000..09726249c34b
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/unix/Makefile
@@ -0,0 +1,79 @@
+#*************************************************************************
+#
+# $RCSfile: Makefile,v $
+#
+# $Revision: 1.5 $
+#
+# last change: $Author: rt $ $Date: 2005-01-31 16:40:47 $
+#
+# The Contents of this file are made available subject to the terms of
+# the BSD license.
+#
+# Copyright (c) 2003 by Sun Microsystems, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+#**************************************************************************
+
+# Builds the OfficeDevDesktopEnvironment native library of the Developers Guide.
+
+PRJ=../../../../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+include $(SETTINGS)/dk.mk
+
+# Define non-platform/compiler specific settings
+SHL_NAME=nativeview
+SHL_LIBRARY=$(SHAREDLIB_OUT)/$(SHAREDLIB_PRE)$(SHL_NAME).$(SHAREDLIB_EXT)
+
+OUT_SHL_SLO=$(OUT_SLO)/nativeview
+
+CFILES = nativeview.c
+
+SLOFILES = $(patsubst %.c,$(OUT_SHL_SLO)/%.$(OBJ_EXT),$(CFILES))
+
+
+# Targets
+.PHONY: ALL
+ALL : $(SHL_LIBRARY)
+
+include $(SETTINGS)/stdtarget.mk
+
+$(OUT_SHL_SLO)/%.$(OBJ_EXT) : %.c
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(CC) $(CC_FLAGS) $(CC_INCLUDES) $(SDK_JAVA_INCLUDES) $(CC_DEFINES) $(CC_OUTPUT_SWITCH)$(subst /,$(PS),$@) $<
+
+$(SHAREDLIB_OUT)/$(SHAREDLIB_PRE)$(SHL_NAME).$(SHAREDLIB_EXT) : $(SLOFILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(LINK) $(LIBRARY_LINK_FLAGS) $(LINK_LIBS) $(LINK_JAVA_LIBS) -o $@ $< \
+ -ljawt $(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) $(STLPORTLIB) $(STDC++LIB)
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_SHL_SLO))
+ -$(DEL) $(subst /,$(PS),$(SHAREDLIB_OUT))$(PS)*$(SHL_NAME)*.*
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/unix/nativeview.c b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/unix/nativeview.c
new file mode 100644
index 000000000000..ba06d3fb2231
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/unix/nativeview.c
@@ -0,0 +1,117 @@
+/*************************************************************************
+ *
+ * $RCSfile: nativeview.c,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:41:12 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Intrinsic.h>
+
+#include "jawt.h"
+#include "jawt_md.h"
+#include "nativeview.h"
+
+#define MY_ASSERT(X,S) if (!X) { fprintf(stderr,S); return 0L;}
+
+#define SYSTEM_WIN32 1
+#define SYSTEM_WIN16 2
+#define SYSTEM_JAVA 3
+#define SYSTEM_OS2 4
+#define SYSTEM_MAC 5
+#define SYSTEM_XWINDOW 6
+
+/*****************************************************************************/
+/*
+ * Class: NativeView
+ * Method: getNativeWindowSystemType
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_NativeView_getNativeWindowSystemType
+ (JNIEnv * env, jobject obj_this)
+{
+ return (SYSTEM_XWINDOW);
+}
+
+/*****************************************************************************/
+/*
+ * Class: NativeView
+ * Method: getNativeWindow
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_NativeView_getNativeWindow
+ (JNIEnv * env, jobject obj_this)
+{
+ jboolean result ;
+ jint lock ;
+ JAWT awt ;
+ JAWT_DrawingSurface* ds ;
+ JAWT_DrawingSurfaceInfo* dsi ;
+ JAWT_X11DrawingSurfaceInfo* dsi_x11 ;
+ Drawable drawable;
+ Display* display ;
+
+ /* Get the AWT */
+ awt.version = JAWT_VERSION_1_3;
+ result = JAWT_GetAWT(env, &awt);
+ MY_ASSERT(result != JNI_FALSE,"wrong jawt version");
+
+ /* Get the drawing surface */
+ if ((ds = awt.GetDrawingSurface(env, obj_this)) == NULL)
+ return 0L;
+
+ /* Lock the drawing surface */
+ lock = ds->Lock(ds);
+ MY_ASSERT((lock & JAWT_LOCK_ERROR)==0,"can't lock the drawing surface");
+
+ /* Get the drawing surface info */
+ dsi = ds->GetDrawingSurfaceInfo(ds);
+
+ /* Get the platform-specific drawing info */
+ dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo;
+ drawable = dsi_x11->drawable;
+ display = dsi_x11->display;
+
+ /* Free the drawing surface info */
+ ds->FreeDrawingSurfaceInfo(dsi);
+ /* Unlock the drawing surface */
+ ds->Unlock(ds);
+ /* Free the drawing surface */
+ awt.FreeDrawingSurface(ds);
+
+ return ((jlong)drawable);
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/unix/nativeview.h b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/unix/nativeview.h
new file mode 100644
index 000000000000..9cd5f2e7d69b
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/unix/nativeview.h
@@ -0,0 +1,69 @@
+/*************************************************************************
+ *
+ * $RCSfile: nativeview.h,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:41:26 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class org_openoffice_OpenOffice */
+
+#ifndef _Included_NativeView
+#define _Included_NativeView
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class: org_openoffice_OpenOffice
+ * Method: getNativeWindowSystemType
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_NativeView_getNativeWindowSystemType
+ (JNIEnv *, jobject);
+
+/*
+ * Class: org_openoffice_OpenOffice
+ * Method: getNativeWindow
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_NativeView_getNativeWindow
+ (JNIEnv *, jobject);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/windows/Makefile b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/windows/Makefile
new file mode 100644
index 000000000000..7a0f16e6a687
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/windows/Makefile
@@ -0,0 +1,87 @@
+#*************************************************************************
+#
+# $RCSfile: Makefile,v $
+#
+# $Revision: 1.4 $
+#
+# last change: $Author: rt $ $Date: 2004-05-18 13:25:26 $
+#
+# The Contents of this file are made available subject to the terms of
+# the BSD license.
+#
+# Copyright (c) 2003 by Sun Microsystems, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+#**************************************************************************
+
+# Builds the OfficeDevDesktopEnvironment native library of the Developers Guide.
+
+PRJ=../../../../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+include $(SETTINGS)/dk.mk
+
+# Define non-platform/compiler specific settings
+SHL_NAME=nativeview
+SHL_LIBRARY=$(SHAREDLIB_OUT)/$(SHAREDLIB_PRE)$(SHL_NAME).$(SHAREDLIB_EXT)
+
+OUT_SHL_SLO=$(OUT_SLO)/nativeview
+OUT_SHL_MISC=$(OUT_MISC)/nativeview
+
+CFILES = nativeview.c
+
+SLOFILES = $(patsubst %.c,$(OUT_SHL_SLO)/%.$(OBJ_EXT),$(CFILES))
+
+# Targets
+.PHONY: ALL
+ALL : \
+ $(SHL_LIBRARY)
+
+include $(SETTINGS)/stdtarget.mk
+
+$(OUT_SHL_SLO)/%.$(OBJ_EXT) : %.c
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(CC) $(CC_FLAGS) $(CC_INCLUDES) $(SDK_JAVA_INCLUDES) $(CC_DEFINES) $(CC_OUTPUT_SWITCH)$(subst /,$(PS),$@) $<
+
+$(OUT_SHL_MISC)/%.def : exports.dxp
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo EXPORTS > $(OUT_SHL_MISC)/$(SHL_NAME).def
+ $(CAT) exports.dxp >> $(OUT_SHL_MISC)/$(SHL_NAME).def
+
+$(SHAREDLIB_OUT)/$(SHAREDLIB_PRE)$(SHL_NAME).$(SHAREDLIB_EXT) : $(SLOFILES) $(OUT_SHL_MISC)/$(SHL_NAME).def
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(LINK) $(LIBRARY_LINK_FLAGS) /OUT:$@ /MAP:$(OUT_SHL_MISC)/$(SHL_NAME).map \
+ /DEF:$(OUT_SHL_MISC)/$(SHL_NAME).def $(LINK_JAVA_LIBS) \
+ $(SLOFILES) jawt.lib msvcrt.lib kernel32.lib user32.lib
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_SHL_SLO))
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_SHL_MISC))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$(SHAREDLIB_OUT))$(PS)*$(SHL_NAME)*.*)
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/windows/nativeview.c b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/windows/nativeview.c
new file mode 100644
index 000000000000..dafce5419b47
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/windows/nativeview.c
@@ -0,0 +1,184 @@
+/*************************************************************************
+ *
+ * $RCSfile: nativeview.c,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:42:03 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+#include <windows.h>
+
+#include "jawt.h"
+#include "jawt_md.h"
+#include "NativeView.h"
+
+#define MY_ASSERT(X,S) if (!X) { fprintf(stderr,"%s\n",S); return 0L;}
+
+#define SYSTEM_WIN32 1
+#define SYSTEM_WIN16 2
+#define SYSTEM_JAVA 3
+#define SYSTEM_OS2 4
+#define SYSTEM_MAC 5
+#define SYSTEM_XWINDOW 6
+
+// property name to register own window procedure on hwnd
+#define OLD_PROC_KEY "oldwindowproc"
+// signature of this window procedure
+static LRESULT APIENTRY NativeViewWndProc( HWND , UINT , WPARAM , LPARAM );
+
+/*****************************************************************************
+ *
+ * Class : NativeView
+ * Method : getNativeWindowSystemType
+ * Signature : ()I
+ * Description: returns an identifier for the current operating system
+ */
+JNIEXPORT jint JNICALL Java_NativeView_getNativeWindowSystemType
+ (JNIEnv * env, jobject obj_this)
+{
+ return (SYSTEM_WIN32);
+}
+
+/*****************************************************************************
+ *
+ * Class : NativeView
+ * Method : getNativeWindow
+ * Signature : ()J
+ * Description: returns the native systemw window handle of this object
+ */
+JNIEXPORT jlong JNICALL Java_NativeView_getNativeWindow
+ (JNIEnv * env, jobject obj_this)
+{
+ jboolean result ;
+ jint lock ;
+ JAWT awt ;
+ JAWT_DrawingSurface* ds ;
+ JAWT_DrawingSurfaceInfo* dsi ;
+ JAWT_Win32DrawingSurfaceInfo* dsi_win ;
+ HDC hdc ;
+ HWND hWnd ;
+ LONG hFuncPtr;
+
+ /* Get the AWT */
+ awt.version = JAWT_VERSION_1_3;
+ result = JAWT_GetAWT(env, &awt);
+ MY_ASSERT(result!=JNI_FALSE,"wrong jawt version");
+
+ /* Get the drawing surface */
+ if ((ds = awt.GetDrawingSurface(env, obj_this)) == NULL)
+ return 0L;
+
+ /* Lock the drawing surface */
+ lock = ds->Lock(ds);
+ MY_ASSERT((lock & JAWT_LOCK_ERROR)==0,"can't lock the drawing surface");
+
+ /* Get the drawing surface info */
+ dsi = ds->GetDrawingSurfaceInfo(ds);
+
+ /* Get the platform-specific drawing info */
+ dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
+ hdc = dsi_win->hdc;
+ hWnd = dsi_win->hwnd;
+
+ /* Free the drawing surface info */
+ ds->FreeDrawingSurfaceInfo(dsi);
+ /* Unlock the drawing surface */
+ ds->Unlock(ds);
+ /* Free the drawing surface */
+ awt.FreeDrawingSurface(ds);
+
+ /* Register own window procedure
+ Do it one times only! Otherwhise
+ multiple instances will be registered
+ and calls on such construct produce
+ a stack overflow.
+ */
+ if (GetProp( hWnd, OLD_PROC_KEY )==0)
+ {
+ hFuncPtr = SetWindowLong( hWnd, GWL_WNDPROC, (DWORD)NativeViewWndProc );
+ SetProp( hWnd, OLD_PROC_KEY, (HANDLE)hFuncPtr );
+ }
+
+ return ((jlong)hWnd);
+}
+
+/*****************************************************************************
+ *
+ * Class : -
+ * Method : NativeViewWndProc
+ * Signature : -
+ * Description: registered window handler to intercept window messages between
+ * java and office process
+ */
+static LRESULT APIENTRY NativeViewWndProc(
+ HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ HANDLE hFuncPtr;
+
+ /* resize new created child window to fill out the java window complete */
+ if (uMsg==WM_PARENTNOTIFY)
+ {
+ if (wParam == WM_CREATE)
+ {
+ RECT rect;
+ HWND hChild = (HWND) lParam;
+
+ GetClientRect(hWnd, &rect);
+
+ SetWindowPos(hChild,
+ NULL,
+ rect.left,
+ rect.top,
+ rect.right - rect.left,
+ rect.bottom - rect.top,
+ SWP_NOZORDER);
+ }
+ }
+ /* handle normal resize events */
+ else if(uMsg==WM_SIZE)
+ {
+ WORD newHeight = HIWORD(lParam);
+ WORD newWidth = LOWORD(lParam);
+ HWND hChild = GetWindow(hWnd, GW_CHILD);
+
+ if (hChild != NULL)
+ SetWindowPos(hChild, NULL, 0, 0, newWidth, newHeight, SWP_NOZORDER);
+ }
+
+ /* forward request to original handler which is intercepted by this window procedure */
+ hFuncPtr = GetProp(hWnd, OLD_PROC_KEY);
+ MY_ASSERT(hFuncPtr,"lost original window proc handler");
+ return CallWindowProc( hFuncPtr, hWnd, uMsg, wParam, lParam);
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/windows/nativeview.h b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/windows/nativeview.h
new file mode 100644
index 000000000000..1da98ba3158e
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/windows/nativeview.h
@@ -0,0 +1,69 @@
+/*************************************************************************
+ *
+ * $RCSfile: nativeview.h,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:42:16 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class org_openoffice_OpenOffice */
+
+#ifndef _Included_NativeView
+#define _Included_NativeView
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class: org_openoffice_OpenOffice
+ * Method: getNativeWindowSystemType
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_NativeView_getNativeWindowSystemType
+ (JNIEnv *, jobject);
+
+/*
+ * Class: org_openoffice_OpenOffice
+ * Method: getNativeWindow
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_NativeView_getNativeWindow
+ (JNIEnv *, jobject);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DisableCommands/DisableCommandsTest.java b/odk/examples/DevelopersGuide/OfficeDev/DisableCommands/DisableCommandsTest.java
new file mode 100644
index 000000000000..97d292b143bf
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DisableCommands/DisableCommandsTest.java
@@ -0,0 +1,417 @@
+/*************************************************************************
+ *
+ * $RCSfile: DisableCommandsTest.java,v $
+ *
+ * $Revision: 1.7 $
+ *
+ * last change: $Author: vg $ $Date: 2006-03-15 09:28:40 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+import com.sun.star.util.XURLTransformer;
+import com.sun.star.frame.XDesktop;
+import com.sun.star.frame.XComponentLoader;
+import com.sun.star.text.XTextDocument;
+
+/*
+ *
+ * @author Carsten Driesner
+ * Provides example code how to enable/disable
+ * commands.
+ */
+public class DisableCommandsTest extends java.lang.Object {
+
+ /*
+ * A list of command names
+ */
+ final static private String[] aCommandURLTestSet =
+ {
+ new String( "Open" ),
+ new String( "About" ),
+ new String( "SelectAll" ),
+ new String( "Quit" ),
+ };
+
+ private static XComponentContext xRemoteContext = null;
+ private static XMultiComponentFactory xRemoteServiceManager = null;
+ private static XURLTransformer xTransformer = null;
+ private static XMultiServiceFactory xConfigProvider = null;
+
+ /*
+ * @param args the command line arguments
+ */
+ public static void main(String[] args) {
+
+ try {
+ // get the remote office context. If necessary a new office
+ // process is started
+ xRemoteContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+ System.out.println("Connected to a running office ...");
+ xRemoteServiceManager = xRemoteContext.getServiceManager();
+
+ Object transformer = xRemoteServiceManager.createInstanceWithContext(
+ "com.sun.star.util.URLTransformer", xRemoteContext );
+ xTransformer = (com.sun.star.util.XURLTransformer)
+ UnoRuntime.queryInterface(com.sun.star.util.XURLTransformer.class,
+ transformer );
+
+ Object configProvider = xRemoteServiceManager.createInstanceWithContext(
+ "com.sun.star.configuration.ConfigurationProvider",
+ xRemoteContext );
+ xConfigProvider = (com.sun.star.lang.XMultiServiceFactory)
+ UnoRuntime.queryInterface(
+ com.sun.star.lang.XMultiServiceFactory.class, configProvider );
+
+ // create a new test document
+ Object oDesktop = xRemoteServiceManager.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xRemoteContext);
+
+ XComponentLoader xCompLoader =(XComponentLoader)
+ UnoRuntime.queryInterface(XComponentLoader.class, oDesktop);
+
+ com.sun.star.lang.XComponent xComponent =
+ xCompLoader.loadComponentFromURL("private:factory/swriter",
+ "_blank", 0, new com.sun.star.beans.PropertyValue[0]);
+ {
+ XTextDocument xDoc =(XTextDocument)
+ UnoRuntime.queryInterface(XTextDocument.class, xComponent);
+ xDoc.getText().setString("You can now check the disabled commands. The "
+ +"following commands are disabled:\n\n"
+ +" Open...\n Exit\n Select All\n "
+ +"About StarOffice|OpenOffice\n\nPress "
+ + "\"return\" in the shell where you have "
+ + "started the example to enable the "
+ + "commands!\n\nCheck the commands again and "
+ + "press once more \"return\" to finish the "
+ + "example and close the document.");
+
+ // ensure that the document content is optimal visible
+ com.sun.star.frame.XModel xModel =
+ (com.sun.star.frame.XModel)UnoRuntime.queryInterface(
+ com.sun.star.frame.XModel.class, xDoc);
+ // get the frame for later usage
+ com.sun.star.frame.XFrame xFrame =
+ xModel.getCurrentController().getFrame();
+
+ com.sun.star.view.XViewSettingsSupplier xViewSettings =
+ (com.sun.star.view.XViewSettingsSupplier)UnoRuntime.queryInterface(
+ com.sun.star.view.XViewSettingsSupplier.class,
+ xModel.getCurrentController());
+ xViewSettings.getViewSettings().setPropertyValue(
+ "ZoomType", new Short((short)0));
+ }
+ // test document will be closed later
+
+ // First we need a defined starting point. So we have to remove
+ // all commands from the disabled set!
+ enableCommands();
+
+ // Check if the commands are usable
+ testCommands( false );
+
+ // Disable the commands
+ disableCommands();
+
+ // Now the commands shouldn't be usable anymore
+ testCommands( true );
+
+ // you can now check the test document and see which commands are
+ // disabled
+ System.out.println("\nYou can now check the disabled commands.\n"
+ +"Please press 'return' to enable the commands!");
+ waitForUserInput();
+
+ // Remove disable commands to make Office usable again
+ enableCommands();
+
+ // you can check the test document again and see that the commands
+ // are enabled now
+ System.out.println("Check again the now enabled commands.\n"
+ +"Please press 'return' to finish the example and "
+ +"close the document!");
+ waitForUserInput();
+
+ // close test document
+ com.sun.star.util.XCloseable xCloseable = (com.sun.star.util.XCloseable)
+ UnoRuntime.queryInterface(com.sun.star.util.XCloseable.class,
+ xComponent );
+
+ if (xCloseable != null ) {
+ xCloseable.close(false);
+ } else
+ {
+ xComponent.dispose();
+ }
+ }
+ catch (java.lang.Exception e){
+ e.printStackTrace();
+ }
+ finally {
+ System.exit(0);
+ }
+ }
+
+ /**
+ * Wait for user input -> until the user press 'return'
+ */
+ private static void waitForUserInput() throws java.io.IOException {
+
+ java.io.BufferedReader reader
+ = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
+
+ reader.read();
+ }
+
+ /**
+ * Test the commands that we enabled/disabled
+ */
+ private static void testCommands( boolean bDisabledCmds )
+ throws com.sun.star.uno.Exception
+ {
+ // We need the desktop to get access to the current frame
+ Object desktop = xRemoteServiceManager.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xRemoteContext );
+ com.sun.star.frame.XDesktop xDesktop = (com.sun.star.frame.XDesktop)
+ UnoRuntime.queryInterface(com.sun.star.frame.XDesktop.class, desktop );
+ com.sun.star.frame.XFrame xFrame = xDesktop.getCurrentFrame();
+ com.sun.star.frame.XDispatchProvider xDispatchProvider = null;
+ if ( xFrame != null )
+ {
+ // We have a frame. Now we need access to the dispatch provider.
+ xDispatchProvider =
+ (com.sun.star.frame.XDispatchProvider)UnoRuntime.queryInterface(
+ com.sun.star.frame.XDispatchProvider.class, xFrame );
+ if ( xDispatchProvider != null )
+ {
+ // As we have the dispatch provider we can now check if we get
+ // a dispatch object or not.
+ for ( int n = 0; n < aCommandURLTestSet.length; n++ )
+ {
+ // Prepare the URL
+ com.sun.star.util.URL[] aURL = new com.sun.star.util.URL[1];
+ aURL[0] = new com.sun.star.util.URL();
+ com.sun.star.frame.XDispatch xDispatch = null;
+
+ aURL[0].Complete = ".uno:" + aCommandURLTestSet[n];
+ xTransformer.parseSmart( aURL, ".uno:" );
+
+ // Try to get a dispatch object for our URL
+ xDispatch = xDispatchProvider.queryDispatch( aURL[0], "", 0 );
+
+ if ( xDispatch != null )
+ {
+ if ( bDisabledCmds )
+ System.out.println(
+ "Something is wrong, I got dispatch object for "
+ + aURL[0].Complete );
+ else
+ System.out.println( "Ok, dispatch object for "
+ + aURL[0].Complete );
+ }
+ else
+ {
+ if ( !bDisabledCmds )
+ System.out.println("Something is wrong, I cannot get dispatch object for " + aURL[0].Complete );
+ else
+ System.out.println( "Ok, no dispatch object for "
+ + aURL[0].Complete );
+ }
+ resetURL( aURL[0] );
+ }
+ }
+ else
+ System.out.println( "Couldn't get XDispatchProvider from Frame!" );
+ }
+ else
+ System.out.println( "Couldn't get current Frame from Desktop!" );
+ }
+
+ /**
+ * Ensure that there are no disabled commands in the user layer. The
+ * implementation removes all commands from the disabled set!
+ */
+ private static void enableCommands() {
+ // Set the root path for our configuration access
+ com.sun.star.beans.PropertyValue[] lParams =
+ new com.sun.star.beans.PropertyValue[1];
+
+ lParams[0] = new com.sun.star.beans.PropertyValue();
+ lParams[0].Name = new String("nodepath");
+ lParams[0].Value = "/org.openoffice.Office.Commands/Execute/Disabled";
+
+ try {
+ // Create configuration update access to have write access to the
+ // configuration
+ Object xAccess = xConfigProvider.createInstanceWithArguments(
+ "com.sun.star.configuration.ConfigurationUpdateAccess",
+ lParams );
+
+ com.sun.star.container.XNameAccess xNameAccess =
+ (com.sun.star.container.XNameAccess)UnoRuntime.queryInterface(
+ com.sun.star.container.XNameAccess.class, xAccess );
+
+ if ( xNameAccess != null ) {
+ // We need the XNameContainer interface to remove the nodes by name
+ com.sun.star.container.XNameContainer xNameContainer =
+ (com.sun.star.container.XNameContainer)
+ UnoRuntime.queryInterface(
+ com.sun.star.container.XNameContainer.class, xAccess );
+
+ // Retrieves the names of all Disabled nodes
+ String[] aCommandsSeq = xNameAccess.getElementNames();
+ for ( int n = 0; n < aCommandsSeq.length; n++ ) {
+ try {
+ // remove the node
+ xNameContainer.removeByName( aCommandsSeq[n] );
+ }
+ catch ( com.sun.star.lang.WrappedTargetException e ) {
+ }
+ catch ( com.sun.star.container.NoSuchElementException e ) {
+ }
+ }
+ }
+
+ // Commit our changes
+ com.sun.star.util.XChangesBatch xFlush =
+ (com.sun.star.util.XChangesBatch)UnoRuntime.queryInterface(
+ com.sun.star.util.XChangesBatch.class, xAccess);
+
+ xFlush.commitChanges();
+ }
+ catch ( com.sun.star.uno.Exception e ) {
+ System.out.println( "Exception detected!" );
+ System.out.println( e );
+ }
+ }
+
+ /**
+ * Disable all commands defined in the aCommandURLTestSet array
+ */
+ private static void disableCommands() {
+ // Set the root path for our configuration access
+ com.sun.star.beans.PropertyValue[] lParams =
+ new com.sun.star.beans.PropertyValue[1];
+
+ lParams[0] = new com.sun.star.beans.PropertyValue();
+ lParams[0].Name = new String("nodepath");
+ lParams[0].Value = "/org.openoffice.Office.Commands/Execute/Disabled";
+
+ try {
+ // Create configuration update access to have write access to the
+ // configuration
+ Object xAccess = xConfigProvider.createInstanceWithArguments(
+ "com.sun.star.configuration.ConfigurationUpdateAccess",
+ lParams );
+
+ com.sun.star.lang.XSingleServiceFactory xSetElementFactory =
+ (com.sun.star.lang.XSingleServiceFactory)UnoRuntime.queryInterface(
+ com.sun.star.lang.XSingleServiceFactory.class, xAccess );
+
+ com.sun.star.container.XNameContainer xNameContainer =
+ (com.sun.star.container.XNameContainer)UnoRuntime.queryInterface(
+ com.sun.star.container.XNameContainer.class, xAccess );
+
+ if ( xSetElementFactory != null && xNameContainer != null ) {
+ Object[] aArgs = new Object[0];
+
+ for ( int i = 0; i < aCommandURLTestSet.length; i++ ) {
+ // Create the nodes with the XSingleServiceFactory of the
+ // configuration
+ Object xNewElement =
+ xSetElementFactory.createInstanceWithArguments( aArgs );
+
+ if ( xNewElement != null ) {
+ // We have a new node. To set the properties of the node
+ // we need the XPropertySet interface.
+ com.sun.star.beans.XPropertySet xPropertySet =
+ (com.sun.star.beans.XPropertySet)
+ UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class,
+ xNewElement );
+
+ if ( xPropertySet != null ) {
+ // Create a unique node name.
+ String aCmdNodeName = new String( "Command-" );
+ aCmdNodeName += i;
+
+ // Insert the node into the Disabled set
+ xPropertySet.setPropertyValue( "Command",
+ aCommandURLTestSet[i] );
+ xNameContainer.insertByName( aCmdNodeName,
+ xNewElement );
+ }
+ }
+ }
+
+ // Commit our changes
+ com.sun.star.util.XChangesBatch xFlush =
+ (com.sun.star.util.XChangesBatch)UnoRuntime.queryInterface(
+ com.sun.star.util.XChangesBatch.class, xAccess);
+ xFlush.commitChanges();
+ }
+ }
+ catch ( com.sun.star.uno.Exception e )
+ {
+ System.err.println( "Exception detected!" + e);
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * reset URL so it can be reused
+ *
+ * @param aURL
+ * the URL that should be reseted
+ */
+ private static void resetURL( com.sun.star.util.URL aURL )
+ {
+ aURL.Protocol = "";
+ aURL.User = "";
+ aURL.Password = "";
+ aURL.Server = "";
+ aURL.Port = 0;
+ aURL.Path = "";
+ aURL.Name = "";
+ aURL.Arguments = "";
+ aURL.Mark = "";
+ aURL.Main = "";
+ aURL.Complete = "";
+ }
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DisableCommands/Makefile b/odk/examples/DevelopersGuide/OfficeDev/DisableCommands/Makefile
new file mode 100644
index 000000000000..c9ca2fd074ca
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DisableCommands/Makefile
@@ -0,0 +1,98 @@
+#*************************************************************************
+#
+# $RCSfile: Makefile,v $
+#
+# $Revision: 1.6 $
+#
+# last change: $Author: rt $ $Date: 2005-03-29 12:11:36 $
+#
+# The Contents of this file are made available subject to the terms of
+# the BSD license.
+#
+# Copyright (c) 2003 by Sun Microsystems, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+#**************************************************************************
+
+# Builds the OfficeDevDisableCommandsTest example of the Developers Guide.
+
+PRJ=../../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+include $(SETTINGS)/dk.mk
+
+# Define non-platform/compiler specific settings
+EXAMPLE_NAME=OfficeDevDisableCommandsTest
+OUT_APP_CLASS = $(OUT_CLASS)/$(EXAMPLE_NAME)
+
+APP1_NAME=DisableCommandsTest
+APP1_JAR=$(OUT_APP_CLASS)/$(APP1_NAME).jar
+
+SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
+ $(PATH_SEPARATOR)$(OUT_APP_CLASS))
+
+
+# Targets
+.PHONY: ALL
+ALL : $(EXAMPLE_NAME)
+
+include $(SETTINGS)/stdtarget.mk
+
+$(OUT_APP_CLASS)/%.class : %.java
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_APP_CLASS) $<
+
+$(OUT_APP_CLASS)/%.mf :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo Main-Class: com.sun.star.lib.loader.Loader> $@
+ $(ECHOLINE)>> $@
+ @echo Name: com/sun/star/lib/loader/Loader.class>> $@
+ @echo Application-Class: $*>> $@
+
+$(OUT_APP_CLASS)/%.jar : $(OUT_APP_CLASS)/%.mf $(OUT_APP_CLASS)/%.class
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ +cd $(subst /,$(PS),$(OUT_APP_CLASS)) && $(SDK_JAR) cvfm $(@F) $*.mf $*.class
+ +$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES)
+
+$(APP1_JAR) : $(OUT_APP_CLASS)/$(APP1_NAME).mf $(OUT_APP_CLASS)/$(APP1_NAME).class
+
+$(EXAMPLE_NAME) : $(APP1_JAR)
+ @echo --------------------------------------------------------------------------------
+ @echo Please use the following command to execute the example!
+ @echo -
+ @echo $(MAKE) $(APP1_NAME).run
+ @echo --------------------------------------------------------------------------------
+
+%.run: $(OUT_APP_CLASS)/%.jar
+ $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $<
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_CLASS))
diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/AsciiReplaceFilter.java b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/AsciiReplaceFilter.java
new file mode 100644
index 000000000000..d784ced025d5
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/AsciiReplaceFilter.java
@@ -0,0 +1,739 @@
+/*************************************************************************
+ *
+ * $RCSfile: AsciiReplaceFilter.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:42:54 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+package OfficeDev.samples.Filter;
+
+import com.sun.star.lib.uno.helper.Factory;
+import com.sun.star.lib.uno.helper.WeakBase;
+import com.sun.star.registry.XRegistryKey;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.lang.XSingleComponentFactory;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.Type;
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.beans.PropertyValue;
+
+import com.sun.star.lang.XInitialization;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.container.XNamed;
+import com.sun.star.document.XImporter;
+import com.sun.star.document.XExporter;
+import com.sun.star.document.XFilter;
+
+
+import com.sun.star.lang.IllegalArgumentException;
+
+/*-************************************************************************
+ @title implements a filter to import pure ascii text files
+ @description This filter can use an existing In/OutputStream of given
+ MediaDescriptor or use an existing URL instead of that
+ to open the file directly. But for second case the local
+ file system will be used only. There is no support for remote.
+
+ During import/export special functionality can be used to
+ e.g. to change some characters inside the file content
+ or replace some strings (no using of regular expressions!).
+ User can decide at runtime which functionality realy should
+ be used by selecting it in an extra filter property dialog.
+
+ So we show how a filter works fro iport/export, use or create
+ streams and how a filter can offer properties for filtering
+ which can be edit by the user.
+ ************************************************************************-*/
+
+public class AsciiReplaceFilter
+{
+
+
+
+ public static class _AsciiReplaceFilter extends WeakBase
+ implements XInitialization ,
+ XServiceInfo ,
+ XNamed ,
+ XImporter ,
+ XExporter ,
+ XFilter
+ {
+ //______________________________
+ // const
+
+ // the supported service names, the first one being the service name of the component itself
+ public static final String[] m_serviceNames = { "com.sun.star.comp.ansifilter.AsciiReplaceFilter" , "com.sun.star.document.ImportFilter", "com.sun.star.document.ExportFilter" };
+
+ // filterprocess states
+ public static final int FILTERPROC_RUNS = 0;
+ public static final int FILTERPROC_BREAK = 1;
+ public static final int FILTERPROC_STOPPED = 2;
+
+ //______________________________
+ // member
+
+
+ /// The initial component context, that gives access to the service manager, supported singletons, ...
+ private XComponentContext m_Ctx;
+ /// The service manager, that gives access to all registered services and which is passed to the FilterOptions class for instantiating a ucb service
+ private XMultiComponentFactory m_xMCF;
+ /// we must provide our name
+ private String m_sInternalName;
+ /// saved document reference for import or export (depends on other member m_bImport!)
+ private com.sun.star.text.XTextDocument m_xDocument;
+ /// because we implement an import AND an export filter, we must know which one is required
+ private boolean m_bImport;
+ // we need a flag to cancel any running filter operation
+ private int m_nFilterProcState;
+
+ //______________________________
+ // native interface
+ /**
+ * special debug helper to get an idea how expensive
+ * the implemented filter operations are realy.
+ * May be usefully for own purposes.
+ *
+ * To see the output inside an office environment
+ * use "soffice ...params... >output.txt"
+ */
+ private long m_nStart;
+ private long m_nLast ;
+
+ private void measure( String sText )
+ {
+ long nNow = System.currentTimeMillis();
+ System.err.println(sText+"\t"+(nNow-m_nStart)+"\t"+(nNow-m_nLast));
+ m_nLast = nNow;
+ }
+
+ //______________________________
+ // native interface
+ /**
+ * The constructor to initialize every instance
+ *
+ * @param xCompContext
+ * the component context of the office
+ */
+ //ctor
+ public _AsciiReplaceFilter(XComponentContext Context )
+ {
+ measure("ctor started");
+ try
+ {
+ m_Ctx = Context ;
+ m_xMCF = m_Ctx.getServiceManager() ;
+ }
+ catch( Exception e )
+ {
+ e.printStackTrace();
+ }
+
+ // these are safe, thus no errorhandling needed:
+ m_sInternalName = new String() ;
+ m_xDocument = null ;
+ m_bImport = true ;
+ m_nFilterProcState = FILTERPROC_STOPPED ;
+
+ m_nLast = System.currentTimeMillis();
+ m_nStart = m_nLast;
+ }
+
+ //______________________________
+ // interface XInitialization
+ /**
+ * used for initializing after creation
+ * If an instance of this service is created by UNO we will be called
+ * automaticly after that to get optional parameters of this creation call.
+ * E.g.: The service com.sun.star.document.FilterFactory use such mechanism
+ * to pass our own configuration data to this instance.
+ *
+ * @param lArguments
+ * This array of arbitrary objects represent our own filter configuration
+ * and may optional given parameters of the createWithArguments() call.
+ *
+ * @throws Exception
+ * Every exception will not be handled, but will be
+ * passed to the caller.
+ */
+ public void initialize( Object[] lArguments ) throws com.sun.star.uno.Exception
+ {
+ measure("initialize {");
+
+ if (lArguments.length<1)
+ return;
+
+ // lArguments[0] = own configuration data
+ com.sun.star.beans.PropertyValue[] lConfig = (com.sun.star.beans.PropertyValue[])lArguments[0];
+
+ /*
+ // lArguments[1..n] = optional arguments of create request
+ for (int n=1; n<lArguments.length; ++n)
+ {
+ }
+ */
+
+ // analyze own configuration data for our own internal filter name!
+ // Important for generic filter services, which are registered more then once.
+ // They can use this information to find out, which specialization of it
+ // is required.
+ for (int i=0; i<lConfig.length; ++i)
+ {
+ if (lConfig[i].Name.equals("Name"))
+ {
+ synchronized(this)
+ {
+ try
+ {
+ m_sInternalName = AnyConverter.toString(lConfig[i].Value);
+ }
+ catch(com.sun.star.lang.IllegalArgumentException exConvert) {}
+ }
+ }
+ }
+
+ measure("} initialize");
+ }
+
+ //______________________________
+ // interface XNamed
+ /**
+ * For external user of us we must provide our internal filter name
+ * (which is registered inside configuration package TypeDetection).
+ * User will be able then to ask there for furthe information about us.
+ * Otherwhise we must implement a full featured XPropertySet ...
+ *
+ * @return our internal filter name of configuration
+ */
+ public String getName()
+ {
+ synchronized(this)
+ {
+ return m_sInternalName;
+ }
+ }
+
+ /**
+ * It's not allowed for us - neither very easy to change our internal
+ * name during runtime of an office. Because every filter name must
+ * be unambigous ...
+ * So we doesn't implement this method here.
+ */
+ public void setName( String sName )
+ {
+ }
+
+ //______________________________
+ // interface XImporter
+ /**
+ * This interface is used to tell us: "you will be used for importing a document".
+ * We must save the given model reference to use it inside our own filter request.
+ *
+ * @param xDocument
+ * the document model for importing
+ *
+ * @throw IllegalArgumentException
+ * if given document isn't the right one or seams to be corrupt
+ */
+ public void setTargetDocument( com.sun.star.lang.XComponent xDocument ) throws com.sun.star.lang.IllegalArgumentException
+ {
+ measure("setTargetDocument {");
+
+ if (xDocument==null)
+ throw new com.sun.star.lang.IllegalArgumentException("null reference detected");
+
+ com.sun.star.lang.XServiceInfo xInfo = (com.sun.star.lang.XServiceInfo)UnoRuntime.queryInterface(
+ com.sun.star.lang.XServiceInfo.class, xDocument);
+ if ( ! xInfo.supportsService("com.sun.star.text.TextDocument") )
+ throw new com.sun.star.lang.IllegalArgumentException( "wrong document type" );
+
+ // safe it as target document for import
+ // Don't forget to mark this filter used for importing too
+ synchronized(this)
+ {
+ m_xDocument = (com.sun.star.text.XTextDocument)UnoRuntime.queryInterface(
+ com.sun.star.text.XTextDocument.class, xDocument);
+ m_bImport = true;
+ }
+
+ measure("} setTargetDocument");
+ }
+
+ //______________________________
+ // interface XExporter
+ /**
+ * This interface is used to tell us: "you will be used for exporting a document".
+ * We must save the given model reference to use it inside our own filter request.
+ *
+ * @param xDocument
+ * the document model for exporting
+ *
+ * @throw IllegalArgumentException
+ * if given document isn't the right one or seams to be corrupt
+ */
+ public void setSourceDocument( com.sun.star.lang.XComponent xDocument ) throws com.sun.star.lang.IllegalArgumentException
+ {
+ measure("setSourceDocument {");
+
+ if (xDocument==null)
+ throw new com.sun.star.lang.IllegalArgumentException( "null reference given" );
+
+ com.sun.star.lang.XServiceInfo xInfo = (com.sun.star.lang.XServiceInfo)UnoRuntime.queryInterface(
+ com.sun.star.lang.XServiceInfo.class, xDocument);
+ if ( ! xInfo.supportsService("com.sun.star.text.TextDocument") )
+ throw new com.sun.star.lang.IllegalArgumentException( "wrong document type" );
+
+ // safe it as source document for export
+ // Don't forget to mark this filter used for exporting too
+ synchronized(this)
+ {
+ m_xDocument = (com.sun.star.text.XTextDocument)UnoRuntime.queryInterface(
+ com.sun.star.text.XTextDocument.class, xDocument);
+ m_bImport = false;
+ }
+
+ measure("} setSourceDocument");
+ }
+
+
+ //______________________________
+ // interface XFilter
+ /**
+ * Implements the real filter method. We detect if it must be an import or an export.
+ * Depends on that we use an existing stream (given inside the MediaDescriptor)
+ * or open it by using an URL (must be a part of the descriptor too).
+ *
+ * @param lDescriptor
+ * the MediaDescriptor which describes the document
+ *
+ * @return a bool value which describes if method was successfully or not.
+ */
+
+ public boolean filter( com.sun.star.beans.PropertyValue[] lDescriptor )
+ {
+ measure("filter {");
+
+ // first get state of filter operation (import/export)
+ // and try to create or get corresponding streams
+ // Means: analyze given MediaDescriptor
+ // By the way: use synchronized section to get some copies of other
+ // internal states too.
+ FilterOptions aOptions = null ;
+ boolean bImport = false;
+ com.sun.star.text.XTextDocument xText = null ;
+ synchronized(this)
+ {
+ aOptions = new FilterOptions(m_xMCF, m_Ctx, m_bImport, lDescriptor);
+ bImport = m_bImport;
+ xText = m_xDocument;
+ }
+
+ measure("options analyzed");
+
+ if (aOptions.isValid()==false)
+ return false;
+
+ // start real filtering
+ boolean bState = false;
+ if (bImport)
+ bState = implts_import( xText, aOptions );
+ else
+ bState = implts_export( xText, aOptions );
+
+ measure("} filter");
+
+ return bState;
+ }
+
+ /**
+ * Makes the filter process breakable. To do so the outside code may use threads.
+ * We use a internal "condition" variable wich is queried by the real filter method on
+ * every loop they do. So it's more a polling mechanism.
+ */
+ public void cancel()
+ {
+ measure("cancel {");
+
+ synchronized(this)
+ {
+ if (m_nFilterProcState==FILTERPROC_RUNS)
+ m_nFilterProcState=FILTERPROC_BREAK;
+ }
+
+ while (true)
+ {
+ synchronized(this)
+ {
+ if (m_nFilterProcState==FILTERPROC_STOPPED)
+ break;
+ }
+ }
+
+ measure("} cancel");
+ }
+
+ //______________________________
+ // private helper
+ /**
+ * This helper function imports a simple ascii text file into
+ * a text model. We copy every letter to the document.
+ * But if some optional filter options are given
+ * we make some changes: replace chars or complete strings.
+ *
+ * Note: It's not alloed for a filter to seek inside the stream.
+ * Because the outside frameloader has to set the stream position
+ * right and a filter must read till EOF occures only.
+ *
+ * @param xTarget
+ * the target text model to put the data in
+ *
+ * @param aOptions
+ * capsulate all other neccessary informations for this filter request
+ * (streams, replace values ...)
+ *
+ * @return a bool value which describes if method was successfully or not.
+ */
+ private boolean implts_import( com.sun.star.text.XTextDocument xTarget ,
+ FilterOptions aOptions )
+ {
+ measure("implts_import {");
+
+ com.sun.star.text.XSimpleText xText = (com.sun.star.text.XSimpleText)UnoRuntime.queryInterface(
+ com.sun.star.text.XSimpleText.class,
+ xTarget.getText());
+
+ measure("cast XSimpleText");
+
+ boolean bBreaked = false;
+
+ try
+ {
+ StringBuffer sBuffer = new StringBuffer(100000);
+ byte[][] lData = new byte[1][];
+ int nRead = aOptions.m_xInput.readBytes( lData, 4096 );
+
+ measure("read first bytes");
+
+ while (nRead>0 && !bBreaked)
+ {
+ // copy data from stream to temp. buffer
+ sBuffer.append( new String(lData[0]) );
+ measure("buffer append ["+nRead+"]");
+
+ nRead = aOptions.m_xInput.readBytes( lData, 2048 );
+ measure("read next bytes");
+
+ // check for cancelled filter proc on every loop!
+ synchronized(this)
+ {
+ if (m_nFilterProcState==FILTERPROC_BREAK)
+ {
+ m_nFilterProcState = FILTERPROC_STOPPED;
+ return false;
+ }
+ }
+ measure("break check");
+ }
+
+ // Make some replacements inside the buffer.
+ String sText = implts_replace( sBuffer, aOptions );
+ measure("replace");
+
+ // copy current buffer to the document model.
+ // Create a new paragraph for every line inside original file.
+ // May not all data could be readed - but that doesn't matter here.
+ // Reason: somewhere cancelled this function.
+ // But check for optioanl replace request before ...
+ int nStart = 0;
+ int nEnd = -1;
+ int nLength = sText.length();
+
+ com.sun.star.text.XTextRange xCursor = (com.sun.star.text.XTextRange)UnoRuntime.queryInterface(
+ com.sun.star.text.XTextRange.class,
+ xText.createTextCursor());
+
+ while (true)
+ {
+ nEnd = sText.indexOf('\n',nStart);
+
+ if (nEnd==-1 && nStart<nLength)
+ nEnd = nLength;
+
+ if (nEnd==-1)
+ break;
+
+ String sLine = sText.substring(nStart,nEnd);
+ nStart = nEnd+1;
+
+ xText.insertString(xCursor,sLine,false);
+ xText.insertControlCharacter(xCursor,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,false);
+
+ // check for cancelled filter proc on every loop!
+ synchronized(this)
+ {
+ if (m_nFilterProcState==FILTERPROC_BREAK)
+ {
+ m_nFilterProcState = FILTERPROC_STOPPED;
+ return false;
+ }
+ }
+ measure("break check");
+ }
+
+ measure("set on model");
+
+ // with refreshing the document we are on the safe-side, otherwise the first time the filter is used the document is not fully shown (flaw!).
+ com.sun.star.util.XRefreshable xRefresh = (com.sun.star.util.XRefreshable)UnoRuntime.queryInterface(
+ com.sun.star.util.XRefreshable.class,
+ xTarget);
+ xRefresh.refresh();
+
+ // If we created used stream - we must close it too.
+ if (aOptions.m_bStreamOwner==true)
+ {
+ aOptions.m_xInput.closeInput();
+ measure("stream close");
+ }
+ }
+ catch(com.sun.star.lang.IllegalArgumentException exArgument ) { bBreaked = true; }
+ catch(com.sun.star.io.BufferSizeExceededException exExceed ) { bBreaked = true; }
+ catch(com.sun.star.io.NotConnectedException exConnect ) { bBreaked = true; }
+ catch(com.sun.star.io.IOException exIO ) { bBreaked = true; }
+
+
+
+ measure("} implts_import");
+
+ return !bBreaked;
+ }
+
+ /**
+ * This helper function exports a simple ansi text file from
+ * a text model. We copy every letter from the document.
+ * There are no checks.
+ *
+ * Note: It's not alloed for a filter to seek inside the stream.
+ * Because the outside frameloader has to set the stream position
+ * right and a filter must read till EOF occures only.
+ *
+ * @param xSource
+ * the source text model to get the data from
+ *
+ * @param aOptions
+ * capsulate all other neccessary informations for this filter request
+ * (streams, replace values ...)
+ *
+ * @return a bool value which describes if method was successfully or not.
+ */
+ private boolean implts_export( com.sun.star.text.XTextDocument xSource ,
+ FilterOptions aOptions)
+ {
+ measure("implts_export {");
+
+ com.sun.star.text.XTextRange xText = (com.sun.star.text.XSimpleText)UnoRuntime.queryInterface(
+ com.sun.star.text.XSimpleText.class,
+ xSource.getText());
+
+ measure("cast XTextRange");
+
+ boolean bBreaked = false;
+
+ try
+ {
+ StringBuffer sBuffer = new StringBuffer(xText.getString());
+ String sText = implts_replace(sBuffer,aOptions);
+
+ measure("get text from model");
+
+ // Normaly this function isn't realy cancelable
+ // But we following operation can be very expensive. So
+ // this place is the last one to stop it.
+ synchronized(this)
+ {
+ if (m_nFilterProcState==FILTERPROC_BREAK)
+ {
+ m_nFilterProcState = FILTERPROC_STOPPED;
+ return false;
+ }
+ }
+
+ aOptions.m_xOutput.writeBytes(sText.getBytes());
+ aOptions.m_xOutput.flush();
+
+ measure("written to file");
+
+ // If we created used stream - we must close it too.
+ if (aOptions.m_bStreamOwner==true)
+ {
+ aOptions.m_xOutput.closeOutput();
+ measure("stream close");
+ }
+ }
+ catch(com.sun.star.io.BufferSizeExceededException exExceed ) { bBreaked = true; }
+ catch(com.sun.star.io.NotConnectedException exConnect ) { bBreaked = true; }
+ catch(com.sun.star.io.IOException exIO ) { bBreaked = true; }
+
+ measure("} implts_export");
+
+ return !bBreaked;
+ }
+
+ /**
+ * helper function to convert the used StringBuffer into a Strig value.
+ * And we use this chance to have a look on optional filter options
+ * which can invite replacing of strings.
+ */
+ private String implts_replace( StringBuffer rBuffer, FilterOptions aOptions )
+ {
+ // replace complete strings first
+ // Because its easiear on a buffer then on a string
+ if ( ! aOptions.m_sOld.equals(aOptions.m_sNew) )
+ {
+ int nStart = rBuffer.indexOf(aOptions.m_sOld);
+ int nLength = aOptions.m_sNew.length();
+ int nEnd = nStart+nLength;
+ while (nStart!=-1)
+ {
+ rBuffer.replace(nStart,nEnd,aOptions.m_sNew);
+ nStart = rBuffer.indexOf(aOptions.m_sOld,nEnd);
+ nEnd = nStart+nLength;
+ }
+ }
+
+ // convert buffer into return format [string]
+ // and convert to lower or upper case if required.
+ String sResult = rBuffer.toString();
+ if (aOptions.m_bCaseChange==true)
+ {
+ if (aOptions.m_bLower==true)
+ sResult = sResult.toLowerCase();
+ else
+ sResult = sResult.toUpperCase();
+ }
+
+ return sResult;
+ }
+
+
+ //______________________________
+ // interface XServiceInfo
+ /**
+ * This method returns an array of all supported service names.
+ *
+ * @return Array of supported service names.
+ */
+ public String[] getSupportedServiceNames()
+ {
+ return m_serviceNames;
+ }
+
+ /**
+ * This method returns true, if the given service will be
+ * supported by this component.
+ *
+ * @param sService
+ * the requested service name
+ *
+ * @return True, if the given service name will be supported;
+ * False otherwhise.
+ */
+ public boolean supportsService( String sService )
+ {
+ return (
+ sService.equals( m_serviceNames[0] ) ||
+ sService.equals( m_serviceNames[1] ) ||
+ sService.equals( m_serviceNames[2] )
+ );
+ }
+
+ /**
+ * Return the real class name of the component
+ *
+ * @return Class name of the component.
+ */
+ public String getImplementationName()
+ {
+ return _AsciiReplaceFilter.class.getName();
+ }
+
+
+ }
+ // end of inner class, the wrapper class just has the two methods required for registering the component
+
+ /**
+ * Gives a factory for creating the service.
+ * This method is called by the <code>JavaLoader</code>
+ *
+ * @param sImplName
+ * The implementation name of the component.
+ *
+ * @return Returns a <code>XSingleComponentFactory</code> for
+ * creating the component.
+ *
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+
+ public static XSingleComponentFactory __getComponentFactory(String sImplName)
+ {
+ XSingleComponentFactory xFactory = null;
+
+ if ( sImplName.equals( _AsciiReplaceFilter.class.getName() ) )
+ xFactory = com.sun.star.lib.uno.helper.Factory.createComponentFactory(_AsciiReplaceFilter.class,
+ _AsciiReplaceFilter.m_serviceNames);
+ return xFactory;
+ }
+
+
+ /**
+ * Writes the service information into the given registry key.
+ * This method is called by the <code>JavaLoader</code>.
+ *
+ * @param xRegistryKey
+ * Makes structural information (except regarding tree
+ * structures) of a single registry key accessible.
+ *
+ * @return returns true if the operation succeeded
+ *
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static boolean __writeRegistryServiceInfo( com.sun.star.registry.XRegistryKey xRegistryKey )
+ {
+ return Factory.writeRegistryServiceInfo(
+ _AsciiReplaceFilter.class.getName(),
+ _AsciiReplaceFilter.m_serviceNames,
+ xRegistryKey );
+ }
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/FilterOptions.java b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/FilterOptions.java
new file mode 100644
index 000000000000..cea1330fb2d6
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/FilterOptions.java
@@ -0,0 +1,236 @@
+/*************************************************************************
+ *
+ * $RCSfile: FilterOptions.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:43:18 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+package OfficeDev.samples.Filter;
+
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.io.XInputStream;
+import com.sun.star.io.XOutputStream;
+import com.sun.star.ucb.XSimpleFileAccess;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.uno.UnoRuntime;
+
+import com.sun.star.uno.Exception;
+import com.sun.star.ucb.CommandAbortedException;
+import com.sun.star.lang.IllegalArgumentException;
+
+/*-************************************************************************
+ @title helper to analyze neccessary option properties of our filter
+ @description Our filter needs some neccessary properties for working:
+ - a stream for input or output
+ - or an URL for creating such streams
+ - informations about required action on filtering
+
+ @attention This class mustn't be threadsafe - because instances of it
+ are used temp. only - not as members. So no concurrent access
+ should occure.
+ Another reason: It wuold be very difficult to safe every
+ access on our internal member. To do so - we must implement
+ special methods instead of allowing pure member access.
+ ************************************************************************-*/
+
+public class FilterOptions
+{
+ //_____________________________________
+ // public member to provide these options to our outside filter class
+ public com.sun.star.io.XInputStream m_xInput ;
+ public com.sun.star.io.XOutputStream m_xOutput ;
+ public boolean m_bStreamOwner ;
+ public String m_sURL ;
+ public String m_sOld ;
+ public String m_sNew ;
+ public boolean m_bCaseChange ;
+ public boolean m_bLower ;
+
+ //_____________________________________
+ // private members for internal things
+ private XMultiComponentFactory m_xMCF ;
+ private XComponentContext m_Ctx ;
+
+ //_____________________________________
+ // interface
+ /**
+ * creates a new instance of this class
+ * It use the given MediaDescriptor to find right
+ * properties for initialization of the internal members.
+ * To do so it use another interface method analyze()
+ * which can be used after creation of an object instance
+ * to set a new descriptor here.
+ *
+ * @param xSMGR
+ * we need it to create special help service top open
+ * streams in case they are not already a part of given
+ * MediaDescriptor
+ *
+ * @param bImport
+ * we must know which stream member should be valid initialized
+ *
+ * @param lDescriptor
+ * the initial MediaDescriptor to set internal member from it
+ */
+ public FilterOptions( XMultiComponentFactory xMCF ,
+ XComponentContext Context ,
+ boolean bImport ,
+ com.sun.star.beans.PropertyValue[] lDescriptor )
+ {
+ m_xMCF = xMCF;
+ m_Ctx = Context;
+ analyze(bImport, lDescriptor);
+ }
+
+ /**
+ * analyze given MediaDescriptor to find values for our internal member
+ * It reset all members to defaults before - to prevent us against
+ * mixed descriptor values!
+ *
+ * @param bImport
+ * we must know which stream member should be valid initialized
+ *
+ * @param lDescriptor
+ * the new MediaDescriptor to set internal member from it
+ */
+ public void analyze( boolean bImport ,
+ com.sun.star.beans.PropertyValue[] lDescriptor )
+ {
+ m_xInput = null ;
+ m_xOutput = null ;
+ m_bStreamOwner = false ;
+ m_sURL = null ;
+ m_sOld = new String();
+ m_sNew = new String();
+ m_bCaseChange = false ;
+ m_bLower = false ;
+
+ for ( int i=0; i<lDescriptor.length; ++i )
+ {
+ try
+ {
+ if (lDescriptor[i].Name.equals("FileName"))
+ m_sURL = AnyConverter.toString(lDescriptor[i].Value);
+ else
+ if (lDescriptor[i].Name.equals("InputStream"))
+ m_xInput = (com.sun.star.io.XInputStream)AnyConverter.toObject(new com.sun.star.uno.Type(com.sun.star.io.XInputStream.class), lDescriptor[i].Value);
+ else
+ if (lDescriptor[i].Name.equals("OutputStream"))
+ m_xOutput = (com.sun.star.io.XOutputStream)AnyConverter.toObject(new com.sun.star.uno.Type(com.sun.star.io.XOutputStream.class), lDescriptor[i].Value);
+ else
+ if (lDescriptor[i].Name.equals("FilterData"))
+ {
+ com.sun.star.beans.PropertyValue[] lFilterProps = (com.sun.star.beans.PropertyValue[])AnyConverter.toArray(lDescriptor[i].Value);
+ int nCount = lFilterProps.length;
+ for (int p=0; p<nCount; ++p)
+ {
+ if (lFilterProps[p].Name.equals("OldString"))
+ m_sOld = AnyConverter.toString(lFilterProps[p].Value);
+ else
+ if (lFilterProps[p].Name.equals("NewString"))
+ m_sNew = AnyConverter.toString(lFilterProps[p].Value);
+ else
+ if (lFilterProps[p].Name.equals("LowerCase"))
+ {
+ m_bLower = AnyConverter.toBoolean(lFilterProps[p].Value);
+ m_bCaseChange = true; // Set it after m_bLower - because an exception can occure and we must use default values then!
+ }
+ }
+ }
+ }
+ catch(com.sun.star.lang.IllegalArgumentException exConvert)
+ {
+ // ONE argument has the wrong type
+ // But I think we mustn't react here - because we setted
+ // default values for every neccessary item we need.
+ // In case this exception occures - this default exist
+ // and we can live with it.
+ }
+ }
+
+ // Decide if it's neccessary AND possible to open streams.
+ // Outside user can check for valid FilterOptions by using
+ // corresponding method isValid(). So it's not neccessary to
+ // handle this error here in any case.
+ if (m_xInput==null && m_xOutput==null && m_sURL!=null)
+ impl_openStreams(bImport);
+ }
+
+ /**
+ * with this method it's possible for the outside filter to decide
+ * if he can use this FilterOptions realy or not.
+ * That means especialy if neccessary streams are available or not.
+ */
+ public boolean isValid()
+ {
+ return(m_xInput!=null || m_xOutput!=null);
+ }
+
+ //_____________________________________
+ // helper
+ /**
+ * In case we couldn't found any valid stream inside the given MediaDescriptor,
+ * we must create it. Then we use a special helper service in combination
+ * with an existing URL to open a stream for reading or writing. It depends
+ * from given parameter bImport.
+ *
+ * Note: This method doesn't check for a valid URL. It must be done before.
+ *
+ * @param bImport
+ * inidcates which stream member must be valid as result of this call
+ */
+ private void impl_openStreams( boolean bImport )
+ {
+ try{
+ com.sun.star.ucb.XSimpleFileAccess xHelper = (com.sun.star.ucb.XSimpleFileAccess)UnoRuntime.queryInterface(
+ com.sun.star.ucb.XSimpleFileAccess.class,
+ m_xMCF.createInstanceWithContext("com.sun.star.ucb.SimpleFileAccess", m_Ctx));
+ if (xHelper!=null)
+ {
+ if (bImport==true)
+ m_xInput = xHelper.openFileRead(m_sURL);
+ else
+ m_xOutput = xHelper.openFileWrite(m_sURL);
+ }
+
+ m_bStreamOwner = (m_xInput!=null || m_xOutput!=null);
+ }
+ catch(com.sun.star.ucb.CommandAbortedException exAborted) {}
+ catch(com.sun.star.uno.Exception exUno ) {}
+ }
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/Makefile b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/Makefile
new file mode 100644
index 000000000000..9432746e9ab7
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/Makefile
@@ -0,0 +1,144 @@
+#*************************************************************************
+#
+# $RCSfile: Makefile,v $
+#
+# $Revision: 1.6 $
+#
+# last change: $Author: obo $ $Date: 2007-01-25 11:06:02 $
+#
+# The Contents of this file are made available subject to the terms of
+# the BSD license.
+#
+# Copyright (c) 2003 by Sun Microsystems, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+#**************************************************************************
+
+# Builds the OfficeDevFilter example of the Developers Guide.
+
+PRJ=../../../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+include $(SETTINGS)/dk.mk
+
+# Define non-platform/compiler specific settings
+SAMPLE_NAME=OfficeDevAsciiFilterExample
+SAMPLE_CLASS_OUT = $(OUT_CLASS)/$(SAMPLE_NAME)
+SAMPLE_GEN_OUT = $(OUT_MISC)/$(SAMPLE_NAME)
+
+COMP_NAME=SampleFilter
+COMP_CLASS_OUT=$(SAMPLE_CLASS_OUT)/$(COMP_NAME)
+COMP_PACKAGE = $(OUT_BIN)/$(COMP_NAME).$(UNOOXT_EXT)
+COMP_PACKAGE_URL = $(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP_NAME).$(UNOOXT_EXT)")
+COMP_JAR_NAME = $(COMP_NAME).uno.jar
+COMP_JAR = $(SAMPLE_CLASS_OUT)/$(COMP_JAR_NAME)
+COMP_MANIFESTFILE = $(SAMPLE_GEN_OUT)/$(COMP_NAME).uno.Manifest
+COMP_UNOPKG_MANIFEST = $(SAMPLE_GEN_OUT)/$(COMP_NAME)/META-INF/manifest.xml
+COMP_REGISTERFLAG = $(SAMPLE_GEN_OUT)/devguide_$(COMP_NAME)_component.flag
+
+# often the java files are structured in a hierarchy similar to the package,
+# for the example we know the package
+PACKAGE = OfficeDev/samples/Filter
+
+COMP_JAVAFILES = \
+ FilterOptions.java \
+ AsciiReplaceFilter.java
+
+COMP_CLASSFILES = $(patsubst %.java,$(COMP_CLASS_OUT)/$(PACKAGE)/%.class,$(COMP_JAVAFILES))
+
+SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
+ $(PATH_SEPARATOR)$(COMP_CLASS_OUT))
+
+
+# Targets
+.PHONY: ALL
+ALL : $(SAMPLE_NAME)
+
+include $(SETTINGS)/stdtarget.mk
+
+$(SAMPLE_GEN_OUT)/%.Manifest :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo RegistrationClassName: $(subst /,.,$(PACKAGE)).AsciiReplaceFilter> $@
+
+$(COMP_CLASSFILES) : $(COMP_JAVAFILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(COMP_CLASS_OUT) $(COMP_JAVAFILES)
+
+# rule for component jar file
+$(COMP_JAR) : $(COMP_MANIFESTFILE) $(COMP_CLASSFILES)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAR) cvfm $@ $< -C $(COMP_CLASS_OUT) .
+
+# rule for component package manifest
+$(SAMPLE_GEN_OUT)/%/manifest.xml :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@
+ @echo $(OSEP)!DOCTYPE manifest:manifest PUBLIC "$(QM)-//OpenOffice.org//DTD Manifest 1.0//EN$(QM)" "$(QM)Manifest.dtd$(QM)"$(CSEP) >> $@
+ @echo $(OSEP)manifest:manifest xmlns:manifest="$(QM)http://openoffice.org/2001/manifest$(QM)"$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.configuration-data$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)TypeDetection.xcu$(QM)"/$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-component;type=Java$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(subst /META-INF,,$(subst $(SAMPLE_GEN_OUT)/,,$(@D))).uno.jar$(QM)"/$(CSEP) >> $@
+ @echo $(OSEP)/manifest:manifest$(CSEP) >> $@
+
+# rule for component package file
+$(COMP_PACKAGE) : $(COMP_JAR) TypeDetection.xcu $(COMP_UNOPKG_MANIFEST)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_ZIP) $@ TypeDetection.xcu
+ cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_ZIP) -u ../../bin/$(@F) $(<F)
+ cd $(subst /,$(PS),$(SAMPLE_GEN_OUT)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml
+
+$(COMP_REGISTERFLAG) : $(COMP_PACKAGE)
+ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES"
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(DEPLOYTOOL) $(COMP_PACKAGE_URL)
+ @echo flagged > $(subst /,$(PS),$@)
+else
+ @echo --------------------------------------------------------------------------------
+ @echo If you want to install your component automatically, please set the environment
+ @echo variable SDK_AUTO_DEPLOYMENT = YES. But note that auto deployment is only
+ @echo possible if no office instance is running.
+ @echo --------------------------------------------------------------------------------
+endif
+
+$(SAMPLE_NAME) : $(COMP_REGISTERFLAG)
+ @echo --------------------------------------------------------------------------------
+ @echo The "$(QM)$(COMP_NAME)$(QM)" Java component was installed if SDK_AUTO_DEPLOYMENT = YES.
+ @echo You can use the "$(QM)ASCII Replace$(QM)" filter in your office installation, see the
+ @echo example description.
+ @echo --------------------------------------------------------------------------------
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_CLASS_OUT))
+ -$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_GEN_OUT))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_PACKAGE_URL)))
diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/TypeDetection.xcu b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/TypeDetection.xcu
new file mode 100644
index 000000000000..a03358394d72
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/TypeDetection.xcu
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:name="TypeDetection" oor:package="org.openoffice.Office">
+ <node oor:name="Types">
+ <node oor:name="ascii" oor:op="replace">
+ <prop oor:name="Data" oor:type="xs:string">
+ <value>0,text/plain,,,txt,0</value>
+ </prop>
+ <prop oor:name="UIName" oor:type="xs:string">
+ <value xml:lang="en-US">ASCII</value>
+ </prop>
+ </node>
+ </node>
+ <node oor:name="Filters">
+ <node oor:name="Ascii_Replace" oor:op="replace">
+ <prop oor:name="Data" oor:type="xs:string">
+ <value>0,ascii,com.sun.star.text.TextDocument,com.sun.star.comp.ansifilter.AsciiReplaceFilter,268959747,,0,,</value>
+ </prop>
+ <prop oor:name="Installed" oor:type="xs:boolean">
+ <value>true</value>
+ </prop>
+ <prop oor:name="UIName" oor:type="xs:string">
+ <!-- The x-no-translate entry is a marker to prevent l10n tooling from translation. It it is not necessary. -->
+ <value xml:lang="x-no-translate"></value>
+ <value xml:lang="en-US">ASCII Replace</value>
+ <value xml:lang="de">ASCII Konvertierung</value>
+ </prop>
+ </node>
+ </node>
+</oor:component-data>
diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/FlatXmlTypeDetection.xcu b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/FlatXmlTypeDetection.xcu
new file mode 100644
index 000000000000..67f8006db558
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/FlatXmlTypeDetection.xcu
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE oor:component-data SYSTEM "../../../../component-update.dtd">
+<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:package="org.openoffice.TypeDetection" oor:name="Types">
+ <node oor:name="Types">
+ <node oor:name="devguide_FlatXMLType_Cpp_calc" oor:op="replace">
+ <prop oor:name="UIOrder"><value>0</value></prop>
+ <prop oor:name="DetectService"><value>devguide.officedev.samples.filter.FlatXmlDetect</value></prop>
+ <prop oor:name="URLPattern"/>
+ <prop oor:name="Extensions"><value>fods</value></prop>
+ <prop oor:name="MediaType"/>
+ <prop oor:name="Preferred"><value>false</value></prop>
+ <prop oor:name="PreferredFilter"><value>devguide_FlatXMLFilter_Cpp_calc</value></prop>
+ <prop oor:name="UIName">
+ <value xml:lang="en-US">DevGuide FlatXML Calc</value>
+ </prop>
+ <prop oor:name="ClipboardFormat"><value>doctype:office:document</value></prop>
+ </node>
+ <node oor:name="devguide_FlatXMLType_Cpp_draw" oor:op="replace">
+ <prop oor:name="UIOrder"><value>0</value></prop>
+ <prop oor:name="DetectService"><value>devguide.officedev.samples.filter.FlatXmlDetect</value></prop>
+ <prop oor:name="URLPattern"/>
+ <prop oor:name="Extensions"><value>fodg</value></prop>
+ <prop oor:name="MediaType"/>
+ <prop oor:name="Preferred"><value>false</value></prop>
+ <prop oor:name="PreferredFilter"><value>devguide_FlatXMLFilter_Cpp_draw</value></prop>
+ <prop oor:name="UIName">
+ <value xml:lang="en-US">DevGuide FlatXML Draw</value>
+ </prop>
+ <prop oor:name="ClipboardFormat"><value>doctype:office:document</value></prop>
+ </node>
+ <node oor:name="devguide_FlatXMLType_Cpp_impress" oor:op="replace">
+ <prop oor:name="UIOrder"><value>0</value></prop>
+ <prop oor:name="DetectService"><value>devguide.officedev.samples.filter.FlatXmlDetect</value></prop>
+ <prop oor:name="URLPattern"/>
+ <prop oor:name="Extensions"><value>fodp</value></prop>
+ <prop oor:name="MediaType"/>
+ <prop oor:name="Preferred"><value>false</value></prop>
+ <prop oor:name="PreferredFilter"><value>devguide_FlatXMLFilter_Cpp_impress</value></prop>
+ <prop oor:name="UIName">
+ <value xml:lang="en-US">DevGuide FlatXML Impress</value>
+ </prop>
+ <prop oor:name="ClipboardFormat"><value>doctype:office:document</value></prop>
+ </node>
+ <node oor:name="devguide_FlatXMLType_Cpp_writer" oor:op="replace">
+ <prop oor:name="UIOrder"><value>0</value></prop>
+ <prop oor:name="DetectService"><value>devguide.officedev.samples.filter.FlatXmlDetect</value></prop>
+ <prop oor:name="URLPattern"/>
+ <prop oor:name="Extensions"><value>fodt</value></prop>
+ <prop oor:name="MediaType"/>
+ <prop oor:name="Preferred"><value>false</value></prop>
+ <prop oor:name="PreferredFilter"><value>devguide_FlatXMLFilter_Cpp_writer</value></prop>
+ <prop oor:name="UIName">
+ <value xml:lang="en-US">DevGuide FlatXML Writer</value>
+ </prop>
+ <prop oor:name="ClipboardFormat"><value>doctype:office:document</value></prop>
+ </node>
+ <node oor:name="devguide_FlatXMLType_Cpp_master" oor:op="replace">
+ <prop oor:name="UIOrder"><value>0</value></prop>
+ <prop oor:name="DetectService"><value>devguide.officedev.samples.filter.FlatXmlDetect</value></prop>
+ <prop oor:name="URLPattern"/>
+ <prop oor:name="Extensions"><value>fodm</value></prop>
+ <prop oor:name="MediaType"/>
+ <prop oor:name="Preferred"><value>false</value></prop>
+ <prop oor:name="PreferredFilter"><value>devguide_FlatXMLFilter_Cpp_master</value></prop>
+ <prop oor:name="UIName">
+ <value xml:lang="en-US">DevGuide FlatXML Master</value>
+ </prop>
+ <prop oor:name="ClipboardFormat"><value>doctype:office:document</value></prop>
+ </node>
+ </node>
+</oor:component-data>
diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/Makefile b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/Makefile
new file mode 100644
index 000000000000..8883c4fe0de9
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/Makefile
@@ -0,0 +1,156 @@
+#*************************************************************************
+#
+# $RCSfile: Makefile,v $
+#
+# $Revision: 1.11 $
+#
+# last change: $Author: rt $ $Date: 2008-07-11 14:22:52 $
+#
+# The Contents of this file are made available subject to the terms of
+# the BSD license.
+#
+# Copyright (c) 2003 by Sun Microsystems, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+#**************************************************************************
+
+# Builds the filterdetection component for the FlatXmlFilter of the Developers Guide.
+
+PRJ=../../../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+include $(SETTINGS)/dk.mk
+
+# Define non-platform/compiler specific settings
+COMP_NAME=FlatXmlTypeDetection
+COMP_IMPL_NAME=$(COMP_NAME).uno.$(SHAREDLIB_EXT)
+OUT_COMP_INC = $(OUT_INC)/$(COMP_NAME)
+OUT_COMP_GEN = $(OUT_MISC)/$(COMP_NAME)
+OUT_COMP_SLO=$(OUT_SLO)/$(COMP_NAME)
+COMP_RDB_NAME = $(COMP_NAME).uno.rdb
+COMP_RDB = $(OUT_COMP_GEN)/$(COMP_RDB_NAME)
+COMP_PACKAGE = $(OUT_BIN)/$(COMP_NAME).$(UNOOXT_EXT)
+COMP_PACKAGE_URL = $(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP_NAME).$(UNOOXT_EXT)")
+COMP_UNOPKG_MANIFEST = $(OUT_COMP_GEN)/$(COMP_NAME)/META-INF/manifest.xml
+COMP_MAPFILE = $(OUT_COMP_GEN)/$(COMP_NAME).uno.map
+
+REGISTERFLAG = $(OUT_MISC)/devguide_$(COMP_NAME)_register_component.flag
+
+CXXFILES = filterdetect.cxx \
+ fdcomp.cxx
+
+SLOFILES = $(patsubst %.cxx,$(OUT_COMP_SLO)/%.$(OBJ_EXT),$(CXXFILES))
+
+# Targets
+.PHONY: ALL
+ALL : \
+ XMLFilterDetect
+
+include $(SETTINGS)/stdtarget.mk
+
+$(OUT_COMP_SLO)/%.$(OBJ_EXT) : %.cxx $(SDKTYPEFLAG)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(CC) $(CC_FLAGS) $(CC_INCLUDES) -I$(OUT_COMP_INC) $(CC_DEFINES) $(CC_OUTPUT_SWITCH)$(subst /,$(PS),$@) $<
+
+$(COMP_MAPFILE) : $(SLOFILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ cat $(PRJ)/settings/component.uno.map > $(COMP_MAPFILE)
+ifeq "$(OS)" "MACOSX"
+ nm -gx $(SLOFILES) | $(ADDSYMBOLS) >> $(COMP_MAPFILE)
+endif
+
+ifeq "$(OS)" "WIN"
+$(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ -$(MKDIR) $(subst /,$(PS),$(OUT_COMP_GEN))
+ $(LINK) $(COMP_LINK_FLAGS) /OUT:$@ \
+ /MAP:$(OUT_COMP_GEN)/$(subst $(SHAREDLIB_EXT),map,$(@F)) $(SLOFILES) \
+ $(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) $(STLPORTLIB) msvcrt.lib kernel32.lib
+ $(LINK_MANIFEST_VC8_ONLY)
+else
+$(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES) $(COMP_MAPFILE)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(LINK) $(COMP_LINK_FLAGS) $(LINK_LIBS) -o $@ $(SLOFILES) \
+ $(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) $(STLPORTLIB) $(STC++LIB) $(CPPUHELPERDYLIB) $(CPPUDYLIB) $(SALDYLIB)
+ifeq "$(OS)" "MACOSX"
+ $(INSTALL_NAME_URELIBS) $@
+endif
+endif
+
+# rule for component package manifest
+$(OUT_COMP_GEN)/%/manifest.xml :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@
+ @echo $(OSEP)!DOCTYPE manifest:manifest PUBLIC "$(QM)-//OpenOffice.org//DTD Manifest 1.0//EN$(QM)" "$(QM)Manifest.dtd$(QM)"$(CSEP) >> $@
+ @echo $(OSEP)manifest:manifest xmlns:manifest="$(QM)http://openoffice.org/2001/manifest$(QM)"$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.configuration-data$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)FlatXmlTypeDetection.xcu$(QM)"/$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-component;type=native;platform=$(UNOPKG_PLATFORM)$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(subst /META-INF,,$(subst $(OUT_COMP_GEN)/,,$(UNOPKG_PLATFORM)/$(@D))).uno.$(SHAREDLIB_EXT)$(QM)"/$(CSEP) >> $@
+ @echo $(OSEP)/manifest:manifest$(CSEP) >> $@
+
+# rule for component package file
+$(COMP_PACKAGE) : $(SHAREDLIB_OUT)/$(COMP_IMPL_NAME) FlatXmlTypeDetection.xcu $(COMP_UNOPKG_MANIFEST)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ -$(MKDIR) $(subst /,$(PS),$(OUT_COMP_GEN)/$(UNOPKG_PLATFORM))
+ $(COPY) $(subst /,$(PS),$<) $(subst /,$(PS),$(OUT_COMP_GEN)/$(UNOPKG_PLATFORM))
+ $(SDK_ZIP) $@ FlatXmlTypeDetection.xcu
+ cd $(subst /,$(PS),$(OUT_COMP_GEN)) && $(SDK_ZIP) -u ../../bin/$(@F) $(UNOPKG_PLATFORM)/$(<F)
+ cd $(subst /,$(PS),$(OUT_COMP_GEN)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml
+
+$(REGISTERFLAG) : $(COMP_PACKAGE)
+ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES"
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(DEPLOYTOOL) $(COMP_PACKAGE_URL)
+ @echo flagged > $(subst /,$(PS),$@)
+else
+ @echo --------------------------------------------------------------------------------
+ @echo If you want to install your component automatically, please set the environment
+ @echo variable SDK_AUTO_DEPLOYMENT = YES. But note that auto deployment is only
+ @echo possible if no office instance is running.
+ @echo --------------------------------------------------------------------------------
+endif
+
+XMLFilterDetect : $(REGISTERFLAG)
+ @echo --------------------------------------------------------------------------------
+ @echo The FlatXMLFilterDetection component is installed if SDK_AUTO_DEPLOYMENT = YES.
+ @echo You will use this component implicitly in your office installation when you have
+ @echo installed a FlatXMLFilter component C++ or Java.
+ @echo --------------------------------------------------------------------------------
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_INC))
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_GEN))
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_SLO))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_PACKAGE_URL)))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$(REGISTERFLAG)))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$(SHAREDLIB_OUT)/$(COMP_NAME).*))
diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/fdcomp.cxx b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/fdcomp.cxx
new file mode 100644
index 000000000000..9e4480f94624
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/fdcomp.cxx
@@ -0,0 +1,115 @@
+/*************************************************************************
+ *
+ * $RCSfile: fdcomp.cxx,v $
+ *
+ * $Revision: 1.6 $
+ *
+ * last change: $Author: rt $ $Date: 2008-04-10 16:46:03 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+#include <stdio.h>
+
+#include <osl/mutex.hxx>
+#include <osl/thread.h>
+#include <cppuhelper/factory.hxx>
+#include <com/sun/star/lang/XSingleServiceFactory.hpp>
+
+#include "filterdetect.hxx"
+
+using namespace ::rtl;
+using namespace ::cppu;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::registry;
+
+extern "C"
+{
+//==================================================================================================
+void SAL_CALL component_getImplementationEnvironment(
+ const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv )
+{
+ *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
+}
+
+//==================================================================================================
+sal_Bool SAL_CALL component_writeInfo(
+ void * pServiceManager, void * pRegistryKey )
+{
+ if (pRegistryKey)
+ {
+ try
+ {
+ Reference< XRegistryKey > xNewKey(
+ reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( FilterDetect_getImplementationName() ) );
+ xNewKey = xNewKey->createKey( OUString::createFromAscii( "/UNO/SERVICES" ) );
+
+ const Sequence< OUString > & rSNL = FilterDetect_getSupportedServiceNames();
+ const OUString * pArray = rSNL.getConstArray();
+ for ( sal_Int32 nPos = rSNL.getLength(); nPos--; )
+ xNewKey->createKey( pArray[nPos] );
+
+ return sal_True;
+ }
+ catch (InvalidRegistryException &)
+ {
+ OSL_ENSURE( sal_False, "### InvalidRegistryException!" );
+ }
+ }
+ return sal_False;
+}
+
+//==================================================================================================
+void * SAL_CALL component_getFactory(
+ const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
+{
+ void * pRet = 0;
+
+ OUString implName = OUString::createFromAscii( pImplName );
+ if ( pServiceManager && implName.equals(FilterDetect_getImplementationName()) )
+ {
+ Reference< XSingleServiceFactory > xFactory( createSingleFactory(
+ reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
+ OUString::createFromAscii( pImplName ),
+ FilterDetect_createInstance, FilterDetect_getSupportedServiceNames() ) );
+
+ if (xFactory.is())
+ {
+ xFactory->acquire();
+ pRet = xFactory.get();
+ }
+ }
+ return pRet;
+}
+
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/filterdetect.cxx b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/filterdetect.cxx
new file mode 100644
index 000000000000..557815a74e50
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/filterdetect.cxx
@@ -0,0 +1,260 @@
+/*************************************************************************
+ *
+ * $RCSfile: filterdetect.cxx,v $
+ *
+ * $Revision: 1.10 $
+ *
+ * last change: $Author: rt $ $Date: 2008-07-11 14:23:20 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+#include "filterdetect.hxx"
+#include <osl/diagnose.h>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/io/XActiveDataSource.hpp>
+#include <com/sun/star/io/XOutputStream.hpp>
+#include <com/sun/star/io/XInputStream.hpp>
+#include <com/sun/star/io/XSeekable.hpp>
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#include <com/sun/star/xml/sax/InputSource.hpp>
+#include <com/sun/star/xml/sax/XParser.hpp>
+#include <com/sun/star/xml/XImportFilter.hpp>
+#include <com/sun/star/xml/XExportFilter.hpp>
+#include <com/sun/star/frame/XModel.hpp>
+#include <com/sun/star/frame/XController.hpp>
+#include <com/sun/star/task/XStatusIndicator.hpp>
+#include <com/sun/star/task/XStatusIndicatorFactory.hpp>
+#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
+#include <com/sun/star/style/XStyleLoader.hpp>
+#include <com/sun/star/io/XInputStream.hpp>
+#include <com/sun/star/document/XExtendedFilterDetection.hpp>
+#include <com/sun/star/beans/PropertyState.hpp>
+#include <com/sun/star/ucb/XSimpleFileAccess.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+
+
+using namespace rtl;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::document;
+using namespace com::sun::star::lang;
+using namespace com::sun::star::io;
+using namespace com::sun::star::beans;
+using namespace com::sun::star::xml::sax;
+using namespace com::sun::star::xml;
+using namespace com::sun::star::task;
+using namespace com::sun::star::frame;
+using namespace com::sun::star::container;
+using namespace com::sun::star::ucb;
+
+
+OUString SAL_CALL FilterDetect::detect(Sequence< PropertyValue >& aArguments )
+ throw( RuntimeException )
+{
+ // type name to return
+ OUString sOriginalTypeName;
+ OUString sTypeName;
+ OUString sURL;
+ // stream of the document to be detected
+ Reference< XInputStream > xInStream;
+ for ( sal_Int32 i = 0 ; i < aArguments.getLength(); i++)
+ {
+ OUString aName = aArguments[i].Name;
+ if (aName.equalsAscii("TypeName" ) )
+ aArguments[i].Value >>= sOriginalTypeName;
+ if (aName.equalsAscii("URL" ) )
+ aArguments[i].Value >>= sURL;
+ if (aName.equalsAscii("InputStream" ) )
+ aArguments[i].Value >>= xInStream;
+ }
+
+ if (!xInStream.is())
+ {
+ // open the stream if it was not suplied by the framework
+ Reference< XSimpleFileAccess > xSFI(mxMSF->createInstance(
+ OUString::createFromAscii("com.sun.star.ucb.SimpleFileAccess" )), UNO_QUERY);
+ if (sURL.getLength() > 0 && xSFI.is())
+ {
+ try
+ {
+ xInStream = xSFI->openFileRead( sURL);
+ }
+ catch( Exception& )
+ {
+ return sTypeName;
+ }
+ } else {
+ // failed to access UCB
+ return sTypeName;
+ }
+ }
+
+ // flatxml starts with an office:document element. this element
+ // conatains a clas="..." attribut by which we can deduct the
+ // type of document that is to be loaded
+ //
+ // WARNING:
+ // parsing the plain text of the document is an easy way to do this
+ // but not the purest solution, since namespaces and other xml details
+ // may lead to another syntactic expression of the same document.
+ // this example works for the way the office serializes it's XML stream
+ // but might need extension for other data sources...
+ static OString aDocToken("office:document");
+ // static OString aClassToken("office:class=\"");
+ static OString aMimeTypeToken("office:mimetype=\"");
+
+ sal_Int32 nHeadSize = 4096;
+ Sequence< sal_Int8 > aHeadData(nHeadSize);
+
+ // rewind seekable stream
+ Reference< XSeekable > xSeek(xInStream, UNO_QUERY);
+ if (xSeek.is())
+ xSeek->seek(0);
+
+ long bytestRead = xInStream->readBytes(aHeadData, nHeadSize);
+
+ OString aHead = OString((const sal_Char *)aHeadData.getConstArray(), bytestRead).toAsciiLowerCase();
+
+ // check for document element of flatxml format
+ if (aHead.indexOf(aDocToken) >= 0)
+ {
+ // read document class
+ sal_Int32 n = aHead.indexOf(aMimeTypeToken);
+ if (n >= 0)
+ {
+ n += aMimeTypeToken.getLength();
+ OString aMimeType = aHead.copy(n, aHead.indexOf('\"', n) - n);
+ // return type for class found
+ if (aMimeType.equals("application/x-vnd.oasis.opendocument.text") ||
+ aMimeType.equals("application/vnd.oasis.opendocument.text"))
+ sTypeName = OUString::createFromAscii("devguide_FlatXMLType_Cpp_writer");
+ else if (aMimeType.equals("application/x-vnd.oasis.opendocument.text-master") ||
+ aMimeType.equals("application/vnd.oasis.opendocument.text-master"))
+ sTypeName = OUString::createFromAscii("devguide_FlatXMLType_Cpp_master");
+ else if (aMimeType.equals("application/x-vnd.oasis.openoffice.text-global") ||
+ aMimeType.equals("application/vnd.oasis.openoffice.text-global"))
+ sTypeName = OUString::createFromAscii("devguide_FlatXMLType_Cpp_master");
+ else if (aMimeType.equals("application/x-vnd.oasis.opendocument.spreadsheet") ||
+ aMimeType.equals("application/vnd.oasis.opendocument.spreadsheet"))
+ sTypeName = OUString::createFromAscii("devguide_FlatXMLType_Cpp_calc");
+ else if (aMimeType.equals("application/x-vnd.oasis.opendocument.drawing") ||
+ aMimeType.equals("application/vnd.oasis.opendocument.drawing"))
+ sTypeName = OUString::createFromAscii("devguide_FlatXMLType_Cpp_draw");
+ else if (aMimeType.equals("application/x-vnd.oasis.opendocument.presentation") ||
+ aMimeType.equals("application/vnd.oasis.opendocument.presentation"))
+ sTypeName = OUString::createFromAscii("devguide_FlatXMLType_Cpp_impress");
+ else if (aMimeType.equals("application/x-vnd.oasis.opendocument.presentation") ||
+ aMimeType.equals("application/vnd.oasis.opendocument.presentation"))
+ sTypeName = OUString::createFromAscii("devguide_FlatXMLType_Cpp_impress");
+ }
+ }
+ return sTypeName;
+}
+
+
+// XInitialization
+void SAL_CALL FilterDetect::initialize( const Sequence< Any >& aArguments )
+ throw (Exception, RuntimeException)
+{
+ Sequence < PropertyValue > aAnySeq;
+ sal_Int32 nLength = aArguments.getLength();
+ if ( nLength && ( aArguments[0] >>= aAnySeq ) )
+ {
+ const PropertyValue * pValue = aAnySeq.getConstArray();
+ nLength = aAnySeq.getLength();
+ for ( sal_Int32 i = 0 ; i < nLength; i++)
+ {
+ if ( pValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "Type" ) ) )
+ {
+ pValue[i].Value >>= msFilterName;
+ }
+ else if ( pValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "UserData" ) ) )
+ {
+ pValue[i].Value >>= msUserData;
+ }
+ else if ( pValue[i].Name.equalsAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "TemplateName" ) ) )
+ {
+ pValue[i].Value>>=msTemplateName;
+ }
+ }
+ }
+}
+
+OUString FilterDetect_getImplementationName ()
+ throw (RuntimeException)
+{
+ return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "devguide.officedev.samples.filter.FlatXmlDetect" ) );
+}
+
+#define SERVICE_NAME1 "com.sun.star.document.ExtendedTypeDetection"
+
+sal_Bool SAL_CALL FilterDetect_supportsService( const OUString& ServiceName )
+ throw (RuntimeException)
+{
+ return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME1 ) );
+}
+
+Sequence< OUString > SAL_CALL FilterDetect_getSupportedServiceNames( )
+ throw (RuntimeException)
+{
+ Sequence < OUString > aRet(2);
+ OUString* pArray = aRet.getArray();
+ pArray[0] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME1 ) );
+ return aRet;
+}
+#undef SERVICE_NAME1
+#undef SERVICE_NAME2
+
+Reference< XInterface > SAL_CALL FilterDetect_createInstance( const Reference< XMultiServiceFactory > & rSMgr)
+ throw( Exception )
+{
+ return (cppu::OWeakObject*) new FilterDetect( rSMgr );
+}
+
+// XServiceInfo
+OUString SAL_CALL FilterDetect::getImplementationName( )
+ throw (RuntimeException)
+{
+ return FilterDetect_getImplementationName();
+}
+
+sal_Bool SAL_CALL FilterDetect::supportsService( const OUString& rServiceName )
+ throw (RuntimeException)
+{
+ return FilterDetect_supportsService( rServiceName );
+}
+
+Sequence< OUString > SAL_CALL FilterDetect::getSupportedServiceNames( )
+ throw (RuntimeException)
+{
+ return FilterDetect_getSupportedServiceNames();
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/filterdetect.hxx b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/filterdetect.hxx
new file mode 100644
index 000000000000..152b7252c2e8
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilterDetection/filterdetect.hxx
@@ -0,0 +1,124 @@
+/*************************************************************************
+ *
+ * $RCSfile: filterdetect.hxx,v $
+ *
+ * $Revision: 1.5 $
+ *
+ * last change: $Author: rt $ $Date: 2008-04-10 16:46:41 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+#ifndef _FILTERDETECT_HXX
+#define _FILTERDETECT_HXX
+
+
+#include <com/sun/star/document/XFilter.hpp>
+#include <com/sun/star/document/XExporter.hpp>
+#include <com/sun/star/document/XExtendedFilterDetection.hpp>
+#include <com/sun/star/document/XImporter.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <cppuhelper/implbase5.hxx>
+
+#ifndef _CPPUHELPER_IMPLBASE4_HXX_
+#include <cppuhelper/implbase3.hxx>
+#endif
+
+enum FilterType
+{
+ FILTER_IMPORT,
+ FILTER_EXPORT
+};
+
+/* This component will be instantiated for both import or export. Whether it calls
+ * setSourceDocument or setTargetDocument determines which Impl function the filter
+ * member calls */
+class FilterDetect : public cppu::WeakImplHelper3 <com::sun::star::document::XExtendedFilterDetection,
+ com::sun::star::lang::XInitialization,
+ com::sun::star::lang::XServiceInfo>
+{
+protected:
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMSF;
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > mxDoc;
+ ::rtl::OUString msFilterName;
+ ::com::sun::star::uno::Sequence< ::rtl::OUString > msUserData;
+ ::rtl::OUString msTemplateName;
+
+ sal_Bool SAL_CALL exportImpl( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
+ throw (::com::sun::star::uno::RuntimeException);
+
+ sal_Bool SAL_CALL importImpl( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
+ throw (::com::sun::star::uno::RuntimeException);
+
+public:
+ FilterDetect( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > &rxMSF)
+ : mxMSF( rxMSF ) {}
+
+ virtual ~FilterDetect() {}
+
+ //XExtendedFilterDetection
+ virtual ::rtl::OUString SAL_CALL detect( com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& lDescriptor )
+ throw( com::sun::star::uno::RuntimeException );
+
+ // XInitialization
+
+ virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
+ throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
+
+ // XServiceInfo
+ virtual ::rtl::OUString SAL_CALL getImplementationName( )
+ throw (::com::sun::star::uno::RuntimeException);
+
+ virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
+ throw (::com::sun::star::uno::RuntimeException);
+
+ virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( )
+ throw (::com::sun::star::uno::RuntimeException);
+};
+
+
+::rtl::OUString FilterDetect_getImplementationName()
+ throw ( ::com::sun::star::uno::RuntimeException );
+
+sal_Bool SAL_CALL FilterDetect_supportsService( const ::rtl::OUString& ServiceName )
+ throw ( ::com::sun::star::uno::RuntimeException );
+
+::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL FilterDetect_getSupportedServiceNames( )
+ throw ( ::com::sun::star::uno::RuntimeException );
+
+::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
+SAL_CALL FilterDetect_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr)
+ throw ( ::com::sun::star::uno::Exception );
+
+#endif
+
diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/FlatXml.cxx b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/FlatXml.cxx
new file mode 100644
index 000000000000..08fbceefd40d
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/FlatXml.cxx
@@ -0,0 +1,379 @@
+/*************************************************************************
+ *
+ * $RCSfile: FlatXml.cxx,v $
+ *
+ * $Revision: 1.7 $
+ *
+ * last change: $Author: kz $ $Date: 2006-11-06 15:03:03 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+#include <cppuhelper/factory.hxx>
+#include <cppuhelper/servicefactory.hxx>
+#include <cppuhelper/implbase1.hxx>
+#include <cppuhelper/implbase2.hxx>
+#include <cppuhelper/implbase3.hxx>
+#include <cppuhelper/implbase.hxx>
+
+#include <com/sun/star/lang/XComponent.hpp>
+
+#include <com/sun/star/uno/Any.hxx>
+#include <com/sun/star/uno/Type.hxx>
+
+#include <com/sun/star/beans/PropertyValue.hpp>
+
+#include <com/sun/star/xml/sax/XParser.hpp>
+#include <com/sun/star/xml/sax/InputSource.hpp>
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
+#include <com/sun/star/xml/sax/SAXException.hpp>
+#include <com/sun/star/xml/XImportFilter.hpp>
+#include <com/sun/star/xml/XExportFilter.hpp>
+
+#include <com/sun/star/io/XInputStream.hpp>
+#include <com/sun/star/io/XOutputStream.hpp>
+#include <com/sun/star/io/XActiveDataSource.hpp>
+#include <com/sun/star/io/XSeekable.hpp>
+
+using namespace ::rtl;
+using namespace ::cppu;
+using namespace ::osl;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::io;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::registry;
+using namespace ::com::sun::star::xml;
+using namespace ::com::sun::star::xml::sax;
+
+namespace XFlatXml {
+
+class XFlatXml : public WeakImplHelper3< XImportFilter, XExportFilter, XDocumentHandler>
+{
+private:
+ // the UNO ServiceFactory
+ Reference< XMultiServiceFactory > m_rServiceFactory;
+
+ // DocumentHandler interface of the css::xml::sax::Writer service
+ Reference < XExtendedDocumentHandler > m_rDocumentHandler;
+
+ // controls pretty-printing
+ sal_Bool m_bPrettyPrint;
+
+public:
+
+ // ctor...
+ XFlatXml( const Reference< XMultiServiceFactory > &r )
+ : m_rServiceFactory(r)
+ , m_bPrettyPrint(sal_True)
+ {}
+
+ // XImportFilter
+ virtual sal_Bool SAL_CALL importer(
+ const Sequence<PropertyValue>& aSourceData,
+ const Reference<XDocumentHandler>& xHandler,
+ const Sequence<OUString>& msUserData)
+ throw(RuntimeException);
+
+ // XExportFilter
+ virtual sal_Bool SAL_CALL exporter(
+ const Sequence<PropertyValue>& aSourceData,
+ const Sequence<OUString>& msUserData)
+ throw(RuntimeException);
+
+ // XDocumentHandler
+ virtual void SAL_CALL startDocument()
+ throw (SAXException,RuntimeException);
+ virtual void SAL_CALL endDocument()
+ throw (SAXException, RuntimeException);
+ virtual void SAL_CALL startElement(const OUString& str, const Reference<XAttributeList>& attriblist)
+ throw (SAXException,RuntimeException);
+ virtual void SAL_CALL endElement(const OUString& str)
+ throw (SAXException, RuntimeException);
+ virtual void SAL_CALL characters(const OUString& str)
+ throw (SAXException, RuntimeException);
+ virtual void SAL_CALL ignorableWhitespace(const OUString& str)
+ throw (SAXException, RuntimeException);
+ virtual void SAL_CALL processingInstruction(const OUString& str, const OUString& str2)
+ throw (com::sun::star::xml::sax::SAXException,RuntimeException);
+ virtual void SAL_CALL setDocumentLocator(const Reference<XLocator>& doclocator)
+ throw (SAXException,RuntimeException);
+};
+
+sal_Bool XFlatXml::importer(
+ const Sequence<PropertyValue>& aSourceData,
+ const Reference<XDocumentHandler>& xHandler,
+ const Sequence<OUString>& msUserData)
+ throw (RuntimeException)
+{
+ // get information from media descriptor
+ // the imput stream that represents the imported file
+ // is most important here since we need to supply it to
+ // the sax parser that drives the supplied document handler
+ sal_Int32 nLength = aSourceData.getLength();
+ OUString aName, aFileName, aURL;
+ Reference< XInputStream > xInputStream;
+ for ( sal_Int32 i = 0 ; i < nLength; i++)
+ {
+ aName = aSourceData[i].Name;
+ if (aName.equalsAscii("InputStream"))
+ aSourceData[i].Value >>= xInputStream;
+ else if ( aName.equalsAscii("FileName"))
+ aSourceData[i].Value >>= aFileName;
+ else if ( aName.equalsAscii("URL"))
+ aSourceData[i].Value >>= aURL;
+ }
+
+ // we need an input stream
+ OSL_ASSERT(xInputStream.is());
+ if (!xInputStream.is()) return sal_False;
+
+ // rewind seekable stream
+ Reference< XSeekable > xSeek(xInputStream, UNO_QUERY);
+ if (xSeek.is())
+ xSeek->seek(0);
+
+
+ // create SAX parser that will read the document file
+ // and provide events to xHandler passed to this call
+ Reference < XParser > xSaxParser( m_rServiceFactory->createInstance(
+ OUString::createFromAscii("com.sun.star.xml.sax.Parser")), UNO_QUERY );
+ OSL_ASSERT(xSaxParser.is());
+ if(!xSaxParser.is())return sal_False;
+
+ // let the parser try to send the sax event to the document handler
+ try
+ {
+ InputSource aInput;
+ aInput.sSystemId = aURL;
+ aInput.sPublicId = aURL;
+ aInput.aInputStream = xInputStream;
+ xSaxParser->setDocumentHandler(xHandler);
+ xSaxParser->parseStream(aInput);
+ }
+ catch( Exception &exc)
+ {
+ // something went wrong
+ OSL_ENSURE(0, exc.Message);
+ return sal_False;
+ }
+
+ // done
+ return sal_True;
+}
+
+sal_Bool XFlatXml::exporter(
+ const Sequence<PropertyValue>& aSourceData,
+ const Sequence<OUString>& msUserData)
+ throw (RuntimeException)
+{
+
+ // read source data
+ // we are especialy interested in the output stream
+ // since that is where our xml-writer will push the data
+ // from it's data-source interface
+ OUString aName, sURL;
+ Reference<XOutputStream> rOutputStream;
+ sal_Int32 nLength = aSourceData.getLength();
+ for ( sal_Int32 i = 0 ; i < nLength; i++)
+ {
+ aName = aSourceData[i].Name;
+ if ( aName.equalsAscii("OutputStream"))
+ aSourceData[i].Value >>= rOutputStream;
+ else if ( aName.equalsAscii("URL" ))
+ aSourceData[i].Value >>= sURL;
+ }
+
+ if (!m_rDocumentHandler.is()) {
+ // get the document writer
+ m_rDocumentHandler = Reference<XExtendedDocumentHandler>(
+ m_rServiceFactory->createInstance(
+ OUString::createFromAscii("com.sun.star.xml.sax.Writer")),
+ UNO_QUERY);
+ OSL_ASSERT(m_rDocumentHandler.is());
+ if (!m_rDocumentHandler.is()) return sal_False;
+ }
+ // get data source interface ...
+ Reference< XActiveDataSource > rDataSource(m_rDocumentHandler, UNO_QUERY);
+ OSL_ASSERT(rDataSource.is());
+ if (!rDataSource.is()) return sal_False;
+ OSL_ASSERT(rOutputStream.is());
+ if (!rOutputStream.is()) return sal_False;
+ // ... and set output stream
+ rDataSource->setOutputStream(rOutputStream);
+
+ return sal_True;
+}
+
+// for the DocumentHandler implementation, we just proxy the the
+// events to the XML writer that we created upon the output stream
+// that was provided by the XMLFilterAdapter
+void XFlatXml::startDocument() throw (SAXException,RuntimeException){
+ OSL_ASSERT(m_rDocumentHandler.is());
+ m_rDocumentHandler->startDocument();
+}
+
+void XFlatXml::endDocument() throw (SAXException,RuntimeException){
+ OSL_ASSERT(m_rDocumentHandler.is());
+ m_rDocumentHandler->endDocument();
+}
+
+void XFlatXml::startElement(const OUString& str, const Reference<XAttributeList>& attriblist)
+ throw (SAXException, RuntimeException)
+{
+ OSL_ASSERT(m_rDocumentHandler.is());
+ m_rDocumentHandler->startElement(str, attriblist);
+}
+
+void XFlatXml::endElement(const OUString& str)
+ throw (SAXException, RuntimeException)
+{
+ OSL_ASSERT(m_rDocumentHandler.is());
+ m_rDocumentHandler->endElement(str);
+}
+
+void XFlatXml::characters(const OUString& str)
+ throw (SAXException, RuntimeException)
+{
+ OSL_ASSERT(m_rDocumentHandler.is());
+ m_rDocumentHandler->characters(str);
+}
+
+void XFlatXml::ignorableWhitespace(const OUString& str)
+ throw (SAXException, RuntimeException)
+{
+ OSL_ASSERT(m_rDocumentHandler.is());
+ if (!m_bPrettyPrint) return;
+ m_rDocumentHandler->ignorableWhitespace(str);
+}
+
+void XFlatXml::processingInstruction(const OUString& str, const OUString& str2)
+ throw (SAXException, RuntimeException)
+{
+ OSL_ASSERT(m_rDocumentHandler.is());
+ m_rDocumentHandler->processingInstruction(str, str2);
+}
+
+void XFlatXml::setDocumentLocator(const Reference<XLocator>& doclocator)
+ throw (SAXException, RuntimeException)
+{
+ OSL_ASSERT(m_rDocumentHandler.is());
+ m_rDocumentHandler->setDocumentLocator(doclocator);
+}
+
+// --------------------------------------
+// Component management
+// --------------------------------------
+Reference< XInterface > SAL_CALL CreateInstance( const Reference< XMultiServiceFactory > &r)
+{
+ return Reference< XInterface >(( OWeakObject *)new XFlatXml(r));
+}
+
+Sequence< OUString > getSupportedServiceNames()
+{
+ static Sequence < OUString > *pNames = 0;
+ if( ! pNames )
+ {
+ MutexGuard guard( Mutex::getGlobalMutex() );
+ if( !pNames )
+ {
+ static Sequence< OUString > seqNames(1);
+ seqNames.getArray()[0] = OUString::createFromAscii(
+ "devguide.officedev.samples.filter.FlatXmlCpp");
+ pNames = &seqNames;
+ }
+ }
+ return *pNames;
+}
+
+}
+
+using namespace XFlatXml;
+#define IMPLEMENTATION_NAME "devguide.officedev.samples.filter.FlatXmlCpp"
+
+
+extern "C"
+{
+void SAL_CALL component_getImplementationEnvironment(
+ const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv )
+{
+ *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
+}
+
+sal_Bool SAL_CALL component_writeInfo(void * pServiceManager, void * pRegistryKey )
+{
+ if (pRegistryKey)
+ {
+ try
+ {
+ Reference< XRegistryKey > xNewKey(
+ reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey(
+ OUString::createFromAscii( "/" IMPLEMENTATION_NAME "/UNO/SERVICES" ) ) );
+
+ const Sequence< OUString > & rSNL = getSupportedServiceNames();
+ const OUString * pArray = rSNL.getConstArray();
+ for ( sal_Int32 nPos = rSNL.getLength(); nPos--; )
+ xNewKey->createKey( pArray[nPos] );
+
+ return sal_True;
+ }
+ catch (InvalidRegistryException &)
+ {
+ OSL_ENSURE( sal_False, "### InvalidRegistryException!" );
+ }
+ }
+ return sal_False;
+}
+
+void * SAL_CALL component_getFactory(
+ const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
+{
+ void * pRet = 0;
+
+ if (pServiceManager && rtl_str_compare( pImplName, IMPLEMENTATION_NAME ) == 0)
+ {
+ Reference< XSingleServiceFactory > xFactory( createSingleFactory(
+ reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
+ OUString::createFromAscii( pImplName ),
+ CreateInstance, getSupportedServiceNames() ) );
+
+ if (xFactory.is())
+ {
+ xFactory->acquire();
+ pRet = xFactory.get();
+ }
+ }
+ return pRet;
+}
+
+} // extern "C"
diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/FlatXmlFilter_cpp.uno.xml b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/FlatXmlFilter_cpp.uno.xml
new file mode 100644
index 000000000000..9202844eef76
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/FlatXmlFilter_cpp.uno.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE module-description PUBLIC "-//StarOffice//DTD ComponentDescription 1.0//EN" "module-description.dtd">
+<module-description xmlns:xlink="http://www.w3.org/1999/xlink">
+ <module-name> FlatXml </module-name>
+ <component-description>
+ <author> Aidan Butler </author>
+ <name>devguide.officedev.samples.filter.FlatXmlCpp</name>
+
+<description>
+ This component is a sample implementation, which describes how a filter may be written that uses the XmlFilterAdaptor component. This filter opens and saves Flat Xml files.
+ </description>
+ <loader-name> com.sun.star.loader.SharedLibrary </loader-name>
+ <language> c++ </language>
+ <status value="final"/>
+ <supported-service>devguide.officedev.samples.filter.FlatXmlCpp</supported-service>
+ <type>com.sun.star.lang.XSingleServiceFactory</type>
+ <type>com.sun.star.uno.XNamingService</type>
+ <type>com.sun.star.uno.XComponentContext</type>
+ <type>com.sun.star.uno.XWeak</type>
+ <type>com.sun.star.lang.XMain</type>
+ <type>com.sun.star.uno.XAggregation</type>
+ <type>com.sun.star.lang.XMultiServiceFactory</type>
+ <type>com.sun.star.lang.XSingleComponentFactory</type>
+ <type>com.sun.star.lang.XTypeProvider</type>
+ <type>com.sun.star.frame.XComponentLoader</type>
+ <type>com.sun.star.registry.XSimpleRegistry</type>
+ <type>com.sun.star.loader.XImplementationLoader</type>
+ <type>com.sun.star.registry.XImplementationRegistration</type>
+ <type>com.sun.star.lang.XComponent</type>
+ <type>com.sun.star.bridge.XBridgeFactory</type>
+ <type>com.sun.star.bridge.XUnoUrlResolver</type>
+ <type>com.sun.star.connection.XAcceptor</type>
+ <type>com.sun.star.connection.XConnector</type>
+ <type>com.sun.star.container.XHierarchicalNameAccess</type>
+ <type>com.sun.star.lang.XServiceInfo</type>
+ <type>com.sun.star.xml.sax.XDocumentHandler</type>
+ <type>com.sun.star.xml.sax.XExtendedDocumentHandler</type>
+ <type>com.sun.star.text.XTextDocument</type>
+ <type>com.sun.star.xml.XImportFilter</type>
+ <type>com.sun.star.xml.XExportFilter</type>
+ <type>com.sun.star.io.XInputStream</type>
+ <type>com.sun.star.io.XOutputStream</type>
+ <type>com.sun.star.io.XActiveDataSource</type>
+ <type>com.sun.star.io.XSeekable</type>
+ <type>com.sun.star.frame.XConfigManager</type>
+ <type>com.sun.star.xml.sax.XParser</type>
+ <type>com.sun.star.ucb.XSimpleFileAccess</type>
+ <type>com.sun.star.beans.XPropertySet</type>
+ </component-description>
+ <project-build-dependency> cppuhelper </project-build-dependency>
+ <project-build-dependency> cppu </project-build-dependency>
+ <project-build-dependency> sal </project-build-dependency>
+ <runtime-module-dependency> cppuhelper$(UDK_MAJOR)$(COM) </runtime-module-dependency>
+ <runtime-module-dependency> salhelper$(UDK_MAJOR)$(COM) </runtime-module-dependency>
+ <runtime-module-dependency> cppu$(UDK_MAJOR) </runtime-module-dependency>
+ <runtime-module-dependency> reg$(UDK_MAJOR) </runtime-module-dependency>
+ <runtime-module-dependency> store$(UDK_MAJOR) </runtime-module-dependency>
+ <runtime-module-dependency> sal$(UDK_MAJOR) </runtime-module-dependency>
+</module-description>
diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/FlatXmlFilter_cpp.xcu b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/FlatXmlFilter_cpp.xcu
new file mode 100644
index 000000000000..8244bbd3a810
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/FlatXmlFilter_cpp.xcu
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE oor:component-data SYSTEM "../../../../component-update.dtd">
+<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:package="org.openoffice.TypeDetection" oor:name="Filter">
+ <node oor:name="Filters">
+ <node oor:name="devguide_FlatXMLFilter_Cpp_calc" oor:op="replace">
+ <prop oor:name="FileFormatVersion"><value>0</value></prop>
+ <prop oor:name="Type"><value>devguide_FlatXMLType_Cpp_calc</value></prop>
+ <prop oor:name="DocumentService"><value>com.sun.star.sheet.SpreadsheetDocument</value></prop>
+ <prop oor:name="UIComponent"/>
+ <prop oor:name="UserData"><value oor:separator=",">devguide.officedev.samples.filter.FlatXmlCpp, ,com.sun.star.comp.Calc.XMLOasisImporter,com.sun.star.comp.Calc.XMLOasisExporter</value></prop>
+ <prop oor:name="FilterService"><value>com.sun.star.comp.Writer.XmlFilterAdaptor</value></prop>
+ <prop oor:name="TemplateName"/>
+ <prop oor:name="UIName">
+ <!-- The x-no-translate entry is a marker to prevent l10n tooling from translation. It it is not necessary. -->
+ <value xml:lang="x-no-translate"></value>
+ <value xml:lang="de">DevGuide FlatXML Calc</value>
+ <value xml:lang="en-US">DevGuide FlatXML Calc</value>
+ </prop>
+ <prop oor:name="Flags"><value>IMPORT EXPORT ALIEN 3RDPARTYFILTER</value></prop>
+ </node>
+ <node oor:name="devguide_FlatXMLFilter_Cpp_draw" oor:op="replace">
+ <prop oor:name="FileFormatVersion"><value>0</value></prop>
+ <prop oor:name="Type"><value>devguide_FlatXMLType_Cpp_draw</value></prop>
+ <prop oor:name="DocumentService"><value>com.sun.star.drawing.DrawingDocument</value></prop>
+ <prop oor:name="UIComponent"/>
+ <prop oor:name="UserData"><value oor:separator=",">devguide.officedev.samples.filter.FlatXmlCpp, ,com.sun.star.comp.DrawingLayer.XMLOasisImporter,com.sun.star.comp.DrawingLayer.XMLOasisExporter</value></prop>
+ <prop oor:name="FilterService"><value>com.sun.star.comp.Writer.XmlFilterAdaptor</value></prop>
+ <prop oor:name="TemplateName"/>
+ <prop oor:name="UIName">
+ <!-- The x-no-translate entry is a marker to prevent l10n tooling from translation. It it is not necessary. -->
+ <value xml:lang="x-no-translate"></value>
+ <value xml:lang="de">DevGuide FlatXML Draw</value>
+ <value xml:lang="en-US">DevGuide FlatXML Draw</value>
+ </prop>
+ <prop oor:name="Flags"><value>IMPORT EXPORT ALIEN 3RDPARTYFILTER</value></prop>
+ </node>
+ <node oor:name="devguide_FlatXMLFilter_Cpp_impress" oor:op="replace">
+ <prop oor:name="FileFormatVersion"><value>0</value></prop>
+ <prop oor:name="Type"><value>devguide_FlatXMLType_Cpp_impress</value></prop>
+ <prop oor:name="DocumentService"><value>com.sun.star.presentation.PresentationDocument</value></prop>
+ <prop oor:name="UIComponent"/>
+ <prop oor:name="UserData"><value oor:separator=",">devguide.officedev.samples.filter.FlatXmlCpp, ,com.sun.star.comp.Impress.XMLOasisImporter,com.sun.star.comp.Impress.XMLOasisExporter</value></prop>
+ <prop oor:name="FilterService"><value>com.sun.star.comp.Writer.XmlFilterAdaptor</value></prop>
+ <prop oor:name="TemplateName"/>
+ <prop oor:name="UIName">
+ <!-- The x-no-translate entry is a marker to prevent l10n tooling from translation. It it is not necessary. -->
+ <value xml:lang="x-no-translate"></value>
+ <value xml:lang="de">DevGuide FlatXML Impress</value>
+ <value xml:lang="en-US">DevGuide FlatXML Impress</value>
+ </prop>
+ <prop oor:name="Flags"><value>IMPORT EXPORT ALIEN 3RDPARTYFILTER</value></prop>
+ </node>
+ <node oor:name="devguide_FlatXMLFilter_Cpp_writer" oor:op="replace">
+ <prop oor:name="FileFormatVersion"><value>0</value></prop>
+ <prop oor:name="Type"><value>devguide_FlatXMLType_Cpp_writer</value></prop>
+ <prop oor:name="DocumentService"><value>com.sun.star.text.TextDocument</value></prop>
+ <prop oor:name="UIComponent"/>
+ <prop oor:name="UserData"><value oor:separator=",">devguide.officedev.samples.filter.FlatXmlCpp, ,com.sun.star.comp.Writer.XMLOasisImporter,com.sun.star.comp.Writer.XMLOasisExporter</value></prop>
+ <prop oor:name="FilterService"><value>com.sun.star.comp.Writer.XmlFilterAdaptor</value></prop>
+ <prop oor:name="TemplateName"/>
+ <prop oor:name="UIName">
+ <!-- The x-no-translate entry is a marker to prevent l10n tooling from translation. It it is not necessary. -->
+ <value xml:lang="x-no-translate"></value>
+ <value xml:lang="de">DevGuide FlatXML Writer</value>
+ <value xml:lang="en-US">DevGuide FlatXML Writer</value>
+ </prop>
+ <prop oor:name="Flags"><value>IMPORT EXPORT ALIEN 3RDPARTYFILTER</value></prop>
+ </node>
+ <node oor:name="devguide_FlatXMLFilter_Cpp_master" oor:op="replace">
+ <prop oor:name="FileFormatVersion"><value>0</value></prop>
+ <prop oor:name="Type"><value>devguide_FlatXMLType_Cpp_master</value></prop>
+ <prop oor:name="DocumentService"><value>com.sun.star.text.GlobalDocument</value></prop>
+ <prop oor:name="UIComponent"/>
+ <prop oor:name="UserData"><value oor:separator=",">devguide.officedev.samples.filter.FlatXmlCpp, ,com.sun.star.comp.Writer.XMLOasisImporter,com.sun.star.comp.Writer.XMLOasisExporter</value></prop>
+ <prop oor:name="FilterService"><value>com.sun.star.comp.Writer.XmlFilterAdaptor</value></prop>
+ <prop oor:name="TemplateName"/>
+ <prop oor:name="UIName">
+ <!-- The x-no-translate entry is a marker to prevent l10n tooling from translation. It it is not necessary. -->
+ <value xml:lang="x-no-translate"></value>
+ <value xml:lang="de">DevGuide FlatXML Matser</value>
+ <value xml:lang="en-US">DevGuide FlatXML Master</value>
+ </prop>
+ <prop oor:name="Flags"><value>IMPORT EXPORT ALIEN 3RDPARTYFILTER</value></prop>
+ </node>
+ </node>
+</oor:component-data>
diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/Makefile b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/Makefile
new file mode 100644
index 000000000000..4ab62f8997da
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp/Makefile
@@ -0,0 +1,154 @@
+#*************************************************************************
+#
+# $RCSfile: Makefile,v $
+#
+# $Revision: 1.9 $
+#
+# last change: $Author: rt $ $Date: 2008-07-11 14:23:49 $
+#
+# The Contents of this file are made available subject to the terms of
+# the BSD license.
+#
+# Copyright (c) 2003 by Sun Microsystems, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+#**************************************************************************
+
+# Builds the C++ FlatXmlFilter component example of the Developers Guide.
+
+PRJ=../../../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+include $(SETTINGS)/dk.mk
+
+# Define non-platform/compiler specific settings
+COMP_NAME=FlatXmlFilter_cpp
+COMP_IMPL_NAME=$(COMP_NAME).uno.$(SHAREDLIB_EXT)
+OUT_COMP_INC = $(OUT_INC)/$(COMP_NAME)
+OUT_COMP_GEN = $(OUT_MISC)/$(COMP_NAME)
+OUT_COMP_SLO=$(OUT_SLO)/$(COMP_NAME)
+COMP_PACKAGE = $(OUT_BIN)/$(COMP_NAME).$(UNOOXT_EXT)
+COMP_PACKAGE_URL = $(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP_NAME).$(UNOOXT_EXT)")
+COMP_UNOPKG_MANIFEST = $(OUT_COMP_GEN)/$(COMP_NAME)/META-INF/manifest.xml
+COMP_MAPFILE = $(OUT_COMP_GEN)/$(COMP_NAME).uno.map
+
+REGISTERFLAG = $(OUT_MISC)/devguide_$(COMP_NAME)_register_component.flag
+
+CXXFILES = FlatXml.cxx
+
+SLOFILES = $(patsubst %.cxx,$(OUT_COMP_SLO)/%.$(OBJ_EXT),$(CXXFILES))
+
+# Targets
+.PHONY: ALL
+ALL : \
+ FlatXmlFilterCppExample
+
+include $(SETTINGS)/stdtarget.mk
+
+$(OUT_COMP_SLO)/%.$(OBJ_EXT) : %.cxx $(SDKTYPEFLAG)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(CC) $(CC_FLAGS) $(CC_INCLUDES) -I$(OUT_COMP_INC) $(CC_DEFINES) $(CC_OUTPUT_SWITCH)$(subst /,$(PS),$@) $<
+
+$(COMP_MAPFILE) : $(SLOFILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ cat $(PRJ)/settings/component.uno.map > $(COMP_MAPFILE)
+ifeq "$(OS)" "MACOSX"
+ nm -gx $(SLOFILES) | $(ADDSYMBOLS) >> $(COMP_MAPFILE)
+endif
+
+ifeq "$(OS)" "WIN"
+$(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ -$(MKDIR) $(subst /,$(PS),$(OUT_COMP_GEN))
+ $(LINK) $(COMP_LINK_FLAGS) /OUT:$@ \
+ /MAP:$(OUT_COMP_GEN)/$(subst $(SHAREDLIB_EXT),map,$(@F)) $(SLOFILES) \
+ $(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) $(STLPORTLIB) msvcrt.lib kernel32.lib
+ $(LINK_MANIFEST_VC8_ONLY)
+else
+$(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES) $(COMP_MAPFILE)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(LINK) $(COMP_LINK_FLAGS) $(LINK_LIBS) -o $@ $(SLOFILES) \
+ $(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) $(STLPORTLIB) $(STC++LIB) $(CPPUHELPERDYLIB) $(CPPUDYLIB) $(SALDYLIB)
+ifeq "$(OS)" "MACOSX"
+ $(INSTALL_NAME_URELIBS) $@
+endif
+endif
+
+# rule for component package manifest
+$(OUT_COMP_GEN)/%/manifest.xml :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@
+ @echo $(OSEP)!DOCTYPE manifest:manifest PUBLIC "$(QM)-//OpenOffice.org//DTD Manifest 1.0//EN$(QM)" "$(QM)Manifest.dtd$(QM)"$(CSEP) >> $@
+ @echo $(OSEP)manifest:manifest xmlns:manifest="$(QM)http://openoffice.org/2001/manifest$(QM)"$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.configuration-data$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)FlatXmlFilter_cpp.xcu$(QM)"/$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-component;type=native;platform=$(UNOPKG_PLATFORM)$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(subst /META-INF,,$(subst $(OUT_COMP_GEN)/,,$(UNOPKG_PLATFORM)/$(@D))).uno.$(SHAREDLIB_EXT)$(QM)"/$(CSEP) >> $@
+ @echo $(OSEP)/manifest:manifest$(CSEP) >> $@
+
+# rule for component package file
+$(COMP_PACKAGE) : $(SHAREDLIB_OUT)/$(COMP_IMPL_NAME) FlatXmlFilter_cpp.xcu $(COMP_UNOPKG_MANIFEST)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ -$(MKDIR) $(subst /,$(PS),$(OUT_COMP_GEN)/$(UNOPKG_PLATFORM))
+ $(COPY) $(subst /,$(PS),$<) $(subst /,$(PS),$(OUT_COMP_GEN)/$(UNOPKG_PLATFORM))
+ $(SDK_ZIP) $@ FlatXmlFilter_cpp.xcu
+ cd $(subst /,$(PS),$(OUT_COMP_GEN)) && $(SDK_ZIP) -u ../../bin/$(@F) $(UNOPKG_PLATFORM)/$(<F)
+ cd $(subst /,$(PS),$(OUT_COMP_GEN)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml
+
+$(REGISTERFLAG) : $(COMP_PACKAGE)
+ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES"
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(DEPLOYTOOL) $(COMP_PACKAGE_URL)
+ @echo flagged > $(subst /,$(PS),$@)
+else
+ @echo --------------------------------------------------------------------------------
+ @echo If you want to install your component automatically, please set the environment
+ @echo variable SDK_AUTO_DEPLOYMENT = YES. But note that auto deployment is only
+ @echo possible if no office instance is running.
+ @echo --------------------------------------------------------------------------------
+endif
+
+FlatXmlFilterCppExample : $(REGISTERFLAG)
+ @echo --------------------------------------------------------------------------------
+ @echo The C++ FlatXmlFilter component is installed if SDK_AUTO_DEPLOYMENT = YES.
+ @echo You can use the filters "$(QM)DevGuide FlatXML ...$(QM)" inside your office installation
+ @echo after you have installed the "$(QM)FlatXmlTypeDetection.uno.pkg"$(QM) as well.
+ @echo --------------------------------------------------------------------------------
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_INC))
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_GEN))
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_SLO))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_PACKAGE_URL)))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$(REGISTERFLAG)))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_TYPEFLAG)))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$(SHAREDLIB_OUT)/$(COMP_NAME).*))
diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/FlatXml.java b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/FlatXml.java
new file mode 100644
index 000000000000..c2e852dab345
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/FlatXml.java
@@ -0,0 +1,279 @@
+/*************************************************************************
+ *
+ * $RCSfile: FlatXml.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: hr $ $Date: 2004-03-09 10:11:06 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import java.io.*;
+import java.util.*;
+import com.sun.star.uno.*;
+import com.sun.star.lang.*;
+import com.sun.star.beans.*;
+
+import com.sun.star.comp.loader.FactoryHelper;
+import com.sun.star.registry.XRegistryKey;
+
+import com.sun.star.xml.*;
+import com.sun.star.xml.sax.*;
+
+import com.sun.star.io.XInputStream;
+import com.sun.star.io.XOutputStream;
+import com.sun.star.io.XActiveDataSource;
+
+
+
+public class FlatXml implements XImportFilter, XExportFilter, XServiceName,
+ XServiceInfo, XDocumentHandler, XTypeProvider
+{
+
+ /*
+ * private data members
+ */
+ private XMultiServiceFactory m_xServiceFactory;
+ private XExtendedDocumentHandler m_xHandler;
+ private boolean m_bPrettyPrint = true;
+
+ static private final String __serviceName = "devguide.officedev.samples.filter.FlatXmlJava";
+ static private final String __implName = "FlatXml";
+ static private final String[] __supportedServiceNames = {
+ "devguide.officedev.samples.filter.FlatXmlJava"
+ };
+
+ public FlatXml(XMultiServiceFactory f) {
+ m_xServiceFactory = f;
+ }
+
+ // --- XTypeProvider ---
+ public byte[] getImplementationId() {
+ return Integer.toString(this.hashCode()).getBytes();
+ }
+
+ // --- XServiceName ---
+ public String getServiceName() {
+ return( __serviceName );
+ }
+
+ // --- XServiceInfo ---
+ public boolean supportsService(String sName) {
+ for (int i = 0; i < __supportedServiceNames.length; i++) {
+ if (__supportedServiceNames[i].equals(sName)) return true;
+ }
+ return false;
+ }
+ public String getImplementationName() {
+ return( this.getClass().getName() );
+ }
+ public String[] getSupportedServiceNames() {
+ return( __supportedServiceNames );
+ }
+
+ public com.sun.star.uno.Type[] getTypes() {
+ Type[] typeReturn = {};
+ try {
+ typeReturn = new Type[] {
+ new Type( XTypeProvider.class ),
+ new Type( XExportFilter.class ),
+ new Type( XImportFilter.class ),
+ new Type( XServiceName.class ),
+ new Type( XServiceInfo.class )
+ };
+ } catch( java.lang.Exception exception ) {
+ return null;
+ }
+ return( typeReturn );
+ }
+
+ public boolean importer(PropertyValue[] aSourceData, XDocumentHandler xDocHandler, String[] msUserData)
+ throws com.sun.star.uno.RuntimeException, com.sun.star.lang.IllegalArgumentException
+ {
+ String sName = null;
+ String sFileName = null;
+ String sURL = null;
+ com.sun.star.io.XInputStream xin = null;
+
+ try {
+
+ for (int i = 0 ; i < aSourceData.length; i++)
+ {
+ sName = aSourceData[i].Name;
+ if (sName.equals("InputStream"))
+ xin = (XInputStream)AnyConverter.toObject(XInputStream.class, aSourceData[i].Value);
+ if (sName.equals("URL"))
+ sURL=(String)AnyConverter.toObject(String.class, aSourceData[i].Value);
+ if (sName.equals("FileName"))
+ sFileName=(String)AnyConverter.toObject(String.class, aSourceData[i].Value);
+ }
+
+ Object tmpObj=m_xServiceFactory.createInstance("com.sun.star.xml.sax.Parser");
+ if (tmpObj == null) return false;
+
+ XParser xParser = (XParser)UnoRuntime.queryInterface(XParser.class , tmpObj);
+ if (xParser == null) return false;
+
+ InputSource aInput = new InputSource();
+ aInput.sSystemId = sURL;
+ aInput.aInputStream =xin;
+ xParser.setDocumentHandler ( xDocHandler );
+ xParser.parseStream ( aInput );
+ } catch (com.sun.star.uno.Exception e){
+ e.printStackTrace();
+ return false;
+ }
+
+ // done...
+ return true;
+ }
+
+ public boolean exporter(PropertyValue[] aSourceData, String[] msUserData)
+ throws com.sun.star.uno.RuntimeException, com.sun.star.lang.IllegalArgumentException
+ {
+ try {
+ String sURL = null;
+ String sName = null;
+ XOutputStream xos = null;
+
+ // get interesting values from sourceData
+ for (int i = 0 ; i < aSourceData.length; i++)
+ {
+ sName = aSourceData[i].Name;
+ if (sName.equals("OutputStream"))
+ xos = (XOutputStream)AnyConverter.toObject(XOutputStream.class, aSourceData[i].Value);
+ if (sName.equals("URL"))
+ sURL=(String)AnyConverter.toObject(String.class, aSourceData[i].Value);
+ }
+
+ // prepare the XML writer
+ Object tmpObj = null;
+ if (m_xHandler == null)
+ {
+ tmpObj = m_xServiceFactory.createInstance("com.sun.star.xml.sax.Writer");
+ if (tmpObj != null)
+ m_xHandler = (XExtendedDocumentHandler)UnoRuntime.queryInterface(XExtendedDocumentHandler.class, tmpObj);
+ }
+ if (m_xHandler == null)
+ return false;
+
+ // Connect the provided output stream to the writer
+ XActiveDataSource xADSource = (XActiveDataSource)UnoRuntime.queryInterface(
+ XActiveDataSource.class, m_xHandler);
+
+ if (xADSource != null && xos != null)
+ xADSource.setOutputStream(xos);
+ else
+ return false;
+ } catch (com.sun.star.uno.Exception e){
+ return false;
+ }
+
+ // done ...
+ return true;
+ }
+
+ public void startDocument ()
+ throws com.sun.star.xml.sax.SAXException
+ {
+ m_xHandler.startDocument();
+ }
+
+ public void endDocument()
+ throws com.sun.star.xml.sax.SAXException
+ {
+ m_xHandler.endDocument();
+ }
+
+ public void startElement (String str, com.sun.star.xml.sax.XAttributeList xattribs)
+ throws com.sun.star.xml.sax.SAXException
+ {
+ m_xHandler.startElement(str, xattribs);
+ }
+
+ public void endElement(String str)
+ throws com.sun.star.xml.sax.SAXException
+ {
+ m_xHandler.endElement(str);
+ }
+
+ public void characters(String str)
+ throws com.sun.star.xml.sax.SAXException
+ {
+ m_xHandler.characters(str);
+ }
+
+ public void ignorableWhitespace(String str)
+ throws com.sun.star.xml.sax.SAXException
+ {
+ if (!m_bPrettyPrint) return;
+ else m_xHandler.ignorableWhitespace(str);
+ }
+
+ public void processingInstruction(String aTarget, String aData)
+ throws com.sun.star.xml.sax.SAXException
+ {
+ m_xHandler.processingInstruction(aTarget, aData);
+ }
+
+ public void setDocumentLocator(XLocator xLocator)
+ throws com.sun.star.xml.sax.SAXException
+ {
+ m_xHandler.setDocumentLocator(xLocator);
+ }
+
+ // ------------------------------------------------------------
+ // component management
+
+ public static XSingleServiceFactory __getServiceFactory(String implName,
+ XMultiServiceFactory multiFactory, XRegistryKey regKey)
+ {
+ XSingleServiceFactory xSingleServiceFactory = null;
+ if (implName.equals(__implName) ) {
+ try {
+ xSingleServiceFactory = FactoryHelper.getServiceFactory(
+ Class.forName(implName), __serviceName, multiFactory, regKey);
+ } catch (java.lang.ClassNotFoundException e) {
+ return null;
+ }
+ }
+ return xSingleServiceFactory;
+ }
+
+ public static boolean __writeRegistryServiceInfo(XRegistryKey regKey)
+ {
+ return FactoryHelper.writeRegistryServiceInfo(__implName,
+ __serviceName, regKey);
+ }
+
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/FlatXmlFilter_java.xcu b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/FlatXmlFilter_java.xcu
new file mode 100644
index 000000000000..16a04144c5e7
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/FlatXmlFilter_java.xcu
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE oor:component-data SYSTEM "../../../../component-update.dtd">
+<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:package="org.openoffice.TypeDetection" oor:name="Filter">
+ <node oor:name="Filters">
+ <node oor:name="devguide_FlatXMLFilter_Java_calc" oor:op="replace">
+ <prop oor:name="FileFormatVersion"><value>0</value></prop>
+ <prop oor:name="Type"><value>devguide_FlatXMLType_Cpp_calc</value></prop>
+ <prop oor:name="DocumentService"><value>com.sun.star.sheet.SpreadsheetDocument</value></prop>
+ <prop oor:name="UIComponent"/>
+ <prop oor:name="UserData"><value oor:separator=",">devguide.officedev.samples.filter.FlatXmlJava, ,com.sun.star.comp.Calc.XMLOasisImporter,com.sun.star.comp.Calc.XMLOasisExporter</value></prop>
+ <prop oor:name="FilterService"><value>com.sun.star.comp.Writer.XmlFilterAdaptor</value></prop>
+ <prop oor:name="TemplateName"/>
+ <prop oor:name="UIName">
+ <!-- The x-no-translate entry is a marker to prevent l10n tooling from translation. It it is not necessary. -->
+ <value xml:lang="x-no-translate"></value>
+ <value xml:lang="de">DevGuide FlatXML Calc</value>
+ <value xml:lang="en-US">DevGuide FlatXML Calc</value>
+ </prop>
+ <prop oor:name="Flags"><value>IMPORT EXPORT ALIEN 3RDPARTYFILTER</value></prop>
+ </node>
+ <node oor:name="devguide_FlatXMLFilter_Java_draw" oor:op="replace">
+ <prop oor:name="FileFormatVersion"><value>0</value></prop>
+ <prop oor:name="Type"><value>devguide_FlatXMLType_Cpp_draw</value></prop>
+ <prop oor:name="DocumentService"><value>com.sun.star.drawing.DrawingDocument</value></prop>
+ <prop oor:name="UIComponent"/>
+ <prop oor:name="UserData"><value oor:separator=",">devguide.officedev.samples.filter.FlatXmlJava, ,com.sun.star.comp.DrawingLayer.XMLOasisImporter,com.sun.star.comp.DrawingLayer.XMLOasisExporter</value></prop>
+ <prop oor:name="FilterService"><value>com.sun.star.comp.Writer.XmlFilterAdaptor</value></prop>
+ <prop oor:name="TemplateName"/>
+ <prop oor:name="UIName">
+ <!-- The x-no-translate entry is a marker to prevent l10n tooling from translation. It it is not necessary. -->
+ <value xml:lang="x-no-translate"></value>
+ <value xml:lang="de">DevGuide FlatXML Draw</value>
+ <value xml:lang="en-US">DevGuide FlatXML Draw</value>
+ </prop>
+ <prop oor:name="Flags"><value>IMPORT EXPORT ALIEN 3RDPARTYFILTER</value></prop>
+ </node>
+ <node oor:name="devguide_FlatXMLFilter_Java_impress" oor:op="replace">
+ <prop oor:name="FileFormatVersion"><value>0</value></prop>
+ <prop oor:name="Type"><value>devguide_FlatXMLType_Cpp_impress</value></prop>
+ <prop oor:name="DocumentService"><value>com.sun.star.presentation.PresentationDocument</value></prop>
+ <prop oor:name="UIComponent"/>
+ <prop oor:name="UserData"><value oor:separator=",">devguide.officedev.samples.filter.FlatXmlJava, ,com.sun.star.comp.Impress.XMLOasisImporter,com.sun.star.comp.Impress.XMLOasisExporter</value></prop>
+ <prop oor:name="FilterService"><value>com.sun.star.comp.Writer.XmlFilterAdaptor</value></prop>
+ <prop oor:name="TemplateName"/>
+ <prop oor:name="UIName">
+ <!-- The x-no-translate entry is a marker to prevent l10n tooling from translation. It it is not necessary. -->
+ <value xml:lang="x-no-translate"></value>
+ <value xml:lang="de">DevGuide FlatXML Impress</value>
+ <value xml:lang="en-US">DevGuide FlatXML Impress</value>
+ </prop>
+ <prop oor:name="Flags"><value>IMPORT EXPORT ALIEN 3RDPARTYFILTER</value></prop>
+ </node>
+ <node oor:name="devguide_FlatXMLFilter_Java_writer" oor:op="replace">
+ <prop oor:name="FileFormatVersion"><value>0</value></prop>
+ <prop oor:name="Type"><value>devguide_FlatXMLType_Cpp_writer</value></prop>
+ <prop oor:name="DocumentService"><value>com.sun.star.text.TextDocument</value></prop>
+ <prop oor:name="UIComponent"/>
+ <prop oor:name="UserData"><value oor:separator=",">devguide.officedev.samples.filter.FlatXmlJava, ,com.sun.star.comp.Writer.XMLOasisImporter,com.sun.star.comp.Writer.XMLOasisExporter</value></prop>
+ <prop oor:name="FilterService"><value>com.sun.star.comp.Writer.XmlFilterAdaptor</value></prop>
+ <prop oor:name="TemplateName"/>
+ <prop oor:name="UIName">
+ <!-- The x-no-translate entry is a marker to prevent l10n tooling from translation. It it is not necessary. -->
+ <value xml:lang="x-no-translate"></value>
+ <value xml:lang="de">DevGuide FlatXML Writer</value>
+ <value xml:lang="en-US">DevGuide FlatXML Writer</value>
+ </prop>
+ <prop oor:name="Flags"><value>IMPORT EXPORT ALIEN 3RDPARTYFILTER</value></prop>
+ </node>
+ <node oor:name="devguide_FlatXMLFilter_Java_master" oor:op="replace">
+ <prop oor:name="FileFormatVersion"><value>0</value></prop>
+ <prop oor:name="Type"><value>devguide_FlatXMLType_Cpp_master</value></prop>
+ <prop oor:name="DocumentService"><value>com.sun.star.text.GlobalDocument</value></prop>
+ <prop oor:name="UIComponent"/>
+ <prop oor:name="UserData"><value oor:separator=",">devguide.officedev.samples.filter.FlatXmlJava, ,com.sun.star.comp.Writer.XMLOasisImporter,com.sun.star.comp.Writer.XMLOasisExporter</value></prop>
+ <prop oor:name="FilterService"><value>com.sun.star.comp.Writer.XmlFilterAdaptor</value></prop>
+ <prop oor:name="TemplateName"/>
+ <prop oor:name="UIName">
+ <!-- The x-no-translate entry is a marker to prevent l10n tooling from translation. It it is not necessary. -->
+ <value xml:lang="x-no-translate"></value>
+ <value xml:lang="de">DevGuide FlatXML Master</value>
+ <value xml:lang="en-US">DevGuide FlatXML Master</value>
+ </prop>
+ <prop oor:name="Flags"><value>IMPORT EXPORT ALIEN 3RDPARTYFILTER</value></prop>
+ </node>
+ </node>
+</oor:component-data>
diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/Makefile b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/Makefile
new file mode 100644
index 000000000000..d45c4aabf85b
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/Makefile
@@ -0,0 +1,147 @@
+#*************************************************************************
+#
+# $RCSfile: Makefile,v $
+#
+# $Revision: 1.7 $
+#
+# last change: $Author: obo $ $Date: 2007-01-25 11:06:55 $
+#
+# The Contents of this file are made available subject to the terms of
+# the BSD license.
+#
+# Copyright (c) 2003 by Sun Microsystems, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+#**************************************************************************
+
+# Builds the Java FlatXMLFilter component example of the Developers Guide.
+
+PRJ=../../../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+include $(SETTINGS)/dk.mk
+
+# Define non-platform/compiler specific settings
+COMPONENT_NAME=FlatXmlFilter_java
+OUT_COMP_CLASS = $(OUT_CLASS)/$(COMPONENT_NAME)
+COMPONENT_PACKAGE = $(OUT_BIN)/$(COMPONENT_NAME).$(UNOOXT_EXT)
+COMPONENT_PACKAGE_URL = $(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMPONENT_NAME).$(UNOOXT_EXT)")
+COMPONENT_JAR_NAME = $(COMPONENT_NAME).uno.jar
+COMPONENT_JAR = $(OUT_COMP_CLASS)/$(COMPONENT_JAR_NAME)
+COMPONENT_MANIFESTFILE = $(OUT_COMP_CLASS)/$(COMPONENT_NAME).uno.Manifest
+COMPONENT_UNOPKG_MANIFEST = $(OUT_COMP_CLASS)/$(COMPONENT_NAME)/META-INF/manifest.xml
+REGISTERFLAG = $(OUT_MISC)$(PS)devguide_$(COMPONENT_NAME)_register_component.flag
+
+JAVAFILES = \
+ FlatXml.java \
+
+CLASSFILES = $(patsubst %.java,$(OUT_COMP_CLASS)/%.class,$(JAVAFILES))
+
+
+#$(COMPONENT_NAME)_CLASSFILES = FlatXml.class FlatXml$(dlr)_FlatXml.class
+
+$(COMPONENT_NAME)_CLASSFILES = *.class
+
+SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
+ $(PATH_SEPARATOR)$(OUT_COMP_CLASS))
+
+
+# Targets
+.PHONY: ALL
+ALL : \
+ FlatXmlFilterJavaExample
+
+include $(SETTINGS)/stdtarget.mk
+
+$(OUT_COMP_CLASS)/%.Manifest :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo RegistrationClassName: FlatXml> $@
+
+$(CLASSFILES) : $(JAVAFILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_COMP_CLASS) $(JAVAFILES)
+
+# rule for component jar file
+$(COMPONENT_JAR) : $(COMPONENT_MANIFESTFILE) $(CLASSFILES)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_JAR) cvfm $(@F) $(<F) $($(basename $(basename $(@F)))_CLASSFILES)
+
+# rule for component package manifest
+$(OUT_COMP_CLASS)/%/manifest.xml :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@
+ @echo $(OSEP)!DOCTYPE manifest:manifest PUBLIC "$(QM)-//OpenOffice.org//DTD Manifest 1.0//EN$(QM)" "$(QM)Manifest.dtd$(QM)"$(CSEP) >> $@
+ @echo $(OSEP)manifest:manifest xmlns:manifest="$(QM)http://openoffice.org/2001/manifest$(QM)"$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.configuration-data$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)FlatXmlFilter_java.xcu$(QM)"/$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-component;type=Java$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(subst /META-INF,,$(subst $(OUT_COMP_CLASS)/,,$(@D))).uno.jar$(QM)"/$(CSEP) >> $@
+ @echo $(OSEP)/manifest:manifest$(CSEP) >> $@
+
+# rule for component package file
+$(COMPONENT_PACKAGE) : $(COMPONENT_JAR) FlatXmlFilter_java.xcu $(COMPONENT_UNOPKG_MANIFEST)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_ZIP) $@ FlatXmlFilter_java.xcu
+ cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_ZIP) ../../bin/$(@F) $(<F)
+ cd $(subst /,$(PS),$(OUT_COMP_CLASS)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml
+
+$(REGISTERFLAG) : $(COMPONENT_PACKAGE)
+ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES"
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(DEPLOYTOOL) $(COMPONENT_PACKAGE_URL)
+ @echo flagged > $(subst /,$(PS),$@)
+else
+ @echo --------------------------------------------------------------------------------
+ @echo If you want to install your component automatically, please set the environment
+ @echo variable SDK_AUTO_DEPLOYMENT = YES. But note that auto deployment is only
+ @echo possible if no office instance is running.
+ @echo --------------------------------------------------------------------------------
+endif
+
+FlatXmlFilterJavaExample : $(REGISTERFLAG)
+ @echo --------------------------------------------------------------------------------
+ @echo The Java FlatXmlFilter component is installed if SDK_AUTO_DEPLOYMENT = YES.
+ @echo You can use the filters "$(QM)DevGuide FlatXML ...$(QM)" inside your office installation
+ @echo after you have installed the "$(QM)FlatXmlTypeDetection.uno.pkg"$(QM) as well.
+ @echo --------------------------------------------------------------------------------
+
+%.run: $(OUT_COMP_CLASS)/%.class
+ $(SDK_JAVA) -classpath "$(SDK_CLASSPATH)" $(basename $@)
+
+%.local: $(OUT_COMP_CLASS)/%.class
+ $(SDK_JAVA) -classpath "$(SDK_CLASSPATH)" $(basename $@) local
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_CLASS))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMPONENT_PACKAGE_URL)))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$(REGISTERFLAG)))
diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/LinguisticExamples.java b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/LinguisticExamples.java
new file mode 100644
index 000000000000..21dd3f9c0113
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/LinguisticExamples.java
@@ -0,0 +1,374 @@
+/*************************************************************************
+ *
+ * $RCSfile: LinguisticExamples.java,v $
+ *
+ * $Revision: 1.5 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:47:11 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+// used interfaces
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.linguistic2.XLinguServiceManager;
+import com.sun.star.linguistic2.XSpellChecker;
+import com.sun.star.linguistic2.XHyphenator;
+import com.sun.star.linguistic2.XThesaurus;
+import com.sun.star.linguistic2.XSpellAlternatives;
+import com.sun.star.linguistic2.XHyphenatedWord;
+import com.sun.star.linguistic2.XPossibleHyphens;
+import com.sun.star.linguistic2.XMeaning;
+import com.sun.star.linguistic2.XSearchableDictionaryList;
+import com.sun.star.linguistic2.XLinguServiceEventListener;
+import com.sun.star.linguistic2.LinguServiceEvent;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.uno.XNamingService;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.lang.EventObject;
+import com.sun.star.lang.Locale;
+import com.sun.star.bridge.XUnoUrlResolver;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.Any;
+import com.sun.star.lang.XComponent;
+
+public class LinguisticExamples
+{
+ // The remote office ocntext
+ protected XComponentContext mxRemoteContext = null;
+ // The MultiServiceFactory interface of the Office
+ protected XMultiComponentFactory mxRemoteServiceManager = null;
+
+ // The LinguServiceManager interface
+ protected XLinguServiceManager mxLinguSvcMgr = null;
+
+ // The SpellChecker interface
+ protected XSpellChecker mxSpell = null;
+
+ // The Hyphenator interface
+ protected XHyphenator mxHyph = null;
+
+ // The Thesaurus interface
+ protected XThesaurus mxThes = null;
+
+ // The DictionaryList interface
+ protected XSearchableDictionaryList mxDicList = null;
+
+ // The LinguProperties interface
+ protected XPropertySet mxLinguProps = null;
+
+
+ public static void main(String args[])
+ {
+ // Create an instance of the class and call it's begin method
+ try {
+ LinguisticExamples aExample = new LinguisticExamples();
+ aExample.Connect();
+ aExample.Run();
+ } catch (Exception e) {
+ System.err.println("failed to run examples");
+ e.printStackTrace();
+ }
+ }
+
+
+ public void Connect()
+ throws java.lang.Exception
+ {
+ // get the remote office context. If necessary a new office
+ // process is started
+ mxRemoteContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+ System.out.println("Connected to a running office ...");
+ mxRemoteServiceManager = mxRemoteContext.getServiceManager();
+ }
+
+
+ /** Get the LinguServiceManager to be used. For example to access spell
+ checker, thesaurus and hyphenator, also the component may choose to
+ register itself as listener to it in order to get notified of relevant
+ events. */
+ public boolean GetLinguSvcMgr()
+ throws com.sun.star.uno.Exception
+ {
+ if (mxRemoteContext != null && mxRemoteServiceManager != null) {
+ Object aObj = mxRemoteServiceManager.createInstanceWithContext(
+ "com.sun.star.linguistic2.LinguServiceManager", mxRemoteContext );
+ mxLinguSvcMgr = (XLinguServiceManager)
+ UnoRuntime.queryInterface(XLinguServiceManager.class, aObj);
+ }
+ return mxLinguSvcMgr != null;
+ }
+
+
+ /** Get the SpellChecker to be used.
+ */
+ public boolean GetSpell()
+ throws com.sun.star.uno.Exception,
+ com.sun.star.uno.RuntimeException
+ {
+ if (mxLinguSvcMgr != null)
+ mxSpell = mxLinguSvcMgr.getSpellChecker();
+ return mxSpell != null;
+ }
+
+ /** Get the Hyphenator to be used.
+ */
+ public boolean GetHyph()
+ throws com.sun.star.uno.Exception,
+ com.sun.star.uno.RuntimeException
+ {
+ if (mxLinguSvcMgr != null)
+ mxHyph = mxLinguSvcMgr.getHyphenator();
+ return mxHyph != null;
+ }
+
+ /** Get the Thesaurus to be used.
+ */
+ public boolean GetThes()
+ throws com.sun.star.uno.Exception,
+ com.sun.star.uno.RuntimeException
+ {
+ if (mxLinguSvcMgr != null)
+ mxThes = mxLinguSvcMgr.getThesaurus();
+ return mxThes != null;
+ }
+
+
+ public void Run()
+ throws Exception
+ {
+ GetLinguSvcMgr();
+
+
+ // list of property values to used in function calls below.
+ // Only properties with values different from the (default) values
+ // in the LinguProperties property set need to be supllied.
+ // Thus we may stay with an empty list in order to use the ones
+ // form the property set.
+ PropertyValue[] aEmptyProps = new PropertyValue[0];
+
+ // use american english as language
+ Locale aLocale = new Locale("en","US","");
+
+
+
+ // another list of property values to used in function calls below.
+ // Only properties with values different from the (default) values
+ // in the LinguProperties property set need to be supllied.
+ PropertyValue[] aProps = new PropertyValue[1];
+ aProps[0] = new PropertyValue();
+ aProps[0].Name = "IsGermanPreReform";
+ aProps[0].Value = new Boolean( true );
+
+
+ GetSpell();
+ if (mxSpell != null)
+ {
+ // test with correct word
+ String aWord = "horseback";
+ boolean bIsCorrect = mxSpell.isValid( aWord, aLocale, aEmptyProps );
+ System.out.println( aWord + ": " + bIsCorrect );
+
+ // test with incorrect word
+ aWord = "course";
+ bIsCorrect = mxSpell.isValid( aWord, aLocale , aEmptyProps );
+ System.out.println( aWord + ": " + bIsCorrect );
+
+
+ aWord = "house";
+ XSpellAlternatives xAlt = mxSpell.spell( aWord, aLocale, aEmptyProps );
+ if (xAlt == null)
+ System.out.println( aWord + " is correct." );
+ else
+ {
+ System.out.println( aWord + " is not correct. A list of proposals follows." );
+ String[] aAlternatives = xAlt.getAlternatives();
+ if (aAlternatives.length == 0)
+ System.out.println( "no proposal found." );
+ else
+ {
+ for (int i = 0; i < aAlternatives.length; ++i)
+ System.out.println( aAlternatives[i] );
+ }
+ }
+ }
+
+
+ GetHyph();
+ if (mxHyph != null)
+ {
+ // maximum number of characters to remain before the hyphen
+ // character in the resulting word of the hyphenation
+ short nMaxLeading = 6;
+
+ XHyphenatedWord xHyphWord = mxHyph.hyphenate( "waterfall",
+ aLocale, nMaxLeading ,
+ aEmptyProps );
+ if (xHyphWord == null)
+ System.out.println( "no valid hyphenation position found" );
+ else
+ {
+ System.out.println( "valid hyphenation pos found at "
+ + xHyphWord.getHyphenationPos()
+ + " in " + xHyphWord.getWord() );
+ System.out.println( "hyphenation char will be after char "
+ + xHyphWord.getHyphenPos()
+ + " in " + xHyphWord.getHyphenatedWord() );
+ }
+
+
+ //! Note: 'aProps' needs to have set 'IsGermanPreReform' to true!
+ xHyphWord = mxHyph.queryAlternativeSpelling( "Schiffahrt",
+ new Locale("de","DE",""), (short)4, aProps );
+ if (xHyphWord == null)
+ System.out.println( "no alternative spelling found at specified position." );
+ else
+ {
+ if (xHyphWord.isAlternativeSpelling())
+ System.out.println( "alternative spelling detectetd!" );
+ System.out.println( "valid hyphenation pos found at "
+ + xHyphWord.getHyphenationPos()
+ + " in " + xHyphWord.getWord() );
+ System.out.println( "hyphenation char will be after char "
+ + xHyphWord.getHyphenPos()
+ + " in " + xHyphWord.getHyphenatedWord() );
+ }
+
+
+ XPossibleHyphens xPossHyph = mxHyph.createPossibleHyphens("waterfall",
+ aLocale,
+ aEmptyProps );
+ if (xPossHyph == null)
+ System.out.println( "no hyphenation positions found." );
+ else
+ System.out.println( xPossHyph.getPossibleHyphens() );
+ }
+
+
+ GetThes();
+ if (mxThes != null)
+ {
+ XMeaning[] xMeanings = mxThes.queryMeanings("house", aLocale,
+ aEmptyProps );
+ if (xMeanings == null)
+ System.out.println( "nothing found." );
+ else
+ {
+ for (int i = 0; i < xMeanings.length; ++i)
+ {
+ System.out.println( "Meaning: " + xMeanings[i].getMeaning() );
+ String[] aSynonyms = xMeanings[i].querySynonyms();
+ for (int k = 0; k < aSynonyms.length; ++k)
+ System.out.println( " Synonym: " + aSynonyms[k] );
+ }
+ }
+ }
+
+
+
+ XLinguServiceEventListener aClient = new Client();
+
+ // get access to LinguProperties property set
+ Object aObj = mxRemoteServiceManager.createInstanceWithContext(
+ "com.sun.star.linguistic2.LinguProperties", mxRemoteContext);
+ XPropertySet aLinguProps = (XPropertySet) UnoRuntime.queryInterface(
+ XPropertySet.class,aObj);
+
+ // set a spellchecker and hyphenator property value to a defined state
+ try {
+ aLinguProps.setPropertyValue("IsGermanPreReform", new Boolean(true));
+ } catch (Exception e) {
+ }
+
+ // now add the client as listener to the service manager to
+ // get informed when spellchecking or hyphenation may produce
+ // different results then before.
+ mxLinguSvcMgr.addLinguServiceManagerListener(aClient);
+
+ // change that property value in order to trigger a property change
+ // event that eventually results in the listeners
+ // 'processLinguServiceEvent' function being called
+ try {
+ aLinguProps.setPropertyValue("IsGermanPreReform", new Boolean(false));
+ } catch (Exception e) {
+ }
+
+ //! keep the listener and the program alive until the event will
+ //! be launched.
+ //! There is a voluntary delay before launching the event!
+ // Of course this code would usually not be in a *real* client
+ // its
+ synchronized(this) {
+ try {
+ this.wait(4000);
+ } catch(Exception e) {
+
+ }
+ }
+
+ //! remove listener before programm termination.
+ //! should not be omitted.
+ mxLinguSvcMgr.removeLinguServiceManagerListener(aClient);
+
+
+ System.exit(0);
+ }
+
+ /** simple sample implementation of a clients XLinguServiceEventListener
+ * interface implementation
+ */
+ public class Client
+ implements XLinguServiceEventListener
+ {
+ public void disposing ( EventObject aEventObj )
+ {
+ //! any references to the EventObjects source have to be
+ //! released here now!
+
+ System.out.println("object listened to will be disposed");
+ }
+
+ public void processLinguServiceEvent( LinguServiceEvent aServiceEvent )
+ {
+ //! do here whatever you think needs to be done depending
+ //! on the event recieved (e.g. trigger background spellchecking
+ //! or hyphenation again.)
+
+ System.out.println("Listener called");
+ }
+ };
+
+}
+
diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/Makefile b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/Makefile
new file mode 100644
index 000000000000..9058fefedce0
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/Makefile
@@ -0,0 +1,243 @@
+#*************************************************************************
+#
+# $RCSfile: Makefile,v $
+#
+# $Revision: 1.9 $
+#
+# last change: $Author: obo $ $Date: 2007-01-25 11:07:08 $
+#
+# The Contents of this file are made available subject to the terms of
+# the BSD license.
+#
+# Copyright (c) 2003 by Sun Microsystems, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+#**************************************************************************
+
+# Builds the OfficeDevLinguistic examples of the Developers Guide.
+
+PRJ=../../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+include $(SETTINGS)/dk.mk
+
+# Define non-platform/compiler specific settings
+EXAMPLE_NAME=OfficeDevLinguisticExample
+OUT_COMP_CLASS = $(OUT_CLASS)/$(EXAMPLE_NAME)
+
+COMPONENT1_NAME=SampleHyphenator
+COMPONENT1_PACKAGE = $(OUT_BIN)/$(COMPONENT1_NAME).$(UNOOXT_EXT)
+COMPONENT1_PACKAGE_URL = $(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMPONENT1_NAME).$(UNOOXT_EXT)")
+COMPONENT1_JAR_NAME = $(COMPONENT1_NAME).uno.jar
+COMPONENT1_JAR = $(OUT_COMP_CLASS)/$(COMPONENT1_JAR_NAME)
+COMPONENT1_MANIFESTFILE = $(OUT_COMP_CLASS)/$(COMPONENT1_NAME).uno.Manifest
+COMPONENT1_UNOPKG_MANIFEST = $(OUT_COMP_CLASS)/$(COMPONENT1_NAME)/META-INF/manifest.xml
+
+COMPONENT2_NAME=SampleSpellChecker
+COMPONENT2_PACKAGE = $(OUT_BIN)/$(COMPONENT2_NAME).$(UNOOXT_EXT)
+COMPONENT2_PACKAGE_URL = $(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMPONENT2_NAME).$(UNOOXT_EXT)")
+COMPONENT2_JAR_NAME = $(COMPONENT2_NAME).uno.jar
+COMPONENT2_JAR = $(OUT_COMP_CLASS)/$(COMPONENT2_JAR_NAME)
+COMPONENT2_MANIFESTFILE = $(OUT_COMP_CLASS)/$(COMPONENT2_NAME).uno.Manifest
+COMPONENT2_UNOPKG_MANIFEST = $(OUT_COMP_CLASS)/$(COMPONENT2_NAME)/META-INF/manifest.xml
+
+COMPONENT3_NAME=SampleThesaurus
+COMPONENT3_PACKAGE = $(OUT_BIN)/$(COMPONENT3_NAME).$(UNOOXT_EXT)
+COMPONENT3_PACKAGE_URL = $(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMPONENT3_NAME).$(UNOOXT_EXT)")
+COMPONENT3_JAR_NAME = $(COMPONENT3_NAME).uno.jar
+COMPONENT3_JAR = $(OUT_COMP_CLASS)/$(COMPONENT3_JAR_NAME)
+COMPONENT3_MANIFESTFILE = $(OUT_COMP_CLASS)/$(COMPONENT3_NAME).uno.Manifest
+COMPONENT3_UNOPKG_MANIFEST = $(OUT_COMP_CLASS)/$(COMPONENT3_NAME)/META-INF/manifest.xml
+
+APP1_NAME=LinguisticExamples
+APP1_JAR=$(OUT_COMP_CLASS)/$(APP1_NAME).jar
+
+REGISTERFLAG = $(OUT_MISC)/devguide_officedevlinguistic_register_component.flag
+
+JAVAFILES = \
+ OneInstanceFactory.java \
+ PropChgHelper.java \
+ PropChgHelper_Hyph.java \
+ PropChgHelper_Spell.java \
+ XHyphenatedWord_impl.java \
+ XMeaning_impl.java \
+ XPossibleHyphens_impl.java \
+ XSpellAlternatives_impl.java \
+ SampleHyphenator.java \
+ SampleSpellChecker.java \
+ SampleThesaurus.java
+
+CLASSFILES = $(patsubst %.java,$(OUT_COMP_CLASS)/%.class,$(JAVAFILES))
+
+$(COMPONENT1_NAME)_CLASSFILES = XHyphenatedWord_impl.class \
+ XPossibleHyphens_impl.class \
+ PropChgHelper.class \
+ PropChgHelper_Hyph.class \
+ OneInstanceFactory.class \
+ $(COMPONENT1_NAME).class
+
+$(COMPONENT2_NAME)_CLASSFILES = XSpellAlternatives_impl.class \
+ PropChgHelper_Spell.class \
+ PropChgHelper.class \
+ OneInstanceFactory.class \
+ $(COMPONENT2_NAME).class
+
+$(COMPONENT3_NAME)_CLASSFILES = XMeaning_impl.class \
+ OneInstanceFactory.class \
+ $(COMPONENT3_NAME).class
+
+SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
+ $(PATH_SEPARATOR)$(OUT_COMP_CLASS))
+
+.PHONY: ALL
+ALL : $(EXAMPLE_NAME)
+
+include $(SETTINGS)/stdtarget.mk
+
+$(OUT_COMP_CLASS)/%.Manifest :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo RegistrationClassName: $(basename $(basename $(@F)))> $@
+
+$(CLASSFILES) : $(JAVAFILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_COMP_CLASS) $(JAVAFILES)
+
+# NOTE: because of gnu make problems with full qualified paths, the pattern
+# rules for the component jars and the packages doesn't work proper and we
+# defined explicit rules
+
+#$(OUT_COMP_CLASS)/%.jar : $(OUT_COMP_CLASS)/%.Manifest $(CLASSFILES)
+# -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+# -$(MKDIR) $(subst /,$(PS),$(@D))
+# cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_JAR) cvfm $(@F) $(<F) $($(basename $(basename $(@F)))_CLASSFILES)
+
+# rule for component package manifest
+$(OUT_COMP_CLASS)/%/manifest.xml :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@
+ @echo $(OSEP)!DOCTYPE manifest:manifest PUBLIC "$(QM)-//OpenOffice.org//DTD Manifest 1.0//EN$(QM)" "$(QM)Manifest.dtd$(QM)"$(CSEP) >> $@
+ @echo $(OSEP)manifest:manifest xmlns:manifest="$(QM)http://openoffice.org/2001/manifest$(QM)"$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-component;type=Java$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(subst /META-INF,,$(subst $(OUT_COMP_CLASS)/,,$(@D))).uno.jar$(QM)"/$(CSEP) >> $@
+ @echo $(OSEP)/manifest:manifest$(CSEP) >> $@
+
+#$(OUT_BIN)/%.uno.pkg : $(OUT_COMP_CLASS)/%.uno.jar $(OUT_COMP_CLASS)/%/META-INF/manifest.xml
+# -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+# -$(MKDIR) $(subst /,$(PS),$(@D))
+# cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_ZIP) ../../bin/$(@F) $(<F)
+# cd $(subst /,$(PS),$(OUT_COMP_CLASS)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml
+
+$(COMPONENT1_JAR) : $(COMPONENT1_MANIFESTFILE) $(CLASSFILES)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_JAR) cvfm $(@F) $(<F) $($(basename $(basename $(@F)))_CLASSFILES)
+
+$(COMPONENT1_PACKAGE) : $(COMPONENT1_JAR) $(COMPONENT1_UNOPKG_MANIFEST)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_ZIP) ../../bin/$(@F) $(<F)
+ cd $(subst /,$(PS),$(OUT_COMP_CLASS)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml
+
+$(COMPONENT2_JAR) : $(COMPONENT2_MANIFESTFILE) $(CLASSFILES)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_JAR) cvfm $(@F) $(<F) $($(basename $(basename $(@F)))_CLASSFILES)
+
+$(COMPONENT2_PACKAGE) : $(COMPONENT2_JAR) $(COMPONENT2_UNOPKG_MANIFEST)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_ZIP) ../../bin/$(@F) $(<F)
+ cd $(subst /,$(PS),$(OUT_COMP_CLASS)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml
+
+$(COMPONENT3_JAR) : $(COMPONENT3_MANIFESTFILE) $(CLASSFILES)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_JAR) cvfm $(@F) $(<F) $($(basename $(basename $(@F)))_CLASSFILES)
+
+$(COMPONENT3_PACKAGE) : $(COMPONENT3_JAR) $(COMPONENT3_UNOPKG_MANIFEST)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_ZIP) ../../bin/$(@F) $(<F)
+ cd $(subst /,$(PS),$(OUT_COMP_CLASS)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml
+
+$(REGISTERFLAG) : $(COMPONENT1_PACKAGE) $(COMPONENT2_PACKAGE) $(COMPONENT3_PACKAGE)
+ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES"
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ $(DEPLOYTOOL) $(COMPONENT1_PACKAGE_URL)
+ $(DEPLOYTOOL) $(COMPONENT2_PACKAGE_URL)
+ $(DEPLOYTOOL) $(COMPONENT3_PACKAGE_URL)
+ @echo flagged > $(subst /,$(PS),$@)
+else
+ @echo --------------------------------------------------------------------------------
+ @echo If you want to install your component automatically, please set the environment
+ @echo variable SDK_AUTO_DEPLOYMENT = YES. But note that auto deployment is only
+ @echo possible if no office instance is running.
+ @echo --------------------------------------------------------------------------------
+endif
+
+$(OUT_COMP_CLASS)/%.class : %.java
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_COMP_CLASS) $<
+
+$(OUT_COMP_CLASS)/%.mf :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo Main-Class: com.sun.star.lib.loader.Loader> $@
+ $(ECHOLINE)>> $@
+ @echo Name: com/sun/star/lib/loader/Loader.class>> $@
+ @echo Application-Class: $*>> $@
+
+$(APP1_JAR) : $(OUT_COMP_CLASS)/$(APP1_NAME).mf $(OUT_COMP_CLASS)/$(APP1_NAME).class
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ +cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_JAR) cvfm $(@F) $(basename $(@F)).mf $(basename $(@F)).class $(basename $(@F))$(QUOTE)$$Client.class
+ +$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES)
+
+
+$(EXAMPLE_NAME) : $(REGISTERFLAG) $(APP1_JAR)
+ @echo --------------------------------------------------------------------------------
+ @echo Please use the following command to execute the example!
+ @echo -
+ @echo $(MAKE) $(APP1_NAME).run
+ @echo --------
+ @echo Before you can run the examples the components "$(QM)$(COMPONENT1_NAME)$(QM)",
+ @echo "$(QM)$(COMPONENT2_NAME)$(QM)" and "$(QM)$(COMPONENT3_NAME)$(QM)" must be deployed.
+ @echo The components will be automatically deployed if SDK_AUTO_DEPLOYMENT = YES.
+ @echo --------------------------------------------------------------------------------
+
+%.run: $(OUT_COMP_CLASS)/%.jar
+ $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $<
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_CLASS))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMPONENT1_PACKAGE_URL)))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMPONENT2_PACKAGE_URL)))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMPONENT3_PACKAGE_URL)))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$(REGISTERFLAG)))
diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/OneInstanceFactory.java b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/OneInstanceFactory.java
new file mode 100644
index 000000000000..7fa0c69dabbb
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/OneInstanceFactory.java
@@ -0,0 +1,161 @@
+/*************************************************************************
+ *
+ * $RCSfile: OneInstanceFactory.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:47:36 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.lang.XSingleServiceFactory;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.lang.XInitialization;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.uno.XInterface;
+import com.sun.star.uno.Any;
+import com.sun.star.uno.UnoRuntime;
+
+import java.lang.reflect.Constructor;
+
+//
+// purpose of this class is to provide a service factory that instantiates
+// the services only once (as long as this factory itself exists)
+// and returns only reference to that instance.
+//
+
+public class OneInstanceFactory implements
+ XSingleServiceFactory,
+ XServiceInfo
+{
+ Class aMyClass;
+ String aSvcImplName;
+ String[] aSupportedSvcNames;
+ XInterface xInstantiatedService;
+ XMultiServiceFactory xMultiFactory;
+
+ public OneInstanceFactory(
+ Class aMyClass,
+ String aSvcImplName,
+ String[] aSupportedSvcNames,
+ XMultiServiceFactory xMultiFactory )
+ {
+ this.aMyClass = aMyClass;
+ this.aSvcImplName = aSvcImplName;
+ this.aSupportedSvcNames = aSupportedSvcNames;
+ this.xMultiFactory = xMultiFactory;
+ xInstantiatedService = null;
+ }
+
+ //**********************
+ // XSingleServiceFactory
+ //**********************
+ public Object createInstance()
+ throws com.sun.star.uno.Exception,
+ com.sun.star.uno.RuntimeException
+ {
+ if (xInstantiatedService == null)
+ {
+ //!! the here used services all have exact one constructor!!
+ Constructor [] aCtor = aMyClass.getConstructors();
+ try {
+ xInstantiatedService = (XInterface) aCtor[0].newInstance( (Object[])null );
+ }
+ catch( Exception e ) {
+ }
+
+ //!! workaround for services not always being created
+ //!! via 'createInstanceWithArguments'
+ XInitialization xIni = (XInitialization) UnoRuntime.queryInterface(
+ XInitialization.class, createInstance());
+ if (xIni != null)
+ {
+ Object[] aArguments = new Object[]{ null, null };
+ if (xMultiFactory != null)
+ {
+ XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(
+ XPropertySet.class , xMultiFactory.createInstance(
+ "com.sun.star.linguistic2.LinguProperties" ) );
+ aArguments[0] = xPropSet;
+ }
+ xIni.initialize( aArguments );
+ }
+ }
+ return xInstantiatedService;
+ }
+
+ public Object createInstanceWithArguments( Object[] aArguments )
+ throws com.sun.star.uno.Exception,
+ com.sun.star.uno.RuntimeException
+ {
+ if (xInstantiatedService == null)
+ {
+ XInitialization xIni = (XInitialization) UnoRuntime.queryInterface(
+ XInitialization.class, createInstance());
+ if (xIni != null)
+ xIni.initialize( aArguments );
+ }
+ return xInstantiatedService;
+ }
+
+
+ //*************
+ // XServiceInfo
+ //*************
+ public boolean supportsService( String aServiceName )
+ throws com.sun.star.uno.RuntimeException
+ {
+ boolean bFound = false;
+ int nCnt = aSupportedSvcNames.length;
+ for (int i = 0; i < nCnt && !bFound; ++i)
+ {
+ if (aServiceName.equals( aSupportedSvcNames[i] ))
+ bFound = true;
+ }
+ return bFound;
+ }
+
+ public String getImplementationName()
+ throws com.sun.star.uno.RuntimeException
+ {
+ return aSvcImplName;
+ }
+
+ public String[] getSupportedServiceNames()
+ throws com.sun.star.uno.RuntimeException
+ {
+ return aSupportedSvcNames;
+ }
+};
+
diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/PropChgHelper.java b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/PropChgHelper.java
new file mode 100644
index 000000000000..854a21ad9993
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/PropChgHelper.java
@@ -0,0 +1,200 @@
+/*************************************************************************
+ *
+ * $RCSfile: PropChgHelper.java,v $
+ *
+ * $Revision: 1.3 $
+ *
+ * last change: $Author: hr $ $Date: 2003-06-30 15:40:24 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.linguistic2.XLinguServiceEventBroadcaster;
+import com.sun.star.linguistic2.XLinguServiceEventListener;
+import com.sun.star.linguistic2.LinguServiceEvent;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.beans.XPropertyChangeListener;
+import com.sun.star.beans.PropertyChangeEvent;
+import com.sun.star.lang.EventObject;
+import com.sun.star.uno.XInterface;
+
+import java.util.ArrayList;
+
+public class PropChgHelper implements
+ XPropertyChangeListener,
+ XLinguServiceEventBroadcaster
+{
+ XInterface xEvtSource;
+ String[] aPropNames;
+ XPropertySet xPropSet;
+ ArrayList aLngSvcEvtListeners;
+
+ public PropChgHelper(
+ XInterface xEvtSource,
+ String[] aPropNames )
+ {
+ this.xEvtSource = xEvtSource;
+ this.aPropNames = aPropNames;
+ xPropSet = null;
+ aLngSvcEvtListeners = new ArrayList();
+ }
+
+ public XInterface GetEvtSource()
+ {
+ return xEvtSource;
+ }
+
+ public XPropertySet GetPropSet()
+ {
+ return xPropSet;
+ }
+
+ public String[] GetPropNames()
+ {
+ return aPropNames;
+ }
+
+ public void LaunchEvent( LinguServiceEvent aEvt )
+ {
+ int nCnt = aLngSvcEvtListeners.size();
+ for (int i = 0; i < nCnt; ++i)
+ {
+ XLinguServiceEventListener xLstnr =
+ (XLinguServiceEventListener) aLngSvcEvtListeners.get(i);
+ if (xLstnr != null)
+ xLstnr.processLinguServiceEvent( aEvt );
+ }
+ }
+
+ public void AddAsListenerTo( XPropertySet xPropertySet )
+ {
+ // do not listen any longer to the old property set (if any)
+ RemoveAsListener();
+
+ // set new property set to be used and register as listener to it
+ xPropSet = xPropertySet;
+ if (xPropSet != null)
+ {
+ int nLen = aPropNames.length;
+ for (int i = 0; i < nLen; ++i)
+ {
+ if (aPropNames[i].length() != 0)
+ {
+ try {
+ xPropSet.addPropertyChangeListener(
+ aPropNames[i], (XPropertyChangeListener) this );
+ }
+ catch( Exception e ) {
+ }
+ }
+ }
+ }
+ }
+
+ public void RemoveAsListener()
+ {
+ if (xPropSet != null)
+ {
+ int nLen = aPropNames.length;
+ for (int i = 0; i < nLen; ++i)
+ {
+ if (aPropNames[i].length() != 0)
+ {
+ try {
+ xPropSet.removePropertyChangeListener(
+ aPropNames[i], (XPropertyChangeListener) this );
+ }
+ catch( Exception e ) {
+ }
+ }
+ }
+
+ xPropSet = null;
+ }
+ }
+
+ // __________ interface methods __________
+
+ //***************
+ // XEventListener
+ //***************
+ public void disposing( EventObject aSource )
+ throws com.sun.star.uno.RuntimeException
+ {
+ if (aSource.Source == xPropSet)
+ {
+ RemoveAsListener();
+ }
+ }
+
+ //************************
+ // XPropertyChangeListener
+ //************************
+ public void propertyChange( PropertyChangeEvent aEvt )
+ throws com.sun.star.uno.RuntimeException
+ {
+ // will be overloaded in derived classes
+ }
+
+ //******************************
+ // XLinguServiceEventBroadcaster
+ //******************************
+ public boolean addLinguServiceEventListener(
+ XLinguServiceEventListener xListener )
+ throws com.sun.star.uno.RuntimeException
+ {
+ boolean bRes = false;
+ if (xListener != null)
+ {
+ bRes = aLngSvcEvtListeners.add( xListener );
+ }
+ return bRes;
+ }
+
+ public boolean removeLinguServiceEventListener(
+ XLinguServiceEventListener xListener )
+ throws com.sun.star.uno.RuntimeException
+ {
+ boolean bRes = false;
+ if (xListener != null)
+ {
+ int nIdx = aLngSvcEvtListeners.indexOf( xListener );
+ if (nIdx != -1)
+ {
+ aLngSvcEvtListeners.remove( nIdx );
+ bRes = true;
+ }
+ }
+ return bRes;
+ }
+};
+
diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/PropChgHelper_Hyph.java b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/PropChgHelper_Hyph.java
new file mode 100644
index 000000000000..2abad6efb170
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/PropChgHelper_Hyph.java
@@ -0,0 +1,92 @@
+/*************************************************************************
+ *
+ * $RCSfile: PropChgHelper_Hyph.java,v $
+ *
+ * $Revision: 1.3 $
+ *
+ * last change: $Author: hr $ $Date: 2003-06-30 15:40:34 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.linguistic2.XLinguServiceEventBroadcaster;
+import com.sun.star.linguistic2.XLinguServiceEventListener;
+import com.sun.star.linguistic2.LinguServiceEvent;
+import com.sun.star.linguistic2.LinguServiceEventFlags;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.beans.XPropertyChangeListener;
+import com.sun.star.beans.PropertyChangeEvent;
+import com.sun.star.lang.EventObject;
+import com.sun.star.uno.XInterface;
+import com.sun.star.uno.UnoRuntime;
+
+import java.util.ArrayList;
+
+public class PropChgHelper_Hyph extends PropChgHelper
+{
+ public PropChgHelper_Hyph(
+ XInterface xEvtSource,
+ String[] aPropNames )
+ {
+ super( xEvtSource, aPropNames );
+ }
+
+ //************************
+ // XPropertyChangeListener
+ //************************
+ public void propertyChange( PropertyChangeEvent aEvt )
+ throws com.sun.star.uno.RuntimeException
+ {
+ {
+ short nLngSvcFlags = 0;
+ if (aEvt.PropertyName.equals( "IsIgnoreControlCharacters" ))
+ {
+ // nothing to be done
+ }
+ else if (aEvt.PropertyName.equals( "IsUseDictionaryList" ) ||
+ aEvt.PropertyName.equals( "IsGermanPreReform" ) ||
+ aEvt.PropertyName.equals( "HyphMinLeading" ) ||
+ aEvt.PropertyName.equals( "HyphMinTrailing" ) ||
+ aEvt.PropertyName.equals( "HyphMinWordLength" ))
+ {
+ nLngSvcFlags = LinguServiceEventFlags.HYPHENATE_AGAIN;
+ }
+
+ if (nLngSvcFlags != 0)
+ {
+ LinguServiceEvent aEvent = new LinguServiceEvent( GetEvtSource(), nLngSvcFlags );
+ LaunchEvent( aEvent );
+ }
+ }
+ }
+};
+
diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/PropChgHelper_Spell.java b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/PropChgHelper_Spell.java
new file mode 100644
index 000000000000..974b45b7e4ef
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/PropChgHelper_Spell.java
@@ -0,0 +1,116 @@
+/*************************************************************************
+ *
+ * $RCSfile: PropChgHelper_Spell.java,v $
+ *
+ * $Revision: 1.3 $
+ *
+ * last change: $Author: hr $ $Date: 2003-06-30 15:40:47 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.linguistic2.XLinguServiceEventBroadcaster;
+import com.sun.star.linguistic2.XLinguServiceEventListener;
+import com.sun.star.linguistic2.LinguServiceEvent;
+import com.sun.star.linguistic2.LinguServiceEventFlags;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.beans.XPropertyChangeListener;
+import com.sun.star.beans.PropertyChangeEvent;
+import com.sun.star.lang.EventObject;
+import com.sun.star.uno.XInterface;
+import com.sun.star.uno.UnoRuntime;
+
+import java.util.ArrayList;
+
+public class PropChgHelper_Spell extends PropChgHelper
+{
+ public PropChgHelper_Spell(
+ XInterface xEvtSource,
+ String[] aPropNames )
+ {
+ super( xEvtSource, aPropNames );
+ }
+
+ //************************
+ // XPropertyChangeListener
+ //************************
+ public void propertyChange( PropertyChangeEvent aEvt )
+ throws com.sun.star.uno.RuntimeException
+ {
+ {
+ short nLngSvcFlags = 0;
+ boolean bSCWA = false; // SPELL_CORRECT_WORDS_AGAIN ?
+ boolean bSWWA = false; // SPELL_WRONG_WORDS_AGAIN ?
+
+ boolean bVal = ((Boolean) aEvt.NewValue).booleanValue();
+
+ if (aEvt.PropertyName.equals( "IsIgnoreControlCharacters" ))
+ {
+ // nothing to be done
+ }
+ else if (aEvt.PropertyName.equals( "IsGermanPreReform" ))
+ {
+ bSCWA = bSWWA = true;
+ }
+ else if (aEvt.PropertyName.equals( "IsUseDictionaryList" ))
+ {
+ bSCWA = bSWWA = true;
+ }
+ else if (aEvt.PropertyName.equals( "IsSpellUpperCase" ))
+ {
+ bSCWA = false == bVal; // FALSE->TRUE change?
+ bSWWA = !bSCWA; // TRUE->FALSE change?
+ }
+ else if (aEvt.PropertyName.equals( "IsSpellWithDigits" ))
+ {
+ bSCWA = false == bVal; // FALSE->TRUE change?
+ bSWWA = !bSCWA; // TRUE->FALSE change?
+ }
+ else if (aEvt.PropertyName.equals( "IsSpellCapitalization" ))
+ {
+ bSCWA = false == bVal; // FALSE->TRUE change?
+ bSWWA = !bSCWA; // TRUE->FALSE change?
+ }
+
+ if (bSCWA)
+ nLngSvcFlags |= LinguServiceEventFlags.SPELL_CORRECT_WORDS_AGAIN;
+ if (bSWWA)
+ nLngSvcFlags |= LinguServiceEventFlags.SPELL_WRONG_WORDS_AGAIN;
+ if (nLngSvcFlags != 0)
+ {
+ LinguServiceEvent aEvent = new LinguServiceEvent( GetEvtSource(), nLngSvcFlags );
+ LaunchEvent( aEvent );
+ }
+ }
+ }
+};
+
diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleHyphenator.java b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleHyphenator.java
new file mode 100644
index 000000000000..85366db9d45d
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleHyphenator.java
@@ -0,0 +1,554 @@
+/*************************************************************************
+ *
+ * $RCSfile: SampleHyphenator.java,v $
+ *
+ * $Revision: 1.3 $
+ *
+ * last change: $Author: hr $ $Date: 2003-06-30 15:40:57 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+// uno
+import com.sun.star.lib.uno.helper.ComponentBase;
+import com.sun.star.uno.UnoRuntime;
+
+// factories
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+
+// supported Interfaces
+import com.sun.star.linguistic2.XHyphenator;
+import com.sun.star.linguistic2.XLinguServiceEventBroadcaster;
+import com.sun.star.lang.XInitialization;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.lang.XServiceDisplayName;
+
+// Exceptions
+import com.sun.star.uno.Exception;
+import com.sun.star.uno.RuntimeException;
+import com.sun.star.lang.IllegalArgumentException;
+
+//used Interfaces
+import com.sun.star.linguistic2.XLinguServiceEventListener;
+import com.sun.star.linguistic2.XHyphenatedWord;
+import com.sun.star.linguistic2.XPossibleHyphens;
+import com.sun.star.lang.Locale;
+import com.sun.star.lang.XEventListener;
+import com.sun.star.lang.EventObject;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.lang.XTypeProvider;
+import com.sun.star.uno.XInterface;
+import com.sun.star.uno.Type;
+
+import java.util.ArrayList;
+
+public class SampleHyphenator extends ComponentBase implements
+ XHyphenator,
+ XLinguServiceEventBroadcaster,
+ XInitialization,
+ XServiceDisplayName,
+ XServiceInfo
+{
+ PropChgHelper_Hyph aPropChgHelper;
+ ArrayList aEvtListeners;
+ boolean bDisposing;
+
+ public SampleHyphenator()
+ {
+ // names of relevant properties to be used
+ String[] aProps = new String[]
+ {
+ "IsIgnoreControlCharacters",
+ "IsUseDictionaryList",
+ "IsGermanPreReform",
+ "HyphMinLeading",
+ "HyphMinTrailing",
+ "HyphMinWordLength"
+ };
+ aPropChgHelper = new PropChgHelper_Hyph( (XHyphenator) this, aProps );
+ aEvtListeners = new ArrayList();;
+ bDisposing = false;
+ }
+
+ private boolean IsEqual( Locale aLoc1, Locale aLoc2 )
+ {
+ return aLoc1.Language.equals( aLoc2.Language ) &&
+ aLoc1.Country .equals( aLoc2.Country ) &&
+ aLoc1.Variant .equals( aLoc2.Variant );
+ }
+
+ private boolean GetValueToUse(
+ String aPropName,
+ boolean bDefaultVal,
+ PropertyValue[] aProps )
+ {
+ boolean bRes = bDefaultVal;
+
+ try
+ {
+ // use temporary value if supplied
+ for (int i = 0; i < aProps.length; ++i)
+ {
+ if (aPropName.equals( aProps[i].Name ))
+ {
+ Object aObj = aProps[i].Value;
+ if (AnyConverter.isBoolean( aObj ))
+ {
+ bRes = AnyConverter.toBoolean( aObj );
+ return bRes;
+ }
+ }
+ }
+
+ // otherwise use value from property set (if available)
+ XPropertySet xPropSet = aPropChgHelper.GetPropSet();
+ if (xPropSet != null) // should always be the case
+ {
+ Object aObj = xPropSet.getPropertyValue( aPropName );
+ if (AnyConverter.isBoolean( aObj ))
+ bRes = AnyConverter.toBoolean( aObj );
+ }
+ }
+ catch (Exception e) {
+ bRes = bDefaultVal;
+ }
+
+ return bRes;
+ }
+
+ private short GetValueToUse(
+ String aPropName,
+ short nDefaultVal,
+ PropertyValue[] aProps )
+ {
+ short nRes = nDefaultVal;
+
+ try
+ {
+ // use temporary value if supplied
+ for (int i = 0; i < aProps.length; ++i)
+ {
+ if (aPropName.equals( aProps[i].Name ))
+ {
+ Object aObj = aProps[i].Value;
+ if (AnyConverter.isShort( aObj ))
+ {
+ nRes = AnyConverter.toShort( aObj );
+ return nRes;
+ }
+ }
+ }
+
+ // otherwise use value from property set (if available)
+ XPropertySet xPropSet = aPropChgHelper.GetPropSet();
+ if (xPropSet != null) // should always be the case
+ {
+ Object aObj = xPropSet.getPropertyValue( aPropName );
+ if (AnyConverter.isShort( aObj ))
+ nRes = AnyConverter.toShort( aObj );
+ }
+ }
+ catch (Exception e) {
+ nRes = nDefaultVal;
+ }
+
+ return nRes;
+ }
+
+ // __________ interface methods __________
+
+
+ //*****************
+ //XSupportedLocales
+ //*****************
+ public Locale[] getLocales()
+ throws com.sun.star.uno.RuntimeException
+ {
+ Locale aLocales[] =
+ {
+ new Locale( "de", "DE", "" ),
+ new Locale( "en", "US", "" )
+ };
+
+ return aLocales;
+ }
+
+ public boolean hasLocale( Locale aLocale )
+ throws com.sun.star.uno.RuntimeException
+ {
+ boolean bRes = false;
+ if ( IsEqual( aLocale, new Locale( "de", "DE", "" ) ) ||
+ IsEqual( aLocale, new Locale( "en", "US", "" ) ))
+ bRes = true;
+ return bRes;
+ }
+
+ //***********
+ //XHyphenator
+ //***********
+ public XHyphenatedWord hyphenate(
+ String aWord, Locale aLocale,
+ short nMaxLeading, PropertyValue[] aProperties )
+ throws com.sun.star.uno.RuntimeException,
+ IllegalArgumentException
+ {
+ if (IsEqual( aLocale, new Locale() ) || aWord.length() == 0)
+ return null;
+
+ // linguistic is currently not allowed to throw exceptions
+ // thus we return null fwhich means 'word cannot be hyphenated'
+ if (!hasLocale( aLocale ))
+ return null;
+
+ // get values of relevant properties that may be used.
+ //! The values for 'IsIgnoreControlCharacters' and 'IsUseDictionaryList'
+ //! are handled by the dispatcher! Thus there is no need to access
+ //! them here.
+ boolean bIsIgnoreControlCharacters = GetValueToUse( "IsIgnoreControlCharacters", true, aProperties );
+ boolean bIsUseDictionaryList = GetValueToUse( "IsUseDictionaryList", true, aProperties );
+ boolean bIsGermanPreReform = GetValueToUse( "IsGermanPreReform", false, aProperties );
+ short nHyphMinLeading = GetValueToUse( "HyphMinLeading", (short)2, aProperties );
+ short nHyphMinTrailing = GetValueToUse( "HyphMinTrailing", (short)2, aProperties );
+ short nHyphMinWordLen = GetValueToUse( "HyphMinWordLength", (short)5, aProperties );
+
+ XHyphenatedWord xRes = null;
+
+ if (aWord.length() >= nHyphMinWordLen)
+ {
+ String aHyphenatedWord = aWord;
+ short nHyphenationPos = -1;
+ short nHyphenPos = -1;
+
+ //!! This code needs to be replaced by code calling the actual
+ //!! implementation of your hyphenator
+ if (IsEqual( aLocale, new Locale( "de", "DE", "" ) ) )
+ {
+ if (bIsGermanPreReform && aWord.equals( "Schiffahrt" ))
+ {
+ // Note: there is only one position where the word
+ // can be hyphenated...
+
+ aHyphenatedWord = "Schifffahrt";
+ nHyphenationPos = 4;
+ nHyphenPos = 5;
+ }
+ else if (!bIsGermanPreReform && aWord.equals( "Schifffahrt" ))
+ {
+ nHyphenationPos = nHyphenPos = 5;
+ }
+ }
+ else if (IsEqual( aLocale, new Locale( "en", "US", "" ) ) )
+ {
+ int nLast = aWord.length() - 1 - nHyphMinTrailing;
+
+ if ( aWord.equals( "waterfall" ) )
+ {
+ if (4 <= nLast)
+ nHyphenationPos = nHyphenPos = 4;
+ else
+ nHyphenationPos = nHyphenPos = 1;
+ }
+ else if ( aWord.equals( "driving" ) )
+ {
+ nHyphenationPos = nHyphenPos = 3;
+ }
+ }
+
+ // check if hyphenation pos is valid,
+ // a value of -1 indicates that hyphenation is not possible
+ if ( nHyphenationPos != -1 &&
+ !(nHyphenationPos < nHyphMinLeading) &&
+ !(nHyphenationPos >= aWord.length() - nHyphMinTrailing))
+ {
+ xRes = new XHyphenatedWord_impl(aWord, aLocale,
+ nHyphenationPos, aHyphenatedWord, nHyphenPos);
+ }
+ }
+ return xRes;
+ }
+
+ public XHyphenatedWord queryAlternativeSpelling(
+ String aWord, Locale aLocale,
+ short nIndex, PropertyValue[] aProperties )
+ throws com.sun.star.uno.RuntimeException,
+ IllegalArgumentException
+ {
+ if (IsEqual( aLocale, new Locale() ) || aWord.length() == 0)
+ return null;
+
+ // linguistic is currently not allowed to throw exceptions
+ // thus we return null which means 'word cannot be hyphenated'
+ if (!hasLocale( aLocale ))
+ return null;
+
+ // get values of relevant properties that may be used.
+ //! The values for 'IsIgnoreControlCharacters' and 'IsUseDictionaryList'
+ //! are handled by the dispatcher! Thus there is no need to access
+ //! them here.
+ boolean bIsIgnoreControlCharacters = GetValueToUse( "IsIgnoreControlCharacters", true, aProperties );
+ boolean bIsUseDictionaryList = GetValueToUse( "IsUseDictionaryList", true, aProperties );
+ boolean bIsGermanPreReform = GetValueToUse( "IsGermanPreReform", false, aProperties );
+ short nHyphMinLeading = GetValueToUse( "HyphMinLeading", (short)2, aProperties );
+ short nHyphMinTrailing = GetValueToUse( "HyphMinTrailing", (short)2, aProperties );
+ short nHyphMinWordLen = GetValueToUse( "HyphMinWordLength", (short)5, aProperties );
+
+ XHyphenatedWord xRes = null;
+
+ //!! This code needs to be replaced by code calling the actual
+ //!! implementation of your hyphenator
+ if ( IsEqual( aLocale, new Locale( "de", "DE", "" ) ) )
+ {
+ // there is an alternative spelling only when the
+ // word is hyphenated between the "ff" and old german spelling
+ // is set.
+ if (aWord.equals( "Schiffahrt" ) &&
+ bIsGermanPreReform && nIndex == 4)
+ {
+ xRes = new XHyphenatedWord_impl(aWord, aLocale,
+ (short)4, "Schifffahrt", (short)5 );
+ }
+ }
+ else if ( IsEqual( aLocale, new Locale( "en", "US", "" ) ) )
+ {
+ // There are no alternative spellings in the English language
+ }
+
+ return xRes;
+ }
+
+ public XPossibleHyphens createPossibleHyphens(
+ String aWord, Locale aLocale,
+ PropertyValue[] aProperties )
+ throws com.sun.star.uno.RuntimeException,
+ IllegalArgumentException
+ {
+ if (IsEqual( aLocale, new Locale() ) || aWord.length() == 0)
+ return null;
+
+ // linguistic is currently not allowed to throw exceptions
+ // thus we return null which means 'word cannot be hyphenated'
+ if (!hasLocale( aLocale ))
+ return null;
+
+ // get values of relevant properties that may be used.
+ //! The values for 'IsIgnoreControlCharacters' and 'IsUseDictionaryList'
+ //! are handled by the dispatcher! Thus there is no need to access
+ //! them here.
+ boolean bIsIgnoreControlCharacters = GetValueToUse( "IsIgnoreControlCharacters", true, aProperties );
+ boolean bIsUseDictionaryList = GetValueToUse( "IsUseDictionaryList", true, aProperties );
+ boolean bIsGermanPreReform = GetValueToUse( "IsGermanPreReform", false, aProperties );
+ short nHyphMinLeading = GetValueToUse( "HyphMinLeading", (short)2, aProperties );
+ short nHyphMinTrailing = GetValueToUse( "HyphMinTrailing", (short)2, aProperties );
+ short nHyphMinWordLen = GetValueToUse( "HyphMinWordLength", (short)5, aProperties );
+
+ XPossibleHyphens xRes = null;
+
+ //!! This code needs to be replaced by code calling the actual
+ //!! implementation of your hyphenator
+ if ( IsEqual( aLocale, new Locale( "de", "DE", "" ) ) )
+ {
+ if (bIsGermanPreReform && aWord.equals( "Schiffahrt" ))
+ {
+ short aPos[] = new short[] { (short) 4 };
+ xRes = new XPossibleHyphens_impl(aWord, aLocale,
+ "Schiff=fahrt", aPos);
+ }
+ else if (!bIsGermanPreReform && aWord.equals( "Schifffahrt" ))
+ {
+ short aPos[] = new short[] { (short) 5 };
+ xRes = new XPossibleHyphens_impl(aWord, aLocale,
+ "Schiff=fahrt", aPos);
+ }
+ }
+ else if ( IsEqual( aLocale, new Locale( "en", "US", "" ) ) )
+ {
+ if ( aWord.equals( "waterfall" ) )
+ {
+ short aPos[] = new short[]
+ { (short) 1, (short) 4 };
+ xRes = new XPossibleHyphens_impl(aWord, aLocale,
+ "wa=ter=fall", aPos);
+ }
+ else if ( aWord.equals( "driving" ) )
+ {
+ short aPos[] = new short[]
+ { (short) 3 };
+ xRes = new XPossibleHyphens_impl(aWord, aLocale,
+ "driv=ing", aPos);
+ }
+ }
+
+ return xRes;
+ }
+
+ //*****************************
+ //XLinguServiceEventBroadcaster
+ //*****************************
+ public boolean addLinguServiceEventListener (
+ XLinguServiceEventListener xLstnr )
+ throws com.sun.star.uno.RuntimeException
+ {
+ boolean bRes = false;
+ if (!bDisposing && xLstnr != null)
+ bRes = aPropChgHelper.addLinguServiceEventListener( xLstnr );
+ return bRes;
+ }
+
+ public boolean removeLinguServiceEventListener(
+ XLinguServiceEventListener xLstnr )
+ throws com.sun.star.uno.RuntimeException
+ {
+ boolean bRes = false;
+ if (!bDisposing && xLstnr != null)
+ bRes = aPropChgHelper.removeLinguServiceEventListener( xLstnr );
+ return bRes;
+ }
+
+ //********************
+ // XServiceDisplayName
+ //********************
+ public String getServiceDisplayName( Locale aLocale )
+ throws com.sun.star.uno.RuntimeException
+ {
+ return "Java Samples";
+ }
+
+ //****************
+ // XInitialization
+ //****************
+ public void initialize( Object[] aArguments )
+ throws com.sun.star.uno.Exception,
+ com.sun.star.uno.RuntimeException
+ {
+ int nLen = aArguments.length;
+ if (2 == nLen)
+ {
+ XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface(
+ XPropertySet.class, aArguments[0]);
+ // start listening to property changes
+ aPropChgHelper.AddAsListenerTo( xPropSet );
+ }
+ }
+
+
+ //*************
+ // XServiceInfo
+ //*************
+ public boolean supportsService( String aServiceName )
+ throws com.sun.star.uno.RuntimeException
+ {
+ String[] aServices = getSupportedServiceNames_Static();
+ int i, nLength = aServices.length;
+ boolean bResult = false;
+
+ for( i = 0; !bResult && i < nLength; ++i )
+ bResult = aServiceName.equals( aServices[ i ] );
+
+ return bResult;
+ }
+
+ public String getImplementationName()
+ throws com.sun.star.uno.RuntimeException
+ {
+ return _aSvcImplName;
+ }
+
+ public String[] getSupportedServiceNames()
+ throws com.sun.star.uno.RuntimeException
+ {
+ return getSupportedServiceNames_Static();
+ }
+
+ // __________ static things __________
+
+ public static String _aSvcImplName = "com.sun.star.linguistic2.JavaSamples.SampleHyphenator";
+
+ public static String[] getSupportedServiceNames_Static()
+ {
+ String[] aResult = { "com.sun.star.linguistic2.Hyphenator" };
+ return aResult;
+ }
+
+
+ /**
+ * Returns a factory for creating the service.
+ * This method is called by the <code>JavaLoader</code>
+ * <p>
+ * @return returns a <code>XSingleServiceFactory</code> for creating the component
+ * @param implName the name of the implementation for which a service is desired
+ * @param multiFactory the service manager to be used if needed
+ * @param regKey the registryKey
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static XSingleServiceFactory __getServiceFactory(
+ String aImplName,
+ XMultiServiceFactory xMultiFactory,
+ com.sun.star.registry.XRegistryKey xRegKey )
+ {
+ XSingleServiceFactory xSingleServiceFactory = null;
+ if( aImplName.equals( _aSvcImplName ) )
+ {
+ xSingleServiceFactory = new OneInstanceFactory(
+ SampleHyphenator.class, _aSvcImplName,
+ getSupportedServiceNames_Static(),
+ xMultiFactory );
+ }
+ return xSingleServiceFactory;
+ }
+
+ /**
+ * Writes the service information into the given registry key.
+ * This method is called by the <code>JavaLoader</code>
+ * <p>
+ * @return returns true if the operation succeeded
+ * @param xRegKey the registryKey
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static boolean __writeRegistryServiceInfo(
+ com.sun.star.registry.XRegistryKey xRegKey )
+ {
+ boolean bResult = true;
+ String[] aServices = getSupportedServiceNames_Static();
+ int i, nLength = aServices.length;
+ for( i = 0; i < nLength; ++i )
+ {
+ bResult = bResult && com.sun.star.comp.loader.FactoryHelper.writeRegistryServiceInfo(
+ _aSvcImplName, aServices[i], xRegKey );
+ }
+ return bResult;
+ }
+}
+
diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleSpellChecker.java b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleSpellChecker.java
new file mode 100644
index 000000000000..3284b2841a37
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleSpellChecker.java
@@ -0,0 +1,497 @@
+/*************************************************************************
+ *
+ * $RCSfile: SampleSpellChecker.java,v $
+ *
+ * $Revision: 1.3 $
+ *
+ * last change: $Author: hr $ $Date: 2003-06-30 15:41:09 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+// uno
+import com.sun.star.lib.uno.helper.ComponentBase;
+import com.sun.star.uno.UnoRuntime;
+
+// factories
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+
+// supported Interfaces
+import com.sun.star.linguistic2.XSpellChecker;
+import com.sun.star.linguistic2.XLinguServiceEventBroadcaster;
+import com.sun.star.lang.XInitialization;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.lang.XServiceDisplayName;
+
+// Exceptions
+import com.sun.star.uno.Exception;
+import com.sun.star.uno.RuntimeException;
+import com.sun.star.lang.IllegalArgumentException;
+
+//used Interfaces
+import com.sun.star.linguistic2.XLinguServiceEventListener;
+import com.sun.star.linguistic2.XSpellAlternatives;
+import com.sun.star.linguistic2.SpellFailure;
+import com.sun.star.lang.Locale;
+import com.sun.star.lang.XEventListener;
+import com.sun.star.lang.EventObject;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.lang.XTypeProvider;
+import com.sun.star.uno.XInterface;
+import com.sun.star.uno.Type;
+
+import java.util.ArrayList;
+
+public class SampleSpellChecker extends ComponentBase implements
+ XSpellChecker,
+ XLinguServiceEventBroadcaster,
+ XInitialization,
+ XServiceDisplayName,
+ XServiceInfo
+{
+ PropChgHelper_Spell aPropChgHelper;
+ ArrayList aEvtListeners;
+ boolean bDisposing;
+
+ public SampleSpellChecker()
+ {
+ // names of relevant properties to be used
+ String[] aProps = new String[]
+ {
+ "IsIgnoreControlCharacters",
+ "IsUseDictionaryList",
+ "IsGermanPreReform",
+ "IsSpellUpperCase",
+ "IsSpellWithDigits",
+ "IsSpellCapitalization"
+ };
+ aPropChgHelper = new PropChgHelper_Spell( (XSpellChecker) this, aProps );
+ aEvtListeners = new ArrayList();
+ bDisposing = false;
+ }
+
+ private boolean IsEqual( Locale aLoc1, Locale aLoc2 )
+ {
+ return aLoc1.Language.equals( aLoc2.Language ) &&
+ aLoc1.Country .equals( aLoc2.Country ) &&
+ aLoc1.Variant .equals( aLoc2.Variant );
+ }
+
+ private boolean GetValueToUse(
+ String aPropName,
+ boolean bDefaultVal,
+ PropertyValue[] aProps )
+ {
+ boolean bRes = bDefaultVal;
+
+ try
+ {
+ // use temporary value if supplied
+ for (int i = 0; i < aProps.length; ++i)
+ {
+ if (aPropName.equals( aProps[i].Name ))
+ {
+ Object aObj = aProps[i].Value;
+ if (AnyConverter.isBoolean( aObj ))
+ {
+ bRes = AnyConverter.toBoolean( aObj );
+ return bRes;
+ }
+ }
+ }
+
+ // otherwise use value from property set (if available)
+ XPropertySet xPropSet = aPropChgHelper.GetPropSet();
+ if (xPropSet != null) // should always be the case
+ {
+ Object aObj = xPropSet.getPropertyValue( aPropName );
+ if (AnyConverter.isBoolean( aObj ))
+ bRes = AnyConverter.toBoolean( aObj );
+ }
+ }
+ catch (Exception e) {
+ bRes = bDefaultVal;
+ }
+
+ return bRes;
+ }
+
+ private boolean IsUpper( String aWord, Locale aLocale )
+ {
+ java.util.Locale aLang = new java.util.Locale(
+ aLocale.Language, aLocale.Country, aLocale.Variant );
+ return aWord.equals( aWord.toUpperCase( aLang ) );
+ }
+
+ private boolean HasDigits( String aWord )
+ {
+ int nLen = aWord.length();
+ for (int i = 0; i < nLen; ++i)
+ {
+ if (Character.isDigit( aWord.charAt(i) ))
+ return true;
+ }
+ return false;
+ }
+
+ private short GetSpellFailure(
+ String aWord,
+ Locale aLocale,
+ PropertyValue[] aProperties )
+ {
+ short nRes = -1;
+
+ //!! This code needs to be replaced by code calling the actual
+ //!! implementation of your spellchecker
+ boolean bIsGermanPreReform = GetValueToUse( "IsGermanPreReform", false, aProperties );
+ if (IsEqual( aLocale, new Locale( "de", "DE", "" ) ))
+ {
+ if (bIsGermanPreReform && aWord.equals( "Schifffahrt" ))
+ nRes = SpellFailure.SPELLING_ERROR;
+ else if (!bIsGermanPreReform && aWord.equals( "Schiffahrt" ))
+ nRes = SpellFailure.SPELLING_ERROR;
+ }
+ else if (IsEqual( aLocale, new Locale( "en", "US", "" ) ))
+ {
+ // words with 'u', 'U' and 'arizona' are defined to be incorrect
+ boolean bIsValid = !(aWord.indexOf( "u" ) != -1 || aWord.indexOf( "U" ) != -1)
+ && !aWord.equals( "arizona" );
+
+ if (!bIsValid)
+ {
+ // default value (no other SpellFailure type is applicable)
+ nRes = SpellFailure.SPELLING_ERROR;
+
+ if (aWord.equals( "arizona" ))
+ nRes = SpellFailure.CAPTION_ERROR;
+ else if (aWord.equals( "house" ))
+ nRes = SpellFailure.SPELLING_ERROR;
+ else if (aWord.equals( "course" ))
+ nRes = SpellFailure.IS_NEGATIVE_WORD;
+ }
+ }
+
+ return nRes;
+ }
+
+ private XSpellAlternatives GetProposals(
+ String aWord,
+ Locale aLocale,
+ PropertyValue[] aProperties )
+ {
+ short nType = SpellFailure.SPELLING_ERROR;
+ String[] aProposals = null;
+
+ // get values of relevant properties that may be used.
+ //! The values for 'IsIgnoreControlCharacters' and 'IsUseDictionaryList'
+ //! are handled by the dispatcher! Thus there is no need to access
+ //! them here.
+ boolean bIsGermanPreReform = GetValueToUse( "IsGermanPreReform", false, aProperties );
+ boolean bIsSpellWithDigits = GetValueToUse( "IsSpellWithDigits", false, aProperties );
+ boolean bIsSpellUpperCase = GetValueToUse( "IsSpellUpperCase", false, aProperties );
+ boolean bIsSpellCapitalization = GetValueToUse( "IsSpellCapitalization", true, aProperties );
+
+ //!! This code needs to be replaced by code calling the actual
+ //!! implementation of your spellchecker
+ if (IsEqual( aLocale, new Locale( "de", "DE", "" ) ))
+ {
+ if (bIsGermanPreReform && aWord.equals( "Schifffahrt" ))
+ {
+ nType = SpellFailure.SPELLING_ERROR;
+ aProposals = new String[]{ "Schiffahrt" };
+ }
+ else if (!bIsGermanPreReform && aWord.equals( "Schiffahrt" ))
+ {
+ nType = SpellFailure.SPELLING_ERROR;
+ aProposals = new String[]{ "Schifffahrt" };
+ }
+ }
+ else if (IsEqual( aLocale, new Locale( "en", "US", "" ) ))
+ {
+ if (aWord.equals( "arizona" ))
+ {
+ nType = SpellFailure.CAPTION_ERROR;
+ aProposals = new String[]{ "Arizona" };
+ }
+ else if (aWord.equals( "house" ))
+ {
+ nType = SpellFailure.SPELLING_ERROR;
+ aProposals = new String[]{ "horse", "home" };
+ }
+ else if (aWord.equals( "course" ))
+ {
+ nType = SpellFailure.IS_NEGATIVE_WORD;
+ aProposals = new String[]{ "line", "plan", "approach" };
+ }
+ }
+
+ // always return a result if word is incorrect,
+ // proposals may be empty though.
+ return new XSpellAlternatives_impl( aWord, aLocale,
+ nType, aProposals );
+ }
+
+ // __________ interface methods __________
+
+
+ //*****************
+ //XSupportedLocales
+ //*****************
+ public Locale[] getLocales()
+ throws com.sun.star.uno.RuntimeException
+ {
+ Locale aLocales[] =
+ {
+ new Locale( "de", "DE", "" ),
+ new Locale( "en", "US", "" )
+ };
+
+ return aLocales;
+ }
+
+ public boolean hasLocale( Locale aLocale )
+ throws com.sun.star.uno.RuntimeException
+ {
+ boolean bRes = false;
+ if ( IsEqual( aLocale, new Locale( "de", "DE", "" ) ) ||
+ IsEqual( aLocale, new Locale( "en", "US", "" ) ))
+ bRes = true;
+ return bRes;
+ }
+
+
+ //*************
+ //XSpellChecker
+ //*************
+ public boolean isValid(
+ String aWord, Locale aLocale,
+ PropertyValue[] aProperties )
+ throws com.sun.star.uno.RuntimeException,
+ IllegalArgumentException
+ {
+ if (IsEqual( aLocale, new Locale() ) || aWord.length() == 0)
+ return true;
+
+ // linguistic is currently not allowed to throw exceptions
+ // thus we return null which means 'word cannot be spelled'
+ if (!hasLocale( aLocale ))
+ return true;
+
+ // get values of relevant properties that may be used.
+ //! The values for 'IsIgnoreControlCharacters' and 'IsUseDictionaryList'
+ //! are handled by the dispatcher! Thus there is no need to access
+ //! them here.
+ boolean bIsGermanPreReform = GetValueToUse( "IsGermanPreReform", false, aProperties );
+ boolean bIsSpellWithDigits = GetValueToUse( "IsSpellWithDigits", false, aProperties );
+ boolean bIsSpellUpperCase = GetValueToUse( "IsSpellUpperCase", false, aProperties );
+ boolean bIsSpellCapitalization = GetValueToUse( "IsSpellCapitalization", true, aProperties );
+
+ short nFailure = GetSpellFailure( aWord, aLocale, aProperties );
+ if (nFailure != -1)
+ {
+ // postprocess result for errors that should be ignored
+ if ( (!bIsSpellUpperCase && IsUpper( aWord, aLocale ))
+ || (!bIsSpellWithDigits && HasDigits( aWord ))
+ || (!bIsSpellCapitalization
+ && nFailure == SpellFailure.CAPTION_ERROR)
+ )
+ nFailure = -1;
+ }
+
+ return nFailure == -1;
+ }
+
+
+ public XSpellAlternatives spell(
+ String aWord, Locale aLocale,
+ PropertyValue[] aProperties )
+ throws com.sun.star.uno.RuntimeException,
+ IllegalArgumentException
+ {
+ if (IsEqual( aLocale, new Locale() ) || aWord.length() == 0)
+ return null;
+
+ // linguistic is currently not allowed to throw exceptions
+ // thus we return null fwhich means 'word cannot be spelled'
+ if (!hasLocale( aLocale ))
+ return null;
+
+ XSpellAlternatives xRes = null;
+ if (!isValid( aWord, aLocale, aProperties ))
+ {
+ xRes = GetProposals( aWord, aLocale, aProperties );
+ }
+ return xRes;
+ }
+
+
+ //*****************************
+ //XLinguServiceEventBroadcaster
+ //*****************************
+ public boolean addLinguServiceEventListener (
+ XLinguServiceEventListener xLstnr )
+ throws com.sun.star.uno.RuntimeException
+ {
+ boolean bRes = false;
+ if (!bDisposing && xLstnr != null)
+ bRes = aPropChgHelper.addLinguServiceEventListener( xLstnr );
+ return bRes;
+ }
+
+ public boolean removeLinguServiceEventListener(
+ XLinguServiceEventListener xLstnr )
+ throws com.sun.star.uno.RuntimeException
+ {
+ boolean bRes = false;
+ if (!bDisposing && xLstnr != null)
+ bRes = aPropChgHelper.removeLinguServiceEventListener( xLstnr );
+ return bRes;
+ }
+
+ //********************
+ // XServiceDisplayName
+ //********************
+ public String getServiceDisplayName( Locale aLocale )
+ throws com.sun.star.uno.RuntimeException
+ {
+ return "Java Samples";
+ }
+
+ //****************
+ // XInitialization
+ //****************
+ public void initialize( Object[] aArguments )
+ throws com.sun.star.uno.Exception,
+ com.sun.star.uno.RuntimeException
+ {
+ int nLen = aArguments.length;
+ if (2 == nLen)
+ {
+ XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface(
+ XPropertySet.class, aArguments[0]);
+ // start listening to property changes
+ aPropChgHelper.AddAsListenerTo( xPropSet );
+ }
+ }
+
+ //*************
+ // XServiceInfo
+ //*************
+ public boolean supportsService( String aServiceName )
+ throws com.sun.star.uno.RuntimeException
+ {
+ String[] aServices = getSupportedServiceNames_Static();
+ int i, nLength = aServices.length;
+ boolean bResult = false;
+
+ for( i = 0; !bResult && i < nLength; ++i )
+ bResult = aServiceName.equals( aServices[ i ] );
+
+ return bResult;
+ }
+
+ public String getImplementationName()
+ throws com.sun.star.uno.RuntimeException
+ {
+ return _aSvcImplName;
+ }
+
+ public String[] getSupportedServiceNames()
+ throws com.sun.star.uno.RuntimeException
+ {
+ return getSupportedServiceNames_Static();
+ }
+
+ // __________ static things __________
+
+ public static String _aSvcImplName = "com.sun.star.linguistic2.JavaSamples.SampleSpellChecker";
+
+ public static String[] getSupportedServiceNames_Static()
+ {
+ String[] aResult = { "com.sun.star.linguistic2.SpellChecker" };
+ return aResult;
+ }
+
+
+ /**
+ * Returns a factory for creating the service.
+ * This method is called by the <code>JavaLoader</code>
+ * <p>
+ * @return returns a <code>XSingleServiceFactory</code> for creating the component
+ * @param implName the name of the implementation for which a service is desired
+ * @param multiFactory the service manager to be used if needed
+ * @param regKey the registryKey
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static XSingleServiceFactory __getServiceFactory(
+ String aImplName,
+ XMultiServiceFactory xMultiFactory,
+ com.sun.star.registry.XRegistryKey xRegKey )
+ {
+ XSingleServiceFactory xSingleServiceFactory = null;
+ if( aImplName.equals( _aSvcImplName ) )
+ {
+ xSingleServiceFactory = new OneInstanceFactory(
+ SampleSpellChecker.class, _aSvcImplName,
+ getSupportedServiceNames_Static(),
+ xMultiFactory );
+ }
+ return xSingleServiceFactory;
+ }
+
+ /**
+ * Writes the service information into the given registry key.
+ * This method is called by the <code>JavaLoader</code>
+ * <p>
+ * @return returns true if the operation succeeded
+ * @param xRegKey the registryKey
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static boolean __writeRegistryServiceInfo(
+ com.sun.star.registry.XRegistryKey xRegKey )
+ {
+ boolean bResult = true;
+ String[] aServices = getSupportedServiceNames_Static();
+ int i, nLength = aServices.length;
+ for( i = 0; i < nLength; ++i )
+ {
+ bResult = bResult && com.sun.star.comp.loader.FactoryHelper.writeRegistryServiceInfo(
+ _aSvcImplName, aServices[i], xRegKey );
+ }
+ return bResult;
+ }
+}
+
diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleThesaurus.java b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleThesaurus.java
new file mode 100644
index 000000000000..56f0a5baec4f
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleThesaurus.java
@@ -0,0 +1,334 @@
+/*************************************************************************
+ *
+ * $RCSfile: SampleThesaurus.java,v $
+ *
+ * $Revision: 1.3 $
+ *
+ * last change: $Author: hr $ $Date: 2003-06-30 15:41:22 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+// uno
+import com.sun.star.lib.uno.helper.ComponentBase;
+import com.sun.star.uno.UnoRuntime;
+
+// factories
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+
+// supported Interfaces
+import com.sun.star.linguistic2.XThesaurus;
+import com.sun.star.lang.XInitialization;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.lang.XServiceDisplayName;
+
+// Exceptions
+import com.sun.star.uno.Exception;
+import com.sun.star.uno.RuntimeException;
+import com.sun.star.lang.IllegalArgumentException;
+
+//used Interfaces
+import com.sun.star.linguistic2.XMeaning;
+import com.sun.star.lang.Locale;
+import com.sun.star.lang.XEventListener;
+import com.sun.star.lang.EventObject;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.lang.XTypeProvider;
+import com.sun.star.uno.Type;
+
+import java.util.ArrayList;
+
+public class SampleThesaurus extends ComponentBase implements
+ XThesaurus,
+ XInitialization,
+ XServiceDisplayName,
+ XServiceInfo
+{
+ PropChgHelper aPropChgHelper;
+ ArrayList aEvtListeners;
+ boolean bDisposing;
+
+ public SampleThesaurus()
+ {
+ // names of relevant properties to be used
+ String[] aProps = new String[]
+ {
+ "IsIgnoreControlCharacters",
+ "IsUseDictionaryList",
+ "IsGermanPreReform",
+ };
+
+ // this service has no listeners thus we may use the base class,
+ // which is here basically used only to keep track of the
+ // property set (and it's lifetime) since it gets used in the
+ // 'GetValueToUse' function
+ aPropChgHelper = new PropChgHelper( (XThesaurus) this, aProps );
+
+ aEvtListeners = new ArrayList();
+ bDisposing = false;
+ }
+
+ private boolean IsEqual( Locale aLoc1, Locale aLoc2 )
+ {
+ return aLoc1.Language.equals( aLoc2.Language ) &&
+ aLoc1.Country .equals( aLoc2.Country ) &&
+ aLoc1.Variant .equals( aLoc2.Variant );
+ }
+
+ private boolean GetValueToUse(
+ String aPropName,
+ boolean bDefaultVal,
+ PropertyValue[] aProps )
+ {
+ boolean bRes = bDefaultVal;
+
+ try
+ {
+ // use temporary value if supplied
+ for (int i = 0; i < aProps.length; ++i)
+ {
+ if (aPropName.equals( aProps[i].Name ))
+ {
+ Object aObj = aProps[i].Value;
+ if (AnyConverter.isBoolean( aObj ))
+ {
+ bRes = AnyConverter.toBoolean( aObj );
+ return bRes;
+ }
+ }
+ }
+
+ // otherwise use value from property set (if available)
+ XPropertySet xPropSet = aPropChgHelper.GetPropSet();
+ if (xPropSet != null) // should always be the case
+ {
+ Object aObj = xPropSet.getPropertyValue( aPropName );
+ if (AnyConverter.isBoolean( aObj ))
+ bRes = AnyConverter.toBoolean( aObj );
+ }
+ }
+ catch (Exception e) {
+ bRes = bDefaultVal;
+ }
+
+ return bRes;
+ }
+
+ // __________ interface methods __________
+
+
+ //*****************
+ //XSupportedLocales
+ //*****************
+ public Locale[] getLocales()
+ throws com.sun.star.uno.RuntimeException
+ {
+ Locale aLocales[] =
+ {
+ new Locale( "en", "US", "" )
+ };
+
+ return aLocales;
+ }
+
+ public boolean hasLocale( Locale aLocale )
+ throws com.sun.star.uno.RuntimeException
+ {
+ boolean bRes = false;
+ if (IsEqual( aLocale, new Locale( "en", "US", "" ) ))
+ bRes = true;
+ return bRes;
+ }
+
+ //**********
+ //XThesaurus
+ //**********
+ public XMeaning[] queryMeanings(
+ String aTerm, Locale aLocale,
+ PropertyValue[] aProperties )
+ throws com.sun.star.lang.IllegalArgumentException,
+ com.sun.star.uno.RuntimeException
+ {
+ if (IsEqual( aLocale, new Locale() ) || aTerm.length() == 0)
+ return null;
+
+ // linguistic is currently not allowed to throw exceptions
+ // thus we return null fwhich means 'word cannot be looked up'
+ if (!hasLocale( aLocale ))
+ return null;
+
+ // get values of relevant properties that may be used.
+ //! The values for 'IsIgnoreControlCharacters' and 'IsUseDictionaryList'
+ //! are handled by the dispatcher! Thus there is no need to access
+ //! them here.
+ boolean bIsGermanPreReform = GetValueToUse( "IsGermanPreReform", false, aProperties );
+
+ XMeaning[] aRes = null;
+
+ //!! This code needs to be replaced by code calling the actual
+ //!! implementation of your thesaurus
+ if (aTerm.equals( "house" ) &&
+ IsEqual( aLocale, new Locale( "en", "US", "" ) ) )
+ {
+ aRes = new XMeaning[]
+ {
+ new XMeaning_impl( "a building where one lives",
+ new String[]{ "home", "place", "dwelling" } ),
+ new XMeaning_impl( "a group of people sharing common ancestry",
+ new String[]{ "family", "clan", "kindred" } ),
+ new XMeaning_impl( "to provide with lodging",
+ new String[]{ "room", "board", "put up" } )
+ };
+ }
+
+ return aRes;
+ }
+
+
+ //********************
+ // XServiceDisplayName
+ //********************
+ public String getServiceDisplayName( Locale aLocale )
+ throws com.sun.star.uno.RuntimeException
+ {
+ return "Java Samples";
+ }
+
+ //****************
+ // XInitialization
+ //****************
+ public void initialize( Object[] aArguments )
+ throws com.sun.star.uno.Exception,
+ com.sun.star.uno.RuntimeException
+ {
+ int nLen = aArguments.length;
+ if (2 == nLen)
+ {
+ XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface(
+ XPropertySet.class, aArguments[0]);
+ // start listening to property changes
+ aPropChgHelper.AddAsListenerTo( xPropSet );
+ }
+ }
+
+ //*************
+ // XServiceInfo
+ //*************
+ public boolean supportsService( String aServiceName )
+ throws com.sun.star.uno.RuntimeException
+ {
+ String[] aServices = getSupportedServiceNames_Static();
+ int i, nLength = aServices.length;
+ boolean bResult = false;
+
+ for( i = 0; !bResult && i < nLength; ++i )
+ bResult = aServiceName.equals( aServices[ i ] );
+
+ return bResult;
+ }
+
+ public String getImplementationName()
+ throws com.sun.star.uno.RuntimeException
+ {
+ return _aSvcImplName;
+ }
+
+ public String[] getSupportedServiceNames()
+ throws com.sun.star.uno.RuntimeException
+ {
+ return getSupportedServiceNames_Static();
+ }
+
+ // __________ static things __________
+
+ public static String _aSvcImplName = "com.sun.star.linguistic2.JavaSamples.SampleThesaurus";
+
+ public static String[] getSupportedServiceNames_Static()
+ {
+ String[] aResult = { "com.sun.star.linguistic2.Thesaurus" };
+ return aResult;
+ }
+
+
+ /**
+ * Returns a factory for creating the service.
+ * This method is called by the <code>JavaLoader</code>
+ * <p>
+ * @return returns a <code>XSingleServiceFactory</code> for creating the component
+ * @param implName the name of the implementation for which a service is desired
+ * @param multiFactory the service manager to be used if needed
+ * @param regKey the registryKey
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static XSingleServiceFactory __getServiceFactory(
+ String aImplName,
+ XMultiServiceFactory xMultiFactory,
+ com.sun.star.registry.XRegistryKey xRegKey )
+ {
+ XSingleServiceFactory xSingleServiceFactory = null;
+ if( aImplName.equals( _aSvcImplName ) )
+ {
+ xSingleServiceFactory = new OneInstanceFactory(
+ SampleThesaurus.class, _aSvcImplName,
+ getSupportedServiceNames_Static(),
+ xMultiFactory );
+ }
+ return xSingleServiceFactory;
+ }
+
+ /**
+ * Writes the service information into the given registry key.
+ * This method is called by the <code>JavaLoader</code>
+ * <p>
+ * @return returns true if the operation succeeded
+ * @param xRegKey the registryKey
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static boolean __writeRegistryServiceInfo(
+ com.sun.star.registry.XRegistryKey xRegKey )
+ {
+ boolean bResult = true;
+ String[] aServices = getSupportedServiceNames_Static();
+ int i, nLength = aServices.length;
+ for( i = 0; i < nLength; ++i )
+ {
+ bResult = bResult && com.sun.star.comp.loader.FactoryHelper.writeRegistryServiceInfo(
+ _aSvcImplName, aServices[i], xRegKey );
+ }
+ return bResult;
+ }
+}
+
diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/XHyphenatedWord_impl.java b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/XHyphenatedWord_impl.java
new file mode 100644
index 000000000000..3fa427fc7e24
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/XHyphenatedWord_impl.java
@@ -0,0 +1,103 @@
+/*************************************************************************
+ *
+ * $RCSfile: XHyphenatedWord_impl.java,v $
+ *
+ * $Revision: 1.3 $
+ *
+ * last change: $Author: hr $ $Date: 2003-06-30 15:41:35 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.lang.Locale;
+
+public class XHyphenatedWord_impl implements
+ com.sun.star.linguistic2.XHyphenatedWord
+{
+ String aWord;
+ String aHyphenatedWord;
+ short nHyphenPos;
+ short nHyphenationPos;
+ Locale aLang;
+ boolean bIsAltSpelling;
+
+ public XHyphenatedWord_impl(
+ String aWord,
+ Locale aLang,
+ short nHyphenationPos,
+ String aHyphenatedWord,
+ short nHyphenPos )
+ {
+ this.aWord = aWord;
+ this.aLang = aLang;
+ this.nHyphenationPos = nHyphenationPos;
+ this.aHyphenatedWord = aHyphenatedWord;
+ this.nHyphenPos = nHyphenPos;
+ this.bIsAltSpelling = (aWord != aHyphenatedWord);
+
+ //!! none of these cases should ever occur!
+ //!! values provided only for safety
+ if (this.aWord == null)
+ this.aWord = new String();
+ if (this.aLang == null)
+ this.aLang = new Locale();
+ if (this.aHyphenatedWord == null)
+ this.aHyphenatedWord = new String();
+ }
+
+
+ // XHyphenatedWord
+ public String getWord() throws com.sun.star.uno.RuntimeException
+ {
+ return aWord;
+ }
+ public Locale getLocale() throws com.sun.star.uno.RuntimeException
+ {
+ return aLang;
+ }
+ public short getHyphenationPos() throws com.sun.star.uno.RuntimeException
+ {
+ return nHyphenationPos;
+ }
+ public String getHyphenatedWord() throws com.sun.star.uno.RuntimeException
+ {
+ return aHyphenatedWord;
+ }
+ public short getHyphenPos() throws com.sun.star.uno.RuntimeException
+ {
+ return nHyphenPos;
+ }
+ public boolean isAlternativeSpelling() throws com.sun.star.uno.RuntimeException
+ {
+ return bIsAltSpelling;
+ }
+};
diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/XMeaning_impl.java b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/XMeaning_impl.java
new file mode 100644
index 000000000000..d330f803db85
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/XMeaning_impl.java
@@ -0,0 +1,75 @@
+/*************************************************************************
+ *
+ * $RCSfile: XMeaning_impl.java,v $
+ *
+ * $Revision: 1.3 $
+ *
+ * last change: $Author: hr $ $Date: 2003-06-30 15:41:45 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.lang.Locale;
+
+public class XMeaning_impl implements
+ com.sun.star.linguistic2.XMeaning
+{
+ String aMeaning;
+ String[] aSynonyms;
+
+ public XMeaning_impl ( String aMeaning, String[] aSynonyms )
+ {
+ this.aMeaning = aMeaning;
+ this.aSynonyms = aSynonyms;
+
+ //!! none of these cases should ever occur!
+ //!! values provided only for safety
+ if (this.aMeaning == null)
+ this.aMeaning = new String();
+
+ // a meaning without synonyms may be OK though.
+ // still for safety an empty existing array has to be provided.
+ if (this.aSynonyms == null)
+ this.aSynonyms = new String[]{};
+ }
+
+ // XMeaning
+ public String getMeaning() throws com.sun.star.uno.RuntimeException
+ {
+ return aMeaning;
+ }
+ public String[] querySynonyms() throws com.sun.star.uno.RuntimeException
+ {
+ return aSynonyms;
+ }
+};
+
diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/XPossibleHyphens_impl.java b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/XPossibleHyphens_impl.java
new file mode 100644
index 000000000000..bd38dcc418f7
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/XPossibleHyphens_impl.java
@@ -0,0 +1,95 @@
+/*************************************************************************
+ *
+ * $RCSfile: XPossibleHyphens_impl.java,v $
+ *
+ * $Revision: 1.3 $
+ *
+ * last change: $Author: hr $ $Date: 2003-06-30 15:41:57 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.lang.Locale;
+
+public class XPossibleHyphens_impl implements
+ com.sun.star.linguistic2.XPossibleHyphens
+{
+ String aWord;
+ String aHyphWord;
+ short[] aOrigHyphenPos;
+ Locale aLang;
+
+ public XPossibleHyphens_impl(
+ String aWord,
+ Locale aLang,
+ String aHyphWord,
+ short[] aOrigHyphenPos)
+ {
+ this.aWord = aWord;
+ this.aLang = aLang;
+ this.aHyphWord = aHyphWord;
+ this.aOrigHyphenPos = aOrigHyphenPos;
+
+ //!! none of these cases should ever occur!
+ //!! values provided only for safety
+ if (this.aWord == null)
+ this.aWord = new String();
+ if (this.aLang == null)
+ this.aLang = new Locale();
+ if (this.aHyphWord == null)
+ this.aHyphWord = new String();
+
+ // having no hyphenation positions is OK though.
+ // still for safety an empty existing array has to be provided.
+ if (this.aOrigHyphenPos == null)
+ this.aOrigHyphenPos = new short[]{};
+ }
+
+ // XPossibleHyphens
+ public String getWord() throws com.sun.star.uno.RuntimeException
+ {
+ return aWord;
+ }
+
+ public Locale getLocale() throws com.sun.star.uno.RuntimeException
+ {
+ return aLang;
+ }
+ public String getPossibleHyphens() throws com.sun.star.uno.RuntimeException
+ {
+ return aHyphWord;
+ }
+ public short[] getHyphenationPositions() throws com.sun.star.uno.RuntimeException
+ {
+ return aOrigHyphenPos;
+ }
+};
diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/XSpellAlternatives_impl.java b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/XSpellAlternatives_impl.java
new file mode 100644
index 000000000000..4251c6ec3236
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/XSpellAlternatives_impl.java
@@ -0,0 +1,98 @@
+/*************************************************************************
+ *
+ * $RCSfile: XSpellAlternatives_impl.java,v $
+ *
+ * $Revision: 1.3 $
+ *
+ * last change: $Author: hr $ $Date: 2003-06-30 15:42:09 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.lang.Locale;
+
+
+public class XSpellAlternatives_impl implements
+ com.sun.star.linguistic2.XSpellAlternatives
+{
+ String aWord;
+ Locale aLanguage;
+ String[] aAlt; // list of alternatives, may be empty.
+ short nType; // type of failure
+
+ public XSpellAlternatives_impl(
+ String aWord,
+ Locale aLanguage,
+ short nFailureType,
+ String[] aAlt )
+ {
+ this.aWord = aWord;
+ this.aLanguage = aLanguage;
+ this.aAlt = aAlt;
+ this.nType = nFailureType;
+
+ //!! none of these cases should ever occur!
+ //!! values provided only for safety
+ if (this.aWord == null)
+ this.aWord = new String();
+ if (this.aLanguage == null)
+ this.aLanguage = new Locale();
+
+ // having no alternatives is OK though.
+ // still for safety an empty existing array has to be provided.
+ if (this.aAlt == null)
+ this.aAlt = new String[]{};
+ }
+
+ // XSpellAlternatives
+ public String getWord() throws com.sun.star.uno.RuntimeException
+ {
+ return aWord;
+ }
+ public Locale getLocale() throws com.sun.star.uno.RuntimeException
+ {
+ return aLanguage;
+ }
+ public short getFailureType() throws com.sun.star.uno.RuntimeException
+ {
+ return nType;
+ }
+ public short getAlternativesCount() throws com.sun.star.uno.RuntimeException
+ {
+ return (short) aAlt.length;
+ }
+ public String[] getAlternatives() throws com.sun.star.uno.RuntimeException
+ {
+ return aAlt;
+ }
+};
+
diff --git a/odk/examples/DevelopersGuide/OfficeDev/Makefile b/odk/examples/DevelopersGuide/OfficeDev/Makefile
new file mode 100644
index 000000000000..6412b75012f2
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Makefile
@@ -0,0 +1,112 @@
+#*************************************************************************
+#
+# $RCSfile: Makefile,v $
+#
+# $Revision: 1.6 $
+#
+# last change: $Author: rt $ $Date: 2005-03-29 12:10:52 $
+#
+# The Contents of this file are made available subject to the terms of
+# the BSD license.
+#
+# Copyright (c) 2003 by Sun Microsystems, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+#**************************************************************************
+
+# Builds the OfficeDev examples of the Developers Guide.
+
+PRJ=../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+include $(SETTINGS)/dk.mk
+
+# Define non-platform/compiler specific settings
+EXAMPLE_NAME=OfficeDevExamples
+OUT_APP_CLASS = $(OUT_CLASS)/$(EXAMPLE_NAME)
+
+APP1_NAME=ContextMenuInterceptor
+APP1_JAR=$(OUT_APP_CLASS)/$(APP1_NAME).jar
+APP2_NAME=Number_Formats
+APP2_JAR=$(OUT_APP_CLASS)/$(APP2_NAME).jar
+
+APP1_JAVAFILES = \
+ MenuElement.java \
+ OfficeConnect.java \
+ ContextMenuInterceptor.java \
+
+APP1_CLASSFILES = $(patsubst %.java,$(OUT_APP_CLASS)/%.class,$(APP1_JAVAFILES))
+APP1_CLASSNAMES = $(patsubst %.java,%.class,$(APP1_JAVAFILES))
+
+SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
+ $(PATH_SEPARATOR)$(OUT_APP_CLASS))
+
+
+# Targets
+.PHONY: ALL
+ALL : $(EXAMPLE_NAME)
+
+include $(SETTINGS)/stdtarget.mk
+
+$(OUT_APP_CLASS)/%.class : %.java
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_APP_CLASS) $<
+
+$(OUT_APP_CLASS)/%.mf :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo Main-Class: com.sun.star.lib.loader.Loader> $@
+ $(ECHOLINE)>> $@
+ @echo Name: com/sun/star/lib/loader/Loader.class>> $@
+ @echo Application-Class: $*>> $@
+
+$(APP1_JAR) : $(OUT_APP_CLASS)/$(APP1_NAME).mf $(APP1_CLASSFILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ +cd $(subst /,$(PS),$(OUT_APP_CLASS)) && $(SDK_JAR) cvfm $(@F) $(basename $(@F)).mf $(APP1_CLASSNAMES)
+ +$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES)
+
+$(APP2_JAR) : $(OUT_APP_CLASS)/$(APP2_NAME).mf $(OUT_APP_CLASS)/$(APP2_NAME).class
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ +cd $(subst /,$(PS),$(OUT_APP_CLASS)) && $(SDK_JAR) cvfm $(@F) $(basename $(@F)).mf $(basename $(@F)).class
+ +$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES)
+
+
+$(EXAMPLE_NAME) : $(APP1_JAR) $(APP2_JAR)
+ @echo --------------------------------------------------------------------------------
+ @echo Please use the following commands to execute the examples!
+ @echo -
+ @echo $(MAKE) $(APP1_NAME).run
+ @echo $(MAKE) $(APP2_NAME).run
+ @echo --------------------------------------------------------------------------------
+
+%.run: $(OUT_APP_CLASS)/%.jar
+ $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $<
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_CLASS))
diff --git a/odk/examples/DevelopersGuide/OfficeDev/MenuElement.java b/odk/examples/DevelopersGuide/OfficeDev/MenuElement.java
new file mode 100644
index 000000000000..a2d3b406f817
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/MenuElement.java
@@ -0,0 +1,62 @@
+/*************************************************************************
+ *
+ * $RCSfile: MenuElement.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:35:27 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.uno.UnoRuntime;
+
+// A helper class to determine the menu element type
+public class MenuElement
+{
+ static public boolean IsMenuEntry( com.sun.star.beans.XPropertySet xMenuElement ) {
+ com.sun.star.lang.XServiceInfo xServiceInfo =
+ (com.sun.star.lang.XServiceInfo)UnoRuntime.queryInterface(
+ com.sun.star.lang.XServiceInfo.class, xMenuElement );
+
+ return xServiceInfo.supportsService( "com.sun.star.ui.ActionTrigger" );
+ }
+
+ static public boolean IsMenuSeparator( com.sun.star.beans.XPropertySet xMenuElement ) {
+ com.sun.star.lang.XServiceInfo xServiceInfo =
+ (com.sun.star.lang.XServiceInfo)UnoRuntime.queryInterface(
+ com.sun.star.lang.XServiceInfo.class, xMenuElement );
+
+ return xServiceInfo.supportsService( "com.sun.star.ui.ActionTriggerSeparator" );
+ }
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/Number_Formats.java b/odk/examples/DevelopersGuide/OfficeDev/Number_Formats.java
new file mode 100644
index 000000000000..6330421c8015
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Number_Formats.java
@@ -0,0 +1,259 @@
+/*************************************************************************
+ *
+ * $RCSfile: Number_Formats.java,v $
+ *
+ * $Revision: 1.5 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:35:39 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+// __________ Imports __________
+
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.container.XIndexAccess;
+import com.sun.star.frame.XComponentLoader;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.sheet.XSpreadsheet;
+import com.sun.star.sheet.XSpreadsheets;
+import com.sun.star.sheet.XSpreadsheetDocument;
+import com.sun.star.table.XCell;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+
+
+// __________ Implementation __________
+
+/** Create a spreadsheet document and provide access to a sheet framework that
+ is then used to modify some number formats.
+ @author Eike Rathke
+ */
+public class Number_Formats
+{
+ // __________ public members and methods __________
+
+
+ // ____________________
+
+ public static void main( String args[] )
+ {
+ try
+ {
+ Number_Formats aSample = new Number_Formats( args );
+ aSample.doFunction();
+ }
+ catch( Exception ex )
+ {
+ System.err.println( "Sample caught exception! " + ex );
+ ex.printStackTrace();
+ System.exit(1);
+ }
+
+ System.out.println( "Sample done." );
+ System.exit(0);
+ }
+
+ // ____________________
+
+ public void doFunction() throws RuntimeException, Exception
+ {
+ // Assume:
+ // com.sun.star.sheet.XSpreadsheetDocument maSpreadsheetDoc;
+ // com.sun.star.sheet.XSpreadsheet maSheet;
+
+ // Query the number formats supplier of the spreadsheet document
+ com.sun.star.util.XNumberFormatsSupplier xNumberFormatsSupplier =
+ (com.sun.star.util.XNumberFormatsSupplier)
+ UnoRuntime.queryInterface(
+ com.sun.star.util.XNumberFormatsSupplier.class, maSpreadsheetDoc );
+
+ // Get the number formats from the supplier
+ com.sun.star.util.XNumberFormats xNumberFormats =
+ xNumberFormatsSupplier.getNumberFormats();
+
+ // Query the XNumberFormatTypes interface
+ com.sun.star.util.XNumberFormatTypes xNumberFormatTypes =
+ (com.sun.star.util.XNumberFormatTypes)
+ UnoRuntime.queryInterface(
+ com.sun.star.util.XNumberFormatTypes.class, xNumberFormats );
+
+ // Get the number format index key of the default currency format,
+ // note the empty locale for default locale
+ com.sun.star.lang.Locale aLocale = new com.sun.star.lang.Locale();
+ int nCurrencyKey = xNumberFormatTypes.getStandardFormat(
+ com.sun.star.util.NumberFormat.CURRENCY, aLocale );
+
+ // Get cell range B3:B11
+ com.sun.star.table.XCellRange xCellRange =
+ maSheet.getCellRangeByPosition( 1, 2, 1, 10 );
+
+ // Query the property set of the cell range
+ com.sun.star.beans.XPropertySet xCellProp =
+ (com.sun.star.beans.XPropertySet)
+ UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xCellRange );
+
+ // Set number format to default currency
+ xCellProp.setPropertyValue( "NumberFormat", new Integer(nCurrencyKey) );
+
+ // Get cell B3
+ com.sun.star.table.XCell xCell = maSheet.getCellByPosition( 1, 2 );
+
+ // Query the property set of the cell
+ xCellProp = (com.sun.star.beans.XPropertySet)
+ UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xCell );
+
+ // Get the number format index key of the cell's properties
+ int nIndexKey = ((Integer) xCellProp.getPropertyValue( "NumberFormat" )).intValue();
+ if ( nIndexKey != nCurrencyKey )
+ System.out.println( "Number format doesn't match!" );
+
+ // Get the properties of the number format
+ com.sun.star.beans.XPropertySet xProp = xNumberFormats.getByKey( nIndexKey );
+
+ // Get the format code string of the number format's properties
+ String aFormatCode = (String) xProp.getPropertyValue( "FormatString" );
+ System.out.println( "FormatString: `" + aFormatCode + "'" );
+
+ // Create an arbitrary format code
+ aFormatCode = "\"wonderful \"" + aFormatCode;
+
+ // Test if it's already present
+ nIndexKey = xNumberFormats.queryKey( aFormatCode, aLocale, false );
+
+ // If not, add to number formats collection
+ if ( nIndexKey == -1 )
+ {
+ try
+ {
+ nIndexKey = xNumberFormats.addNew( aFormatCode, aLocale );
+ }
+ catch( com.sun.star.util.MalformedNumberFormatException ex )
+ {
+ System.err.println( "Bad number format code: " + ex );
+ ex.printStackTrace();
+ nIndexKey = -1;
+ }
+ }
+
+ // Set the new format at the cell
+ if ( nIndexKey != -1 )
+ xCellProp.setPropertyValue( "NumberFormat", new Integer(nIndexKey) );
+
+
+ // Set column containing the example values to optimal width to show
+ // the new format of cell B3
+ com.sun.star.table.XColumnRowRange xColRowRange =
+ (com.sun.star.table.XColumnRowRange)
+ UnoRuntime.queryInterface(com.sun.star.table.XColumnRowRange.class,
+ maSheet);
+
+ com.sun.star.container.XIndexAccess xIndexAccess =
+ (com.sun.star.container.XIndexAccess)
+ UnoRuntime.queryInterface(com.sun.star.container.XIndexAccess.class,
+ xColRowRange.getColumns());
+
+ com.sun.star.beans.XPropertySet xColPropSet =
+ (com.sun.star.beans.XPropertySet)
+ UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,
+ xIndexAccess.getByIndex(1));
+
+ xColPropSet.setPropertyValue( "OptimalWidth", new Boolean(true) );
+ }
+
+ // ____________________
+
+ public Number_Formats( String[] args ) throws java.lang.Exception
+ {
+ // get the remote office context. If necessary a new office
+ // process is started
+ maOfficeContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+ System.out.println("Connected to a running office ...");
+ maServiceManager = maOfficeContext.getServiceManager();
+
+ // create a new spreadsheet document
+ XComponentLoader aLoader = (XComponentLoader) UnoRuntime.queryInterface(
+ XComponentLoader.class, maServiceManager.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", maOfficeContext) );
+
+ maSpreadsheetDoc = (XSpreadsheetDocument) UnoRuntime.queryInterface(
+ XSpreadsheetDocument.class,
+ aLoader.loadComponentFromURL( "private:factory/scalc",
+ "_blank",
+ 0,
+ new PropertyValue[ 0 ] ) );
+
+ if ( !initSpreadsheet() )
+ System.exit( 0 );
+ }
+
+
+ // __________ private members and methods __________
+ private final String msDataSheetName = "Data";
+
+ private XComponentContext maOfficeContext;
+ private XMultiComponentFactory maServiceManager;
+ private XSpreadsheetDocument maSpreadsheetDoc;
+ private XSpreadsheet maSheet; // the first sheet
+
+
+ // ____________________
+
+ /** init the first sheet
+ */
+ private boolean initSpreadsheet()
+ {
+ boolean bOk = true;
+ XSpreadsheets aSheets = maSpreadsheetDoc.getSheets();
+ try
+ {
+ XIndexAccess aSheetsIA = (XIndexAccess) UnoRuntime.queryInterface( XIndexAccess.class, aSheets );
+ maSheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, aSheetsIA.getByIndex( 0 ));
+
+ // enter some values in B3:B11
+ for( int iCounter=1; iCounter < 10; iCounter++ )
+ {
+ XCell aCell = maSheet.getCellByPosition( 1, 1 + iCounter );
+ aCell.setValue( (double) iCounter );
+ }
+ }
+ catch( Exception ex )
+ {
+ System.err.println( "Couldn't initialize Spreadsheet Document: " + ex );
+ ex.printStackTrace();
+ bOk = false;
+ }
+ return bOk;
+ }
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/OfficeConnect.java b/odk/examples/DevelopersGuide/OfficeDev/OfficeConnect.java
new file mode 100644
index 000000000000..41fb35b8b20d
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/OfficeConnect.java
@@ -0,0 +1,190 @@
+/*************************************************************************
+ *
+ * $RCSfile: OfficeConnect.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:35:51 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+// __________ Imports __________
+
+// structs, const, ...
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.bridge.XUnoUrlResolver;
+
+// exceptions
+import com.sun.star.container.NoSuchElementException;
+
+// interfaces
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.uno.Any;
+import com.sun.star.uno.Exception;
+
+import com.sun.star.uno.UnoRuntime;
+
+// others
+import java.lang.String;
+
+// __________ Implementation __________
+
+/**
+ * support ONE singleton uno connection to an running office installation!
+ * Can be used to open/use/close connection to uno environment of an already running office.
+ * ctor isn't available from outside. You should call static function "getConnection()"
+ * to open or use internal set connection which is created one times only.
+ *
+ * @author Andreas Schl&uuml;ns
+ * @created 7. Februar 2002
+ * @modified 05.02.2002 12:10
+ */
+public class OfficeConnect
+{
+ // ____________________
+
+ /**
+ * At first call we create static connection object and get the remote office
+ * context and the remote office service manager. A new office process is
+ * started if necessary.
+ * Then - and for all further requests we return these static connection member.
+ */
+ public static synchronized OfficeConnect createConnection()
+ throws java.lang.Exception
+ {
+ if (maConnection == null)
+ {
+ maConnection = new OfficeConnect();
+ }
+ return maConnection;
+ }
+
+ // ____________________
+
+ public static synchronized OfficeConnect getConnection()
+ {
+ return maConnection;
+ }
+
+ // ____________________
+
+ /**
+ * ctor
+ * We try to open the connection in our ctor ... transparently for the user.
+ * We made it private to support singleton pattern of these implementation.
+ * see getConnection() for further informations
+ */
+ private OfficeConnect() throws java.lang.Exception
+ {
+ // get the remote office context. If necessary a new office
+ // process is started
+ mxOfficeContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+ System.out.println("Connected to a running office ...");
+ mxServiceManager = mxOfficeContext.getServiceManager();
+ }
+
+ // ____________________
+
+ /**
+ * create uno components inside remote office process
+ * After connection of these proccess to a running office we have access to remote service manager of it.
+ * So we can use it to create all existing services. Use this method to create components by name and
+ * get her interface. Casting of it to right target interface is part of your implementation.
+ *
+ * @param aType describe class type of created service
+ * Returned object can be casted directly to this one.
+ * Uno query was done by this method automaticly.
+ * @param sServiceSpecifier name of service which should be created
+ * @return Description of the Returned Value
+ */
+ public Object createRemoteInstance(Class aType, String sServiceSpecifier)
+ {
+ Object aResult = null;
+ try
+ {
+ aResult = UnoRuntime.queryInterface(
+ aType, mxServiceManager.createInstanceWithContext(
+ sServiceSpecifier, mxOfficeContext));
+ }
+ catch (com.sun.star.uno.Exception ex)
+ {
+ System.err.println("Couldn't create Service of type " + sServiceSpecifier + ": " + ex);
+ ex.printStackTrace();
+ System.exit(0);
+ }
+ return aResult;
+ }
+
+ // ____________________
+
+ /**
+ * same as "createRemoteInstance()" but supports additional parameter for initializing created object
+ *
+ * @param lArguments optional arguments
+ * They are used to initialize new created service.
+ * @param aType Description of Parameter
+ * @param sServiceSpecifier Description of Parameter
+ * @return Description of the Returned Value
+ */
+ public Object createRemoteInstanceWithArguments(Class aType, String sServiceSpecifier, Any[] lArguments)
+ {
+ Object aResult = null;
+ try
+ {
+ aResult = UnoRuntime.queryInterface(
+ aType, mxServiceManager.createInstanceWithArgumentsAndContext(
+ sServiceSpecifier, lArguments, mxOfficeContext));
+ }
+ catch (com.sun.star.uno.Exception ex)
+ {
+ System.err.println("Couldn't create Service of type " + sServiceSpecifier + ": " + ex);
+ ex.printStackTrace();
+ System.exit(0);
+ }
+ return aResult;
+ }
+
+ // ____________________
+
+ /**
+ * member
+ */
+ // singleton connection instance
+ private static OfficeConnect maConnection;
+
+ // reference to remote office context
+ private com.sun.star.uno.XComponentContext mxOfficeContext;
+ // reference to remote service manager
+ private com.sun.star.lang.XMultiComponentFactory mxServiceManager;
+}
+
diff --git a/odk/examples/DevelopersGuide/OfficeDev/PathSettings/Makefile b/odk/examples/DevelopersGuide/OfficeDev/PathSettings/Makefile
new file mode 100644
index 000000000000..e2d5597c8d43
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/PathSettings/Makefile
@@ -0,0 +1,98 @@
+#*************************************************************************
+#
+# $RCSfile: Makefile,v $
+#
+# $Revision: 1.6 $
+#
+# last change: $Author: rt $ $Date: 2005-03-29 12:12:04 $
+#
+# The Contents of this file are made available subject to the terms of
+# the BSD license.
+#
+# Copyright (c) 2003 by Sun Microsystems, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+#**************************************************************************
+
+# Builds the OfficeDevPathSettingsTest example of the Developers Guide.
+
+PRJ=../../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+include $(SETTINGS)/dk.mk
+
+# Define non-platform/compiler specific settings
+EXAMPLE_NAME=OfficeDevPathSettingsTest
+OUT_APP_CLASS = $(OUT_CLASS)/$(EXAMPLE_NAME)
+
+APP1_NAME=PathSettingsTest
+APP1_JAR=$(OUT_APP_CLASS)/$(APP1_NAME).jar
+
+SDK_CLASSPATH=$(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
+ $(PATH_SEPARATOR)$(OUT_APP_CLASS))
+
+
+# Targets
+.PHONY: ALL
+ALL : $(EXAMPLE_NAME)
+
+include $(SETTINGS)/stdtarget.mk
+
+$(OUT_APP_CLASS)/%.class : %.java
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_APP_CLASS) $<
+
+$(OUT_APP_CLASS)/%.mf :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo Main-Class: com.sun.star.lib.loader.Loader> $@
+ $(ECHOLINE)>> $@
+ @echo Name: com/sun/star/lib/loader/Loader.class>> $@
+ @echo Application-Class: $*>> $@
+
+$(OUT_APP_CLASS)/%.jar : $(OUT_APP_CLASS)/%.mf $(OUT_APP_CLASS)/%.class
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ +cd $(subst /,$(PS),$(OUT_APP_CLASS)) && $(SDK_JAR) cvfm $(@F) $*.mf $*.class
+ +$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES)
+
+$(APP1_JAR) : $(OUT_APP_CLASS)/$(APP1_NAME).mf $(OUT_APP_CLASS)/$(APP1_NAME).class
+
+$(EXAMPLE_NAME) : $(APP1_JAR)
+ @echo --------------------------------------------------------------------------------
+ @echo Please use the following commands to execute the examples!
+ @echo -
+ @echo $(MAKE) $(APP1_NAME).run
+ @echo --------------------------------------------------------------------------------
+
+%.run: $(OUT_APP_CLASS)/%.jar
+ $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $<
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_CLASS))
diff --git a/odk/examples/DevelopersGuide/OfficeDev/PathSettings/PathSettingsTest.java b/odk/examples/DevelopersGuide/OfficeDev/PathSettings/PathSettingsTest.java
new file mode 100644
index 000000000000..edce05c13281
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/PathSettings/PathSettingsTest.java
@@ -0,0 +1,174 @@
+/*************************************************************************
+ *
+ * $RCSfile: PathSettingsTest.java,v $
+ *
+ * $Revision: 1.5 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:48:02 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.beans.UnknownPropertyException;
+
+/*
+ *
+ * @author Carsten Driesner
+ * Provides example code how to access and use the
+ * path pathsettings servce.
+ */
+public class PathSettingsTest extends java.lang.Object {
+
+ /*
+ * List of pre-defined path variables supported by
+ * the path settings service.
+ */
+ private static String[] predefinedPathProperties = {
+ "Addin",
+ "AutoCorrect",
+ "AutoText",
+ "Backup",
+ "Basic",
+ "Bitmap",
+ "Config",
+ "Dictionary",
+ "Favorite",
+ "Filter",
+ "Gallery",
+ "Graphic",
+ "Help",
+ "Linguistic",
+ "Module",
+ "Palette",
+ "Plugin",
+ "Storage",
+ "Temp",
+ "Template",
+ "UIConfig",
+ "UserConfig",
+ "UserDictionary",
+ "Work"
+ };
+
+ /*
+ * @param args the command line arguments
+ */
+ public static void main(String[] args) {
+
+ XComponentContext xRemoteContext = null;
+ XMultiComponentFactory xRemoteServiceManager = null;
+ XPropertySet xPathSettingsService = null;
+
+ try {
+ // get the remote office context. If necessary a new office
+ // process is started
+ xRemoteContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+ System.out.println("Connected to a running office ...");
+ xRemoteServiceManager = xRemoteContext.getServiceManager();
+
+ Object pathSubst = xRemoteServiceManager.createInstanceWithContext(
+ "com.sun.star.comp.framework.PathSettings", xRemoteContext );
+ xPathSettingsService = (XPropertySet)UnoRuntime.queryInterface(
+ XPropertySet.class, pathSubst);
+
+ /* Work with path settings */
+ workWithPathSettings( xPathSettingsService );
+ }
+ catch (java.lang.Exception e){
+ e.printStackTrace();
+ }
+ finally {
+ System.exit(0);
+ }
+ }
+
+ /*
+ * Retrieve and set path properties from path settings service
+ * @param xPathSettingsService the path settings service
+ */
+ public static void workWithPathSettings( XPropertySet xPathSettingsService )
+ {
+ if ( xPathSettingsService != null ) {
+ for ( int i=0; i<predefinedPathProperties.length; i++ ) {
+ try {
+ /* Retrieve values for path properties from path settings
+ * service*/
+ Object aValue = xPathSettingsService.getPropertyValue(
+ predefinedPathProperties[i] );
+
+ // getPropertyValue returns an Object, you have to cast
+ // it to type that you need
+ String aPath = (String)aValue;
+ System.out.println( "Property="+ predefinedPathProperties[i]
+ + " Path=" + aPath );
+ }
+ catch ( com.sun.star.beans.UnknownPropertyException e) {
+ System.err.println( "UnknownPropertyException has been thrown accessing "+predefinedPathProperties[i]);
+ }
+ catch ( com.sun.star.lang.WrappedTargetException e ) {
+ System.err.println( "WrappedTargetException has been thrown accessing "+predefinedPathProperties[i]);
+ }
+ }
+
+ // Try to modfiy the work path property. After running this example
+ // you should see the new value of "My Documents" in the path options
+ // tab page, accessible via "Tools - Options - [Star|Open]Office -
+ // Paths".
+ // If you want to revert the changes, you can also do it with the
+ // path tab page.
+ try {
+ xPathSettingsService.setPropertyValue( "Work", "$(temp)" );
+ String aValue = (String)xPathSettingsService.getPropertyValue( "Work" );
+ System.out.println( "\nNote: The example changes your current "
+ +"setting of the work path!\nThe work path "
+ +"should be now=" + aValue );
+ }
+ catch ( com.sun.star.beans.UnknownPropertyException e) {
+ System.err.println( "UnknownPropertyException has been thrown accessing PathSettings service");
+ }
+ catch ( com.sun.star.lang.WrappedTargetException e ) {
+ System.err.println( "WrappedTargetException has been thrown accessing PathSettings service");
+ }
+ catch ( com.sun.star.beans.PropertyVetoException e ) {
+ System.err.println( "PropertyVetoException has been thrown accessing PathSettings service");
+ }
+ catch ( com.sun.star.lang.IllegalArgumentException e ) {
+ System.err.println( "IllegalArgumentException has been thrown accessing PathSettings service");
+ }
+ }
+ }
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/PathSubstitution/Makefile b/odk/examples/DevelopersGuide/OfficeDev/PathSubstitution/Makefile
new file mode 100644
index 000000000000..cc0acc06da1a
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/PathSubstitution/Makefile
@@ -0,0 +1,98 @@
+#*************************************************************************
+#
+# $RCSfile: Makefile,v $
+#
+# $Revision: 1.6 $
+#
+# last change: $Author: rt $ $Date: 2005-03-29 12:12:18 $
+#
+# The Contents of this file are made available subject to the terms of
+# the BSD license.
+#
+# Copyright (c) 2003 by Sun Microsystems, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+#**************************************************************************
+
+# Builds the OfficeDevPathSettingsTest example of the Developers Guide.
+
+PRJ=../../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+include $(SETTINGS)/dk.mk
+
+# Define non-platform/compiler specific settings
+EXAMPLE_NAME=OfficeDevPathSubstitutionTest
+OUT_APP_CLASS = $(OUT_CLASS)/$(EXAMPLE_NAME)
+
+APP1_NAME=PathSubstitutionTest
+APP1_JAR=$(OUT_APP_CLASS)/$(APP1_NAME).jar
+
+SDK_CLASSPATH=$(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
+ $(PATH_SEPARATOR)$(OUT_APP_CLASS))
+
+
+# Targets
+.PHONY: ALL
+ALL : $(EXAMPLE_NAME)
+
+include $(SETTINGS)/stdtarget.mk
+
+$(OUT_APP_CLASS)/%.class : %.java
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_APP_CLASS) $<
+
+$(OUT_APP_CLASS)/%.mf :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo Main-Class: com.sun.star.lib.loader.Loader> $@
+ $(ECHOLINE)>> $@
+ @echo Name: com/sun/star/lib/loader/Loader.class>> $@
+ @echo Application-Class: $*>> $@
+
+$(OUT_APP_CLASS)/%.jar : $(OUT_APP_CLASS)/%.mf $(OUT_APP_CLASS)/%.class
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ +cd $(subst /,$(PS),$(OUT_APP_CLASS)) && $(SDK_JAR) cvfm $(@F) $*.mf $*.class
+ +$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES)
+
+$(APP1_JAR) : $(OUT_APP_CLASS)/$(APP1_NAME).mf $(OUT_APP_CLASS)/$(APP1_NAME).class
+
+$(EXAMPLE_NAME) : $(APP1_JAR)
+ @echo --------------------------------------------------------------------------------
+ @echo Please use the following commands to execute the examples!
+ @echo -
+ @echo $(MAKE) $(APP1_NAME).run
+ @echo --------------------------------------------------------------------------------
+
+%.run: $(OUT_APP_CLASS)/%.jar
+ $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $<
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_CLASS))
diff --git a/odk/examples/DevelopersGuide/OfficeDev/PathSubstitution/PathSubstitutionTest.java b/odk/examples/DevelopersGuide/OfficeDev/PathSubstitution/PathSubstitutionTest.java
new file mode 100644
index 000000000000..ee0a3dc1a54c
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/PathSubstitution/PathSubstitutionTest.java
@@ -0,0 +1,125 @@
+/*************************************************************************
+ *
+ * $RCSfile: PathSubstitutionTest.java,v $
+ *
+ * $Revision: 1.5 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:48:27 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.beans.PropertyValue;
+
+import com.sun.star.util.XStringSubstitution;
+
+/*
+ * @author Carsten Driesner
+ */
+public class PathSubstitutionTest extends java.lang.Object {
+
+ /*
+ * List of pre-defined path variables supported by
+ * the path substitution service.
+ */
+ private static String[] predefinedPathVariables = {
+ "$(home)","$(inst)","$(prog)","$(temp)","$(user)",
+ "$(work)","$(path)","$(lang)","$(langid)","$(vlang)"
+ };
+
+ /*
+ * @param args the command line arguments
+ */
+ public static void main(String[] args) {
+
+ XComponentContext xRemoteContext = null;
+ XMultiComponentFactory xRemoteServiceManager = null;
+ XStringSubstitution xPathSubstService = null;
+
+ try {
+ // get the remote office context. If necessary a new office
+ // process is started
+ xRemoteContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+ System.out.println("Connected to a running office ...");
+ xRemoteServiceManager = xRemoteContext.getServiceManager();
+
+ Object pathSubst = xRemoteServiceManager.createInstanceWithContext(
+ "com.sun.star.comp.framework.PathSubstitution", xRemoteContext );
+ xPathSubstService = (XStringSubstitution)UnoRuntime.queryInterface(
+ XStringSubstitution.class, pathSubst);
+
+ /* Work with path variables */
+ workWithPathVariables( xPathSubstService );
+ }
+ catch (java.lang.Exception e){
+ e.printStackTrace();
+ }
+ finally {
+ System.exit(0);
+ }
+ }
+
+ public static void workWithPathVariables( XStringSubstitution xPathSubstService )
+ {
+ if ( xPathSubstService != null ) {
+ for ( int i=0; i<predefinedPathVariables.length; i++ ) {
+ try {
+ /* Retrieve values for pre-defined path variables */
+ String aValue = xPathSubstService.getSubstituteVariableValue(
+ predefinedPathVariables[i] );
+ System.out.println( "Variable: "+ predefinedPathVariables[i] +
+ " value=" + aValue );
+ }
+ catch ( com.sun.star.container.NoSuchElementException e) {
+ System.err.println( "NoSuchElementException has been thrown accessing "+predefinedPathVariables[i]);
+ }
+ }
+
+ // Check the resubstitution function
+ try {
+ String aPath = xPathSubstService.getSubstituteVariableValue(
+ predefinedPathVariables[0] ); // Use $(home) as starting point
+ aPath += "/test"; // extend the path
+ System.out.println( "Path="+aPath );
+ String aResubstPath = xPathSubstService.reSubstituteVariables( aPath );
+ System.out.println( "Resubstituted path="+aResubstPath );
+ }
+ catch ( com.sun.star.container.NoSuchElementException e ) {
+ System.err.println( "NoSuchElementException has been thrown accessing "+predefinedPathVariables[0]);
+ }
+ }
+ }
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/Makefile b/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/Makefile
new file mode 100644
index 000000000000..e3d1eba852f7
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/Makefile
@@ -0,0 +1,103 @@
+#*************************************************************************
+#
+# $RCSfile: Makefile,v $
+#
+# $Revision: 1.6 $
+#
+# last change: $Author: rt $ $Date: 2005-03-29 12:12:32 $
+#
+# The Contents of this file are made available subject to the terms of
+# the BSD license.
+#
+# Copyright (c) 2003 by Sun Microsystems, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+#**************************************************************************
+
+# Builds the OfficeDevClipboard example of the Developers Guide.
+
+PRJ=../../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+include $(SETTINGS)/dk.mk
+
+# Define non-platform/compiler specific settings
+EXAMPLE_NAME=OfficeDevTerminationTest
+OUT_APP_CLASS = $(OUT_CLASS)/$(EXAMPLE_NAME)
+
+APP1_NAME=TerminationTest
+APP1_JAR=$(OUT_APP_CLASS)/$(APP1_NAME).jar
+
+APP1_JAVAFILES = \
+ TerminateListener.java \
+ TerminationTest.java
+
+APP1_CLASSFILES = $(patsubst %.java,$(OUT_APP_CLASS)/%.class,$(APP1_JAVAFILES))
+APP1_CLASSNAMES = $(patsubst %.java,%.class,$(APP1_JAVAFILES))
+
+SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
+ $(PATH_SEPARATOR)$(OUT_APP_CLASS))
+
+
+# Targets
+.PHONY: ALL
+ALL : $(EXAMPLE_NAME)
+
+include $(SETTINGS)/stdtarget.mk
+
+$(APP1_CLASSFILES) : $(APP1_JAVAFILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_APP_CLASS) $^
+
+$(OUT_APP_CLASS)/%.mf :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo Main-Class: com.sun.star.lib.loader.Loader> $@
+ $(ECHOLINE)>> $@
+ @echo Name: com/sun/star/lib/loader/Loader.class>> $@
+ @echo Application-Class: $*>> $@
+
+$(APP1_JAR) : $(OUT_APP_CLASS)/$(APP1_NAME).mf $(APP1_CLASSFILES)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ +cd $(subst /,$(PS),$(OUT_APP_CLASS)) && $(SDK_JAR) cvfm $(@F) $(basename $(@F)).mf $(APP1_CLASSNAMES)
+ +$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES)
+
+$(EXAMPLE_NAME) : $(APP1_JAR)
+ @echo --------------------------------------------------------------------------------
+ @echo Please use the following command to execute the example!
+ @echo -
+ @echo $(MAKE) $(APP1_NAME).run
+ @echo --------------------------------------------------------------------------------
+
+%.run: $(OUT_APP_CLASS)/%.jar
+ $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $<
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_CLASS))
diff --git a/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/TerminateListener.java b/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/TerminateListener.java
new file mode 100644
index 000000000000..bb0dd9c1679f
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/TerminateListener.java
@@ -0,0 +1,66 @@
+/*************************************************************************
+ *
+ * $RCSfile: TerminateListener.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:48:52 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.frame.TerminationVetoException;
+import com.sun.star.frame.XTerminateListener;
+
+/**
+ *
+ * @author dschulten
+ */
+public class TerminateListener implements XTerminateListener {
+
+ public void notifyTermination(com.sun.star.lang.EventObject eventObject) {
+ System.out.println("about to terminate...");
+ }
+
+ public void queryTermination(com.sun.star.lang.EventObject eventObject)
+ throws TerminationVetoException {
+
+ // test if we can terminate now
+ if (TerminationTest.isAtWork() == true) {
+ System.out.println("Terminate while we are at work? You can't mean it serious ;-)!");
+ throw new TerminationVetoException();
+ }
+ }
+
+ public void disposing(com.sun.star.lang.EventObject eventObject) {
+ }
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/TerminationTest.java b/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/TerminationTest.java
new file mode 100644
index 000000000000..7242dc5b96e9
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/TerminationTest.java
@@ -0,0 +1,107 @@
+/*************************************************************************
+ *
+ * $RCSfile: TerminationTest.java,v $
+ *
+ * $Revision: 1.5 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:49:06 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.frame.XDesktop;
+
+/**
+ *
+ * @author dschulten
+ */
+public class TerminationTest extends java.lang.Object {
+
+ private static boolean atWork = false;
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String[] args) {
+
+ XComponentContext xRemoteContext = null;
+ XMultiComponentFactory xRemoteServiceManager = null;
+ XDesktop xDesktop = null;
+
+ try {
+ // get the remote office context. If necessary a new office
+ // process is started
+ xRemoteContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+ System.out.println("Connected to a running office ...");
+ xRemoteServiceManager = xRemoteContext.getServiceManager();
+
+ Object desktop = xRemoteServiceManager.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xRemoteContext);
+ xDesktop = (XDesktop)UnoRuntime.queryInterface(XDesktop.class, desktop);
+
+ TerminateListener terminateListener = new TerminateListener();
+ xDesktop.addTerminateListener(terminateListener);
+
+ atWork = true;
+ // try to terminate while we are at work
+ boolean terminated = xDesktop.terminate();
+ System.out.println("The Office " +
+ (terminated == true ?
+ "has been terminated" :
+ "is still running, we are at work"));
+
+ // no longer at work
+ atWork = false;
+ // once more: try to terminate
+ terminated = xDesktop.terminate();
+ System.out.println("The Office " +
+ (terminated == true ?
+ "has been terminated" :
+ "is still running. Someone else prevents termination, " +
+ "e.g. the quickstarter"));
+ }
+ catch (java.lang.Exception e){
+ e.printStackTrace();
+ }
+ finally {
+ System.exit(0);
+ }
+
+
+ }
+ public static boolean isAtWork() {
+ return atWork;
+ }
+
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/makefile.mk b/odk/examples/DevelopersGuide/OfficeDev/makefile.mk
new file mode 100644
index 000000000000..061fa1763201
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/makefile.mk
@@ -0,0 +1,184 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2008 by Sun Microsystems, Inc.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# $RCSfile: makefile.mk,v $
+#
+# $Revision: 1.6 $
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+PRJ=..$/..$/..
+PRJNAME=odk
+TARGET=copying
+
+#----------------------------------------------------------------
+.INCLUDE: settings.mk
+.INCLUDE: $(PRJ)$/util$/makefile.pmk
+#----------------------------------------------------------------
+
+#----------------------------------------------------
+# this makefile is only used for copying the example
+# files into the SDK
+#----------------------------------------------------
+
+
+OFFICEDEV_FILES=\
+ $(DESTDIRDEVGUIDEEXAMPLES)$/OfficeDev$/ContextMenuInterceptor.java \
+ $(DESTDIRDEVGUIDEEXAMPLES)$/OfficeDev$/Makefile \
+ $(DESTDIRDEVGUIDEEXAMPLES)$/OfficeDev$/MenuElement.java \
+ $(DESTDIRDEVGUIDEEXAMPLES)$/OfficeDev$/Number_Formats.java \
+ $(DESTDIRDEVGUIDEEXAMPLES)$/OfficeDev$/OfficeConnect.java
+
+DESTCLIPBOARD=$(DESTDIRDEVGUIDEEXAMPLES)$/OfficeDev$/Clipboard
+CLIPBOARD_FILES=\
+ $(DESTCLIPBOARD)$/Clipboard.java \
+ $(DESTCLIPBOARD)$/ClipboardListener.java \
+ $(DESTCLIPBOARD)$/ClipboardOwner.java \
+ $(DESTCLIPBOARD)$/Makefile \
+ $(DESTCLIPBOARD)$/TextTransferable.java
+
+DESTDESKTOPENV=$(DESTDIRDEVGUIDEEXAMPLES)$/OfficeDev$/DesktopEnvironment
+DESKTOPENV_FILES=\
+ $(DESTDESKTOPENV)$/nativelib$/unix$/exports.dxp \
+ $(DESTDESKTOPENV)$/nativelib$/unix$/Makefile \
+ $(DESTDESKTOPENV)$/nativelib$/unix$/nativeview.c \
+ $(DESTDESKTOPENV)$/nativelib$/unix$/nativeview.h \
+ $(DESTDESKTOPENV)$/nativelib$/windows$/exports.dxp \
+ $(DESTDESKTOPENV)$/nativelib$/windows$/Makefile \
+ $(DESTDESKTOPENV)$/nativelib$/windows$/nativeview.c \
+ $(DESTDESKTOPENV)$/nativelib$/windows$/nativeview.h \
+ $(DESTDESKTOPENV)$/CustomizeView.java \
+ $(DESTDESKTOPENV)$/Desk.java \
+ $(DESTDESKTOPENV)$/DocumentView.java \
+ $(DESTDESKTOPENV)$/FunctionHelper.java \
+ $(DESTDESKTOPENV)$/Install.txt \
+ $(DESTDESKTOPENV)$/Interceptor.java \
+ $(DESTDESKTOPENV)$/IOnewayLink.java \
+ $(DESTDESKTOPENV)$/IShutdownListener.java \
+ $(DESTDESKTOPENV)$/JavaWindowPeerFake.java \
+ $(DESTDESKTOPENV)$/Makefile \
+ $(DESTDESKTOPENV)$/NativeView.java \
+ $(DESTDESKTOPENV)$/OfficeConnect.java \
+ $(DESTDESKTOPENV)$/OnewayExecutor.java \
+ $(DESTDESKTOPENV)$/StatusListener.java \
+ $(DESTDESKTOPENV)$/StatusView.java \
+ $(DESTDESKTOPENV)$/ViewContainer.java
+
+DESTASCIIFILTER=$(DESTDIRDEVGUIDEEXAMPLES)$/OfficeDev$/FilterDevelopment$/AsciiFilter
+ASCIIFILTER_FILES=\
+ $(DESTASCIIFILTER)$/AsciiReplaceFilter.java \
+ $(DESTASCIIFILTER)$/FilterOptions.java \
+ $(DESTASCIIFILTER)$/Makefile \
+ $(DESTASCIIFILTER)$/TypeDetection.xcu
+
+DESTFILTERDETECTION=$(DESTDIRDEVGUIDEEXAMPLES)$/OfficeDev$/FilterDevelopment$/FlatXmlFilterDetection
+FILTERDETECTION_FILES=\
+ $(DESTFILTERDETECTION)$/fdcomp.cxx \
+ $(DESTFILTERDETECTION)$/filterdetect.cxx \
+ $(DESTFILTERDETECTION)$/filterdetect.hxx \
+ $(DESTFILTERDETECTION)$/FlatXmlTypeDetection.uno.xml \
+ $(DESTFILTERDETECTION)$/FlatXmlTypeDetection.xcu \
+ $(DESTFILTERDETECTION)$/Makefile
+
+DESTFLATXMLCPP=$(DESTDIRDEVGUIDEEXAMPLES)$/OfficeDev$/FilterDevelopment$/FlatXmlFilter_cpp
+FLATXMLCPP_FILES=\
+ $(DESTFLATXMLCPP)$/FlatXml.cxx \
+ $(DESTFLATXMLCPP)$/FlatXmlFilter_cpp.uno.xml \
+ $(DESTFLATXMLCPP)$/Makefile \
+ $(DESTFLATXMLCPP)$/FlatXmlFilter_cpp.xcu
+
+DESTFLATXMLJAVA=$(DESTDIRDEVGUIDEEXAMPLES)$/OfficeDev$/FilterDevelopment$/FlatXmlFilter_java
+FLATXMLJAVA_FILES=\
+ $(DESTFLATXMLJAVA)$/Makefile \
+ $(DESTFLATXMLJAVA)$/FlatXmlFilter_java.xcu \
+ $(DESTFLATXMLJAVA)$/FlatXml.java
+
+DESTLINGUISTIC=$(DESTDIRDEVGUIDEEXAMPLES)$/OfficeDev$/Linguistic
+LINGUISTIC_FILES=\
+ $(DESTLINGUISTIC)$/LinguisticExamples.java \
+ $(DESTLINGUISTIC)$/Makefile \
+ $(DESTLINGUISTIC)$/OneInstanceFactory.java \
+ $(DESTLINGUISTIC)$/PropChgHelper.java \
+ $(DESTLINGUISTIC)$/PropChgHelper_Hyph.java \
+ $(DESTLINGUISTIC)$/PropChgHelper_Spell.java \
+ $(DESTLINGUISTIC)$/SampleHyphenator.java \
+ $(DESTLINGUISTIC)$/SampleSpellChecker.java \
+ $(DESTLINGUISTIC)$/SampleThesaurus.java \
+ $(DESTLINGUISTIC)$/XHyphenatedWord_impl.java \
+ $(DESTLINGUISTIC)$/XMeaning_impl.java \
+ $(DESTLINGUISTIC)$/XPossibleHyphens_impl.java \
+ $(DESTLINGUISTIC)$/XSpellAlternatives_impl.java
+
+DESTPATHSETTINGS=$(DESTDIRDEVGUIDEEXAMPLES)$/OfficeDev$/PathSettings
+PATHSETTINGS_FILES=\
+ $(DESTPATHSETTINGS)$/Makefile \
+ $(DESTPATHSETTINGS)$/PathSettingsTest.java
+
+DESTPATHSUBSTITUTION=$(DESTDIRDEVGUIDEEXAMPLES)$/OfficeDev$/PathSubstitution
+PATHSUBSTITUTION_FILES=\
+ $(DESTPATHSUBSTITUTION)$/Makefile \
+ $(DESTPATHSUBSTITUTION)$/PathSubstitutionTest.java
+
+DESTTERMINATIONTEST=$(DESTDIRDEVGUIDEEXAMPLES)$/OfficeDev$/TerminationTest
+TERMINATION_FILES=\
+ $(DESTTERMINATIONTEST)$/Makefile \
+ $(DESTTERMINATIONTEST)$/TerminateListener.java \
+ $(DESTTERMINATIONTEST)$/TerminationTest.java
+
+DESTDISABLECOMMANDS=$(DESTDIRDEVGUIDEEXAMPLES)$/OfficeDev$/DisableCommands
+DISABLECOMMANDS_FILES=\
+ $(DESTDISABLECOMMANDS)$/Makefile \
+ $(DESTDISABLECOMMANDS)$/DisableCommandsTest.java
+
+DIR_FILE_LIST= \
+ $(OFFICEDEV_FILES) \
+ $(CLIPBOARD_FILES) \
+ $(DESKTOPENV_FILES) \
+ $(ASCIIFILTER_FILES) \
+ $(FILTERDETECTION_FILES) \
+ $(FLATXMLCPP_FILES) \
+ $(FLATXMLJAVA_FILES) \
+ $(LINGUISTIC_FILES) \
+ $(PATHSETTINGS_FILES) \
+ $(PATHSUBSTITUTION_FILES) \
+ $(TERMINATION_FILES) \
+ $(DISABLECOMMANDS_FILES)
+
+DIR_DIRECTORY_LIST=$(uniq $(DIR_FILE_LIST:d))
+DIR_CREATE_FLAG=$(MISC)$/devguide_officedev_dirs_created.txt
+DIR_FILE_FLAG=$(MISC)$/devguide_officedev.txt
+
+#--------------------------------------------------
+# TARGETS
+#--------------------------------------------------
+all : \
+ $(DIR_FILE_LIST) \
+ $(DIR_FILE_FLAG)
+
+#--------------------------------------------------
+# use global rules
+#--------------------------------------------------
+.INCLUDE: $(PRJ)$/util$/odk_rules.pmk
+