Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcbridgha2004-11-24 13:00:19 +0000
committercbridgha2004-11-24 13:00:19 +0000
commit967084bf4c24813ac82dbd6229f33bc70602281b (patch)
treefe6a5264516cd372cad59e40820aceb0eeb475b5 /plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal
parentcde36f87fc36974477f8d3e4afa268e3eb037e84 (diff)
downloadwebtools.javaee-967084bf4c24813ac82dbd6229f33bc70602281b.tar.gz
webtools.javaee-967084bf4c24813ac82dbd6229f33bc70602281b.tar.xz
webtools.javaee-967084bf4c24813ac82dbd6229f33bc70602281b.zip
internal rename
Diffstat (limited to 'plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal')
-rw-r--r--plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/locator/AbstractTaglibLocator.java189
-rw-r--r--plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/locator/AbstractWebTaglibLocator.java260
-rw-r--r--plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/locator/JavaProjectTaglibLocator.java122
-rw-r--r--plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/locator/WebLibModuleTaglibLocator.java227
-rw-r--r--plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/locator/WebProjectServerTargetTaglibLocator.java130
-rw-r--r--plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/locator/WebProjectTaglibLocator.java191
-rw-r--r--plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/locator/WebXMLTaglibLocator.java329
-rw-r--r--plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/DirTaglibInfo.java109
-rw-r--r--plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/ServerJarsUtil.java97
-rw-r--r--plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/TLDDigester.java250
-rw-r--r--plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/TaglibInfo.java379
-rw-r--r--plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/TaglibRegistryManager.java172
-rw-r--r--plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/WebProjectServerTaglibListener.java63
-rw-r--r--plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/WebXMLTaglibInfo.java79
-rw-r--r--plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/registry/AbstractTaglibRegistry.java555
-rw-r--r--plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/registry/JavaTaglibRegistry.java70
-rw-r--r--plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/registry/WebTaglibRegistry.java178
17 files changed, 3400 insertions, 0 deletions
diff --git a/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/locator/AbstractTaglibLocator.java b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/locator/AbstractTaglibLocator.java
new file mode 100644
index 000000000..ddbb2a139
--- /dev/null
+++ b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/locator/AbstractTaglibLocator.java
@@ -0,0 +1,189 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 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.jst.j2ee.internal.web.locator;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceVisitor;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jst.j2ee.internal.web.taglib.TLDDigester;
+import org.eclipse.jst.j2ee.internal.web.taglib.TaglibInfo;
+import org.eclipse.jst.j2ee.web.taglib.ITaglibInfo;
+import org.eclipse.jst.j2ee.web.taglib.ITaglibLocator;
+
+import com.ibm.wtp.common.logger.proxy.Logger;
+
+
+/**
+ * @version 1.0
+ * @author
+ */
+public abstract class AbstractTaglibLocator implements ITaglibLocator {
+ protected IProject project;
+ static protected final ITaglibInfo[] EMPTY_TAGLIBINFO_ARRAY = new ITaglibInfo[0];
+
+ public AbstractTaglibLocator(IProject project) {
+ this.project = project;
+ }
+
+ protected String calculateURIForFile(IPath projectRelativePath) {
+ IPath result = new Path("/"); //$NON-NLS-1$
+ IPath serverRoot = getServerRoot();
+ IPath filePath = projectRelativePath;
+ result = result.append(filePath.removeFirstSegments(serverRoot.segmentCount()));
+ return result.makeAbsolute().toString();
+ }
+
+ abstract protected IPath getServerRoot();
+
+ protected TLDDigester getTLDDigester(IFile tldFile) {
+ InputStream stream = null;
+ try {
+ stream = tldFile.getContents();
+ return getTLDDigester(stream);
+ } catch (CoreException e) {
+ Logger.getLogger().log(e);
+ } finally {
+ if (stream != null) {
+ try {
+ stream.close();
+ } catch (IOException e) {
+ Logger.getLogger().log(e);
+ }
+ }
+ }
+ return null;
+ }
+
+ protected TLDDigester getTLDDigester(InputStream stream) {
+ TLDDigester digester = new TLDDigester(stream);
+ return digester;
+ }
+
+ protected ITaglibInfo createTaglibForTLD(IFile file) {
+ TLDDigester digester = getTLDDigester(file);
+ try {
+ if (digester != null) {
+ if (isValidTLD(digester)) {
+ String uri = digester.getURI();
+ if (uri != null) {
+ TaglibInfo taglibInfo = new TaglibInfo(this.project, uri, file.getProjectRelativePath());
+ taglibInfo.setPrefix(digester.getShortName());
+ taglibInfo.setIsURIFromTLD(true);
+ return taglibInfo;
+ }
+ }
+ }
+ } finally {
+ if (digester != null)
+ digester.close();
+ }
+ return null;
+ }
+
+ protected ITaglibInfo createTaglibForTLD(String uri, IPath file) {
+ return new TaglibInfo(this.project, uri, file);
+ }
+
+ protected ITaglibInfo createTaglibForJar(String uri, IPath jarfile, IPath tldLocation) {
+ return new TaglibInfo(this.project, uri, jarfile, tldLocation);
+ }
+
+ protected ITaglibInfo createTaglibForLibModuleJar(String uri, IPath jarfile, IResource tldFile) {
+ TaglibInfo taglibInfo = new TaglibInfo(tldFile.getProject(), uri, jarfile, tldFile.getProjectRelativePath());
+ taglibInfo.setIsLibModule(true);
+ return taglibInfo;
+ }
+
+ protected boolean hasJarExtension(IPath file) {
+ String extension = file.getFileExtension();
+ if (extension != null) {
+ if (extension.equalsIgnoreCase("jar")) //$NON-NLS-1$
+ return true;
+ if (extension.equalsIgnoreCase("zip")) //$NON-NLS-1$
+ return true;
+ }
+ return false;
+ }
+
+
+ protected boolean hasJarExtension(String filename) {
+ return hasJarExtension(new Path(filename));
+ }
+
+
+ protected boolean hasTLDExtension(IPath file) {
+ String extension = file.getFileExtension();
+ if (extension != null && extension.equalsIgnoreCase("tld")) //$NON-NLS-1$
+ return true;
+ return false;
+ }
+
+ protected boolean hasTagExtension(String filename) {
+ return hasTagExtension(new Path(filename));
+ }
+
+ protected boolean hasTagExtension(IPath file) {
+ String extension = file.getFileExtension();
+ if (extension != null && extension.equalsIgnoreCase("tag")) //$NON-NLS-1$
+ return true;
+ return false;
+ }
+
+
+ protected boolean hasTLDExtension(String filename) {
+ return hasTLDExtension(filename);
+ }
+
+ protected boolean isValidTLD(TLDDigester digester) {
+ return true;
+ }
+
+ /*
+ * @see ITaglibLocator#search(IResource)
+ */
+ public ITaglibInfo[] search(IResource resource) {
+ final ArrayList results = new ArrayList();
+
+ try {
+ resource.accept(new IResourceVisitor() {
+ public boolean visit(IResource aresource) throws CoreException {
+ if (aresource.getType() != IResource.FILE) {
+ if (aresource.getType() != IResource.ROOT && aresource.getProject() != AbstractTaglibLocator.this.project)
+ return false;
+ return true;
+ }
+ ITaglibInfo[] taglibs = searchFile((IFile) aresource);
+ if (taglibs != null)
+ results.addAll(Arrays.asList(taglibs));
+
+ return false;
+ }
+ });
+ } catch (CoreException e) {
+ Logger.getLogger().log(e);
+ }
+ return (ITaglibInfo[]) results.toArray(new ITaglibInfo[results.size()]);
+ }
+
+ abstract protected ITaglibInfo[] searchFile(IFile file);
+
+
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/locator/AbstractWebTaglibLocator.java b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/locator/AbstractWebTaglibLocator.java
new file mode 100644
index 000000000..392f6a4f1
--- /dev/null
+++ b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/locator/AbstractWebTaglibLocator.java
@@ -0,0 +1,260 @@
+/***************************************************************************************************
+ * Copyright (c) 2003, 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.jst.j2ee.internal.web.locator;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipException;
+import java.util.zip.ZipFile;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jst.j2ee.internal.project.IWebNatureConstants;
+import org.eclipse.jst.j2ee.internal.web.operations.J2EEWebNatureRuntime;
+import org.eclipse.jst.j2ee.internal.web.operations.J2EEWebNatureRuntimeUtilities;
+import org.eclipse.jst.j2ee.internal.web.taglib.TLDDigester;
+import org.eclipse.jst.j2ee.internal.web.taglib.TaglibInfo;
+import org.eclipse.jst.j2ee.web.taglib.ITaglibInfo;
+
+import com.ibm.wtp.common.logger.proxy.Logger;
+
+abstract public class AbstractWebTaglibLocator extends AbstractTaglibLocator {
+ /**
+ * Constructor for AbstractWebProjectTaglibLocator.
+ *
+ * @param project
+ */
+ public AbstractWebTaglibLocator(IProject project) {
+ super(project);
+ }
+
+ protected boolean isInLibFolder(IFile file) {
+ J2EEWebNatureRuntime nature = getWebNature();
+ IContainer libFolder = nature.getLibraryFolder();
+ IPath libPath = libFolder.getProjectRelativePath();
+ int numOfLibPathSegs = libPath.segmentCount();
+ if (file.getProjectRelativePath().matchingFirstSegments(libPath) == numOfLibPathSegs) {
+ return true;
+ }
+ return false;
+ }
+
+ protected boolean isTLDFile(IFile file) {
+ J2EEWebNatureRuntime nature = getWebNature();
+
+ // defect CMVC 214409
+ if (nature.getJSPLevel().equals(J2EEWebNatureRuntime.JSPLEVEL_1_2)) {
+ return isInWebInfFolder(file) && hasTLDExtension(file.getProjectRelativePath());
+ } else if (nature.getJSPLevel().equals(J2EEWebNatureRuntime.JSPLEVEL_2_0)) {
+ return isInWebInfFolder(file) && hasTLDExtension(file.getProjectRelativePath());
+ }
+
+ return /* isInWebInfFolder(file) && */hasTLDExtension(file.getProjectRelativePath());
+ }
+
+ protected boolean isInWebInfFolder(IFile file) {
+ J2EEWebNatureRuntime nature = getWebNature();
+ IPath webInfPath = nature.getWEBINFPath();
+ int numOfWebInfPathSegs = webInfPath.segmentCount();
+ if (file.getProjectRelativePath().matchingFirstSegments(webInfPath) == numOfWebInfPathSegs) {
+ return true;
+ }
+ return false;
+ }
+
+ protected boolean isTaglibJar(IFile file) {
+ return isInLibFolder(file) && hasJarExtension(file.getProjectRelativePath());
+ }
+
+ protected boolean isTaglibTLD(String filename) {
+ if (filename != null) {
+ if (filename.equalsIgnoreCase(IWebNatureConstants.META_INFO_DIRECTORY + "/taglib.tld")) //$NON-NLS-1$
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * @see AbstractTaglibLocator#getServerRoot()
+ */
+ protected IPath getServerRoot() {
+ return getWebNature().getModuleServerRoot().getProjectRelativePath();
+ }
+
+ protected J2EEWebNatureRuntime getWebNature() {
+ return (J2EEWebNatureRuntime) J2EEWebNatureRuntimeUtilities.getRuntime(this.project);
+ }
+
+ protected ZipEntry[] findTLDEntriesInZip(ZipFile zFile) {
+ Enumeration entries = zFile.entries();
+ ArrayList results = new ArrayList();
+
+ while (entries.hasMoreElements()) {
+ ZipEntry entry = (ZipEntry) entries.nextElement();
+ if (!entry.isDirectory()) {
+ // Look for the first .tld file found in the META-INF directory.
+ IPath entryPath = new Path(entry.getName());
+ if (isValidTLDJarPath(entryPath))
+ results.add(entry);
+ }
+ }
+
+ return (ZipEntry[]) results.toArray(new ZipEntry[results.size()]);
+ }
+
+ protected TLDDigester getTLDDigester(IFile jarFile, IPath jarRelativePath) {
+ InputStream stream = null;
+ TLDDigester digester = null;
+ try {
+ ZipFile zFile = new ZipFile(jarFile.getLocation().toFile());
+ ZipEntry[] entries = findTLDEntriesInZip(zFile);
+ if (entries != null) {
+ for (int i = 0; i < entries.length; i++) {
+ ZipEntry entry = entries[i];
+ if (entry.getName().equalsIgnoreCase(jarRelativePath.toString())) {
+ stream = zFile.getInputStream(entry);
+ break;
+ }
+ }
+ if (stream != null)
+ digester = getTLDDigester(stream);
+ }
+ } catch (Exception e) {
+ Logger.getLogger().log(e);
+ } finally {
+ if (stream != null) {
+ try {
+ stream.close();
+ } catch (IOException e) {
+ Logger.getLogger().log(e);
+ }
+ }
+ }
+ return digester;
+ }
+
+ protected boolean isValidTLD(TLDDigester digester) {
+ if (digester == null || !super.isValidTLD(digester))
+ return false;
+
+ // JSP 1.2 TLDs are not allowed in JSP 1.1 projects
+ if (getWebNature().getJSPLevel().equals(J2EEWebNatureRuntime.JSPLEVEL_1_1) && (digester.getJSPLevel() == null || !digester.getJSPLevel().equals(J2EEWebNatureRuntime.JSPLEVEL_1_1)))
+ return false;
+ // JSP 2.0 TLDs are not allowed in JSP 1.2 projects
+ if (getWebNature().getJSPLevel().equals(J2EEWebNatureRuntime.JSPLEVEL_1_2) && (digester.getJSPLevel() == null || !digester.getJSPLevel().equals(J2EEWebNatureRuntime.JSPLEVEL_1_2) || !digester.getJSPLevel().equals(J2EEWebNatureRuntime.JSPLEVEL_1_1)))
+ return false;
+
+ // JSP 2.0 TLDs are allowed in JSP 2.0 projects only
+ if (getWebNature().getJSPLevel().equals(J2EEWebNatureRuntime.JSPLEVEL_2_0) && (digester.getJSPLevel() == null || !digester.getJSPLevel().equals(J2EEWebNatureRuntime.JSPLEVEL_2_0) || !digester.getJSPLevel().equals(J2EEWebNatureRuntime.JSPLEVEL_1_2) || !digester.getJSPLevel().equals(J2EEWebNatureRuntime.JSPLEVEL_1_1)))
+ return false;
+
+
+ return true;
+ }
+
+ protected boolean isValidTLDJarPath(IPath path) {
+ boolean isJSP12 = getWebNature().getJSPLevel().equals(J2EEWebNatureRuntime.JSPLEVEL_1_2);
+ boolean isJSP20 = getWebNature().getJSPLevel().equals(J2EEWebNatureRuntime.JSPLEVEL_2_0);
+
+ if (isJSP12 || isJSP20) {
+ if (!hasTLDExtension(path))
+ return false;
+ if (!(path.matchingFirstSegments(new Path("META-INF")) > 0)) //$NON-NLS-1$
+ return false;
+ } else {
+ if (!path.equals(new Path("META-INF/taglib.tld"))) //$NON-NLS-1$
+ return false;
+ }
+ return true;
+ }
+
+ protected ITaglibInfo[] searchJarFile(IFile jarFile) {
+ return searchJarFile(null, jarFile.getLocation().toFile(), jarFile.getProjectRelativePath());
+ }
+
+ protected ITaglibInfo[] searchJarFile(File jarFile) {
+ return searchJarFile(null, jarFile, new Path(jarFile.getAbsolutePath()));
+ }
+
+ protected ITaglibInfo[] searchJarFile(String uri, File jarFile, IPath projectRelativePath) {
+
+ ArrayList results = new ArrayList();
+ ZipFile zFile = null;
+ try {
+ // Need to check if the jar file has a .tld file anywhere under the
+ // META-INF directory. If there is, add a taglib for the uri that
+ // is inside the TLD file.
+ zFile = new ZipFile(jarFile);
+ ZipEntry[] entries = findTLDEntriesInZip(zFile);
+
+ for (int i = 0; i < entries.length; i++) {
+ ZipEntry entry = entries[i];
+ if (entry != null) {
+ // most entries can be skipped this way
+ if (entry.getName() == null || !entry.getName().toLowerCase().endsWith("tld")) //$NON-NLS-1$
+ continue;
+ TLDDigester digester = getTLDDigester(zFile.getInputStream(entry));
+ IPath entryPath = new Path(entry.getName());
+ if (getWebNature().getJSPLevel().equals(J2EEWebNatureRuntime.JSPLEVEL_1_2) || getWebNature().getJSPLevel().equals(J2EEWebNatureRuntime.JSPLEVEL_2_0)) {
+ String tURI = uri;
+ if (uri == null) {
+ tURI = digester.getURI();
+ }
+
+ // If a uri is found, add a taglib for the uri
+ if (tURI != null) {
+ ITaglibInfo taglib = createTaglibForJar(tURI, projectRelativePath, entryPath);
+ ((TaglibInfo) taglib).setIsURIFromTLD(true);
+ ((TaglibInfo) taglib).setPrefix(digester);
+ results.add(taglib);
+ }
+ }
+
+ if (isTaglibTLD(entryPath.toString())) {
+ boolean canAddTaglibTLD = canAddTaglibTld(digester);
+ if (canAddTaglibTLD) {
+ ITaglibInfo taglib = createTaglibForJar(calculateURIForFile(projectRelativePath), projectRelativePath, entryPath);
+ ((TaglibInfo) taglib).setPrefix(digester);
+ results.add(taglib);
+ }
+ }
+ if (digester != null)
+ digester.close();
+ }
+ }
+ } catch (ZipException e) {
+ Logger.getLogger().logError(e);
+ } catch (IOException e) {
+ Logger.getLogger().logError(e);
+ } finally {
+ if (zFile != null) {
+ try {
+ zFile.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+ return (ITaglibInfo[]) results.toArray(new ITaglibInfo[results.size()]);
+ }
+
+ /**
+ * @return
+ */
+ protected boolean canAddTaglibTld(TLDDigester digester) {
+ return isValidTLD(digester);
+ }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/locator/JavaProjectTaglibLocator.java b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/locator/JavaProjectTaglibLocator.java
new file mode 100644
index 000000000..9e1d916ad
--- /dev/null
+++ b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/locator/JavaProjectTaglibLocator.java
@@ -0,0 +1,122 @@
+/***************************************************************************************************
+ * Copyright (c) 2003, 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.jst.j2ee.internal.web.locator;
+
+import java.util.ArrayList;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jst.j2ee.internal.J2EEConstants;
+import org.eclipse.jst.j2ee.internal.web.taglib.TLDDigester;
+import org.eclipse.jst.j2ee.internal.web.taglib.TaglibInfo;
+import org.eclipse.jst.j2ee.web.taglib.ITaglibInfo;
+
+
+public class JavaProjectTaglibLocator extends AbstractTaglibLocator {
+ protected IJavaProject javaProject;
+ protected IPath metaInfPath;
+
+ /**
+ * Constructor for JavaProjectTaglibLocator.
+ *
+ * @param project
+ */
+ public JavaProjectTaglibLocator(IProject project) {
+ super(project);
+ }
+
+ protected boolean isTLDFile(IFile file) {
+ return isInMetaInfFolder(file) && hasTLDExtension(file.getProjectRelativePath());
+ }
+
+ protected boolean isTaglibTLD(IFile tldFile) {
+ return isTLDFile(tldFile) && tldFile.getProjectRelativePath().lastSegment().equalsIgnoreCase("taglib.tld"); //$NON-NLS-1$
+ }
+
+ protected boolean isInMetaInfFolder(IFile file) {
+ this.metaInfPath = getMetaInfPath();
+ if (file.getFullPath().matchingFirstSegments(this.metaInfPath) >= 1) {
+ return true;
+ }
+ return false;
+ }
+
+ protected IPath getMetaInfPath() {
+ if (this.metaInfPath == null) {
+ try {
+ this.metaInfPath = getJavaProject().getOutputLocation();
+ this.metaInfPath = this.metaInfPath.append(J2EEConstants.META_INF);
+ } catch (JavaModelException e) {
+ this.metaInfPath = new Path("/"); //$NON-NLS-1$
+ }
+ }
+ return this.metaInfPath;
+ }
+
+ /**
+ * @see AbstractTaglibLocator#searchFile(IFile)
+ */
+ protected ITaglibInfo[] searchFile(IFile file) {
+ if (isTLDFile(file)) {
+ return searchTLDFile(file);
+ }
+ return EMPTY_TAGLIBINFO_ARRAY;
+ }
+
+ protected IJavaProject getJavaProject() {
+ if (this.javaProject == null)
+ this.javaProject = JavaCore.create(this.project);
+ return this.javaProject;
+ }
+
+ /**
+ * @see AbstractTaglibLocator#getServerRoot()
+ */
+ protected IPath getServerRoot() {
+ try {
+ return getJavaProject().getOutputLocation();
+ } catch (JavaModelException e) {
+ }
+ return new Path("/"); //$NON-NLS-1$
+ }
+
+ protected ITaglibInfo[] searchTLDFile(IFile file) {
+ ArrayList results = new ArrayList(2);
+ TLDDigester digester = null;
+ try {
+ // Add a taglib for the uri in the tld file.
+ digester = getTLDDigester(file);
+ ITaglibInfo taglib = createTaglibForTLD(file);
+ if (taglib != null) {
+ ((TaglibInfo) taglib).setPrefix(digester);
+ results.add(taglib);
+ }
+
+
+ // Create a URI based on the file location in the project
+ if (isTaglibTLD(file)) {
+ taglib = createTaglibForTLD(calculateURIForFile(file.getProjectRelativePath()), file.getProjectRelativePath());
+ if (taglib != null) {
+ ((TaglibInfo) taglib).setPrefix(digester);
+ results.add(taglib);
+ }
+ }
+
+ } finally {
+ if (digester != null)
+ digester.close();
+ }
+ return (ITaglibInfo[]) results.toArray(new ITaglibInfo[results.size()]);
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/locator/WebLibModuleTaglibLocator.java b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/locator/WebLibModuleTaglibLocator.java
new file mode 100644
index 000000000..d174cc969
--- /dev/null
+++ b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/locator/WebLibModuleTaglibLocator.java
@@ -0,0 +1,227 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 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.jst.j2ee.internal.web.locator;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Vector;
+import java.util.zip.ZipException;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jst.j2ee.internal.web.operations.J2EEWebNatureRuntime;
+import org.eclipse.jst.j2ee.internal.web.plugin.WebPlugin;
+import org.eclipse.jst.j2ee.internal.web.taglib.TLDDigester;
+import org.eclipse.jst.j2ee.internal.web.taglib.TaglibInfo;
+import org.eclipse.jst.j2ee.web.taglib.ITaglibInfo;
+import org.eclipse.jst.j2ee.web.taglib.ITaglibRegistry;
+import org.eclipse.wst.web.internal.operation.ILibModule;
+
+
+/**
+ * @version 1.0
+ * @author
+ */
+public class WebLibModuleTaglibLocator extends AbstractWebTaglibLocator {
+
+ public WebLibModuleTaglibLocator(IProject project) {
+ super(project);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.j2ee.internal.internal.internal.web.taglib.AbstractTaglibLocator#search(org.eclipse.core.resources.IResource)
+ */
+ public ITaglibInfo[] search(IResource resource) {
+ List libModuleTaglibs = calculateLibModuleTaglibs();
+ return (ITaglibInfo[]) libModuleTaglibs.toArray(new ITaglibInfo[libModuleTaglibs.size()]);
+ }
+
+ protected List calculateLibModuleTaglibs() {
+ // Check to see if there are any lib modules, if so, we must check to see
+ // if there are any taglibs in these and concat the results.
+
+ J2EEWebNatureRuntime nature = getWebNature();
+ ILibModule[] libModules = nature.getLibModules();
+ Vector results = new Vector();
+
+ // Go through all of the library modules and add any taglibs
+ // from the java projects they map to.
+ boolean addedJar = false;
+
+ for (int i = 0; i < libModules.length; i++) {
+ ILibModule iLibModule = libModules[i];
+ IProject prj = iLibModule.getProject();
+ ITaglibRegistry registry = WebPlugin.getDefault().getTaglibRegistryManager().getTaglibRegistry(prj);
+ if (registry != null) { // CMVC defect 221661, Web library project being closed
+ ITaglibInfo[] javaTaglibs = registry.getTaglibs();
+
+ // Need to go through the java taglibs and change them to the
+ // appropriate
+ for (int j = 0; j < javaTaglibs.length; j++) {
+ ITaglibInfo iTaglibInfo = javaTaglibs[j];
+ if (iTaglibInfo.isInJar())
+ break;
+ // defect 212671
+ IPath webProjectRelativePath = nature.getLibraryFolder().getProjectRelativePath();
+ IPath jarLocationPath = webProjectRelativePath.append(iLibModule.getJarName());
+ IPath jarName = jarLocationPath.removeFirstSegments(nature.getModuleServerRoot().getProjectRelativePath().segmentCount());
+ // defect 212671 This is important because jarName may not have a leading /
+ IPath jarURI = new Path("/"); //$NON-NLS-1$
+ jarURI = jarURI.append(jarName);
+ if (iTaglibInfo.isURIFromTLD()) {
+ if (getWebNature().getJSPLevel().equals(J2EEWebNatureRuntime.JSPLEVEL_1_2) || getWebNature().getJSPLevel().equals(J2EEWebNatureRuntime.JSPLEVEL_2_0)) {
+ TaglibInfo newTaglib = new TaglibInfo(prj, iTaglibInfo.getURI(), jarLocationPath, iTaglibInfo.getTLDLocation());
+ newTaglib.setIsLibModule(true);
+ newTaglib.setIsURIFromTLD(true);
+ results.add(newTaglib);
+ }
+ }
+ // Add a taglib entry for the jar file if it contains a taglib.tld file.
+ if (!addedJar && isTaglibTLD(iTaglibInfo.getTLDLocation())) {
+ // Direct references can be made no matter what the JSP Level
+ TaglibInfo newTaglib = new TaglibInfo(prj, jarURI.toString(), jarLocationPath, iTaglibInfo.getTLDLocation());
+ newTaglib.setIsLibModule(true);
+ // defect 212671
+ newTaglib.setIsURIFromTLD(false);
+ boolean canAddTaglibTLD = true;
+ if (getWebNature().getJSPLevel().equals(J2EEWebNatureRuntime.JSPLEVEL_1_1)) { // this
+ // clause
+ // is
+ // for
+ // performance,
+ // get
+ // digester
+ // only
+ // for
+ // jsp
+ // 1.1
+ try {
+ TLDDigester digester = new TLDDigester(newTaglib.getTLDStream());
+ if (digester.getJSPLevel() == null || !digester.getJSPLevel().equals(J2EEWebNatureRuntime.JSPLEVEL_1_1))// If
+ // JSP1.1
+ // then
+ // tld
+ // better
+ // be
+ // 1.1
+ // defect
+ // CMVC
+ // 217548
+ canAddTaglibTLD = false;
+ } catch (ZipException e) {
+ } catch (IOException e) {
+ } catch (CoreException e) {
+ }
+ } else if (getWebNature().getJSPLevel().equals(J2EEWebNatureRuntime.JSPLEVEL_1_2)) { // this
+ // clause
+ // is
+ // for
+ // performance,
+ // get
+ // digester
+ // only
+ // for
+ // jsp
+ // 1.1
+ try {
+ TLDDigester digester = new TLDDigester(newTaglib.getTLDStream());
+ String digesterJSPLevel = digester.getJSPLevel();
+
+ if (digesterJSPLevel == null || !digesterJSPLevel.equals(J2EEWebNatureRuntime.JSPLEVEL_1_2) || !digesterJSPLevel.equals(J2EEWebNatureRuntime.JSPLEVEL_1_1))// If
+ // JSP2.0
+ // then
+ // tld
+ // better
+ // be
+ // 1.1
+ // or
+ // 1.2
+ // and
+ // not
+ // 2.0
+ // defect
+ // CMVC
+ // 217548
+ canAddTaglibTLD = false;
+ } catch (ZipException e) {
+ } catch (IOException e) {
+ } catch (CoreException e) {
+ }
+ } else if (getWebNature().getJSPLevel().equals(J2EEWebNatureRuntime.JSPLEVEL_2_0)) { // this
+ // clause
+ // is
+ // for
+ // performance,
+ // get
+ // digester
+ // only
+ // for
+ // jsp
+ // 1.1
+ try {
+ TLDDigester digester = new TLDDigester(newTaglib.getTLDStream());
+ String digesterJSPLevel = digester.getJSPLevel();
+
+ if (digesterJSPLevel == null || !digesterJSPLevel.equals(J2EEWebNatureRuntime.JSPLEVEL_2_0) || !digesterJSPLevel.equals(J2EEWebNatureRuntime.JSPLEVEL_1_2) || !digesterJSPLevel.equals(J2EEWebNatureRuntime.JSPLEVEL_1_1))// If
+ // JSP2.0
+ // then
+ // tld
+ // better
+ // be
+ // 1.1
+ // or
+ // 1.2
+ // and
+ // not
+ // 2.0
+ // defect
+ // CMVC
+ // 217548
+ canAddTaglibTLD = false;
+ } catch (ZipException e) {
+ } catch (IOException e) {
+ } catch (CoreException e) {
+ }
+ }
+ if (canAddTaglibTLD)
+ results.add(newTaglib);
+ addedJar = true; // no matter whether we added the entry or not we cannot
+ // add any other entry either.
+ }
+ }
+ }
+ }
+ return results;
+ }
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.j2ee.internal.internal.internal.web.taglib.AbstractTaglibLocator#searchFile(org.eclipse.core.resources.IFile)
+ */
+ protected ITaglibInfo[] searchFile(IFile file) {
+ // do nothing
+ return new ITaglibInfo[0];
+ }
+
+ protected boolean isTaglibTLD(IPath tldPath) {
+ return tldPath.lastSegment().equalsIgnoreCase("taglib.tld"); //$NON-NLS-1$
+ }
+
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/locator/WebProjectServerTargetTaglibLocator.java b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/locator/WebProjectServerTargetTaglibLocator.java
new file mode 100644
index 000000000..989f13dbd
--- /dev/null
+++ b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/locator/WebProjectServerTargetTaglibLocator.java
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 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
+ *******************************************************************************/
+/*
+ * Created on Jun 15, 2004
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.eclipse.jst.j2ee.internal.web.locator;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jst.j2ee.internal.web.operations.ServerTargetUtil;
+import org.eclipse.jst.j2ee.internal.web.taglib.ServerJarsUtil;
+import org.eclipse.jst.j2ee.internal.web.taglib.TLDDigester;
+import org.eclipse.jst.j2ee.internal.web.taglib.TaglibInfo;
+import org.eclipse.jst.j2ee.web.taglib.ITaglibInfo;
+import org.eclipse.wst.server.core.IRuntime;
+
+/**
+ * @author admin
+ *
+ * TODO To change the template for this generated type comment go to Window - Preferences - Java -
+ * Code Style - Code Templates
+ */
+public class WebProjectServerTargetTaglibLocator extends AbstractWebTaglibLocator {
+
+ private List serverTaglibs;
+ private IRuntime runtime;
+
+ /**
+ * @param project
+ */
+ public WebProjectServerTargetTaglibLocator(IProject project) {
+ super(project);
+ this.serverTaglibs = new ArrayList(2);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.j2ee.internal.internal.internal.web.taglib.AbstractTaglibLocator#search(org.eclipse.core.resources.IResource)
+ */
+ public ITaglibInfo[] search(IResource resource) {
+ // ignore resource calculate server target taglibs
+ IRuntime newRuntime = ServerTargetUtil.getServerTarget(this.project.getName());
+ if (this.runtime != newRuntime) {
+ try {
+ // TODO right now only v6 server contributes taglibs, if more servers are added need
+ // to determine that
+ if (ServerJarsUtil.isTargetedAtWASV6(newRuntime)) {
+ this.serverTaglibs = calculateServerTargetTaglibs();
+ } else
+ this.serverTaglibs.clear();
+
+ } catch (Throwable e) {
+ e.printStackTrace();
+ } finally {
+ this.runtime = newRuntime;
+ }
+ }
+ return (ITaglibInfo[]) this.serverTaglibs.toArray(new ITaglibInfo[this.serverTaglibs.size()]);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.j2ee.internal.internal.internal.web.taglib.AbstractTaglibLocator#searchFile(org.eclipse.core.resources.IFile)
+ */
+ protected ITaglibInfo[] searchFile(File file) {
+ if (hasJarExtension(file.getName())) {
+ return searchJarFile(file);
+ }
+ return EMPTY_TAGLIBINFO_ARRAY;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.j2ee.internal.internal.internal.web.taglib.AbstractTaglibLocator#searchFile(org.eclipse.core.resources.IFile)
+ */
+ protected ITaglibInfo[] searchFile(IFile file) {
+ // do nothing
+ return null;
+ }
+
+ /**
+ * @return
+ */
+ protected List calculateServerTargetTaglibs() {
+ IPath serverJars[] = ServerJarsUtil.getServerJars(this.project);
+ List serverTaglibList = new ArrayList();
+ for (int i = 0; i < serverJars.length; i++) {
+ IPath path = serverJars[i];
+ serverTaglibList.addAll(Arrays.asList(searchFile(path.toFile())));
+ }
+ return serverTaglibList;
+ }
+
+ protected ITaglibInfo createTaglibForJar(String uri, IPath jarfile, IPath tldLocation) {
+ TaglibInfo info = (TaglibInfo) super.createTaglibForJar(uri, jarfile, tldLocation);
+ info.setServerContribution(true);
+ return info;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.j2ee.internal.internal.internal.web.taglib.locator.AbstractWebTaglibLocator#canAddTaglibTld(org.eclipse.jst.j2ee.internal.internal.internal.web.taglib.TLDDigester)
+ */
+ protected boolean canAddTaglibTld(TLDDigester digester) {
+ // as this is a server contributed entry
+ return false;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/locator/WebProjectTaglibLocator.java b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/locator/WebProjectTaglibLocator.java
new file mode 100644
index 000000000..0a7c6f7e0
--- /dev/null
+++ b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/locator/WebProjectTaglibLocator.java
@@ -0,0 +1,191 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 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.jst.j2ee.internal.web.locator;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceVisitor;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jst.j2ee.internal.web.operations.J2EEWebNatureRuntime;
+import org.eclipse.jst.j2ee.internal.web.taglib.DirTaglibInfo;
+import org.eclipse.jst.j2ee.internal.web.taglib.TLDDigester;
+import org.eclipse.jst.j2ee.internal.web.taglib.TaglibInfo;
+import org.eclipse.jst.j2ee.web.taglib.ITaglibInfo;
+
+import com.ibm.wtp.common.logger.proxy.Logger;
+
+/**
+ * @version 1.0
+ * @author
+ */
+public class WebProjectTaglibLocator extends AbstractWebTaglibLocator {
+ public WebProjectTaglibLocator(IProject project) {
+ super(project);
+ }
+
+ protected ITaglibInfo[] searchFile(IFile file) {
+ if (isTaglibJar(file)) {
+ return searchJarFile(file);
+ } else if (isTLDFile(file)) {
+ return searchTLDFile(file);
+ }
+ return EMPTY_TAGLIBINFO_ARRAY;
+ }
+
+ protected ITaglibInfo[] searchDir(IContainer container) {
+ // File containerDir = container.getLocation().toFile();
+ // if(containerDir.isDirectory()){
+ // File tldFiles[] = containerDir.listFiles(new FileFilter() {
+ // public boolean accept(File pathname) {
+ // return (!pathname.isDirectory() && ((new Path(pathname
+ // .getName()).getFileExtension()
+ // .equalsIgnoreCase("tld"))));
+ // }
+ // });
+ // if (tldFiles == null || tldFiles.length == 0) {
+ File tagFiles[] = container.getLocation().toFile().listFiles(new FileFilter() {
+ public boolean accept(File pathname) {
+ return (!pathname.isDirectory() && ((new Path(pathname.getName()).getFileExtension().equalsIgnoreCase("tag")))); //$NON-NLS-1$
+ }
+ });
+ if (tagFiles != null && tagFiles.length > 0) {
+ ITaglibInfo taglib = createTaglibForDir(container, tagFiles);
+
+ if (taglib != null)
+ return new ITaglibInfo[]{taglib};
+ }
+ // }
+ // }
+ return EMPTY_TAGLIBINFO_ARRAY;
+ }
+
+
+ /**
+ * @param container
+ * @param tagFiles
+ * @return
+ */
+ private ITaglibInfo createTaglibForDir(IContainer container, File[] tagFiles) {
+ String uri = calculateURIForFile(container.getProjectRelativePath());
+
+
+
+ DirTaglibInfo dirTaglibInfo = new DirTaglibInfo(container, uri, container.getProjectRelativePath());
+
+ dirTaglibInfo.setPrefix(calculateShortNameForTaglib(uri));
+
+ return dirTaglibInfo;
+ }
+
+ /**
+ * @param uri
+ * @return
+ */
+ private String calculateShortNameForTaglib(String uri) {
+ uri = uri.replace('\\', '/');
+ if (uri.equalsIgnoreCase("/WEB-INF/tags")) //$NON-NLS-1$
+ return "tags"; //$NON-NLS-1$
+
+
+ String suffixOfURI = uri.substring("/WEB-INF/tags/".length()); //$NON-NLS-1$
+ suffixOfURI = suffixOfURI.replace('/', '-');
+ suffixOfURI = suffixOfURI.replace('\\', '-');
+
+ return suffixOfURI;
+
+ }
+
+ protected ITaglibInfo[] searchTLDFile(IFile file) {
+ ArrayList results = new ArrayList(2);
+
+ // Even though the spec says auto-discover should work for loose tld's, both websphere &
+ // tomcat dont do it hence
+ // it is commented
+ // // Add a taglib for the uri in the tld file.
+ // if (getWebNature().isJSP1_2() && isInWebInfFolder(file)) {
+ // ITaglibInfo taglib = createTaglibForTLD(file);
+ // if (taglib != null)
+ // results.add(taglib);
+ // }
+
+ // Create a URI based on the file location in the project
+ //TLDDigester
+ boolean canAddTaglibTLD = true;
+ TLDDigester digester = getTLDDigester(file);
+
+ if (!isValidTLD(digester))// If JSP1.1 then taglib.tld better be 1.1 defect CMVC 217548
+ canAddTaglibTLD = false;
+
+ if (canAddTaglibTLD) {
+ ITaglibInfo taglib = createTaglibForTLD(calculateURIForFile(file.getProjectRelativePath()), file.getProjectRelativePath());
+ ((TaglibInfo) taglib).setPrefix(digester);
+ if (taglib != null)
+ results.add(taglib);
+ }
+ if (digester != null)
+ digester.close();
+ return (ITaglibInfo[]) results.toArray(new ITaglibInfo[results.size()]);
+ }
+
+
+ /*
+ * @see ITaglibLocator#search(IResource)
+ */
+ public ITaglibInfo[] search(IResource resource) {
+ final ArrayList results = new ArrayList();
+
+ try {
+ resource.accept(new IResourceVisitor() {
+ public boolean visit(IResource aresource) throws CoreException {
+ if (aresource.getType() != IResource.FILE) {
+ if (aresource.getType() != IResource.ROOT && WebProjectTaglibLocator.this.project != aresource.getProject())
+ return false;
+ if (getWebNature().getJSPLevel().equals(J2EEWebNatureRuntime.JSPLEVEL_2_0)) {
+ ITaglibInfo[] taglibs = searchDir((IContainer) aresource);
+ if (taglibs != null)
+ results.addAll(Arrays.asList(taglibs));
+ return true;
+ }
+ // directory taglibs are only in jsp 2.0
+ return false;
+
+ }
+
+ if (hasTagExtension(aresource.getName())) {
+ if (getWebNature().getJSPLevel().equals(J2EEWebNatureRuntime.JSPLEVEL_2_0)) {
+ ITaglibInfo[] taglibs = searchDir(aresource.getParent());
+ if (taglibs != null)
+ results.addAll(Arrays.asList(taglibs));
+ }
+ } else {
+ ITaglibInfo[] taglibs = searchFile((IFile) aresource);
+ if (taglibs != null)
+ results.addAll(Arrays.asList(taglibs));
+ }
+
+ return false;
+ }
+ });
+ } catch (CoreException e) {
+ Logger.getLogger().log(e);
+ }
+ return (ITaglibInfo[]) results.toArray(new ITaglibInfo[results.size()]);
+ }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/locator/WebXMLTaglibLocator.java b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/locator/WebXMLTaglibLocator.java
new file mode 100644
index 000000000..4966ed2e8
--- /dev/null
+++ b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/locator/WebXMLTaglibLocator.java
@@ -0,0 +1,329 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 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.jst.j2ee.internal.web.locator;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipException;
+import java.util.zip.ZipFile;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jst.j2ee.internal.J2EEConstants;
+import org.eclipse.jst.j2ee.internal.J2EEVersionConstants;
+import org.eclipse.jst.j2ee.internal.web.operations.J2EEWebNatureRuntime;
+import org.eclipse.jst.j2ee.internal.web.operations.J2EEWebNatureRuntimeUtilities;
+import org.eclipse.jst.j2ee.internal.web.operations.WebEditModel;
+import org.eclipse.jst.j2ee.internal.web.taglib.TLDDigester;
+import org.eclipse.jst.j2ee.internal.web.taglib.TaglibInfo;
+import org.eclipse.jst.j2ee.internal.web.taglib.WebXMLTaglibInfo;
+import org.eclipse.jst.j2ee.jsp.JSPConfig;
+import org.eclipse.jst.j2ee.jsp.TagLibRefType;
+import org.eclipse.jst.j2ee.web.taglib.ITaglibInfo;
+import org.eclipse.jst.j2ee.webapplication.TagLibRef;
+import org.eclipse.jst.j2ee.webapplication.WebApp;
+import org.eclipse.wst.web.internal.operation.ILibModule;
+
+/**
+ * @version 1.0
+ * @author
+ */
+public class WebXMLTaglibLocator extends AbstractWebTaglibLocator {
+
+ public WebXMLTaglibLocator(IProject project) {
+ super(project);
+ }
+
+ protected ILibModule findLibModule(String jarFile) {
+ String fileName = new Path(jarFile).lastSegment();
+ ILibModule[] libModules = getWebNature().getLibModules();
+ for (int i = 0; i < libModules.length; i++) {
+ ILibModule iLibModule = libModules[i];
+ if (iLibModule.getJarName().equals(fileName))
+ return iLibModule;
+ }
+ return null;
+ }
+
+ protected IFile findWebAppRelativeFile(IPath path) {
+ if (path != null) {
+ IResource resource = getWebNature().getModuleServerRoot().findMember(path);
+ if (resource != null && resource.getType() == IResource.FILE)
+ return (IFile) resource;
+ }
+ return null;
+ }
+
+ protected IPath[] findTLDsInJar(IFile jarFile) {
+ ZipFile zFile = null;
+ IPath[] results = new IPath[0];
+
+ try {
+ zFile = new ZipFile(jarFile.getLocation().toFile());
+ ZipEntry[] entries = findTLDEntriesInZip(zFile);
+ results = new IPath[entries.length];
+ for (int i = 0; i < entries.length; i++) {
+ ZipEntry entry = entries[i];
+ results[i] = new Path(entry.getName());
+ }
+ } catch (ZipException e) {
+ } catch (IOException e) {
+ } finally {
+ if (zFile != null) {
+ try {
+ zFile.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+ return results;
+ }
+
+ /*
+ * @see ITaglibLocator#search(IResource)
+ */
+ public ITaglibInfo[] searchFile(IFile file) {
+ // This locator only looks at web.xml files.
+ if (!getWebNature().getWebXMLPath().equals(file.getFullPath()))
+ return EMPTY_TAGLIBINFO_ARRAY;
+
+ J2EEWebNatureRuntime webNature = getWebNature();
+ WebEditModel editModel = null;
+ ArrayList results = new ArrayList();
+
+ try {
+ editModel = webNature.getWebAppEditModelForRead(this);
+ WebApp webApp = editModel.getWebApp();
+ if (webApp == null)
+ return EMPTY_TAGLIBINFO_ARRAY;
+
+ List taglibs = new ArrayList();
+ if (webApp.getVersionID() >= J2EEVersionConstants.WEB_2_4_ID) {
+ JSPConfig config = webApp.getJspConfig();
+ if (config != null)
+ taglibs = config.getTagLibs();
+ } else {
+ taglibs = webApp.getTagLibs();
+ }
+
+ for (Iterator iter = taglibs.iterator(); iter.hasNext();) {
+ TagLibRef taglibRef13;
+ TagLibRefType taglibRef14;
+ String uri;
+ String taglibLocation;
+ if (webApp.getVersionID() >= J2EEVersionConstants.WEB_2_4_ID) {
+ taglibRef14 = (TagLibRefType) iter.next();
+ uri = taglibRef14.getTaglibURI();
+ taglibLocation = taglibRef14.getTaglibLocation();
+ } else {
+ taglibRef13 = (TagLibRef) iter.next();
+ uri = taglibRef13.getTaglibURI();
+ taglibLocation = taglibRef13.getTaglibLocation();
+ }
+
+ IPath projectRelativeLocation = new Path(taglibLocation);
+ IPath webModuleRelativeLocation = getWebAppRelativePath(taglibLocation);
+ if (webModuleRelativeLocation != null) {
+ projectRelativeLocation = webNature.getModuleServerRoot().getProjectRelativePath().append(webModuleRelativeLocation);
+ }
+ WebXMLTaglibInfo taglibInfo = null;
+ IFile locationFile = findWebAppRelativeFile(webModuleRelativeLocation);
+ boolean isLocationResolved = true;
+ if (hasJarExtension(taglibLocation)) {
+ if (locationFile == null) {
+ // If the location file is null it means that the file could not
+ // be found in this project, check to see if it is referencing
+ // a TLD in a lib module
+ IResource resource = findLibModuleRelativeFile(webModuleRelativeLocation);
+ if (resource == null || !resource.exists()) {
+ // Go ahead and create an entry which cannot be resolved
+ // Only the /META-INF/taglib.tld file can be specified in web.xml
+ isLocationResolved = false;
+ taglibInfo = (WebXMLTaglibInfo) createTaglibForJar(uri, projectRelativeLocation, new Path("META-INF/taglib.tld")); //$NON-NLS-1$
+ } else {
+ locationFile = (IFile) resource;
+ taglibInfo = (WebXMLTaglibInfo) createTaglibForLibModuleJar(uri, projectRelativeLocation, resource);
+ setPrefix(taglibInfo, locationFile);
+ }
+ } else {
+ isLocationResolved = true;
+ // Only the /META-INF/taglib.tld file can be specified in web.xml
+ taglibInfo = (WebXMLTaglibInfo) createTaglibForJar(uri, projectRelativeLocation, new Path("META-INF/taglib.tld")); //$NON-NLS-1$
+ setPrefix(taglibInfo, locationFile);
+ }
+ } else {
+ if (locationFile == null)
+ isLocationResolved = false;
+ taglibInfo = (WebXMLTaglibInfo) createTaglibForTLD(uri, projectRelativeLocation);
+ setPrefix(taglibInfo, locationFile);
+
+ }
+ if (taglibInfo != null) {
+ taglibInfo.setIsWebXMLEntry(true);
+ taglibInfo.setWebXMLLocation(new Path(taglibLocation));
+ taglibInfo.setIsLocationResolved(isLocationResolved);
+ // If the location cannot be resolved, set the taglibInfo to be invalid
+ if (!isLocationResolved)
+ taglibInfo.setIsValid(false);
+ results.add(taglibInfo);
+ }
+ }
+ } finally {
+ if (editModel != null)
+ editModel.releaseAccess(this);
+ }
+ return (ITaglibInfo[]) results.toArray(new ITaglibInfo[results.size()]);
+ }
+
+ /**
+ * This method retrieves the short-name from the tld file and adds it as a prefix to the
+ * ITaglibInfo entry
+ *
+ * @param taglibInfo
+ * @param locationFile
+ */
+ private void setPrefix(ITaglibInfo taglibInfo, IFile locationFile) {
+ if (locationFile != null && locationFile.exists()) {
+ TLDDigester digester = null;
+ try {
+ if (isTaglibJar(locationFile)) {
+ digester = getTLDDigester(locationFile, new Path("META-INF/taglib.tld")); //$NON-NLS-1$
+ ((TaglibInfo) taglibInfo).setPrefix(digester);
+ } else if (hasTLDExtension(locationFile.getFullPath())) {
+ digester = getTLDDigester(locationFile);
+ ((TaglibInfo) taglibInfo).setPrefix(digester);
+ }
+ } finally {
+ if (digester != null)
+ digester.close();
+ }
+ }
+ }
+
+ protected ITaglibInfo createTaglibForTLD(String uri, IPath file) {
+ return new WebXMLTaglibInfo(this.project, uri, file);
+ }
+
+ protected ITaglibInfo createTaglibForJar(String uri, IPath jarfile, IPath tldLocation) {
+ WebXMLTaglibInfo taglibInfo = new WebXMLTaglibInfo(this.project, uri, jarfile, tldLocation);
+ return taglibInfo;
+ }
+
+
+ protected ITaglibInfo createTaglibForLibModuleJar(String uri, IPath jarfile, IResource tldFile) {
+ WebXMLTaglibInfo taglibInfo = new WebXMLTaglibInfo(tldFile.getProject(), uri, jarfile, tldFile.getProjectRelativePath());
+ taglibInfo.setIsLibModule(true);
+ return taglibInfo;
+ }
+
+
+ /**
+ * Method findLibModuleRelativeFile.
+ *
+ * @param location
+ * @return String
+ */
+ private IResource findLibModuleRelativeFile(IPath location) {
+ if (location != null) {
+ ILibModule libModule = findLibModule(location.lastSegment());
+ if (libModule != null) {
+ IProject tProject = libModule.getProject();
+ if (tProject.isOpen()) {
+ try {
+ IJavaProject javaProject = JavaCore.create(tProject);
+ IPath outputLocation = javaProject.getOutputLocation();
+ IPath searchPath = outputLocation.removeFirstSegments(1);
+ searchPath = searchPath.append(J2EEConstants.META_INF);
+ searchPath = searchPath.append("taglib.tld"); //$NON-NLS-1$
+ IResource searchResource = tProject.findMember(searchPath);
+ if (searchResource != null)
+ return searchResource;
+ } catch (JavaModelException e) {
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Method getWebAppRelativePath. This method resolves a location specified in a taglib uri to a
+ * project relative IPath
+ *
+ * @return null if the relative path cannot be resolved to an actual resource or a web library
+ * project
+ * @param location
+ * @return IPath
+ */
+ private IPath getWebAppRelativePath(String location) {
+ IPath resolvedPath = null;
+ if (location != null && !location.trim().equals("")) { //$NON-NLS-1$
+ IPath preResolvePath = new Path(location);
+ J2EEWebNatureRuntime webNature = (J2EEWebNatureRuntime) J2EEWebNatureRuntimeUtilities.getRuntime(this.project);
+ IContainer webModuleFolder = webNature.getModuleServerRoot();
+ IContainer webLibraryFolder = webNature.getLibraryFolder();
+ IContainer webInfFolder = webLibraryFolder.getParent();
+ if (preResolvePath.getDevice() == null && !preResolvePath.isEmpty()) {
+ IContainer searchContainer = webModuleFolder;
+ if (!preResolvePath.isAbsolute()) {
+ searchContainer = webInfFolder;
+ }
+ for (int i = 0; i < preResolvePath.segmentCount(); i++) {
+ String pathSegment = preResolvePath.segment(i);
+ if (pathSegment.equals(".")) //$NON-NLS-1$
+ continue;
+ else if (pathSegment.equals("..")) { //$NON-NLS-1$
+ searchContainer = searchContainer.getParent();
+ if (searchContainer.getFullPath().equals(webModuleFolder.getParent().getFullPath()))
+ break; // path must be confined to webModuleFolder
+ } else {
+ IResource resourceFound = searchContainer.findMember(pathSegment);
+ if (resourceFound instanceof IContainer) {
+ searchContainer = (IContainer) resourceFound;
+ } else if (i == preResolvePath.segmentCount() - 1) {
+ if (resourceFound != null) {
+ if (resourceFound.getType() == IResource.FILE) {
+ resolvedPath = resourceFound.getFullPath().removeFirstSegments(webModuleFolder.getFullPath().segmentCount());
+ break; // for readability
+ }
+ } else {
+ // maybe its a web library project, so let us check if the current
+ // container is the lib folder
+ if (webLibraryFolder.getFullPath().equals(searchContainer.getFullPath())) {
+ // the last segment could be the name of the jar for the web
+ // library project
+ if (findLibModule(pathSegment) != null) {
+ resolvedPath = searchContainer.getFullPath().removeFirstSegments(webModuleFolder.getFullPath().segmentCount());
+ resolvedPath = resolvedPath.append(pathSegment);
+ }
+ }
+ }
+ } else
+ break;// not a container, not the last segment either so its an invalid
+ // path
+ }
+ }
+ }
+ }
+ return resolvedPath;
+ }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/DirTaglibInfo.java b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/DirTaglibInfo.java
new file mode 100644
index 000000000..4813158e0
--- /dev/null
+++ b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/DirTaglibInfo.java
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 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
+ *******************************************************************************/
+/*
+ * Created on Jun 17, 2004
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.eclipse.jst.j2ee.internal.web.taglib;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jst.j2ee.web.taglib.IDirTaglibInfo;
+
+
+/**
+ * @author admin
+ *
+ * TODO To change the template for this generated type comment go to Window - Preferences - Java -
+ * Code Style - Code Templates
+ */
+public class DirTaglibInfo extends TaglibInfo implements IDirTaglibInfo {
+
+ private IContainer container;
+
+ //private IFile[] tagFiles;
+
+ /**
+ * @param project
+ * @param uri
+ * @param tldLocation
+ */
+ public DirTaglibInfo(IContainer container, String uri, IPath tldLocation) {
+ super(container.getProject(), uri, tldLocation);
+ this.container = container;
+ setDirectoryEntry(true);
+ // TODO Auto-generated constructor stub
+ }
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.j2ee.internal.internal.taglib.IDirTaglibInfo#getTagFiles()
+ */
+ public IFile[] getTagFiles() {
+ List iFiles = new ArrayList();
+
+ try {
+ IResource resources[] = this.container.members();
+
+ for (int i = 0; i < resources.length; i++) {
+ IResource resource = resources[i];
+ if (resource.getType() == IResource.FILE && resource.getFileExtension().equalsIgnoreCase("tag")) { //$NON-NLS-1$
+ iFiles.add(resource);
+ }
+ }
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return (IFile[]) iFiles.toArray(new IFile[iFiles.size()]);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.j2ee.internal.internal.taglib.IDirTaglibInfo#getDirectory()
+ */
+ public IContainer getDirectory() {
+ return this.container;
+ }
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.j2ee.internal.internal.taglib.IDirTaglibInfo#getTags()
+ */
+ public String[] getTags() {
+ IFile tagFiles[] = getTagFiles();
+ List tagList = new ArrayList();
+ for (int i = 0; i < tagFiles.length; i++) {
+ IFile array_element = tagFiles[i];
+ String filename = array_element.getName();
+ String extn = (new Path(array_element.getName())).getFileExtension();
+ String tagname = filename.substring(0, filename.indexOf("." + extn)); //$NON-NLS-1$
+ tagList.add(tagname);
+ }
+ return (String[]) tagList.toArray(new String[tagList.size()]);
+ }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/ServerJarsUtil.java b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/ServerJarsUtil.java
new file mode 100644
index 000000000..110e46122
--- /dev/null
+++ b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/ServerJarsUtil.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 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
+ *******************************************************************************/
+/*
+ * Created on Jun 15, 2004
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.eclipse.jst.j2ee.internal.web.taglib;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.IClasspathContainer;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jst.server.core.internal.RuntimeClasspathContainer;
+import org.eclipse.wst.server.core.IRuntime;
+
+/**
+ * @author admin
+ *
+ * TODO To change the template for this generated type comment go to Window - Preferences - Java -
+ * Code Style - Code Templates
+ */
+public class ServerJarsUtil {
+
+ public static final String baseV6 = "com.ibm.ws.ast.st.runtime.v60"; //$NON-NLS-1$
+
+
+
+ public static IPath[] getServerJars(IProject project) {
+ IPath ret[] = new IPath[0];
+ IJavaProject javaProject = null;
+ try {
+ javaProject = (IJavaProject) project.getNature(JavaCore.NATURE_ID);
+
+ List list = new ArrayList();
+ IClasspathEntry[] cp = javaProject.getRawClasspath();
+ int size = cp.length;
+ for (int i = 0; i < size; i++) {
+
+ if (cp[i].getPath().segment(0).equals(RuntimeClasspathContainer.SERVER_CONTAINER)) {
+ IClasspathContainer classpathContainer = JavaCore.getClasspathContainer(cp[i].getPath(), javaProject);
+ for (int j = 0; j < classpathContainer.getClasspathEntries().length; j++) {
+ IClasspathEntry entry = classpathContainer.getClasspathEntries()[j];
+ if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
+ list.add(entry.getPath());
+ }
+ }
+ }
+
+ }
+
+ ret = (IPath[]) list.toArray(new IPath[list.size()]);
+ } catch (Exception e) {
+ }
+
+ return ret;
+ }
+
+ public static boolean isTargetedAtWASV6(IRuntime serverTarget) {
+ boolean allowed = false;
+ String id = getServerId(serverTarget);
+ if (id != null) {
+ // System.out.println("Server id = " + id);
+ // System.out.print("Server type = " +
+ // serverTarget.getRuntimeType());
+ if (serverTarget != null) {
+ if (baseV6.equals(id)) {
+ allowed = true;
+ }
+ }
+ }
+ return allowed;
+ }
+
+ private static String getServerId(IRuntime serverTarget) {
+ String id = null;
+ if (serverTarget != null && serverTarget.getRuntimeType() != null) {
+ id = serverTarget.getRuntimeType().getId();
+ }
+ return id;
+ }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/TLDDigester.java b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/TLDDigester.java
new file mode 100644
index 000000000..1ba574923
--- /dev/null
+++ b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/TLDDigester.java
@@ -0,0 +1,250 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 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.jst.j2ee.internal.web.taglib;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringReader;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.eclipse.jst.j2ee.internal.web.operations.J2EEWebNatureRuntime;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentType;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+import com.ibm.wtp.common.logger.proxy.Logger;
+
+/**
+ * This class parses tld files and produces TLDs, and Tags, and Attributes
+ *
+ * Creation date: (11/7/2001 10:33:15 AM)
+ *
+ * @author: Mindaugas Idzelis
+ */
+public class TLDDigester {
+ private InputStream istream;
+ private Document document;
+
+ protected final static String PUBLICID_11 = "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"; //$NON-NLS-1$
+ protected final static String PUBLICID_12 = "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"; //$NON-NLS-1$
+ protected final static String PUBLICID_20 = "http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd"; //$NON-NLS-1$
+ private static ErrorHandler errorHandler;
+ private static EntityResolver resolver;
+
+
+ public TLDDigester(InputStream stream) {
+ super();
+ this.istream = stream;
+ getDocument();
+ }
+
+ public void close() {
+ if (this.istream != null) {
+ try {
+ this.istream.close();
+ } catch (IOException exc) {
+ }
+ }
+ }
+
+ // public boolean isJSP11() {
+ // if(getDocument() != null){
+ // DocumentType docType = getDocument().getDoctype();
+ // if (docType != null && PUBLICID_11.equals(docType.getPublicId()))
+ // return true;
+ // }
+ // return false;
+ // }
+ public String getJSPLevel() {
+ if (getDocument() != null) {
+ // xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
+ // web-jsptaglibrary_2_0.xsd"
+ // version="2.0"
+ Element docElement = getDocument().getDocumentElement();
+ if (docElement != null && "2.0".equals(docElement.getAttribute("version")) //$NON-NLS-1$ //$NON-NLS-2$
+ && PUBLICID_20.equals(docElement.getAttribute("xsi:schemaLocation"))) //$NON-NLS-1$
+ return J2EEWebNatureRuntime.JSPLEVEL_2_0;
+
+ DocumentType docType = getDocument().getDoctype();
+
+ if (docType != null && PUBLICID_12.equals(docType.getPublicId()))
+ return J2EEWebNatureRuntime.JSPLEVEL_1_2;
+
+ if (docType != null && PUBLICID_11.equals(docType.getPublicId()))
+ return J2EEWebNatureRuntime.JSPLEVEL_1_1;
+
+ }
+ return null;
+ }
+
+ public String getURI() {
+ Node taglibNode = getTaglibNode();
+ if (taglibNode != null)
+ return getTagValue(taglibNode, "uri"); //$NON-NLS-1$
+ return null;
+ }
+
+ public String getShortName() {
+ Node taglibNode = getTaglibNode();
+ String retVal = null;
+ if (taglibNode != null) {
+ retVal = getTagValue(taglibNode, "shortname"); //$NON-NLS-1$
+ if (retVal == null)
+ retVal = getTagValue(taglibNode, "short-name"); //$NON-NLS-1$
+ }
+ return retVal;
+ }
+
+ public String getDescription() {
+ Node taglibNode = getTaglibNode();
+ String retVal = null;
+ if (taglibNode != null) {
+ retVal = getTagValue(taglibNode, "description"); //$NON-NLS-1$
+ if (retVal == null)
+ retVal = getTagValue(taglibNode, "info"); //$NON-NLS-1$
+ }
+ return null;
+ }
+
+ protected Document createDocument() {
+ Document doc = null;
+
+ InputSource inputSource = new InputSource(this.istream);
+ // ClassLoader prevClassLoader = Thread.currentThread().getContextClassLoader();
+ try {
+ // Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ try {
+
+ dbf.setValidating(false);
+
+ // dbf.setAttribute("http://apache.org/xml/features/continue-after-fatal-error",
+ // Boolean.TRUE); //$NON-NLS-1$
+ // dbf.setAttribute("http://apache.org/xml/features/nonvalidating/load-dtd-grammar",
+ // Boolean.FALSE); //$NON-NLS-1$
+ // dbf.setAttribute("http://apache.org/xml/features/nonvalidating/load-external-dtd",
+ // Boolean.FALSE); //$NON-NLS-1$
+
+ DocumentBuilder builder = dbf.newDocumentBuilder();
+ builder.setEntityResolver(getEntityResolver());
+ builder.setErrorHandler(getNullErrorHandler());
+ doc = builder.parse(inputSource);
+ } catch (ParserConfigurationException e) {
+ //e.printStackTrace();
+ } catch (SAXException e) {
+ //e.printStackTrace();
+ } catch (IOException e) {
+ //e.printStackTrace();
+ }
+ } finally {
+ // Thread.currentThread().setContextClassLoader(prevClassLoader);
+ }
+ return doc;
+ }
+
+ public Document getDocument() {
+ if (this.document == null) {
+ this.document = createDocument();
+ }
+ return this.document;
+ }
+
+ protected Node getTaglibNode() {
+ Document doc = getDocument();
+ Node taglibNode = null;
+ if (doc != null) {
+ taglibNode = findChildNode(doc, "taglib"); //$NON-NLS-1$
+ }
+ return taglibNode;
+ }
+
+ protected Node findChildNode(Node parent, String nodeName) {
+ NodeList list = parent.getChildNodes();
+ int length = list.getLength();
+ for (int i = 0; i < length; ++i) {
+ Node curNode = list.item(i);
+ if (curNode.getNodeType() == Node.ELEMENT_NODE) {
+ Element curElement = (Element) curNode;
+ if (curElement.getNodeName().equalsIgnoreCase(nodeName))
+ return curElement;
+ }
+ }
+ return null;
+ }
+
+ protected String getTagValue(Node node, String tagName) {
+ Node childNode = findChildNode(node, tagName);
+ if (childNode != null) {
+ Node textNode = childNode.getFirstChild();
+ if ((textNode != null) && (textNode.getNodeType() == Node.TEXT_NODE)) {
+ return removeWhitespace(textNode.getNodeValue());
+ }
+ }
+ return null;
+ }
+
+ protected String removeWhitespace(String string) {
+ return string.trim().replace(' ', '_');
+ }
+
+ /**
+ * Returns an EntityResolver that won't try to load and resolve ANY entities
+ */
+ private static EntityResolver getEntityResolver() {
+ if (resolver == null) {
+ resolver = new EntityResolver() {
+ public InputSource resolveEntity(String publicID, String systemID) throws SAXException, IOException {
+ InputSource result = null;
+ if (result == null) {
+ result = new InputSource(new StringReader("")); //$NON-NLS-1$
+ result.setPublicId(publicID);
+ result.setSystemId(systemID != null ? systemID : "/_" + getClass().getName()); //$NON-NLS-1$
+ }
+ return result;
+ }
+ };
+ }
+ return resolver;
+ }
+
+ /**
+ * Returns an ErrorHandler that will not stop the parser on reported errors
+ */
+ private static ErrorHandler getNullErrorHandler() {
+ if (errorHandler == null) {
+ errorHandler = new ErrorHandler() {
+ public void error(SAXParseException exception) throws SAXException {
+ Logger.getLogger().log(exception);
+ }
+
+ public void fatalError(SAXParseException exception) throws SAXException {
+ Logger.getLogger().log(exception);
+ }
+
+ public void warning(SAXParseException exception) throws SAXException {
+ Logger.getLogger().log(exception);
+ }
+ };
+ }
+ return errorHandler;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/TaglibInfo.java b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/TaglibInfo.java
new file mode 100644
index 000000000..b392976e0
--- /dev/null
+++ b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/TaglibInfo.java
@@ -0,0 +1,379 @@
+/***************************************************************************************************
+ * Copyright (c) 2003, 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.jst.j2ee.internal.web.taglib;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipException;
+import java.util.zip.ZipFile;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jst.j2ee.internal.web.operations.J2EEWebNatureRuntime;
+import org.eclipse.jst.j2ee.internal.web.operations.J2EEWebNatureRuntimeUtilities;
+import org.eclipse.jst.j2ee.internal.web.operations.ProjectSupportResourceHandler;
+import org.eclipse.jst.j2ee.web.taglib.ITaglibInfo;
+
+
+public class TaglibInfo implements ITaglibInfo, Cloneable {
+ private IPath location;
+ private String uri;
+ private IPath tldLocation;
+ private String prefix;
+ private IProject project;
+
+ private boolean isInJar = false;
+ private boolean isWebXMLEntry = false;
+ private boolean isURIFromTLD = false;
+ private boolean isLibModule = false;
+ private boolean isValid = true;
+
+ private boolean isServerContribution = false;
+ private boolean isDirectoryEntry = false;
+
+ public TaglibInfo(IProject project, String uri, IPath tldLocation) {
+ this.project = project;
+ this.uri = uri;
+ this.location = tldLocation;
+ this.tldLocation = tldLocation;
+ this.isInJar = false;
+ }
+
+ public TaglibInfo(IProject project, String uri, IPath jarLocation, IPath tldLocation) {
+ this.project = project;
+ this.uri = uri;
+ this.location = jarLocation;
+ this.isInJar = true;
+ this.tldLocation = tldLocation;
+ }
+
+
+ public Object clone() {
+ Object o = null;
+ try {
+ o = super.clone();
+ } catch (CloneNotSupportedException e) {
+ System.err.println(ProjectSupportResourceHandler.getString("Cannot_clone_TaglibInfo_1_EXC_")); //$NON-NLS-1$
+ }
+ return o;
+ }
+
+ /*
+ * @see ITaglibInfo#getLocation()
+ */
+ public IPath getLocation() {
+ return this.location;
+ }
+
+ /*
+ * @see ITaglibInfo#getURI()
+ */
+ public String getURI() {
+ return this.uri;
+ }
+
+ /*
+ * @see ITaglibInfo#isInJar()
+ */
+ public boolean isInJar() {
+ return this.isInJar;
+ }
+
+ /*
+ * @see ITaglibInfo#getTLDLocation()
+ */
+ public IPath getTLDLocation() {
+ return this.tldLocation;
+ }
+
+
+ /**
+ * Sets the location of the TLD file.
+ *
+ * @param tldLocation
+ * The tldLocation to set
+ */
+ public void setTLDLocation(IPath tldLocation) {
+ this.tldLocation = tldLocation;
+ }
+
+ /*
+ * @see Object#toString()
+ */
+ public String toString() {
+ if (this.isInJar)
+ return "TaglibInfo(JAR" + (isWebXMLEntry() ? ",WEB.XML: " : ": ") + getURI() + ", " + this.location + ", " + this.tldLocation + ", " + isURIFromTLD() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
+
+ return "TaglibInfo(TLD" + (isWebXMLEntry() ? ",WEB.XML: " : ": ") + getURI() + ", " + this.location + ", " + isURIFromTLD() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
+ }
+
+ /*
+ * @see ITaglibInfo#isWebXMLEntry()
+ */
+ public boolean isWebXMLEntry() {
+ return this.isWebXMLEntry;
+ }
+
+ /*
+ * @see Object#equals(Object)
+ */
+ public boolean equals(Object object) {
+ if (object == null)
+ return false;
+ if (!(object instanceof ITaglibInfo))
+ return false;
+ ITaglibInfo taglibInfo = (ITaglibInfo) object;
+ return this.getLocation().equals(taglibInfo.getLocation()) && this.getTLDLocation().equals(taglibInfo.getTLDLocation()) && this.getURI().equals(taglibInfo.getURI()) && this.isWebXMLEntry() == taglibInfo.isWebXMLEntry();
+ }
+
+ /**
+ * Sets the isWebXMLEntry.
+ *
+ * @param isWebXMLEntry
+ * The isWebXMLEntry to set
+ */
+ public void setIsWebXMLEntry(boolean isWebXMLEntry) {
+ this.isWebXMLEntry = isWebXMLEntry;
+ }
+
+ /*
+ * @see ITaglibInfo#setIsValid()
+ */
+ public void setIsValid(boolean validity) {
+ this.isValid = validity;
+ }
+
+ /*
+ * @see ITaglibInfo#getPrefix()
+ */
+ public String getPrefix() {
+ return this.prefix;
+ }
+
+ /*
+ * @see ITaglibInfo#getSourceProject()
+ */
+ public IProject getSourceProject() {
+ return this.project;
+ }
+
+ /*
+ * @see ITaglibInfo#setPrefix(String)
+ */
+ public void setPrefix(String prefix) {
+ this.prefix = prefix;
+ }
+
+ public void setPrefix(TLDDigester digester) {
+ if (digester != null) {
+ String aprefix = digester.getShortName();
+ if (aprefix != null)
+ setPrefix(aprefix);
+ }
+ }
+
+
+
+ /*
+ * @see ITaglibInfo#getTLDStream()
+ */
+ public InputStream getTLDStream() throws ZipException, IOException, CoreException {
+ File javaIOFile = null;
+ IFile file = null;
+ boolean bIsInJar = false;
+ if (isLibModule()) {
+ file = (IFile) this.project.findMember(getTLDLocation());
+ javaIOFile = file.getLocation().toFile();
+ } else if (isServerContribution()) {
+ javaIOFile = getLocation().toFile();
+ bIsInJar = isInJar();
+ } else {
+ file = (IFile) this.project.findMember(getLocation());
+ if (file != null) {
+ javaIOFile = file.getLocation().toFile();
+ }
+
+
+ // for webxml entries try relative to web.xml
+ if (javaIOFile == null || !javaIOFile.exists()) {
+ if (isWebXMLEntry()) {
+ IPath taglibPath = getLocation();
+ if (!taglibPath.isAbsolute()) {
+ J2EEWebNatureRuntime webNature = (J2EEWebNatureRuntime) J2EEWebNatureRuntimeUtilities.getRuntime(this.project);
+ IContainer webInfContainer = (IContainer) this.project.findMember(webNature.getWEBINFPath());
+ IResource resolvedResource = webInfContainer.findMember(taglibPath);
+ if (resolvedResource instanceof IFile) {
+ file = (IFile) resolvedResource;
+ javaIOFile = file.getLocation().toFile();
+ }
+ }
+ }
+ }
+ bIsInJar = isInJar();
+ }
+
+ if (bIsInJar) {
+ if (javaIOFile != null) {
+ ZipFile zFile = new ZipFile(javaIOFile);
+ try {
+ ZipEntry entry = zFile.getEntry(getTLDLocation().toString());
+ if (entry != null) {
+ InputStream zipInputStream = zFile.getInputStream(entry);
+ InputStream retStream = bufferInputStream(zipInputStream);
+ zipInputStream.close();
+ return retStream;
+ }
+ } finally {
+ if (zFile != null)
+ zFile.close();
+ }
+ }
+ } else {
+ if (file != null)
+ return file.getContents();
+ // there is no server contributed tld, only jars
+ // else if(javaIOFile != null)
+ // return new FileInputStream(javaIOFile);
+ }
+ return null;
+ }
+
+ protected InputStream bufferInputStream(InputStream is) throws IOException {
+ try {
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ if (is != null) {
+ int available = is.available();
+ int totalRead = 0;
+ byte[] read = new byte[available];
+ while (totalRead < available) {
+ int numRead = is.read(read, 0, available);
+ output.write(read, 0, numRead);
+ totalRead += numRead;
+ }
+ }
+ output.close();
+ return new ByteArrayInputStream(output.toByteArray());
+ } catch (IOException e) {
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+ return null;
+ }
+
+ public String getTLDString() {
+ InputStream is = null;
+ try {
+ is = getTLDStream();
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ if (is != null) {
+ int available = is.available();
+ byte[] read = new byte[available];
+ int numRead = is.read(read);
+ output.write(read, 0, numRead);
+ }
+ output.close();
+ return output.toString();
+ } catch (ZipException e) {
+ } catch (IOException e) {
+ } catch (CoreException e) {
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+ return ProjectSupportResourceHandler.getString("Could_not_read_TLD_15"); //$NON-NLS-1$
+ }
+
+ /**
+ * @see ITaglibInfo#isURIFromTLD()
+ */
+ public boolean isURIFromTLD() {
+ return this.isURIFromTLD;
+ }
+
+ /**
+ * Sets the isURIFromTLD.
+ *
+ * @param isURIFromTLD
+ * The isURIFromTLD to set
+ */
+ public void setIsURIFromTLD(boolean isURIFromTLD) {
+ this.isURIFromTLD = isURIFromTLD;
+ }
+
+ /**
+ * @see ITaglibInfo#isLibModule()
+ */
+ public boolean isLibModule() {
+ return this.isLibModule;
+ }
+
+ /**
+ * Sets the isLibModule. flag
+ *
+ * @param isLibModule
+ * The isLibModule to set
+ */
+ public void setIsLibModule(boolean isLibModule) {
+ this.isLibModule = isLibModule;
+ }
+
+ /**
+ * @see ITaglibInfo#isValid()
+ */
+ public boolean isValid() {
+ return this.isValid;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.j2ee.internal.internal.taglib.ITaglibInfo#isServerContribution()
+ */
+ public boolean isServerContribution() {
+ return this.isServerContribution;
+ }
+
+ public void setServerContribution(boolean isServerContribution) {
+ this.isServerContribution = isServerContribution;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.j2ee.internal.internal.taglib.ITaglibInfo#isDirectoryEntry()
+ */
+ public boolean isDirectoryEntry() {
+ return this.isDirectoryEntry;
+ }
+
+ /**
+ * @param isDirectoryEntry
+ * The isDirectoryEntry to set.
+ */
+ public void setDirectoryEntry(boolean isDirectoryEntry) {
+ this.isDirectoryEntry = isDirectoryEntry;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/TaglibRegistryManager.java b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/TaglibRegistryManager.java
new file mode 100644
index 000000000..583e985d6
--- /dev/null
+++ b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/TaglibRegistryManager.java
@@ -0,0 +1,172 @@
+/***************************************************************************************************
+ * Copyright (c) 2003, 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.jst.j2ee.internal.web.taglib;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+
+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.jdt.core.JavaCore;
+import org.eclipse.jst.j2ee.internal.project.IWebNatureConstants;
+import org.eclipse.jst.j2ee.internal.web.taglib.registry.JavaTaglibRegistry;
+import org.eclipse.jst.j2ee.internal.web.taglib.registry.WebTaglibRegistry;
+import org.eclipse.jst.j2ee.web.taglib.ITaglibRegistry;
+import org.eclipse.jst.j2ee.web.taglib.ITaglibRegistryManager;
+
+
+public class TaglibRegistryManager implements ITaglibRegistryManager {
+
+
+
+ protected HashMap registries = new HashMap();
+ protected IResourceChangeListener resourceListener;
+
+ private class ResourceChangeListener implements IResourceChangeListener, IResourceDeltaVisitor {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent)
+ */
+ public void resourceChanged(IResourceChangeEvent event) {
+ if (event.getSource() instanceof IWorkspace) {
+ IResourceDelta delta = event.getDelta();
+ switch (event.getType()) {
+ case IResourceChangeEvent.POST_CHANGE :
+ if (delta != null) {
+ try {
+ delta.accept(this);
+ } catch (CoreException e) {
+ }
+ }
+ break;
+ case IResourceChangeEvent.PRE_CLOSE :
+ case IResourceChangeEvent.PRE_DELETE :
+ removeTaglibRegistry((IProject) event.getResource());
+ break;
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.resources.IResourceDeltaVisitor#visit(org.eclipse.core.resources.IResourceDelta)
+ */
+ public boolean visit(IResourceDelta delta) throws CoreException {
+ if (delta != null) {
+ TaglibRegistryManager.this.resourceChanged(delta);
+ return true;
+ }
+ return false;
+ }
+
+ }
+
+ public TaglibRegistryManager() {
+ super();
+ initialize();
+ }
+
+ protected ITaglibRegistry createNewRegistry(IProject project) {
+ ITaglibRegistry registry = null;
+ try {
+ if (project != null && project.isAccessible()) { // CMVC defect 221661, Web library
+ // project being closed
+ if (project.hasNature(IWebNatureConstants.J2EE_NATURE_ID)) {
+ registry = new WebTaglibRegistry(project);
+ } else if (project.hasNature(JavaCore.NATURE_ID)) {
+ registry = new JavaTaglibRegistry(project);
+ }
+ }
+ } catch (CoreException e) {
+ }
+ if (registry != null) {
+ this.registries.put(project, registry);
+ }
+ return registry;
+ }
+
+ protected void initialize() {
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ this.resourceListener = new ResourceChangeListener();
+ workspace.addResourceChangeListener(this.resourceListener);
+ }
+
+ protected void resourceChanged(IResourceDelta delta) {
+ if (delta.getResource() instanceof IProject)
+ return;
+
+ Collection registryCol = this.registries.values();
+ for (Iterator iter = registryCol.iterator(); iter.hasNext();) {
+ ITaglibRegistry registry = (ITaglibRegistry) iter.next();
+ if (delta.getResource().getProject() == registry.getProject()) {
+ registry.processResourceChanged(delta);
+ }
+ }
+ }
+
+ protected void removeTaglibRegistry(IProject project) {
+ this.registries.remove(project);
+ }
+
+ /**
+ * @see ITaglibRegistryManager#getTaglibRegistry(IProject)
+ */
+ public ITaglibRegistry getTaglibRegistry(IProject project) {
+ ITaglibRegistry registry = (ITaglibRegistry) this.registries.get(project);
+ if (registry == null) {
+ registry = createNewRegistry(project);
+ }
+ return registry;
+ }
+
+ /**
+ * @see ITaglibRegistryManager#dispose()
+ */
+ public void dispose() {
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ workspace.removeResourceChangeListener(this.resourceListener);
+ this.registries = null;
+ }
+
+ /**
+ * @see Object#toString()
+ */
+ public String toString() {
+ StringBuffer buf = new StringBuffer();
+ Collection regCol = this.registries.values();
+ for (Iterator iter = regCol.iterator(); iter.hasNext();) {
+ ITaglibRegistry registry = (ITaglibRegistry) iter.next();
+ buf.append("=== Registry for " + registry.getProject() + "===\n"); //$NON-NLS-1$ //$NON-NLS-2$
+ buf.append(registry);
+ buf.append("\n"); //$NON-NLS-1$
+ }
+ return buf.toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.j2ee.internal.internal.taglib.ITaglibRegistryManager#isTaglibRegistryExists(org.eclipse.core.resources.IProject)
+ */
+ public boolean isTaglibRegistryExists(IProject project) {
+ return this.registries.containsKey(project);
+ }
+
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/WebProjectServerTaglibListener.java b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/WebProjectServerTaglibListener.java
new file mode 100644
index 000000000..837dc5f62
--- /dev/null
+++ b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/WebProjectServerTaglibListener.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 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
+ *******************************************************************************/
+/*
+ * Created on Jun 15, 2004
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.eclipse.jst.j2ee.internal.web.taglib;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jst.j2ee.internal.web.plugin.WebPlugin;
+import org.eclipse.wst.server.core.IRuntime;
+import org.eclipse.wst.server.core.model.IRuntimeTargetHandlerDelegate;
+
+/**
+ * @author admin
+ *
+ * TODO To change the template for this generated type comment go to Window - Preferences - Java -
+ * Code Style - Code Templates
+ */
+public class WebProjectServerTaglibListener implements IRuntimeTargetHandlerDelegate {
+ private IRuntime runtimeToBeRemoved;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.wst.server.core.model.IRuntimeTargetHandlerDelegate#setRuntimeTarget(org.eclipse.core.resources.IProject,
+ * org.eclipse.wst.server.core.IRuntime, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public void setRuntimeTarget(IProject project, IRuntime runtime, IProgressMonitor monitor) throws CoreException {
+ // TODO right now only v6 server contributes taglibs, if more servers are added need to
+ // determine that
+ if (this.runtimeToBeRemoved != null) {
+ if (ServerJarsUtil.isTargetedAtWASV6(this.runtimeToBeRemoved) || ServerJarsUtil.isTargetedAtWASV6(runtime)) {
+ if (WebPlugin.getDefault().getTaglibRegistryManager().isTaglibRegistryExists(project))
+ WebPlugin.getDefault().getTaglibRegistryManager().getTaglibRegistry(project).refresh();
+ }
+ }
+ this.runtimeToBeRemoved = null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.wst.server.core.model.IRuntimeTargetHandlerDelegate#removeRuntimeTarget(org.eclipse.core.resources.IProject,
+ * org.eclipse.wst.server.core.IRuntime, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public void removeRuntimeTarget(IProject project, IRuntime runtime, IProgressMonitor monitor) throws CoreException {
+ this.runtimeToBeRemoved = runtime;
+ }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/WebXMLTaglibInfo.java b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/WebXMLTaglibInfo.java
new file mode 100644
index 000000000..a16aa62f7
--- /dev/null
+++ b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/WebXMLTaglibInfo.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 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.jst.j2ee.internal.web.taglib;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jst.j2ee.web.taglib.IWebXMLTaglibInfo;
+
+
+/**
+ * @author wsad2
+ *
+ * To change this generated comment edit the template variable "typecomment":
+ * Window>Preferences>Java>Templates. To enable and disable the creation of type comments go to
+ * Window>Preferences>Java>Code Generation.
+ */
+public class WebXMLTaglibInfo extends TaglibInfo implements IWebXMLTaglibInfo {
+
+ public WebXMLTaglibInfo(IProject project, String uri, IPath tldLocation) {
+ super(project, uri, tldLocation);
+ setWebXMLLocation(getLocation());
+ }
+
+ public WebXMLTaglibInfo(IProject project, String uri, IPath jarLocation, IPath tldLocation) {
+ super(project, uri, jarLocation, tldLocation);
+ setWebXMLLocation(getLocation());
+ }
+
+
+
+ private boolean isLocationResolved = true;
+
+ private IPath webXMLLocation;
+
+
+ /**
+ * @see org.eclipse.jst.j2ee.internal.internal.taglib.IWebXMLTaglibInfo#isLocationResolved()
+ */
+ public boolean isLocationResolved() {
+ return this.isLocationResolved;
+ }
+
+ /**
+ * @see org.eclipse.jst.j2ee.internal.internal.taglib.IWebXMLTaglibInfo#getWebXMLTaglibLocation()
+ */
+ public IPath getWebXMLTaglibLocation() {
+ return this.webXMLLocation;
+ }
+
+
+ /**
+ * Sets the isLocationResolved.
+ *
+ * @param isLocationResolved
+ * The isLocationResolved to set
+ */
+ public void setIsLocationResolved(boolean isResolved) {
+ this.isLocationResolved = isResolved;
+ }
+
+ /**
+ * Sets the webXMLLocation.
+ *
+ * @param webXMLLocation
+ * The webXMLLocation to set
+ */
+ public void setWebXMLLocation(IPath webXMLLocation) {
+ this.webXMLLocation = webXMLLocation;
+ }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/registry/AbstractTaglibRegistry.java b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/registry/AbstractTaglibRegistry.java
new file mode 100644
index 000000000..dbd5d0942
--- /dev/null
+++ b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/registry/AbstractTaglibRegistry.java
@@ -0,0 +1,555 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 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.jst.j2ee.internal.web.taglib.registry;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.Vector;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IResourceVisitor;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jst.j2ee.internal.project.IWebNatureConstants;
+import org.eclipse.jst.j2ee.internal.web.locator.WebProjectTaglibLocator;
+import org.eclipse.jst.j2ee.internal.web.locator.WebXMLTaglibLocator;
+import org.eclipse.jst.j2ee.web.taglib.ITaglibInfo;
+import org.eclipse.jst.j2ee.web.taglib.ITaglibLocator;
+import org.eclipse.jst.j2ee.web.taglib.ITaglibRegistry;
+import org.eclipse.jst.j2ee.web.taglib.ITaglibRegistryListener;
+
+import com.ibm.wtp.common.logger.proxy.Logger;
+
+
+/**
+ * @version 1.0
+ * @author
+ */
+abstract public class AbstractTaglibRegistry implements ITaglibRegistry {
+ private static final boolean debug = false;
+
+ protected IProject project;
+ protected Vector listeners;
+ protected Vector taglibs; // of type ITaglibInfo
+ protected ITaglibLocator[] locators;
+ protected boolean needsRefresh = false;
+
+ public AbstractTaglibRegistry(IProject project) {
+ this.project = project;
+ initialize();
+ refresh();
+ }
+
+ protected void initialize() {
+ this.locators = new ITaglibLocator[]{new WebProjectTaglibLocator(this.project), new WebXMLTaglibLocator(this.project)};
+ }
+
+ /*
+ * @see ITaglibRegistry#addTaglibRegistryListener(ITaglibRegistryListener)
+ */
+ protected void addTaglib(ITaglibInfo taglib) {
+ // Add web.xml entries at the top of the list so that they are
+ // always returned first from the getTaglib(uri) method.
+ if (taglib.isWebXMLEntry())
+ this.taglibs.add(0, taglib);
+ else
+ this.taglibs.add(taglib);
+ }
+
+ public void addTaglibRegistryListener(ITaglibRegistryListener listener) {
+ if (this.listeners == null)
+ this.listeners = new Vector();
+ this.listeners.add(listener);
+ }
+
+ /*
+ * @see ITaglibRegistry#getTaglib(IPath)
+ */
+ public ITaglibInfo[] getTaglibs(IPath location) {
+ Vector results = getTaglibsVector(location);
+ return (ITaglibInfo[]) results.toArray(new ITaglibInfo[results.size()]);
+ }
+
+ protected Vector getTaglibsVector(IPath location) {
+ Vector results = new Vector();
+ Vector tTaglibs = primGetTaglibs();
+
+ boolean isWebXML = isWebXMLFile(location);
+
+ // Start at the beginning of the taglib list and return the first
+ // one that matches the location passed in.
+ for (Iterator iter = tTaglibs.iterator(); iter.hasNext();) {
+ ITaglibInfo taglib = (ITaglibInfo) iter.next();
+ if (isWebXML) {
+ if (taglib.isWebXMLEntry())
+ results.add(taglib);
+ } else if (taglib.getLocation().equals(location))
+ results.add(taglib);
+ }
+ return results;
+ }
+
+ protected Vector getExistingTaglibs(IPath location) {
+ Vector results = new Vector();
+ Vector tTaglibs = this.taglibs;
+
+ boolean isWebXML = isWebXMLFile(location);
+
+ // Start at the beginning of the taglib list and return the first
+ // one that matches the location passed in.
+ for (Iterator iter = tTaglibs.iterator(); iter.hasNext();) {
+ ITaglibInfo taglib = (ITaglibInfo) iter.next();
+ if (isWebXML) {
+ if (taglib.isWebXMLEntry())
+ results.add(taglib);
+ } else if (taglib.getLocation().equals(location) && !taglib.isWebXMLEntry())
+ results.add(taglib);
+ }
+ return results;
+ }
+
+ public IProject getProject() {
+ return this.project;
+ }
+
+ /*
+ * @see ITaglibRegistry#getRecommendedTaglibs()
+ */
+ public ITaglibInfo[] getRecommendedTaglibs() {
+ // we pass false because we dont want to show all entries per resource,just one
+ return getValidTaglibs(false);
+ }
+
+ /*
+ * @see ITaglibRegistry#getVisibleTaglibs()
+ */
+ public ITaglibInfo[] getVisibleTaglibs() {
+ // we pass true because we want to show all entries that are valid uri's for a resource
+ return getValidTaglibs(true);
+ }
+
+
+ protected ITaglibInfo[] getValidTaglibs(boolean showAllEntriesPerResource) {
+ Vector allTaglibs = primGetTaglibs();
+ Vector results = new Vector(allTaglibs.size());
+ Set locationSet = new HashSet();
+ Set uriSet = new HashSet();
+
+ // first pass web.xml entries
+ for (Iterator iter = allTaglibs.iterator(); iter.hasNext();) {
+ ITaglibInfo iTaglib = (ITaglibInfo) iter.next();
+ if (iTaglib.isWebXMLEntry()) {
+ if (!uriSet.contains(iTaglib.getURI())) {
+ // show all web.xml entries whether they are mapped to the same resource
+ // if(showAllEntriesPerResource ||
+ // !locationSet.contains(iTaglib.getLocation())){
+ if (!locationSet.contains(iTaglib.getLocation()))
+ locationSet.add(iTaglib.getLocation());
+ results.add(iTaglib);
+ // }
+ uriSet.add(iTaglib.getURI());
+ }
+ }
+ }
+
+ // second pass uri in tld entries
+ for (Iterator iter = allTaglibs.iterator(); iter.hasNext();) {
+ ITaglibInfo iTaglib = (ITaglibInfo) iter.next();
+ if (iTaglib.isURIFromTLD() && !iTaglib.isWebXMLEntry()) {
+ if (!uriSet.contains(iTaglib.getURI())) {
+ if (!iTaglib.isInJar()) {
+ // i.e its a tld file in the web application
+ if (showAllEntriesPerResource || !locationSet.contains(iTaglib.getLocation())) {
+ if (!locationSet.contains(iTaglib.getLocation()))
+ locationSet.add(iTaglib.getLocation());
+ results.add(iTaglib);
+ }
+ } else { // i.e its a tld file in a JAR file in the web application
+ String jarRelativePath = iTaglib.getTLDLocation().toString();
+ if (jarRelativePath.equalsIgnoreCase(IWebNatureConstants.META_INFO_DIRECTORY + "/taglib.tld")) { //$NON-NLS-1$
+ if (!iTaglib.isServerContribution() // dont add META-INF/taglib.tld that
+ // comes from a server
+ && (showAllEntriesPerResource || !locationSet.contains(iTaglib.getLocation()))) {
+ if (!locationSet.contains(iTaglib.getLocation()))
+ locationSet.add(iTaglib.getLocation());
+ results.add(iTaglib);
+ }
+ } else { // if not metainf/taglib.tld
+ // we want to include all the non meta-inf entries in the results
+ results.add(iTaglib);
+ }
+ }
+ uriSet.add(iTaglib.getURI());
+ } // if !uriSet.contains
+ } // if .isURIFromTLD
+ }
+
+ // third pass for entries whose uri's are resource paths
+ for (Iterator iter = allTaglibs.iterator(); iter.hasNext();) {
+ ITaglibInfo iTaglib = (ITaglibInfo) iter.next();
+ if (!iTaglib.isURIFromTLD() && !iTaglib.isWebXMLEntry() && !iTaglib.isDirectoryEntry()) {
+ if (!uriSet.contains(iTaglib.getURI())) {
+ if (showAllEntriesPerResource || !locationSet.contains(iTaglib.getLocation())) {
+ results.add(iTaglib);
+ locationSet.add(iTaglib.getLocation());
+ }
+ }
+ }
+ }
+
+ // fourth pass for entries whose uri's are resource paths & directory entries
+ for (Iterator iter = allTaglibs.iterator(); iter.hasNext();) {
+ ITaglibInfo iTaglib = (ITaglibInfo) iter.next();
+ if (iTaglib.isDirectoryEntry()) {
+ IPath directoryLoc = iTaglib.getLocation();
+ if (!uriSet.contains(iTaglib.getURI())) {
+ boolean canAdd = true;
+ for (Iterator iterator = locationSet.iterator(); iterator.hasNext();) {
+ IPath locationPath = (IPath) iterator.next();
+
+ if (directoryLoc.matchingFirstSegments(locationPath) == locationPath.segmentCount() - 1) {
+ canAdd = false;
+ break;
+ }
+ }
+ if (canAdd) {// don't add directories that have tld's in them
+ results.add(iTaglib);
+ locationSet.add(iTaglib.getLocation());
+ }
+ }
+ }
+ }
+
+
+ return (ITaglibInfo[]) results.toArray(new ITaglibInfo[results.size()]);
+ }
+
+ protected Vector primGetTaglibs() {
+ if (this.needsRefresh)
+ refresh();
+ return this.taglibs;
+ }
+
+ /*
+ * @see ITaglibRegistry#getTaglibs()
+ */
+ public ITaglibInfo[] getTaglibs() {
+ Vector tTaglibs = primGetTaglibs();
+ return (ITaglibInfo[]) tTaglibs.toArray(new ITaglibInfo[tTaglibs.size()]);
+ }
+
+ /*
+ * @see ITaglibRegistry#getTaglib(String)
+ */
+ public ITaglibInfo getTaglib(String uri) {
+ List tTaglibs = Arrays.asList(getVisibleTaglibs());
+ //commented out because we dont want to return the taglib for resources that are not
+ // visible
+ // or are not visible because of precedence //primGetTaglibs();
+ for (Iterator iter = tTaglibs.iterator(); iter.hasNext();) {
+ ITaglibInfo taglib = (ITaglibInfo) iter.next();
+ if (taglib.getURI().equals(uri))
+ return taglib;
+ }
+ return null;
+ }
+
+ protected void fireTaglibAdded(ITaglibInfo addedTaglib) {
+ if (debug)
+ System.out.println("TaglibRegistry: taglib added: " + addedTaglib); //$NON-NLS-1$
+
+ if (this.listeners == null)
+ return;
+ for (Iterator iter = this.listeners.iterator(); iter.hasNext();) {
+ ITaglibRegistryListener listener = (ITaglibRegistryListener) iter.next();
+ listener.taglibAdded(addedTaglib);
+ }
+ }
+
+ protected void fireTaglibChanged(ITaglibInfo changedTaglib) {
+ if (debug)
+ System.out.println("TaglibRegistry: taglib changed: " + changedTaglib); //$NON-NLS-1$
+
+ if (this.listeners == null)
+ return;
+ for (Iterator iter = this.listeners.iterator(); iter.hasNext();) {
+ ITaglibRegistryListener listener = (ITaglibRegistryListener) iter.next();
+ listener.taglibChanged(changedTaglib);
+ }
+ }
+
+ protected void fireTaglibRemoved(ITaglibInfo removedTaglib) {
+ if (debug)
+ System.out.println("TaglibRegistry: taglib removed: " + removedTaglib); //$NON-NLS-1$
+
+ if (this.listeners == null)
+ return;
+ for (Iterator iter = this.listeners.iterator(); iter.hasNext();) {
+ ITaglibRegistryListener listener = (ITaglibRegistryListener) iter.next();
+ listener.taglibRemoved(removedTaglib);
+ }
+ }
+
+ abstract protected boolean isWebXMLFile(IPath filePath);
+
+ protected boolean isTaglibTLD(IPath tldPath) {
+ return tldPath.lastSegment().equalsIgnoreCase("taglib.tld"); //$NON-NLS-1$
+ }
+
+ public void processResourceChanged(IResourceDelta delta) {
+ int kind = delta.getKind();
+ IResource resource = delta.getResource();
+ int flags = delta.getFlags();
+ if (delta.getKind() == IResourceDelta.CHANGED && flags == IResourceDelta.NO_CHANGE)
+ return;
+
+ // If the websettings file changed, refresh everything in case the context root
+ // was modified or the J2EE level was changed.
+ if (requiresFullUpdate(delta)) {
+ updateAll();
+ return;
+ }
+ // Make sure resource is not null
+ if (resource == null)
+ return;
+
+ // Only process resource changes that are under the refreshRoot.
+ IPath resourcePath = resource.getProjectRelativePath();
+
+ IResource refreshRoot = getRefreshRoot();
+ // RATLC00974251 for a java project before build is done, output location does not exist
+ if (refreshRoot == null)
+ return;
+
+ IPath refreshPath = refreshRoot.getProjectRelativePath();
+ if (resourcePath.matchingFirstSegments(refreshPath) != refreshPath.segmentCount())
+ return;
+
+ if (debug)
+ System.out.println("TaglibRegistry(" + this.project.getName() + ").resourceChanged: " + delta); //$NON-NLS-1$ //$NON-NLS-2$
+
+ if (kind == IResourceDelta.CHANGED || kind == IResourceDelta.REPLACED) {
+ handleResourceModified(resource);
+ } else if (kind == IResourceDelta.REMOVED) {
+ handleResourceRemoved(resource);
+ } else if (kind == IResourceDelta.ADDED) {
+ handleResourceAdded(resource);
+ } else {
+ if (debug)
+ System.out.println("TaglibRegistry.resourceChanged: UNHANDLED DELTA TYPE"); //$NON-NLS-1$
+ }
+ }
+
+ protected void handleResourceAdded(IResource resource) {
+ handleResourceModified(resource);
+ }
+
+ protected void handleResourceModified(IResource resource) {
+ try {
+ resource.accept(new IResourceVisitor() {
+ public boolean visit(IResource aresource) throws CoreException {
+ if (aresource.getType() != IResource.ROOT && AbstractTaglibRegistry.this.project != aresource.getProject())
+ return false;
+
+ if (aresource.getType() == IResource.FILE) {
+ processFile(aresource);
+ return false;
+ }
+ if (shouldProcessDirectory(aresource)) {
+ processDirectory(aresource);
+ }
+ return (canVisitResource(aresource));
+
+ }
+
+
+ });
+ } catch (CoreException e) {
+ Logger.getLogger().log(e);
+ }
+ }
+
+ /**
+ * Return true if the resource and its children should be visited
+ *
+ * @param resource
+ * @return
+ */
+ protected boolean canVisitResource(IResource resource) {
+ if (resource.getType() != IResource.ROOT && this.project != resource.getProject())
+ return false;
+ if (resource.getType() != IResource.FILE)
+ return true;
+ return true;
+ }
+
+ protected void handleResourceRemoved(IResource resource) {
+ IPath location = resource.getProjectRelativePath();
+ ITaglibInfo[] removedTaglibs = removeTaglibs(location);
+ if (removedTaglibs != null) {
+ for (int i = 0; i < removedTaglibs.length; i++) {
+ ITaglibInfo iTaglibInfo = removedTaglibs[i];
+ if (debug)
+ System.out.println("TaglibRegistry.handleResourceRemoved taglib removed: " + iTaglibInfo); //$NON-NLS-1$
+ fireTaglibRemoved(iTaglibInfo);
+ }
+ }
+ }
+
+ protected IResource getRefreshRoot() {
+ return getProject();
+ }
+
+ public void refresh() {
+ this.taglibs = new Vector();
+ IResource refreshRoot = getRefreshRoot();
+
+ // RATLC00974251 for a java project before build is done, output location does not exist
+ if (refreshRoot != null)
+ handleResourceAdded(refreshRoot);
+
+ this.needsRefresh = false;
+ }
+
+ protected void updateAll() {
+ try {
+ IResource refreshRoot = getRefreshRoot();
+
+ // RATLC00974251 for a java project before build is done, output location does not exist
+ if (refreshRoot == null)
+ return;
+ refreshRoot.accept(new IResourceVisitor() {
+ public boolean visit(IResource resource) throws CoreException {
+ handleResourceModified(resource);
+ return true;
+ }
+ });
+ } catch (CoreException e) {
+ }
+ }
+
+ /**
+ * Remove all the taglibs associated with the location.
+ *
+ * @param location
+ * @return ITaglibInfo[] The taglibs that are removed. Null if none are removed.
+ */
+ protected ITaglibInfo[] removeTaglibs(IPath location) {
+ List results = new ArrayList();
+
+ boolean isWebXML = isWebXMLFile(location);
+ for (int i = 0; i < this.taglibs.size(); i++) {
+ ITaglibInfo taglib = (ITaglibInfo) this.taglibs.get(i);
+ if (isWebXML) {
+ if (taglib.isWebXMLEntry()) {
+ removeTaglib(i);
+ results.add(taglib);
+ i--;
+ }
+ } else if (taglib.getLocation().equals(location)) {
+ removeTaglib(i);
+ results.add(taglib);
+ i--;
+ }
+ }
+ return results.isEmpty() ? null : (ITaglibInfo[]) results.toArray(new ITaglibInfo[results.size()]);
+ }
+
+ abstract protected boolean requiresFullUpdate(IResourceDelta delta);
+
+ protected void removeTaglib(int i) {
+ this.taglibs.remove(i);
+ }
+
+ protected ITaglibInfo[] searchForTaglibs(IResource resource) {
+ ArrayList results = new ArrayList();
+ for (int i = 0; i < this.locators.length; i++) {
+ ITaglibLocator tLocator = this.locators[i];
+ ITaglibInfo[] tTaglibs = tLocator.search(resource);
+ if (tTaglibs != null) {
+ for (int j = 0; j < tTaglibs.length; j++) {
+ results.add(tTaglibs[j]);
+ }
+ }
+ }
+ return (ITaglibInfo[]) results.toArray(new ITaglibInfo[results.size()]);
+ }
+
+ /*
+ * @see ITaglibRegistry#removeTaglibRegistryListener(ITaglibRegistryListener)
+ */
+ public void removeTaglibRegistryListener(ITaglibRegistryListener listener) {
+ if (this.listeners == null)
+ return;
+ this.listeners.remove(listener);
+ }
+
+ /*
+ * @see Object#toString()
+ */
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("TaglibRegistry: \n"); //$NON-NLS-1$
+ for (Iterator iter = this.taglibs.iterator(); iter.hasNext();) {
+ ITaglibInfo taglib = (ITaglibInfo) iter.next();
+ sb.append("\t"); //$NON-NLS-1$
+ sb.append(taglib);
+ sb.append("\n"); //$NON-NLS-1$
+ }
+ return sb.toString();
+ }
+
+ protected void processDirectory(IResource resource) {
+ // do nothing
+ }
+
+ protected boolean shouldProcessDirectory(IResource resource) {
+ return true;
+ }
+
+ /**
+ * @param resource
+ */
+ protected void processFile(IResource resource) {
+ Vector existingTaglibs = getExistingTaglibs(resource.getProjectRelativePath());
+ ITaglibInfo[] newTaglibs = searchForTaglibs(resource);
+
+ for (int i = 0; i < newTaglibs.length; i++) {
+ ITaglibInfo newTaglib = newTaglibs[i];
+ int existingIndex = existingTaglibs.indexOf(newTaglib);
+ if (existingIndex >= 0) {
+ // If its an exact match, leave it in alone the taglibs registry
+ // but fire a taglibChangedEvent.
+ if (!newTaglib.isWebXMLEntry())
+ fireTaglibChanged(newTaglib);
+ existingTaglibs.remove(existingIndex);
+ } else {
+ // The taglib did not exist previously in the list, add it and
+ // fire a taglibAdded event.
+ addTaglib(newTaglib);
+ fireTaglibAdded(newTaglib);
+ }
+ }
+
+ for (Iterator iter = existingTaglibs.iterator(); iter.hasNext();) {
+ ITaglibInfo remainingTaglib = (ITaglibInfo) iter.next();
+ this.taglibs.remove(remainingTaglib);
+ fireTaglibRemoved(remainingTaglib);
+ }
+ }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/registry/JavaTaglibRegistry.java b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/registry/JavaTaglibRegistry.java
new file mode 100644
index 000000000..0c248da91
--- /dev/null
+++ b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/registry/JavaTaglibRegistry.java
@@ -0,0 +1,70 @@
+/***************************************************************************************************
+ * Copyright (c) 2003, 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.jst.j2ee.internal.web.taglib.registry;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jst.j2ee.internal.web.locator.JavaProjectTaglibLocator;
+import org.eclipse.jst.j2ee.web.taglib.ITaglibLocator;
+
+
+public class JavaTaglibRegistry extends AbstractTaglibRegistry {
+
+ protected IPath classpathFilePath;
+
+ /**
+ * Constructor for JavaTaglibRegistry.
+ *
+ * @param project
+ */
+ public JavaTaglibRegistry(IProject project) {
+ super(project);
+ }
+
+ protected void initialize() {
+ this.locators = new ITaglibLocator[]{new JavaProjectTaglibLocator(this.project)};
+ }
+
+ protected boolean isWebXMLFile(IPath filePath) {
+ return false;
+ }
+
+ protected IPath getClasspathFilePath() {
+ if (this.classpathFilePath == null)
+ this.classpathFilePath = getProject().getFullPath().append(".classpath"); //$NON-NLS-1$
+ return this.classpathFilePath;
+ }
+
+ protected IJavaProject getJavaProject() {
+ return JavaCore.create(getProject());
+ }
+
+ protected IResource getRefreshRoot() {
+ try {
+ return getProject().getWorkspace().getRoot().findMember(getJavaProject().getOutputLocation());
+ } catch (JavaModelException e) {
+ }
+ return getProject();
+ }
+
+ /**
+ * @see AbstractTaglibRegistry#requiresFullUpdate(IResourceDelta)
+ */
+ protected boolean requiresFullUpdate(IResourceDelta delta) {
+ // If the websettings are updated, a full refresh is required.
+ return delta.getResource().getFullPath().equals(getClasspathFilePath());
+ }
+
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/registry/WebTaglibRegistry.java b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/registry/WebTaglibRegistry.java
new file mode 100644
index 000000000..33d81b68e
--- /dev/null
+++ b/plugins/org.eclipse.jst.j2ee.web/taglib/org/eclipse/jst/j2ee/internal/web/taglib/registry/WebTaglibRegistry.java
@@ -0,0 +1,178 @@
+/***************************************************************************************************
+ * Copyright (c) 2003, 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.jst.j2ee.internal.web.taglib.registry;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.Vector;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jst.j2ee.internal.project.IWebNatureConstants;
+import org.eclipse.jst.j2ee.internal.web.locator.WebLibModuleTaglibLocator;
+import org.eclipse.jst.j2ee.internal.web.locator.WebProjectServerTargetTaglibLocator;
+import org.eclipse.jst.j2ee.internal.web.locator.WebProjectTaglibLocator;
+import org.eclipse.jst.j2ee.internal.web.locator.WebXMLTaglibLocator;
+import org.eclipse.jst.j2ee.internal.web.operations.J2EEWebNatureRuntime;
+import org.eclipse.jst.j2ee.internal.web.operations.J2EEWebNatureRuntimeUtilities;
+import org.eclipse.jst.j2ee.web.taglib.ITaglibInfo;
+import org.eclipse.jst.j2ee.web.taglib.ITaglibLocator;
+
+
+public class WebTaglibRegistry extends AbstractTaglibRegistry {
+
+ private ITaglibLocator libModuleLocator;
+ private ITaglibLocator serverTargetLocator;
+ private ITaglibLocator webProjectTaglibLocator;
+
+ /**
+ * Constructor for WebTaglibRegistry.
+ *
+ * @param project
+ */
+ public WebTaglibRegistry(IProject project) {
+ super(project);
+ }
+
+ protected void initialize() {
+ // the reason these two locators are not part of the list is they are per file locator but
+ // per project
+ this.libModuleLocator = new WebLibModuleTaglibLocator(this.project);
+ this.serverTargetLocator = new WebProjectServerTargetTaglibLocator(this.project);
+ this.webProjectTaglibLocator = new WebProjectTaglibLocator(this.project);
+ this.locators = new ITaglibLocator[]{this.webProjectTaglibLocator, new WebXMLTaglibLocator(this.project)};
+ }
+
+ protected J2EEWebNatureRuntime getWebNature() {
+ return (J2EEWebNatureRuntime) J2EEWebNatureRuntimeUtilities.getRuntime(this.project);
+ }
+
+ protected boolean isWebXMLFile(IPath filePath) {
+ return getWebNature().getWebXMLPath().removeFirstSegments(1).equals(filePath);
+ }
+
+ protected boolean requiresFullUpdate(IResourceDelta delta) {
+ // If the websettings are updated, a full refresh is required.
+ boolean ret = false;
+ if (delta != null) { // added for RATLC00963945 - JB
+ J2EEWebNatureRuntime webNature = getWebNature();
+ if (webNature != null) // added for RATLC00963945 - RAJ
+ ret = delta.getResource().getFullPath().equals(webNature.getWebSettingsPath());
+ }
+ return ret;
+ }
+
+ /*
+ * (non-Javadoc) we need to return the Resource/folder from where taglib search begins and for a
+ * web project we can make it faster by searching from WEB-INF folder
+ *
+ * @see org.eclipse.jst.j2ee.internal.internal.internal.web.taglib.registry.AbstractTaglibRegistry#getRefreshRoot()
+ */
+ protected IResource getRefreshRoot() {
+ IResource ret = null;
+ J2EEWebNatureRuntime webNature = getWebNature();
+ if (webNature != null) // added for RATLC00963945 - RAJ
+ ret = webNature.getModuleServerRoot().findMember(IWebNatureConstants.INFO_DIRECTORY);
+
+ return ret;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.j2ee.internal.internal.internal.web.taglib.registry.AbstractTaglibRegistry#shouldProcessDirectory()
+ */
+ protected boolean shouldProcessDirectory(IResource resource) {
+ IContainer tagsFolder = getTagsFolder();
+ if (tagsFolder != null && tagsFolder.getProjectRelativePath().equals(resource.getProjectRelativePath())) {
+ return true;
+ }
+ return false;
+
+ }
+
+ private IContainer getTagsFolder() {
+ IContainer webinf = (IContainer) getRefreshRoot();
+ if (webinf != null) {
+ IResource tagsFolder = webinf.findMember("tags"); //$NON-NLS-1$
+ if (tagsFolder != null && tagsFolder instanceof IContainer)
+ return (IContainer) tagsFolder;
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc) return true only if the resource is a parent of WEB-INF or is within WEB-INF
+ *
+ * @see org.eclipse.jst.j2ee.internal.internal.internal.web.taglib.registry.AbstractTaglibRegistry#canVisitResource(org.eclipse.core.resources.IResource)
+ */
+ protected boolean canVisitResource(IResource resource) {
+ if (resource != null && resource.getType() != IResource.ROOT && this.project != resource.getProject())
+ return false;
+
+ IResource webinf = getRefreshRoot();
+ // resource within WEB-INF
+ if (webinf != null && resource != null && webinf.getProjectRelativePath().isPrefixOf(resource.getProjectRelativePath()))
+ return true;
+ // resource parent of WEB-INF
+ else if (webinf != null && resource != null && resource.getProjectRelativePath().isPrefixOf(webinf.getProjectRelativePath()))
+ return true;
+ // some other branch
+ else
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jst.j2ee.internal.internal.internal.web.taglib.registry.AbstractTaglibRegistry#processDirectory(org.eclipse.core.resources.IResource)
+ */
+ protected void processDirectory(IResource resource) {
+ Vector existingTaglibs = getExistingTaglibs(resource.getProjectRelativePath());
+ ITaglibInfo[] newTaglibs = this.webProjectTaglibLocator.search(resource);
+
+ for (int i = 0; i < newTaglibs.length; i++) {
+ ITaglibInfo newTaglib = newTaglibs[i];
+ int existingIndex = existingTaglibs.indexOf(newTaglib);
+ if (existingIndex >= 0) {
+ // If its an exact match, leave it in alone the taglibs registry
+ // but fire a taglibChangedEvent.
+ if (!newTaglib.isWebXMLEntry())
+ fireTaglibChanged(newTaglib);
+ existingTaglibs.remove(existingIndex);
+ } else {
+ // The taglib did not exist previously in the list, add it and
+ // fire a taglibAdded event.
+ addTaglib(newTaglib);
+ fireTaglibAdded(newTaglib);
+ }
+ }
+
+ for (Iterator iter = existingTaglibs.iterator(); iter.hasNext();) {
+ ITaglibInfo remainingTaglib = (ITaglibInfo) iter.next();
+ this.taglibs.remove(remainingTaglib);
+ fireTaglibRemoved(remainingTaglib);
+ }
+
+ }
+
+ protected Vector primGetTaglibs() {
+ // Check to see if there are any lib modules, if so, we must check to see
+ // if there are any taglibs in these and concat the results.
+ Vector results = new Vector();
+ results.addAll(super.primGetTaglibs());
+
+ results.addAll(Arrays.asList(this.libModuleLocator.search(this.project)));
+ results.addAll(Arrays.asList(this.serverTargetLocator.search(this.project)));
+ return results;
+ }
+} \ No newline at end of file

Back to the top