Example usage for org.apache.wicket.resource IPropertiesFactory load

List of usage examples for org.apache.wicket.resource IPropertiesFactory load

Introduction

In this page you can find the example usage for org.apache.wicket.resource IPropertiesFactory load.

Prototype

Properties load(final Class<?> clazz, final String path);

Source Link

Document

Load the properties associated with the path

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)./* w  w w  .  j  a  va2  s .  co m*/
 * 
 * @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.
 *//*from   www  . j  av a  2 s .c  om*/
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.js.ext.ExtObservableHelper.java

License:Apache License

static JSONObject renderResources(final IExtObservable extObservable, Class<?> baseClass) throws JSONException {
    JSONObject resources = new JSONObject();

    IPropertiesFactory propertiesFactory = Application.get().getResourceSettings().getPropertiesFactory();
    Session session = Session.get();/*www  .j av a2  s  .  co  m*/
    String style = session.getStyle();
    Locale locale = session.getLocale();

    Class<?> clazz = extObservable.getClass();
    while (clazz != baseClass) {
        String path = clazz.getName().replace('.', '/');
        ResourceNameIterator iter = new ResourceNameIterator(path, style, null, locale, null, false);
        while (iter.hasNext()) {
            String newPath = iter.next();

            final Properties props = propertiesFactory.load(clazz, newPath);
            if (props != null) {
                ValueMap all = props.getAll();
                for (Map.Entry<String, Object> entry : all.entrySet()) {
                    if (!resources.has(entry.getKey())) {
                        resources.put(entry.getKey(), entry.getValue());
                    }
                }
            }
        }
        clazz = clazz.getSuperclass();
    }
    return resources;
}