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());
}
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));
}
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"));
}
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;
}
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;
}
Aggregations