Search in sources :

Example 11 with XmlNSDescriptorImpl

use of com.intellij.xml.impl.schema.XmlNSDescriptorImpl in project intellij-community by JetBrains.

the class CreateNSDeclarationIntentionFix method processExternalUrisImpl.

private static void processExternalUrisImpl(final MetaHandler metaHandler, final PsiFile file, final ExternalUriProcessor processor) {
    final ProgressIndicator pi = ProgressManager.getInstance().getProgressIndicator();
    final String searchFor = metaHandler.searchFor();
    if (pi != null)
        pi.setText(XmlErrorMessages.message("looking.in.schemas"));
    final ExternalResourceManager instanceEx = ExternalResourceManager.getInstance();
    final String[] availableUrls = instanceEx.getResourceUrls(null, true);
    int i = 0;
    for (String url : availableUrls) {
        if (pi != null) {
            pi.setFraction((double) i / availableUrls.length);
            pi.setText2(url);
            ++i;
        }
        final XmlFile xmlFile = XmlUtil.findNamespace(file, url);
        if (xmlFile != null) {
            final boolean wordFound = checkIfGivenXmlHasTheseWords(searchFor, xmlFile);
            if (!wordFound)
                continue;
            final XmlDocument document = xmlFile.getDocument();
            assert document != null;
            final PsiMetaData metaData = document.getMetaData();
            if (metaHandler.isAcceptableMetaData(metaData, url)) {
                final XmlNSDescriptorImpl descriptor = metaData instanceof XmlNSDescriptorImpl ? (XmlNSDescriptorImpl) metaData : null;
                final String defaultNamespace = descriptor != null ? descriptor.getDefaultNamespace() : url;
                // Skip rare stuff
                if (!XmlUtil.XML_SCHEMA_URI2.equals(defaultNamespace) && !XmlUtil.XML_SCHEMA_URI3.equals(defaultNamespace)) {
                    processor.process(defaultNamespace, url);
                }
            }
        }
    }
}
Also used : ExternalResourceManager(com.intellij.javaee.ExternalResourceManager) PsiMetaData(com.intellij.psi.meta.PsiMetaData) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) XmlNSDescriptorImpl(com.intellij.xml.impl.schema.XmlNSDescriptorImpl)

Example 12 with XmlNSDescriptorImpl

use of com.intellij.xml.impl.schema.XmlNSDescriptorImpl in project intellij-community by JetBrains.

the class HtmlElementDescriptorImpl method getAttributeDescriptor.

@Override
public XmlAttributeDescriptor getAttributeDescriptor(String attributeName, final XmlTag context) {
    String caseSensitiveAttributeName = !myCaseSensitive ? attributeName.toLowerCase() : attributeName;
    XmlAttributeDescriptor descriptor = super.getAttributeDescriptor(caseSensitiveAttributeName, context);
    if (descriptor == null)
        descriptor = RelaxedHtmlFromSchemaElementDescriptor.getAttributeDescriptorFromFacelets(attributeName, context);
    if (descriptor == null) {
        String prefix = XmlUtil.findPrefixByQualifiedName(attributeName);
        if ("xml".equals(prefix)) {
            // todo this is not technically correct dtd document references namespaces but we should handle it at least for xml stuff
            XmlNSDescriptor nsdescriptor = context.getNSDescriptor(XmlUtil.XML_NAMESPACE_URI, true);
            if (nsdescriptor instanceof XmlNSDescriptorImpl) {
                descriptor = ((XmlNSDescriptorImpl) nsdescriptor).getAttribute(XmlUtil.findLocalNameByQualifiedName(caseSensitiveAttributeName), XmlUtil.XML_NAMESPACE_URI, context);
            }
        }
    }
    if (descriptor == null && HtmlUtil.isHtml5Context(context)) {
        descriptor = myDelegate.getAttributeDescriptor(attributeName, context);
    }
    return descriptor;
}
Also used : XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) XmlNSDescriptorImpl(com.intellij.xml.impl.schema.XmlNSDescriptorImpl)

Aggregations

XmlNSDescriptorImpl (com.intellij.xml.impl.schema.XmlNSDescriptorImpl)12 XmlTag (com.intellij.psi.xml.XmlTag)5 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)5 XmlFile (com.intellij.psi.xml.XmlFile)4 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)4 PsiFile (com.intellij.psi.PsiFile)3 XmlDocument (com.intellij.psi.xml.XmlDocument)3 Nullable (org.jetbrains.annotations.Nullable)3 PsiMetaData (com.intellij.psi.meta.PsiMetaData)2 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)2 ExternalResourceManager (com.intellij.javaee.ExternalResourceManager)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiElement (com.intellij.psi.PsiElement)1 XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 ComplexTypeDescriptor (com.intellij.xml.impl.schema.ComplexTypeDescriptor)1 TypeDescriptor (com.intellij.xml.impl.schema.TypeDescriptor)1 THashSet (gnu.trove.THashSet)1 MalformedURLException (java.net.MalformedURLException)1