private static void processElementDescriptors( XmlElementDescriptor descriptor, XmlTag tag, ElementNames names, Set<XmlElementDescriptor> history) { if (!history.add(descriptor)) { return; } final String namespace = descriptor instanceof XmlElementDescriptorImpl ? ((XmlElementDescriptorImpl) descriptor).getNamespace() : tag.getNamespace(); names.elementNames.add(new QName(namespace, descriptor.getName())); final XmlAttributeDescriptor[] attributesDescriptors = descriptor.getAttributesDescriptors(null); for (XmlAttributeDescriptor attributesDescriptor : attributesDescriptors) { final String localPart = attributesDescriptor.getName(); if (!"xmlns".equals(localPart)) names.attributeNames.add(new QName(localPart)); } final XmlElementDescriptor[] descriptors = descriptor.getElementsDescriptors(tag); for (XmlElementDescriptor elem : descriptors) { processElementDescriptors(elem, tag, names, history); } }
private static HighlightInfoType getTagProblemInfoType(XmlTag tag) { if (tag instanceof HtmlTag && XmlUtil.HTML_URI.equals(tag.getNamespace())) { if (isInjectedHtmlTagForWhichNoProblemsReporting((HtmlTag) tag)) return HighlightInfoType.INFORMATION; return HighlightInfoType.WARNING; } return HighlightInfoType.WRONG_REF; }
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(); //noinspection unchecked final Set<XmlElementDescriptor> history = new THashSet<XmlElementDescriptor>(); 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()); final XmlElementDescriptor[] e = rootDescriptor.getRootElementsDescriptors(document); for (XmlElementDescriptor descriptor : e) { processElementDescriptors(descriptor, tag, names, history); } } 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); } }
@NotNull public XmlTag[] findSubTags(final String name, final String namespace) { final XmlTag[] subTags = getSubTags(); final List<XmlTag> result = new ArrayList<XmlTag>(); for (final XmlTag subTag : subTags) { if (namespace == null) { if (name.equals(subTag.getName())) result.add(subTag); } else if (name.equals(subTag.getLocalName()) && namespace.equals(subTag.getNamespace())) { result.add(subTag); } } return ContainerUtil.toArray(result, new XmlTag[result.size()]); }
@Nullable @Override public MyValidationMessageConsumer collectInformation(@NotNull final PsiFile file) { final FileType type = file.getFileType(); if (type != StdFileTypes.XML && type != RncFileType.getInstance()) { return null; } final XmlFile xmlfile = (XmlFile) file; final XmlDocument document = xmlfile.getDocument(); if (document == null) { return null; } if (type == StdFileTypes.XML) { final XmlTag rootTag = document.getRootTag(); if (rootTag == null) { return null; } if (!ApplicationLoader.RNG_NAMESPACE.equals(rootTag.getNamespace())) { return null; } } else { if (!ApplicationManager.getApplication().isUnitTestMode() && MyErrorFinder.hasError(xmlfile)) { return null; } } final Document doc = PsiDocumentManager.getInstance(file.getProject()).getDocument(file); final MyValidationMessageConsumer consumer = new MyValidationMessageConsumer(); ErrorHandler eh = new DefaultHandler() { @Override public void warning(SAXParseException e) { handleError(e, file, doc, consumer.warning()); } @Override public void error(SAXParseException e) { handleError(e, file, doc, consumer.error()); } }; RngParser.parsePattern(file, eh, true); return consumer; }
@Override @SuppressWarnings("ConstantConditions") public XmlNSDescriptor getRootTagNSDescriptor() { XmlTag rootTag = getRootTag(); return rootTag != null ? rootTag.getNSDescriptor(rootTag.getNamespace(), false) : null; }
public XmlNSDescriptor getRootTagNSDescriptor() { XmlTag rootTag = getRootTag(); return rootTag != null ? rootTag.getNSDescriptor(rootTag.getNamespace(), false) : null; }