Search in sources :

Example 6 with DTDElement

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

the class DTDModelBuilder method createOrFindElement.

/**
 * Find the real element that is referenced by the current element
 */
private DTDElement createOrFindElement(String name, Object obj) {
    // DTDElement aElement = getDTDFile().findElement(name);
    DTDElement aElement = (DTDElement) dtdUtil.getElementPool().get(name);
    if (aElement != null) {
        return aElement;
    }
    // $NON-NLS-1$
    String errorMsg = DTDCoreMessages._ERROR_UNDECLARED_ELEMENT_1;
    // $NON-NLS-1$ //$NON-NLS-2$
    errorMsg += "\"" + name + "\"";
    // $NON-NLS-1$
    errorMsg += DTDCoreMessages._UI_ERRORPART_UNDECLARED_ELEMENT_2;
    ErrorMessage dtdError = new ErrorMessage();
    dtdError.setErrorMessage(errorMsg);
    addErrorMessage(dtdError, obj);
    // System.out.println(errorMsg);
    // setDTDErrorMessage(errorMsg);
    getDTDFile().setParseError(true);
    // 
    // Create an empty element for the reference to make it valid
    // 
    DTDFactory factory = getFactory();
    DTDElement dtdelement = factory.createDTDElement();
    dtdelement.setName(name);
    DTDEmptyContent emptyContent = factory.createDTDEmptyContent();
    dtdelement.setContent(emptyContent);
    getDTDFile().getDTDObject().add(dtdelement);
    dtdUtil.getElementPool().put(name, dtdelement);
    return dtdelement;
}
Also used : DTDElement(org.eclipse.wst.dtd.core.internal.emf.DTDElement) ErrorMessage(org.eclipse.wst.dtd.core.internal.saxparser.ErrorMessage) DTDFactory(org.eclipse.wst.dtd.core.internal.emf.DTDFactory) DTDEmptyContent(org.eclipse.wst.dtd.core.internal.emf.DTDEmptyContent)

Example 7 with DTDElement

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

the class DTDModelBuilder method hasIDAttribute.

public boolean hasIDAttribute(DTDAttribute dtdattr) {
    boolean hasID = false;
    DTDElement element = dtdattr.getDTDElement();
    EList attrs = element.getDTDAttribute();
    Iterator i = attrs.iterator();
    while (i.hasNext()) {
        DTDAttribute attr = (DTDAttribute) i.next();
        DTDType dType = attr.getDTDType();
        if (dType instanceof DTDBasicType) {
            if (((DTDBasicType) dType).getKind().getValue() == DTDBasicTypeKind.ID) {
                hasID = true;
                break;
            }
        }
    }
    return hasID;
}
Also used : EList(org.eclipse.emf.common.util.EList) DTDBasicType(org.eclipse.wst.dtd.core.internal.emf.DTDBasicType) Iterator(java.util.Iterator) DTDElement(org.eclipse.wst.dtd.core.internal.emf.DTDElement) DTDType(org.eclipse.wst.dtd.core.internal.emf.DTDType) DTDAttribute(org.eclipse.wst.dtd.core.internal.emf.DTDAttribute)

Example 8 with DTDElement

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

the class DTDModelBuilder method addAttlistAndContentModel.

private void addAttlistAndContentModel(DTD dtd, DTDFile dFile) {
    // System.out.println("addAttListAndCotentModel - dtd:" +
    // dtd.getName());
    Enumeration en = dtd.externalElements();
    while (en.hasMoreElements()) {
        Object e = en.nextElement();
        if (e instanceof ElementDecl) {
            DTDElement dtdelement = (DTDElement) dtdUtil.getElementPool().get(((ElementDecl) e).getNodeName());
            if (dtdelement == null) {
                dtdelement = getFactory().createDTDElement();
                dtdFile.getDTDObject().add(dtdelement);
            }
            finishElementDecl(dtdelement, (ElementDecl) e);
        } else if (e instanceof Attlist) {
            processAttList((Attlist) e);
        }
    }
}
Also used : Enumeration(java.util.Enumeration) Attlist(org.eclipse.wst.dtd.core.internal.saxparser.Attlist) DTDElement(org.eclipse.wst.dtd.core.internal.emf.DTDElement) ElementDecl(org.eclipse.wst.dtd.core.internal.saxparser.ElementDecl)

