protected void reportUnusedElement(Element element, int severity) {
   Node parent = element.getParentNode();
   report(
       NLS.bind(
           MDECoreMessages.Builders_Manifest_unused_element,
           (new String[] {element.getNodeName(), parent.getNodeName()})),
       getLine(element),
       severity,
       MDEMarkerFactory.CAT_OTHER);
 }
 /**
  * @param parentElement
  * @param childElement
  * @param severity
  */
 private void reportMaxOccurenceViolation(ElementOccurrenceResult result, int severity) {
   Element childElement = result.getElement();
   String allowedOccurrences = new Integer(result.getAllowedOccurrences()).toString();
   String message =
       NLS.bind(
           MDECoreMessages.ExtensionsErrorReporter_maxOccurrence,
           new String[] {allowedOccurrences, childElement.getNodeName()});
   report(
       message,
       getLine(childElement),
       severity,
       MDEMarkerFactory.P_ILLEGAL_XML_NODE,
       childElement,
       null,
       MDEMarkerFactory.CAT_FATAL);
 }
 protected void validateTranslatableElementContent(Element element) {
   int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_NOT_EXTERNALIZED);
   if (severity == CompilerFlags.IGNORE) return;
   String value = getTextContent(element);
   if (value == null) return;
   if (!value.startsWith("%")) { // $NON-NLS-1$
     report(
         NLS.bind(MDECoreMessages.Builders_Manifest_non_ext_element, element.getNodeName()),
         getLine(element),
         severity,
         MDEMarkerFactory.P_UNTRANSLATED_NODE,
         element,
         null,
         MDEMarkerFactory.CAT_NLS);
   } else if (fModel instanceof AbstractNLModel) {
     NLResourceHelper helper = ((AbstractNLModel) fModel).getNLResourceHelper();
     if (helper == null || !helper.resourceExists(value)) {
       report(
           NLS.bind(MDECoreMessages.Builders_Manifest_key_not_found, value.substring(1)),
           getLine(element),
           severity,
           MDEMarkerFactory.CAT_NLS);
     }
   }
 }
 protected void reportDeprecatedElement(Element element) {
   int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_DEPRECATED);
   if (severity != CompilerFlags.IGNORE) {
     report(
         NLS.bind(MDECoreMessages.Builders_Manifest_deprecated_element, element.getNodeName()),
         getLine(element),
         severity,
         MDEMarkerFactory.CAT_DEPRECATION);
   }
 }
  private void validateRequiredExtensionAttributes(Element element, ISchemaElement schemaElement) {
    int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_NO_REQUIRED_ATT);
    if (severity == CompilerFlags.IGNORE) return;

    ISchemaAttribute[] attInfos = schemaElement.getAttributes();
    for (int i = 0; i < attInfos.length; i++) {
      ISchemaAttribute attInfo = attInfos[i];
      if (attInfo.getUse() == ISchemaAttribute.REQUIRED) {
        boolean found = element.getAttributeNode(attInfo.getName()) != null;
        if (!found && attInfo.getKind() == IMetaAttribute.JAVA) {
          NodeList children = element.getChildNodes();
          for (int j = 0; j < children.getLength(); j++) {
            if (attInfo.getName().equals(children.item(j).getNodeName())) {
              found = true;
              break;
            }
          }
        }
        if (!found) {
          reportMissingRequiredAttribute(element, attInfo.getName(), severity);
        }
      }
    }
  }
 protected void reportDeprecatedRootElement(Element element, String suggestion) {
   int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_DEPRECATED);
   if (severity != CompilerFlags.IGNORE) {
     String point = element.getAttribute("point"); // $NON-NLS-1$
     if (point == null) return; // should never come to this...
     String message;
     if (suggestion != null)
       message =
           NLS.bind(
               MDECoreMessages.Builders_Manifest_deprecated_rootElementSuggestion,
               point,
               suggestion);
     else message = NLS.bind(MDECoreMessages.Builders_Manifest_deprecated_rootElement, point);
     report(
         message,
         getLine(element, "point"),
         severity,
         MDEMarkerFactory.CAT_DEPRECATION); // $NON-NLS-1$
   }
 }
  private void validateInternalExtensionAttribute(Element element, ISchemaElement schemaElement) {
    int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_INTERNAL);
    if (severity == CompilerFlags.IGNORE) return;

    if (schemaElement instanceof ISchemaRootElement) {
      ISchemaRootElement rootElement = (ISchemaRootElement) schemaElement;
      String epid = schemaElement.getSchema().getPluginId();
      String pid = fModel.getMonitorBase().getId();
      if (epid == null || pid == null) return;
      if (rootElement.isInternal() && !epid.equals(pid)) {
        String point = element.getAttribute("point"); // $NON-NLS-1$
        if (point == null) return; // should never come to this...
        report(
            NLS.bind(MDECoreMessages.Builders_Manifest_internal_rootElement, point),
            getLine(element, "point"),
            severity,
            MDEMarkerFactory.CAT_DEPRECATION); // $NON-NLS-1$
      }
    }
  }
 protected void validateExtension(Element element) {
   if (!assertAttributeDefined(element, "point", CompilerFlags.ERROR)) // $NON-NLS-1$
   return;
   String pointID = element.getAttribute("point"); // $NON-NLS-1$
   if (!MDECore.getDefault().getExtensionsRegistry().hasExtensionPoint(pointID)) {
     int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNRESOLVED_EX_POINTS);
     if (severity != CompilerFlags.IGNORE) {
       report(
           NLS.bind(MDECoreMessages.Builders_Manifest_ex_point, pointID),
           getLine(element, "point"),
           severity,
           MDEMarkerFactory.CAT_OTHER); // $NON-NLS-1$
     }
   } else {
     SchemaRegistry reg = MDECore.getDefault().getSchemaRegistry();
     ISchema schema = reg.getSchema(pointID);
     if (schema != null) {
       validateElement(element, schema, true);
     }
   }
 }
  public void validateContent(IProgressMonitor monitor) {
    Element element = getDocumentRoot();
    if (element == null) return;
    String elementName = element.getNodeName();
    if (!"plugin".equals(elementName)
        && !"fragment".equals(elementName)) { // $NON-NLS-1$ //$NON-NLS-2$
      reportIllegalElement(element, CompilerFlags.ERROR);
    } else {
      int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_DEPRECATED);
      if (severity != CompilerFlags.IGNORE) {
        NamedNodeMap attrs = element.getAttributes();
        for (int i = 0; i < attrs.getLength(); i++) {
          reportUnusedAttribute(element, attrs.item(i).getNodeName(), severity);
        }
      }

      NodeList children = element.getChildNodes();
      for (int i = 0; i < children.getLength(); i++) {
        if (monitor.isCanceled()) break;
        Element child = (Element) children.item(i);
        String name = child.getNodeName();
        if (name.equals("extension")) { // $NON-NLS-1$
          validateExtension(child);
        } else if (name.equals("extension-point")) { // $NON-NLS-1$
          validateExtensionPoint(child);
        } else {
          if (!name.equals("runtime") && !name.equals("requires")) { // $NON-NLS-1$ //$NON-NLS-2$
            severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ELEMENT);
            if (severity != CompilerFlags.IGNORE) reportIllegalElement(child, severity);
          } else {
            severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_DEPRECATED);
            if (severity != CompilerFlags.IGNORE) reportUnusedElement(child, severity);
          }
        }
      }

      IExtensions extensions = fModel.getExtensions();
      if (extensions != null
          && extensions.getExtensions().length == 0
          && extensions.getExtensionPoints().length == 0)
        report(
            MDECoreMessages.Builders_Manifest_useless_file,
            -1,
            IMarker.SEVERITY_WARNING,
            MDEMarkerFactory.P_USELESS_FILE,
            MDEMarkerFactory.CAT_OTHER);
    }
  }
  protected void validateExtensionPoint(Element element) {
    if (assertAttributeDefined(element, "id", CompilerFlags.ERROR)) { // $NON-NLS-1$
      Attr idAttr = element.getAttributeNode("id"); // $NON-NLS-1$
      double schemaVersion = getSchemaVersion();
      String message = null;
      if (schemaVersion < 3.2 && !IdUtil.isValidSimpleID(idAttr.getValue()))
        message = NLS.bind(MDECoreMessages.Builders_Manifest_simpleID, idAttr.getValue());
      else if (schemaVersion >= 3.2) {
        if (!IdUtil.isValidCompositeID(idAttr.getValue())) {
          message = NLS.bind(MDECoreMessages.Builders_Manifest_compositeID, idAttr.getValue());
        }
      }

      if (message != null)
        report(
            message,
            getLine(element, idAttr.getName()),
            CompilerFlags.WARNING,
            MDEMarkerFactory.CAT_OTHER);
    }

    assertAttributeDefined(element, "name", CompilerFlags.ERROR); // $NON-NLS-1$

    int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ATTRIBUTE);
    NamedNodeMap attrs = element.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
      Attr attr = (Attr) attrs.item(i);
      String name = attr.getName();
      if ("name".equals(name)) { // $NON-NLS-1$
        validateTranslatableString(element, attr, true);
      } else if (!"id".equals(name)
          && !"schema".equals(name)
          && severity != CompilerFlags.IGNORE) { // $NON-NLS-1$ //$NON-NLS-2$
        reportUnknownAttribute(element, name, severity);
      }
    }

    severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ELEMENT);
    if (severity != CompilerFlags.IGNORE) {
      NodeList children = element.getChildNodes();
      for (int i = 0; i < children.getLength(); i++)
        reportIllegalElement((Element) children.item(i), severity);
    }

    // Validate the "schema" attribute of the extension point
    Attr attr = element.getAttributeNode(IMonitorExtensionPoint.P_SCHEMA);
    // Only validate the attribute if it was defined
    if (attr != null) {
      String schemaValue = attr.getValue();
      IResource res = getFile().getProject().findMember(schemaValue);
      String errorMessage = null;
      // Check to see if the value specified is an extension point schema and it exists
      if (!(res instanceof IFile
          && (res.getName().endsWith(".exsd")
              || //$NON-NLS-1$
              res.getName().endsWith(".mxsd")))) // $NON-NLS-1$
      errorMessage = MDECoreMessages.ExtensionsErrorReporter_InvalidSchema;
      // Report an error if one was found
      if (errorMessage != null) {
        severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_RESOURCE);
        if (severity != CompilerFlags.IGNORE)
          report(
              NLS.bind(errorMessage, schemaValue),
              getLine(element),
              severity,
              MDEMarkerFactory.CAT_OTHER);
      }
    }
  }
  protected void validateElement(Element element, ISchema schema, boolean isTopLevel) {
    String elementName = element.getNodeName();
    ISchemaElement schemaElement = schema.findElement(elementName);

    // Validate element occurrence violations
    if ((schemaElement != null) && (schemaElement.getType() instanceof ISchemaComplexType)) {
      validateMaxElementMult(element, schemaElement);
      validateMinElementMult(element, schemaElement);
    }

    ISchemaElement parentSchema = null;
    if (!"extension".equals(elementName)) { // $NON-NLS-1$
      Node parent = element.getParentNode();
      parentSchema = schema.findElement(parent.getNodeName());
    } else if (isTopLevel == false) {
      // This is an "extension" element; but, not a top level one.
      // It is nested within another "extension" element somewhere
      // e.g. "extension" element is a child element of another element
      // that is not a "plugin" elment
      // element
      // Report illegal element
      int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ELEMENT);
      reportIllegalElement(element, severity);
      return;
    }

    if (parentSchema != null) {
      int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ELEMENT);
      if (severity != CompilerFlags.IGNORE) {
        HashSet allowedElements = new HashSet();
        computeAllowedElements(parentSchema.getType(), allowedElements);
        if (!allowedElements.contains(elementName)) {
          reportIllegalElement(element, severity);
          return;
        }
      }
    }
    if (schemaElement == null && parentSchema != null) {
      ISchemaAttribute attr = parentSchema.getAttribute(elementName);
      if (attr != null && attr.getKind() == IMetaAttribute.JAVA) {
        if (attr.isDeprecated())
          reportDeprecatedAttribute(element, element.getAttributeNode("class")); // $NON-NLS-1$
        validateJavaAttribute(element, element.getAttributeNode("class")); // $NON-NLS-1$			
      }
    } else {
      if (schemaElement != null) {
        validateRequiredExtensionAttributes(element, schemaElement);
        validateExistingExtensionAttributes(element, element.getAttributes(), schemaElement);
        validateInternalExtensionAttribute(element, schemaElement);
        if (schemaElement.isDeprecated()) {
          if (schemaElement instanceof ISchemaRootElement)
            reportDeprecatedRootElement(
                element, ((ISchemaRootElement) schemaElement).getDeprecatedSuggestion());
          else reportDeprecatedElement(element);
        }
        if (schemaElement.hasTranslatableContent()) validateTranslatableElementContent(element);
        // Bug 213457 - look up elements based on the schema in which the parent is found
        schema = schemaElement.getSchema();
      }
      NodeList children = element.getChildNodes();
      for (int i = 0; i < children.getLength(); i++) {
        validateElement((Element) children.item(i), schema, false);
      }
    }
  }