correct support html5+jspx; support html5 by default

This commit is contained in:
Eugene Kudelevsky
2012-04-13 16:19:23 +04:00
parent 2f700aee2e
commit ab29424ee0
6 changed files with 46 additions and 12 deletions
@@ -35,6 +35,7 @@ import com.intellij.psi.xml.XmlFile;
import com.intellij.util.ArrayUtil;
import com.intellij.util.containers.CollectionFactory;
import com.intellij.util.containers.HashMap;
import com.intellij.xml.Html5SchemaProvider;
import com.intellij.xml.XmlSchemaProvider;
import com.intellij.xml.util.XmlUtil;
import org.jdom.Element;
@@ -75,7 +76,7 @@ public class ExternalResourceManagerImpl extends ExternalResourceManagerEx imple
}
};
private String myDefaultHtmlDoctype = XmlUtil.XHTML_URI;
private String myDefaultHtmlDoctype = Html5SchemaProvider.HTML5_SCHEMA_LOCATION;
protected Map<String, Map<String, Resource>> computeStdResources() {
ResourceRegistrarImpl registrar = new ResourceRegistrarImpl();
@@ -27,7 +27,6 @@ import com.intellij.psi.xml.XmlFile;
import com.intellij.psi.xml.XmlTag;
import com.intellij.psi.xml.XmlToken;
import com.intellij.xml.XmlNSDescriptor;
import com.intellij.xml.util.HtmlUtil;
import com.intellij.xml.util.XmlTagUtil;
/**
@@ -42,7 +41,7 @@ public class XMLExternalAnnotator extends ExternalAnnotator {
XmlTag rootTag = document.getRootTag();
XmlNSDescriptor nsDescriptor = rootTag == null ? null : rootTag.getNSDescriptor(rootTag.getNamespace(), false);
if (nsDescriptor instanceof Validator && !HtmlUtil.isHtml5Document(document)) {
if (nsDescriptor instanceof Validator) {
//noinspection unchecked
((Validator<XmlDocument>)nsDescriptor).validate(document, new MyHost(holder));
}
@@ -39,7 +39,7 @@ public class XmlElementsGroupImpl implements XmlElementsGroup {
return ContainerUtil.map(myParticle.getSubParticles(), new Function<XmlContentParticle, XmlElementsGroup>() {
@Override
public XmlElementsGroup fun(XmlContentParticle xmlContentParticle) {
return new XmlElementsGroupImpl(xmlContentParticle, XmlElementsGroupImpl.this);
return new XmlElementsGroupImpl(xmlContentParticle, XmlElementsGroupImpl.this);
}
});
}
@@ -37,6 +37,7 @@ import com.intellij.util.ArrayUtil;
import com.intellij.xml.XmlAttributeDescriptor;
import com.intellij.xml.XmlElementDescriptor;
import com.intellij.xml.XmlNSDescriptor;
import com.intellij.xml.XmlNSDescriptorEx;
import com.intellij.xml.impl.ExternalDocumentValidator;
import com.intellij.xml.util.XmlUtil;
import gnu.trove.THashSet;
@@ -50,7 +51,7 @@ import java.util.*;
* @author Mike
*/
@SuppressWarnings({"HardCodedStringLiteral"})
public class XmlNSDescriptorImpl implements XmlNSDescriptor,Validator<XmlDocument>, DumbAware, XmlNSTypeDescriptorProvider {
public class XmlNSDescriptorImpl implements XmlNSDescriptorEx,Validator<XmlDocument>, DumbAware, XmlNSTypeDescriptorProvider {
private static final Logger LOG = Logger.getInstance("#com.intellij.xml.impl.schema.XmlNSDescriptorImpl");
@NonNls private static final Set<String> STD_TYPES = new HashSet<String>();
private static final Set<String> UNDECLARED_STD_TYPES = new HashSet<String>();
@@ -0,0 +1,8 @@
package com.intellij.xml;
/**
* @author Eugene.Kudelevsky
*/
public interface XmlNSDescriptorEx extends XmlNSDescriptor {
XmlElementDescriptor getElementDescriptor(String localName, String namespace);
}
@@ -35,7 +35,8 @@ import com.intellij.util.ArrayUtil;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.HashMap;
import com.intellij.xml.XmlElementDescriptor;
import com.intellij.xml.XmlNSDescriptor;
import com.intellij.xml.XmlNSDescriptorEx;
import com.intellij.xml.impl.schema.AnyXmlElementDescriptor;
import org.intellij.plugins.relaxNG.ApplicationLoader;
import org.intellij.plugins.relaxNG.model.resolve.RelaxIncludeIndex;
import org.intellij.plugins.relaxNG.validation.RngParser;
@@ -48,17 +49,17 @@ import org.kohsuke.rngom.digested.DPattern;
import org.kohsuke.rngom.nc.NameClass;
import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* Created by IntelliJ IDEA.
* User: sweinreuter
* Date: 18.07.2007
*/
public class RngNsDescriptor implements XmlNSDescriptor, Validator {
public class RngNsDescriptor implements XmlNSDescriptorEx, Validator {
private final Map<QName, CachedValue<XmlElementDescriptor>> myDescriptorsMap =
Collections.synchronizedMap(new HashMap<QName, CachedValue<XmlElementDescriptor>>());
private static final Key<ParameterizedCachedValue<XmlElementDescriptor, RngNsDescriptor>> ROOT_KEY = Key.create("ROOT_DESCRIPTOR");
private XmlFile myFile;
@@ -95,7 +96,7 @@ public class RngNsDescriptor implements XmlNSDescriptor, Validator {
}
}
if (desc == null) {
if (desc == null || desc instanceof AnyXmlElementDescriptor) {
return findRootDescriptor(tag);
}
@@ -124,6 +125,11 @@ public class RngNsDescriptor implements XmlNSDescriptor, Validator {
return descriptor != null ? descriptor : findDescriptor(tag, ChildElementFinder.find(myPattern));
}
private XmlElementDescriptor findRootDescriptorInner(QName qName) {
return findDescriptor(qName, ContainerUtil.findAll(
ChildElementFinder.find(-1, myPattern), NamedPatternFilter.INSTANCE));
}
public XmlElementDescriptor findDescriptor(XmlTag tag, List<DElementPattern> list) {
final QName qName = new QName(tag.getNamespace(), tag.getLocalName());
@@ -279,4 +285,23 @@ public class RngNsDescriptor implements XmlNSDescriptor, Validator {
XmlInstanceValidator.doValidation(doc, host, getDescriptorFile());
}
}
//@Override
public XmlElementDescriptor getElementDescriptor(String localName, String namespace) {
final QName qName = new QName(namespace, localName);
CachedValue<XmlElementDescriptor> cachedValue = myDescriptorsMap.get(qName);
if (cachedValue == null) {
cachedValue =
CachedValuesManager.getManager(myElement.getProject()).createCachedValue(new CachedValueProvider<XmlElementDescriptor>() {
public Result<XmlElementDescriptor> compute() {
final XmlElementDescriptor descriptor = findRootDescriptorInner(qName);
return descriptor != null
? new Result<XmlElementDescriptor>(descriptor, descriptor.getDependences())
: new Result<XmlElementDescriptor>(null, getDependences());
}
}, false);
myDescriptorsMap.put(qName, cachedValue);
}
return cachedValue.getValue();
}
}