SampleThesaurus.java (34dd1e25) SampleThesaurus.java (be8bac39)
1/**************************************************************
1/**************************************************************
2 *
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
19 *
20 *************************************************************/
21
22
23
24// uno
25import com.sun.star.lib.uno.helper.ComponentBase;
26import com.sun.star.uno.UnoRuntime;
27
28// factories
29import com.sun.star.lang.XMultiServiceFactory;
30import com.sun.star.lang.XSingleServiceFactory;
31
32// supported Interfaces
33import com.sun.star.linguistic2.XThesaurus;
20 *************************************************************/
21
22
23
24// uno
25import com.sun.star.lib.uno.helper.ComponentBase;
26import com.sun.star.uno.UnoRuntime;
27
28// factories
29import com.sun.star.lang.XMultiServiceFactory;
30import com.sun.star.lang.XSingleServiceFactory;
31
32// supported Interfaces
33import com.sun.star.linguistic2.XThesaurus;
34import com.sun.star.lang.XInitialization;
34import com.sun.star.lang.XInitialization;
35import com.sun.star.lang.XComponent;
35import com.sun.star.lang.XComponent;
36import com.sun.star.lang.XServiceInfo;
37import com.sun.star.lang.XServiceDisplayName;
36import com.sun.star.lang.XServiceInfo;
37import com.sun.star.lang.XServiceDisplayName;
38
39// Exceptions
40import com.sun.star.uno.Exception;
41import com.sun.star.uno.RuntimeException;
42import com.sun.star.lang.IllegalArgumentException;
43
44//used Interfaces
45import com.sun.star.linguistic2.XMeaning;

--- 12 unchanged lines hidden (view full) ---

