Search in sources :

Example 1 with Properties

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;
}
Also used : IEntity(org.whole.lang.model.IEntity) ArrayList(java.util.ArrayList) Properties(org.whole.lang.properties.model.Properties)

Example 2 with Properties

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, "");
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Charset(java.nio.charset.Charset) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Properties(org.whole.lang.properties.model.Properties)

Example 3 with Properties

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();
    }
}
Also used : IOException(java.io.IOException) Properties(org.whole.lang.properties.model.Properties) Test(org.junit.Test)

Example 4 with Properties

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");
}
Also used : Properties(org.whole.lang.properties.model.Properties) Test(org.junit.Test)

Example 5 with Properties

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);
}
Also used : PropertiesEntityFactory(org.whole.lang.properties.factories.PropertiesEntityFactory) Properties(org.whole.lang.properties.model.Properties) Property(org.whole.lang.properties.model.Property) Test(org.junit.Test)

Aggregations

Properties (org.whole.lang.properties.model.Properties)10 Test (org.junit.Test)5 IEntity (org.whole.lang.model.IEntity)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 PropertiesEntityFactory (org.whole.lang.properties.factories.PropertiesEntityFactory)2 Property (org.whole.lang.properties.model.Property)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 Charset (java.nio.charset.Charset)1 Enumeration (java.util.Enumeration)1 ModelBuilderOperation (org.whole.lang.builders.ModelBuilderOperation)1 JavaStoreProducerBuilder (org.whole.lang.java.util.JavaStoreProducerBuilder)1 JavaStoreProducerBuilderOperation (org.whole.lang.java.util.JavaStoreProducerBuilderOperation)1 Entries (org.whole.lang.properties.model.Entries)1 PropertyValue (org.whole.lang.properties.model.PropertyValue)1 ModelTemplate (org.whole.lang.templates.ModelTemplate)1