Example usage for org.apache.wicket.resource Properties getString

List of usage examples for org.apache.wicket.resource Properties getString

Introduction

In this page you can find the example usage for org.apache.wicket.resource Properties getString.

Prototype

public final String getString(final String key) 

Source Link

Document

Get the property value identified by its 'key'.

Usage

From source file:org.geoserver.web.GeoServerStringResourceLoader.java

License:Open Source License

/**
 * Get the string resource for the given combination of class, key, locale and style. The
 * information is obtained from a resource bundle associated with the provided Class (or one of
 * its super classes).//from w  w  w .  j  a v  a 2s  .  c om
 * 
 * @param clazz
 *            The Class to find resources to be loaded (might be null if we want a context-less search)
 * @param key
 *            The key to obtain the string for
 * @param locale
 *            The locale identifying the resource set to select the strings from
 * @param style
 *            The (optional) style identifying the resource set to select the strings from (see
 *            {@link org.apache.wicket.Session})
 * @return The string resource value or null if resource not found
 */
public String loadStringResource(Class clazz, final String key, final Locale locale, final String style) {
    // Load the properties associated with the path
    IPropertiesFactory propertiesFactory = Application.get().getResourceSettings().getPropertiesFactory();

    // All GeoServer releated resources are loaded into a GeoServerApplication*.properties file
    String path = "/GeoServerApplication";
    while (true) {
        // Iterator over all the combinations
        ResourceNameIterator iter = new ResourceNameIterator(path, style, locale, ",properties,xml");
        while (iter.hasNext()) {
            String newPath = (String) iter.next();

            final Properties props = propertiesFactory.load(clazz, newPath);
            if (props != null) {
                // Lookup the qualified key
                String qualifiedKey = clazz != null ? clazz.getSimpleName() + "." + key : key;
                String value = props.getString(qualifiedKey);
                if (value != null)
                    return value;
            }
        }

        // Didn't find the key yet, continue searching if possible
        if (isStopResourceSearch(clazz)) {
            break;
        }

        // Move to the next superclass
        clazz = clazz.getSuperclass();

        if (clazz == null) {
            // nothing more to search, done
            break;
        }
    }

    // not found
    return null;
}

From source file:org.hippoecm.frontend.editor.layout.XmlLayoutDescriptor.java

License:Apache License

/**
 * Determine the name by use of properties files.  The lookup procedure uses the
 * variant properties file, if available, falling back to the no-variant 
 * <code>location + ".properties"</code> file.  The key that is used is the name
 * of the layout (i.e. the last part of its location path), initially tried with
 * the variant appended and falling back to the using the name itself as key if
 * this fails.  Finally, if no properties files are found, the name is returned.
 *//*  w w  w.  j av  a2s. c o m*/
public IModel<String> getName() {
    return new LoadableDetachableModel<String>() {
        private static final long serialVersionUID = 1L;

        @Override
        protected String load() {
            // Load the properties associated with the path
            IPropertiesFactory propertiesFactory = Application.get().getResourceSettings()
                    .getPropertiesFactory();

            Locale locale = Session.get().getLocale();
            String name = location.substring(location.lastIndexOf('/') + 1);
            ResourceNameIterator iterator = new ResourceNameIterator(location, null, variant, locale, null,
                    false);
            while (iterator.hasNext()) {
                String path = iterator.next();
                final Properties props = propertiesFactory.load(null, path);
                if (props != null) {
                    if (variant != null) {
                        // Lookup the value
                        String value = props.getString(name + "_" + variant);
                        if (value != null) {
                            return value;
                        }
                    }
                    String value = props.getString(name);
                    if (value != null) {
                        return value;
                    }
                }
            }
            return name;
        }

    };
}

From source file:org.wicketstuff.extjs.util.ExtConfigResourceLoader.java

License:Apache License

private void matchProps(Properties props, String keyPrefix, Config config) {
    // Lookup the value
    Iterator i = props.getAll().keySet().iterator();
    while (i.hasNext()) {
        String name = (String) i.next();
        if (name.startsWith(keyPrefix + ".")) {
            String property = name.substring(keyPrefix.length() + 1);
            config.putIfNotExists(property, Ext.parseValue(props.getString(name)));
        }//from www . jav  a2s . co m
    }
}