Search in sources :

Example 1 with DTDEntityReferenceContent

use of org.eclipse.wst.dtd.core.internal.emf.DTDEntityReferenceContent in project webtools.sourceediting by eclipse.

the class DTDElementContentImpl method getPathname.

public String getPathname() {
    int cnt = 0;
    DTDObject parent = getGroup();
    if (parent == null) {
        parent = getElement();
    } else {
        DTDGroupContent group = (DTDGroupContent) parent;
        Iterator i = group.getContent().iterator();
        while (i.hasNext()) {
            DTDElementContent content = (DTDElementContent) i.next();
            if (content == this) {
                break;
            }
            if ((content instanceof DTDElementReferenceContent) || (content instanceof DTDEntityReferenceContent)) {
                continue;
            }
            cnt++;
        }
    }
    // $NON-NLS-1$ //$NON-NLS-2$
    return DTDPathnameUtil.makePath(((parent == null) ? "NULL_PARENT" : parent.getPathname()), "Content", null, cnt);
}
Also used : DTDElementContent(org.eclipse.wst.dtd.core.internal.emf.DTDElementContent) DTDGroupContent(org.eclipse.wst.dtd.core.internal.emf.DTDGroupContent) DTDElementReferenceContent(org.eclipse.wst.dtd.core.internal.emf.DTDElementReferenceContent) DTDEntityReferenceContent(org.eclipse.wst.dtd.core.internal.emf.DTDEntityReferenceContent) Iterator(java.util.Iterator) DTDObject(org.eclipse.wst.dtd.core.internal.emf.DTDObject)

Example 2 with DTDEntityReferenceContent

use of org.eclipse.wst.dtd.core.internal.emf.DTDEntityReferenceContent in project webtools.sourceediting by eclipse.

the class DTDPrinter method visitDTDElementContent.

public void visitDTDElementContent(DTDElementContent content) {
    updateStartOffset(content, sb.length());
    // $NON-NLS-1$
    String trailingChars = "";
    if (content instanceof DTDRepeatableContent) {
        DTDRepeatableContent repeatContent = (DTDRepeatableContent) content;
        DTDOccurrenceType occurrenceType = repeatContent.getOccurrence();
        // Integer occurrence = repeatContent.getOccurrence();
        if (occurrenceType != null) {
            int occurType = occurrenceType.getValue();
            if (occurType != DTDOccurrenceType.ONE) {
                if (repeatContent instanceof DTDEntityReferenceContent) {
                    // $NON-NLS-1$
                    sb.append("(");
                    // $NON-NLS-1$
                    trailingChars = ")";
                }
                trailingChars += (char) occurType;
            }
        }
    // end of if ()
    }
    if (content instanceof DTDGroupContent) {
        super.visitDTDElementContent(content);
    } else // end of if ()
    if (content instanceof DTDElementReferenceContent || content instanceof DTDEntityReferenceContent) {
        sb.append(((DTDRepeatableContent) content).unparseRepeatableContent());
    } else // end of if ()
    {
        // handle DTDPCDataContent, DTDAnyContent and DTDEmptyContent here
        sb.append(content.getContentName());
    }
    // end of else
    sb.append(trailingChars);
    updateEndOffset(content, sb.length());
}
Also used : DTDGroupContent(org.eclipse.wst.dtd.core.internal.emf.DTDGroupContent) DTDEntityReferenceContent(org.eclipse.wst.dtd.core.internal.emf.DTDEntityReferenceContent) DTDElementReferenceContent(org.eclipse.wst.dtd.core.internal.emf.DTDElementReferenceContent) DTDRepeatableContent(org.eclipse.wst.dtd.core.internal.emf.DTDRepeatableContent) DTDOccurrenceType(org.eclipse.wst.dtd.core.internal.emf.DTDOccurrenceType)

Example 3 with DTDEntityReferenceContent

