private void validateRequires(Element parent) { NodeList list = getChildrenByName(parent, "requires"); // $NON-NLS-1$ if (list.getLength() > 0) { validateImports((Element) list.item(0)); reportExtraneousElements(list, 1); } }
/** @param element */ private void validatePlugins(Element parent) { NodeList list = getChildrenByName(parent, "plugin"); // $NON-NLS-1$ for (int i = 0; i < list.getLength(); i++) { if (fMonitor.isCanceled()) return; Element plugin = (Element) list.item(i); assertAttributeDefined(plugin, "id", CompilerFlags.ERROR); // $NON-NLS-1$ assertAttributeDefined(plugin, "version", CompilerFlags.ERROR); // $NON-NLS-1$ NamedNodeMap attributes = plugin.getAttributes(); boolean isFragment = plugin.getAttribute("fragment").equals("true"); // $NON-NLS-1$ //$NON-NLS-2$ for (int j = 0; j < attributes.getLength(); j++) { Attr attr = (Attr) attributes.item(j); String name = attr.getName(); if (name.equals("id")) { // $NON-NLS-1$ validatePluginID(plugin, attr, isFragment); } else if (name.equals("version")) { // $NON-NLS-1$ validateVersionAttribute(plugin, attr); validateVersion(plugin, attr); } else if (name.equals("fragment") || name.equals("unpack")) { // $NON-NLS-1$ //$NON-NLS-2$ validateBoolean(plugin, attr); } else if (!name.equals("os") && !name.equals("ws") && !name.equals("nl") // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ && !name.equals("arch") && !name.equals("download-size") // $NON-NLS-1$ //$NON-NLS-2$ && !name.equals("install-size") && !name.equals("filter")) { // $NON-NLS-1$ //$NON-NLS-2$ reportUnknownAttribute(plugin, name, CompilerFlags.ERROR); } } validateUnpack(plugin); } }
private void validateImports(Element parent) { NodeList list = getChildrenByName(parent, "import"); // $NON-NLS-1$ for (int i = 0; i < list.getLength(); i++) { if (fMonitor.isCanceled()) return; Element element = (Element) list.item(i); Attr plugin = element.getAttributeNode("plugin"); // $NON-NLS-1$ Attr feature = element.getAttributeNode("feature"); // $NON-NLS-1$ if (plugin == null && feature == null) { assertAttributeDefined(element, "plugin", CompilerFlags.ERROR); // $NON-NLS-1$ } else if (plugin != null && feature != null) { reportExclusiveAttributes( element, "plugin", "feature", CompilerFlags.ERROR); // $NON-NLS-1$//$NON-NLS-2$ } else if (plugin != null) { validatePluginID(element, plugin, false); } else if (feature != null) { validateFeatureID(element, feature); } NamedNodeMap attributes = element.getAttributes(); for (int j = 0; j < attributes.getLength(); j++) { Attr attr = (Attr) attributes.item(j); String name = attr.getName(); if (name.equals("version")) { // $NON-NLS-1$ validateVersionAttribute(element, attr); } else if (name.equals("match")) { // $NON-NLS-1$ if (element.getAttributeNode("patch") != null) { // $NON-NLS-1$ report( NLS.bind(MDECoreMessages.Builders_Feature_patchedMatch, attr.getValue()), getLine(element, attr.getValue()), CompilerFlags.ERROR, MDEMarkerFactory.CAT_FATAL); } else { validateMatch(element, attr); } } else if (name.equals("patch")) { // $NON-NLS-1$ if ("true".equalsIgnoreCase(attr.getValue()) && feature == null) { // $NON-NLS-1$ report( NLS.bind(MDECoreMessages.Builders_Feature_patchPlugin, attr.getValue()), getLine(element, attr.getValue()), CompilerFlags.ERROR, MDEMarkerFactory.CAT_FATAL); } else if ("true".equalsIgnoreCase(attr.getValue()) && element.getAttributeNode("version") == null) { // $NON-NLS-1$ //$NON-NLS-2$ report( NLS.bind(MDECoreMessages.Builders_Feature_patchedVersion, attr.getValue()), getLine(element, attr.getValue()), CompilerFlags.ERROR, MDEMarkerFactory.CAT_FATAL); } else { validateBoolean(element, attr); } } else if (!name.equals("plugin") && !name.equals("feature") && !name.equals("filter")) { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ reportUnknownAttribute(element, name, CompilerFlags.ERROR); } } } }
private void validateURLElement(Element parent) { NodeList list = getChildrenByName(parent, "url"); // $NON-NLS-1$ if (list.getLength() > 0) { Element url = (Element) list.item(0); validateUpdateURL(url); validateDiscoveryURL(url); reportExtraneousElements(list, 1); } }
private void validateInstallHandler(Element element) { NodeList elements = getChildrenByName(element, "install-handler"); // $NON-NLS-1$ if (elements.getLength() > 0) { if (fMonitor.isCanceled()) return; Element handler = (Element) elements.item(0); NamedNodeMap attributes = handler.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { String name = attributes.item(i).getNodeName(); if (!name.equals("library") && !name.equals("handler")) // $NON-NLS-1$ //$NON-NLS-2$ reportUnknownAttribute(handler, name, CompilerFlags.ERROR); } reportExtraneousElements(elements, 1); } }
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); } }
private void validateUpdateURL(Element parent) { NodeList list = getChildrenByName(parent, "update"); // $NON-NLS-1$ if (list.getLength() > 0) { if (fMonitor.isCanceled()) return; Element update = (Element) list.item(0); assertAttributeDefined(update, "url", CompilerFlags.ERROR); // $NON-NLS-1$ NamedNodeMap attributes = update.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { String name = attributes.item(i).getNodeName(); if (name.equals("url")) { // $NON-NLS-1$ validateURL(update, "url"); // $NON-NLS-1$ } else if (!name.equals("label")) { // $NON-NLS-1$ reportUnknownAttribute(update, name, CompilerFlags.ERROR); } } reportExtraneousElements(list, 1); } }
private void validateDescription(Element parent) { NodeList list = getChildrenByName(parent, "description"); // $NON-NLS-1$ if (list.getLength() > 0) { if (fMonitor.isCanceled()) return; Element element = (Element) list.item(0); validateElementWithContent((Element) list.item(0), true); NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Attr attr = (Attr) attributes.item(i); String name = attr.getName(); if (name.equals("url")) { // $NON-NLS-1$ validateURL(element, name); } else { reportUnknownAttribute(element, name, CompilerFlags.ERROR); } } reportExtraneousElements(list, 1); } }
private void validateIncludes(Element parent) { NodeList list = getChildrenByName(parent, "includes"); // $NON-NLS-1$ for (int i = 0; i < list.getLength(); i++) { if (fMonitor.isCanceled()) return; Element include = (Element) list.item(i); if (assertAttributeDefined(include, "id", CompilerFlags.ERROR) // $NON-NLS-1$ && assertAttributeDefined( include, "version", //$NON-NLS-1$ CompilerFlags.ERROR)) { validateFeatureID(include, include.getAttributeNode("id")); // $NON-NLS-1$ } NamedNodeMap attributes = include.getAttributes(); for (int j = 0; j < attributes.getLength(); j++) { Attr attr = (Attr) attributes.item(j); String name = attr.getName(); if (name.equals("version")) { // $NON-NLS-1$ validateVersionAttribute(include, attr); } else if (name.equals("optional")) { // $NON-NLS-1$ validateBoolean(include, attr); } else if (name.equals("search-location")) { // $NON-NLS-1$ String value = include.getAttribute("search-location"); // $NON-NLS-1$ if (!value.equals("root") && !value.equals("self") && !value.equals("both")) { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ reportIllegalAttributeValue(include, attr); } } else if (!name.equals("id") && !name.equals("name") && !name.equals("os") && !name.equals("ws") // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ && !name.equals("nl") && !name.equals("arch") && !name.equals("filter")) { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ reportUnknownAttribute(include, name, CompilerFlags.ERROR); } } } }
private void validateData(Element parent) { NodeList list = getChildrenByName(parent, "data"); // $NON-NLS-1$ for (int i = 0; i < list.getLength(); i++) { if (fMonitor.isCanceled()) return; Element data = (Element) list.item(i); assertAttributeDefined(data, "id", CompilerFlags.ERROR); // $NON-NLS-1$ NamedNodeMap attributes = data.getAttributes(); for (int j = 0; j < attributes.getLength(); j++) { Attr attr = (Attr) attributes.item(j); String name = attr.getName(); if (!name.equals("id") && !name.equals("os") && !name.equals("ws") // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ && !name.equals("nl") && !name.equals("arch") // $NON-NLS-1$ //$NON-NLS-2$ && !name.equals("download-size") && !name.equals("install-size")) { // $NON-NLS-1$ //$NON-NLS-2$ reportUnknownAttribute(data, name, CompilerFlags.ERROR); } } } }
private void validateDiscoveryURL(Element parent) { NodeList list = getChildrenByName(parent, "discovery"); // $NON-NLS-1$ if (list.getLength() > 0) { if (fMonitor.isCanceled()) return; Element discovery = (Element) list.item(0); assertAttributeDefined(discovery, "url", CompilerFlags.ERROR); // $NON-NLS-1$ NamedNodeMap attributes = discovery.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { String name = attributes.item(i).getNodeName(); if (name.equals("url")) { // $NON-NLS-1$ validateURL(discovery, "url"); // $NON-NLS-1$ } else if (name.equals("type")) { // $NON-NLS-1$ String value = discovery.getAttribute("type"); // $NON-NLS-1$ if (!value.equals("web") && !value.equals("update")) { // $NON-NLS-1$ //$NON-NLS-2$ reportIllegalAttributeValue(discovery, (Attr) attributes.item(i)); } reportDeprecatedAttribute(discovery, discovery.getAttributeNode("type")); // $NON-NLS-1$ } else if (!name.equals("label")) { // $NON-NLS-1$ reportUnknownAttribute(discovery, name, CompilerFlags.ERROR); } } } }
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); } } }