Example usage for org.apache.wicket.core.util.resource.locator ResourceNameIterator next

List of usage examples for org.apache.wicket.core.util.resource.locator ResourceNameIterator next

Introduction

In this page you can find the example usage for org.apache.wicket.core.util.resource.locator ResourceNameIterator next.

Prototype

@Override
public String next() 

Source Link

Usage

From source file:org.hippoecm.frontend.ClassFromKeyStringResourceLoader.java

License:Apache License

private String getStringForClass(String realKey, Locale locale, String style, String clazz) {
    // Create the base path
    String path = clazz.replace('.', '/');

    // Iterator over all the combinations
    ResourceNameIterator iter = new ResourceNameIterator(path, style, null, locale,
            Arrays.asList("properties", "xml"), false);
    while (iter.hasNext()) {
        String newPath = iter.next();
        Properties properties = getProperties(newPath);
        String value = properties.getProperty(realKey);
        if (value != null) {
            return value;
        }//from ww  w  .j  a v a  2 s .  c o m
    }
    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  w w w.j  a va 2 s. 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.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();//from  w ww  .  jav a  2  s  . c  o  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;
}