Skip to main content
summaryrefslogtreecommitdiffstats
blob: 7b1414b729f77db55051e74d6d926f83a68d5c5c (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
/*******************************************************************************
 * Copyright (c) 2004, 2005 Sybase, Inc. 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:
 *     Sybase, Inc. - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.jsf.facesconfig.ui.pageflow.util;

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

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;

/**
 * utility class for JSP related information.
 * 
 * @author Yang Liu
 */
public class JSPUtil {

	/**
	 * get the action list in the jsp file
	 * @param jspFileName 
	 * 
	 * @return - action list
	 */
	public static List getActionListInJSPFile(String jspFileName) {
		/** jsp dom adapter */

        List actions = new ArrayList();

        // convert the relative directory to project directory, e.g., /a.jsp to
        // /testproject/webroot/a.sjp
        String physicalJspPath = jspFileName;
        if (physicalJspPath != null && physicalJspPath.length() > 0)
        {
            IPath jspPath = new Path(physicalJspPath);
            IFile jspFile = ResourcesPlugin.getWorkspace().getRoot().getFile(
                    jspPath);

            if (jspFile != null && jspFile.exists())
            {
                JSPDomAdapter jspAdapter = null;
                try
                {
                    jspAdapter = new JSPDomAdapter();
                    // initialize the adapter to initialize the model of jsp
                    if (jspAdapter.initialize(jspFile))
                    {
                        // the prefix of JSF HTML TagLib
                        String prefix = jspAdapter
                                .getTagLibPrefix(JSPDomAdapter.JSF_HTML_TAGLIB);

                        // get the command butonns
                        List buttonActions = jspAdapter.getElementsByTagNameNS(
                                prefix, "commandButton");//$NON-NLS-1$
                        if (buttonActions != null)
                            actions.addAll(buttonActions);

                        // get the command links
                        List linkActions = jspAdapter.getElementsByTagNameNS(
                                prefix, "commandLink");//$NON-NLS-1$
                        if (linkActions != null)
                            actions.addAll(linkActions);
                    }
                }
                finally
                {
                    if (jspAdapter != null)
                    {
                        jspAdapter.releaseModel();
                    }
                }
            }
        }
        return actions;
	}
}

Back to the top