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 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 validateJavaAttribute(Element element, Attr attr) {
    String value = attr.getValue();
    IJavaProject javaProject = JavaCore.create(fFile.getProject());

    // be careful: people have the option to use the format:
    // fullqualifiedName:staticMethod
    int index = value.indexOf(":"); // $NON-NLS-1$
    if (index != -1) value = value.substring(0, index);

    // assume we're on the classpath already
    boolean onClasspath = true;
    int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_CLASS);
    if (severity != CompilerFlags.IGNORE && javaProject.isOpen()) {
      onClasspath = PDEJavaHelper.isOnClasspath(value, javaProject);
      if (!onClasspath) {
        report(
            NLS.bind(
                MDECoreMessages.Builders_Manifest_class, (new String[] {value, attr.getName()})),
            getLine(element, attr.getName()),
            severity,
            MDEMarkerFactory.P_UNKNOWN_CLASS,
            element,
            attr.getName() + F_ATT_VALUE_PREFIX + attr.getValue(),
            MDEMarkerFactory.CAT_FATAL);
      }
    }

    severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_DISCOURAGED_CLASS);
    if (severity != CompilerFlags.IGNORE && javaProject.isOpen()) {
      BundleDescription desc = fModel.getBundleDescription();
      if (desc == null) return;
      // only check if we're discouraged if there is something on the classpath
      if (onClasspath && PDEJavaHelper.isDiscouraged(value, javaProject, desc)) {
        report(
            NLS.bind(
                MDECoreMessages.Builders_Manifest_discouragedClass,
                (new String[] {value, attr.getName()})),
            getLine(element, attr.getName()),
            severity,
            MDEMarkerFactory.M_DISCOURAGED_CLASS,
            element,
            attr.getName() + F_ATT_VALUE_PREFIX + attr.getValue(),
            MDEMarkerFactory.CAT_OTHER);
      }
    }
  }
 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);
   }
 }
 protected void validateResourceAttribute(Element element, Attr attr) {
   int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_RESOURCE);
   if (severity != CompilerFlags.IGNORE && !resourceExists(attr.getValue())) {
     report(
         NLS.bind(
             MDECoreMessages.Builders_Manifest_resource,
             (new String[] {attr.getValue(), attr.getName()})),
         getLine(element, attr.getName()),
         severity,
         MDEMarkerFactory.CAT_OTHER);
   }
 }
 /**
  * @param element
  * @param schemaElement
  */
 private void validateMaxElementMult(Element element, ISchemaElement schemaElement) {
   // Validate max element occurence violations
   int maxSeverity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ELEMENT);
   if (maxSeverity != CompilerFlags.IGNORE) {
     HashSet maxElementSet =
         ElementOccurenceChecker.findMaxOccurenceViolations(schemaElement, element);
     Iterator maxIterator = maxElementSet.iterator();
     while (maxIterator.hasNext()) {
       reportMaxOccurenceViolation((ElementOccurrenceResult) maxIterator.next(), maxSeverity);
     }
   }
 }
 private void validateFeatureID(Element element, Attr attr) {
   int severity = CompilerFlags.getFlag(fProject, CompilerFlags.F_UNRESOLVED_FEATURES);
   if (severity != CompilerFlags.IGNORE) {
     IFeatureModel[] models =
         MDECore.getDefault().getFeatureModelManager().findFeatureModels(attr.getValue());
     if (models.length == 0) {
       report(
           NLS.bind(MDECoreMessages.Builders_Feature_freference, attr.getValue()),
           getLine(element, attr.getName()),
           severity,
           MDEMarkerFactory.CAT_OTHER);
     }
   }
 }
  private void validateUnpack(Element parent) {
    int severity = CompilerFlags.getFlag(fProject, CompilerFlags.F_UNRESOLVED_PLUGINS);
    if (severity == CompilerFlags.IGNORE) {
      return;
    }
    if (severity == CompilerFlags.ERROR) {
      // this might not be an error, so max the flag at WARNING level.
      severity = CompilerFlags.WARNING;
    }
    String unpack = parent.getAttribute("unpack"); // $NON-NLS-1$
    IMonitorModelBase pModel = MonitorRegistry.findModel(parent.getAttribute("id")); // $NON-NLS-1$
    if (pModel == null) {
      return;
    }

    if (pModel instanceof IBundlePluginModel) {
      IBundlePluginModel bModel = (IBundlePluginModel) pModel;
      IManifestHeader header =
          bModel
              .getBundleModel()
              .getBundle()
              .getManifestHeader(ICoreConstants.ECLIPSE_BUNDLE_SHAPE);
      if (header != null) {
        String value = header.getValue();
        String unpackValue =
            "true".equals(unpack) ? "jar" : "dir"; // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        if (value != null && !value.equalsIgnoreCase(unpackValue)) {
          String message =
              NLS.bind(
                  MDECoreMessages.Builders_Feature_mismatchUnpackBundleShape,
                  (new String[] {
                    "unpack=" + unpack, parent.getAttribute("id"), "Eclipse-BundleShape: " + value
                  })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
          report(message, getLine(parent), severity, MDEMarkerFactory.CAT_OTHER);
        }
      }
    }

    if ("true".equals(unpack)
        && !CoreUtility.guessUnpack(pModel.getBundleDescription())) { // $NON-NLS-1$
      String message =
          NLS.bind(
              MDECoreMessages.Builders_Feature_missingUnpackFalse,
              (new String[] {
                parent.getAttribute("id"), "unpack=\"false\""
              })); //$NON-NLS-1$ //$NON-NLS-2$
      report(message, getLine(parent), severity, MDEMarkerFactory.CAT_OTHER);
    }
  }
 private void validateExistingExtensionAttributes(
     Element element, NamedNodeMap attrs, ISchemaElement schemaElement) {
   for (int i = 0; i < attrs.getLength(); i++) {
     Attr attr = (Attr) attrs.item(i);
     ISchemaAttribute attInfo = schemaElement.getAttribute(attr.getName());
     if (attInfo == null) {
       HashSet allowedElements = new HashSet();
       computeAllowedElements(schemaElement.getType(), allowedElements);
       if (allowedElements.contains(attr.getName())) {
         validateJavaAttribute(element, attr);
       } else {
         int flag = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_ATTRIBUTE);
         if (flag != CompilerFlags.IGNORE) reportUnknownAttribute(element, attr.getName(), flag);
       }
     } else {
       validateExtensionAttribute(element, attr, attInfo);
     }
   }
 }
  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 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 validateIdentifierAttribute(Element element, Attr attr, ISchemaAttribute attInfo) {
   int severity = CompilerFlags.getFlag(fProject, CompilerFlags.P_UNKNOWN_IDENTIFIER);
   if (severity != CompilerFlags.IGNORE) {
     String value = attr.getValue();
     String basedOn = attInfo.getBasedOn();
     // only validate if we have a valid value and basedOn value
     if (value != null && basedOn != null && value.length() > 0 && basedOn.length() > 0) {
       Map attributes = PDESchemaHelper.getValidAttributes(attInfo);
       if (!attributes.containsKey(value)) { // report error if we are missing something
         report(
             NLS.bind(
                 MDECoreMessages.ExtensionsErrorReporter_unknownIdentifier,
                 (new String[] {attr.getValue(), attr.getName()})),
             getLine(element, attr.getName()),
             severity,
             MDEMarkerFactory.CAT_OTHER);
       }
     }
   }
 }
 private void validatePluginID(Element element, Attr attr, boolean isFragment) {
   String id = attr.getValue();
   if (!validatePluginID(element, attr)) {
     return;
   }
   int severity = CompilerFlags.getFlag(fProject, CompilerFlags.F_UNRESOLVED_PLUGINS);
   if (severity != CompilerFlags.IGNORE) {
     IMonitorModelBase model = MonitorRegistry.findModel(id);
     if (model == null
         || !model.isEnabled()
         || (isFragment && !model.isFragmentModel())
         || (!isFragment && model.isFragmentModel())) {
       report(
           NLS.bind(MDECoreMessages.Builders_Feature_reference, id),
           getLine(element, attr.getName()),
           severity,
           MDEMarkerFactory.CAT_OTHER);
     }
   }
 }
 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);
     }
   }
 }
  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 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);
      }
    }
  }