use of org.eclipse.wst.dtd.core.internal.emf.DTDPCDataContent in project webtools.sourceediting by eclipse.
the class DTDPrinter method visitDTDElement.
public void visitDTDElement(DTDElement element) {
generateComment(element);
updateStartOffset(element, sb.length());
// $NON-NLS-1$
sb.append("<!ELEMENT " + element.getName());
DTDElementContent content = element.getContent();
if (content instanceof DTDPCDataContent || content instanceof DTDElementReferenceContent) {
// $NON-NLS-1$
sb.append(" (");
super.visitDTDElement(element);
// $NON-NLS-1$
sb.append(")");
} else // end of if ()
{
// $NON-NLS-1$
sb.append(" ");
super.visitDTDElement(element);
}
// end of else
endTag();
// -1 for the newline char
updateEndOffset(element, sb.length() - 1);
visitAttributes(element);
}
use of org.eclipse.wst.dtd.core.internal.emf.DTDPCDataContent in project webtools.sourceediting by eclipse.
the class DTDModelBuilder method processGroupContent.
/**
* Add a new group to the current group
*
* @param parent -
* the parent node for this group element
* @param op1Node -
* the group e.g. (a,b)
* @param op2Node -
* set only if called by processCM1op e.g. (a,b)+
*/
void processGroupContent(DTDGroupContent parent, CMGroupNode grpNode) {
Enumeration children = grpNode.getChildren().elements();
DTDFactory factory = getFactory();
while (children.hasMoreElements()) {
CMNode cnode = (CMNode) children.nextElement();
if (cnode instanceof CMGroupNode) {
CMGroupNode gNode = (CMGroupNode) cnode;
DTDGroupContent groupContent = factory.createDTDGroupContent();
DTDGroupKind groupKind = DTDGroupKind.get(computeMofGroupKind(gNode.getGroupKind()));
groupContent.setGroupKind(groupKind);
DTDOccurrenceType occurrenceType = DTDOccurrenceType.get(computeMofOccurrence(gNode));
groupContent.setOccurrence(occurrenceType);
parent.getContent().add(groupContent);
processGroupContent(groupContent, gNode);
} else if (cnode instanceof CMBasicNode) {
CMBasicNode n = (CMBasicNode) cnode;
if (n.getType() == CMNodeType.PCDATA) {
// Create a DTDPCDataContent for a leaf PCData node
//
DTDPCDataContent pcData = factory.createDTDPCDataContent();
// Add #PCDATA to the Group, i.e Mixed content model
parent.getContent().add(pcData);
}
} else if (cnode instanceof CMReferenceNode) {
CMReferenceNode rn = (CMReferenceNode) cnode;
if (rn.getType() == CMNodeType.ELEMENT_REFERENCE) {
// System.out.println("CM Element Ref name: " +
// rn.getName());
//
// Create an DTDElementReference and set its referenced
// element
//
DTDElementReferenceContent elemRef = factory.createDTDElementReferenceContent();
//
// Find the real element for this element references
// If the real element does not yet exist, create it
//
DTDElement anElement = createOrFindElement(rn.getName(), elemRef);
elemRef.setReferencedElement(anElement);
DTDOccurrenceType occurrenceType = DTDOccurrenceType.get(computeMofOccurrence(rn));
elemRef.setOccurrence(occurrenceType);
// Add DTDElementReference to the Group
parent.getContent().add(elemRef);
} else // PE Reference
{
String entityName = rn.getName().trim();
// System.out.println("CM PE Ref name: " + entityName);
DTDEntity anEntity = (DTDEntity) dtdUtil.getPEPool().get(entityName);
if (anEntity != null) {
//
// Create an DTDEntityReference and set its referenced
// element
//
DTDEntityReferenceContent enRef = factory.createDTDEntityReferenceContent();
enRef.setElementReferencedEntity(anEntity);
DTDOccurrenceType occurrenceType = DTDOccurrenceType.get(computeMofOccurrence(rn));
enRef.setOccurrence(occurrenceType);
// Add DTDEntityReference to the Group
parent.getContent().add(enRef);
}
}
}
}
}
use of org.eclipse.wst.dtd.core.internal.emf.DTDPCDataContent in project webtools.sourceediting by eclipse.
the class DTDModelBuilder method finishElementDecl.
// /////////////////////////////////////////////////////////////
//
// Methods for finishing the import of a DTDElement
//
// /////////////////////////////////////////////////////////////
public void finishElementDecl(DTDElement dtdElement, ElementDecl ed) {
dtdElement.setName(ed.getNodeName());
CMNode cmNode = ed.getContentModelNode();
if (ed.getComment() != null) {
dtdElement.setComment(ed.getComment());
}
if (ed.getErrorMessage() != null) {
addErrorMessage(ed.getErrorMessage(), dtdElement);
}
if (cmNode instanceof CMBasicNode) {
CMBasicNode bn = (CMBasicNode) cmNode;
switch(bn.getType()) {
case CMNodeType.EMPTY:
DTDEmptyContent emptyContent = getFactory().createDTDEmptyContent();
dtdElement.setContent(emptyContent);
break;
case CMNodeType.ANY:
DTDAnyContent anyContent = getFactory().createDTDAnyContent();
dtdElement.setContent(anyContent);
break;
case CMNodeType.PCDATA:
DTDPCDataContent pcData = getFactory().createDTDPCDataContent();
dtdElement.setContent(pcData);
}
} else if (cmNode instanceof CMReferenceNode) {
CMReferenceNode rn = (CMReferenceNode) cmNode;
if (rn.getType() == CMNodeType.ENTITY_REFERENCE) {
String entityName = rn.getName().trim();
DTDEntity anEntity = (DTDEntity) dtdUtil.getPEPool().get(entityName);
if (anEntity != null) {
//
// Create an DTDEntityReference and set its referenced
// element
//
DTDEntityReferenceContent enRef = getFactory().createDTDEntityReferenceContent();
enRef.setElementReferencedEntity(anEntity);
DTDOccurrenceType occurrenceType = DTDOccurrenceType.get(computeMofOccurrence(rn));
enRef.setOccurrence(occurrenceType);
dtdElement.setContent(enRef);
} else {
// create default content
DTDEmptyContent emptyContent = getFactory().createDTDEmptyContent();
dtdElement.setContent(emptyContent);
}
} else {
//
// Find the real element for this element references
// If the real element does not yet exist, create it
//
DTDElement anElement = createOrFindElement(rn.getName(), dtdElement);
//
// Create an DTDElementReference and set its referenced
// element
//
DTDElementReferenceContent elemRef = getFactory().createDTDElementReferenceContent();
elemRef.setReferencedElement(anElement);
DTDOccurrenceType occurrenceType = DTDOccurrenceType.get(computeMofOccurrence(rn));
elemRef.setOccurrence(occurrenceType);
// setContent to DTDElementReference
dtdElement.setContent(elemRef);
}
} else if (cmNode instanceof CMGroupNode) {
CMGroupNode grpNode = (CMGroupNode) cmNode;
DTDGroupContent groupContent = getFactory().createDTDGroupContent();
DTDGroupKind groupKind = DTDGroupKind.get(computeMofGroupKind(grpNode.getGroupKind()));
groupContent.setGroupKind(groupKind);
DTDOccurrenceType occurrenceType = DTDOccurrenceType.get(computeMofOccurrence(grpNode));
groupContent.setOccurrence(occurrenceType);
// just use the locator for the element as the closest guess
processGroupContent(groupContent, grpNode);
dtdElement.setContent(groupContent);
} else if (cmNode == null) {
// bad thing happened here, just create a pcdata
DTDEmptyContent emptyContent = getFactory().createDTDEmptyContent();
dtdElement.setContent(emptyContent);
}
}
Aggregations