2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.html
.impl
;
18 import com
.intellij
.openapi
.extensions
.Extensions
;
19 import com
.intellij
.psi
.xml
.XmlAttribute
;
20 import com
.intellij
.psi
.xml
.XmlTag
;
21 import com
.intellij
.util
.ArrayUtil
;
22 import com
.intellij
.xml
.XmlAttributeDescriptor
;
23 import com
.intellij
.xml
.XmlElementDescriptor
;
24 import com
.intellij
.xml
.XmlExtension
;
25 import com
.intellij
.xml
.XmlAttributeDescriptorsProvider
;
26 import com
.intellij
.xml
.impl
.schema
.AnyXmlElementDescriptor
;
27 import com
.intellij
.xml
.impl
.schema
.XmlElementDescriptorImpl
;
28 import com
.intellij
.xml
.util
.HtmlUtil
;
29 import com
.intellij
.xml
.util
.XmlUtil
;
30 import org
.jetbrains
.annotations
.Nullable
;
33 * @author Maxim.Mossienko
35 public class RelaxedHtmlFromSchemaElementDescriptor
extends XmlElementDescriptorImpl
{
37 RelaxedHtmlFromSchemaElementDescriptor(XmlTag tag
) {
41 public XmlElementDescriptor
getElementDescriptor(XmlTag childTag
, XmlTag contextTag
) {
42 XmlElementDescriptor elementDescriptor
= super.getElementDescriptor(childTag
, contextTag
);
44 if (elementDescriptor
== null) {
45 return getRelaxedDescriptor(this, childTag
);
48 return elementDescriptor
;
51 public XmlElementDescriptor
[] getElementsDescriptors(final XmlTag context
) {
52 return ArrayUtil
.mergeArrays(
53 super.getElementsDescriptors(context
),
54 HtmlUtil
.getCustomTagDescriptors(context
),
55 XmlElementDescriptor
.class
59 public static XmlElementDescriptor
getRelaxedDescriptor(XmlElementDescriptor base
, final XmlTag childTag
) {
60 final String namespace
= childTag
.getNamespace();
61 final XmlExtension extension
= XmlExtension
.getExtensionByElement(childTag
);
62 if(!XmlUtil
.XHTML_URI
.equals(namespace
) &&
63 ( base
.getContentType() != XmlElementDescriptor
.CONTENT_TYPE_EMPTY
||
64 (extension
!= null && extension
.isCustomTagAllowed(childTag
)) // allow custom tag
66 return new AnyXmlElementDescriptor(base
,childTag
.getNSDescriptor(namespace
,true));
71 public XmlAttributeDescriptor
[] getAttributesDescriptors(final XmlTag context
) {
72 return addAttrDescriptorsForFacelets(context
, super.getAttributesDescriptors(context
));
75 public static XmlAttributeDescriptor
[] addAttrDescriptorsForFacelets(final XmlTag context
,
76 XmlAttributeDescriptor
[] descriptors
) {
77 if (context
== null) {
80 for (XmlAttributeDescriptorsProvider provider
: Extensions
.getExtensions(XmlAttributeDescriptorsProvider
.EP_NAME
)) {
81 descriptors
= ArrayUtil
.mergeArrays(descriptors
, provider
.getAttributeDescriptors(context
), XmlAttributeDescriptor
.class);
87 public XmlAttributeDescriptor
getAttributeDescriptor(XmlAttribute attribute
) {
88 return getAttributeDescriptor(attribute
.getName(), attribute
.getParent());
91 public XmlAttributeDescriptor
getAttributeDescriptor(String attributeName
, final XmlTag context
) {
92 final XmlAttributeDescriptor descriptor
= super.getAttributeDescriptor(attributeName
.toLowerCase(), context
);
93 if (descriptor
!= null) return descriptor
;
95 return getAttributeDescriptorFromFacelets(attributeName
, context
);
99 public static XmlAttributeDescriptor
getAttributeDescriptorFromFacelets(final String attributeName
, final XmlTag context
) {
100 if (context
== null) {
103 for (XmlAttributeDescriptorsProvider provider
: Extensions
.getExtensions(XmlAttributeDescriptorsProvider
.EP_NAME
)) {
104 final XmlAttributeDescriptor descriptor
= provider
.getAttributeDescriptor(attributeName
, context
);
105 if (descriptor
!= null) {
112 public boolean allowElementsFromNamespace(final String namespace
, final XmlTag context
) {