Skip to main content
summaryrefslogtreecommitdiffstats
blob: 00e4873ec09fc92411b0e238c09de68c9399384e (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
/*******************************************************************************
 * Copyright (c) 2001, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.wst.dtd.ui.internal.validation;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.wst.dtd.core.internal.validation.DTDValidationMessages;
import org.eclipse.wst.dtd.core.internal.validation.Validator;
import org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage;
import org.eclipse.wst.xml.core.internal.validation.core.ValidationReport;
import org.eclipse.wst.xml.ui.internal.validation.core.ValidateAction;


/**
 * This class managers the 'UI' related details of validation Here's a quick
 * overview of the details : - manages Marker creation based on the results of
 * the validation - (optionally) displays dialog to summarize the results of
 * validation - temporarily copies XML to a temp file to workaround a xerces
 * bug (InputSource from InputStream bug)
 */
public class ValidateDTDAction extends ValidateAction {
	/**
	 * Constructor.
	 * 
	 * @param file
	 *            The file to validate.
	 * @param showDialog
	 *            Whether or not to show dialogs during validation.
	 */
	public ValidateDTDAction(IFile file, boolean showDialog) {
		super(file, showDialog);
	}

	protected void validate(final IFile fileToValidate) {
		final ValidationOutcome validationOutcome = new ValidationOutcome();
		IPath path = fileToValidate.getLocation();
		final String uri = createURIForFilePath(path.toString());
		Validator dtdValidator = Validator.getInstance();

		clearMarkers(fileToValidate);

		ValidationReport valreport = dtdValidator.validate(uri);
		validationOutcome.isValid = valreport.isValid();
		if (valreport.getValidationMessages().length == 0) {
			validationOutcome.hasMessages = false;
		}
		else {
			validationOutcome.hasMessages = true;
		}
		createMarkers(fileToValidate, valreport.getValidationMessages());

		try {
			fileToValidate.setSessionProperty(ValidationMessage.ERROR_MESSAGE_MAP_QUALIFIED_NAME, valreport.getNestedMessages());
		}
		catch (CoreException e) {
		}


		if (showDialog) {
			if (!validationOutcome.isValid) {
				String title = DTDValidationMessages._UI_DIALOG_DTD_INVALID_TITLE;
				String message = DTDValidationMessages._UI_DIALOG_DTD_INVALID_TEXT;
				openErrorDialog(title, message);
			}
			else {
				String title = DTDValidationMessages._UI_DIALOG_DTD_VALID_TITLE;
				String message = DTDValidationMessages._UI_DIALOG_DTD_VALID_TEXT;
				openValidDialog(title, message);
			}
		}
	}
}

Back to the top