Skip to main content
summaryrefslogtreecommitdiffstats
blob: 4dc4ad08a25f164cf54b0ee76e9e77fb17068b94 (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
package org.eclipse.help.internal.util;

/*
 * Licensed Materials - Property of IBM,
 * WebSphere Studio Workbench
 * (c) Copyright IBM Corp 2000
 */

import java.util.*;
import org.xml.sax.*;
import org.eclipse.core.runtime.*;

/**
 * This class is intended to capture all runtime exception happening during
 * the execution of the Help System.
 */

public class RuntimeHelpStatus {
	private static RuntimeHelpStatus inst = null;

	// contains Status objects of errors occurred
	private ArrayList errorList = new ArrayList();

	// contains File names (Strings) of invalid contribution files.
	private ArrayList badFilesList = new ArrayList();

	// contains the error messages (Strings) from the parser
	private ArrayList parserErrorMessagesList = new ArrayList();

	/**
	 * RuntimeHelpStatus constructor comment.
	 */
	public RuntimeHelpStatus() {
		super();
	}
	public synchronized void addError(Status status) {
		errorList.add(status);

	}
	public synchronized void addParseError(
		String message,
		String invalidFileName) {
		// add the Exception to the files list only once. These exceptions will be used to
		// produce the list of files with errors.
		if (!badFilesList.contains(invalidFileName))
			badFilesList.add(invalidFileName);

		// now add the message. All parser messages are added
		parserErrorMessagesList.add(message);

	}
	public synchronized void addParseError(
		String message,
		SAXParseException parseException) {
		// add the Exception to the files list only once. These exceptions will be used to
		// produce the list of files with errors.
		if (!badFilesList.contains(parseException))
			badFilesList.add(parseException);

		// now add the message. All parser messages are added
		parserErrorMessagesList.add(message);

	}
	public boolean errorsExist() {
		if (errorList.isEmpty()
			&& parserErrorMessagesList.isEmpty()
			&& badFilesList.isEmpty())
			return false;
		else
			return true;
	}
	public static synchronized RuntimeHelpStatus getInstance() {
		if (inst == null) // create instance
			inst = new RuntimeHelpStatus();
		return inst;
	}
	/**
	 * clears RuntimeHelpStatus object.
	 */
	public void reset() {
		errorList.clear();
		badFilesList.clear();
		parserErrorMessagesList.clear();
	}
	public synchronized String toString() {
		StringBuffer fullText = new StringBuffer();
		if (!errorList.isEmpty()) {
			fullText.append(Resources.getString("E006"));
			fullText.append("***************************** \n");
			for (int i = 0; i < errorList.size(); i++) {
				fullText.append(((Status) (errorList.get(i))).getMessage());
				fullText.append("\n");
			}
		}

		if (fullText.length() > 0)
			fullText.append("\n");

		if (!parserErrorMessagesList.isEmpty()) {
			// display the files that failed to parse
			fullText.append(Resources.getString("E007"));
			fullText.append("*****************************  \n");
			for (int i = 0; i < badFilesList.size(); i++) {
				fullText.append(((String) (badFilesList.get(i))));
				fullText.append("\n");
			}

			fullText.append("\n");

			// and the parse error message
			fullText.append(Resources.getString("E008"));
			fullText.append("********************  \n");
			for (int i = 0; i < parserErrorMessagesList.size(); i++) {
				fullText.append(((String) (parserErrorMessagesList.get(i))));
				fullText.append("\n");
			}
		}

		if (fullText.length() > 0)
			return fullText.toString();
		else
			return "null status object";

	}
}

Back to the top