use of org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap in project webtools.sourceediting by eclipse.
the class TestFixedCMDocuments method checkDocument.
private void checkDocument(Object documentKey) {
CMDocument document = JSPCMDocumentFactory.getCMDocument(documentKey.toString());
assertNotNull("missing doc:" + documentKey.toString(), document);
CMNamedNodeMap elements = document.getElements();
for (int i = 0; i < elements.getLength(); i++) {
CMNode item = elements.item(i);
verifyElementDeclarationHasName(item);
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap in project webtools.sourceediting by eclipse.
the class TestFixedCMDocuments method checkAttrNames.
/**
* @param cm_doc_type
* @param elementName
* @param attrNameImport
*/
private void checkAttrNames(String documentKey, String elementName, String[] attrNames) {
CMDocument document = JSPCMDocumentFactory.getCMDocument(documentKey);
CMNode elementDeclaration = document.getElements().getNamedItem(elementName);
assertEquals("not an element declaration:" + elementDeclaration, CMNode.ELEMENT_DECLARATION, elementDeclaration.getNodeType());
assertNotNull("missing element declaration:" + elementName, elementDeclaration);
CMNamedNodeMap attributes = ((CMElementDeclaration) elementDeclaration).getAttributes();
for (int i = 0; i < attrNames.length; i++) {
assertNotNull("missing attribute declaration:" + attrNames[i], attributes.getNamedItem(attrNames[i]));
}
assertEquals("Attributes defined in content model that are not expected by the test", attributes.getLength(), attrNames.length);
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap in project webtools.sourceediting by eclipse.
the class DocumentImpl method getCMAttributes.
/**
* Provides an element's attribute declarations
* @param element the element to retrieve the attribute map of
* @return a <code>CMNamedNodeMap</code> of attributes if the declaration exists; null otherwise.
*/
CMNamedNodeMap getCMAttributes(Element element) {
CMNamedNodeMap map = (CMNamedNodeMap) fCMCache.get(element);
if (map == null) {
ModelQuery modelQuery = ModelQueryUtil.getModelQuery(this);
CMElementDeclaration decl = modelQuery != null ? modelQuery.getCMElementDeclaration(element) : null;
if (decl != null) {
map = decl.getAttributes();
fCMCache.put(element, map);
}
}
return map;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap in project webtools.sourceediting by eclipse.
the class DocumentImpl method getCharValue.
/**
* getCharValue method
*
* @return java.lang.String
* @param name
* java.lang.String
*/
protected String getCharValue(String name) {
if (name == null)
return null;
int length = name.length();
if (length == 0)
return null;
if (name.charAt(0) == '#') {
// character reference
if (length == 1)
return null;
int radix = 10;
String s = null;
// now allow hexadecimal also for non XML document
if (name.charAt(1) == 'x') {
// hexadecimal
radix = 16;
s = name.substring(2);
} else {
// decimal
s = name.substring(1);
}
if (s == null || s.length() == 0)
return null;
if (s.charAt(0) == '-')
// no minus accepted
return null;
char c = 0;
try {
c = (char) Integer.parseInt(s, radix);
} catch (NumberFormatException ex) {
}
if (c == 0)
return null;
return String.valueOf(c);
}
// implicit character entities for XML
if (name.equals(IXMLCharEntity.LT_NAME))
return IXMLCharEntity.LT_VALUE;
if (name.equals(IXMLCharEntity.GT_NAME))
return IXMLCharEntity.GT_VALUE;
if (name.equals(IXMLCharEntity.AMP_NAME))
return IXMLCharEntity.AMP_VALUE;
if (name.equals(IXMLCharEntity.QUOT_NAME))
return IXMLCharEntity.QUOT_VALUE;
if (isXMLType()) {
if (name.equals(IXMLCharEntity.APOS_NAME))
return IXMLCharEntity.APOS_VALUE;
}
CMDocument cm = getCMDocument();
if (cm != null) {
CMNamedNodeMap map = cm.getEntities();
if (map != null) {
CMEntityDeclaration decl = (CMEntityDeclaration) map.getNamedItem(name);
if (decl != null) {
String value = decl.getValue();
if (value == null)
return null;
int valueLength = value.length();
if (valueLength > 1 && value.charAt(0) == '&' && value.charAt(1) == '#' && value.charAt(valueLength - 1) == ';') {
// character reference
return getCharValue(value.substring(1, valueLength - 1));
}
return value;
}
}
}
return null;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap in project webtools.sourceediting by eclipse.
the class DOMContentBuilderImpl method visitCMElementDeclaration.
public void visitCMElementDeclaration(CMElementDeclaration ed) {
int forcedMin = (buildOptionalElements(buildPolicy) || alwaysVisit) ? 1 : 0;
int min = Math.max(ed.getMinOccur(), forcedMin);
// a group.
if (!cmGroupStack.isEmpty()) {
CMGroup group = (CMGroup) cmGroupStack.peek();
int gmin = group.getMinOccur();
if (gmin == 0)
if (buildOptionalElements(buildPolicy)) {
/* do nothing: min = min */
} else {
// min = 0
min = min * gmin;
}
else {
min = min * gmin;
}
}
int max = Math.min(ed.getMaxOccur(), getNumOfRepeatableElements());
if (max < min)
max = min;
alwaysVisit = false;
// involved.
if (// leave
buildFirstSubstitution(buildPolicy) || isAbstract(ed)) // this
// for
// backward
// compatibility
// for now
{
// Note - To change so that if ed is optional, we do not
// generate anything here.
ed = getSubstitution(ed);
// Note - the returned ed may be an abstract element in
// which case the xml will be invalid.
}
if (min > 0 && !visitedCMElementDeclarationList.contains(ed)) {
visitedCMElementDeclarationList.add(ed);
for (int i = 1; i <= max; i++) {
// create an Element for each
Element element = null;
if (rootElement != null) {
element = rootElement;
rootElement = null;
} else {
element = createElement(ed, computeName(ed, currentParent), currentParent);
}
// visit the children of the GrammarElement
Node oldParent = currentParent;
currentParent = element;
handlePushParent(element, ed);
namespaceTable.addElement(element);
boolean oldAttachNodesToParent = attachNodesToParent;
attachNodesToParent = true;
// 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
attachNodesToParent = oldAttachNodesToParent;
handlePopParent(element, ed);
currentParent = oldParent;
linkNode(element);
}
int size = visitedCMElementDeclarationList.size();
visitedCMElementDeclarationList.remove(size - 1);
}
}
Aggregations