public static String generateDocumentDTD(XmlDocument doc, boolean full) { final Map<String, List<String>> tags = new LinkedHashMap<String, List<String>>(); final Map<String, List<MyAttributeInfo>> attributes = new LinkedHashMap<String, List<MyAttributeInfo>>(); try { XmlEntityRefImpl.setNoEntityExpandOutOfDocument(doc, true); final XmlTag rootTag = doc.getRootTag(); computeTag(rootTag, tags, attributes, full); // For supporting not well-formed XML for (PsiElement element = rootTag != null ? rootTag.getNextSibling() : null; element != null; element = element.getNextSibling()) { if (element instanceof XmlTag) { computeTag((XmlTag)element, tags, attributes, full); } } } finally { XmlEntityRefImpl.setNoEntityExpandOutOfDocument(doc, false); } final StringBuilder buffer = new StringBuilder(); for (final String tagName : tags.keySet()) { buffer.append(generateElementDTD(tagName, tags.get(tagName), attributes.get(tagName))); } return buffer.toString(); }
private static PsiElement parseEntityDecl(final XmlEntityDecl entityDecl, final PsiFile targetFile, final XmlEntityDecl.EntityContextType type, final XmlEntityRef entityRef) { CachedValue<PsiElement> value = entityRef.getUserData(PARSED_DECL_KEY); if(value == null) { value = CachedValuesManager.getManager(entityDecl.getProject()).createCachedValue(() -> { final PsiElement res = entityDecl.parse(targetFile, type, entityRef); if(res == null) { return new CachedValueProvider.Result<>(res, targetFile); } if(!entityDecl.isInternalReference()) { XmlEntityCache.copyEntityCaches(res.getContainingFile(), targetFile); } return new CachedValueProvider.Result<>(res, res.getUserData(XmlElement.DEPENDING_ELEMENT), entityDecl, targetFile, entityRef); }, false); value = ((XmlEntityRefImpl) entityRef).putUserDataIfAbsent(PARSED_DECL_KEY, value); } return value.getValue(); }
@Override @Nullable public PsiElement resolve() { XmlEntityDecl xmlEntityDecl = XmlEntityRefImpl.resolveEntity((XmlElement) myElement, (myElement instanceof XmlEntityRef ? myElement.getLastChild() : myElement).getText(), myElement .getContainingFile()); if(xmlEntityDecl != null && !xmlEntityDecl.isPhysical()) { PsiNamedElement element = XmlUtil.findRealNamedElement(xmlEntityDecl); if(element != null) { xmlEntityDecl = (XmlEntityDecl) element; } } return xmlEntityDecl; }
@Override @Nullable public PsiElement resolve() { XmlEntityDecl xmlEntityDecl = XmlEntityRefImpl.resolveEntity( (XmlElement)myElement, (myElement instanceof XmlEntityRef ? myElement.getLastChild():myElement).getText(), myElement.getContainingFile() ); if (xmlEntityDecl != null && !xmlEntityDecl.isPhysical()) { PsiNamedElement element = XmlUtil.findRealNamedElement(xmlEntityDecl); if (element != null) xmlEntityDecl = (XmlEntityDecl)element; } return xmlEntityDecl; }
@Nullable public PsiElement resolve() { XmlEntityDecl xmlEntityDecl = XmlEntityRefImpl.resolveEntity( (XmlElement)myElement, (myElement instanceof XmlEntityRef ? myElement.getLastChild():myElement).getText(), myElement.getContainingFile() ); if (xmlEntityDecl != null && !xmlEntityDecl.isPhysical()) { PsiNamedElement element = XmlUtil.findRealNamedElement(xmlEntityDecl); if (element != null) xmlEntityDecl = (XmlEntityDecl)element; } return xmlEntityDecl; }
public static String generateDocumentDTD(XmlDocument doc, boolean full) { final Map<String, List<String>> tags = new LinkedHashMap<>(); final Map<String, List<MyAttributeInfo>> attributes = new LinkedHashMap<>(); try { XmlEntityRefImpl.setNoEntityExpandOutOfDocument(doc, true); final XmlTag rootTag = doc.getRootTag(); computeTag(rootTag, tags, attributes, full); // For supporting not well-formed XML for(PsiElement element = rootTag != null ? rootTag.getNextSibling() : null; element != null; element = element.getNextSibling()) { if(element instanceof XmlTag) { computeTag((XmlTag) element, tags, attributes, full); } } } finally { XmlEntityRefImpl.setNoEntityExpandOutOfDocument(doc, false); } final StringBuilder buffer = new StringBuilder(); for(final String tagName : tags.keySet()) { buffer.append(generateElementDTD(tagName, tags.get(tagName), attributes.get(tagName))); } return buffer.toString(); }