private Properties readComponentProperties(IComponent component, Locale locale, Resource propertiesResource, Properties parent) { String encoding = getComponentMessagesEncoding(component, locale); return readPropertiesResource(propertiesResource.getResourceURL(), encoding, parent); }
private Properties readNamespaceProperties(INamespace namespace, Locale locale, Resource propertiesResource, Properties parent) { String encoding = getNamespaceMessagesEncoding(namespace, locale); return readPropertiesResource(propertiesResource.getResourceURL(), encoding, parent); }
private Properties assembleComponentProperties(IComponent component, Resource baseResourceLocation, Map propertiesMap, Locale locale) List localizations = findLocalizationsForResource(component, baseResourceLocation, locale, component.getSpecification().getProperty(NAMESPACE_PROPERTIES_NAME)); Properties namespaceProperties = getNamespaceProperties(component, l); Properties properties = readComponentProperties(component, l, rl.getResource(), null);
private Properties assembleNamespaceProperties(INamespace namespace, Map propertiesMap, Locale locale) { List localizations = findLocalizationsForResource(namespace.getSpecificationLocation(), locale, namespace.getPropertyValue(NAMESPACE_PROPERTIES_NAME)); // Build them back up in reverse order. Properties parent = _emptyProperties; Iterator i = localizations.iterator(); while(i.hasNext()) { ResourceLocalization rl = (ResourceLocalization) i.next(); Locale l = rl.getLocale(); Properties properties = (Properties) propertiesMap.get(l); if (properties == null) { properties = readNamespaceProperties(namespace, l, rl.getResource(), parent); propertiesMap.put(l, properties); } parent = properties; } return parent; }
/** * Returns an instance of {@link Properties} containing the properly * localized messages for the component, in the {@link Locale} identified by * the component's containing page. * * @param component * The component to get properties for. * * @return A new {@link Properties} instance representing the localized properties for * the specified component. */ protected Properties getLocalizedProperties(IComponent component) { Defense.notNull(component, "component"); Resource specificationLocation = component.getSpecification().getSpecificationLocation(); Locale locale = component.getPage().getLocale(); Map propertiesMap = findPropertiesMapForResource(specificationLocation); Properties result = (Properties) propertiesMap.get(locale); if (result == null) { // Not found, create it now. result = assembleComponentProperties(component, specificationLocation, propertiesMap, locale); propertiesMap.put(locale, result); } return result; }
private Properties getNamespaceProperties(IComponent component, Locale locale) { INamespace namespace = component.getNamespace(); Resource namespaceLocation = namespace.getSpecificationLocation(); Map propertiesMap = findPropertiesMapForResource(namespaceLocation); Properties result = (Properties) propertiesMap.get(locale); if (result == null) { result = new Properties(); // recurse through parent properties List spaceList = new ArrayList(); spaceList.add(namespace); INamespace parent = namespace; while (parent.getParentNamespace() != null) { parent = parent.getParentNamespace(); spaceList.add(parent); } // reverse it so top most namespace comes first for (int i=spaceList.size() - 1; i > -1; i--) { INamespace space = (INamespace)spaceList.get(i); result.putAll(assembleNamespaceProperties(space, findPropertiesMapForResource(space.getSpecificationLocation()), locale)); } propertiesMap.put(locale, result); } return result; }
private List findLocalizationsForResource(IComponent component, Resource resource, Locale locale, String alternateName) { List result = new ArrayList(); String baseName = null; if (alternateName != null) { baseName = alternateName.replace('.', '/'); } else { baseName = extractBaseName(resource); } LocalizedNameGenerator g = new LocalizedNameGenerator(baseName, locale, ""); while(g.more()) { String localizedName = g.next(); Locale l = g.getCurrentLocale(); Resource localizedResource = _resourceResolver.findComponentResource(component, null, localizedName, SUFFIX, null); if (localizedResource == null) continue; result.add(new ResourceLocalization(l, localizedResource)); } Collections.reverse(result); return result; }
public Messages getMessages(IComponent component) { return new ComponentMessages(component.getPage().getLocale(), getLocalizedProperties(component)); }
private Properties assembleComponentProperties(IComponent component, Resource baseResourceLocation, Map propertiesMap, Locale locale) List localizations = findLocalizationsForResource(component, baseResourceLocation, locale, component.getSpecification().getProperty(NAMESPACE_PROPERTIES_NAME)); Properties namespaceProperties = getNamespaceProperties(component, l); Properties properties = readComponentProperties(component, l, rl.getResource(), null);
private Properties assembleNamespaceProperties(INamespace namespace, Map propertiesMap, Locale locale) { List localizations = findLocalizationsForResource(namespace.getSpecificationLocation(), locale, namespace.getPropertyValue(NAMESPACE_PROPERTIES_NAME)); // Build them back up in reverse order. Properties parent = _emptyProperties; Iterator i = localizations.iterator(); while(i.hasNext()) { ResourceLocalization rl = (ResourceLocalization) i.next(); Locale l = rl.getLocale(); Properties properties = (Properties) propertiesMap.get(l); if (properties == null) { properties = readNamespaceProperties(namespace, l, rl.getResource(), parent); propertiesMap.put(l, properties); } parent = properties; } return parent; }
/** * Returns an instance of {@link Properties} containing the properly * localized messages for the component, in the {@link Locale} identified by * the component's containing page. * * @param component * The component to get properties for. * * @return A new {@link Properties} instance representing the localized properties for * the specified component. */ protected Properties getLocalizedProperties(IComponent component) { Defense.notNull(component, "component"); Resource specificationLocation = component.getSpecification().getSpecificationLocation(); Locale locale = component.getPage().getLocale(); Map propertiesMap = findPropertiesMapForResource(specificationLocation); Properties result = (Properties) propertiesMap.get(locale); if (result == null) { // Not found, create it now. result = assembleComponentProperties(component, specificationLocation, propertiesMap, locale); propertiesMap.put(locale, result); } return result; }
private Properties getNamespaceProperties(IComponent component, Locale locale) { INamespace namespace = component.getNamespace(); Resource namespaceLocation = namespace.getSpecificationLocation(); Map propertiesMap = findPropertiesMapForResource(namespaceLocation); Properties result = (Properties) propertiesMap.get(locale); if (result == null) { result = new Properties(); // recurse through parent properties List spaceList = new ArrayList(); spaceList.add(namespace); INamespace parent = namespace; while (parent.getParentNamespace() != null) { parent = parent.getParentNamespace(); spaceList.add(parent); } // reverse it so top most namespace comes first for (int i=spaceList.size() - 1; i > -1; i--) { INamespace space = (INamespace)spaceList.get(i); result.putAll(assembleNamespaceProperties(space, findPropertiesMapForResource(space.getSpecificationLocation()), locale)); } propertiesMap.put(locale, result); } return result; }
private List findLocalizationsForResource(IComponent component, Resource resource, Locale locale, String alternateName) { List result = new ArrayList(); String baseName = null; if (alternateName != null) { baseName = alternateName.replace('.', '/'); } else { baseName = extractBaseName(resource); } LocalizedNameGenerator g = new LocalizedNameGenerator(baseName, locale, ""); while(g.more()) { String localizedName = g.next(); Locale l = g.getCurrentLocale(); Resource localizedResource = _resourceResolver.findComponentResource(component, null, localizedName, SUFFIX, null); if (localizedResource == null) continue; result.add(new ResourceLocalization(l, localizedResource)); } Collections.reverse(result); return result; }
public Messages getMessages(IComponent component) { return new ComponentMessages(component.getPage().getLocale(), getLocalizedProperties(component)); }
private Properties readNamespaceProperties(INamespace namespace, Locale locale, Resource propertiesResource, Properties parent) { String encoding = getNamespaceMessagesEncoding(namespace, locale); return readPropertiesResource(propertiesResource.getResourceURL(), encoding, parent); }
private Properties readComponentProperties(IComponent component, Locale locale, Resource propertiesResource, Properties parent) { String encoding = getComponentMessagesEncoding(component, locale); return readPropertiesResource(propertiesResource.getResourceURL(), encoding, parent); }
/** * Finds the localizations of the provided resource. Returns a List of * {@link ResourceLocalization}(each pairing a locale with a localized * resource). The list is ordered from most general (i.e., "foo.properties") * to most specific (i.e., "foo_en_US_yokel.properties"). */ private List findLocalizationsForResource(Resource resource, Locale locale, String alternateName) { List result = new ArrayList(); String baseName = null; if (alternateName != null) { baseName = alternateName.replace('.', '/'); } else { baseName = extractBaseName(resource); } LocalizedNameGenerator g = new LocalizedNameGenerator(baseName, locale, SUFFIX); while(g.more()) { String localizedName = g.next(); Locale l = g.getCurrentLocale(); Resource localizedResource = resource.getRelativeResource(localizedName); if (localizedResource.getResourceURL() == null) { localizedResource = _classpathResourceFactory.newResource(baseName + SUFFIX); } result.add(new ResourceLocalization(l, localizedResource)); } Collections.reverse(result); return result; }
/** * Finds the localizations of the provided resource. Returns a List of * {@link ResourceLocalization}(each pairing a locale with a localized * resource). The list is ordered from most general (i.e., "foo.properties") * to most specific (i.e., "foo_en_US_yokel.properties"). */ private List findLocalizationsForResource(Resource resource, Locale locale, String alternateName) { List result = new ArrayList(); String baseName = null; if (alternateName != null) { baseName = alternateName.replace('.', '/'); } else { baseName = extractBaseName(resource); } LocalizedNameGenerator g = new LocalizedNameGenerator(baseName, locale, SUFFIX); while(g.more()) { String localizedName = g.next(); Locale l = g.getCurrentLocale(); Resource localizedResource = resource.getRelativeResource(localizedName); if (localizedResource.getResourceURL() == null) { localizedResource = _classpathResourceFactory.newResource(baseName + SUFFIX); } result.add(new ResourceLocalization(l, localizedResource)); } Collections.reverse(result); return result; }