This week I was working on extending the DownloadAction class to support the hyphenation dictionaries. For adding the support to download the hyphenation dictionary files as in Bug 1276588 I have modified the Download Action, Study Action and Base Action in DLC module.
We introduced the hyphenation dictionary as separate kind in Download Content. So the StudyAction class now can identify whether the content that is about to be downloaded is either a hyphenation-dictionary or a font. Previously the StudyAction which is responsible for determine the content that are in the catalog are fit to be downloaded by the application, was checking only for one kind of file - font. Now we planned on introducing a new method to determine whether the content to be downloaded is known.
public boolean isKnownContent() { return isFont() || isHyphenationDictionary(); }
The changes were made to the class Download Content. Few lines of unwanted code was removed from the Download Action class.
The major change to this patch was in the Base Action class.
File destinationDirectory;
if (content.isFont()) {
destinationDirectory = new File(context.getApplicationInfo().dataDir, "fonts");
} else if (content.isHyphenationDictionary()) {
destinationDirectory = new File(context.getApplicationInfo().dataDir, "hyphenation");
} else {
throw new UnrecoverableDownloadContentException("Can't determine destination for kind: " + content.getKind());
}
As shown in the above snippet, we are checking for the file’s kind and accordingly setting the destination path as either ‘fonts’ or ‘hyphenation’. The name of the data directory is chosen as hyphenation because the ‘Gecko’ already looks for the hyphenation-dictionary in the folder named ‘hyphenation’. So when we download the files and set its destination folder as ‘hyphenation’ it is automatically looked up and the hyphens are loaded as before.