Search in sources :

Example 1 with ValueMap

use of org.apache.wicket.util.value.ValueMap in project wicket by apache.

the class SerializableCheckerTest method valueMap.

/**
 * Test {@link ValueMap} serializability.
 *
 * @throws IOException
 */
@Test
public void valueMap() throws IOException {
    CheckingObjectOutputStream checker = new CheckingObjectOutputStream(new ByteArrayOutputStream(), new ObjectSerializationChecker(new NotSerializableException()));
    checker.writeObject(new ValueMap());
}
Also used : NotSerializableException(java.io.NotSerializableException) ObjectSerializationChecker(org.apache.wicket.core.util.objects.checker.ObjectSerializationChecker) ValueMap(org.apache.wicket.util.value.ValueMap) CheckingObjectOutputStream(org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream) Test(org.junit.Test)

Example 2 with ValueMap

use of org.apache.wicket.util.value.ValueMap in project wicket by apache.

the class LocalizerTest method testGetStringPropertySubstitution.

/**
 */
@Test
public void testGetStringPropertySubstitution() {
    Session.get().setLocale(Locale.GERMAN);
    ValueMap vm = new ValueMap();
    vm.put("user", "John Doe");
    vm.put("rating", 4.5);
    IModel<ValueMap> model = new Model<ValueMap>(vm);
    Assert.assertEquals("Property substitution should occur", "John Doe gives 4,5 stars", localizer.getString("test.substitute", null, model, null));
}
Also used : ValueMap(org.apache.wicket.util.value.ValueMap) Model(org.apache.wicket.model.Model) PropertyModel(org.apache.wicket.model.PropertyModel) IModel(org.apache.wicket.model.IModel) Test(org.junit.Test)

Example 3 with ValueMap

use of org.apache.wicket.util.value.ValueMap in project wicket by apache.

the class SimplePageTest method renderHomePage_2b.

/**
 * @throws Exception
 */
@Test
public void renderHomePage_2b() throws Exception {
    // Render the component without having rendered the page previously
    SimplePage page = new SimplePage();
    Label label = (Label) page.get("myLabel");
    assertNotNull(label);
    ValueMap attr = label.getMarkupAttributes();
    assertNotNull(attr);
    assertEquals("myLabel", attr.getString("wicket:id"));
    Panel panel = (Panel) page.get("myPanel");
    assertNotNull(panel);
    attr = panel.getMarkupAttributes();
    assertNotNull(attr);
    assertEquals("myPanel", attr.getString("wicket:id"));
    label = (Label) page.get("myPanel:label");
    assertNotNull(label);
    attr = label.getMarkupAttributes();
    assertNotNull(attr);
    assertEquals("label", attr.getString("wicket:id"));
    Border border = (Border) page.get("myBorder");
    assertNotNull(border);
    attr = border.getMarkupAttributes();
    assertNotNull(attr);
    assertEquals("myBorder", attr.getString("wicket:id"));
    border = (Border) page.get("myBorder2");
    assertNotNull(border);
    attr = border.getMarkupAttributes();
    assertNotNull(attr);
    assertEquals("myBorder2", attr.getString("wicket:id"));
    // do the same test twice. Igor reported a problem with that, so we have to test it.
    border = (Border) page.get("myBorder2");
    assertNotNull(border);
    attr = border.getMarkupAttributes();
    assertNotNull(attr);
    assertEquals("myBorder2", attr.getString("wicket:id"));
    WebMarkupContainer container = (WebMarkupContainer) page.get("test");
    assertNotNull(container);
    attr = container.getMarkupAttributes();
    assertNotNull(attr);
    assertEquals("test", attr.getString("wicket:id"));
    label = (Label) page.get("test:myLabel2");
    assertNotNull(label);
    attr = label.getMarkupAttributes();
    assertNotNull(attr);
    assertEquals("myLabel2", attr.getString("wicket:id"));
}
Also used : Panel(org.apache.wicket.markup.html.panel.Panel) ValueMap(org.apache.wicket.util.value.ValueMap) Border(org.apache.wicket.markup.html.border.Border) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) Test(org.junit.Test)

Example 4 with ValueMap

use of org.apache.wicket.util.value.ValueMap in project wicket by apache.

the class PropertiesFactory method loadFromLoader.

/**
 * @param loader
 * @param resourceStream
 * @return properties
 */
