summaryrefslogtreecommitdiffstats
path: root/odk/examples/DevelopersGuide/OfficeDev/Linguistic
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Linguistic/LinguisticExamples.java360
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Linguistic/Makefile231
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Linguistic/OneInstanceFactory.java155
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Linguistic/PropChgHelper.java193
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Linguistic/PropChgHelper_Hyph.java81
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Linguistic/PropChgHelper_Spell.java105
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleHyphenator.components8
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleHyphenator.java514
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleSpellChecker.components8
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleSpellChecker.java457
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleThesaurus.components8
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleThesaurus.java293
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Linguistic/XHyphenatedWord_impl.java100
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Linguistic/XMeaning_impl.java71
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Linguistic/XPossibleHyphens_impl.java92
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/Linguistic/XSpellAlternatives_impl.java94
16 files changed, 2770 insertions, 0 deletions
diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/LinguisticExamples.java b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/LinguisticExamples.java
new file mode 100644
index 000000000..9cbd481cb
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/LinguisticExamples.java
@@ -0,0 +1,360 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * 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.lang.EventObject;
+import com.sun.star.lang.Locale;
+import com.sun.star.uno.UnoRuntime;
+
+public class LinguisticExamples
+{
+ // The remote office context
+ 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 its 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 = UnoRuntime.queryInterface(XLinguServiceManager.class, aObj);
+ }
+ return mxLinguSvcMgr != null;
+ }
+
+
+ /** Get the SpellChecker to be used.
+ */
+ public boolean GetSpell()
+ throws 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.RuntimeException
+ {
+ if (mxLinguSvcMgr != null)
+ mxHyph = mxLinguSvcMgr.getHyphenator();
+ return mxHyph != null;
+ }
+
+ /** Get the Thesaurus to be used.
+ */
+ public boolean GetThes()
+ throws 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
+ // from 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 = 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 detected!" );
+ 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 = UnoRuntime.queryInterface(
+ XPropertySet.class,aObj);
+
+ // set a spellchecker and hyphenator property value to a defined state
+ try {
+ aLinguProps.setPropertyValue("IsGermanPreReform", 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", 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 program termination.
+ //! should not be omitted.
+ mxLinguSvcMgr.removeLinguServiceManagerListener(aClient);
+
+
+ System.exit(0);
+ }
+
+ /** simple sample implementation of a clients XLinguServiceEventListener
+ * interface implementation
+ */
+ private 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 received (e.g. trigger background spellchecking
+ //! or hyphenation again.)
+
+ System.out.println("Listener called");
+ }
+ }
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/Makefile b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/Makefile
new file mode 100644
index 000000000..95b6204c0
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/Makefile
@@ -0,0 +1,231 @@
+#*************************************************************************
+#
+# The Contents of this file are made available subject to the terms of
+# the BSD license.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+# 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
+
+# Define non-platform/compiler specific settings
+EXAMPLE_NAME=OfficeDevLinguisticExample
+OUT_COMP_CLASS = $(OUT_CLASS)/$(EXAMPLE_NAME)
+
+COMP1_NAME=SampleHyphenator
+COMP1_PACKAGE = $(OUT_BIN)/$(COMP1_NAME).$(UNOOXT_EXT)
+COMP1_PACKAGE_URL = $(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP1_NAME).$(UNOOXT_EXT)")
+COMP1_JAR_NAME = $(COMP1_NAME).uno.jar
+COMP1_JAR = $(OUT_COMP_CLASS)/$(COMP1_JAR_NAME)
+COMP1_MANIFESTFILE = $(OUT_COMP_CLASS)/$(COMP1_NAME).uno.Manifest
+COMP1_UNOPKG_MANIFEST = $(OUT_COMP_CLASS)/$(COMP1_NAME)/META-INF/manifest.xml
+COMP1_COMPONENTS=$(COMP1_NAME).components
+
+COMP2_NAME=SampleSpellChecker
+COMP2_PACKAGE = $(OUT_BIN)/$(COMP2_NAME).$(UNOOXT_EXT)
+COMP2_PACKAGE_URL = $(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP2_NAME).$(UNOOXT_EXT)")
+COMP2_JAR_NAME = $(COMP2_NAME).uno.jar
+COMP2_JAR = $(OUT_COMP_CLASS)/$(COMP2_JAR_NAME)
+COMP2_MANIFESTFILE = $(OUT_COMP_CLASS)/$(COMP2_NAME).uno.Manifest
+COMP2_UNOPKG_MANIFEST = $(OUT_COMP_CLASS)/$(COMP2_NAME)/META-INF/manifest.xml
+COMP2_COMPONENTS=$(COMP2_NAME).components
+
+COMP3_NAME=SampleThesaurus
+COMP3_PACKAGE = $(OUT_BIN)/$(COMP3_NAME).$(UNOOXT_EXT)
+COMP3_PACKAGE_URL = $(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP3_NAME).$(UNOOXT_EXT)")
+COMP3_JAR_NAME = $(COMP3_NAME).uno.jar
+COMP3_JAR = $(OUT_COMP_CLASS)/$(COMP3_JAR_NAME)
+COMP3_MANIFESTFILE = $(OUT_COMP_CLASS)/$(COMP3_NAME).uno.Manifest
+COMP3_UNOPKG_MANIFEST = $(OUT_COMP_CLASS)/$(COMP3_NAME)/META-INF/manifest.xml
+COMP3_COMPONENTS=$(COMP2_NAME).components
+
+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))
+
+$(COMP1_NAME)_CLASSFILES = XHyphenatedWord_impl.class \
+ XPossibleHyphens_impl.class \
+ PropChgHelper.class \
+ PropChgHelper_Hyph.class \
+ OneInstanceFactory.class \
+ $(COMP1_NAME).class
+
+$(COMP2_NAME)_CLASSFILES = XSpellAlternatives_impl.class \
+ PropChgHelper_Spell.class \
+ PropChgHelper.class \
+ OneInstanceFactory.class \
+ $(COMP2_NAME).class
+
+$(COMP3_NAME)_CLASSFILES = XMeaning_impl.class \
+ OneInstanceFactory.class \
+ $(COMP3_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
+
+# 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-components$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(subst /META-INF,,$(subst $(OUT_COMP_CLASS)/,,$(@D))).components$(QM)"/$(CSEP) >> $@
+ @echo $(OSEP)/manifest:manifest$(CSEP) >> $@
+
+$(COMP1_JAR) : $(COMP1_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)
+
+$(COMP1_PACKAGE) : $(COMP1_JAR) $(COMP1_UNOPKG_MANIFEST) $(COMP1_COMPONENTS)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_ZIP) $@ $(COMP1_COMPONENTS)
+ cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_ZIP) -u ../../bin/$(@F) $(<F)
+ cd $(subst /,$(PS),$(OUT_COMP_CLASS)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml
+
+$(COMP2_JAR) : $(COMP2_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)
+
+$(COMP2_PACKAGE) : $(COMP2_JAR) $(COMP2_UNOPKG_MANIFEST) $(COMP2_COMPONENTS)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_ZIP) $@ $(COMP2_COMPONENTS)
+ cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_ZIP) -u ../../bin/$(@F) $(<F)
+ cd $(subst /,$(PS),$(OUT_COMP_CLASS)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml
+
+$(COMP3_JAR) : $(COMP3_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)
+
+$(COMP3_PACKAGE) : $(COMP3_JAR) $(COMP3_UNOPKG_MANIFEST) $(COMP3_COMPONENTS)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_ZIP) $@ $(COMP3_COMPONENTS)
+ cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_ZIP) -u ../../bin/$(@F) $(<F)
+ cd $(subst /,$(PS),$(OUT_COMP_CLASS)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml
+
+$(REGISTERFLAG) : $(COMP1_PACKAGE) $(COMP2_PACKAGE) $(COMP3_PACKAGE)
+ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES"
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ $(DEPLOYTOOL) $(COMP1_PACKAGE_URL)
+ $(DEPLOYTOOL) $(COMP2_PACKAGE_URL)
+ $(DEPLOYTOOL) $(COMP3_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)$(COMP1_NAME)$(QM)",
+ @echo "$(QM)$(COMP2_NAME)$(QM)" and "$(QM)$(COMP3_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),$(COMP1_PACKAGE_URL)))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP2_PACKAGE_URL)))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP3_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 000000000..5e1fdd60b
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/OneInstanceFactory.java
@@ -0,0 +1,155 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * 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.XSingleComponentFactory;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.lang.XInitialization;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.uno.XInterface;
+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
+ XSingleComponentFactory,
+ XServiceInfo
+{
+ private final Class aMyClass;
+ private final String aSvcImplName;
+ private final String[] aSupportedSvcNames;
+ private XInterface xInstantiatedService;
+
+ public OneInstanceFactory(
+ Class aMyClass,
+ String aSvcImplName,
+ String[] aSupportedSvcNames )
+ {
+ this.aMyClass = aMyClass;
+ this.aSvcImplName = aSvcImplName;
+ this.aSupportedSvcNames = aSupportedSvcNames;
+ xInstantiatedService = null;
+ }
+
+
+ // XSingleComponentFactory
+
+ public Object createInstanceWithContext( XComponentContext context )
+ 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 = UnoRuntime.queryInterface(
+ XInitialization.class, createInstanceWithContext(context));
+ if (xIni != null)
+ {
+ Object[] aArguments = new Object[]{ null, null };
+ if (context != null)
+ {
+ XPropertySet xPropSet = UnoRuntime.queryInterface(
+ XPropertySet.class,
+ context.getServiceManager().createInstanceWithContext(
+ "com.sun.star.linguistic2.LinguProperties",
+ context ) );
+ aArguments[0] = xPropSet;
+ }
+ xIni.initialize( aArguments );
+ }
+ }
+ return xInstantiatedService;
+ }
+
+ public Object createInstanceWithArgumentsAndContext( Object[] aArguments, XComponentContext context )
+ throws com.sun.star.uno.Exception,
+ com.sun.star.uno.RuntimeException
+ {
+ if (xInstantiatedService == null)
+ {
+ XInitialization xIni = UnoRuntime.queryInterface(
+ XInitialization.class, createInstanceWithContext( context ));
+ 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;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/PropChgHelper.java b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/PropChgHelper.java
new file mode 100644
index 000000000..46fcff061
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/PropChgHelper.java
@@ -0,0 +1,193 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * 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
+{
+ private final XInterface xEvtSource;
+ private final String[] aPropNames;
+ private XPropertySet xPropSet;
+ private final ArrayList<XLinguServiceEventListener> aLngSvcEvtListeners;
+
+ public PropChgHelper(
+ XInterface xEvtSource,
+ String[] aPropNames )
+ {
+ this.xEvtSource = xEvtSource;
+ this.aPropNames = aPropNames;
+ xPropSet = null;
+ aLngSvcEvtListeners = new ArrayList<XLinguServiceEventListener>();
+ }
+
+ public XInterface GetEvtSource()
+ {
+ return xEvtSource;
+ }
+
+ public XPropertySet GetPropSet()
+ {
+ return xPropSet;
+ }
+
+
+
+ public void LaunchEvent( LinguServiceEvent aEvt )
+ {
+ int nCnt = aLngSvcEvtListeners.size();
+ for (int i = 0; i < nCnt; ++i)
+ {
+ XLinguServiceEventListener xLstnr =
+ 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], this );
+ }
+ catch( Exception e ) {
+ }
+ }
+ }
+ }
+ }
+
+ private 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], 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 overridden 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;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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 000000000..0945e413f
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/PropChgHelper_Hyph.java
@@ -0,0 +1,81 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * 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.LinguServiceEvent;
+import com.sun.star.linguistic2.LinguServiceEventFlags;
+import com.sun.star.beans.PropertyChangeEvent;
+import com.sun.star.uno.XInterface;
+
+public class PropChgHelper_Hyph extends PropChgHelper
+{
+ public PropChgHelper_Hyph(
+ XInterface xEvtSource,
+ String[] aPropNames )
+ {
+ super( xEvtSource, aPropNames );
+ }
+
+
+ // XPropertyChangeListener
+
+ @Override
+ 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 );
+ }
+ }
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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 000000000..edd0498db
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/PropChgHelper_Spell.java
@@ -0,0 +1,105 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * 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.LinguServiceEvent;
+import com.sun.star.linguistic2.LinguServiceEventFlags;
+import com.sun.star.beans.PropertyChangeEvent;
+import com.sun.star.uno.XInterface;
+
+public class PropChgHelper_Spell extends PropChgHelper
+{
+ public PropChgHelper_Spell(
+ XInterface xEvtSource,
+ String[] aPropNames )
+ {
+ super( xEvtSource, aPropNames );
+ }
+
+
+ // XPropertyChangeListener
+
+ @Override
+ 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 = !bVal; // FALSE->TRUE change?
+ bSWWA = !bSCWA; // TRUE->FALSE change?
+ }
+ else if (aEvt.PropertyName.equals( "IsSpellWithDigits" ))
+ {
+ bSCWA = !bVal; // FALSE->TRUE change?
+ bSWWA = !bSCWA; // TRUE->FALSE change?
+ }
+ else if (aEvt.PropertyName.equals( "IsSpellCapitalization" ))
+ {
+ bSCWA = !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 );
+ }
+ }
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleHyphenator.components b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleHyphenator.components
new file mode 100644
index 000000000..bf083b386
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleHyphenator.components
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<components xmlns="http://openoffice.org/2010/uno-components">
+ <component loader="com.sun.star.loader.Java2" uri="SampleHyphenator.uno.jar">
+ <implementation name="SampleHyphenator">
+ <service name="com.sun.star.linguistic2.Hyphenator"/>
+ </implementation>
+ </component>
+</components>
diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleHyphenator.java b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleHyphenator.java
new file mode 100644
index 000000000..930d42c32
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleHyphenator.java
@@ -0,0 +1,514 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * 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.XSingleComponentFactory;
+
+// 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.XServiceInfo;
+import com.sun.star.lang.XServiceDisplayName;
+
+// Exceptions
+import com.sun.star.uno.Exception;
+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.beans.XPropertySet;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.uno.AnyConverter;
+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( this, aProps );
+ aEvtListeners = new ArrayList<Object>();
+ 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 = 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 = SampleHyphenator.class.getName();
+
+ 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>XComponentServiceFactory</code> for creating the component
+ * @param aImplName the name of the implementation for which a service is desired
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static XSingleComponentFactory __getComponentFactory(
+ String aImplName )
+ {
+ XSingleComponentFactory xSingleComponentFactory = null;
+ if( aImplName.equals( _aSvcImplName ) )
+ {
+ xSingleComponentFactory = new OneInstanceFactory(
+ SampleHyphenator.class, _aSvcImplName,
+ getSupportedServiceNames_Static() );
+ }
+ return xSingleComponentFactory;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleSpellChecker.components b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleSpellChecker.components
new file mode 100644
index 000000000..bb489918b
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleSpellChecker.components
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<components xmlns="http://openoffice.org/2010/uno-components">
+ <component loader="com.sun.star.loader.Java2" uri="SampleSpellChecker.uno.jar">
+ <implementation name="SampleSpellChecker">
+ <service name="com.sun.star.linguistic2.SpellChecker"/>
+ </implementation>
+ </component>
+</components>
diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleSpellChecker.java b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleSpellChecker.java
new file mode 100644
index 000000000..dc7ddfddd
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleSpellChecker.java
@@ -0,0 +1,457 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * 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.XSingleComponentFactory;
+
+// 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.XServiceInfo;
+import com.sun.star.lang.XServiceDisplayName;
+
+// Exceptions
+import com.sun.star.uno.Exception;
+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.beans.XPropertySet;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.uno.AnyConverter;
+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( this, aProps );
+ aEvtListeners = new ArrayList<Object>();
+ 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 = 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 = SampleSpellChecker.class.getName();
+
+ 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>XSingleComponentFactory</code> for creating the component
+ * @param aImplName the name of the implementation for which a service is desired
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static XSingleComponentFactory __getComponentFactory(
+ String aImplName )
+ {
+ XSingleComponentFactory xSingleComponentFactory = null;
+ if( aImplName.equals( _aSvcImplName ) )
+ {
+ xSingleComponentFactory = new OneInstanceFactory(
+ SampleSpellChecker.class, _aSvcImplName,
+ getSupportedServiceNames_Static() );
+ }
+ return xSingleComponentFactory;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleThesaurus.components b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleThesaurus.components
new file mode 100644
index 000000000..025f42451
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleThesaurus.components
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<components xmlns="http://openoffice.org/2010/uno-components">
+ <component loader="com.sun.star.loader.Java2" uri="SampleThesaurus.uno.jar">
+ <implementation name="SampleThesaurus">
+ <service name="com.sun.star.linguistic2.Thesaurus"/>
+ </implementation>
+ </component>
+</components>
diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleThesaurus.java b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleThesaurus.java
new file mode 100644
index 000000000..f5c437095
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleThesaurus.java
@@ -0,0 +1,293 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * 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.XSingleComponentFactory;
+
+// supported Interfaces
+import com.sun.star.linguistic2.XThesaurus;
+import com.sun.star.lang.XInitialization;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.lang.XServiceDisplayName;
+
+// Exceptions
+import com.sun.star.uno.Exception;
+//used Interfaces
+import com.sun.star.linguistic2.XMeaning;
+import com.sun.star.lang.Locale;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.uno.AnyConverter;
+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 its lifetime) since it gets used in the
+ // 'GetValueToUse' function
+ aPropChgHelper = new PropChgHelper( this, aProps );
+
+ aEvtListeners = new ArrayList<Object>();
+ 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 = 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 = SampleThesaurus.class.getName();
+
+ 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>XSingleComponentFactory</code> for creating the component
+ * @param aImplName the name of the implementation for which a service is desired
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static XSingleComponentFactory __getComponentFactory(
+ String aImplName )
+ {
+ XSingleComponentFactory xSingleComponentFactory = null;
+ if( aImplName.equals( _aSvcImplName ) )
+ {
+ xSingleComponentFactory = new OneInstanceFactory(
+ SampleThesaurus.class, _aSvcImplName,
+ getSupportedServiceNames_Static() );
+ }
+ return xSingleComponentFactory;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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 000000000..47963441b
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/XHyphenatedWord_impl.java
@@ -0,0 +1,100 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * 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
+{
+ private String aWord;
+ private String aHyphenatedWord;
+ private final short nHyphenPos;
+ private final short nHyphenationPos;
+ private Locale aLang;
+ private final 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 = "";
+ if (this.aLang == null)
+ this.aLang = new Locale();
+ if (this.aHyphenatedWord == null)
+ this.aHyphenatedWord = "";
+ }
+
+
+ // 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;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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 000000000..5e30ef22e
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/XMeaning_impl.java
@@ -0,0 +1,71 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * 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.
+ *
+ *************************************************************************/
+
+
+
+public class XMeaning_impl implements
+ com.sun.star.linguistic2.XMeaning
+{
+ private String aMeaning;
+ private 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 = "";
+
+ // 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;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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 000000000..e64752029
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/XPossibleHyphens_impl.java
@@ -0,0 +1,92 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * 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
+{
+ private String aWord;
+ private String aHyphWord;
+ private short[] aOrigHyphenPos;
+ private 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 = "";
+ if (this.aLang == null)
+ this.aLang = new Locale();
+ if (this.aHyphWord == null)
+ this.aHyphWord = "";
+
+ // 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;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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 000000000..d2e9ecbea
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/XSpellAlternatives_impl.java
@@ -0,0 +1,94 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * 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
+{
+ private String aWord;
+ private Locale aLanguage;
+ private String[] aAlt; // list of alternatives, may be empty.
+ private final 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 = "";
+ 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;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */