namespace vs location
[fedora-idea.git] / xml / openapi / src / com / intellij / xml / XmlSchemaProvider.java
blobc6b6322f59132443bb705ba3f4108f8262997f3e
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.intellij.xml;
19 import com.intellij.openapi.extensions.ExtensionPointName;
20 import com.intellij.openapi.extensions.Extensions;
21 import com.intellij.openapi.module.Module;
22 import com.intellij.openapi.module.ModuleUtil;
23 import com.intellij.openapi.project.DumbAware;
24 import com.intellij.openapi.project.DumbService;
25 import com.intellij.openapi.util.Condition;
26 import com.intellij.psi.PsiDirectory;
27 import com.intellij.psi.PsiFile;
28 import com.intellij.psi.xml.XmlFile;
29 import com.intellij.util.containers.ContainerUtil;
30 import org.jetbrains.annotations.NonNls;
31 import org.jetbrains.annotations.NotNull;
32 import org.jetbrains.annotations.Nullable;
34 import java.util.Collections;
35 import java.util.List;
36 import java.util.Set;
38 /**
39 * @author Dmitry Avdeev
41 public abstract class XmlSchemaProvider {
43 public final static ExtensionPointName<XmlSchemaProvider> EP_NAME = new ExtensionPointName<XmlSchemaProvider>("com.intellij.xml.schemaProvider");
45 @Nullable
46 public static XmlFile findSchema(@NotNull @NonNls String namespace, @Nullable Module module, @NotNull PsiFile file) {
47 final boolean dumb = DumbService.getInstance(file.getProject()).isDumb();
49 for (XmlSchemaProvider provider: Extensions.getExtensions(EP_NAME)) {
50 if (dumb && !(provider instanceof DumbAware)) {
51 continue;
54 if (file instanceof XmlFile && !provider.isAvailable((XmlFile)file)) {
55 continue;
57 final XmlFile schema = provider.getSchema(namespace, module, file);
58 if (schema != null) {
59 return schema;
62 return null;
65 @Nullable
66 public static XmlFile findSchema(@NotNull @NonNls String namespace, @NotNull PsiFile baseFile) {
67 final PsiDirectory directory = baseFile.getParent();
68 final Module module = ModuleUtil.findModuleForPsiElement(directory == null ? baseFile : directory);
69 return findSchema(namespace, module, baseFile);
72 /**
73 * @see #getAvailableProviders(com.intellij.psi.xml.XmlFile)
75 @Deprecated
76 @Nullable
77 public static XmlSchemaProvider getAvailableProvider(final @NotNull XmlFile file) {
78 for (XmlSchemaProvider provider: Extensions.getExtensions(EP_NAME)) {
79 if (provider.isAvailable(file)) {
80 return provider;
83 return null;
86 public static List<XmlSchemaProvider> getAvailableProviders(final @NotNull XmlFile file) {
87 return ContainerUtil.findAll(Extensions.getExtensions(EP_NAME), new Condition<XmlSchemaProvider>() {
88 public boolean value(XmlSchemaProvider xmlSchemaProvider) {
89 return xmlSchemaProvider.isAvailable(file);
91 });
94 @Nullable
95 public abstract XmlFile getSchema(@NotNull @NonNls String url, @Nullable Module module, @NotNull final PsiFile baseFile);
98 public boolean isAvailable(final @NotNull XmlFile file) {
99 return false;
103 * Provides specific namespaces for given xml file.
104 * @param file an xml or jsp file.
105 * @param tagName optional
106 * @return available namespace uris, or <code>null</code> if the provider did not recognize the file.
108 @NotNull
109 public Set<String> getAvailableNamespaces(final @NotNull XmlFile file, final @Nullable String tagName) {
110 return Collections.emptySet();
113 @Nullable
114 public String getDefaultPrefix(@NotNull @NonNls String namespace, @NotNull final XmlFile context) {
115 return null;
118 @Nullable
119 public Set<String> getLocations(@NotNull @NonNls String namespace, @NotNull final XmlFile context) {
120 return null;