use of org.whole.lang.xml.model.Document in project whole by wholeplatform.
the class PersistenceTest method testSaxHandlerBuilder.
@Test
public void testSaxHandlerBuilder() throws Exception {
Document xmlModel = (Document) XmlSourcePersistenceKit.instance().readModel(new ClasspathPersistenceProvider("org/whole/lang/xsd/util/javaee_web_services_client_1_2.xsd"));
ModelBuilderOperation op = new ModelBuilderOperation();
SaxConsumerHandler saxHandler = new SaxConsumerHandler(op, !EntityUtils.isResolver(xmlModel.getProlog().getXmlDecl()));
SaxHandlerBuilderOperation sbop = new SaxHandlerBuilderOperation(saxHandler, saxHandler);
new ModelTemplate(xmlModel).apply(sbop);
assertTrue(Matcher.match(op.wGetResult(), xmlModel));
}
use of org.whole.lang.xml.model.Document in project whole by wholeplatform.
the class DocumentPart method getModelSpecificChildren.
protected List<IEntity> getModelSpecificChildren() {
List<IEntity> list = new ArrayList<IEntity>(2);
Document document = getModelEntity();
list.add(document.getProlog());
list.add(document.getElement());
return list;
}
use of org.whole.lang.xml.model.Document in project whole by wholeplatform.
the class XmlNormalizerBuilderTest method testNormalizationWithCDataSectMerge.
@Test
public void testNormalizationWithCDataSectMerge() {
try {
// create queries
Path findNestedContent = (Path) XmlNormalizerBuilderTemplateManager.instance().create("findNestedContent");
Path findMissingContentEntities = (Path) XmlNormalizerBuilderTemplateManager.instance().create("findMissingContentEntities");
Path findConsecutiveCharDataOrCDataSect = (Path) XmlNormalizerBuilderTemplateManager.instance().create("findConsecutiveCharDataOrCDataSect");
// create normalized sample xml model
SampleXmlModel sampleXmlModelTemplate = new SampleXmlModel();
Document xmlDocument = sampleXmlModelTemplate.create();
IBindingManager parameters = BindingManagerFactory.instance.createArguments();
parameters.wDefValue("mergeCDataSect", true);
ModelBuilderOperation mop = new ModelBuilderOperation();
XmlNormalizerBuilderOperation xnop = new XmlNormalizerBuilderOperation(mop, parameters);
sampleXmlModelTemplate.apply(xnop);
Document normalizedXmlDocument = (Document) mop.wGetResult();
// no nested Content
IEntityIterator<IEntity> iterator = BehaviorUtils.compileAndLazyEvaluate(findNestedContent, normalizedXmlDocument);
assertFalse(iterator.hasNext());
// no nested implied Content
iterator = BehaviorUtils.compileAndLazyEvaluate(findMissingContentEntities, normalizedXmlDocument);
assertFalse(iterator.hasNext());
// no consecutive CharData
iterator = BehaviorUtils.compileAndLazyEvaluate(findConsecutiveCharDataOrCDataSect, normalizedXmlDocument);
assertFalse(iterator.hasNext());
// no CDataSect at all
iterator = IteratorFactory.descendantOrSelfMatcherIterator().withPattern(XmlEntityDescriptorEnum.CDataSect);
iterator.reset(normalizedXmlDocument);
assertFalse(iterator.hasNext());
// both normalization strategies must yield the same result
assertTrue(Matcher.match(normalizedXmlDocument, NormalizerOperation.normalize(xmlDocument, parameters)));
} catch (Exception e) {
fail();
}
}
use of org.whole.lang.xml.model.Document in project whole by wholeplatform.
the class XmlNormalizerBuilderTest method testNormalizationWithoutCDataSectMerge.
@Test
public void testNormalizationWithoutCDataSectMerge() {
try {
// create queries
Path findNestedContent = (Path) XmlNormalizerBuilderTemplateManager.instance().create("findNestedContent");
Path findMissingContentEntities = (Path) XmlNormalizerBuilderTemplateManager.instance().create("findMissingContentEntities");
Path findConsecutiveCharDataOrCDataSect = (Path) XmlNormalizerBuilderTemplateManager.instance().create("findConsecutiveCharDataOrCDataSect");
// create sample xml model
SampleXmlModel sampleXmlModelTemplate = new SampleXmlModel();
Document xmlDocument = sampleXmlModelTemplate.create();
// has nested Content
IEntityIterator<IEntity> iterator = BehaviorUtils.compileAndLazyEvaluate(findNestedContent, xmlDocument);
assertTrue(iterator.hasNext());
// has nested implied Content
iterator = BehaviorUtils.compileAndLazyEvaluate(findMissingContentEntities, xmlDocument);
assertTrue(iterator.hasNext());
// has consecutive CharData or consecutive CDataSect
iterator = BehaviorUtils.compileAndLazyEvaluate(findConsecutiveCharDataOrCDataSect, xmlDocument);
assertTrue(iterator.hasNext());
// create normalized sample xml model
ModelBuilderOperation mop = new ModelBuilderOperation();
XmlNormalizerBuilderOperation xnop = new XmlNormalizerBuilderOperation(mop);
sampleXmlModelTemplate.apply(xnop);
Document normalizedXmlDocument = (Document) mop.wGetResult();
// no nested Content
iterator = BehaviorUtils.compileAndLazyEvaluate(findNestedContent, normalizedXmlDocument);
assertFalse(iterator.hasNext());
// no nested implied Content
iterator = BehaviorUtils.compileAndLazyEvaluate(findMissingContentEntities, normalizedXmlDocument);
assertFalse(iterator.hasNext());
// no consecutive CharData or consecutive CDataSect
iterator = BehaviorUtils.compileAndLazyEvaluate(findConsecutiveCharDataOrCDataSect, normalizedXmlDocument);
assertFalse(iterator.hasNext());
// both normalization strategies must yield the same result
assertTrue(Matcher.match(normalizedXmlDocument, NormalizerOperation.normalize(xmlDocument)));
} catch (Exception e) {
fail();
}
}
use of org.whole.lang.xml.model.Document in project whole by wholeplatform.
the class XsdModelBuilderTest method testBuilderAPI.
@Category(KnownFailingTests.class)
@Test
public void testBuilderAPI() throws Exception {
Schema xsdFromInputStream = (Schema) XsdPersistenceKit.instance().readModel(new StreamPersistenceProvider(getInputStream("datatypes.xsd")));
Document document = (Document) XmlSourcePersistenceKit.instance().readModel(new StreamPersistenceProvider(getInputStream("datatypes.xsd")));
IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
bm.wDefValue("mergeCDataSect", true);
XsdDeployStrategies.setDeployStrategy(bm, XsdDeployStrategies.ALL);
ModelBuilderOperation mop = new ModelBuilderOperation();
IBuilderOperation xsdBuilderOperation = new XmlSpecific2XsdBuilderAdapterOperation(mop, bm);
XmlNormalizerBuilderOperation normalizerOp = new XmlNormalizerBuilderOperation(xsdBuilderOperation, bm);
ModelTemplate template = new ModelTemplate(document);
template.apply(new XmlGenericBuilderAdapter((IXmlBuilder) normalizerOp.wGetBuilder(XmlLanguageKit.URI)));
Schema xsdFromXmlModel = (Schema) mop.wGetResult();
Assert.assertTrue(Matcher.match(xsdFromInputStream, xsdFromXmlModel));
}
Aggregations