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 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 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 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); } } }