Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 34b20c0abaf24bcc0ea2e5b0c523bd9d06bb18a9 (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
/*******************************************************************************
 * Copyright (c) 2009 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.ua.tests.doc.internal.actions;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.help.internal.HelpPlugin;
import org.eclipse.help.internal.toc.Toc;
import org.eclipse.help.internal.validation.TocValidator;
import org.eclipse.help.internal.validation.TocValidator.BrokenLink;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ua.tests.doc.internal.dialogs.SelectTocDialog;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;

public class CheckTocAction implements IWorkbenchWindowActionDelegate {
	private IWorkbenchWindow window;
    public static List errors = new ArrayList();
    
    public static void showErrors() {
    	if (errors.size() == 0) {
    		reportStatus("No errors detected in load");
    	}
    	for (int i = 0; i < errors.size(); i++) {
			BrokenLink link = (BrokenLink)errors.get(i);
			reportStatus("Invalid link in \"" + link.getTocID() + "\": " + link.getHref());
		}
	}

	private static void reportStatus(String errorMessage) {
		HelpPlugin.logWarning(errorMessage);
	}
	
	
	/**
	 * The constructor.
	 */
	public CheckTocAction() {
	}

	/**
	 * The action has been activated. The argument of the
	 * method represents the 'real' action sitting
	 * in the workbench UI.
	 * @see IWorkbenchWindowActionDelegate#run
	 */
	public void run(IAction action) {
		SelectTocDialog dlg = new SelectTocDialog(window.getShell());
		dlg.open();
		if (dlg.getReturnCode() == SelectTocDialog.CANCEL) {
			return;
		}
		Toc[] tocsToCheck = dlg.getTocsToCheck();
	    checkTocFilesExist(tocsToCheck);

	}

	public  void checkTocFilesExist(Toc[] tocsToCheck) {
		for (int i = 0; i < tocsToCheck.length; i++) {
			Toc toc = tocsToCheck[i];
			String id = toc.getTocContribution().getId();
			reportStatus("Testing " + id);
			String[] href = { id };
			try {
				errors = TocValidator.validate(href);
			} catch (Exception e) {
				e.printStackTrace();
			}	
			showErrors();
		}
	}



	/**
	 * Selection in the workbench has been changed. We 
	 * can change the state of the 'real' action here
	 * if we want, but this can only happen after 
	 * the delegate has been created.
	 * @see IWorkbenchWindowActionDelegate#selectionChanged
	 */
	public void selectionChanged(IAction action, ISelection selection) {
	}

	/**
	 * We can use this method to dispose of any system
	 * resources we previously allocated.
	 * @see IWorkbenchWindowActionDelegate#dispose
	 */
	public void dispose() {
	}

	/**
	 * We will cache window object in order to
	 * be able to provide parent shell for the message dialog.
	 * @see IWorkbenchWindowActionDelegate#init
	 */
	public void init(IWorkbenchWindow window) {
		this.window = window;
	}
}

Back to the top