protected CMElementDeclaration getCMElementDeclaration(
      Element targetElement, List list, String publicId, String systemId) {
    CMElementDeclaration currentED = null;
    try {
      int listSize = list.size();
      for (int i = 0; i < listSize; i++) {
        Element element = (Element) list.get(i);

        final String nodeName = element.getNodeName();

        CMElementDeclaration ed = null;

        // see if the element is a local of the currentED
        //
        if (currentED != null) {
          ed = (CMElementDeclaration) currentED.getLocalElements().getNamedItem(nodeName);
        }

        if (ed == null) {
          CMDocument cmDocument = getCMDocument(publicId, systemId, "XSD"); // $NON-NLS-1$
          if (cmDocument != null) {
            ed = (CMElementDeclaration) cmDocument.getElements().getNamedItem(nodeName);
          }
        }
        currentED = ed;
      }
    } catch (Exception e) {
      Logger.logException(
          "exception locating element declaration for " + targetElement, e); // $NON-NLS-1$
    }

    return currentED;
  }
  protected CMElementDeclaration getCMElementDeclaration(
      Element targetElement, List list, NamespaceTable namespaceTable) {
    CMElementDeclaration currentED = null;
    try {
      int listSize = list.size();
      for (int i = 0; i < listSize; i++) {
        Element element = (Element) list.get(i);

        if (i != 0) {
          namespaceTable.addElement(element);
        }

        String nodeName = element.getNodeName();
        String unprefixedName = DOMNamespaceHelper.getUnprefixedName(nodeName);
        String prefix = DOMNamespaceHelper.getPrefix(nodeName);

        CMElementDeclaration ed = null;

        // see if the element is a local of the currentED
        //
        if (currentED != null) {
          ed = (CMElementDeclaration) currentED.getLocalElements().getNamedItem(unprefixedName);
        }

        if (ed == null) {
          NamespaceInfo namespaceInfo = namespaceTable.getNamespaceInfoForPrefix(prefix);
          if (namespaceInfo != null) {
            CMDocument cmDocument =
                getCMDocument(namespaceInfo.uri, namespaceInfo.locationHint, "XSD"); // $NON-NLS-1$
            if (cmDocument != null) {
              ed = (CMElementDeclaration) cmDocument.getElements().getNamedItem(unprefixedName);
            }
          }
        }
        currentED = ed;

        // handle XSIType
        if (currentED != null) {
          CMElementDeclaration derivedED =
              getDerivedCMElementDeclaration(element, currentED, namespaceTable);
          if (derivedED != null) {
            currentED = derivedED;
          }
        }
      }
    } catch (Exception e) {
      Logger.logException(
          "exception locating element declaration for " + targetElement, e); // $NON-NLS-1$
    }

    return currentED;
  }
 protected void generateEndTag(
     String tagName, Node parentNode, CMElementDeclaration elementDecl, StringBuffer buffer) {
   if (elementDecl == null) {
     return;
   }
   if (elementDecl.getContentType() != CMElementDeclaration.EMPTY) {
     buffer.append("</" + tagName + ">"); // $NON-NLS-2$//$NON-NLS-1$
   }
   return;
 }
 public CMAttributeDeclaration getCMAttributeDeclaration(Attr attr) {
   CMAttributeDeclaration result = null;
   Element element = attr.getOwnerElement();
   if (element != null) {
     CMElementDeclaration ed = getCMElementDeclaration(element);
     if (ed != null) {
       result = (CMAttributeDeclaration) ed.getAttributes().getNamedItem(attr.getName());
       if (result == null) {
         // try to get the unprefixed name
         String name = DOMNamespaceHelper.getUnprefixedName(attr.getName());
         result = (CMAttributeDeclaration) ed.getAttributes().getNamedItem(name);
       }
       if (result == null) {
         // todo... perhaps this is a globally defined attribute...
       }
     }
   }
   return result;
 }
  protected void generateEndTag(
      String tagName, Node parentNode, CMElementDeclaration elementDecl, StringBuffer buffer) {
    if (elementDecl == null) return;
    if (elementDecl instanceof HTMLElementDeclaration) {
      if (((Boolean) elementDecl.getProperty(HTMLCMProperties.IS_JSP)).booleanValue()) {
        if (elementDecl.getContentType() == CMElementDeclaration.EMPTY) return;
      } else {
        String ommission = (String) elementDecl.getProperty(HTMLCMProperties.OMIT_TYPE);
        if (ommission.equals(HTMLCMProperties.Values.OMIT_END)
            || ommission.equals(HTMLCMProperties.Values.OMIT_END_DEFAULT)
            || ommission.equals(HTMLCMProperties.Values.OMIT_END_MUST)) {
          return;
        }
      }
    }

    if (elementDecl.getContentType() == CMElementDeclaration.EMPTY) return;
    buffer.append("</" + tagName + ">"); // $NON-NLS-2$//$NON-NLS-1$
    return;
  }
 protected CMElementDeclaration getDerivedCMElementDeclaration(
     Element element, CMElementDeclaration ed, NamespaceTable namespaceTable) {
   CMElementDeclaration result = null;
   String xsiPrefix =
       namespaceTable.getPrefixForURI("http://www.w3.org/2001/XMLSchema-instance"); // $NON-NLS-1$
   if (xsiPrefix != null) {
     String xsiTypeValue = element.getAttribute(xsiPrefix + ":type"); // $NON-NLS-1$
     if (xsiTypeValue != null && xsiTypeValue.length() > 0) {
       String typePrefix = DOMNamespaceHelper.getPrefix(xsiTypeValue);
       String typeName = DOMNamespaceHelper.getUnprefixedName(xsiTypeValue);
       String typeURI = namespaceTable.getURIForPrefix(typePrefix);
       String uriQualifiedTypeName = typeName;
       if (typeURI != null && typeURI.length() > 0) {
         uriQualifiedTypeName = "[" + typeURI + "]" + typeName; // $NON-NLS-1$ //$NON-NLS-2$
       }
       result =
           (CMElementDeclaration)
               ed.getProperty("DerivedElementDeclaration=" + uriQualifiedTypeName); // $NON-NLS-1$
       if (result == null) {
         String reference = null;
         NamespaceInfo namespaceInfo = namespaceTable.getNamespaceInfoForPrefix(typePrefix);
         if (namespaceInfo != null) {
           String locationHint =
               resolveGrammarURI(
                   element.getOwnerDocument(), namespaceInfo.uri, namespaceInfo.locationHint);
           if (locationHint != null) {
             reference = "[" + locationHint + "]" + typeName; // $NON-NLS-1$ //$NON-NLS-2$
           }
         }
         if (reference != null) {
           result =
               (CMElementDeclaration)
                   ed.getProperty(
                       "ExternallyDerivedElementDeclaration=" + reference); // $NON-NLS-1$
         }
       }
     }
   }
   return result;
 }
 public String getStartTagClose(Node parentNode, CMElementDeclaration elementDecl) {
   String other = getOtherClose(parentNode);
   if (other != null) {
     return other;
   }
   if (elementDecl == null) {
     return ">"; //$NON-NLS-1$
   }
   if (elementDecl.getContentType() == CMElementDeclaration.EMPTY) {
     return "/>"; //$NON-NLS-1$
   }
   return ">"; //$NON-NLS-1$
 }
  public String getStartTagClose(Node parentNode, CMElementDeclaration elementDecl) {
    String other = getOtherClose(parentNode);
    if (other != null) return other;
    if (elementDecl == null) return ">"; // $NON-NLS-1$
    if (elementDecl instanceof HTMLElementDeclaration) {
      if (((Boolean) elementDecl.getProperty(HTMLCMProperties.IS_JSP)).booleanValue()) {
        if (elementDecl.getContentType() == CMElementDeclaration.EMPTY) return "/>"; // $NON-NLS-1$
      } else {
        String ommission = (String) elementDecl.getProperty(HTMLCMProperties.OMIT_TYPE);
        if (ommission.equals(HTMLCMProperties.Values.OMIT_END)
            || ommission.equals(HTMLCMProperties.Values.OMIT_END_DEFAULT)
            || ommission.equals(HTMLCMProperties.Values.OMIT_END_MUST)) {
          return ">"; //$NON-NLS-1$
        }
      }
    }

    // if not an html element and empty, assume start tag needs to be closed
    else if (elementDecl.getContentType() == CMElementDeclaration.EMPTY) {
      return "/>"; //$NON-NLS-1$
    }

    return ">"; //$NON-NLS-1$
  }