Skip to main content
summaryrefslogtreecommitdiffstats
blob: 45b5fce2f514f74c0f27a8196f52e3cba4b94f3c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package org.eclipse.team.internal.ccvs.core.util;

/*
 * (c) Copyright IBM Corp. 2000, 2001.
 * All Rights Reserved.
 */
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;

import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.team.internal.ccvs.core.Policy;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;

public class ProjectDescriptionContentHandler implements ContentHandler {

	IProjectDescription desc;
	boolean inProjectDescription = false;

	boolean inComment = false;
	StringBuffer buffer = new StringBuffer();

	boolean inBuilder = false;
	List builders = new ArrayList();
	ICommand currentBuilder = null;
	Map args = new HashMap();

	List natures = new ArrayList();

	List references = new ArrayList();

	Stack tagStack = new Stack();

	ProjectDescriptionContentHandler(IProjectDescription desc) {
		this.desc = desc;
	}
	/**
	 * @see ContentHandler#characters(char[], int, int)
	 */
	public void characters(char[] chars, int startIndex, int length)
		throws SAXException {
		buffer.append(chars, startIndex, length);
	}
	/**
	 * @see ContentHandler#endDocument()
	 */
	public void endDocument() throws SAXException {
	}
	/**
	 * @see ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
	 */
	public void endElement(String namespaceURI, String localName, String qName)
		throws SAXException {
		if (localName.equals("project-description") && inProjectDescription) { //$NON-NLS-1$
			inProjectDescription = false;
			desc.setBuildSpec((ICommand[]) builders.toArray(new ICommand[builders.size()]));
			desc.setNatureIds((String[]) natures.toArray(new String[natures.size()]));
			desc.setReferencedProjects(
				(IProject[]) references.toArray(new IProject[references.size()]));
		} else if (localName.equals("comment") && inProjectDescription && inComment) { //$NON-NLS-1$
			inComment = false;
			desc.setComment(buffer.toString());
		} else if (localName.equals("builder") && inProjectDescription && inBuilder) { //$NON-NLS-1$
			inBuilder = false;
			currentBuilder.setArguments(args);
			if (currentBuilder.getBuilderName() != null)
				builders.add(currentBuilder);
		}
		if (!localName.equals(tagStack.peek())) {
			throw new RuntimeException(Policy.bind("ProjectDescriptionContentHandler.xml")); //$NON-NLS-1$
		}
		tagStack.pop();
	}
	/**
	 * @see ContentHandler#endPrefixMapping(java.lang.String)
	 */
	public void endPrefixMapping(String arg0) throws SAXException {
	}
	/**
	 * @see ContentHandler#ignorableWhitespace(char[], int, int)
	 */
	public void ignorableWhitespace(char[] arg0, int arg1, int arg2)
		throws SAXException {
	}
	/**
	 * @see ContentHandler#processingInstruction(java.lang.String, java.lang.String)
	 */
	public void processingInstruction(String arg0, String arg1)
		throws SAXException {
	}
	/**
	 * @see ContentHandler#setDocumentLocator(org.xml.sax.Locator)
	 */
	public void setDocumentLocator(Locator arg0) {
	}
	/**
	 * @see ContentHandler#skippedEntity(java.lang.String)
	 */
	public void skippedEntity(String e) throws SAXException {
	}
	/**
	 * @see ContentHandler#startDocument()
	 */
	public void startDocument() throws SAXException {
	}
	/**
	 * @see ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
	 */
	public void startElement(
		String namespaceURI,
		String localName,
		String qName,
		Attributes atts)
		throws SAXException {
		if (localName.equals("project-description") && !inProjectDescription) { //$NON-NLS-1$
			inProjectDescription = true;
		} else if (localName.equals("comment") && inProjectDescription && !inComment) { //$NON-NLS-1$
			inComment = true;
		} else if (localName.equals("builder") && inProjectDescription && !inBuilder) { //$NON-NLS-1$
			String builderName = atts.getValue("name"); //$NON-NLS-1$
			if (builderName != null) {
				inBuilder = true;
				currentBuilder = desc.newCommand();
				currentBuilder.setBuilderName(builderName);
				args = new HashMap(11);
			}
		} else if (localName.equals("arg") && inProjectDescription && inBuilder) { //$NON-NLS-1$
			String argName = atts.getValue("name"); //$NON-NLS-1$
			String argValue = atts.getValue("value"); //$NON-NLS-1$
			if (argName != null && argValue != null)
				args.put(argName, argValue);
		} else if (localName.equals("nature") && inProjectDescription && !inBuilder) { //$NON-NLS-1$
			String natureId = atts.getValue("id"); //$NON-NLS-1$
			if (natureId != null)
				natures.add(natureId);
		} else if (
			localName.equals("reference") && inProjectDescription && !inBuilder) { //$NON-NLS-1$
			String projectName = atts.getValue("project-name"); //$NON-NLS-1$
			if (projectName != null)
				references.add(
					ResourcesPlugin.getWorkspace().getRoot().getProject(projectName));
		}
		// empty buffer
		buffer = new StringBuffer();
		tagStack.push(localName);
	}
	/**
	 * @see ContentHandler#startPrefixMapping(java.lang.String, java.lang.String)
	 */
	public void startPrefixMapping(String arg0, String arg1) throws SAXException {
	}
}

Back to the top