Search in sources :

Example 1 with XmlEntityFactory

use of org.whole.lang.xml.factories.XmlEntityFactory in project whole by wholeplatform.

the class ByChildAPITest method testAbstractUListEntity.

@Test
public void testAbstractUListEntity() {
    XmlEntityFactory xmlf = XmlEntityFactory.instance(RegistryConfigurations.STRICT);
    Attribute a1 = xmlf.createAttribute(xmlf.createName("attr1"), xmlf.createValue("value1"));
    Attribute a2 = xmlf.createAttribute(xmlf.createName("attr2"), xmlf.createValue("value2"));
    Attribute a3 = xmlf.createAttribute(xmlf.createName("attr3"), xmlf.createValue("value3"));
    Attribute[] attributesArray = new Attribute[] { a1, a2, a3 };
    int[] businessEquivalence = new int[] { 0, 1, 2 };
    Attributes attributes = xmlf.createAttributes(attributesArray);
    orderedCompositeOperationsEntityTest(attributesArray, businessEquivalence, attributes);
    commonOperationsEntityTest(attributesArray, attributesArray, attributes);
    uniqueOperationsEntityTest(attributesArray, attributes);
    propertyChangeEntityTest(attributesArray, attributes, xmlf.createAttribute(xmlf.createName("attr4"), xmlf.createValue("value4")));
}
Also used : Attribute(org.whole.lang.xml.model.Attribute) Attributes(org.whole.lang.xml.model.Attributes) XmlEntityFactory(org.whole.lang.xml.factories.XmlEntityFactory) Test(org.junit.Test)

Example 2 with XmlEntityFactory

use of org.whole.lang.xml.factories.XmlEntityFactory in project whole by wholeplatform.

the class NormalizerOperationTest method testXmlBehavior.

@Test
public void testXmlBehavior() {
    assertTrue(ReflectionFactory.getLanguageKit(XmlLanguageKit.URI).hasVisitor(NormalizerOperation.ID));
    XmlEntityFactory ef = XmlEntityFactory.instance;
    CDataSect data = ef.createCDataSect(ef.createCDataSectData("one"), ef.createCDataSectData("two"), ef.createCDataSectData("three"));
    CDataSect dataOrig = EntityUtils.clone(data);
    NormalizerOperation.normalize(data);
    assertFalse(Matcher.match(dataOrig, data));
    CDataSect dataOrig2 = EntityUtils.clone(data);
    NormalizerOperation.normalize(data);
    assertTrue(Matcher.match(dataOrig2, data));
}
Also used : CDataSect(org.whole.lang.xml.model.CDataSect) XmlEntityFactory(org.whole.lang.xml.factories.XmlEntityFactory) Test(org.junit.Test)

Example 3 with XmlEntityFactory

use of org.whole.lang.xml.factories.XmlEntityFactory in project whole by wholeplatform.

the class XmlSpecific2XsiBuilderAdapter method normalizeXmlFragment.

protected org.whole.lang.xml.model.Element normalizeXmlFragment(org.whole.lang.xml.model.Element xmlFragment) {
    XmlFragmentNormalizer normalizer = new XmlFragmentNormalizer(true);
    xmlFragment.accept(normalizer);
    // add needed namespace declarations
    XmlEntityFactory xef = XmlEntityFactory.instance;
    IEntity attributes = xmlFragment.getAttributes();
    for (String prefix : normalizer.getNeededNamespaces()) attributes.wAdd(xef.createAttribute(xef.createQualifiedName(xef.createNameSpace("xmlns"), xef.createName(prefix)), xef.createValue(ns.wStringValue(prefix))));
    return xmlFragment;
}
Also used : IEntity(org.whole.lang.model.IEntity) XmlEntityFactory(org.whole.lang.xml.factories.XmlEntityFactory)

Example 4 with XmlEntityFactory

use of org.whole.lang.xml.factories.XmlEntityFactory in project whole by wholeplatform.

the class GrammarsUtilsTest method testUnparseXmlElement.

@Test
public void testUnparseXmlElement() {
    XmlEntityFactory xf = XmlEntityFactory.instance;
    Element e = xf.createElement(xf.createQualifiedName(xf.createNameSpace("ns"), xf.createName("tag")), xf.createAttributes(xf.createAttribute(xf.createName("attr"), xf.createValue("val")), xf.createAttribute(xf.createName("attr2"), xf.createValue("val2"))), xf.createCharData("test"));
    StringBuilder sb = new StringBuilder();
    GrammarsUtils.unparse(e, sb, xmlGrammarURI);
    Assert.assertEquals("<ns:tag attr=\"val\" attr2=\"val2\">test</ns:tag>", sb.toString());
}
Also used : Element(org.whole.lang.xml.model.Element) XmlEntityFactory(org.whole.lang.xml.factories.XmlEntityFactory) Test(org.junit.Test)

Aggregations

XmlEntityFactory (org.whole.lang.xml.factories.XmlEntityFactory)4 Test (org.junit.Test)3 IEntity (org.whole.lang.model.IEntity)1 Attribute (org.whole.lang.xml.model.Attribute)1 Attributes (org.whole.lang.xml.model.Attributes)1 CDataSect (org.whole.lang.xml.model.CDataSect)1 Element (org.whole.lang.xml.model.Element)1