1 11 package org.eclipse.pde.internal.core.builders; 12 13 import org.eclipse.core.resources.IFile; 14 import org.eclipse.core.runtime.IProgressMonitor; 15 import org.w3c.dom.Attr ; 16 import org.w3c.dom.Element ; 17 import org.w3c.dom.NamedNodeMap ; 18 import org.w3c.dom.NodeList ; 19 20 21 public class UpdateSiteErrorReporter extends ManifestErrorReporter { 22 23 private IProgressMonitor fMonitor; 24 25 public UpdateSiteErrorReporter(IFile file) { 26 super(file); 27 } 28 29 32 public void validateContent(IProgressMonitor monitor) { 33 fMonitor = monitor; 34 Element root = getDocumentRoot(); 35 if (root == null) 36 return; 37 String elementName = root.getNodeName(); 38 if (!"site".equals(elementName)) { reportIllegalElement(root, CompilerFlags.ERROR); 40 } else { 41 NamedNodeMap attributes = root.getAttributes(); 42 for (int i = 0; i < attributes.getLength(); i++) { 43 Attr attr = (Attr )attributes.item(i); 44 String name = attr.getName(); 45 if (!name.equals("type") && !name.equals("url") && !name.equals("mirrorsURL") && !name.equals("digestURL") && !name.equals("pack200") && !name.equals("availableLocales") && !name.equals("associateSitesURL")) { reportUnknownAttribute(root, name, CompilerFlags.ERROR); 53 } 54 } 55 validateDescription(root); 56 validateFeatures(root); 57 validateCategoryDefinitions(root); 58 validateArchives(root); 59 } 60 } 61 62 65 private void validateArchives(Element root) { 66 NodeList list = getChildrenByName(root, "archive"); for (int i = 0; i < list.getLength(); i++) { 68 if (fMonitor.isCanceled()) 69 return; 70 Element element = (Element )list.item(i); 71 assertAttributeDefined(element, "path", CompilerFlags.ERROR); assertAttributeDefined(element, "url", CompilerFlags.ERROR); NamedNodeMap attributes = element.getAttributes(); 74 for (int j = 0; j < attributes.getLength(); j++) { 75 Attr attr = (Attr )attributes.item(j); 76 String name = attr.getName(); 77 if (name.equals("url")) { validateURL(element, "url"); } else if (!name.equals("path")) { reportUnknownAttribute(element, name, CompilerFlags.ERROR); 81 } 82 } 83 } 84 } 85 86 89 private void validateCategoryDefinitions(Element root) { 90 NodeList list = getChildrenByName(root, "category-def"); for (int i = 0; i < list.getLength(); i++) { 92 if (fMonitor.isCanceled()) 93 return; 94 Element element = (Element )list.item(i); 95 assertAttributeDefined(element, "name", CompilerFlags.ERROR); assertAttributeDefined(element, "label", CompilerFlags.ERROR); NamedNodeMap attributes = element.getAttributes(); 98 for (int j = 0; j < attributes.getLength(); j++) { 99 Attr attr = (Attr )attributes.item(j); 100 String name = attr.getName(); 101 if (!name.equals("name") && !name.equals("label")) { reportUnknownAttribute(element, name, CompilerFlags.ERROR); 103 } 104 } 105 validateDescription(element); 106 } 107 } 108 109 112 private void validateCategories(Element root) { 113 NodeList list = getChildrenByName(root, "category"); for (int i = 0; i < list.getLength(); i++) { 115 if (fMonitor.isCanceled()) 116 return; 117 Element element = (Element )list.item(i); 118 assertAttributeDefined(element, "name", CompilerFlags.ERROR); NamedNodeMap attributes = element.getAttributes(); 120 for (int j = 0; j < attributes.getLength(); j++) { 121 Attr attr = (Attr )attributes.item(j); 122 String name = attr.getName(); 123 if (!name.equals("name")) { reportUnknownAttribute(element, name, CompilerFlags.ERROR); 125 } 126 } 127 } 128 } 129 130 private void validateFeatures(Element parent) { 131 NodeList list = getChildrenByName(parent, "feature"); for (int i = 0; i < list.getLength(); i++) { 133 Element element = (Element ) list.item(i); 134 assertAttributeDefined(element, "url", CompilerFlags.ERROR); NamedNodeMap attributes = element.getAttributes(); 136 for (int j = 0; j < attributes.getLength(); j++) { 137 Attr attr = (Attr ) attributes.item(j); 138 String name = attr.getName(); 139 if (name.equals("url")) { validateURL(element, "url"); } else if (name.equals("patch")) { validateBoolean(element, attr); 143 } else if (name.equals("version")) { validateVersionAttribute(element, attr); 145 } 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); 149 } 150 } 151 validateCategories(element); 152 } 153 } 154 155 158 private void validateDescription(Element parent) { 159 NodeList list = getChildrenByName(parent, "description"); if (list.getLength() > 0) { 161 if (fMonitor.isCanceled()) 162 return; 163 Element element = (Element )list.item(0); 164 validateElementWithContent((Element )list.item(0), true); 165 if (element.getAttributeNode("url") != null) validateURL(element, "url"); reportExtraneousElements(list, 1); 168 } 169 } 170 171 172 173 } 174 | Popular Tags |