1
package com.lddubeau.oowebdict.comp;
3
import java.net.MalformedURLException;
5
import com.lddubeau.ddb.BasicLexicon;
6
import com.lddubeau.ddb.CancelledByUser;
7
import com.lddubeau.oowebdict.comp.IndexImpl.ProgressGlue;
8
import com.sun.star.lang.XSingleComponentFactory;
9
import com.sun.star.lib.uno.helper.Factory;
10
import com.sun.star.lib.uno.helper.WeakBase;
11
import com.sun.star.registry.XRegistryKey;
12
import com.sun.star.uno.Exception;
13
import com.sun.star.uno.XComponentContext;
15
public final class BasicLexiconImpl extends WeakBase
17
com.sun.star.lang.XInitialization,
18
com.lddubeau.oowebdict.XBasicLexicon,
19
com.sun.star.lang.XServiceInfo
21
private final XComponentContext m_xContext;
23
private static final String m_implementationName = BasicLexiconImpl.class
26
protected static final String __serviceName = "com.lddubeau.oowebdict.BasicLexicon";
28
private BasicLexicon lexicon = null;
30
public BasicLexiconImpl(XComponentContext context)
35
public static XSingleComponentFactory __getComponentFactory(
36
String sImplementationName)
38
XSingleComponentFactory xFactory = null;
40
if (sImplementationName.equals(m_implementationName))
41
xFactory = Factory.createComponentFactory(BasicLexiconImpl.class,
42
new String[]{__serviceName});
46
public static boolean __writeRegistryServiceInfo(XRegistryKey xRegistryKey)
48
return Factory.writeRegistryServiceInfo(m_implementationName,
49
new String[]{__serviceName}, xRegistryKey);
52
// com.sun.star.lang.XInitialization:
53
public void initialize(Object [] aArguments)
54
throws com.sun.star.uno.Exception
58
String url = (String) aArguments[0];
59
this.lexicon = new BasicLexicon(url, new ProgressGlue(url));
61
catch (MalformedURLException ex)
63
throw new Exception("bad URL " + (String) aArguments[0] + " "
68
// com.lddubeau.oowebdict.XBasicLexicon:
69
public boolean exists(String term)
70
throws com.lddubeau.oowebdict.CancelledByUser
74
return this.lexicon.exists(term);
76
catch (CancelledByUser e)
78
throw new com.lddubeau.oowebdict.CancelledByUser();
82
public int getLongestTermLength()
83
throws com.lddubeau.oowebdict.CancelledByUser
87
return this.lexicon.getLongestTermLength();
89
catch (CancelledByUser e)
91
throw new com.lddubeau.oowebdict.CancelledByUser();
95
public String getTermData(String term)
96
throws com.lddubeau.oowebdict.CancelledByUser
100
String ret = this.lexicon.getTermData(term);
101
// By IDL requirements, we can't return null.
102
return (ret == null)?"":ret;
104
catch (CancelledByUser e)
106
throw new com.lddubeau.oowebdict.CancelledByUser();
110
// com.sun.star.lang.XServiceInfo:
111
public String getImplementationName()
113
return m_implementationName;
116
public boolean supportsService(String sService)
118
return sService.equals(__serviceName);
121
public String [] getSupportedServiceNames()
123
return new String[] {__serviceName};