diff options
Diffstat (limited to 'bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/taglib')
7 files changed, 0 insertions, 1860 deletions
diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/taglib/BuildPathClassLoader.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/taglib/BuildPathClassLoader.java deleted file mode 100644 index 7b5443f1d0..0000000000 --- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/taglib/BuildPathClassLoader.java +++ /dev/null @@ -1,234 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.core.internal.taglib; - -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.ZipFile; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jst.jsp.core.internal.Logger; -import org.eclipse.wst.sse.core.utils.StringUtils; - -/** - * Custom ClassLoader backed by a Java Project. - */ -public class BuildPathClassLoader extends ClassLoader { - private static final boolean DEBUG = Boolean.valueOf(Platform.getDebugOption("org.eclipse.jst.jsp.core/debug/taglibclassloader")).booleanValue(); //$NON-NLS-1$ - private IJavaProject fProject; - - public BuildPathClassLoader(ClassLoader parent, IJavaProject project) { - super(parent); - fProject = project; - } - - /** - * Closes the given file with "extreme prejudice". - * - * @param file the zip file to be closed - */ - public void closeJarFile(ZipFile file) { - if (file == null) - return; - try { - file.close(); - } - catch (IOException ioe) { - // no cleanup can be done - Logger.logException("JarUtilities: Could not close file " + file.getName(), ioe); //$NON-NLS-1$ - } - } - - /* - * This may pose a runtime performance problem as it opens the containing - * .jar file for each class, but this is countered by no longer leaving - * file handles open nor having to directly interact the build path at - * all. If it is a problem, the TaglibHelper should control some - * "batching" whereby we leave the JarFiles open until directed to close - * them at the end of TaglibHelper.addTEIVariables(...). - * - * @see java.lang.ClassLoader#findClass(java.lang.String) - */ - protected Class findClass(String className) throws ClassNotFoundException { - if (DEBUG) - System.out.println("finding: [" + className + "]"); //$NON-NLS-1$ //$NON-NLS-2$ - try { - IType type = fProject.findType(className); - int offset = -1; - if (type == null && (offset = className.indexOf('$')) != -1) { - // Internal classes from source files must be referenced by . instead of $ - String cls = className.substring(0, offset) + className.substring(offset).replace('$', '.'); - type = fProject.findType(cls); - } - if (type != null) { - IPath path = null; - IResource resource = type.getResource(); - - if (resource != null) - path = resource.getLocation(); - if (path == null) - path = type.getPath(); - - // needs to be compiled before we can load it - if ("class".equalsIgnoreCase(path.getFileExtension())) { - IFile file = null; - - if (resource != null && resource.getType() == IResource.FILE) - file = (IFile) resource; - else - file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); - - if (file != null && file.isAccessible()) { - byte[] bytes = loadBytes(file); - return defineClass(className, bytes, 0, bytes.length); - } - } - // Look up the class file based on the output location of the java project - else if ("java".equalsIgnoreCase(path.getFileExtension()) && resource != null) { //$NON-NLS-1$ - if (resource.getProject() != null) { - IJavaProject jProject = JavaCore.create(resource.getProject()); - String outputClass = StringUtils.replace(type.getFullyQualifiedName(), ".", "/").concat(".class"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - IPath classPath = jProject.getOutputLocation().append(outputClass); - IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(classPath); - if (file != null && file.isAccessible()) { - byte[] bytes = loadBytes(file); - return defineClass(className, bytes, 0, bytes.length); - } - } - } - else if ("jar".equalsIgnoreCase(path.getFileExtension())) { - String expectedFileName = StringUtils.replace(className, ".", "/").concat(".class"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - byte[] bytes = getCachedInputStream(path.toOSString(), expectedFileName); - return defineClass(className, bytes, 0, bytes.length); - } - } - } - catch (JavaModelException e) { - Logger.logException(e); - } - return super.findClass(className); - } - - /** - * Get the entry from the jarfile - * @param jarFilename the string path of the jarfile - * @param entryName the fully-qualified entry - * @return the bytes for the entry within the jarfile or a byte array of size 0 - */ - private byte[] getCachedInputStream(String jarFilename, String entryName) { - ByteArrayOutputStream buffer = null; - - File testFile = new File(jarFilename); - if (!testFile.exists()) - return null; - - ZipFile jarfile = null; - try { - jarfile = new ZipFile(jarFilename); - - if (jarfile != null) { - ZipEntry zentry = jarfile.getEntry(entryName); - if (zentry != null) { - InputStream entryInputStream = null; - try { - entryInputStream = jarfile.getInputStream(zentry); - } - catch (IOException ioExc) { - Logger.logException("JarUtilities: " + jarFilename, ioExc); //$NON-NLS-1$ - } - - if (entryInputStream != null) { - int c; - if (zentry.getSize() > 0) { - buffer = new ByteArrayOutputStream((int) zentry.getSize()); - } - else { - buffer = new ByteArrayOutputStream(); - } - // array dim restriction? - byte bytes[] = new byte[2048]; - try { - while ((c = entryInputStream.read(bytes)) >= 0) { - buffer.write(bytes, 0, c); - } - } - catch (IOException ioe) { - // no cleanup can be done - } - finally { - try { - entryInputStream.close(); - } - catch (IOException e) { - } - } - } - } - } - } - catch (IOException ioExc) { - Logger.logException("JarUtilities: " + jarFilename, ioExc); //$NON-NLS-1$ - } - finally { - closeJarFile(jarfile); - } - - if (buffer != null) { - return buffer.toByteArray(); - } - return new byte[0]; - } - - /** - * @param file - * @return - */ - private byte[] loadBytes(IFile file) { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - InputStream in = null; - try { - in = file.getContents(); - byte[] buffer = new byte[4096]; - int read = 0; - while ((read = in.read(buffer)) != -1) { - out.write(buffer, 0, read); - } - } - catch (CoreException e) { - Logger.logException(e); - } - catch (IOException e) { - Logger.logException(e); - } - finally { - try { - if (in != null) - in.close(); - } - catch (IOException e) { - } - } - return out.toByteArray(); - } - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/taglib/CustomTag.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/taglib/CustomTag.java deleted file mode 100644 index 01867134e1..0000000000 --- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/taglib/CustomTag.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.core.internal.taglib; - -/** - * Contains information about a custom tag including the tag name (with prefix), - * the class that defines the functionality of the tag, TEI class, any scripting variables associated with the - * TEI class, and if the class is an iteration tag - * - */ -public class CustomTag { - - private final String fTagName; - private final String fClassName; - private final String fTeiClassName; - private final boolean fIsIterationTag; - private final TaglibVariable[] fVariables; - - public CustomTag(String tagName, String className, String teiClassName, TaglibVariable[] tagVariables, boolean isIterationTag) { - fTagName = tagName; - fClassName = className; - fTeiClassName = teiClassName; - fVariables = tagVariables; - fIsIterationTag = isIterationTag; - } - - /** - * Returns the name of the tag with its prefix - * @return the tag name including prefix - */ - public String getTagName() { - return fTagName; - } - - /** - * Returns the name of the implementation class for the tag - * @return the name of the implementation class for the tag - */ - public String getTagClassName() { - return fClassName; - } - - /** - * Returns the name of the TagExtraInfo class for the tag - * @return the name of the TagExtraInfo class for the tag - */ - public String getTeiClassName() { - return fTeiClassName; - } - - /** - * Returns an array of scripting variables associated with the TagExtraInfo class - * @return an array of scripting variables associated with the TagExtraInfo class - */ - public TaglibVariable[] getTagVariables() { - return fVariables; - } - - /** - * Identifies if the tag implements the IterationTag interface - * @return true if the tag implements the IterationTag interface; false otherwise - */ - public boolean isIterationTag() { - return fIsIterationTag; - } -} diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/taglib/TaglibClassLoader.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/taglib/TaglibClassLoader.java deleted file mode 100644 index 0dc3948e8d..0000000000 --- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/taglib/TaglibClassLoader.java +++ /dev/null @@ -1,91 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 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.jsp.core.internal.taglib; - - -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; - -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jst.jsp.core.internal.Logger; - -/** - * Custom classloader which allows you to add source directories (folders - * containing .class files) and jars to the classpath. - */ -public class TaglibClassLoader extends URLClassLoader { - // for debugging - private static final boolean DEBUG = Boolean.valueOf(Platform.getDebugOption("org.eclipse.jst.jsp.core/debug/taglibclassloader")).booleanValue(); //$NON-NLS-1$ - - private static final String FILE = "file:/"; - private static final String RESOURCE = "platform:/resource/"; - - public TaglibClassLoader(ClassLoader parentLoader) { - super(new URL[0], parentLoader); - } - - public void addDirectory(String dirPath) { - addJavaFile(dirPath + "/"); //$NON-NLS-1$ - } - - public void addFile(IPath filePath) { - try { - URL url = new URL(RESOURCE + filePath.toString()); //$NON-NLS-1$ - super.addURL(url); - if (DEBUG) - System.out.println("added: [" + url + "] to classpath"); //$NON-NLS-1$ //$NON-NLS-2$ - } - catch (MalformedURLException e) { - Logger.logException(filePath.toString(), e); - } - } - - public void addFolder(IPath folderPath) { - try { - URL url = new URL(RESOURCE + folderPath.toString() + "/"); //$NON-NLS-1$ - super.addURL(url); - if (DEBUG) - System.out.println("added: [" + url + "] to classpath"); //$NON-NLS-1$ //$NON-NLS-2$ - } - catch (MalformedURLException e) { - Logger.logException(folderPath.toString(), e); - } - } - - public void addJar(String filename) { - addJavaFile(filename); - } - - void addJavaFile(String filename) { - try { - URL url = new URL(FILE + filename); - super.addURL(url); - if (DEBUG) - System.out.println("added: [" + url + "] to classpath"); //$NON-NLS-1$ //$NON-NLS-2$ - } - catch (MalformedURLException e) { - Logger.logException(filename, e); - } - } - - /* - * (non-Javadoc) - * - * @see java.net.URLClassLoader#findClass(java.lang.String) - */ - protected Class findClass(String className) throws ClassNotFoundException { - if (DEBUG) - System.out.println("finding: [" + className + "]"); //$NON-NLS-1$ //$NON-NLS-2$ - return super.findClass(className); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/taglib/TaglibHelper.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/taglib/TaglibHelper.java deleted file mode 100644 index b1cda51803..0000000000 --- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/taglib/TaglibHelper.java +++ /dev/null @@ -1,1007 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2010 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.jsp.core.internal.taglib; - - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import javax.servlet.jsp.tagext.FunctionInfo; -import javax.servlet.jsp.tagext.TagAttributeInfo; -import javax.servlet.jsp.tagext.TagData; -import javax.servlet.jsp.tagext.TagExtraInfo; -import javax.servlet.jsp.tagext.TagFileInfo; -import javax.servlet.jsp.tagext.TagInfo; -import javax.servlet.jsp.tagext.TagLibraryInfo; -import javax.servlet.jsp.tagext.ValidationMessage; -import javax.servlet.jsp.tagext.VariableInfo; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.core.Signature; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jst.jsp.core.internal.JSPCoreMessages; -import org.eclipse.jst.jsp.core.internal.Logger; -import org.eclipse.jst.jsp.core.internal.contentmodel.TaglibController; -import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager; -import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker; -import org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDAttributeDeclaration; -import org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDDocument; -import org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDElementDeclaration; -import org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDVariable; -import org.eclipse.jst.jsp.core.internal.java.IJSPProblem; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.NotImplementedException; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList; -import org.eclipse.wst.sse.core.internal.util.AbstractMemoryListener; -import org.eclipse.wst.sse.core.utils.StringUtils; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMNodeWrapper; -import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; -import org.osgi.service.event.Event; - -import com.ibm.icu.text.MessageFormat; - -/** - * This class helps find TaglibVariables in a JSP file. - */ -public class TaglibHelper { - - private static final String ITERATION_QUALIFIER = "javax.servlet.jsp.tagext"; //$NON-NLS-1$ - private static final String ITERATION_NAME = "IterationTag"; //$NON-NLS-1$ - - // for debugging - private static final boolean DEBUG; - static { - String value = Platform.getDebugOption("org.eclipse.jst.jsp.core/debug/taglibvars"); //$NON-NLS-1$ - DEBUG = value != null && value.equalsIgnoreCase("true"); //$NON-NLS-1$ - } - - private IProject fProject = null; - private ClassLoader fLoader = null; - - private IJavaProject fJavaProject; - - /** - * A cache of class names that the class loader could not find. - * Because the TaglibHelper is destroyed and recreated whenever - * the classpath changes this cache will not become stale - */ - private Set fNotFoundClasses = null; - - private Map fClassMap = null; - - /** - * Used to keep the {@link #fNotFoundClasses} cache clean when memory is low - */ - private MemoryListener fMemoryListener; - - public TaglibHelper(IProject project) { - super(); - setProject(project); - fMemoryListener = new MemoryListener(); - fMemoryListener.connect(); - fNotFoundClasses = new HashSet(); - fClassMap = Collections.synchronizedMap(new HashMap()); - } - - /** - * Checks that <code>type</code> implements an IterationTag - * - * @param type - * @return true if <code>type</code> implements IterationTag - * @throws JavaModelException - * @throws ClassNotFoundException thrown when the <code>type</code> is null - */ - private boolean isIterationTag(IType type) throws JavaModelException, ClassNotFoundException { - if (type == null) { - throw new ClassNotFoundException(); - } - synchronized (fClassMap) { - if (fClassMap.containsKey(type.getFullyQualifiedName())) - return ((Boolean) fClassMap.get(type.getFullyQualifiedName())).booleanValue(); - } - - String signature; - String qualifier; - String name; - String[] interfaces = type.getSuperInterfaceTypeSignatures(); - boolean isIteration = false; - // Check any super interfaces for the iteration tag - for (int i = 0; i < interfaces.length; i++) { - // For source files, the interface may need to be resolved - String erasureSig = Signature.getTypeErasure(interfaces[i]); - qualifier = Signature.getSignatureQualifier(erasureSig); - name = Signature.getSignatureSimpleName(erasureSig); - // Interface type is unresolved - if (erasureSig.charAt(0) == Signature.C_UNRESOLVED) { - String[][] types = type.resolveType(getQualifiedType(qualifier, name)); - // Type was resolved - if (types != null && types.length > 0) { - isIteration = handleInterface(type, types[0][0], types[0][1]); - } - } - else { - isIteration = handleInterface(type, qualifier, name); - } - if (isIteration) - return true; - } - - signature = type.getSuperclassTypeSignature(); - if (signature != null) { - String erasureSig = Signature.getTypeErasure(signature); - qualifier = Signature.getSignatureQualifier(erasureSig); - name = Signature.getSignatureSimpleName(erasureSig); - // superclass was unresolved - if (erasureSig.charAt(0) == Signature.C_UNRESOLVED) { - String[][] types = type.resolveType(getQualifiedType(qualifier, name)); - // Type was resolved - if (types != null && types.length > 0) { - isIteration = isIterationTag(fJavaProject.findType(types[0][0], types[0][1])); - } - } - else { - isIteration = isIterationTag(fJavaProject.findType(qualifier, name)); - } - } - fClassMap.put(type.getFullyQualifiedName(), Boolean.valueOf(isIteration)); - return isIteration; - } - - private boolean handleInterface(IType type, String qualifier, String name) throws JavaModelException, ClassNotFoundException { - boolean isIteration = false; - // Qualified interface is an iteration tag - if (ITERATION_QUALIFIER.equals(qualifier) && ITERATION_NAME.equals(name)) - isIteration = true; - // Check ancestors of this interface - else - isIteration = isIterationTag(fJavaProject.findType(qualifier, name)); - - fClassMap.put(type.getFullyQualifiedName(), Boolean.valueOf(isIteration)); - return isIteration; - } - - private String getQualifiedType(String qualifier, String name) { - StringBuffer qual = new StringBuffer(qualifier); - if (qual.length() > 0) - qual.append('.'); - qual.append(name); - return qual.toString(); - } - - private boolean isIterationTag(TLDElementDeclaration elementDecl, IStructuredDocument document, ITextRegionCollection customTag, List problems) { - String className = elementDecl.getTagclass(); - if (className == null || className.length() == 0 || fProject == null || fNotFoundClasses.contains(className)) - return false; - - try { - synchronized (fClassMap) { - if (fClassMap.containsKey(className)) - return ((Boolean) fClassMap.get(className)).booleanValue(); - } - return isIterationTag(fJavaProject.findType(className)); - } catch (ClassNotFoundException e) { - //the class could not be found so add it to the cache - fNotFoundClasses.add(className); - - Object createdProblem = createJSPProblem(document, customTag, IJSPProblem.TagClassNotFound, JSPCoreMessages.TaglibHelper_3, className, true); - if (createdProblem != null) - problems.add(createdProblem); - if (DEBUG) - Logger.logException(className, e); - } catch (JavaModelException e) { - if (DEBUG) - Logger.logException(className, e); - } catch (Exception e) { - // this is 3rd party code, need to catch all errors - if (DEBUG) - Logger.logException(className, e); - } catch (Error e) { - // this is 3rd party code, need to catch all errors - if (DEBUG) - Logger.logException(className, e); - } - - return false; - } - - public CustomTag getCustomTag(String tagToAdd, IStructuredDocument structuredDoc, ITextRegionCollection customTag, List problems) { - List results = new ArrayList(); - boolean isIterationTag = false; - String tagClass = null; - String teiClass = null; - if (problems == null) - problems = new ArrayList(); - ModelQuery mq = getModelQuery(structuredDoc); - if (mq != null) { - TLDCMDocumentManager mgr = TaglibController.getTLDCMDocumentManager(structuredDoc); - - if (mgr != null) { - - List trackers = mgr.getCMDocumentTrackers(-1); - Iterator taglibs = trackers.iterator(); - - CMDocument doc = null; - CMNamedNodeMap elements = null; - while (taglibs.hasNext()) { - doc = (CMDocument) taglibs.next(); - CMNode node = null; - if ((elements = doc.getElements()) != null && (node = elements.getNamedItem(tagToAdd)) != null && node.getNodeType() == CMNode.ELEMENT_DECLARATION) { - - if (node instanceof CMNodeWrapper) { - node = ((CMNodeWrapper) node).getOriginNode(); - } - TLDElementDeclaration tldElementDecl = (TLDElementDeclaration) node; - - tagClass = tldElementDecl.getTagclass(); - teiClass = tldElementDecl.getTeiclass(); - isIterationTag = isIterationTag(tldElementDecl, structuredDoc, customTag, problems); - /* - * Although clearly not the right place to add validation - * design-wise, this is the first time we have the - * necessary information to validate the tag class. - */ - validateTagClass(structuredDoc, customTag, tldElementDecl, problems); - - // 1.2+ taglib style - addVariables(results, node, customTag); - - // for 1.1 need more info from taglib tracker - if (doc instanceof TaglibTracker) { - String uri = ((TaglibTracker) doc).getURI(); - String prefix = ((TaglibTracker) doc).getPrefix(); - // only for 1.1 taglibs - addTEIVariables(structuredDoc, customTag, results, tldElementDecl, prefix, uri, problems); - } - break; - } - } - } - } - - return new CustomTag(tagToAdd, tagClass, teiClass, (TaglibVariable[]) results.toArray(new TaglibVariable[results.size()]), isIterationTag); - } - /** - * @param tagToAdd - * is the name of the tag whose variables we want - * @param structuredDoc - * is the IStructuredDocument where the tag is found - * @param customTag - * is the IStructuredDocumentRegion opening tag for the custom - * tag - * @param problems problems that are generated while creating variables are added to this collection - */ - public TaglibVariable[] getTaglibVariables(String tagToAdd, IStructuredDocument structuredDoc, ITextRegionCollection customTag, List problems) { - - List results = new ArrayList(); - if (problems == null) - problems = new ArrayList(); - ModelQuery mq = getModelQuery(structuredDoc); - if (mq != null) { - TLDCMDocumentManager mgr = TaglibController.getTLDCMDocumentManager(structuredDoc); - - // TaglibSupport support = ((TaglibModelQuery) - // mq).getTaglibSupport(); - if (mgr == null) - return new TaglibVariable[0]; - - List trackers = mgr.getCMDocumentTrackers(-1); - Iterator taglibs = trackers.iterator(); - - // TaglibSupport support = ((TaglibModelQuery) - // mq).getTaglibSupport(); - // if (support == null) - // return new TaglibVariable[0]; - // - // Iterator taglibs = - // support.getCMDocuments(customTag.getStartOffset()).iterator(); - CMDocument doc = null; - CMNamedNodeMap elements = null; - while (taglibs.hasNext()) { - doc = (CMDocument) taglibs.next(); - CMNode node = null; - if ((elements = doc.getElements()) != null && (node = elements.getNamedItem(tagToAdd)) != null && node.getNodeType() == CMNode.ELEMENT_DECLARATION) { - - if (node instanceof CMNodeWrapper) { - node = ((CMNodeWrapper) node).getOriginNode(); - } - TLDElementDeclaration tldElementDecl = (TLDElementDeclaration) node; - - /* - * Although clearly not the right place to add validation - * design-wise, this is the first time we have the - * necessary information to validate the tag class. - */ - validateTagClass(structuredDoc, customTag, tldElementDecl, problems); - - // 1.2+ taglib style - addVariables(results, node, customTag); - - // for 1.1 need more info from taglib tracker - if (doc instanceof TaglibTracker) { - String uri = ((TaglibTracker) doc).getURI(); - String prefix = ((TaglibTracker) doc).getPrefix(); - // only for 1.1 taglibs - addTEIVariables(structuredDoc, customTag, results, tldElementDecl, prefix, uri, problems); - } - } - } - } - - return (TaglibVariable[]) results.toArray(new TaglibVariable[results.size()]); - } - - /** - * Adds 1.2 style TaglibVariables to the results list. - * - * @param results - * list where the <code>TaglibVariable</code> s are added - * @param node - */ - private void addVariables(List results, CMNode node, ITextRegionCollection customTag) { - List list = ((TLDElementDeclaration) node).getVariables(); - Iterator it = list.iterator(); - while (it.hasNext()) { - TLDVariable var = (TLDVariable) it.next(); - if (!var.getDeclare()) - continue; - - String varName = var.getNameGiven(); - if (varName == null) { - // 2.0 - varName = var.getAlias(); - } - if (varName == null) { - String attrName = var.getNameFromAttribute(); - /* - * Iterate through the document region to find the - * corresponding attribute name, and then use its value - */ - ITextRegionList regions = customTag.getRegions(); - boolean attrNameFound = false; - for (int i = 2; i < regions.size(); i++) { - ITextRegion region = regions.get(i); - if (DOMRegionContext.XML_TAG_ATTRIBUTE_NAME.equals(region.getType())) { - attrNameFound = attrName.equals(customTag.getText(region)); - } - if (attrNameFound && DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE.equals(region.getType())) { - varName = StringUtils.strip(customTag.getText(region)); - } - } - } - if (varName != null) { - String varClass = "java.lang.String"; // the default - // class...//$NON-NLS-1$ - if (var.getVariableClass() != null) { - varClass = var.getVariableClass(); - } - results.add(new TaglibVariable(varClass, varName, var.getScope(), var.getDescription())); - } - } - } - - /** - * Adds 1.1 style TaglibVariables (defined in a TagExtraInfo class) to the - * results list. Also reports problems with the tag and tei classes in - * fTranslatorProblems. - * - * @param customTag - * @param results - * list where the <code>TaglibVariable</code> s are added - * @param decl - * TLDElementDeclaration for the custom tag - * @param prefix - * custom tag prefix - * @param uri - * URI where the tld can be found - */ - private void addTEIVariables(IStructuredDocument document, ITextRegionCollection customTag, List results, TLDElementDeclaration decl, String prefix, String uri, List problems) { - String teiClassname = decl.getTeiclass(); - if (teiClassname == null || teiClassname.length() == 0 || fJavaProject == null || fNotFoundClasses.contains(teiClassname)) - return; - - ClassLoader loader = getClassloader(); - - Class teiClass = null; - try { - /* - * JDT could tell us about it, but loading and calling it would - * still take time - */ - teiClass = Class.forName(teiClassname, true, loader); - if (teiClass != null) { - Object teiObject = teiClass.newInstance(); - if (TagExtraInfo.class.isInstance(teiObject)) { - TagExtraInfo tei = (TagExtraInfo) teiObject; - Hashtable tagDataTable = extractTagData(customTag); - TagInfo info = getTagInfo(decl, tei, prefix, uri); - if (info != null) { - tei.setTagInfo(info); - - // add to results - TagData td = new TagData(tagDataTable); - - VariableInfo[] vInfos = tei.getVariableInfo(td); - if (vInfos != null) { - for (int i = 0; i < vInfos.length; i++) { - results.add(new TaglibVariable(vInfos[i].getClassName(), vInfos[i].getVarName(), vInfos[i].getScope(), decl.getDescription())); - } - } - - ValidationMessage[] messages = tei.validate(td); - if (messages != null && messages.length > 0) { - for (int i = 0; i < messages.length; i++) { - Object createdProblem = createValidationMessageProblem(document, customTag, messages[i].getMessage()); - if (createdProblem != null) { - problems.add(createdProblem); - } - } - } - } - } - else { - Object createdProblem = createJSPProblem(document, customTag, IJSPProblem.TEIClassMisc, JSPCoreMessages.TaglibHelper_2, teiClassname, true); - if (createdProblem != null) { - problems.add(createdProblem); - } - // this is 3rd party code, need to catch all exceptions - if (DEBUG) { - Logger.log(Logger.WARNING, teiClassname + " is not a subclass of TaxExtraInfo"); //$NON-NLS-1$ - } - } - } - } - catch (ClassNotFoundException e) { - //the class could not be found so add it to the cache - fNotFoundClasses.add(teiClassname); - - Object createdProblem = createJSPProblem(document, customTag, IJSPProblem.TEIClassNotFound, JSPCoreMessages.TaglibHelper_0, teiClassname, true); - if (createdProblem != null) { - problems.add(createdProblem); - } - // TEI class wasn't on build path - if (DEBUG) - logException(teiClassname, e); - } - catch (InstantiationException e) { - Object createdProblem = createJSPProblem(document, customTag, IJSPProblem.TEIClassNotInstantiated, JSPCoreMessages.TaglibHelper_1, teiClassname, true); - if (createdProblem != null) { - problems.add(createdProblem); - } - // TEI class couldn't be instantiated - if (DEBUG) - logException(teiClassname, e); - } - catch (IllegalAccessException e) { - if (DEBUG) - logException(teiClassname, e); - } - // catch (ClassCastException e) { - // // TEI class wasn't really a subclass of TagExtraInfo - // if (DEBUG) - // logException(teiClassname, e); - // } - catch (Exception e) { - Object createdProblem = createJSPProblem(document, customTag, IJSPProblem.TEIClassMisc, JSPCoreMessages.TaglibHelper_2, teiClassname, true); - if (createdProblem != null) { - problems.add(createdProblem); - } - // this is 3rd party code, need to catch all exceptions - if (DEBUG) - logException(teiClassname, e); - } - catch (Error e) { - // this is 3rd party code, need to catch all errors - Object createdProblem = createJSPProblem(document, customTag, IJSPProblem.TEIClassNotInstantiated, JSPCoreMessages.TaglibHelper_1, teiClassname, true); - if (createdProblem != null) { - problems.add(createdProblem); - } - if (DEBUG) - logException(teiClassname, e); - } - finally { - // Thread.currentThread().setContextClassLoader(oldLoader); - } - } - - /** - * @param customTag - * @param teiClass - * @return - */ - private Object createJSPProblem(final IStructuredDocument document, final ITextRegionCollection customTag, final int problemID, final String messageKey, final String argument, boolean preferVars) { - final String tagname = customTag.getText(customTag.getRegions().get(1)); - - final int start; - if (customTag.getNumberOfRegions() > 1) { - start = customTag.getStartOffset(customTag.getRegions().get(1)); - } - else { - start = customTag.getStartOffset(); - } - - final int end; - if (customTag.getNumberOfRegions() > 1) { - end = customTag.getTextEndOffset(customTag.getRegions().get(1)) - 1; - } - else { - end = customTag.getTextEndOffset() - 1; - } - - final int line = document.getLineOfOffset(start); - - final char[] name; - IPath location = TaglibController.getLocation(document); - if (location == null) { - name = new char[0]; - } - else { - name = location.toString().toCharArray(); - } - - /* - * Note: these problems would result in translation errors on the - * server, so the severity is not meant to be controllable - */ - return new IJSPProblem() { - public void setSourceStart(int sourceStart) { - } - - public void setSourceLineNumber(int lineNumber) { - } - - public void setSourceEnd(int sourceEnd) { - } - - public boolean isWarning() { - return false; - } - - public boolean isError() { - return true; - } - - public int getSourceStart() { - return start; - } - - public int getSourceLineNumber() { - return line; - } - - public int getSourceEnd() { - return end; - } - - public char[] getOriginatingFileName() { - return name; - } - - public String getMessage() { - return MessageFormat.format(messageKey, new String[]{tagname, argument}); - } - - public int getID() { - return problemID; - } - - public String[] getArguments() { - return new String[0]; - } - - public int getEID() { - return problemID; - } - }; - } - - /** - * @param customTag - * @param validationMessage - * @return - */ - private Object createValidationMessageProblem(final IStructuredDocument document, final ITextRegionCollection customTag, final String validationMessage) { - final int start; - if (customTag.getNumberOfRegions() > 3) { - start = customTag.getStartOffset(customTag.getRegions().get(2)); - } - else if (customTag.getNumberOfRegions() > 1) { - start = customTag.getStartOffset(customTag.getRegions().get(1)); - } - else { - start = customTag.getStartOffset(); - } - - final int end; - if (customTag.getNumberOfRegions() > 3) { - end = customTag.getTextEndOffset(customTag.getRegions().get(customTag.getNumberOfRegions() - 2)) - 1; - } - else if (customTag.getNumberOfRegions() > 1) { - end = customTag.getTextEndOffset(customTag.getRegions().get(1)) - 1; - } - else { - end = customTag.getTextEndOffset(); - } - - final int line = document.getLineOfOffset(start); - - final char[] name; - IPath location = TaglibController.getLocation(document); - if (location == null) { - name = new char[0]; - } - else { - name = location.toString().toCharArray(); - } - - return new IJSPProblem() { - public void setSourceStart(int sourceStart) { - } - - public void setSourceLineNumber(int lineNumber) { - } - - public void setSourceEnd(int sourceEnd) { - } - - public boolean isWarning() { - return true; - } - - public boolean isError() { - return false; - } - - public int getSourceStart() { - return start; - } - - public int getSourceLineNumber() { - return line; - } - - public int getSourceEnd() { - return end; - } - - public char[] getOriginatingFileName() { - return name; - } - - public String getMessage() { - return validationMessage; - } - - public int getID() { - return getEID(); - } - - public String[] getArguments() { - return new String[0]; - } - - public int getEID() { - return IJSPProblem.TEIValidationMessage; - } - }; - } - - /** - * @param decl - * @return the TagInfo for the TLDELementDeclaration if the declaration is - * valid, otherwise null - */ - private TagInfo getTagInfo(final TLDElementDeclaration decl, TagExtraInfo tei, String prefix, String uri) { - - TagLibraryInfo libInfo = new TagLibraryInfoImpl(prefix, uri, decl); - - CMNamedNodeMap attrs = decl.getAttributes(); - TagAttributeInfo[] attrInfos = new TagAttributeInfo[attrs.getLength()]; - TLDAttributeDeclaration attr = null; - String type = ""; //$NON-NLS-1$ - - // get tag attribute infos - for (int i = 0; i < attrs.getLength(); i++) { - attr = (TLDAttributeDeclaration) attrs.item(i); - type = attr.getType(); - // default value for type is String - if (attr.getType() == null || attr.getType().equals("")) //$NON-NLS-1$ - type = "java.lang.String"; //$NON-NLS-1$ - attrInfos[i] = new TagAttributeInfo(attr.getAttrName(), attr.isRequired(), type, false); - } - - String tagName = decl.getNodeName(); - String tagClass = decl.getTagclass(); - String bodyContent = decl.getBodycontent(); - if (tagName != null && tagClass != null && bodyContent != null) - return new TagInfo(tagName, tagClass, bodyContent, decl.getInfo(), libInfo, tei, attrInfos); - return null; - - } - - /** - * @param e - */ - private void logException(String teiClassname, Throwable e) { - - String message = "teiClassname: ["; //$NON-NLS-1$ - if (teiClassname != null) - message += teiClassname; - message += "]"; //$NON-NLS-1$ - Logger.logException(message, e); - } - - /** - * Returns all attribute -> value pairs for the tag in a Hashtable. - * - * @param customTag - * @return - */ - private Hashtable extractTagData(ITextRegionCollection customTag) { - Hashtable tagDataTable = new Hashtable(); - ITextRegionList regions = customTag.getRegions(); - ITextRegion r = null; - String attrName = ""; //$NON-NLS-1$ - String attrValue = ""; //$NON-NLS-1$ - for (int i = 2; i < regions.size(); i++) { - r = regions.get(i); - // check if attr name - if (r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) { - attrName = customTag.getText(r); - // check equals is next region - if (regions.size() > ++i) { - r = regions.get(i); - if (r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS && regions.size() > ++i) { - // get attr value - r = regions.get(i); - if (r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) { - // attributes in our document have quotes, so we - // need to strip them - attrValue = StringUtils.stripQuotes(customTag.getText(r)); - tagDataTable.put(attrName, attrValue); - } - } - } - } - } - - tagDataTable.put("jsp:id", customTag.getText(regions.get(1)) + "_" + customTag.getStartOffset()); //$NON-NLS-1$ - - return tagDataTable; - } - - private ClassLoader getClassloader() { - if (fLoader == null) { - fLoader = new BuildPathClassLoader(this.getClass().getClassLoader(), fJavaProject); - } - return fLoader; - } - - /** - * @return Returns the fModelQuery. - */ - public ModelQuery getModelQuery(IDocument doc) { - IStructuredModel model = null; - ModelQuery mq = null; - try { - model = StructuredModelManager.getModelManager().getExistingModelForRead(doc); - mq = ModelQueryUtil.getModelQuery(model); - } - finally { - if (model != null) - model.releaseFromRead(); - } - return mq; - } - - - /** - * @return Returns the fFile. - */ - public IProject getProject() { - - return fProject; - } - - /** - * @param file - * The fFile to set. - */ - public void setProject(IProject p) { - fProject = p; - IJavaProject javaProject = JavaCore.create(p); - if (javaProject.exists()) { - fJavaProject = javaProject; - } - } - - private void validateTagClass(IStructuredDocument document, ITextRegionCollection customTag, TLDElementDeclaration decl, List problems) { - // skip if from a tag file - if (TLDElementDeclaration.SOURCE_TAG_FILE.equals(decl.getProperty(TLDElementDeclaration.TAG_SOURCE)) || fJavaProject == null) { - return; - } - - String tagClassname = decl.getTagclass(); - Object tagClass = null; - if (tagClassname != null && tagClassname.length() > 0 && fJavaProject.exists()) { - try { - tagClass = fJavaProject.findType(tagClassname); - } - catch (JavaModelException e) { - Logger.logException(e); - } - } - if (tagClass == null) { - Object createdProblem = createJSPProblem(document, customTag, IJSPProblem.TagClassNotFound, JSPCoreMessages.TaglibHelper_3, tagClassname, false); - if (createdProblem != null) { - problems.add(createdProblem); - } - } - } - - /** - * - */ - public void dispose() { - fLoader = null; - fJavaProject = null; - fProject = null; - fNotFoundClasses = null; - fClassMap = null; - fMemoryListener.disconnect(); - fMemoryListener = null; - } - - public void invalidateClass(String className) { - fClassMap.remove(className); - } - - /** - * <p>A {@link AbstractMemoryListener} that clears the {@link #fNotFoundClasses} cache - * whenever specific memory events are received.</p> - * - * <p>Events: - * <ul> - * <li>{@link AbstractMemoryListener#SEV_NORMAL}</li> - * <li>{@link AbstractMemoryListener#SEV_SERIOUS}</li> - * <li>{@link AbstractMemoryListener#SEV_CRITICAL}</li> - * </ul> - * </p> - */ - private class MemoryListener extends AbstractMemoryListener { - /** - * <p>Constructor causes this listener to listen for specific memory events.</p> - * <p>Events: - * <ul> - * <li>{@link AbstractMemoryListener#SEV_NORMAL}</li> - * <li>{@link AbstractMemoryListener#SEV_SERIOUS}</li> - * <li>{@link AbstractMemoryListener#SEV_CRITICAL}</li> - * </ul> - * </p> - */ - MemoryListener() { - super(new String[] { SEV_NORMAL, SEV_SERIOUS, SEV_CRITICAL }); - } - - /** - * On any memory event we handle clear out the project descriptions - * - * @see org.eclipse.jst.jsp.core.internal.util.AbstractMemoryListener#handleMemoryEvent(org.osgi.service.event.Event) - */ - protected void handleMemoryEvent(Event event) { - /* if running low on memory then this cache can be cleared - * and rebuilt at the expense of processing time - */ - fNotFoundClasses.clear(); - fClassMap.clear(); - } - - } - - class TagLibraryInfoImpl extends TagLibraryInfo { - TLDElementDeclaration decl; - - TagLibraryInfoImpl(String prefix, String uri, TLDElementDeclaration decl){ - super(prefix, uri); - this.decl = decl; - } - - public String getURI() { - if (Platform.inDebugMode()) - new NotImplementedException().printStackTrace(); - return super.getURI(); - } - - public String getPrefixString() { - if (Platform.inDebugMode()) - new NotImplementedException().printStackTrace(); - return super.getPrefixString(); - } - - public String getShortName() { - return ((TLDDocument)decl.getOwnerDocument()).getShortname(); - } - - public String getReliableURN() { - return ((TLDDocument)decl.getOwnerDocument()).getUri(); - } - - public String getInfoString() { - return ((TLDDocument)decl.getOwnerDocument()).getInfo(); - } - - public String getRequiredVersion() { - return ((TLDDocument)decl.getOwnerDocument()).getJspversion(); - } - - public TagInfo[] getTags() { - if (Platform.inDebugMode()) - new NotImplementedException().printStackTrace(); - return super.getTags(); - } - - public TagFileInfo[] getTagFiles() { - if (Platform.inDebugMode()) - new NotImplementedException().printStackTrace(); - return super.getTagFiles(); - } - - public TagInfo getTag(String shortname) { - if (Platform.inDebugMode()) - new NotImplementedException().printStackTrace(); - return super.getTag(shortname); - } - - public TagFileInfo getTagFile(String shortname) { - if (Platform.inDebugMode()) - new NotImplementedException().printStackTrace(); - return super.getTagFile(shortname); - } - - public FunctionInfo[] getFunctions() { - if (Platform.inDebugMode()) - new NotImplementedException().printStackTrace(); - return super.getFunctions(); - } - - public FunctionInfo getFunction(String name) { - new NotImplementedException(name).printStackTrace(); - return super.getFunction(name); - } - - public TagLibraryInfo[] getTagLibraryInfos() { - if (Platform.inDebugMode()) - new NotImplementedException().printStackTrace(); - return new TagLibraryInfo[] { this }; - } - } -} diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/taglib/TaglibHelperCache.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/taglib/TaglibHelperCache.java deleted file mode 100644 index 8c5eadfee6..0000000000 --- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/taglib/TaglibHelperCache.java +++ /dev/null @@ -1,183 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.jst.jsp.core.internal.taglib; - - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jst.jsp.core.internal.Logger; - -/** - * A simple cache for TaglibHelpers to avoid excessive creation of TaglibClassLoaders - * @author pavery - */ -class TaglibHelperCache { - - private static final boolean DEBUG; - static { - String value = Platform.getDebugOption("org.eclipse.jst.jsp.core/debug/taglibvars"); //$NON-NLS-1$ - DEBUG = value != null && value.equalsIgnoreCase("true"); //$NON-NLS-1$ - } - - /** - * An entry for the cache (projectPath string & TaglibHelper) - */ - class Entry { - private TaglibHelper fHelper; - private String fProjectName; - - public Entry(String projectName, TaglibHelper helper) { - setProjectName(projectName); - setHelper(helper); - } - public TaglibHelper getHelper() { - return fHelper; - } - public void setHelper(TaglibHelper helper) { - fHelper = helper; - } - public String getProjectName() { - return fProjectName; - } - public void setProjectName(String projectName) { - fProjectName = projectName; - } - public String toString() { - return "Taglib Helper Entry [" + getProjectName() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - private List fHelpers; - // max size for the cache - private int MAX_SIZE; - - /** - * Not intended to be large since underlying implmementation uses - * a List. - */ - public TaglibHelperCache(int size) { - MAX_SIZE = size; - fHelpers = Collections.synchronizedList(new ArrayList(MAX_SIZE)); - } - /** - * - * @param projectPath - * @param f - * @param mq - * @return - */ - public final synchronized TaglibHelper getHelper(IProject project) { - TaglibHelper helper = null; - Entry entry = null; - String projectName = project.getName(); - int size = fHelpers.size(); - // fist check for existing - for (int i=0; i<size; i++) { - entry = (Entry)fHelpers.get(i); - if(entry.getProjectName().equals(projectName)) { - // exists - helper = entry.getHelper(); - // only move to front if it's not the first entry - if(i>0) { - fHelpers.remove(entry); - fHelpers.add(1, entry); - if(DEBUG) { - Logger.log(Logger.INFO, "(->) TaglibHelperCache moved: " + entry + " to the front of the list"); //$NON-NLS-1$ //$NON-NLS-2$ - printCacheContents(); - } - } - break; - } - } - // didn't exist - if(helper == null) { - helper = createNewHelper(projectName, project); - } - return helper; - } - - /** - * @param projectName - * @param f - * @param mq - * @return - */ - private TaglibHelper createNewHelper(String projectName, IProject project) { - - TaglibHelper helper; - // create - helper = new TaglibHelper(project); - Entry newEntry = new Entry(projectName, helper); - fHelpers.add(0, newEntry); - if(DEBUG) { - Logger.log(Logger.INFO, "(+) TaglibHelperCache added: " + newEntry); //$NON-NLS-1$ - printCacheContents(); - } - if(fHelpers.size() > MAX_SIZE) { - // one too many, remove last - Entry removed = (Entry) fHelpers.remove(fHelpers.size()-1); - removed.getHelper().dispose(); - if(DEBUG) { - Logger.log(Logger.INFO, "(-) TaglibHelperCache removed: " + removed.getProjectName()); //$NON-NLS-1$ - printCacheContents(); - } - } - return helper; - } - - public final synchronized void removeHelper(String projectName) { - Entry entry = null; - Iterator it = fHelpers.iterator(); - while(it.hasNext()) { - entry = (Entry)it.next(); - if(entry.getProjectName().equals(projectName)) { - entry.getHelper().dispose(); - fHelpers.remove(entry); - if(DEBUG) { - Logger.log(Logger.INFO, "(-) TaglibHelperCache removed: " + entry); //$NON-NLS-1$ - printCacheContents(); - } - break; - } - } - } - - public final synchronized void invalidate(String projectName, String className) { - Entry entry = null; - Iterator it = fHelpers.iterator(); - while(it.hasNext()) { - entry = (Entry)it.next(); - if(entry.getProjectName().equals(projectName)) { - entry.getHelper().invalidateClass(className); - if(DEBUG) { - Logger.log(Logger.INFO, "(-) TaglibHelperCache invalidated: " + className); //$NON-NLS-1$ - printCacheContents(); - } - break; - } - } - } - private void printCacheContents() { - StringBuffer debugString = new StringBuffer(); - debugString.append("\n-----------------------------------------------------------"); //$NON-NLS-1$ - debugString.append("\ncache contents:"); //$NON-NLS-1$ - for (int i=0; i<fHelpers.size(); i++) - debugString.append("\n -" + i + "- " + fHelpers.get(i)); //$NON-NLS-1$ //$NON-NLS-2$ - debugString.append("\n-----------------------------------------------------------"); //$NON-NLS-1$ - Logger.log(Logger.INFO, debugString.toString()); - } -} diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/taglib/TaglibHelperManager.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/taglib/TaglibHelperManager.java deleted file mode 100644 index c0b26e0bae..0000000000 --- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/taglib/TaglibHelperManager.java +++ /dev/null @@ -1,104 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 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.jsp.core.internal.taglib; - - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.jdt.core.ElementChangedEvent; -import org.eclipse.jdt.core.IElementChangedListener; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IJavaElementDelta; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IType; - -/** - * Manages creation and caching (ordered MRU) of TaglibHelpers. - * Removes helpers when their classpath changes (so they are rebuilt). - * There is one helper per project (with a specific classpath entry). - * - * @author pavery - */ -public class TaglibHelperManager implements IElementChangedListener { - - - private static TaglibHelperManager instance = null; - // using a cache of just 3 loaders - private TaglibHelperCache fCache = new TaglibHelperCache(3); - - private TaglibHelperManager() { - // use instance - } - public static synchronized TaglibHelperManager getInstance() { - if(instance == null) - instance = new TaglibHelperManager(); - return instance; - } - - public TaglibHelper getTaglibHelper(IFile f) { - IProject p = f.getProject(); - return getHelperFromCache(p); - } - - /** - * @param projectPath - */ - private TaglibHelper getHelperFromCache(IProject project) { - return fCache.getHelper(project); - } - - /** - * Update classpath for appropriate loader. - * @see org.eclipse.jdt.core.IElementChangedListener#elementChanged(org.eclipse.jdt.core.ElementChangedEvent) - */ - public void elementChanged(ElementChangedEvent event) { - // handle classpath changes - IJavaElementDelta delta = event.getDelta(); - if (delta.getElement().getElementType() == IJavaElement.JAVA_MODEL) { - IJavaElementDelta[] changed = delta.getChangedChildren(); - for (int i = 0; i < changed.length; i++) { - if ((changed[i].getFlags() & IJavaElementDelta.F_CLASSPATH_CHANGED) != 0 || (changed[i].getFlags() & IJavaElementDelta.F_REORDER) != 0 || (changed[i].getFlags() & IJavaElementDelta.F_RESOLVED_CLASSPATH_CHANGED) != 0 || (changed[i].getFlags() & IJavaElementDelta.F_PRIMARY_RESOURCE) != 0) { - IJavaElement proj = changed[i].getElement(); - handleClasspathChange(changed, i, proj); - } - } - } - else if (delta.getElement().getElementType() == IJavaElement.COMPILATION_UNIT) { - IJavaElementDelta[] changed = delta.getChangedChildren(); - for (int i = 0; i < changed.length; i++) { - if ((changed[i].getFlags() & IJavaElementDelta.F_SUPER_TYPES) != 0) { - IJavaElement element = changed[i].getElement(); - handleSuperTypeChange(element); - } - } - } - } - - private void handleSuperTypeChange(IJavaElement element) { - IJavaProject project = element.getJavaProject(); - if (element instanceof IType) { - fCache.invalidate(project.getProject().getName(), ((IType) element).getFullyQualifiedName()); - } - } - - /** - * @param changed - * @param i - * @param proj - */ - private void handleClasspathChange(IJavaElementDelta[] changed, int i, IJavaElement proj) { - if (proj.getElementType() == IJavaElement.JAVA_PROJECT) { - String projectName = ((IJavaProject) proj).getProject().getName(); - fCache.removeHelper(projectName); - } - } -} diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/taglib/TaglibVariable.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/taglib/TaglibVariable.java deleted file mode 100644 index ab91ce9366..0000000000 --- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/taglib/TaglibVariable.java +++ /dev/null @@ -1,167 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2010 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.jsp.core.internal.taglib; - -import javax.servlet.jsp.tagext.VariableInfo; - -import org.eclipse.wst.sse.core.utils.StringUtils; - -/** - * Contains info about a TaglibVariable: classname, variablename. - */ -public class TaglibVariable { - - private String fVarClass = null; - private String fVarName = null; - private int fScope; - private String fDescription; - - /** fixed end-of-line value */ - private final String ENDL = "\n"; //$NON-NLS-1$ - - private final static String AT_END = "AT_END"; - private final static String AT_BEGIN = "AT_BEGIN"; - private final static String NESTED = "NESTED"; - - public static final int M_PRIVATE = 1; - public static final int M_NONE = 0; - - /** - * - */ - public TaglibVariable(String varClass, String varName, int scope) { - setVarClass(varClass); - setVarName(varName); - setScope(scope); - } - - public TaglibVariable(String varClass, String varName, String scope) { - setVarClass(varClass); - setVarName(varName); - setScope(scope); - } - - public TaglibVariable(String varClass, String varName, String scope, String description) { - setVarClass(varClass); - setVarName(varName); - setScope(scope); - setDescription(description); - } - - TaglibVariable(String varClass, String varName, int scope, String description) { - setVarClass(varClass); - setVarName(varName); - setScope(scope); - setDescription(description); - } - - /** - * @return Returns the fVarClass. - */ - public final String getVarClass() { - return fVarClass; - } - - /** - * @param varClass - * The fVarClass to set. - */ - public final void setVarClass(String varClass) { - fVarClass = varClass; - } - - /** - * @return Returns the fVarName. - */ - public final String getVarName() { - return fVarName; - } - - /** - * @param varName - * The fVarName to set. - */ - public final void setVarName(String varName) { - fVarName = varName; - } - - /** - * Convenience method. - * - * @return - */ - public final String getDeclarationString() { - return getDeclarationString(false, M_NONE); - } - - /** - * Convenience method. - * - * @return - */ - public final String getDeclarationString(boolean includeDoc, int style) { - String declaration = null; - /* - * no description for now --JDT would need to show it for local - * variables and ILocalVariable has no "doc range" - */ - if (includeDoc && getDescription() != null) { - if (style == M_PRIVATE) { - declaration = "/** " + ENDL + StringUtils.replace(getDescription(), "*/", "*\\/") + ENDL + " */ " + ENDL + "private " + getVarClass() + " " + getVarName() + " = (" + getVarClass() + ") pageContext.getAttribute(\"" + getVarName() + "\");" + ENDL; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ - } - else { - declaration = "/** " + ENDL + StringUtils.replace(getDescription(), "*/", "*\\/") + ENDL + " */ " + ENDL + getVarClass() + " " + getVarName() + " = (" + getVarClass() + ") pageContext.getAttribute(\"" + getVarName() + "\");" + ENDL; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ - } - } - else { - if (style == M_PRIVATE) { - declaration = "private " + getVarClass() + " " + getVarName() + " = (" + getVarClass() + ") pageContext.getAttribute(\"" + getVarName() + "\");" + ENDL; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ - } - else { - declaration = getVarClass() + " " + getVarName() + " = (" + getVarClass() + ") pageContext.getAttribute(\"" + getVarName() + "\");" + ENDL; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - } - } - return declaration; - } - - public String getDescription() { - return fDescription; - } - - public int getScope() { - return fScope; - } - - public void setScope(int scope) { - fScope = scope; - } - - public void setScope(String scopeString) { - int scope = VariableInfo.AT_BEGIN; - - String trimmedScope = scopeString.trim(); - if (NESTED.equals(trimmedScope)) { - scope = VariableInfo.NESTED; - } - else if (AT_BEGIN.equals(trimmedScope)) { - scope = VariableInfo.AT_BEGIN; - } - else if (AT_END.equals(trimmedScope)) { - scope = VariableInfo.AT_END; - } - - fScope = scope; - } - - public void setDescription(String description) { - fDescription = description; - } -} |