Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: dc851a9f2ca3fa191a131116773390b5379a509e (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
/*******************************************************************************
 * Copyright (c) 2001, 2008 Oracle 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:
 *     Oracle Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.jsf.core.jsflibraryconfiguration;

import java.util.Collection;
import java.util.HashSet;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jst.jsf.core.internal.JSFCorePlugin;
import org.eclipse.jst.jsf.core.jsflibraryconfiguration.internal.JSFLibraryReferenceFacadeFactory;

/**
 * Helper class for adopters needing to deal with JSF Library References
 * 
 * <p><b>Provisional API - subject to change</b></p>
 * @since WTP JSF 1.0
 */
public final class JSFLibraryConfigurationHelper {
	/**
	 * container id for JSF Library Classpath Containers 
	 */
	public static final String JSF_LIBRARY_CP_CONTAINER_ID="org.eclipse.jst.jsf.core.internal.jsflibrarycontainer";

	/**
	 * @param project 
	 * @return collection of references
	 */
	public static Collection<JSFLibraryReference> getJSFLibraryReferences(IProject project) {
		Collection<JSFLibraryReference> results = new HashSet<JSFLibraryReference>();
		IJavaProject jproj = JavaCore.create(project);
		try {
			IClasspathEntry[] entries = jproj.getRawClasspath();
			boolean foundImpl = false;
			for (int i=0;i<entries.length;i++){
				JSFLibraryReference ref = JSFLibraryReferenceFacadeFactory.create(entries[i]);
				if (ref != null){
					results.add(ref);
					if (ref.isJSFImplementation())
						foundImpl = true;
				}
			}
			if (! foundImpl){
				results.add(JSFLibraryReferenceFacadeFactory.createServerSuppliedJSFLibRef());
			}
		} catch (JavaModelException e) {
			JSFCorePlugin.log(e, "Exception occurred calling getJSFLibraryReferences for "+project.getName());
		}
		return results;
	}

	/**
	 * @param cpEntry
	 * @return boolean indicating that the classpath entry is a JSF Libary Classpath Container
	 */
	public static boolean isJSFLibraryContainer(IClasspathEntry cpEntry) {
		if (cpEntry.getEntryKind() != IClasspathEntry.CPE_CONTAINER)
			return false;
		
		IPath path = cpEntry.getPath();
		return path != null && path.segmentCount() == 2 && JSF_LIBRARY_CP_CONTAINER_ID.equals(path.segment(0));
	}
	
	/**
	 * @param project
	 * @return true if the JSF Faceted project is configured to use system supplied implementation
	 */
	public static boolean isConfiguredForSystemSuppliedImplementation(IProject project) {
		Collection<JSFLibraryReference> refs = getJSFLibraryReferences(project);
		for(JSFLibraryReference ref : refs){			
			if (ref instanceof JSFLibraryReferenceServerSupplied)
				return true;
		}
		return false;
	}
}

Back to the top