diff options
Diffstat (limited to 'odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleSpellChecker.java')
-rw-r--r-- | odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleSpellChecker.java | 102 |
1 files changed, 51 insertions, 51 deletions
diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleSpellChecker.java b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleSpellChecker.java index 9e2cd5a81853..f63bc81af147 100644 --- a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleSpellChecker.java +++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleSpellChecker.java @@ -2,7 +2,7 @@ * * 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. * @@ -29,7 +29,7 @@ * 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 @@ -43,10 +43,10 @@ import com.sun.star.lang.XSingleServiceFactory; // supported Interfaces import com.sun.star.linguistic2.XSpellChecker; import com.sun.star.linguistic2.XLinguServiceEventBroadcaster; -import com.sun.star.lang.XInitialization; +import com.sun.star.lang.XInitialization; import com.sun.star.lang.XComponent; -import com.sun.star.lang.XServiceInfo; -import com.sun.star.lang.XServiceDisplayName; +import com.sun.star.lang.XServiceInfo; +import com.sun.star.lang.XServiceDisplayName; // Exceptions import com.sun.star.uno.Exception; @@ -101,10 +101,10 @@ public class SampleSpellChecker extends ComponentBase implements { return aLoc1.Language.equals( aLoc2.Language ) && aLoc1.Country .equals( aLoc2.Country ) && - aLoc1.Variant .equals( aLoc2.Variant ); + aLoc1.Variant .equals( aLoc2.Variant ); } - private boolean GetValueToUse( + private boolean GetValueToUse( String aPropName, boolean bDefaultVal, PropertyValue[] aProps ) @@ -139,13 +139,13 @@ public class SampleSpellChecker extends ComponentBase implements catch (Exception e) { bRes = bDefaultVal; } - + return bRes; } private boolean IsUpper( String aWord, Locale aLocale ) { - java.util.Locale aLang = new java.util.Locale( + java.util.Locale aLang = new java.util.Locale( aLocale.Language, aLocale.Country, aLocale.Variant ); return aWord.equals( aWord.toUpperCase( aLang ) ); } @@ -161,14 +161,14 @@ public class SampleSpellChecker extends ComponentBase implements return false; } - private short GetSpellFailure( - String aWord, + private short GetSpellFailure( + String aWord, Locale aLocale, - PropertyValue[] aProperties ) + PropertyValue[] aProperties ) { short nRes = -1; - //!! This code needs to be replaced by code calling the actual + //!! 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", "" ) )) @@ -188,23 +188,23 @@ public class SampleSpellChecker extends ComponentBase implements { // 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 ) + private XSpellAlternatives GetProposals( + String aWord, + Locale aLocale, + PropertyValue[] aProperties ) { short nType = SpellFailure.SPELLING_ERROR; String[] aProposals = null; @@ -218,7 +218,7 @@ public class SampleSpellChecker extends ComponentBase implements boolean bIsSpellUpperCase = GetValueToUse( "IsSpellUpperCase", false, aProperties ); boolean bIsSpellCapitalization = GetValueToUse( "IsSpellCapitalization", true, aProperties ); - //!! This code needs to be replaced by code calling the actual + //!! This code needs to be replaced by code calling the actual //!! implementation of your spellchecker if (IsEqual( aLocale, new Locale( "de", "DE", "" ) )) { @@ -257,17 +257,17 @@ public class SampleSpellChecker extends ComponentBase implements return new XSpellAlternatives_impl( aWord, aLocale, nType, aProposals ); } - + // __________ interface methods __________ - - + + //***************** //XSupportedLocales //***************** public Locale[] getLocales() throws com.sun.star.uno.RuntimeException { - Locale aLocales[] = + Locale aLocales[] = { new Locale( "de", "DE", "" ), new Locale( "en", "US", "" ) @@ -275,30 +275,30 @@ public class SampleSpellChecker extends ComponentBase implements return aLocales; } - - public boolean hasLocale( Locale aLocale ) + + 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; + return bRes; } - + //************* //XSpellChecker //************* public boolean isValid( String aWord, Locale aLocale, - PropertyValue[] aProperties ) + 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 )) @@ -312,7 +312,7 @@ public class SampleSpellChecker extends ComponentBase implements 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) { @@ -327,22 +327,22 @@ public class SampleSpellChecker extends ComponentBase implements return nFailure == -1; } - - + + public XSpellAlternatives spell( String aWord, Locale aLocale, - PropertyValue[] aProperties ) + 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 )) { @@ -350,8 +350,8 @@ public class SampleSpellChecker extends ComponentBase implements } return xRes; } - - + + //***************************** //XLinguServiceEventBroadcaster //***************************** @@ -359,35 +359,35 @@ public class SampleSpellChecker extends ComponentBase implements XLinguServiceEventListener xLstnr ) throws com.sun.star.uno.RuntimeException { - boolean bRes = false; + boolean bRes = false; if (!bDisposing && xLstnr != null) bRes = aPropChgHelper.addLinguServiceEventListener( xLstnr ); return bRes; } - + public boolean removeLinguServiceEventListener( - XLinguServiceEventListener xLstnr ) + XLinguServiceEventListener xLstnr ) throws com.sun.star.uno.RuntimeException { - boolean bRes = false; + boolean bRes = false; if (!bDisposing && xLstnr != null) bRes = aPropChgHelper.removeLinguServiceEventListener( xLstnr ); return bRes; - } + } //******************** // XServiceDisplayName //******************** - public String getServiceDisplayName( Locale aLocale ) + public String getServiceDisplayName( Locale aLocale ) throws com.sun.star.uno.RuntimeException { - return "Java Samples"; + return "Java Samples"; } //**************** // XInitialization //**************** - public void initialize( Object[] aArguments ) + public void initialize( Object[] aArguments ) throws com.sun.star.uno.Exception, com.sun.star.uno.RuntimeException { @@ -422,17 +422,17 @@ public class SampleSpellChecker extends ComponentBase implements { return _aSvcImplName; } - + public String[] getSupportedServiceNames() throws com.sun.star.uno.RuntimeException { return getSupportedServiceNames_Static(); } - + // __________ static things __________ public static String _aSvcImplName = "com.sun.star.linguistic2.JavaSamples.SampleSpellChecker"; - + public static String[] getSupportedServiceNames_Static() { String[] aResult = { "com.sun.star.linguistic2.SpellChecker" }; @@ -474,7 +474,7 @@ public class SampleSpellChecker extends ComponentBase implements * @param xRegKey the registryKey * @see com.sun.star.comp.loader.JavaLoader */ - public static boolean __writeRegistryServiceInfo( + public static boolean __writeRegistryServiceInfo( com.sun.star.registry.XRegistryKey xRegKey ) { boolean bResult = true; |