use of org.eclipse.wst.common.core.search.document.ComponentDeclarationEntry in project webtools.sourceediting by eclipse.
the class XMLSearchParticipant method locateMatches.
private void locateMatches(SearchPattern pattern, SearchDocument document, SearchRequestor requestor, Map searchOptions, IProgressMonitor monitor) {
//
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);
// $NON-NLS-1$
searchMatch.map.put("name", entry.getName());
// $NON-NLS-1$
searchMatch.map.put("metaName", entry.getMetaName());
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);
}
}
}
use of org.eclipse.wst.common.core.search.document.ComponentDeclarationEntry in project webtools.sourceediting by eclipse.
the class XMLQuickScanContentHandler method startElement.
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
// Search for targetNamespace if we haven't encountered it yet.
if (// $NON-NLS-1$
targetNamespace.equals("")) {
int nAttributes = attributes.getLength();
for (int i = 0; i < nAttributes; i++) {
if (// $NON-NLS-1$
"targetNamespace".equals(attributes.getQName(i))) {
targetNamespace = attributes.getValue(i);
break;
}
}
}
if ("import".equals(localName) && namespaceMatches(uri)) {
// $NON-NLS-1$
FileReferenceEntry documentEntry = new FileReferenceEntry();
documentEntry.setCategory(IXMLSearchConstants.REF);
// $NON-NLS-1$
documentEntry.setKey("import");
// $NON-NLS-1$
String namespace = attributes.getValue("namespace");
// $NON-NLS-1$
String location = attributes.getValue(getLocationAttributeName(uri));
documentEntry.setPublicIdentifier(namespace);
documentEntry.setRelativeFilePath(location);
document.putEntry(documentEntry);
}
if (// $NON-NLS-1$ //$NON-NLS-2$
("redefine".equals(localName) || "include".equals(localName)) && namespaceMatches(uri)) {
FileReferenceEntry documentEntry = new FileReferenceEntry();
documentEntry.setCategory(IXMLSearchConstants.REF);
// $NON-NLS-1$
documentEntry.setKey("include");
// $NON-NLS-1$
String location = attributes.getValue(getLocationAttributeName(uri));
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);
// $NON-NLS-1$
QualifiedName name = new QualifiedName(targetNamespace, attributes.getValue("name"));
QualifiedName metaName = new QualifiedName(uri, localName);
documentEntry.setKey(name.toString());
documentEntry.setName(name);
documentEntry.setMetaName(metaName);
document.putEntry(documentEntry);
}
}
}
// $NON-NLS-1$
currentPath.push(localName);
}
Aggregations