Search in sources :

Example 1 with FileReferenceEntry

use of org.eclipse.wst.common.core.search.document.FileReferenceEntry in project webtools.sourceediting by eclipse.

the class XMLSearchParticipant method isLinked.

private boolean isLinked(SearchDocumentSet set, String source, String target, HashMap visited) {
    if (source.equals(target))
        return true;
    // $NON-NLS-1$
    String fileProtocol = "file:///";
    // Fix for bug 204174 - Begin
    if (// $NON-NLS-1$
    target.charAt(fileProtocol.length()) == '/') {
        target = fileProtocol + target.substring(fileProtocol.length() + 1);
    }
    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;
                    // 
                    if (fileReferenceEntry.getRelativeFilePath() != null) {
                        String resolvedURI = uriResolver.resolve(source, null, fileReferenceEntry.getRelativeFilePath());
                        resolveEntry[j] = resolvedURI;
                        if (resolvedURI.equals(target)) {
                            return true;
                        }
                    }
                }
            }
            // 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;
}
Also used : Entry(org.eclipse.wst.common.core.search.document.Entry) ComponentDeclarationEntry(org.eclipse.wst.common.core.search.document.ComponentDeclarationEntry) FileReferenceEntry(org.eclipse.wst.common.core.search.document.FileReferenceEntry) FileReferenceEntry(org.eclipse.wst.common.core.search.document.FileReferenceEntry) URIResolver(org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver) XMLSearchDocument(org.eclipse.wst.xml.core.internal.search.impl.XMLSearchDocument) SearchDocument(org.eclipse.wst.common.core.search.document.SearchDocument)

Example 2 with FileReferenceEntry

use of org.eclipse.wst.common.core.search.document.FileReferenceEntry 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);
}
Also used : FileReferenceEntry(org.eclipse.wst.common.core.search.document.FileReferenceEntry) XMLComponentReferencePattern(org.eclipse.wst.xml.core.internal.search.XMLComponentReferencePattern) QualifiedName(org.eclipse.wst.common.core.search.pattern.QualifiedName) ComponentReferenceEntry(org.eclipse.wst.common.core.search.document.ComponentReferenceEntry) XMLComponentDeclarationPattern(org.eclipse.wst.xml.core.internal.search.XMLComponentDeclarationPattern) ComponentDeclarationEntry(org.eclipse.wst.common.core.search.document.ComponentDeclarationEntry)

Aggregations

ComponentDeclarationEntry (org.eclipse.wst.common.core.search.document.ComponentDeclarationEntry)2 FileReferenceEntry (org.eclipse.wst.common.core.search.document.FileReferenceEntry)2 ComponentReferenceEntry (org.eclipse.wst.common.core.search.document.ComponentReferenceEntry)1 Entry (org.eclipse.wst.common.core.search.document.Entry)1 SearchDocument (org.eclipse.wst.common.core.search.document.SearchDocument)1 QualifiedName (org.eclipse.wst.common.core.search.pattern.QualifiedName)1 URIResolver (org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver)1 XMLComponentDeclarationPattern (org.eclipse.wst.xml.core.internal.search.XMLComponentDeclarationPattern)1 XMLComponentReferencePattern (org.eclipse.wst.xml.core.internal.search.XMLComponentReferencePattern)1 XMLSearchDocument (org.eclipse.wst.xml.core.internal.search.impl.XMLSearchDocument)1