use of org.eclipse.wst.dtd.core.internal.emf.DTDEntityReferenceContent 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);
                }
            }
        }
    }
}
Also used : Enumeration(java.util.Enumeration) DTDGroupContent(org.eclipse.wst.dtd.core.internal.emf.DTDGroupContent) DTDEntityReferenceContent(org.eclipse.wst.dtd.core.internal.emf.DTDEntityReferenceContent) DTDPCDataContent(org.eclipse.wst.dtd.core.internal.emf.DTDPCDataContent) CMReferenceNode(org.eclipse.wst.dtd.core.internal.saxparser.CMReferenceNode) DTDElement(org.eclipse.wst.dtd.core.internal.emf.DTDElement) CMGroupNode(org.eclipse.wst.dtd.core.internal.saxparser.CMGroupNode) DTDOccurrenceType(org.eclipse.wst.dtd.core.internal.emf.DTDOccurrenceType) DTDEntity(org.eclipse.wst.dtd.core.internal.emf.DTDEntity) DTDElementReferenceContent(org.eclipse.wst.dtd.core.internal.emf.DTDElementReferenceContent) DTDGroupKind(org.eclipse.wst.dtd.core.internal.emf.DTDGroupKind) CMNode(org.eclipse.wst.dtd.core.internal.saxparser.CMNode) DTDFactory(org.eclipse.wst.dtd.core.internal.emf.DTDFactory) CMBasicNode(org.eclipse.wst.dtd.core.internal.saxparser.CMBasicNode)

Example 4 with DTDEntityReferenceContent

use of org.eclipse.wst.dtd.core.internal.emf.DTDEntityReferenceContent 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);
    }
}
Also used : DTDAnyContent(org.eclipse.wst.dtd.core.internal.emf.DTDAnyContent) DTDGroupContent(org.eclipse.wst.dtd.core.internal.emf.DTDGroupContent) DTDEntityReferenceContent(org.eclipse.wst.dtd.core.internal.emf.DTDEntityReferenceContent) DTDPCDataContent(org.eclipse.wst.dtd.core.internal.emf.DTDPCDataContent) CMReferenceNode(org.eclipse.wst.dtd.core.internal.saxparser.CMReferenceNode) DTDElement(org.eclipse.wst.dtd.core.internal.emf.DTDElement) CMGroupNode(org.eclipse.wst.dtd.core.internal.saxparser.CMGroupNode) DTDEntity(org.eclipse.wst.dtd.core.internal.emf.DTDEntity) DTDOccurrenceType(org.eclipse.wst.dtd.core.internal.emf.DTDOccurrenceType) DTDElementReferenceContent(org.eclipse.wst.dtd.core.internal.emf.DTDElementReferenceContent) DTDGroupKind(org.eclipse.wst.dtd.core.internal.emf.DTDGroupKind) CMNode(org.eclipse.wst.dtd.core.internal.saxparser.CMNode) CMBasicNode(org.eclipse.wst.dtd.core.internal.saxparser.CMBasicNode) DTDEmptyContent(org.eclipse.wst.dtd.core.internal.emf.DTDEmptyContent)

Aggregations

DTDElementReferenceContent (org.eclipse.wst.dtd.core.internal.emf.DTDElementReferenceContent)4 DTDEntityReferenceContent (org.eclipse.wst.dtd.core.internal.emf.DTDEntityReferenceContent)4 DTDGroupContent (org.eclipse.wst.dtd.core.internal.emf.DTDGroupContent)4 DTDOccurrenceType (org.eclipse.wst.dtd.core.internal.emf.DTDOccurrenceType)3 DTDElement (org.eclipse.wst.dtd.core.internal.emf.DTDElement)2 DTDEntity (org.eclipse.wst.dtd.core.internal.emf.DTDEntity)2 DTDGroupKind (org.eclipse.wst.dtd.core.internal.emf.DTDGroupKind)2 DTDPCDataContent (org.eclipse.wst.dtd.core.internal.emf.DTDPCDataContent)2 CMBasicNode (org.eclipse.wst.dtd.core.internal.saxparser.CMBasicNode)2 CMGroupNode (org.eclipse.wst.dtd.core.internal.saxparser.CMGroupNode)2 CMNode (org.eclipse.wst.dtd.core.internal.saxparser.CMNode)2 CMReferenceNode (org.eclipse.wst.dtd.core.internal.saxparser.CMReferenceNode)2 Enumeration (java.util.Enumeration)1 Iterator (java.util.Iterator)1 DTDAnyContent (org.eclipse.wst.dtd.core.internal.emf.DTDAnyContent)1 DTDElementContent (org.eclipse.wst.dtd.core.internal.emf.DTDElementContent)1 DTDEmptyContent (org.eclipse.wst.dtd.core.internal.emf.DTDEmptyContent)1 DTDFactory (org.eclipse.wst.dtd.core.internal.emf.DTDFactory)1 DTDObject (org.eclipse.wst.dtd.core.internal.emf.DTDObject)1 DTDRepeatableContent (org.eclipse.wst.dtd.core.internal.emf.DTDRepeatableContent)1