update copyright
[fedora-idea.git] / xml / impl / src / com / intellij / psi / impl / source / html / dtd / HtmlElementDescriptorImpl.java
blobd831839b0bc97d020630551a7bf4eb2f11e17ce8
1 /*
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.psi.impl.source.html.dtd;
18 import com.intellij.html.impl.RelaxedHtmlFromSchemaElementDescriptor;
19 import com.intellij.psi.PsiElement;
20 import com.intellij.psi.xml.XmlTag;
21 import com.intellij.xml.XmlAttributeDescriptor;
22 import com.intellij.xml.XmlElementDescriptor;
23 import com.intellij.xml.XmlNSDescriptor;
24 import com.intellij.xml.impl.dtd.BaseXmlElementDescriptorImpl;
26 import java.util.HashMap;
28 /**
29 * @by Maxim.Mossienko
31 public class HtmlElementDescriptorImpl extends BaseXmlElementDescriptorImpl {
32 private final XmlElementDescriptor myDelegate;
33 private final boolean myRelaxed;
34 private final boolean myCaseSensitive;
36 public HtmlElementDescriptorImpl(XmlElementDescriptor _delegate, boolean relaxed, boolean caseSensitive) {
37 myDelegate = _delegate;
38 myRelaxed = relaxed;
39 myCaseSensitive = caseSensitive;
42 public String getQualifiedName() {
43 return myDelegate.getQualifiedName();
46 public String getDefaultName() {
47 return myDelegate.getDefaultName();
50 // Read-only calculation
51 protected final XmlElementDescriptor[] doCollectXmlDescriptors(final XmlTag context) {
52 XmlElementDescriptor[] elementsDescriptors = myDelegate.getElementsDescriptors(context);
53 XmlElementDescriptor[] temp = new XmlElementDescriptor[elementsDescriptors.length];
55 for (int i = 0; i < elementsDescriptors.length; i++) {
56 temp[i] = new HtmlElementDescriptorImpl( elementsDescriptors[i], myRelaxed, myCaseSensitive );
58 return temp;
61 public XmlElementDescriptor getElementDescriptor(XmlTag element, XmlTag contextTag) {
62 String name = element.getName();
63 if (!myCaseSensitive) name = name.toLowerCase();
65 XmlElementDescriptor xmlElementDescriptor = getElementDescriptor(name, element);
66 if (xmlElementDescriptor == null && myRelaxed) {
67 xmlElementDescriptor = RelaxedHtmlFromSchemaElementDescriptor.getRelaxedDescriptor(this, element);
70 return xmlElementDescriptor;
73 // Read-only calculation
74 protected HashMap<String, XmlElementDescriptor> collectElementDescriptorsMap(final XmlTag element) {
75 final HashMap<String, XmlElementDescriptor> hashMap = new HashMap<String, XmlElementDescriptor>();
76 final XmlElementDescriptor[] elementDescriptors = myDelegate.getElementsDescriptors(element);
78 for (XmlElementDescriptor elementDescriptor : elementDescriptors) {
79 hashMap.put(elementDescriptor.getName(), new HtmlElementDescriptorImpl(elementDescriptor, myRelaxed, myCaseSensitive));
81 return hashMap;
84 // Read-only calculation
85 protected XmlAttributeDescriptor[] collectAttributeDescriptors(final XmlTag context) {
86 final XmlAttributeDescriptor[] attributesDescriptors = myDelegate.getAttributesDescriptors(context);
87 XmlAttributeDescriptor[] temp = new XmlAttributeDescriptor[attributesDescriptors.length];
89 for (int i = 0; i < attributesDescriptors.length; i++) {
90 temp[i] = new HtmlAttributeDescriptorImpl(attributesDescriptors[i], myCaseSensitive);
92 return temp;
95 public XmlAttributeDescriptor getAttributeDescriptor(String attributeName, final XmlTag context) {
96 if (!myCaseSensitive) attributeName = attributeName.toLowerCase();
97 XmlAttributeDescriptor descriptor = super.getAttributeDescriptor(attributeName, context);
98 if (descriptor == null) descriptor = RelaxedHtmlFromSchemaElementDescriptor.getAttributeDescriptorFromFacelets(attributeName, context);
99 return descriptor;
102 // Read-only calculation
103 protected HashMap<String, XmlAttributeDescriptor> collectAttributeDescriptorsMap(final XmlTag context) {
104 final HashMap<String, XmlAttributeDescriptor> hashMap = new HashMap<String, XmlAttributeDescriptor>();
105 XmlAttributeDescriptor[] elementAttributeDescriptors = myDelegate.getAttributesDescriptors(context);
107 for (final XmlAttributeDescriptor attributeDescriptor : elementAttributeDescriptors) {
108 hashMap.put(
109 attributeDescriptor.getName(),
110 new HtmlAttributeDescriptorImpl(attributeDescriptor, myCaseSensitive)
113 return hashMap;
116 public XmlNSDescriptor getNSDescriptor() {
117 return myDelegate.getNSDescriptor();
120 public int getContentType() {
121 return myDelegate.getContentType();
124 public PsiElement getDeclaration() {
125 return myDelegate.getDeclaration();
128 public String getName(PsiElement context) {
129 return myDelegate.getName(context);
132 public String getName() {
133 return myDelegate.getName();
136 public void init(PsiElement element) {
137 myDelegate.init(element);
140 public Object[] getDependences() {
141 return myDelegate.getDependences();
144 public XmlAttributeDescriptor[] getAttributesDescriptors(final XmlTag context) {
145 return RelaxedHtmlFromSchemaElementDescriptor.addAttrDescriptorsForFacelets(context, super.getAttributesDescriptors(context));
148 public boolean allowElementsFromNamespace(final String namespace, final XmlTag context) {
149 return true;