protected ValueMap loadFromLoader(final IPropertiesLoader loader, final IResourceStream resourceStream) {
    if (log.isDebugEnabled()) {
        log.debug("Loading properties files from '{}' with loader '{}'", resourceStream, loader);
    }
    BufferedInputStream in = null;
    try {
        // Get the InputStream
        in = new BufferedInputStream(resourceStream.getInputStream());
        ValueMap data = loader.loadWicketProperties(in);
        if (data == null) {
            java.util.Properties props = loader.loadJavaProperties(in);
            if (props != null) {
                // Copy the properties into the ValueMap
                data = new ValueMap();
                Enumeration<?> enumeration = props.propertyNames();
                while (enumeration.hasMoreElements()) {
                    String property = (String) enumeration.nextElement();
                    data.put(property, props.getProperty(property));
                }
            }
        }
        return data;
    } catch (ResourceStreamNotFoundException | IOException e) {
        log.warn("Unable to find resource " + resourceStream, e);
    } finally {
        IOUtils.closeQuietly(in);
        IOUtils.closeQuietly(resourceStream);
    }
    return null;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) ValueMap(org.apache.wicket.util.value.ValueMap) IOException(java.io.IOException) ResourceStreamNotFoundException(org.apache.wicket.util.resource.ResourceStreamNotFoundException)

Example 5 with ValueMap

use of org.apache.wicket.util.value.ValueMap in project wicket by apache.

the class PropertiesFactory method load.

/**
 * @see org.apache.wicket.resource.IPropertiesFactory#load(java.lang.Class, java.lang.String)
 */
@Override
public Properties load(final Class<?> clazz, final String path) {
    // Check the cache
    Properties properties = null;
    if (propertiesCache != null) {
        properties = propertiesCache.get(path);
    }
    if (properties == null) {
        Iterator<IPropertiesLoader> iter = propertiesLoader.iterator();
        while ((properties == null) && iter.hasNext()) {
            IPropertiesLoader loader = iter.next();
            String fullPath = path + "." + loader.getFileExtension();
            // If not in the cache than try to load properties
            IResourceStream resourceStream = context.getResourceStreamLocator().locate(clazz, fullPath);
            if (resourceStream == null) {
                continue;
            }
            // Watch file modifications
            final IModificationWatcher watcher = context.getResourceWatcher(true);
            if (watcher != null) {
                addToWatcher(path, resourceStream, watcher);
            }
            ValueMap props = loadFromLoader(loader, resourceStream);
            if (props != null) {
                properties = new Properties(path, props);
            }
        }
        // Cache the lookup
        if (propertiesCache != null) {
            if (properties == null) {
                // Could not locate properties, store a placeholder
                propertiesCache.put(path, Properties.EMPTY_PROPERTIES);
            } else {
                propertiesCache.put(path, properties);
            }
        }
    }
    if (properties == Properties.EMPTY_PROPERTIES) {
        // Translate empty properties placeholder to null prior to returning
        properties = null;
    }
    return properties;
}
Also used : IModificationWatcher(org.apache.wicket.util.watch.IModificationWatcher) IResourceStream(org.apache.wicket.util.resource.IResourceStream) ValueMap(org.apache.wicket.util.value.ValueMap)

Aggregations

ValueMap (org.apache.wicket.util.value.ValueMap)11 Test (org.junit.Test)7 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)2 BufferedInputStream (java.io.BufferedInputStream)1 IOException (java.io.IOException)1 NotSerializableException (java.io.NotSerializableException)1 CheckingObjectOutputStream (org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream)1 ObjectSerializationChecker (org.apache.wicket.core.util.objects.checker.ObjectSerializationChecker)1 ComponentTag (org.apache.wicket.markup.ComponentTag)1 Label (org.apache.wicket.markup.html.basic.Label)1 Border (org.apache.wicket.markup.html.border.Border)1 Panel (org.apache.wicket.markup.html.panel.Panel)1 IModel (org.apache.wicket.model.IModel)1 Model (org.apache.wicket.model.Model)1 PropertyModel (org.apache.wicket.model.PropertyModel)1 IResourceStream (org.apache.wicket.util.resource.IResourceStream)1 ResourceStreamNotFoundException (org.apache.wicket.util.resource.ResourceStreamNotFoundException)1 IValueMap (org.apache.wicket.util.value.IValueMap)1 IModificationWatcher (org.apache.wicket.util.watch.IModificationWatcher)1