@NotNull @Override public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) { return new XmlElementVisitor() { @Override public void visitXmlAttributeValue(XmlAttributeValue value) { checkRefs(value, holder, isOnTheFly); } @Override public void visitXmlDoctype(XmlDoctype xmlDoctype) { checkRefs(xmlDoctype, holder, isOnTheFly); } @Override public void visitXmlTag(XmlTag tag) { checkRefs(tag, holder, isOnTheFly); } }; }
private static boolean is23(final ConvertContext context) { final DomElement element = DomUtil.getFileElement(context.getInvocationElement()).getRootElement(); final XmlTag tag = element.getXmlTag(); if (tag != null && "web-app".equals(element.getXmlElementName()) && tag.getAttribute("version") == null) { XmlDocument document = (XmlDocument)tag.getParent(); final XmlProlog prolog = document.getProlog(); if (prolog != null) { final XmlDoctype doctype = prolog.getDoctype(); if (doctype != null) { final String uri = doctype.getDtdUri(); if (uri != null && uri.contains("2_3")) return true; } } return false; } return true; }
private boolean hasDtdDeclaration() { XmlDocument document = myFile.getDocument(); if (document == null) return false; XmlProlog prolog = document.getProlog(); if (prolog == null) return false; XmlDoctype doctype = prolog.getDoctype(); if (doctype == null) return false; return true; }
public static boolean hasNonHtml5Doctype(XmlElement context) { XmlDocument doc = PsiTreeUtil.getParentOfType(context, XmlDocument.class); if(doc == null) { return false; } XmlProlog prolog = doc.getProlog(); XmlDoctype doctype = prolog != null ? prolog.getDoctype() : null; return doctype != null && !isHtml5Doctype(doctype); }
@Override @NotNull public XmlElementDescriptor[] getRootElementsDescriptors(@Nullable final XmlDocument document) { // Suggest more appropriate variant if DOCTYPE <element_name> exists final XmlProlog prolog = document != null ? document.getProlog() : null; if(prolog != null) { final XmlDoctype doctype = prolog.getDoctype(); if(doctype != null) { final XmlElement element = doctype.getNameElement(); if(element != null) { final XmlElementDescriptor descriptor = getElementDescriptor(element.getText()); if(descriptor != null) { return new XmlElementDescriptor[]{descriptor}; } } } } return getElements(); }
@NotNull public Collection<StructureViewTreeElement> getChildrenBase() { final XmlDocument document = getElement().getDocument(); List<XmlTag> rootTags = new ArrayList<XmlTag>(); if (document != null) { for (PsiElement element : document.getChildren()) if (element instanceof XmlTag) rootTags.add((XmlTag)element); } Collection<StructureViewTreeElement> structureViewTreeElements = AbstractXmlTagTreeElement.getStructureViewTreeElements(rootTags.toArray(new XmlTag[rootTags.size()])); Collection<StructureViewTreeElement> dtdStructureViewTreeElements = null; final XmlProlog prolog = document != null ? document.getProlog():null; if (prolog != null) { final XmlDoctype doctype = prolog.getDoctype(); if (doctype != null) { final XmlMarkupDecl xmlMarkupDecl = doctype.getMarkupDecl(); if (xmlMarkupDecl != null) { dtdStructureViewTreeElements = DtdFileTreeElement.collectElements(xmlMarkupDecl); } } } if (dtdStructureViewTreeElements != null) { final ArrayList<StructureViewTreeElement> result = new ArrayList<StructureViewTreeElement>( dtdStructureViewTreeElements.size() + structureViewTreeElements.size() ); result.addAll(dtdStructureViewTreeElements); result.addAll(structureViewTreeElements); structureViewTreeElements = result; } return structureViewTreeElements; }
@Nullable XmlDoctype getDoctype(XmlFile file);
@Override public XmlDoctype getDoctype() { return (XmlDoctype)findChildByRoleAsPsiElement(XmlChildRole.XML_DOCTYPE); }
@Nullable @Override public XmlDoctype getDoctype(XmlFile file) { return new RTDoctype(); }
public XmlDoctype getDoctype() { return (XmlDoctype)findChildByRoleAsPsiElement(XmlChildRole.XML_DOCTYPE); }
public static boolean isHtml5Document(XmlDocument doc) { if(doc == null) { return false; } XmlProlog prolog = doc.getProlog(); XmlDoctype doctype = prolog != null ? prolog.getDoctype() : null; if(!isHtmlTagContainingFile(doc)) { return false; } final PsiFile htmlFile = doc.getContainingFile(); final String htmlFileFullName; if(htmlFile != null) { final VirtualFile vFile = htmlFile.getVirtualFile(); if(vFile != null) { htmlFileFullName = vFile.getPath(); } else { htmlFileFullName = htmlFile.getName(); } } else { htmlFileFullName = "unknown"; } if(doctype == null) { LOG.debug("DOCTYPE for " + htmlFileFullName + " is null"); return Html5SchemaProvider.getHtml5SchemaLocation().equals(ExternalResourceManagerEx.getInstanceEx().getDefaultHtmlDoctype(doc.getProject())); } final boolean html5Doctype = isHtml5Doctype(doctype); final String doctypeDescription = "text: " + doctype.getText() + ", dtdUri: " + doctype.getDtdUri() + ", publicId: " + doctype.getPublicId() + ", markupDecl: " + doctype.getMarkupDecl(); LOG.debug("DOCTYPE for " + htmlFileFullName + "; " + doctypeDescription + "; HTML5: " + html5Doctype); return html5Doctype; }
public static boolean isHtml5Doctype(XmlDoctype doctype) { return doctype.getDtdUri() == null && doctype.getPublicId() == null && doctype.getMarkupDecl() == null; }
@Override public XmlDoctype getDoctype() { return (XmlDoctype) findChildByRoleAsPsiElement(XmlChildRole.XML_DOCTYPE); }
@Override public boolean isAcceptable(Object element, PsiElement context) { if(element instanceof XmlTag) { final XmlTag psiElement = (XmlTag) element; if(!psiElement.isValid()) { return false; } final String ns = psiElement.getNamespace(); if(isNamespaceAcceptable(ns)) { return true; } final PsiFile psiFile = psiElement.getContainingFile(); if(psiFile instanceof XmlFile) { // We use file references for as dtd namespace // But we should also check PUBLIC ID for namespace XmlDocument document = ((XmlFile) psiFile).getDocument(); if(document == null) { return false; } final XmlProlog prolog = document.getProlog(); if(prolog != null) { final XmlDoctype doctype = prolog.getDoctype(); if(doctype != null) { final String publicId = doctype.getPublicId(); if(publicId != null) { if(isNamespaceAcceptable(publicId)) { return true; } } } } } } else if(element instanceof XmlDocument) { return isAcceptable(((XmlDocument) element).getRootTag(), context); } return false; }
@Override public void registerReferenceProviders(@NotNull final PsiReferenceRegistrar registrar) { final IdReferenceProvider idReferenceProvider = new IdReferenceProvider(); XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, idReferenceProvider.getIdForAttributeNames(), idReferenceProvider.getIdForFilter(), true, idReferenceProvider, PsiReferenceRegistrar.DEFAULT_PRIORITY); final DtdReferencesProvider dtdReferencesProvider = new DtdReferencesProvider(); //registerReferenceProvider(null, XmlEntityDecl.class,dtdReferencesProvider); registrar.registerReferenceProvider(PlatformPatterns.psiElement(XmlEntityRef.class), dtdReferencesProvider); registrar.registerReferenceProvider(PlatformPatterns.psiElement(XmlDoctype.class), dtdReferencesProvider); registrar.registerReferenceProvider(PlatformPatterns.psiElement(XmlElementDecl.class), dtdReferencesProvider); registrar.registerReferenceProvider(PlatformPatterns.psiElement(XmlAttlistDecl.class), dtdReferencesProvider); registrar.registerReferenceProvider(PlatformPatterns.psiElement(XmlElementContentSpec.class), dtdReferencesProvider); registrar.registerReferenceProvider(PlatformPatterns.psiElement(XmlToken.class), dtdReferencesProvider); registrar.registerReferenceProvider(xmlAttributeValue(), new ArbitraryPlaceUrlReferenceProvider(), PsiReferenceRegistrar.LOWER_PRIORITY); URIReferenceProvider uriProvider = new URIReferenceProvider(); XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, null, dtdReferencesProvider.getSystemReferenceFilter(), uriProvider); XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, new String[]{"href"}, new ScopeFilter(new ParentElementFilter(new AndFilter(new AndFilter(XmlTagFilter.INSTANCE, new XmlTextFilter("include")), new NamespaceFilter(XmlUtil.XINCLUDE_URI)), 2)), true, new XmlBaseReferenceProvider(true)); registrar.registerReferenceProvider(xmlAttributeValue().withLocalName("base").withNamespace(XmlUtil.XML_NAMESPACE_URI), new XmlBaseReferenceProvider(false)); XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, new String[]{MicrodataUtil.ITEM_TYPE}, null, new MicrodataReferenceProvider()); final SchemaReferencesProvider schemaReferencesProvider = new SchemaReferencesProvider(); XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, schemaReferencesProvider.getCandidateAttributeNamesForSchemaReferences(), new ScopeFilter(new ParentElementFilter(new NamespaceFilter(XmlUtil.SCHEMA_URIS), 2)), schemaReferencesProvider); registrar.registerReferenceProvider(xmlAttributeValue(xmlAttribute().withNamespace(XmlUtil.XML_SCHEMA_INSTANCE_URI)). withLocalName("type"), schemaReferencesProvider); registrar.registerReferenceProvider(xmlAttributeValue(xmlAttribute().withNamespace(XmlUtil.XML_SCHEMA_INSTANCE_URI)). withLocalName("noNamespaceSchemaLocation", "schemaLocation"), uriProvider); registrar.registerReferenceProvider(xmlAttributeValue().withLocalName("schemaLocation", "namespace"). withSuperParent(2, xmlTag().withNamespace(XmlUtil.SCHEMA_URIS).withLocalName("import", "include", "redefine")), uriProvider); XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, null, URIReferenceProvider.ELEMENT_FILTER, true, uriProvider); XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, new String[]{"encoding"}, new ScopeFilter(new ParentElementFilter(new ClassFilter(XmlProcessingInstruction.class))), true, new XmlEncodingReferenceProvider()); registrar.registerReferenceProvider(xmlAttributeValue(), new XmlPrefixReferenceProvider()); registrar.registerReferenceProvider(xmlAttributeValue(), new XmlEnumeratedValueReferenceProvider(), PsiReferenceRegistrar.LOWER_PRIORITY); registrar.registerReferenceProvider(xmlTag(), XmlEnumeratedValueReferenceProvider.forTags(), PsiReferenceRegistrar.LOWER_PRIORITY); registrar.registerReferenceProvider(xmlAttributeValue().withLocalName("source").withSuperParent(2, xmlTag().withLocalName("documentation").withNamespace(XmlUtil.SCHEMA_URIS)), new PsiReferenceProvider() { @NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { return new PsiReference[]{new WebReference(element)}; } }); }