use of com.intellij.xml.impl.schema.XmlNSDescriptorImpl in project intellij-community by JetBrains.
the class MavenDomElementDescriptorHolder method doCreateDescriptor.
@Nullable
private XmlNSDescriptorImpl doCreateDescriptor(FileKind kind) {
String schemaUrl = kind.getSchemaUrl();
String location = ExternalResourceManager.getInstance().getResourceLocation(schemaUrl);
if (schemaUrl.equals(location))
return null;
VirtualFile schema;
try {
schema = VfsUtil.findFileByURL(new URL(location));
} catch (MalformedURLException ignore) {
return null;
}
if (schema == null)
return null;
PsiFile psiFile = PsiManager.getInstance(myProject).findFile(schema);
if (!(psiFile instanceof XmlFile))
return null;
XmlNSDescriptorImpl result = new XmlNSDescriptorImpl();
result.init(psiFile);
return result;
}
use of com.intellij.xml.impl.schema.XmlNSDescriptorImpl in project intellij-community by JetBrains.
the class XsltContextProviderBase method fillFromSchema.
private static void fillFromSchema(PsiFile file, ElementNames names) {
if (!(file instanceof XmlFile))
return;
final XmlFile f = (XmlFile) file;
final XmlDocument d = f.getDocument();
if (d == null)
return;
final XmlTag rootTag = d.getRootTag();
if (rootTag == null)
return;
//noinspection unchecked
names.dependencies.add(new NSDeclTracker(rootTag));
try {
final Map<String, String> namespaceDeclarations = rootTag.getLocalNamespaceDeclarations();
final Collection<String> prefixes = namespaceDeclarations.keySet();
final XmlElementFactory ef = XmlElementFactory.getInstance(file.getProject());
int noSchemaNamespaces = 0;
for (String prefix : prefixes) {
final String namespace = namespaceDeclarations.get(prefix);
if (isIgnoredNamespace(prefix, namespace))
continue;
final XmlTag tag = ef.createTagFromText("<dummy-tag xmlns='" + namespace + "' />", XMLLanguage.INSTANCE);
final XmlDocument document = PsiTreeUtil.getParentOfType(tag, XmlDocument.class);
final XmlNSDescriptor rootDescriptor = tag.getNSDescriptor(tag.getNamespace(), true);
if (rootDescriptor == null || (rootDescriptor instanceof XmlNSDescriptorImpl && ((XmlNSDescriptorImpl) rootDescriptor).getTag() == null) || !rootDescriptor.getDeclaration().isPhysical()) {
final QName any = QNameUtil.createAnyLocalName(namespace);
names.elementNames.add(any);
names.attributeNames.add(any);
noSchemaNamespaces++;
continue;
}
//noinspection unchecked
names.dependencies.add(rootDescriptor.getDescriptorFile());
//noinspection unchecked
final Set<XmlElementDescriptor> history = new THashSet<>(150);
final XmlElementDescriptor[] e = rootDescriptor.getRootElementsDescriptors(document);
try {
for (XmlElementDescriptor descriptor : e) {
processElementDescriptors(descriptor, tag, names, history, 0);
}
} catch (StopProcessingException e1) {
Logger.getInstance(XsltContextProviderBase.class).error("Maximum recursion depth reached. Missing equals()/hashCode() implementation?", StringUtil.join(history, descriptor -> descriptor.getClass().getName() + "[" + descriptor.getQualifiedName() + "]", ", "));
}
}
names.validateNames = names.elementNames.size() > noSchemaNamespaces;
// final QName any = QNameUtil.createAnyLocalName("");
// names.elementNames.add(any);
// names.attributeNames.add(any);
} catch (IncorrectOperationException e) {
Logger.getInstance(XsltContextProvider.class.getName()).error(e);
}
}
use of com.intellij.xml.impl.schema.XmlNSDescriptorImpl in project intellij-community by JetBrains.
the class XmlSchemaTest method testAny2.
//public void testAny1() throws Exception {
// XmlDocumentDescriptor documentDescriptor = createDescriptorImpl(
// "<xsd:schema targetNamespace=\"http://foo\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" >" +
// " <xsd:element name=\"root\">" +
// " <xsd:complexType>" +
// " <xsd:sequence minOccurs=\"1\" maxOccurs=\"1\">" +
// " <xsd:any namespace=\"##other\" minOccurs=\"0\" maxOccurs=\"unbounded\" processContents=\"skip\"/>" +
// " </xsd:sequence>" +
// " </xsd:complexType>" +
// " </xsd:element>" +
// "</xsd:schema>"
// );
//
// XmlFile xmlFile = (XmlFile)createFile("file.xml",
// "<root xmlns=\"http://foo\">" +
// " <a:a xmlns:a=\"http://bar\" />" +
// "</root>"
// );
//
// XmlElementDescriptor rootDescriptor = documentDescriptor.getElementDescriptor(xmlFile.saveToString().getRootTag());
// assertNotNull(rootDescriptor);
//
// XmlTag aTag = xmlFile.saveToString().getRootTag().findSubTag("a:a");
// assertNotNull(aTag);
// XmlElementDescriptor aDescriptor = documentDescriptor.getElementDescriptor(aTag);
// assertNotNull(aDescriptor);
//}
public void testAny2() throws Exception {
PsiFile dtdFile = createFile("test.xml", "<xsd:schema targetNamespace=\"http://foo\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" >" + " <xsd:element name=\"root\">" + " <xsd:complexType>" + " <xsd:sequence minOccurs=\"1\" maxOccurs=\"1\">" + " <xsd:any namespace=\"##other\" minOccurs=\"0\" maxOccurs=\"unbounded\" processContents=\"skip\"/>" + " </xsd:sequence>" + " </xsd:complexType>" + " </xsd:element>" + "</xsd:schema>");
XmlNSDescriptor NSDescriptor = new XmlNSDescriptorImpl((XmlFile) dtdFile);
XmlFile xmlFile = (XmlFile) createFile("file.xml", "<foo:root xmlns:foo=\"http://foo\">" + " <foo:a xmlns:a=\"http://bar\" />" + "</foo:root>");
XmlElementDescriptor rootDescriptor = NSDescriptor.getElementDescriptor(xmlFile.getDocument().getRootTag());
assertNotNull(rootDescriptor);
XmlTag aTag = xmlFile.getDocument().getRootTag().findFirstSubTag("foo:a");
assertNotNull(aTag);
//XmlElementDescriptor aDescriptor = NSDescriptor.getElementDescriptor(aTag);
//assertNull(aDescriptor);
}
use of com.intellij.xml.impl.schema.XmlNSDescriptorImpl in project intellij-community by JetBrains.
the class TypeOrElementOrAttributeReference method getDescriptor.
XmlNSDescriptorImpl getDescriptor(final XmlTag tag, String text, boolean[] redefined) {
if (myType != ReferenceType.ElementReference && myType != ReferenceType.AttributeReference) {
final PsiElement parentElement = myElement.getContext();
final PsiElement grandParentElement = parentElement != null ? parentElement.getParent() : null;
boolean doRedefineCheck = false;
if (parentElement instanceof XmlAttribute && grandParentElement instanceof XmlTag) {
final String attrName = ((XmlAttribute) parentElement).getName();
final String tagLocalName = ((XmlTag) grandParentElement).getLocalName();
doRedefineCheck = (SchemaReferencesProvider.REF_ATTR_NAME.equals(attrName) && (SchemaReferencesProvider.GROUP_TAG_NAME.equals(tagLocalName) || SchemaReferencesProvider.ATTRIBUTE_GROUP_TAG_NAME.equals(tagLocalName))) || (SchemaReferencesProvider.BASE_ATTR_NAME.equals(attrName) || SchemaReferencesProvider.MEMBER_TYPES_ATTR_NAME.equals(attrName));
}
if (doRedefineCheck) {
XmlNSDescriptorImpl redefinedDescriptor = SchemaReferencesProvider.findRedefinedDescriptor(tag, text);
if (redefinedDescriptor != null) {
redefined[0] = true;
return redefinedDescriptor;
}
}
}
final String namespace = getNamespace(tag, text);
XmlNSDescriptor nsDescriptor = tag.getNSDescriptor(namespace, true);
final PsiFile file = tag.getContainingFile();
if (!(file instanceof XmlFile))
return null;
final XmlDocument document = ((XmlFile) file).getDocument();
if (nsDescriptor == null) {
// import
nsDescriptor = (XmlNSDescriptor) document.getMetaData();
}
if (nsDescriptor == null) {
final XmlNSDescriptor[] descrs = new XmlNSDescriptor[1];
URLReference.processWsdlSchemas(document.getRootTag(), xmlTag -> {
if (namespace.equals(xmlTag.getAttributeValue(TARGET_NAMESPACE))) {
descrs[0] = (XmlNSDescriptor) xmlTag.getMetaData();
return false;
}
return true;
});
if (descrs[0] instanceof XmlNSDescriptorImpl)
return (XmlNSDescriptorImpl) descrs[0];
}
return nsDescriptor instanceof XmlNSDescriptorImpl ? (XmlNSDescriptorImpl) nsDescriptor : null;
}
use of com.intellij.xml.impl.schema.XmlNSDescriptorImpl in project intellij-community by JetBrains.
the class XmlUtil method findXmlDescriptorByType.
@Nullable
public static XmlElementDescriptor findXmlDescriptorByType(final XmlTag xmlTag, @Nullable XmlTag context) {
String type = xmlTag.getAttributeValue("type", XML_SCHEMA_INSTANCE_URI);
if (type == null) {
String ns = xmlTag.getNamespace();
if (ourSchemaUrisList.indexOf(ns) >= 0) {
type = xmlTag.getAttributeValue("type", null);
}
}
XmlElementDescriptor elementDescriptor = null;
if (type != null) {
final String namespaceByPrefix = findNamespaceByPrefix(findPrefixByQualifiedName(type), xmlTag);
XmlNSDescriptor typeDecr = xmlTag.getNSDescriptor(namespaceByPrefix, true);
if (typeDecr == null && namespaceByPrefix.isEmpty()) {
if (context != null)
typeDecr = context.getNSDescriptor("", true);
if (typeDecr == null) {
final PsiFile containingFile = xmlTag.getContainingFile();
if (containingFile instanceof XmlFile) {
final XmlDocument document = ((XmlFile) containingFile).getDocument();
if (document != null)
typeDecr = (XmlNSDescriptor) document.getMetaData();
}
}
}
if (typeDecr instanceof XmlNSDescriptorImpl) {
final XmlNSDescriptorImpl schemaDescriptor = (XmlNSDescriptorImpl) typeDecr;
elementDescriptor = schemaDescriptor.getDescriptorByType(type, xmlTag);
}
}
return elementDescriptor;
}
Aggregations