String furnitureResourcesLocalDirectory = preferences.getFurnitureResourcesLocalDirectory();
URL furnitureResourcesUrlBase = furnitureResourcesLocalDirectory != null
? new File(furnitureResourcesLocalDirectory).toURI().toURL()
: null;
final List<CatalogPieceOfFurniture> furniture = new ArrayList<CatalogPieceOfFurniture>();
new DefaultFurnitureCatalog(new URL [] {furnitureLibraryUrl}, furnitureResourcesUrlBase) {
@Override
protected CatalogPieceOfFurniture readPieceOfFurniture(ResourceBundle resource,
int index,
URL furnitureCatalogUrl,
URL furnitureResourcesUrlBase) {
if (index == 1) {
furnitureLibrary.setDescription(getOptionalString(resource, DESCRIPTION));
furnitureLibrary.setVersion(getOptionalString(resource, VERSION));
furnitureLibrary.setLicense(getOptionalString(resource, LICENSE));
furnitureLibrary.setProvider(getOptionalString(resource, PROVIDER));
}
CatalogPieceOfFurniture piece = super.readPieceOfFurniture(resource, index, furnitureCatalogUrl, furnitureResourcesUrlBase);
if (piece != null) {
// Set furniture category through dummy catalog
FurnitureCategory category = super.readFurnitureCategory(resource, index);
new FurnitureCatalog() { }.add(category, piece);
furniture.add(piece);
}
return piece;
}
private String getOptionalString(ResourceBundle resource, String propertyKey) {
try {
return resource.getString(propertyKey);
} catch (MissingResourceException ex) {
return null;
}
}
};
// Search which locales are supported
List<ZipEntry> zipEntries = getZipEntries(furnitureLibraryUrl);
Set<Locale> supportedLocales = new HashSet<Locale>();
for (ZipEntry zipEntry : zipEntries) {
String entryName = zipEntry.getName();
if (entryName.startsWith(DefaultFurnitureCatalog.PLUGIN_FURNITURE_CATALOG_FAMILY)
&& entryName.endsWith(".properties")) {
supportedLocales.add(getLocale(entryName));
}
}
// Replace furniture by the one read
for (CatalogPieceOfFurniture piece : furnitureLibrary.getFurniture()) {
furnitureLibrary.deletePieceOfFurniture(piece);
}
for (CatalogPieceOfFurniture piece : furniture) {
furnitureLibrary.addPieceOfFurniture(piece);
}
// Get furniture name and category name in each supported locale
for (Locale locale : supportedLocales) {
if (!FurnitureLibrary.DEFAULT_LANGUAGE.equals(locale.toString())) {
Locale.setDefault(locale);
final String language = locale.toString();
new DefaultFurnitureCatalog(new URL [] {furnitureLibraryUrl}, furnitureResourcesUrlBase) {
@Override
protected CatalogPieceOfFurniture readPieceOfFurniture(ResourceBundle resource,
int index,
URL furnitureCatalogUrl,
URL furnitureResourcesUrlBase) {