KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > builders > UpdateSiteErrorReporter


1 /*******************************************************************************
2  * Copyright (c) 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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     /* (non-Javadoc)
27      * @see org.eclipse.pde.internal.builders.XMLErrorReporter#validateContent(org.eclipse.core.runtime.IProgressMonitor)
28      */

29     public void validateContent(IProgressMonitor monitor) {
30         fMonitor = monitor;
31         Element root = getDocumentRoot();
32         if (root == null)
33             return;
34         String JavaDoc elementName = root.getNodeName();
35         if (!"site".equals(elementName)) { //$NON-NLS-1$
36
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 JavaDoc name = attr.getName();
42                 if (!name.equals("type") && !name.equals("url") && !name.equals("mirrorsURL")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
43
reportUnknownAttribute(root, name, CompilerFlags.ERROR);
44                 }
45             }
46             validateDescription(root);
47             validateFeatures(root);
48             validateCategoryDefinitions(root);
49             validateArchives(root);
50         }
51     }
52
53     /**
54      * @param root
55      */

56     private void validateArchives(Element root) {
57         NodeList list = getChildrenByName(root, "archive"); //$NON-NLS-1$
58
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); //$NON-NLS-1$
63
assertAttributeDefined(element, "url", CompilerFlags.ERROR); //$NON-NLS-1$
64
NamedNodeMap attributes = element.getAttributes();
65             for (int j = 0; j < attributes.getLength(); j++) {
66                 Attr attr = (Attr)attributes.item(j);
67                 String JavaDoc name = attr.getName();
68                 if (name.equals("url")) { //$NON-NLS-1$
69
validateURL(element, "url"); //$NON-NLS-1$
70
} else if (!name.equals("path")) { //$NON-NLS-1$
71
reportUnknownAttribute(element, name, CompilerFlags.ERROR);
72                 }
73             }
74         }
75     }
76
77     /**
78      * @param root
79      */

80     private void validateCategoryDefinitions(Element root) {
81         NodeList list = getChildrenByName(root, "category-def"); //$NON-NLS-1$
82
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); //$NON-NLS-1$
87
assertAttributeDefined(element, "label", CompilerFlags.ERROR); //$NON-NLS-1$
88
NamedNodeMap attributes = element.getAttributes();
89             for (int j = 0; j < attributes.getLength(); j++) {
90                 Attr attr = (Attr)attributes.item(j);
91                 String JavaDoc name = attr.getName();
92                 if (!name.equals("name") && !name.equals("label")) { //$NON-NLS-1$ //$NON-NLS-2$
93
reportUnknownAttribute(element, name, CompilerFlags.ERROR);
94                 }
95             }
96             validateDescription(element);
97         }
98     }
99
100     /**
101      * @param root
102      */

103     private void validateCategories(Element root) {
104         NodeList list = getChildrenByName(root, "category"); //$NON-NLS-1$
105
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); //$NON-NLS-1$
110
NamedNodeMap attributes = element.getAttributes();
111             for (int j = 0; j < attributes.getLength(); j++) {
112                 Attr attr = (Attr)attributes.item(j);
113                 String JavaDoc name = attr.getName();
114                 if (!name.equals("name")) { //$NON-NLS-1$
115
reportUnknownAttribute(element, name, CompilerFlags.ERROR);
116                 }
117             }
118         }
119     }
120
121     private void validateFeatures(Element parent) {
122         NodeList list = getChildrenByName(parent, "feature"); //$NON-NLS-1$
123
for (int i = 0; i < list.getLength(); i++) {
124             Element element = (Element) list.item(i);
125             assertAttributeDefined(element, "url", CompilerFlags.ERROR); //$NON-NLS-1$
126
NamedNodeMap attributes = element.getAttributes();
127             for (int j = 0; j < attributes.getLength(); j++) {
128                 Attr attr = (Attr) attributes.item(j);
129                 String JavaDoc name = attr.getName();
130                 if (name.equals("url")) { //$NON-NLS-1$
131
validateURL(element, "url"); //$NON-NLS-1$
132
} else if (name.equals("patch")) { //$NON-NLS-1$
133
validateBoolean(element, attr);
134                 } else if (name.equals("version")) { //$NON-NLS-1$
135
validateVersionAttribute(element, attr);
136                 } else if (!name.equals("type") && !name.equals("id") //$NON-NLS-1$ //$NON-NLS-2$
137
&& !name.equals("os") && !name.equals("ws") //$NON-NLS-1$ //$NON-NLS-2$
138
&& !name.equals("nl") && !name.equals("arch")) { //$NON-NLS-1$ //$NON-NLS-2$
139
reportUnknownAttribute(element, name, CompilerFlags.ERROR);
140                 }
141             }
142             validateCategories(element);
143         }
144     }
145
146     /**
147      * @param root
148      */

149     private void validateDescription(Element parent) {
150         NodeList list = getChildrenByName(parent, "description"); //$NON-NLS-1$
151
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) //$NON-NLS-1$
157
validateURL(element, "url"); //$NON-NLS-1$
158
reportExtraneousElements(list, 1);
159         }
160     }
161     
162     
163
164 }
165
Popular Tags