KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 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.core.builders;
12
13 import org.eclipse.core.resources.IFile;
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.w3c.dom.Attr JavaDoc;
16 import org.w3c.dom.Element JavaDoc;
17 import org.w3c.dom.NamedNodeMap JavaDoc;
18 import org.w3c.dom.NodeList JavaDoc;
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     /* (non-Javadoc)
30      * @see org.eclipse.pde.internal.builders.XMLErrorReporter#validateContent(org.eclipse.core.runtime.IProgressMonitor)
31      */

32     public void validateContent(IProgressMonitor monitor) {
33         fMonitor = monitor;
34         Element JavaDoc root = getDocumentRoot();
35         if (root == null)
36             return;
37         String JavaDoc elementName = root.getNodeName();
38         if (!"site".equals(elementName)) { //$NON-NLS-1$
39
reportIllegalElement(root, CompilerFlags.ERROR);
40         } else {
41             NamedNodeMap JavaDoc attributes = root.getAttributes();
42             for (int i = 0; i < attributes.getLength(); i++) {
43                 Attr JavaDoc attr = (Attr JavaDoc)attributes.item(i);
44                 String JavaDoc name = attr.getName();
45                 if (!name.equals("type") && //$NON-NLS-1$
46
!name.equals("url") && //$NON-NLS-1$
47
!name.equals("mirrorsURL") && //$NON-NLS-1$
48
!name.equals("digestURL") && //$NON-NLS-1$
49
!name.equals("pack200") && //$NON-NLS-1$
50
!name.equals("availableLocales") && //$NON-NLS-1$
51
!name.equals("associateSitesURL")) { //$NON-NLS-1$
52
reportUnknownAttribute(root, name, CompilerFlags.ERROR);
53                 }
54             }
55             validateDescription(root);
56             validateFeatures(root);
57             validateCategoryDefinitions(root);
58             validateArchives(root);
59         }
60     }
61
62     /**
63      * @param root
64      */

65     private void validateArchives(Element JavaDoc root) {
66         NodeList JavaDoc list = getChildrenByName(root, "archive"); //$NON-NLS-1$
67
for (int i = 0; i < list.getLength(); i++) {
68             if (fMonitor.isCanceled())
69                 return;
70             Element JavaDoc element = (Element JavaDoc)list.item(i);
71             assertAttributeDefined(element, "path", CompilerFlags.ERROR); //$NON-NLS-1$
72
assertAttributeDefined(element, "url", CompilerFlags.ERROR); //$NON-NLS-1$
73
NamedNodeMap JavaDoc attributes = element.getAttributes();
74             for (int j = 0; j < attributes.getLength(); j++) {
75                 Attr JavaDoc attr = (Attr JavaDoc)attributes.item(j);
76                 String JavaDoc name = attr.getName();
77                 if (name.equals("url")) { //$NON-NLS-1$
78
validateURL(element, "url"); //$NON-NLS-1$
79
} else if (!name.equals("path")) { //$NON-NLS-1$
80
reportUnknownAttribute(element, name, CompilerFlags.ERROR);
81                 }
82             }
83         }
84     }
85
86     /**
87      * @param root
88      */

89     private void validateCategoryDefinitions(Element JavaDoc root) {
90         NodeList JavaDoc list = getChildrenByName(root, "category-def"); //$NON-NLS-1$
91
for (int i = 0; i < list.getLength(); i++) {
92             if (fMonitor.isCanceled())
93                 return;
94             Element JavaDoc element = (Element JavaDoc)list.item(i);
95             assertAttributeDefined(element, "name", CompilerFlags.ERROR); //$NON-NLS-1$
96
assertAttributeDefined(element, "label", CompilerFlags.ERROR); //$NON-NLS-1$
97
NamedNodeMap JavaDoc attributes = element.getAttributes();
98             for (int j = 0; j < attributes.getLength(); j++) {
99                 Attr JavaDoc attr = (Attr JavaDoc)attributes.item(j);
100                 String JavaDoc name = attr.getName();
101                 if (!name.equals("name") && !name.equals("label")) { //$NON-NLS-1$ //$NON-NLS-2$
102
reportUnknownAttribute(element, name, CompilerFlags.ERROR);
103                 }
104             }
105             validateDescription(element);
106         }
107     }
108
109     /**
110      * @param root
111      */

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

158     private void validateDescription(Element JavaDoc parent) {
159         NodeList JavaDoc list = getChildrenByName(parent, "description"); //$NON-NLS-1$
160
if (list.getLength() > 0) {
161             if (fMonitor.isCanceled())
162                 return;
163             Element JavaDoc element = (Element JavaDoc)list.item(0);
164             validateElementWithContent((Element JavaDoc)list.item(0), true);
165             if (element.getAttributeNode("url") != null) //$NON-NLS-1$
166
validateURL(element, "url"); //$NON-NLS-1$
167
reportExtraneousElements(list, 1);
168         }
169     }
170     
171     
172
173 }
174
Popular Tags