use of org.eclipse.wst.xml.core.internal.contentmodel.CMDataType in project webtools.sourceediting by eclipse.
the class ContentBuilder method visitCMElementDeclaration.
public void visitCMElementDeclaration(CMElementDeclaration ed) {
int forcedMin = (buildPolicy == BUILD_ALL_CONTENT || alwaysVisit) ? 1 : 0;
int min = Math.max(ed.getMinOccur(), forcedMin);
alwaysVisit = false;
if (min > 0 && !visitedCMElementDeclarationList.contains(ed)) {
visitedCMElementDeclarationList.add(ed);
for (int i = 1; i <= min; i++) {
createElementNodeStart(ed);
// instead of calling super.visitCMElementDeclaration()
// we duplicate the code with some minor modifications
CMNamedNodeMap nodeMap = ed.getAttributes();
int size = nodeMap.getLength();
for (int j = 0; j < size; j++) {
visitCMNode(nodeMap.item(j));
}
CMContent content = ed.getContent();
if (content != null) {
visitCMNode(content);
}
if (ed.getContentType() == CMElementDeclaration.PCDATA) {
CMDataType dataType = ed.getDataType();
if (dataType != null) {
visitCMDataType(dataType);
}
}
// end duplication
createElementNodeEnd(ed);
}
int size = visitedCMElementDeclarationList.size();
visitedCMElementDeclarationList.remove(size - 1);
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMDataType in project webtools.sourceediting by eclipse.
the class BugFixesTest method testXSDTypeWhitespaceFacets.
// @SuppressWarnings("unchecked")
// public void testStackOverflow()
// {
// String namespaceURI = "http://www.w3.org/TR/voicexml20/vxml.xsd";
// String vxmlSchemaURI = locateFileUsingCatalog(namespaceURI);
//
// // See bug 206138
//
// // Two ways to test this.
// // First way. Call findTypesDerivedFrom from XSDImpl.
//
// assertNotNull("unable to locate file for " + namespaceURI, vxmlSchemaURI);
// assertTrue("unable to locate file for " + namespaceURI, vxmlSchemaURI.length() > 0);
// XSDSchema xsdSchema = XSDImpl.buildXSDModel(vxmlSchemaURI);
// assertNotNull("failed to build model for " + vxmlSchemaURI,xsdSchema);
// boolean foundDesiredType = false;
// for (Iterator<XSDTypeDefinition> types = xsdSchema.getTypeDefinitions().iterator(); types.hasNext(); )
// {
// XSDTypeDefinition type = types.next();
// if (type instanceof XSDComplexTypeDefinition)
// {
// XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) type;
// if ("basic.event.handler".equals(complexType.getName()))
// {
// foundDesiredType = true;
// List<XSDTypeDefinition> list = XSDImpl.findTypesDerivedFrom(complexType);
// int size = list.size();
// // assertTrue(size == 1); // if we got something back, then great, there was no out of stack error
// assertTrue("no types found in XSD", size >= 0);
// // Because of bug 203048, there is a change in behaviour to redefined types.
// // The complex type named speaker is no longer circular. In terms of this junit, the value returned is not relevant
// // since we just want some length back (i.e. there was no crash from a stack overflow).
// break;
// }
// }
// }
// assertTrue("type \"basic.event.handler\" not found in XSD", foundDesiredType); // if we didn't even find the complex type, then something terrible went wrong
//
// // Second way to test via content model
//
// CMDocumentFactoryXSD factory = new CMDocumentFactoryXSD();
// assertNotNull("Assert factory is not null", factory);
//
// CMDocument cmDocument = factory.createCMDocument(vxmlSchemaURI);
// assertNotNull("Assert CMDocument is not null", cmDocument);
//
// CMNamedNodeMap elements = cmDocument.getElements();
//
// boolean foundDesiredElement = false;
// for (Iterator<CMElementDeclaration> i = elements.iterator(); i.hasNext(); )
// {
// CMElementDeclaration element = i.next();
// if ("noinput".equals(element.getElementName()))
// {
// CMNamedNodeMap attributes = element.getAttributes();
// assertNotNull(attributes);
// // assertTrue(attributes.getLength() == 3); // if we got something back, then great, there was no out of stack error
// // Because of bug 203048, there is a change in behaviour to redefined types.
// // The complex type named speaker is no longer circular. In terms of this junit, the value returned is not relevant
// // since we just want some length back (i.e. there was no crash from a stack overflow).
// assertTrue(attributes.getLength() >= 0);
// foundDesiredElement = true;
// break;
// }
// }
// assertTrue("element \"noinput\"r not found in XSD", foundDesiredElement); // if we didn't even find the noinput element, then something terrible went wrong
// }
public void testXSDTypeWhitespaceFacets() {
// Bug [194698] - Test that the correct whitespace facets are applied to the types
String XSD_FILE_NAME = "XSDWhitespace.xsd";
String fileURI = FILE_PROTOCOL + PLUGIN_ABSOLUTE_PATH + SAMPLES_DIR + XSD_FILE_NAME;
CMDocumentFactoryXSD factory = new CMDocumentFactoryXSD();
assertNotNull("Assert factory is not null", factory);
CMDocument cmDocument = factory.createCMDocument(fileURI);
assertNotNull("Assert CMDocument is not null", cmDocument);
CMElementDeclaration elemDecl = (CMElementDeclaration) cmDocument.getElements().item(0);
assertEquals("test", elemDecl.getNodeName());
assertTrue(elemDecl.getContent() instanceof XSDModelGroupAdapter);
XSDModelGroupAdapter group = (XSDModelGroupAdapter) elemDecl.getContent();
CMNodeList list = group.getChildNodes();
XSDElementDeclarationAdapter adapter = null;
String nodeName = null, expected = null;
CMDataType type = null;
// Iterate over the child nodes of the element, examining the whitespace facets */
for (int i = 0; i < list.getLength(); i++) {
adapter = (XSDElementDeclarationAdapter) list.item(i);
nodeName = adapter.getNodeName();
assertNotNull(nodeName);
assertTrue(nodeName.contains("-"));
type = adapter.getDataType();
assertNotNull(type);
expected = nodeName.substring(nodeName.indexOf('-') + 1);
assertEquals(expected, type.getProperty(XSDImpl.PROPERTY_WHITESPACE_FACET));
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMDataType in project webtools.sourceediting by eclipse.
the class BugFixesTest method testBase64BinaryDefaultValue.
/**
* See https://bugs.eclipse.org/bugs/show_bug.cgi?id=322841
*/
public void testBase64BinaryDefaultValue() {
Bundle bundle = Platform.getBundle(XSDCoreTestsPlugin.PLUGIN_ID);
// $NON-NLS-1$
URL url = bundle.getEntry("/testresources/samples/base64Binary/Test.xsd");
CMDocument cmDocument = XSDImpl.buildCMDocument(url.toExternalForm());
assertNotNull(cmDocument);
CMNamedNodeMap elements = cmDocument.getElements();
// $NON-NLS-1$
CMElementDeclaration cmElementDeclaration = (CMElementDeclaration) elements.getNamedItem("Test");
assertNotNull(cmElementDeclaration);
CMDataType dataType = cmElementDeclaration.getDataType();
assertNotNull(dataType);
String impliedValue = dataType.generateInstanceValue();
// $NON-NLS-1$
assertEquals("MA==", impliedValue);
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMDataType in project webtools.sourceediting by eclipse.
the class ModelQueryTester method testBodyElement.
/**
* Test the HTML BODY Element for the "bgcolor" attribute declaration
*/
public void testBodyElement() {
setUpHTML();
// set
fModel.getStructuredDocument().set("<html><body bgcolor=\"#ffffff\"><form method=\"post\"></form></body></html>");
// text
// TEST getting a CMElementDeclaration
// node at
Element bodyElement = (Element) fModel.getIndexedRegion(7);
// offset7--should
// be
// <body>
CMElementDeclaration bodyDecl = fModelQuery.getCMElementDeclaration(bodyElement);
int contentType = bodyDecl.getContentType();
assertTrue("CMElementDeclaration CONTENT TYPE INCORRECT FOR BODY", (contentType == CMElementDeclaration.MIXED));
// get permissible attrs
CMNamedNodeMap map = bodyDecl.getAttributes();
assertTrue("ATTRIBUTES FROM ELEMENT DECLARATION == NULL", (map != null));
Vector allowed = new Vector();
for (int i = 0; i < map.getLength(); i++) {
CMAttributeDeclaration node = (CMAttributeDeclaration) map.item(i);
String name = node.getNodeName();
allowed.add(name);
if (name.equalsIgnoreCase("bgcolor")) {
assertTrue("GOT INCORRECT ATTRIBUTE NODE TYPE", (node.getNodeType() == CMNode.ATTRIBUTE_DECLARATION));
CMDataType attrType = node.getAttrType();
// System.out.println("attribute type > " + attrType);
assertTrue("COULD NOT GET ATTRIBUTE TYPE", (attrType != null));
assertTrue("COULDN'T GET IMPLIED VALUE KIND", (attrType.getImpliedValueKind() == CMDataType.IMPLIED_VALUE_NONE));
}
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMDataType in project webtools.sourceediting by eclipse.
the class ModelQueryTester method getValidStrings.
/**
* Return the valid values for an attribute with the given declaration on
* the given element. Derived from XMLPropertySource
*/
private List getValidStrings(Element element, CMAttributeDeclaration attrDecl) {
CMDataType valuesHelper = attrDecl.getAttrType();
Vector values = new Vector();
if (valuesHelper.getImpliedValueKind() == CMDataType.IMPLIED_VALUE_FIXED && valuesHelper.getImpliedValue() != null) {
// FIXED value
values.add(valuesHelper.getImpliedValue());
} else {
// ENUMERATED values
String[] valueStrings = null;
// new way
valueStrings = fModelQuery.getPossibleDataTypeValues(element, attrDecl);
if (valueStrings == null)
// older way
valueStrings = attrDecl.getAttrType().getEnumeratedValues();
if (valueStrings != null) {
for (int i = 0; i < valueStrings.length; i++) {
values.add(valueStrings[i]);
}
}
}
if (valuesHelper.getImpliedValueKind() != CMDataType.IMPLIED_VALUE_NONE && valuesHelper.getImpliedValue() != null) {
if (!values.contains(valuesHelper.getImpliedValue()))
values.add(valuesHelper.getImpliedValue());
}
return values;
}
Aggregations