1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * The Contents of this file are made available subject to the terms of 4*cdf0e10cSrcweir * the BSD license. 5*cdf0e10cSrcweir * 6*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 7*cdf0e10cSrcweir * All rights reserved. 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * Redistribution and use in source and binary forms, with or without 10*cdf0e10cSrcweir * modification, are permitted provided that the following conditions 11*cdf0e10cSrcweir * are met: 12*cdf0e10cSrcweir * 1. Redistributions of source code must retain the above copyright 13*cdf0e10cSrcweir * notice, this list of conditions and the following disclaimer. 14*cdf0e10cSrcweir * 2. Redistributions in binary form must reproduce the above copyright 15*cdf0e10cSrcweir * notice, this list of conditions and the following disclaimer in the 16*cdf0e10cSrcweir * documentation and/or other materials provided with the distribution. 17*cdf0e10cSrcweir * 3. Neither the name of Sun Microsystems, Inc. nor the names of its 18*cdf0e10cSrcweir * contributors may be used to endorse or promote products derived 19*cdf0e10cSrcweir * from this software without specific prior written permission. 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22*cdf0e10cSrcweir * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23*cdf0e10cSrcweir * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24*cdf0e10cSrcweir * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25*cdf0e10cSrcweir * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26*cdf0e10cSrcweir * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27*cdf0e10cSrcweir * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 28*cdf0e10cSrcweir * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29*cdf0e10cSrcweir * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 30*cdf0e10cSrcweir * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 31*cdf0e10cSrcweir * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32*cdf0e10cSrcweir * 33*cdf0e10cSrcweir *************************************************************************/ 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir // uno 36*cdf0e10cSrcweir import com.sun.star.lib.uno.helper.ComponentBase; 37*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir // factories 40*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 41*cdf0e10cSrcweir import com.sun.star.lang.XSingleServiceFactory; 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir // supported Interfaces 44*cdf0e10cSrcweir import com.sun.star.linguistic2.XSpellChecker; 45*cdf0e10cSrcweir import com.sun.star.linguistic2.XLinguServiceEventBroadcaster; 46*cdf0e10cSrcweir import com.sun.star.lang.XInitialization; 47*cdf0e10cSrcweir import com.sun.star.lang.XComponent; 48*cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo; 49*cdf0e10cSrcweir import com.sun.star.lang.XServiceDisplayName; 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir // Exceptions 52*cdf0e10cSrcweir import com.sun.star.uno.Exception; 53*cdf0e10cSrcweir import com.sun.star.uno.RuntimeException; 54*cdf0e10cSrcweir import com.sun.star.lang.IllegalArgumentException; 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir //used Interfaces 57*cdf0e10cSrcweir import com.sun.star.linguistic2.XLinguServiceEventListener; 58*cdf0e10cSrcweir import com.sun.star.linguistic2.XSpellAlternatives; 59*cdf0e10cSrcweir import com.sun.star.linguistic2.SpellFailure; 60*cdf0e10cSrcweir import com.sun.star.lang.Locale; 61*cdf0e10cSrcweir import com.sun.star.lang.XEventListener; 62*cdf0e10cSrcweir import com.sun.star.lang.EventObject; 63*cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 64*cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 65*cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 66*cdf0e10cSrcweir import com.sun.star.lang.XTypeProvider; 67*cdf0e10cSrcweir import com.sun.star.uno.XInterface; 68*cdf0e10cSrcweir import com.sun.star.uno.Type; 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir import java.util.ArrayList; 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir public class SampleSpellChecker extends ComponentBase implements 73*cdf0e10cSrcweir XSpellChecker, 74*cdf0e10cSrcweir XLinguServiceEventBroadcaster, 75*cdf0e10cSrcweir XInitialization, 76*cdf0e10cSrcweir XServiceDisplayName, 77*cdf0e10cSrcweir XServiceInfo 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir PropChgHelper_Spell aPropChgHelper; 80*cdf0e10cSrcweir ArrayList aEvtListeners; 81*cdf0e10cSrcweir boolean bDisposing; 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir public SampleSpellChecker() 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir // names of relevant properties to be used 86*cdf0e10cSrcweir String[] aProps = new String[] 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir "IsIgnoreControlCharacters", 89*cdf0e10cSrcweir "IsUseDictionaryList", 90*cdf0e10cSrcweir "IsGermanPreReform", 91*cdf0e10cSrcweir "IsSpellUpperCase", 92*cdf0e10cSrcweir "IsSpellWithDigits", 93*cdf0e10cSrcweir "IsSpellCapitalization" 94*cdf0e10cSrcweir }; 95*cdf0e10cSrcweir aPropChgHelper = new PropChgHelper_Spell( (XSpellChecker) this, aProps ); 96*cdf0e10cSrcweir aEvtListeners = new ArrayList(); 97*cdf0e10cSrcweir bDisposing = false; 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir private boolean IsEqual( Locale aLoc1, Locale aLoc2 ) 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir return aLoc1.Language.equals( aLoc2.Language ) && 103*cdf0e10cSrcweir aLoc1.Country .equals( aLoc2.Country ) && 104*cdf0e10cSrcweir aLoc1.Variant .equals( aLoc2.Variant ); 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir private boolean GetValueToUse( 108*cdf0e10cSrcweir String aPropName, 109*cdf0e10cSrcweir boolean bDefaultVal, 110*cdf0e10cSrcweir PropertyValue[] aProps ) 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir boolean bRes = bDefaultVal; 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir try 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir // use temporary value if supplied 117*cdf0e10cSrcweir for (int i = 0; i < aProps.length; ++i) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir if (aPropName.equals( aProps[i].Name )) 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir Object aObj = aProps[i].Value; 122*cdf0e10cSrcweir if (AnyConverter.isBoolean( aObj )) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir bRes = AnyConverter.toBoolean( aObj ); 125*cdf0e10cSrcweir return bRes; 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir // otherwise use value from property set (if available) 131*cdf0e10cSrcweir XPropertySet xPropSet = aPropChgHelper.GetPropSet(); 132*cdf0e10cSrcweir if (xPropSet != null) // should always be the case 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir Object aObj = xPropSet.getPropertyValue( aPropName ); 135*cdf0e10cSrcweir if (AnyConverter.isBoolean( aObj )) 136*cdf0e10cSrcweir bRes = AnyConverter.toBoolean( aObj ); 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir catch (Exception e) { 140*cdf0e10cSrcweir bRes = bDefaultVal; 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir return bRes; 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir private boolean IsUpper( String aWord, Locale aLocale ) 147*cdf0e10cSrcweir { 148*cdf0e10cSrcweir java.util.Locale aLang = new java.util.Locale( 149*cdf0e10cSrcweir aLocale.Language, aLocale.Country, aLocale.Variant ); 150*cdf0e10cSrcweir return aWord.equals( aWord.toUpperCase( aLang ) ); 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir private boolean HasDigits( String aWord ) 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir int nLen = aWord.length(); 156*cdf0e10cSrcweir for (int i = 0; i < nLen; ++i) 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir if (Character.isDigit( aWord.charAt(i) )) 159*cdf0e10cSrcweir return true; 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir return false; 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir private short GetSpellFailure( 165*cdf0e10cSrcweir String aWord, 166*cdf0e10cSrcweir Locale aLocale, 167*cdf0e10cSrcweir PropertyValue[] aProperties ) 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir short nRes = -1; 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir //!! This code needs to be replaced by code calling the actual 172*cdf0e10cSrcweir //!! implementation of your spellchecker 173*cdf0e10cSrcweir boolean bIsGermanPreReform = GetValueToUse( "IsGermanPreReform", false, aProperties ); 174*cdf0e10cSrcweir if (IsEqual( aLocale, new Locale( "de", "DE", "" ) )) 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir if (bIsGermanPreReform && aWord.equals( "Schifffahrt" )) 177*cdf0e10cSrcweir nRes = SpellFailure.SPELLING_ERROR; 178*cdf0e10cSrcweir else if (!bIsGermanPreReform && aWord.equals( "Schiffahrt" )) 179*cdf0e10cSrcweir nRes = SpellFailure.SPELLING_ERROR; 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir else if (IsEqual( aLocale, new Locale( "en", "US", "" ) )) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir // words with 'u', 'U' and 'arizona' are defined to be incorrect 184*cdf0e10cSrcweir boolean bIsValid = !(aWord.indexOf( "u" ) != -1 || aWord.indexOf( "U" ) != -1) 185*cdf0e10cSrcweir && !aWord.equals( "arizona" ); 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir if (!bIsValid) 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir // default value (no other SpellFailure type is applicable) 190*cdf0e10cSrcweir nRes = SpellFailure.SPELLING_ERROR; 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir if (aWord.equals( "arizona" )) 193*cdf0e10cSrcweir nRes = SpellFailure.CAPTION_ERROR; 194*cdf0e10cSrcweir else if (aWord.equals( "house" )) 195*cdf0e10cSrcweir nRes = SpellFailure.SPELLING_ERROR; 196*cdf0e10cSrcweir else if (aWord.equals( "course" )) 197*cdf0e10cSrcweir nRes = SpellFailure.IS_NEGATIVE_WORD; 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir return nRes; 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir private XSpellAlternatives GetProposals( 205*cdf0e10cSrcweir String aWord, 206*cdf0e10cSrcweir Locale aLocale, 207*cdf0e10cSrcweir PropertyValue[] aProperties ) 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir short nType = SpellFailure.SPELLING_ERROR; 210*cdf0e10cSrcweir String[] aProposals = null; 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir // get values of relevant properties that may be used. 213*cdf0e10cSrcweir //! The values for 'IsIgnoreControlCharacters' and 'IsUseDictionaryList' 214*cdf0e10cSrcweir //! are handled by the dispatcher! Thus there is no need to access 215*cdf0e10cSrcweir //! them here. 216*cdf0e10cSrcweir boolean bIsGermanPreReform = GetValueToUse( "IsGermanPreReform", false, aProperties ); 217*cdf0e10cSrcweir boolean bIsSpellWithDigits = GetValueToUse( "IsSpellWithDigits", false, aProperties ); 218*cdf0e10cSrcweir boolean bIsSpellUpperCase = GetValueToUse( "IsSpellUpperCase", false, aProperties ); 219*cdf0e10cSrcweir boolean bIsSpellCapitalization = GetValueToUse( "IsSpellCapitalization", true, aProperties ); 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir //!! This code needs to be replaced by code calling the actual 222*cdf0e10cSrcweir //!! implementation of your spellchecker 223*cdf0e10cSrcweir if (IsEqual( aLocale, new Locale( "de", "DE", "" ) )) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir if (bIsGermanPreReform && aWord.equals( "Schifffahrt" )) 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir nType = SpellFailure.SPELLING_ERROR; 228*cdf0e10cSrcweir aProposals = new String[]{ "Schiffahrt" }; 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir else if (!bIsGermanPreReform && aWord.equals( "Schiffahrt" )) 231*cdf0e10cSrcweir { 232*cdf0e10cSrcweir nType = SpellFailure.SPELLING_ERROR; 233*cdf0e10cSrcweir aProposals = new String[]{ "Schifffahrt" }; 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir } 236*cdf0e10cSrcweir else if (IsEqual( aLocale, new Locale( "en", "US", "" ) )) 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir if (aWord.equals( "arizona" )) 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir nType = SpellFailure.CAPTION_ERROR; 241*cdf0e10cSrcweir aProposals = new String[]{ "Arizona" }; 242*cdf0e10cSrcweir } 243*cdf0e10cSrcweir else if (aWord.equals( "house" )) 244*cdf0e10cSrcweir { 245*cdf0e10cSrcweir nType = SpellFailure.SPELLING_ERROR; 246*cdf0e10cSrcweir aProposals = new String[]{ "horse", "home" }; 247*cdf0e10cSrcweir } 248*cdf0e10cSrcweir else if (aWord.equals( "course" )) 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir nType = SpellFailure.IS_NEGATIVE_WORD; 251*cdf0e10cSrcweir aProposals = new String[]{ "line", "plan", "approach" }; 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir // always return a result if word is incorrect, 256*cdf0e10cSrcweir // proposals may be empty though. 257*cdf0e10cSrcweir return new XSpellAlternatives_impl( aWord, aLocale, 258*cdf0e10cSrcweir nType, aProposals ); 259*cdf0e10cSrcweir } 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir // __________ interface methods __________ 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir //***************** 265*cdf0e10cSrcweir //XSupportedLocales 266*cdf0e10cSrcweir //***************** 267*cdf0e10cSrcweir public Locale[] getLocales() 268*cdf0e10cSrcweir throws com.sun.star.uno.RuntimeException 269*cdf0e10cSrcweir { 270*cdf0e10cSrcweir Locale aLocales[] = 271*cdf0e10cSrcweir { 272*cdf0e10cSrcweir new Locale( "de", "DE", "" ), 273*cdf0e10cSrcweir new Locale( "en", "US", "" ) 274*cdf0e10cSrcweir }; 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir return aLocales; 277*cdf0e10cSrcweir } 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir public boolean hasLocale( Locale aLocale ) 280*cdf0e10cSrcweir throws com.sun.star.uno.RuntimeException 281*cdf0e10cSrcweir { 282*cdf0e10cSrcweir boolean bRes = false; 283*cdf0e10cSrcweir if ( IsEqual( aLocale, new Locale( "de", "DE", "" ) ) || 284*cdf0e10cSrcweir IsEqual( aLocale, new Locale( "en", "US", "" ) )) 285*cdf0e10cSrcweir bRes = true; 286*cdf0e10cSrcweir return bRes; 287*cdf0e10cSrcweir } 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir //************* 291*cdf0e10cSrcweir //XSpellChecker 292*cdf0e10cSrcweir //************* 293*cdf0e10cSrcweir public boolean isValid( 294*cdf0e10cSrcweir String aWord, Locale aLocale, 295*cdf0e10cSrcweir PropertyValue[] aProperties ) 296*cdf0e10cSrcweir throws com.sun.star.uno.RuntimeException, 297*cdf0e10cSrcweir IllegalArgumentException 298*cdf0e10cSrcweir { 299*cdf0e10cSrcweir if (IsEqual( aLocale, new Locale() ) || aWord.length() == 0) 300*cdf0e10cSrcweir return true; 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir // linguistic is currently not allowed to throw exceptions 303*cdf0e10cSrcweir // thus we return null which means 'word cannot be spelled' 304*cdf0e10cSrcweir if (!hasLocale( aLocale )) 305*cdf0e10cSrcweir return true; 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir // get values of relevant properties that may be used. 308*cdf0e10cSrcweir //! The values for 'IsIgnoreControlCharacters' and 'IsUseDictionaryList' 309*cdf0e10cSrcweir //! are handled by the dispatcher! Thus there is no need to access 310*cdf0e10cSrcweir //! them here. 311*cdf0e10cSrcweir boolean bIsGermanPreReform = GetValueToUse( "IsGermanPreReform", false, aProperties ); 312*cdf0e10cSrcweir boolean bIsSpellWithDigits = GetValueToUse( "IsSpellWithDigits", false, aProperties ); 313*cdf0e10cSrcweir boolean bIsSpellUpperCase = GetValueToUse( "IsSpellUpperCase", false, aProperties ); 314*cdf0e10cSrcweir boolean bIsSpellCapitalization = GetValueToUse( "IsSpellCapitalization", true, aProperties ); 315*cdf0e10cSrcweir 316*cdf0e10cSrcweir short nFailure = GetSpellFailure( aWord, aLocale, aProperties ); 317*cdf0e10cSrcweir if (nFailure != -1) 318*cdf0e10cSrcweir { 319*cdf0e10cSrcweir // postprocess result for errors that should be ignored 320*cdf0e10cSrcweir if ( (!bIsSpellUpperCase && IsUpper( aWord, aLocale )) 321*cdf0e10cSrcweir || (!bIsSpellWithDigits && HasDigits( aWord )) 322*cdf0e10cSrcweir || (!bIsSpellCapitalization 323*cdf0e10cSrcweir && nFailure == SpellFailure.CAPTION_ERROR) 324*cdf0e10cSrcweir ) 325*cdf0e10cSrcweir nFailure = -1; 326*cdf0e10cSrcweir } 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir return nFailure == -1; 329*cdf0e10cSrcweir } 330*cdf0e10cSrcweir 331*cdf0e10cSrcweir 332*cdf0e10cSrcweir public XSpellAlternatives spell( 333*cdf0e10cSrcweir String aWord, Locale aLocale, 334*cdf0e10cSrcweir PropertyValue[] aProperties ) 335*cdf0e10cSrcweir throws com.sun.star.uno.RuntimeException, 336*cdf0e10cSrcweir IllegalArgumentException 337*cdf0e10cSrcweir { 338*cdf0e10cSrcweir if (IsEqual( aLocale, new Locale() ) || aWord.length() == 0) 339*cdf0e10cSrcweir return null; 340*cdf0e10cSrcweir 341*cdf0e10cSrcweir // linguistic is currently not allowed to throw exceptions 342*cdf0e10cSrcweir // thus we return null fwhich means 'word cannot be spelled' 343*cdf0e10cSrcweir if (!hasLocale( aLocale )) 344*cdf0e10cSrcweir return null; 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir XSpellAlternatives xRes = null; 347*cdf0e10cSrcweir if (!isValid( aWord, aLocale, aProperties )) 348*cdf0e10cSrcweir { 349*cdf0e10cSrcweir xRes = GetProposals( aWord, aLocale, aProperties ); 350*cdf0e10cSrcweir } 351*cdf0e10cSrcweir return xRes; 352*cdf0e10cSrcweir } 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir 355*cdf0e10cSrcweir //***************************** 356*cdf0e10cSrcweir //XLinguServiceEventBroadcaster 357*cdf0e10cSrcweir //***************************** 358*cdf0e10cSrcweir public boolean addLinguServiceEventListener ( 359*cdf0e10cSrcweir XLinguServiceEventListener xLstnr ) 360*cdf0e10cSrcweir throws com.sun.star.uno.RuntimeException 361*cdf0e10cSrcweir { 362*cdf0e10cSrcweir boolean bRes = false; 363*cdf0e10cSrcweir if (!bDisposing && xLstnr != null) 364*cdf0e10cSrcweir bRes = aPropChgHelper.addLinguServiceEventListener( xLstnr ); 365*cdf0e10cSrcweir return bRes; 366*cdf0e10cSrcweir } 367*cdf0e10cSrcweir 368*cdf0e10cSrcweir public boolean removeLinguServiceEventListener( 369*cdf0e10cSrcweir XLinguServiceEventListener xLstnr ) 370*cdf0e10cSrcweir throws com.sun.star.uno.RuntimeException 371*cdf0e10cSrcweir { 372*cdf0e10cSrcweir boolean bRes = false; 373*cdf0e10cSrcweir if (!bDisposing && xLstnr != null) 374*cdf0e10cSrcweir bRes = aPropChgHelper.removeLinguServiceEventListener( xLstnr ); 375*cdf0e10cSrcweir return bRes; 376*cdf0e10cSrcweir } 377*cdf0e10cSrcweir 378*cdf0e10cSrcweir //******************** 379*cdf0e10cSrcweir // XServiceDisplayName 380*cdf0e10cSrcweir //******************** 381*cdf0e10cSrcweir public String getServiceDisplayName( Locale aLocale ) 382*cdf0e10cSrcweir throws com.sun.star.uno.RuntimeException 383*cdf0e10cSrcweir { 384*cdf0e10cSrcweir return "Java Samples"; 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir 387*cdf0e10cSrcweir //**************** 388*cdf0e10cSrcweir // XInitialization 389*cdf0e10cSrcweir //**************** 390*cdf0e10cSrcweir public void initialize( Object[] aArguments ) 391*cdf0e10cSrcweir throws com.sun.star.uno.Exception, 392*cdf0e10cSrcweir com.sun.star.uno.RuntimeException 393*cdf0e10cSrcweir { 394*cdf0e10cSrcweir int nLen = aArguments.length; 395*cdf0e10cSrcweir if (2 == nLen) 396*cdf0e10cSrcweir { 397*cdf0e10cSrcweir XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface( 398*cdf0e10cSrcweir XPropertySet.class, aArguments[0]); 399*cdf0e10cSrcweir // start listening to property changes 400*cdf0e10cSrcweir aPropChgHelper.AddAsListenerTo( xPropSet ); 401*cdf0e10cSrcweir } 402*cdf0e10cSrcweir } 403*cdf0e10cSrcweir 404*cdf0e10cSrcweir //************* 405*cdf0e10cSrcweir // XServiceInfo 406*cdf0e10cSrcweir //************* 407*cdf0e10cSrcweir public boolean supportsService( String aServiceName ) 408*cdf0e10cSrcweir throws com.sun.star.uno.RuntimeException 409*cdf0e10cSrcweir { 410*cdf0e10cSrcweir String[] aServices = getSupportedServiceNames_Static(); 411*cdf0e10cSrcweir int i, nLength = aServices.length; 412*cdf0e10cSrcweir boolean bResult = false; 413*cdf0e10cSrcweir 414*cdf0e10cSrcweir for( i = 0; !bResult && i < nLength; ++i ) 415*cdf0e10cSrcweir bResult = aServiceName.equals( aServices[ i ] ); 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir return bResult; 418*cdf0e10cSrcweir } 419*cdf0e10cSrcweir 420*cdf0e10cSrcweir public String getImplementationName() 421*cdf0e10cSrcweir throws com.sun.star.uno.RuntimeException 422*cdf0e10cSrcweir { 423*cdf0e10cSrcweir return _aSvcImplName; 424*cdf0e10cSrcweir } 425*cdf0e10cSrcweir 426*cdf0e10cSrcweir public String[] getSupportedServiceNames() 427*cdf0e10cSrcweir throws com.sun.star.uno.RuntimeException 428*cdf0e10cSrcweir { 429*cdf0e10cSrcweir return getSupportedServiceNames_Static(); 430*cdf0e10cSrcweir } 431*cdf0e10cSrcweir 432*cdf0e10cSrcweir // __________ static things __________ 433*cdf0e10cSrcweir 434*cdf0e10cSrcweir public static String _aSvcImplName = SampleSpellChecker.class.getName(); 435*cdf0e10cSrcweir 436*cdf0e10cSrcweir public static String[] getSupportedServiceNames_Static() 437*cdf0e10cSrcweir { 438*cdf0e10cSrcweir String[] aResult = { "com.sun.star.linguistic2.SpellChecker" }; 439*cdf0e10cSrcweir return aResult; 440*cdf0e10cSrcweir } 441*cdf0e10cSrcweir 442*cdf0e10cSrcweir 443*cdf0e10cSrcweir /** 444*cdf0e10cSrcweir * Returns a factory for creating the service. 445*cdf0e10cSrcweir * This method is called by the <code>JavaLoader</code> 446*cdf0e10cSrcweir * <p> 447*cdf0e10cSrcweir * @return returns a <code>XSingleServiceFactory</code> for creating the component 448*cdf0e10cSrcweir * @param implName the name of the implementation for which a service is desired 449*cdf0e10cSrcweir * @param multiFactory the service manager to be used if needed 450*cdf0e10cSrcweir * @param regKey the registryKey 451*cdf0e10cSrcweir * @see com.sun.star.comp.loader.JavaLoader 452*cdf0e10cSrcweir */ 453*cdf0e10cSrcweir public static XSingleServiceFactory __getServiceFactory( 454*cdf0e10cSrcweir String aImplName, 455*cdf0e10cSrcweir XMultiServiceFactory xMultiFactory, 456*cdf0e10cSrcweir com.sun.star.registry.XRegistryKey xRegKey ) 457*cdf0e10cSrcweir { 458*cdf0e10cSrcweir XSingleServiceFactory xSingleServiceFactory = null; 459*cdf0e10cSrcweir if( aImplName.equals( _aSvcImplName ) ) 460*cdf0e10cSrcweir { 461*cdf0e10cSrcweir xSingleServiceFactory = new OneInstanceFactory( 462*cdf0e10cSrcweir SampleSpellChecker.class, _aSvcImplName, 463*cdf0e10cSrcweir getSupportedServiceNames_Static(), 464*cdf0e10cSrcweir xMultiFactory ); 465*cdf0e10cSrcweir } 466*cdf0e10cSrcweir return xSingleServiceFactory; 467*cdf0e10cSrcweir } 468*cdf0e10cSrcweir 469*cdf0e10cSrcweir /** 470*cdf0e10cSrcweir * Writes the service information into the given registry key. 471*cdf0e10cSrcweir * This method is called by the <code>JavaLoader</code> 472*cdf0e10cSrcweir * <p> 473*cdf0e10cSrcweir * @return returns true if the operation succeeded 474*cdf0e10cSrcweir * @param xRegKey the registryKey 475*cdf0e10cSrcweir * @see com.sun.star.comp.loader.JavaLoader 476*cdf0e10cSrcweir */ 477*cdf0e10cSrcweir // This method not longer necessary since OOo 3.4 where the component registration 478*cdf0e10cSrcweir // was changed to passive component registration. For more details see 479*cdf0e10cSrcweir // http://wiki.services.openoffice.org/wiki/Passive_Component_Registration 480*cdf0e10cSrcweir 481*cdf0e10cSrcweir // public static boolean __writeRegistryServiceInfo( 482*cdf0e10cSrcweir // com.sun.star.registry.XRegistryKey xRegKey ) 483*cdf0e10cSrcweir // { 484*cdf0e10cSrcweir // boolean bResult = true; 485*cdf0e10cSrcweir // String[] aServices = getSupportedServiceNames_Static(); 486*cdf0e10cSrcweir // int i, nLength = aServices.length; 487*cdf0e10cSrcweir // for( i = 0; i < nLength; ++i ) 488*cdf0e10cSrcweir // { 489*cdf0e10cSrcweir // bResult = bResult && com.sun.star.comp.loader.FactoryHelper.writeRegistryServiceInfo( 490*cdf0e10cSrcweir // _aSvcImplName, aServices[i], xRegKey ); 491*cdf0e10cSrcweir // } 492*cdf0e10cSrcweir // return bResult; 493*cdf0e10cSrcweir // } 494*cdf0e10cSrcweir } 495*cdf0e10cSrcweir 496