diff options
Diffstat (limited to 'bundles/org.eclipse.wst.xml.core/src-search')
16 files changed, 0 insertions, 1633 deletions
diff --git a/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/ComponentSearchContributor.java b/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/ComponentSearchContributor.java deleted file mode 100644 index 6c1dcdeeef..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/ComponentSearchContributor.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 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.wst.xml.core.internal.search; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.eclipse.wst.common.core.search.pattern.QualifiedName; - -public abstract class ComponentSearchContributor { - - protected HashMap declarations; - - protected HashMap references; - - protected String[] namespaces; - - public ComponentSearchContributor() { - super(); - } - - public XMLSearchPattern getDeclarationPattern(QualifiedName componentName) { - return (XMLSearchPattern) getDeclarations().get(componentName); - } - - protected Map getDeclarations() { - if (declarations == null) { - initializeDeclarations(); - } - return declarations; - } - - protected Map getReferences() { - if (references == null) { - initializeReferences(); - } - return references; - } - - public XMLSearchPattern[] getReferencesPatterns(QualifiedName componentName) { - List references = (List) getReferences().get(componentName); - if (references != null) { - return (XMLSearchPattern[]) references - .toArray(new XMLSearchPattern[references.size()]); - } - return new XMLSearchPattern[0]; - } - - - public boolean supports(QualifiedName componentName){ - return getReferencesPatterns(componentName).length > 0 || - getDeclarationPattern(componentName) != null; - } - - public String[] getSupportedNamespaces() { - return namespaces; - } - - protected abstract void initializeDeclarations(); - - protected abstract void initializeReferences(); - - protected abstract void initializeSupportedNamespaces(); -} diff --git a/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/TargetNamespaceReferencePattern.java b/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/TargetNamespaceReferencePattern.java deleted file mode 100644 index 6321b7c3b1..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/TargetNamespaceReferencePattern.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 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.wst.xml.core.internal.search; - -import org.eclipse.wst.common.core.search.pattern.SearchPattern; - -public class TargetNamespaceReferencePattern extends SearchPattern { - - String namespaceURI; - - public TargetNamespaceReferencePattern(int matchRule, String namespaceuri) { - super(matchRule); - namespaceURI = namespaceuri; - } - - public TargetNamespaceReferencePattern(String namespaceuri) { - super(); - namespaceURI = namespaceuri; - } - -} diff --git a/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/XMLComponentDeclarationPattern.java b/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/XMLComponentDeclarationPattern.java deleted file mode 100644 index 19f475beb1..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/XMLComponentDeclarationPattern.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 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.wst.xml.core.internal.search; - -import org.eclipse.core.resources.IFile; -import org.eclipse.wst.common.core.search.pattern.QualifiedName; - -public class XMLComponentDeclarationPattern extends XMLComponentSearchPattern { - - public XMLComponentDeclarationPattern(QualifiedName elementQName, QualifiedName typeQName, int matchRule) { - super(null, elementQName, typeQName, matchRule); - - } - - public XMLComponentDeclarationPattern(IFile file, QualifiedName elementQName, QualifiedName typeQName) { - super(file, elementQName, typeQName); - } - - public XMLComponentDeclarationPattern(QualifiedName elementQName, QualifiedName typeQName) { - super(null, elementQName, typeQName); - } - - - -} diff --git a/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/XMLComponentReferencePattern.java b/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/XMLComponentReferencePattern.java deleted file mode 100644 index e68a8a422a..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/XMLComponentReferencePattern.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 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.wst.xml.core.internal.search; - -import org.eclipse.core.resources.IFile; -import org.eclipse.wst.common.core.search.pattern.QualifiedName; - -public class XMLComponentReferencePattern extends XMLComponentSearchPattern{ - - public XMLComponentReferencePattern(IFile file, QualifiedName elementQName, QualifiedName typeQName, int matchRule) { - super(file, elementQName, typeQName, matchRule); - - } - - public XMLComponentReferencePattern(IFile file, QualifiedName elementQName, QualifiedName typeQName) { - super(file, elementQName, typeQName); - - } - - public XMLComponentReferencePattern(QualifiedName elementQName, QualifiedName typeQName) { - super(null, elementQName, typeQName); - - } - - - - -} diff --git a/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/XMLComponentSearchPattern.java b/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/XMLComponentSearchPattern.java deleted file mode 100644 index 7abd04bada..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/XMLComponentSearchPattern.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 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.wst.xml.core.internal.search; - -import org.eclipse.core.resources.IFile; -import org.eclipse.wst.common.core.search.pattern.ComponentSearchPattern; -import org.eclipse.wst.common.core.search.pattern.QualifiedName; - -/** - * XML component search pattern is a composite pattern that combines XML element pattern. - * - */ -public class XMLComponentSearchPattern extends ComponentSearchPattern { - - /** - * Containing element patterns - */ - XMLSearchPattern[] children = new XMLSearchPattern[0]; - - - public XMLComponentSearchPattern(IFile file, QualifiedName elementQName, QualifiedName typeQName, int matchRule) { - super(file, elementQName, typeQName, matchRule); - - } - - - public XMLComponentSearchPattern(IFile file, QualifiedName elementQName, QualifiedName typeQName) { - super(file, elementQName, typeQName); - - } - - public XMLSearchPattern[] getChildren(){ - return children; - } - - public void setChildren(XMLSearchPattern[] patterns){ - children = patterns; - - } - -} diff --git a/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/XMLSearchParticipant.java b/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/XMLSearchParticipant.java deleted file mode 100644 index 0327e7753a..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/XMLSearchParticipant.java +++ /dev/null @@ -1,387 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 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.wst.xml.core.internal.search; - -import java.util.HashMap; -import java.util.Map; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.wst.common.core.search.SearchMatch; -import org.eclipse.wst.common.core.search.SearchParticipant; -import org.eclipse.wst.common.core.search.SearchRequestor; -import org.eclipse.wst.common.core.search.document.ComponentDeclarationEntry; -import org.eclipse.wst.common.core.search.document.Entry; -import org.eclipse.wst.common.core.search.document.FileReferenceEntry; -import org.eclipse.wst.common.core.search.document.SearchDocument; -import org.eclipse.wst.common.core.search.document.SearchDocumentSet; -import org.eclipse.wst.common.core.search.pattern.ComponentSearchPattern; -import org.eclipse.wst.common.core.search.pattern.FileReferencePattern; -import org.eclipse.wst.common.core.search.pattern.SearchPattern; -import org.eclipse.wst.common.core.search.scope.ContentTypeSearchScope; -import org.eclipse.wst.common.core.search.scope.SearchScope; -import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver; -import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolverPlugin; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; -import org.eclipse.wst.xml.core.internal.search.impl.IXMLSearchConstants; -import org.eclipse.wst.xml.core.internal.search.impl.XMLSearchDocument; -import org.eclipse.wst.xml.core.internal.search.matching.PatternMatcher; -import org.eclipse.wst.xml.core.internal.search.matching.XMLSearchPatternMatcher; -import org.eclipse.wst.xml.core.internal.search.quickscan.XMLQuickScan; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -/** - * - */ -public abstract class XMLSearchParticipant extends SearchParticipant { - - protected static final boolean debugPerf = "true".equalsIgnoreCase(Platform.getDebugOption("org.eclipse.wst.xml.core.internal.search/perf")); //$NON-NLS-1$ //$NON-NLS-2$ - - public XMLSearchParticipant() { - super(); - } - - - /* - public boolean initialize(SearchPattern pattern, String[] contentTypes){ - - super.initialize(pattern, contentTypes); - this.supportedContentTypes = contentTypes; - - if(pattern instanceof XMLComponentSearchPattern){ - return true; - } - return false; - }*/ - - - - public SearchDocument createSearchDocument(String documentPath) { - - return new XMLSearchDocument(documentPath, this); - - } - - public String getDescription() { - return "XML search participant"; //$NON-NLS-1$ - } - - - - private void locateMatches(SearchPattern pattern, SearchDocument document, - SearchRequestor requestor, Map searchOptions, IProgressMonitor monitor) { - - // TODO... utilize search options (that should get passed down via the SearchEngine) - // to specify if accurate source coordinates are req'd if not, simply use the SAX results - // - if (pattern.getMatchRule() == SearchPattern.R_PATTERN_MATCH) - { - IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(document.getPath())); - // TODO.. don't assume the category is COMPONENT_DECL... handle any arbitarty category - Entry[] entries = document.getEntries(IXMLSearchConstants.COMPONENT_DECL, null, 0); - for (int i = 0; i < entries.length; i++) - { - // TODO.. don't assume this is just a component declaration entry - ComponentDeclarationEntry entry = (ComponentDeclarationEntry)entries[i]; - SearchMatch searchMatch = new SearchMatch(null, 0, 0, file); - searchMatch.map.put("name", entry.getName()); //$NON-NLS-1$ - searchMatch.map.put("metaName", entry.getMetaName()); //$NON-NLS-1$ - try - { - requestor.acceptSearchMatch(searchMatch); - } - catch (Exception e) - { - } - } - } - else - { if (document.getModel() instanceof IDOMModel) { - IDOMModel domModel = (IDOMModel) document.getModel(); - IDOMElement contextNode = (IDOMElement) domModel.getDocument() - .getDocumentElement(); - DOMVisitor visitor = new DOMVisitor(document.getPath(), pattern, - requestor); - visitor.visit(contextNode); - } - } - } - - private PatternMatcher getAdapter(Object adaptableObject, Class adapterType) { - if (PatternMatcher.class.equals(adapterType) && - (adaptableObject instanceof XMLSearchPattern || - adaptableObject instanceof XMLComponentSearchPattern) ) { - return new XMLSearchPatternMatcher(); - } - return null; - } - - private class DOMVisitor { - - String path; - SearchPattern pattern; - SearchRequestor requestor; - PatternMatcher matcher; - - - protected DOMVisitor(String path, SearchPattern pattern, - SearchRequestor requestor) { - super(); - this.path = path; - this.pattern = pattern; - - matcher = (PatternMatcher)pattern.getAdapter(PatternMatcher.class); - if(matcher == null){ - matcher = getAdapter(pattern, PatternMatcher.class); - } - this.requestor = requestor; - } - - private void visit(Node node) { - if (node.getNodeType() == Node.ELEMENT_NODE) { - match((Element)node); - NodeList nodeList = node.getChildNodes(); - for (int i = 0; i < nodeList.getLength(); i++) { - Node aNode = nodeList.item(i); - visit(aNode); - } - } - } - - private void match(Element node) { - IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation( - new Path(path)); - if(matcher != null){ - matcher.locateMatches(pattern, file, node, requestor); - } - - - } - - } - - public SearchScope selectDocumentLocations(SearchPattern pattern, SearchScope scope, Map searchOptions, IProgressMonitor monitor) { - /* - * gate #1: reduce the scope to the files with the content type that - * could be searched using this participant - */ - String[] contentTypes = getSupportedContentTypes(); - if(contentTypes != null && contentTypes.length > 0){ - scope = new ContentTypeSearchScope(scope, contentTypes); - } - return super.selectDocumentLocations(pattern, scope, searchOptions, monitor); - } - - public abstract ComponentSearchContributor getSearchContributor(); - - - public void beginSearching(SearchPattern pattern, Map searchOptions) { - - super.beginSearching(pattern, searchOptions); - if(pattern instanceof XMLComponentDeclarationPattern){ - XMLComponentDeclarationPattern componentPattern = (XMLComponentDeclarationPattern)pattern; - XMLSearchPattern childPattern = getSearchContributor().getDeclarationPattern(componentPattern.getMetaName()); - if(childPattern != null){ - childPattern.setSearchName(componentPattern.getName().getLocalName()); - childPattern.setSearchNamespace(componentPattern.getName().getNamespace()); - componentPattern.setChildren(new XMLSearchPattern[]{childPattern}); - } - - } - else if(pattern instanceof XMLComponentReferencePattern){ - XMLComponentReferencePattern componentPattern = (XMLComponentReferencePattern)pattern; - XMLSearchPattern[] childPatterns = getSearchContributor().getReferencesPatterns(componentPattern.getMetaName()); - for (int i = 0; i < childPatterns.length; i++) { - XMLSearchPattern childPattern = childPatterns[i]; - childPattern.setSearchName(componentPattern.getName().getLocalName()); - childPattern.setSearchNamespace(componentPattern.getName().getNamespace()); - } - componentPattern.setChildren(childPatterns); - - } - } - - - /** - * The intend of this method is to limit the search to the files that have content - * which can be searched for the given pattern. It is called from - * {@link #selectDocumentLocations(SearchPattern, SearchScope, IProgressMonitor)} - * - * @param pattern the search pattern that is searched for - * @return content type's unique identifiers that could be searched for the given pattern. - */ - public abstract String[] getSupportedContentTypes(); - - public void populateSearchDocument(SearchDocument document, SearchPattern pattern) - { - PatternMatcher matcher = (PatternMatcher)pattern.getAdapter(PatternMatcher.class); - if(matcher == null){ - matcher = getAdapter(pattern, PatternMatcher.class); - } - XMLQuickScan.populateSearchDocument(document, matcher, pattern); - } - - public void locateMatches(SearchDocumentSet documentSet, SearchPattern pattern, SearchScope scope, SearchRequestor requestor, Map searchOptions, IProgressMonitor monitor) throws CoreException - { - long time = System.currentTimeMillis(); - - // TODO: use the file reference entries in the documents to reduce the scope to the referenced files only - // SearchDocument[] documents = documentSet.getSearchDocuments(id); - - // check to see if the search pattern is qualified by a file location - // if this is the case then we can use file scoping rules to prune the matches - IFile targetFile = null; - if (pattern instanceof ComponentSearchPattern) - { - ComponentSearchPattern componentSearchPattern = (ComponentSearchPattern)pattern; - targetFile = componentSearchPattern.getFile(); - } - - // here we should have in scope only referenced files - IFile[] files = scope.enclosingFiles(); - for (int i = 0; i < files.length; i++) - { - IFile file = files[i]; - String path = file.getLocation().toString(); - SearchDocument document = documentSet.getSearchDocument(path, id); - if (document != null) - { - Entry[] entries = document.getEntries(getSearchEntryCategory(pattern), null, 0); - if ((entries != null && entries.length > 0) || (searchOptions != null && searchOptions.get("searchDirtyContent") != null)) - { - //for (int j = 0; j < entries.length; j++) - //{ - // Entry entry = entries[j]; - //System.out.println("entry " + entry.getCategory() + " " + entry.getKey() + " " + entry.getClass().getName()); - //} - - boolean isInScope = true; - if (targetFile != null) - { - try - { - isInScope = isLinked(documentSet, "file:///" + path, "file:///" + targetFile.getLocation().toString()); //$NON-NLS-1$ //$NON-NLS-2$ - //if (path.endsWith("CancelSelection.wsdl") && path.indexOf("clone1") != -1) - //{ - // fileReferenceTable.debug(qualifiedPath, 0, 5); - //} - } - catch (Exception e) - { - e.printStackTrace(); - } - } - if (isInScope) - { - this.locateMatches(pattern, document, requestor, searchOptions, monitor); - } - } - } - } - - - if (debugPerf) - { - System.out - .println("" //$NON-NLS-1$ - + getDescription() - + ": " + (System.currentTimeMillis() - time) + "ms for locateMatches"); //$NON-NLS-1$ //$NON-NLS-2$ - } - - - } - - private boolean isLinked(SearchDocumentSet set, String source, String target) - { - return isLinked(set, source, target, new HashMap()); - } - - private boolean isLinked(SearchDocumentSet set, String source, String target, HashMap visited) - { - if (source.equals(target)) - return true; - - String fileProtocol = "file:///"; //$NON-NLS-1$ - - // Fix for bug 204174 - Begin - if(target.charAt(fileProtocol.length()) == '/') //$NON-NLS-1$ - { - target = fileProtocol + target.substring(fileProtocol.length() + 1); - } - // Fix for bug 204174 - End - - if (source.startsWith(fileProtocol)) - { - - SearchDocument document = set._tempGetSearchDocumetn(source.substring(fileProtocol.length())); - if (document != null) - { - URIResolver uriResolver = URIResolverPlugin.createResolver(); - Entry[] entries = document.getEntries(IXMLSearchConstants.REF, null, 0); - String[] resolveEntry = new String[entries.length]; - for (int j = 0; j < entries.length; j++) - { - Entry entry = entries[j]; - if (entry instanceof FileReferenceEntry) - { - FileReferenceEntry fileReferenceEntry = (FileReferenceEntry)entry; - // TODO.. record an utilize the public id from the fileReferenceEntry - // - if (fileReferenceEntry.getRelativeFilePath() != null) - { - String resolvedURI = uriResolver.resolve(source, null, fileReferenceEntry.getRelativeFilePath()); - resolveEntry[j] = resolvedURI; - if (resolvedURI.equals(target)) - { - return true; - } - } - } - } - // now see if there's an indirect link from the source to the target - // we keep track of the nodes we've already visited to avoid cycles - if (visited.get(source) == null) - { - visited.put(source, Boolean.TRUE); - for (int j = 0; j < entries.length; j++) - { - String resolvedURI = resolveEntry[j]; - if (resolvedURI != null && isLinked(set, resolveEntry[j], target, visited)) - return true; - } - } - } - } - return false; - } - - - - public static String getSearchEntryCategory(SearchPattern pattern){ - if(pattern instanceof XMLComponentDeclarationPattern){ - return IXMLSearchConstants.COMPONENT_DECL; - } - else if(pattern instanceof XMLComponentReferencePattern){ - return IXMLSearchConstants.COMPONENT_REF; - } - else if(pattern instanceof FileReferencePattern){ - return IXMLSearchConstants.COMPONENT_REF; - } - return null; - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/XMLSearchPattern.java b/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/XMLSearchPattern.java deleted file mode 100644 index e3b58e1ba0..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/XMLSearchPattern.java +++ /dev/null @@ -1,111 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 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.wst.xml.core.internal.search; - -import org.eclipse.wst.common.core.search.pattern.SearchPattern; - -public class XMLSearchPattern extends SearchPattern{ - - private String elementNamespace = null; - private String elementName = null; - private String attributeName = null; - private String searchName = null; - private String searchNamespace = null; - private String parentName = null; - private int depth = -1; - - public XMLSearchPattern(String elementNamespace, String parentElementName,String elementName, String attributeName) { - this(elementNamespace, parentElementName, elementName, attributeName, -1); - } - - public XMLSearchPattern(String elementNamespace, String elementName, String attributeName) { - this(elementNamespace, null, elementName, attributeName, -1); - } - - public XMLSearchPattern(String elementNamespace, String elementName, String attributeName, int depth) { - this(elementNamespace, null, elementName, attributeName, depth); - } - - private XMLSearchPattern(String elementNamespace, String parentElementName, String elementName, String attributeName, int depth) { - super(); - this.attributeName = attributeName; - this.elementName = elementName; - this.parentName = parentElementName; - this.elementNamespace = elementNamespace; - this.depth = depth; - } - - public XMLSearchPattern(){ - - } - - public String getAttributeName() { - return attributeName; - } - - public String getElementName() { - return elementName; - } - - public String getElementNamespace() { - return elementNamespace; - } - - public String getSearchName() { - return searchName; - } - - public String getSearchNamespace() { - return searchNamespace; - } - - public void setSearchName(String searchName) { - this.searchName = searchName; - } - - public void setSearchNamespace(String searchNamespace) { - this.searchNamespace = searchNamespace; - } - - public void setAttributeName(String attributeName) { - this.attributeName = attributeName; - } - - public void setElementName(String elementName) { - this.elementName = elementName; - } - - public void setElementNamespace(String elementNamespace) { - this.elementNamespace = elementNamespace; - } - - public int getDepth() - { - return depth; - } - - public void setDepth(int depth) - { - this.depth = depth; - } - -public String getParentName() { - return parentName; -} - -public void setParentName(String parentName) { - this.parentName = parentName; -} - - - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/impl/IXMLSearchConstants.java b/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/impl/IXMLSearchConstants.java deleted file mode 100644 index d160d819ea..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/impl/IXMLSearchConstants.java +++ /dev/null @@ -1,20 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 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.wst.xml.core.internal.search.impl; - -public interface IXMLSearchConstants -{ - String REF= "outLink"; //$NON-NLS-1$ - String COMPONENT_DECL = "componentDecl"; //$NON-NLS-1$ - String COMPONENT_REF = "componentDecl"; //$NON-NLS-1$ - -} diff --git a/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/impl/Messages.java b/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/impl/Messages.java deleted file mode 100644 index d7ae22f5c2..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/impl/Messages.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 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.wst.xml.core.internal.search.impl; - -import java.text.MessageFormat; -import org.eclipse.osgi.util.NLS; - -public class Messages extends NLS { - - private static final String BUNDLE_NAME = "org.eclipse.wst.xml.core.internal.search.messages";//$NON-NLS-1$ - - - static { - NLS.initializeMessages(BUNDLE_NAME, Messages.class); - } - private Messages() { - // Do not instantiate - } - - /** - * Bind the given message's substitution locations with the given string values. - * - * @param message the message to be manipulated - * @return the manipulated String - */ - public static String bind(String message) { - return bind(message, null); - } - - /** - * Bind the given message's substitution locations with the given string values. - * - * @param message the message to be manipulated - * @param binding the object to be inserted into the message - * @return the manipulated String - */ - public static String bind(String message, Object binding) { - return bind(message, new Object[] {binding}); - } - - /** - * Bind the given message's substitution locations with the given string values. - * - * @param message the message to be manipulated - * @param binding1 An object to be inserted into the message - * @param binding2 A second object to be inserted into the message - * @return the manipulated String - */ - public static String bind(String message, Object binding1, Object binding2) { - return bind(message, new Object[] {binding1, binding2}); - } - - /** - * Bind the given message's substitution locations with the given string values. - * - * @param message the message to be manipulated - * @param bindings An array of objects to be inserted into the message - * @return the manipulated String - */ - public static String bind(String message, Object[] bindings) { - return MessageFormat.format(message, bindings); - } - -} diff --git a/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/impl/XMLSearchDocument.java b/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/impl/XMLSearchDocument.java deleted file mode 100644 index 7908adfac8..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/impl/XMLSearchDocument.java +++ /dev/null @@ -1,105 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 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.wst.xml.core.internal.search.impl; - -import java.io.IOException; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.Path; -import org.eclipse.wst.common.core.search.document.Entry; -import org.eclipse.wst.common.core.search.document.SearchDocument; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; -import org.eclipse.wst.xml.core.internal.search.XMLSearchParticipant; - -public class XMLSearchDocument extends SearchDocument { - - IDOMModel model; - Map entries = new HashMap(); // category -> set (entry) - - public XMLSearchDocument(String documentPath, XMLSearchParticipant participant) { - super(documentPath, participant); - } - - public Object getModel() { - if(model == null){ - //System.out.println("creating DOM for " + getPath()); - IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(getPath())); - if(file != null){ - try { - model = (IDOMModel)StructuredModelManager.getModelManager().getModelForEdit(file); - } catch (IOException e) { - e.printStackTrace(); - } catch (CoreException e) { - e.printStackTrace(); - } - - } - } - return model; - } - - public Entry[] getEntries(String category, String key, int matchRule) - { - // TODO use matchRule - Set results = new HashSet(); - if(category != null){ - Set values = (Set)entries.get(category); - if(values == null){ - return new Entry[0]; - } - if(key == null || "".equals(key) || "*".equals(key)){ //$NON-NLS-1$ //$NON-NLS-2$ - // entries with any key in the given category - results.addAll(values); - } - else{ - // entries with the specified key in the given category - for (Iterator iter = values.iterator(); iter.hasNext();) - { - Entry entry = (Entry) iter.next(); - if(key.equals(entry.getKey())){ - results.add(entry); - } - } - } - - } - return (Entry[]) results.toArray(new Entry[results.size()]); - } - - public void putEntry(Entry entry) - { - if(entry.getCategory() != null){ - Set values = (Set)entries.get(entry.getCategory()); - if(values == null){ - entries.put(entry.getCategory(), values=new HashSet()); - } - values.add(entry); - } - - } - - public void dispose() - { - if (model != null) - { - model.releaseFromEdit(); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/impl/messages.properties b/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/impl/messages.properties deleted file mode 100644 index 43aea953b7..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/impl/messages.properties +++ /dev/null @@ -1,10 +0,0 @@ -############################################################################### -# Copyright (c) 2005, 2006 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 -############################################################################### diff --git a/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/matching/PatternMatcher.java b/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/matching/PatternMatcher.java deleted file mode 100644 index fa518e83f5..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/matching/PatternMatcher.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 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.wst.xml.core.internal.search.matching; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.wst.common.core.search.SearchMatch; -import org.eclipse.wst.common.core.search.SearchRequestor; -import org.eclipse.wst.common.core.search.pattern.SearchPattern; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr; -import org.w3c.dom.Attr; -import org.w3c.dom.Element; - -/** - * This class contains matching implementation. - * <p> - * Subclasses of the PatternMatches should provide an implementation of the specific pattern matching. - * </p> - * <p> - * Subclasses of the PatternMatches should be set as adapters for the patterns that they match. - * </p> - * An implementation of {@link org.eclipse.wst.common.core.search.SearchParticipant#selectDocumentLocations()} will call - * { @link PatternMatcher#matches() } on the adapter on pattern matcher. - * - * An implementation of {@link org.eclipse.wst.common.core.search.SearchParticipant#locateMatches()} will call - * { @link PatternMatcher#locateMatches() } on the adapter on pattern matcher. - * - */ -public abstract class PatternMatcher { - - - /** - * This method does dive actual match location to the requestor if there are matches - */ - public abstract void locateMatches(SearchPattern pattern, IFile file, Element element, SearchRequestor requestor); - - /** - * This method only answers if the pattern matches element, it does not give actual match location - */ - public abstract boolean matches(SearchPattern pattern, Object element); - - protected SearchMatch createSearchMatch(IFile file, Attr attributeNode) - { - int start = 0; - int length = 0; - if(attributeNode instanceof IDOMAttr){ - IDOMAttr domAttr = (IDOMAttr)attributeNode; - start = domAttr.getValueRegionStartOffset(); - length = domAttr.getValueRegionText().length(); - } - SearchMatch match = new SearchMatch(attributeNode, start, length, file); - return match; - } - - protected void addMatch(SearchPattern pattern, IFile file, Attr attributeNode, SearchRequestor requestor) { - //System.out.println("addMatch " + pattern + " " + attributeNode.getName() + "=" + attributeNode.getValue()); - if (attributeNode != null) { - SearchMatch match = createSearchMatch(file, attributeNode); - if(requestor != null){ - try { - requestor.acceptSearchMatch(match); - } catch (CoreException e) { - //do nothing - } - } - } - } - - -} diff --git a/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/matching/SAXSearchElement.java b/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/matching/SAXSearchElement.java deleted file mode 100644 index a9ec4a10a6..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/matching/SAXSearchElement.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 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.wst.xml.core.internal.search.matching; - -import java.util.HashMap; -import java.util.Map; -import org.xml.sax.Attributes; - -public class SAXSearchElement{ - Attributes attributes; - String elementName; - String elementNamespace; - Map namespaceMap = new HashMap(); // Map of string prefix keys and namespace - String targetNamespace = ""; //$NON-NLS-1$ - String parentName; - int depth = -1; - - public SAXSearchElement() { - super(); - } - public Attributes getAttributes() { - return attributes; - } - public String getElementName() { - return elementName; - } - public String getElementNamespace() { - return elementNamespace; - } - public Map getNamespaceMap() { - return namespaceMap; - } - public String getTargetNamespace() { - return targetNamespace; - } - public void setAttributes(Attributes attributes) { - this.attributes = attributes; - } - public void setElementName(String elementName) { - this.elementName = elementName; - } - public void setElementNamespace(String elementNamespace) { - this.elementNamespace = elementNamespace; - } - public void setNamespaceMap(Map namespaceMap) { - this.namespaceMap = namespaceMap; - } - public void setTargetNamespace(String targetNamespace) { - this.targetNamespace = targetNamespace; - } - public int getDepth() - { - return depth; - } - public void setDepth(int depth) - { - this.depth = depth; - } -public String getParentName() { - return parentName; -} -public void setParentName(String parentName) { - this.parentName = parentName; -} - - - - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/matching/XMLSearchPatternMatcher.java b/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/matching/XMLSearchPatternMatcher.java deleted file mode 100644 index 0b9c3d307a..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/matching/XMLSearchPatternMatcher.java +++ /dev/null @@ -1,217 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 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.wst.xml.core.internal.search.matching; - -import org.eclipse.core.resources.IFile; -import org.eclipse.wst.common.core.search.SearchMatch; -import org.eclipse.wst.common.core.search.SearchRequestor; -import org.eclipse.wst.common.core.search.pattern.QualifiedName; -import org.eclipse.wst.common.core.search.pattern.SearchPattern; -import org.eclipse.wst.xml.core.internal.search.XMLComponentSearchPattern; -import org.eclipse.wst.xml.core.internal.search.XMLSearchPattern; -import org.w3c.dom.Attr; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - - -public class XMLSearchPatternMatcher extends PatternMatcher{ - - - protected String computeNamespaceForPrefix(Element element, String prefix) - { - String result = null; - for (Node node = element; node != null; node = node.getParentNode()) - { - if (node.getNodeType() == Node.ELEMENT_NODE) - { - Element e = (Element)node; - String attributeName = (prefix != null && prefix.length() > 0) ? ("xmlns:" + prefix) : "xmlns"; //$NON-NLS-1$ //$NON-NLS-2$ - result = e.getAttribute(attributeName); - if (result != null) - { - break; - } - } - } - return result; - } - - - protected void initialize(XMLSearchPattern pattern, Element domElement) { - - pattern.setElementName(domElement.getLocalName()); - pattern.setElementNamespace(domElement.getNamespaceURI()); - // TODO (cs) set the depth attribute on the pattern - // - String actualValue = domElement.getAttribute(pattern.getAttributeName()); - if(actualValue != null){ - int n = actualValue.indexOf(":"); //$NON-NLS-1$ - if(n > 0){ - String prefix = actualValue.substring(0, n); - pattern.setSearchName(actualValue.substring(n+1)); - - String namespace = computeNamespaceForPrefix(domElement, prefix); - pattern.setSearchNamespace(namespace); - - } - else { - pattern.setSearchName(actualValue); - pattern.setSearchNamespace(domElement.getOwnerDocument().getDocumentElement().getAttribute("targetNamespace")); //$NON-NLS-1$ - } - } - - } - - protected void initialize(XMLSearchPattern pattern, SAXSearchElement saxElement) { - - pattern.setElementName(saxElement.getElementName()); - pattern.setElementNamespace(saxElement.getElementNamespace()); - pattern.setDepth(saxElement.getDepth()); - pattern.setParentName(saxElement.getParentName()); - String actualValue = saxElement.getAttributes().getValue(pattern.getAttributeName()); - if(actualValue != null){ - int n = actualValue.indexOf(":"); //$NON-NLS-1$ - if(n > 0){ - String prefix = actualValue.substring(0, n); - pattern.setSearchName(actualValue.substring(n+1)); - pattern.setSearchNamespace((String)saxElement.getNamespaceMap().get(prefix)); - - } - else { - pattern.setSearchName(actualValue); - pattern.setSearchNamespace(saxElement.getTargetNamespace()); - } - } - - } - - XMLSearchPattern searchPattern; - - public XMLSearchPatternMatcher() { - super(); - - } - - - - - /** - * This method does dive actual match location to the requestor if there are matches - */ - - public void locateMatches(SearchPattern pattern, IFile file, Element element, SearchRequestor requestor) { - if(pattern instanceof XMLComponentSearchPattern){ - XMLSearchPattern[] childPatterns = ((XMLComponentSearchPattern)pattern).getChildren(); - for (int i = 0; i < childPatterns.length; i++) { - PatternMatcher matcher = (PatternMatcher)childPatterns[i].getAdapter(PatternMatcher.class); - if(matcher == null){ - matcher = this; - } - if(matcher != null){ - matcher.locateMatches(childPatterns[i], file, element, requestor); - } - } - } - else if(pattern instanceof XMLSearchPattern){ - if(matches(pattern, element)){ - Attr attribute = element.getAttributeNode(((XMLSearchPattern)pattern).getAttributeName()); - addMatch(pattern, file, attribute, requestor); - } - - } - } - - /** - * This method only answers if the pattern matches element, it does not give actual match location - */ - public boolean matches(SearchPattern pattern, Object element){ - if(pattern instanceof XMLComponentSearchPattern){ - XMLSearchPattern[] childPatterns = ((XMLComponentSearchPattern)pattern).getChildren(); - for (int i = 0; i < childPatterns.length; i++) { - PatternMatcher matcher = (PatternMatcher)childPatterns[i].getAdapter(PatternMatcher.class); - if(matcher == null){ - matcher = this; - } - if(matcher != null){ - if(matcher.matches(childPatterns[i], element)){ - return true; - } - } - - } - } - else if(pattern instanceof XMLSearchPattern){ - - XMLSearchPattern possibleMatch = new XMLSearchPattern(); - possibleMatch.setAttributeName(((XMLSearchPattern)pattern).getAttributeName()); - if(element instanceof Element){ - initialize(possibleMatch, (Element)element); - } - else if(element instanceof SAXSearchElement){ - initialize(possibleMatch, (SAXSearchElement)element); - } - searchPattern = (XMLSearchPattern)pattern; - return matchesPattern(possibleMatch); - } - return false; - } - - protected boolean matchesPattern(SearchPattern pattern) { - if(searchPattern != null && pattern instanceof XMLSearchPattern){ - XMLSearchPattern decodedPattern = (XMLSearchPattern)pattern; - if(searchPattern.getElementName().equals(decodedPattern.getElementName()) && - searchPattern.getElementNamespace().equals(decodedPattern.getElementNamespace())){ - if(searchPattern.getParentName() != null && - decodedPattern.getParentName() != null && - !searchPattern.getParentName().equals(decodedPattern.getParentName())) - { - return false; - } - if(searchPattern.getSearchName() == null) - { - return false; - } - else if ("*".equals(searchPattern.getSearchName())) //$NON-NLS-1$ - { - return true; - } - else if(searchPattern.getSearchNamespace() == null){ - return searchPattern.getSearchName().equals(decodedPattern.getSearchName()); - } - else{ - return searchPattern.getSearchName().equals(decodedPattern.getSearchName()) && - searchPattern.getSearchNamespace().equals(decodedPattern.getSearchNamespace()); - } - } - } - - return false; - } - - - protected SearchMatch createSearchMatch(IFile file, Attr attributeNode) - { - SearchMatch match = super.createSearchMatch(file, attributeNode); - // todo... remove this ugly hack!! - if ("name".equals(attributeNode.getName())) //$NON-NLS-1$ - { - QualifiedName qualifiedName = new QualifiedName("todo-compute-targetNamespace", attributeNode.getValue()); //$NON-NLS-1$ - match.map.put("name", qualifiedName); //$NON-NLS-1$ - } - //Element element = attributeNode.getOwnerDocument().getDocumentElement(); - //if (element.getAttribute("targetNamespace")) - //{ - //} - return match; - } - -} diff --git a/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/quickscan/XMLQuickScan.java b/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/quickscan/XMLQuickScan.java deleted file mode 100644 index bf8a14cd89..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/quickscan/XMLQuickScan.java +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2006 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.wst.xml.core.internal.search.quickscan; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; -import org.eclipse.wst.common.core.search.document.SearchDocument; -import org.eclipse.wst.common.core.search.pattern.SearchPattern; -import org.eclipse.wst.xml.core.internal.search.matching.PatternMatcher; -import org.xml.sax.ErrorHandler; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; -import org.xml.sax.XMLReader; - -/** - * - */ -public class XMLQuickScan -{ - /* - public static String getTargetNamespace(String fullFilePath) - { - XMLQuickScanContentHandler handler = new XMLQuickScanContentHandler(); - parseFile(fullFilePath, handler); - return handler.getTargetNamespace(); - }*/ - - /* - * Returns information about matches encountered based on the criteria - * provided. - * - public static boolean hasMatch(String fullFilePath, PatternMatcher matcher, SearchPattern pattern) - { - XMLQuickScanContentHandler handler = new XMLQuickScanContentHandler(matcher, pattern); - parseFile(fullFilePath, handler); - return handler.hasMatch(); - }*/ - - public static boolean populateSearchDocument(SearchDocument document, PatternMatcher matcher, SearchPattern pattern) - { - XMLQuickScanContentHandler handler = new XMLQuickScanContentHandler(document, matcher, pattern); - parseFile(document.getPath(), handler); - return handler.hasMatch(); - } - - private static XMLReader reader; - private static XMLReader getOrCreateReader() - { - if (reader == null) - { - try - { - SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); - reader = parser.getXMLReader(); - reader.setFeature("http://xml.org/sax/features/namespaces", true); //$NON-NLS-1$ - reader.setErrorHandler(new InternalErrorHandler()); - } - catch (Exception e) - { - } - } - return reader; - } - - static class InternalErrorHandler implements ErrorHandler - { - public void error(SAXParseException exception) throws SAXException - { - } - - public void fatalError(SAXParseException exception) throws SAXException - { - } - public void warning(SAXParseException exception) throws SAXException - { - } - } - - private synchronized static void parseFile(String fullFilePath, - XMLQuickScanContentHandler handler) - { - FileInputStream inputStream = null; - try - { - inputStream = new FileInputStream(new File(fullFilePath)); - XMLReader reader = getOrCreateReader(); - reader.setContentHandler(handler); - //System.out.println("parseFile" + reader + " (" + fullFilePath + ")"); - reader.parse(new InputSource(inputStream)); - } catch (Exception e) - { - // skip the file - } - finally{ - if(inputStream != null){ - try { - inputStream.close(); - } catch (IOException e) { - // can not do much - } - } - - } - } -} diff --git a/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/quickscan/XMLQuickScanContentHandler.java b/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/quickscan/XMLQuickScanContentHandler.java deleted file mode 100644 index 65d87cdc76..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src-search/org/eclipse/wst/xml/core/internal/search/quickscan/XMLQuickScanContentHandler.java +++ /dev/null @@ -1,212 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 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.wst.xml.core.internal.search.quickscan; - -import java.util.HashMap; -import java.util.Map; -import java.util.Stack; - -import org.eclipse.wst.common.core.search.document.ComponentDeclarationEntry; -import org.eclipse.wst.common.core.search.document.ComponentReferenceEntry; -import org.eclipse.wst.common.core.search.document.FileReferenceEntry; -import org.eclipse.wst.common.core.search.document.SearchDocument; -import org.eclipse.wst.common.core.search.pattern.QualifiedName; -import org.eclipse.wst.common.core.search.pattern.SearchPattern; -import org.eclipse.wst.xml.core.internal.search.XMLComponentDeclarationPattern; -import org.eclipse.wst.xml.core.internal.search.XMLComponentReferencePattern; -import org.eclipse.wst.xml.core.internal.search.impl.IXMLSearchConstants; -import org.eclipse.wst.xml.core.internal.search.matching.PatternMatcher; -import org.eclipse.wst.xml.core.internal.search.matching.SAXSearchElement; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.DefaultHandler; - -/** - * This class is a SAX content handler, it should be recycled before scanning a file for the new SearchPattern. - * - */ -public class XMLQuickScanContentHandler extends DefaultHandler -{ - private Map namespaceMap = new HashMap(); // Map of string prefix keys and namespace - private String targetNamespace = ""; //$NON-NLS-1$ - - private SearchPattern pattern; - private SearchDocument document; // we'll add useful entries in the search document as we parsing - private SAXSearchElement searchElement = new SAXSearchElement(); - - private boolean hasMatch = false; - private Stack currentPath = new Stack(); - private PatternMatcher matcher; - - public static final String XMLSCHEMA_NAMESPACE = "http://www.w3.org/2001/XMLSchema"; //$NON-NLS-1$ - public static final String WSDL_NAMESPACE = "http://schemas.xmlsoap.org/wsdl/"; //$NON-NLS-1$ - - - public XMLQuickScanContentHandler(PatternMatcher matcher, SearchPattern pattern) { - super(); - this.pattern = pattern; - this.matcher = matcher; - } - - public XMLQuickScanContentHandler(SearchDocument document, PatternMatcher matcher, SearchPattern pattern) { - super(); - this.pattern = pattern; - this.matcher = matcher; - this.document = document; - } - - public XMLQuickScanContentHandler() { - super(); - } - - public void startElement(String uri, String localName, String qName, - Attributes attributes) throws SAXException - { - // Search for targetNamespace if we haven't encountered it yet. - if (targetNamespace.equals("")) //$NON-NLS-1$ - { - int nAttributes = attributes.getLength(); - for (int i = 0; i < nAttributes; i++) - { - if ("targetNamespace".equals(attributes.getQName(i))) //$NON-NLS-1$ - { - targetNamespace = attributes.getValue(i); - break; - } - } - } - - // collect link info - - // TODO This code should be refactored to delegate the responsibility to - // detect links between files to the search providers/contributors. - // The current code only handles the XSD and WSDL cases. - - if("import".equals(localName) && namespaceMatches(uri)){ //$NON-NLS-1$ - FileReferenceEntry documentEntry = new FileReferenceEntry(); - documentEntry.setCategory(IXMLSearchConstants.REF); - documentEntry.setKey("import"); //$NON-NLS-1$ - String namespace = attributes.getValue("namespace"); //$NON-NLS-1$ - String location = attributes.getValue(getLocationAttributeName(uri)); //$NON-NLS-1$ - documentEntry.setPublicIdentifier(namespace); - documentEntry.setRelativeFilePath(location); - document.putEntry(documentEntry); - } - if(("redefine".equals(localName)|| "include".equals(localName)) && //$NON-NLS-1$ //$NON-NLS-2$ - namespaceMatches(uri)){ - FileReferenceEntry documentEntry = new FileReferenceEntry(); - documentEntry.setCategory(IXMLSearchConstants.REF); - documentEntry.setKey("include"); //$NON-NLS-1$ - String location = attributes.getValue(getLocationAttributeName(uri)); //$NON-NLS-1$ - documentEntry.setPublicIdentifier(uri); - documentEntry.setRelativeFilePath(location); - document.putEntry(documentEntry); - } - - - // issue (cs) you may want to try perf measurements to compate reusing the same - // instance of a SAXSearchElement instead of newing one each time - //XMLSearchPattern.SAXSearchElement searchElement = new XMLSearchPattern.SAXSearchElement(); - searchElement.setElementName(localName); - searchElement.setElementNamespace(uri); - searchElement.setAttributes(attributes); - searchElement.setNamespaceMap(namespaceMap); - searchElement.setTargetNamespace(targetNamespace); - if (currentPath.size() > 0) - { - String parentName = (String)currentPath.peek(); - searchElement.setParentName(parentName); - } - - - if(matcher != null){ - if(matcher.matches(pattern, searchElement)){ - hasMatch = true; - if(pattern instanceof XMLComponentReferencePattern){ - ComponentReferenceEntry documentEntry = new ComponentReferenceEntry(); - documentEntry.setCategory(IXMLSearchConstants.COMPONENT_REF); - QualifiedName name = new QualifiedName(uri, localName); - documentEntry.setKey(name.toString()); - documentEntry.setName(name); - document.putEntry(documentEntry); - } - else if(pattern instanceof XMLComponentDeclarationPattern){ - ComponentDeclarationEntry documentEntry = new ComponentDeclarationEntry(); - documentEntry.setCategory(IXMLSearchConstants.COMPONENT_DECL); - QualifiedName name = new QualifiedName(targetNamespace, attributes.getValue("name")); //$NON-NLS-1$ - QualifiedName metaName = new QualifiedName(uri, localName); - documentEntry.setKey(name.toString()); - documentEntry.setName(name); - documentEntry.setMetaName(metaName); - document.putEntry(documentEntry); - } - } - } - currentPath.push(localName); //$NON-NLS-1$ - } - - private String getLocationAttributeName(String uri) - { - if (XMLSCHEMA_NAMESPACE.equals(uri)) - { - return "schemaLocation"; - } - - else if (WSDL_NAMESPACE.equals(uri)) - { - return "location"; - } - - return ""; - } - - private boolean namespaceMatches(String uri) - { - return XMLSCHEMA_NAMESPACE.equals(uri) || - WSDL_NAMESPACE.equals(uri); - } - - public void endElement(String uri, String localName, String qName) - throws SAXException - { - currentPath.pop(); - } - - /** - * Callback for SAX parser - * - * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String, - * java.lang.String) - */ - public void startPrefixMapping(String arg0, String arg1) - throws SAXException - { - if (arg0 != null && arg0.length() > 0) - { - this.namespaceMap.put(arg0, arg1); - } - } - - public String getTargetNamespace() { - return targetNamespace; - } - - public void setTargetNamespace(String targetNamespace) { - this.targetNamespace = targetNamespace; - } - - public boolean hasMatch() { - return hasMatch; - } - - -}
\ No newline at end of file |