Search in sources :

Example 1 with XMLObject

use of org.exoplatform.xml.object.XMLObject in project kernel by exoplatform.

the class TestCollectionValue method getConfiguredCollection.

private XMLCollection getConfiguredCollection(String... profiles) throws Exception {
    Configuration config = getConfiguration("collection-configuration.xml", profiles);
    Component a = config.getComponent(InitParamsHolder.class.getName());
    ObjectParameter op = a.getInitParams().getObjectParam("test.configuration");
    XMLObject o = op.getXMLObject();
    XMLField xf = o.getField("role");
    return xf.getCollection();
}
Also used : XMLField(org.exoplatform.xml.object.XMLField) Configuration(org.exoplatform.container.xml.Configuration) ObjectParameter(org.exoplatform.container.xml.ObjectParameter) XMLObject(org.exoplatform.xml.object.XMLObject) Component(org.exoplatform.container.xml.Component)

Example 2 with XMLObject

use of org.exoplatform.xml.object.XMLObject in project kernel by exoplatform.

the class TestField method getConfiguredCollection.

private XMLCollection getConfiguredCollection(String... profiles) throws Exception {
    Configuration config = getConfiguration("field-configuration.xml", profiles);
    Component a = config.getComponent(InitParamsHolder.class.getName());
    ObjectParameter op = a.getInitParams().getObjectParam("test.configuration");
    XMLObject o = op.getXMLObject();
    XMLField xf = o.getField("role");
    return xf.getCollection();
}
Also used : XMLField(org.exoplatform.xml.object.XMLField) Configuration(org.exoplatform.container.xml.Configuration) ObjectParameter(org.exoplatform.container.xml.ObjectParameter) XMLObject(org.exoplatform.xml.object.XMLObject) Component(org.exoplatform.container.xml.Component)

Example 3 with XMLObject

use of org.exoplatform.xml.object.XMLObject in project kernel by exoplatform.

the class TestDataXML method testConvert.

public void testConvert() throws Exception {
    String projectdir = System.getProperty("basedir");
    XMLObject xmlobj = new XMLObject(new TestObject());
    String xml1 = new String(xmlobj.toByteArray("UTF-8"));
    FileOutputStream os = new FileOutputStream(projectdir + "/target/test-object-1.xml");
    os.write(xml1.getBytes());
    os.close();
    File file = new File(projectdir + "/target/test-object-1.xml");
    FileInputStream is = new FileInputStream(file);
    FileChannel fchan = is.getChannel();
    ByteBuffer buff = ByteBuffer.allocate((int) file.length());
    fchan.read(buff);
    buff.rewind();
    byte[] data = buff.array();
    buff.clear();
    fchan.close();
    is.close();
    TestObject tobject = (TestObject) XMLObject.getObject(new ByteArrayInputStream(data));
    assertTrue(tobject.nested.intarray.length == 10);
    os = new FileOutputStream(projectdir + "/target/test-object-2.xml");
    xmlobj = new XMLObject(tobject);
    String xml2 = new String(xmlobj.toByteArray("UTF-8"));
    os.write(xml2.getBytes());
    os.close();
    assertTrue(xml1.equals(xml2));
    is.close();
    List list = new ArrayList();
    list.add("test.....................");
    list.add(new Date());
    XMLCollection xmllist = new XMLCollection(list);
    os = new FileOutputStream(projectdir + "/target/list.xml");
    os.write(xmllist.toByteArray("UTF-8"));
    os.close();
}
Also used : FileChannel(java.nio.channels.FileChannel) ArrayList(java.util.ArrayList) XMLObject(org.exoplatform.xml.object.XMLObject) ByteBuffer(java.nio.ByteBuffer) FileInputStream(java.io.FileInputStream) Date(java.util.Date) XMLCollection(org.exoplatform.xml.object.XMLCollection) ByteArrayInputStream(java.io.ByteArrayInputStream) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File)

Aggregations

XMLObject (org.exoplatform.xml.object.XMLObject)3 Component (org.exoplatform.container.xml.Component)2 Configuration (org.exoplatform.container.xml.Configuration)2 ObjectParameter (org.exoplatform.container.xml.ObjectParameter)2 XMLField (org.exoplatform.xml.object.XMLField)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 ByteBuffer (java.nio.ByteBuffer)1 FileChannel (java.nio.channels.FileChannel)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 XMLCollection (org.exoplatform.xml.object.XMLCollection)1