Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/jsfappconfig/DefaultJSFAppConfigLocater.java')
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/jsfappconfig/DefaultJSFAppConfigLocater.java148
1 files changed, 148 insertions, 0 deletions
diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/jsfappconfig/DefaultJSFAppConfigLocater.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/jsfappconfig/DefaultJSFAppConfigLocater.java
new file mode 100644
index 000000000..6bca0c54f
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/jsfappconfig/DefaultJSFAppConfigLocater.java
@@ -0,0 +1,148 @@
+/*******************************************************************************
+ * Copyright (c) 2005 Oracle Corporation.
+ * 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:
+ * Ian Trimble - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.jsf.core.jsfappconfig;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IResourceDeltaVisitor;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jst.jsf.core.internal.JSFCorePlugin;
+import org.eclipse.wst.common.componentcore.resources.IVirtualFolder;
+import org.eclipse.wst.common.componentcore.resources.IVirtualResource;
+
+/**
+ * DefaultJSFAppConfigLocater attempts to locate the default application
+ * configuration file, located at "/WEB-INF/faces-config.xml".
+ *
+ * @author Ian Trimble - Oracle
+ */
+public class DefaultJSFAppConfigLocater extends WebContentRelativeJSFAppConfigLocater
+ implements IResourceChangeListener {
+
+ /**
+ * Web content folder-relative name of the default application
+ * configuration resource file.
+ */
+ public static final String DEF_APPCONFIGRESOURCE_FILENAME = "WEB-INF/faces-config.xml"; //$NON-NLS-1$
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jst.jsf.core.internal.provisional.jsfappconfig.AbstractJSFAppConfigLocater#startLocating()
+ */
+ public void startLocating() {
+ locateProviders();
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ workspace.addResourceChangeListener(this, IResourceChangeEvent.POST_BUILD);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jst.jsf.core.internal.provisional.jsfappconfig.AbstractJSFAppConfigLocater#stopLocating()
+ */
+ public void stopLocating() {
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ workspace.removeResourceChangeListener(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jst.jsf.core.internal.provisional.jsfappconfig.WebContentRelativeJSFAppConfigLocater#getFilenames()
+ */
+ protected List getFilenames() {
+ List filenames = new ArrayList();
+ filenames.add(DEF_APPCONFIGRESOURCE_FILENAME);
+ return filenames;
+ }
+
+ /**
+ * Responds to resource change events.
+ *
+ * @param event IResourceChangeEvent instance.
+ */
+ public void resourceChanged(IResourceChangeEvent event) {
+ IResourceDelta delta = event.getDelta();
+ try {
+ delta.accept(new ResourceDeltaVisitor());
+ } catch (CoreException cex) {
+ JSFCorePlugin.log(
+ IStatus.WARNING,
+ cex.getLocalizedMessage(),
+ cex);
+ }
+ }
+
+ /**
+ * ResourceDeltaVisitor is used to visit an IResourceDelta instance to
+ * discover if the default application configuration resource file has
+ * been added or removed.
+ *
+ * @author Ian Trimble - Oracle
+ */
+ class ResourceDeltaVisitor implements IResourceDeltaVisitor {
+
+ /**
+ * Cached IPath instance for default configuration resource file.
+ */
+ protected IPath defConfigPath = null;
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.resources.IResourceDeltaVisitor#visit(org.eclipse.core.resources.IResourceDelta)
+ */
+ public boolean visit(IResourceDelta delta) {
+ boolean visitChildren = false;
+ initDefConfigPath();
+ if (defConfigPath != null) {
+ IPath deltaPath = delta.getFullPath();
+ if (deltaPath != null) {
+ if (defConfigPath.equals(deltaPath)) {
+ locateProviders();
+ } else if (deltaPath.isPrefixOf(defConfigPath)) {
+ visitChildren = true;
+ }
+ }
+ } else {
+ locateProviders();
+ }
+ return visitChildren;
+ }
+
+ /**
+ * Determines IPath instance for default configuration resource file
+ * and caches in class member.
+ */
+ protected void initDefConfigPath() {
+ if (defConfigPath == null) {
+ IProject project = manager.getProject();
+ if (project != null) {
+ IVirtualFolder webContentFolder = JSFAppConfigUtils.getWebContentFolder(project);
+ if (webContentFolder != null) {
+ IVirtualResource defConfigFile = webContentFolder.findMember(DEF_APPCONFIGRESOURCE_FILENAME);
+ if (defConfigFile != null) {
+ defConfigPath = defConfigFile.getWorkspaceRelativePath();
+ }
+ }
+ }
+ }
+ }
+
+ }
+
+}

Back to the top