dictUrls
= SpellCheckActivator.bundleContext.getBundle()
.findEntries(DEFAULT_DICT_PATH,
"*.zip",
false);
if (dictUrls != null)
{
while (dictUrls.hasMoreElements())
{
URL dictUrl = dictUrls.nextElement();
if (new File(dictUrl.getFile()).getName().equals(
new File(locale.getDictUrl().getFile()).getName()))
{
return true;
}
}
}
}
return false;
}
catch (Exception exc)
{
return false;
}
}
/**
* Determines if locale's dictionary is locally available or a system.
*
* @param locale locale to be checked
* @return true if local resources for dictionary are available and
* accessible, false otherwise
*/
boolean isUserLocale(Parameters.Locale locale)
{
try
{
return getLocalDictForLocale(locale).exists();
}
catch (Exception exc)
{
return false;
}
}
boolean isEnabled()
{
synchronized (this.attachedChats)
{
return enabled;
}
}
void setEnabled(boolean enabled)
{
if (this.enabled != enabled)
{
synchronized (this.attachedChats)
{
this.enabled = enabled;
for (ChatAttachments chatAttachment : this.attachedChats)
chatAttachment.setEnabled(this.enabled);
}
}
}
// copies dictionary to appropriate location, closing the stream afterward
private void copyDictionary(InputStream input, File dest)
throws IOException,
FileNotFoundException
{
byte[] buf = new byte[1024];
FileOutputStream output = new FileOutputStream(dest);
int len;
while ((len = input.read(buf)) > 0)
output.write(buf, 0, len);
input.close();
output.close();
}
/**
* Determines if spell checker dictionary works. Backend API often fails
* when used so this tests that the current dictionary is able to process
* words.
*
* @return true if current dictionary can check words, false otherwise
*/
private boolean isDictionaryValid(SpellDictionary dict)
{
try
{
// spell checker API often works until used
dict.isCorrect("foo");
return true;
}
catch (Exception exc)
{
logger.error("Dictionary validation failed", exc);
return false;
}
}
/**
* Adds a PropertyChangeListener to the listener list.
*
* @param listener the PropertyChangeListener to be added
*/
public void addPropertyChangeListener(PropertyChangeListener listener)
{
synchronized (propertyListeners)
{
Iterator> i
= propertyListeners.iterator();
boolean contains = false;
while (i.hasNext())
{
PropertyChangeListener l = i.next().get();
if (l == null)
i.remove();
else if (l.equals(listener))
contains = true;
}
if (!contains)
propertyListeners.add(
new WeakReference(listener));
}
}
/**
* Removes a PropertyChangeListener from the listener list.
*
* @param listener the PropertyChangeListener to be removed
*/
public void removePropertyChangeListener(PropertyChangeListener listener)
{
synchronized (propertyListeners)
{
Iterator> i
= propertyListeners.iterator();
while (i.hasNext())
{
PropertyChangeListener l = i.next().get();
if ((l == null) || l.equals(listener))
i.remove();
}
}
}
/**
* Fires event.
* @param property
* @param oldValue
* @param newValue
*/
private void firePropertyChangedEvent(String property,
Object oldValue,
Object newValue)
{
PropertyChangeEvent evt = new PropertyChangeEvent(
this, property, oldValue, newValue);
if (logger.isDebugEnabled())
logger.debug("Will dispatch the following plugin component event: "
+ evt);
synchronized (propertyListeners)
{
Iterator> i
= propertyListeners.iterator();
while (i.hasNext())
{
PropertyChangeListener l = i.next().get();
if (l == null)
i.remove();
else
{
l.propertyChange(evt);
}
}
}
}
}