58 XThesaurus,
59 XInitialization,
60 XServiceDisplayName,
61 XServiceInfo
62{
63 PropChgHelper aPropChgHelper;
64 ArrayList aEvtListeners;
65 boolean bDisposing;
38
39// Exceptions
40import com.sun.star.uno.Exception;
41import com.sun.star.uno.RuntimeException;
42import com.sun.star.lang.IllegalArgumentException;
43
44//used Interfaces
45import com.sun.star.linguistic2.XMeaning;

--- 12 unchanged lines hidden (view full) ---

58 XThesaurus,
59 XInitialization,
60 XServiceDisplayName,
61 XServiceInfo
62{
63 PropChgHelper aPropChgHelper;
64 ArrayList aEvtListeners;
65 boolean bDisposing;
66
66
67 public SampleThesaurus()
68 {
69 // names of relevant properties to be used
70 String[] aProps = new String[]
71 {
72 "IsIgnoreControlCharacters",
73 "IsUseDictionaryList",
74 "IsGermanPreReform",
75 };
67 public SampleThesaurus()
68 {
69 // names of relevant properties to be used
70 String[] aProps = new String[]
71 {
72 "IsIgnoreControlCharacters",
73 "IsUseDictionaryList",
74 "IsGermanPreReform",
75 };
76
76
77 // this service has no listeners thus we may use the base class,
77 // this service has no listeners thus we may use the base class,
78 // which is here basically used only to keep track of the
78 // which is here basically used only to keep track of the
79 // property set (and it's lifetime) since it gets used in the
80 // 'GetValueToUse' function
79 // property set (and it's lifetime) since it gets used in the
80 // 'GetValueToUse' function
81 aPropChgHelper = new PropChgHelper( (XThesaurus) this, aProps );
82
83 aEvtListeners = new ArrayList();
84 bDisposing = false;
81 aPropChgHelper = new PropChgHelper( (XThesaurus) this, aProps );
82
83 aEvtListeners = new ArrayList();
84 bDisposing = false;
85 }
86
87 private boolean IsEqual( Locale aLoc1, Locale aLoc2 )
88 {
89 return aLoc1.Language.equals( aLoc2.Language ) &&
85 }
86
87 private boolean IsEqual( Locale aLoc1, Locale aLoc2 )
88 {
89 return aLoc1.Language.equals( aLoc2.Language ) &&
90 aLoc1.Country .equals( aLoc2.Country ) &&
91 aLoc1.Variant .equals( aLoc2.Variant );
90 aLoc1.Country .equals( aLoc2.Country ) &&
91 aLoc1.Variant .equals( aLoc2.Variant );
92 }
93
92 }
93
94 private boolean GetValueToUse(
94 private boolean GetValueToUse(
95 String aPropName,
96 boolean bDefaultVal,
97 PropertyValue[] aProps )
98 {
99 boolean bRes = bDefaultVal;
100
101 try
102 {
103 // use temporary value if supplied
95 String aPropName,
96 boolean bDefaultVal,
97 PropertyValue[] aProps )
98 {
99 boolean bRes = bDefaultVal;
100
101 try
102 {
103 // use temporary value if supplied
104 for (int i = 0; i < aProps.length; ++i)
104 for (int i = 0; i < aProps.length; ++i)
105 {
106 if (aPropName.equals( aProps[i].Name ))
107 {
108 Object aObj = aProps[i].Value;
109 if (AnyConverter.isBoolean( aObj ))
110 {
111 bRes = AnyConverter.toBoolean( aObj );
112 return bRes;
113 }
114 }
115 }
116
117 // otherwise use value from property set (if available)
118 XPropertySet xPropSet = aPropChgHelper.GetPropSet();
105 {
106 if (aPropName.equals( aProps[i].Name ))
107 {
108 Object aObj = aProps[i].Value;
109 if (AnyConverter.isBoolean( aObj ))
110 {
111 bRes = AnyConverter.toBoolean( aObj );
112 return bRes;
113 }
114 }
115 }
116
117 // otherwise use value from property set (if available)
118 XPropertySet xPropSet = aPropChgHelper.GetPropSet();
119 if (xPropSet != null) // should always be the case
119 if (xPropSet != null) // should always be the case
120 {
121 Object aObj = xPropSet.getPropertyValue( aPropName );
122 if (AnyConverter.isBoolean( aObj ))
123 bRes = AnyConverter.toBoolean( aObj );
124 }
125 }
126 catch (Exception e) {
127 bRes = bDefaultVal;
128 }
120 {
121 Object aObj = xPropSet.getPropertyValue( aPropName );
122 if (AnyConverter.isBoolean( aObj ))
123 bRes = AnyConverter.toBoolean( aObj );
124 }
125 }
126 catch (Exception e) {
127 bRes = bDefaultVal;
128 }
129
129
130 return bRes;
131 }
130 return bRes;
131 }
132
132
133 // __________ interface methods __________
133 // __________ interface methods __________
134
135
134
135
136 //*****************
137 //XSupportedLocales
138 //*****************
139 public Locale[] getLocales()
140 throws com.sun.star.uno.RuntimeException
141 {
136 //*****************
137 //XSupportedLocales
138 //*****************
139 public Locale[] getLocales()
140 throws com.sun.star.uno.RuntimeException
141 {
142 Locale aLocales[] =
142 Locale aLocales[] =
143 {
144 new Locale( "en", "US", "" )
145 };
146
147 return aLocales;
148 }
143 {
144 new Locale( "en", "US", "" )
145 };
146
147 return aLocales;
148 }
149
150 public boolean hasLocale( Locale aLocale )
149
150 public boolean hasLocale( Locale aLocale )
151 throws com.sun.star.uno.RuntimeException
152 {
153 boolean bRes = false;
154 if (IsEqual( aLocale, new Locale( "en", "US", "" ) ))
155 bRes = true;
151 throws com.sun.star.uno.RuntimeException
152 {
153 boolean bRes = false;
154 if (IsEqual( aLocale, new Locale( "en", "US", "" ) ))
155 bRes = true;
156 return bRes;
156 return bRes;
157 }
157 }
158
158
159 //**********
160 //XThesaurus
161 //**********
159 //**********
160 //XThesaurus
161 //**********
162 public XMeaning[] queryMeanings(
162 public XMeaning[] queryMeanings(
163 String aTerm, Locale aLocale,
164 PropertyValue[] aProperties )
165 throws com.sun.star.lang.IllegalArgumentException,
166 com.sun.star.uno.RuntimeException
167 {
168 if (IsEqual( aLocale, new Locale() ) || aTerm.length() == 0)
169 return null;
163 String aTerm, Locale aLocale,
164 PropertyValue[] aProperties )
165 throws com.sun.star.lang.IllegalArgumentException,
166 com.sun.star.uno.RuntimeException
167 {
168 if (IsEqual( aLocale, new Locale() ) || aTerm.length() == 0)
169 return null;
170
170
171 // linguistic is currently not allowed to throw exceptions
171 // linguistic is currently not allowed to throw exceptions
172 // thus we return null fwhich means 'word cannot be looked up'
172 // thus we return null which means 'word cannot be looked up'
173 if (!hasLocale( aLocale ))
174 return null;
175
176 // get values of relevant properties that may be used.
177 //! The values for 'IsIgnoreControlCharacters' and 'IsUseDictionaryList'
178 //! are handled by the dispatcher! Thus there is no need to access
179 //! them here.
173 if (!hasLocale( aLocale ))
174 return null;
175
176 // get values of relevant properties that may be used.
177 //! The values for 'IsIgnoreControlCharacters' and 'IsUseDictionaryList'
178 //! are handled by the dispatcher! Thus there is no need to access
179 //! them here.
180 boolean bIsGermanPreReform = GetValueToUse( "IsGermanPreReform", false, aProperties );
180 boolean bIsGermanPreReform = GetValueToUse( "IsGermanPreReform", false, aProperties );
181
182 XMeaning[] aRes = null;
183
181
182 XMeaning[] aRes = null;
183
184 //!! This code needs to be replaced by code calling the actual
184 //!! This code needs to be replaced by code calling the actual
185 //!! implementation of your thesaurus
186 if (aTerm.equals( "house" ) &&
187 IsEqual( aLocale, new Locale( "en", "US", "" ) ) )
188 {
189 aRes = new XMeaning[]
190 {
185 //!! implementation of your thesaurus
186 if (aTerm.equals( "house" ) &&
187 IsEqual( aLocale, new Locale( "en", "US", "" ) ) )
188 {
189 aRes = new XMeaning[]
190 {
191 new XMeaning_impl( "a building where one lives",
191 new XMeaning_impl( "a building where one lives",
192 new String[]{ "home", "place", "dwelling" } ),
192 new String[]{ "home", "place", "dwelling" } ),
193 new XMeaning_impl( "a group of people sharing common ancestry",
193 new XMeaning_impl( "a group of people sharing common ancestry",
194 new String[]{ "family", "clan", "kindred" } ),
194 new String[]{ "family", "clan", "kindred" } ),
195 new XMeaning_impl( "to provide with lodging",
195 new XMeaning_impl( "to provide with lodging",
196 new String[]{ "room", "board", "put up" } )
197 };
198 }
199
200 return aRes;
201 }
196 new String[]{ "room", "board", "put up" } )
197 };
198 }
199
200 return aRes;
201 }
202
203
202
203
204 //********************
205 // XServiceDisplayName
206 //********************
204 //********************
205 // XServiceDisplayName
206 //********************
207 public String getServiceDisplayName( Locale aLocale )
207 public String getServiceDisplayName( Locale aLocale )
208 throws com.sun.star.uno.RuntimeException
209 {
208 throws com.sun.star.uno.RuntimeException
209 {
210 return "Java Samples";
210 return "Java Samples";
211 }
212
213 //****************
214 // XInitialization
215 //****************
211 }
212
213 //****************
214 // XInitialization
215 //****************
216 public void initialize( Object[] aArguments )
216 public void initialize( Object[] aArguments )
217 throws com.sun.star.uno.Exception,
218 com.sun.star.uno.RuntimeException
219 {
220 int nLen = aArguments.length;
221 if (2 == nLen)
222 {
223 XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface(
224 XPropertySet.class, aArguments[0]);

--- 18 unchanged lines hidden (view full) ---

243 return bResult;
244 }
245
246 public String getImplementationName()
247 throws com.sun.star.uno.RuntimeException
248 {
249 return _aSvcImplName;
250 }
217 throws com.sun.star.uno.Exception,
218 com.sun.star.uno.RuntimeException
219 {
220 int nLen = aArguments.length;
221 if (2 == nLen)
222 {
223 XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface(
224 XPropertySet.class, aArguments[0]);

--- 18 unchanged lines hidden (view full) ---

243 return bResult;
244 }
245
246 public String getImplementationName()
247 throws com.sun.star.uno.RuntimeException
248 {
249 return _aSvcImplName;
250 }
251
251
252 public String[] getSupportedServiceNames()
253 throws com.sun.star.uno.RuntimeException
254 {
255 return getSupportedServiceNames_Static();
256 }
252 public String[] getSupportedServiceNames()
253 throws com.sun.star.uno.RuntimeException
254 {
255 return getSupportedServiceNames_Static();
256 }
257
257
258 // __________ static things __________
259
260 public static String _aSvcImplName = SampleThesaurus.class.getName();
258 // __________ static things __________
259
260 public static String _aSvcImplName = SampleThesaurus.class.getName();
261
261
262 public static String[] getSupportedServiceNames_Static()
263 {
264 String[] aResult = { "com.sun.star.linguistic2.Thesaurus" };
265 return aResult;
266 }
267
268
269 /**

--- 27 unchanged lines hidden (view full) ---

297 * This method is called by the <code>JavaLoader</code>
298 * <p>
299 * @return returns true if the operation succeeded
300 * @param xRegKey the registryKey
301 * @see com.sun.star.comp.loader.JavaLoader
302 */
303 // This method not longer necessary since OOo 3.4 where the component registration
304 // was changed to passive component registration. For more details see
262 public static String[] getSupportedServiceNames_Static()
263 {
264 String[] aResult = { "com.sun.star.linguistic2.Thesaurus" };
265 return aResult;
266 }
267
268
269 /**

--- 27 unchanged lines hidden (view full) ---

297 * This method is called by the <code>JavaLoader</code>
298 * <p>
299 * @return returns true if the operation succeeded
300 * @param xRegKey the registryKey
301 * @see com.sun.star.comp.loader.JavaLoader
302 */
303 // This method not longer necessary since OOo 3.4 where the component registration
304 // was changed to passive component registration. For more details see
305 // http://wiki.services.openoffice.org/wiki/Passive_Component_Registration
305 // https://wiki.openoffice.org/wiki/Passive_Component_Registration
306
306
307// public static boolean __writeRegistryServiceInfo(
307// public static boolean __writeRegistryServiceInfo(
308// com.sun.star.registry.XRegistryKey xRegKey )
309// {
310// boolean bResult = true;
311// String[] aServices = getSupportedServiceNames_Static();
312// int i, nLength = aServices.length;
313// for( i = 0; i < nLength; ++i )
314// {
315// bResult = bResult && com.sun.star.comp.loader.FactoryHelper.writeRegistryServiceInfo(
316// _aSvcImplName, aServices[i], xRegKey );
317// }
318// return bResult;
319// }
320}
321
308// com.sun.star.registry.XRegistryKey xRegKey )
309// {
310// boolean bResult = true;
311// String[] aServices = getSupportedServiceNames_Static();
312// int i, nLength = aServices.length;
313// for( i = 0; i < nLength; ++i )
314// {
315// bResult = bResult && com.sun.star.comp.loader.FactoryHelper.writeRegistryServiceInfo(
316// _aSvcImplName, aServices[i], xRegKey );
317// }
318// return bResult;
319// }
320}
321