1 11 package org.eclipse.pde.internal.builders; 12 13 import org.eclipse.core.resources.*; 14 import org.eclipse.core.runtime.*; 15 import org.w3c.dom.*; 16 17 18 public class UpdateSiteErrorReporter extends ManifestErrorReporter { 19 20 private IProgressMonitor fMonitor; 21 22 public UpdateSiteErrorReporter(IFile file) { 23 super(file); 24 } 25 26 29 public void validateContent(IProgressMonitor monitor) { 30 fMonitor = monitor; 31 Element root = getDocumentRoot(); 32 if (root == null) 33 return; 34 String elementName = root.getNodeName(); 35 if (!"site".equals(elementName)) { reportIllegalElement(root, CompilerFlags.ERROR); 37 } else { 38 NamedNodeMap attributes = root.getAttributes(); 39 for (int i = 0; i < attributes.getLength(); i++) { 40 Attr attr = (Attr)attributes.item(i); 41 String name = attr.getName(); 42 if (!name.equals("type") && !name.equals("url") && !name.equals("mirrorsURL")) { reportUnknownAttribute(root, name, CompilerFlags.ERROR); 44 } 45 } 46 validateDescription(root); 47 validateFeatures(root); 48 validateCategoryDefinitions(root); 49 validateArchives(root); 50 } 51 } 52 53 56 private void validateArchives(Element root) { 57 NodeList list = getChildrenByName(root, "archive"); for (int i = 0; i < list.getLength(); i++) { 59 if (fMonitor.isCanceled()) 60 return; 61 Element element = (Element)list.item(i); 62 assertAttributeDefined(element, "path", CompilerFlags.ERROR); assertAttributeDefined(element, "url", CompilerFlags.ERROR); NamedNodeMap attributes = element.getAttributes(); 65 for (int j = 0; j < attributes.getLength(); j++) { 66 Attr attr = (Attr)attributes.item(j); 67 String name = attr.getName(); 68 if (name.equals("url")) { validateURL(element, "url"); } else if (!name.equals("path")) { reportUnknownAttribute(element, name, CompilerFlags.ERROR); 72 } 73 } 74 } 75 } 76 77 80 private void validateCategoryDefinitions(Element root) { 81 NodeList list = getChildrenByName(root, "category-def"); for (int i = 0; i < list.getLength(); i++) { 83 if (fMonitor.isCanceled()) 84 return; 85 Element element = (Element)list.item(i); 86 assertAttributeDefined(element, "name", CompilerFlags.ERROR); assertAttributeDefined(element, "label", CompilerFlags.ERROR); NamedNodeMap attributes = element.getAttributes(); 89 for (int j = 0; j < attributes.getLength(); j++) { 90 Attr attr = (Attr)attributes.item(j); 91 String name = attr.getName(); 92 if (!name.equals("name") && !name.equals("label")) { reportUnknownAttribute(element, name, CompilerFlags.ERROR); 94 } 95 } 96 validateDescription(element); 97 } 98 } 99 100 103 private void validateCategories(Element root) { 104 NodeList list = getChildrenByName(root, "category"); for (int i = 0; i < list.getLength(); i++) { 106 if (fMonitor.isCanceled()) 107 return; 108 Element element = (Element)list.item(i); 109 assertAttributeDefined(element, "name", CompilerFlags.ERROR); NamedNodeMap attributes = element.getAttributes(); 111 for (int j = 0; j < attributes.getLength(); j++) { 112 Attr attr = (Attr)attributes.item(j); 113 String name = attr.getName(); 114 if (!name.equals("name")) { reportUnknownAttribute(element, name, CompilerFlags.ERROR); 116 } 117 } 118 } 119 } 120 121 private void validateFeatures(Element parent) { 122 NodeList list = getChildrenByName(parent, "feature"); for (int i = 0; i < list.getLength(); i++) { 124 Element element = (Element) list.item(i); 125 assertAttributeDefined(element, "url", CompilerFlags.ERROR); NamedNodeMap attributes = element.getAttributes(); 127 for (int j = 0; j < attributes.getLength(); j++) { 128 Attr attr = (Attr) attributes.item(j); 129 String name = attr.getName(); 130 if (name.equals("url")) { validateURL(element, "url"); } else if (name.equals("patch")) { validateBoolean(element, attr); 134 } else if (name.equals("version")) { validateVersionAttribute(element, attr); 136 } else if (!name.equals("type") && !name.equals("id") && !name.equals("os") && !name.equals("ws") && !name.equals("nl") && !name.equals("arch")) { reportUnknownAttribute(element, name, CompilerFlags.ERROR); 140 } 141 } 142 validateCategories(element); 143 } 144 } 145 146 149 private void validateDescription(Element parent) { 150 NodeList list = getChildrenByName(parent, "description"); if (list.getLength() > 0) { 152 if (fMonitor.isCanceled()) 153 return; 154 Element element = (Element)list.item(0); 155 validateElementWithContent((Element)list.item(0), true); 156 if (element.getAttributeNode("url") != null) validateURL(element, "url"); reportExtraneousElements(list, 1); 159 } 160 } 161 162 163 164 } 165 | Popular Tags |