use of org.whole.lang.properties.model.Properties in project whole by wholeplatform.
the class PropertiesTabularPart method getModelSpecificChildren.
@Override
protected List<IEntity> getModelSpecificChildren() {
Properties entity = getModelEntity();
List<IEntity> list = new ArrayList<IEntity>(3);
list.add(entity.getDefaults());
list.add(entity.getComment());
list.add(entity.getEntries());
return list;
}
use of org.whole.lang.properties.model.Properties in project whole by wholeplatform.
the class PropertiesTextPersistenceKit method doWriteModel.
protected void doWriteModel(IEntity model, IPersistenceProvider pp) throws Exception {
if (!model.wGetEntityDescriptor().equals(PropertiesEntityDescriptorEnum.Properties))
throw new IllegalArgumentException("A Properties model is required. Was: " + model);
OutputStream os = pp.getOutputStream();
String encoding = pp.getEncoding();
Charset charset = Charset.forName(encoding);
Charset persistenceCharset = Charset.forName(getDefaultEncoding());
if (!persistenceCharset.equals(charset)) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PropertiesUtils.saveToText((Properties) model, baos, "");
os.write(charset.newEncoder().encode(CharBuffer.wrap(baos.toString(persistenceCharset.name()))).array());
} else
PropertiesUtils.saveToText((Properties) model, os, "");
}
use of org.whole.lang.properties.model.Properties in project whole by wholeplatform.
the class PropertiesTest method testTranslate.
@Test
public void testTranslate() {
java.util.Properties jProps = new java.util.Properties();
jProps.setProperty("key1", "value1");
jProps.setProperty("key2", "value2");
jProps.setProperty("key3", "value3");
jProps.setProperty("key4", "value4");
try {
Properties props = PropertiesUtils.translate(jProps);
Assert.assertEquals(4, props.getEntries().wSize());
Assert.assertTrue(EntityUtils.isResolver(props.getDefaults()));
java.util.Properties jProps3 = PropertiesUtils.translate(props);
Assert.assertEquals(jProps, jProps3);
} catch (IOException e) {
Assert.fail();
}
}
use of org.whole.lang.properties.model.Properties in project whole by wholeplatform.
the class PropertiesTest method testSystemProperties.
@Test
public void testSystemProperties() throws IOException {
Properties props = (Properties) PropertiesTemplateManager.instance().create("System Properties");
PropertiesUtils.saveToText(props, System.out, "comment");
}
use of org.whole.lang.properties.model.Properties in project whole by wholeplatform.
the class PropertiesTest method testGetSetProperty.
@Test
public void testGetSetProperty() {
PropertiesEntityFactory lf = PropertiesEntityFactory.instance;
Properties props = lf.createProperties(lf.createComment("Test properties"), createResolver(PropertiesEntityDescriptorEnum.Properties), lf.createEntries(new Property[] { lf.createProperty(lf.createPropertyName("prop1"), lf.createPropertyValue("value 1")), lf.createProperty(lf.createPropertyName("prop2"), lf.createPropertyValue("value 2")) }));
String prop1Value = PropertiesUtils.getProperty(props, "prop1");
Assert.assertEquals("value 1", prop1Value);
}
Aggregations