Example 9 with DTDElement

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

the class DTDUtil method getName.

// This gets the name with pseudo namespace prefixes if dtdFile is not
// null
public static String getName(DTDObject obj, DTDFile dtdFile) {
    // $NON-NLS-1$
    String name = "";
    if (obj instanceof DTDEntity) {
        DTDEntity entity = (DTDEntity) obj;
        if (dtdFile != null && !entity.getDTDFile().equals(dtdFile)) {
            // $NON-NLS-1$
            name = new Path(entity.getDTDFile().getName()).lastSegment() + ": ";
        }
        // $NON-NLS-1$ //$NON-NLS-2$
        name += "%" + ((DTDEntity) obj).getName() + ";";
    } else if (obj instanceof DTDElement) {
        DTDElement element = (DTDElement) obj;
        if (dtdFile != null && !element.getDTDFile().equals(dtdFile)) {
            // $NON-NLS-1$
            name = new Path(element.getDTDFile().getName()).lastSegment() + ": ";
        }
        name += ((DTDElement) obj).getName();
    } else if (obj instanceof DTDElementContent) {
        return ((DTDElementContent) obj).getContentName();
    }
    return name;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) DTDElementContent(org.eclipse.wst.dtd.core.internal.emf.DTDElementContent) DTDElement(org.eclipse.wst.dtd.core.internal.emf.DTDElement) DTDEntity(org.eclipse.wst.dtd.core.internal.emf.DTDEntity)

Example 10 with DTDElement

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

the class DTDModelBuilder method visitElementDecl.

public void visitElementDecl(ElementDecl element) {
    // Element might have been added earlier because it is referenced
    String declName = element.getNodeName();
    // System.out.println("process ElementDecl:" + declName );
    DTDElement dtdelement = (DTDElement) dtdUtil.getElementPool().get(declName);
    if (dtdelement == null) {
        // System.out.println("process ElementDecl - not found - create"
        // );
        dtdelement = getFactory().createDTDElement();
        dtdelement.setName(declName);
        dtdFile.getDTDObject().add(dtdelement);
        dtdUtil.getElementPool().put(declName, dtdelement);
    }
    super.visitElementDecl(element);
}
Also used : DTDElement(org.eclipse.wst.dtd.core.internal.emf.DTDElement)

Aggregations

DTDElement (org.eclipse.wst.dtd.core.internal.emf.DTDElement)16 Iterator (java.util.Iterator)5 Collection (java.util.Collection)4 DTDElementReferenceContent (org.eclipse.wst.dtd.core.internal.emf.DTDElementReferenceContent)4 DTDEntity (org.eclipse.wst.dtd.core.internal.emf.DTDEntity)3 DTDGroupContent (org.eclipse.wst.dtd.core.internal.emf.DTDGroupContent)3 Enumeration (java.util.Enumeration)2 Hashtable (java.util.Hashtable)2 Vector (java.util.Vector)2 DTDEmptyContent (org.eclipse.wst.dtd.core.internal.emf.DTDEmptyContent)2 DTDEntityReferenceContent (org.eclipse.wst.dtd.core.internal.emf.DTDEntityReferenceContent)2 DTDFactory (org.eclipse.wst.dtd.core.internal.emf.DTDFactory)2 DTDGroupKind (org.eclipse.wst.dtd.core.internal.emf.DTDGroupKind)2 DTDObject (org.eclipse.wst.dtd.core.internal.emf.DTDObject)2 DTDOccurrenceType (org.eclipse.wst.dtd.core.internal.emf.DTDOccurrenceType)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