update copyright
[fedora-idea.git] / xml / impl / src / com / intellij / xml / util / XmlIncludeHandler.java
blob68273799cbb4e56386677af606b84a1a46644db0
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.xml.util;
18 import com.intellij.psi.PsiElement;
19 import com.intellij.psi.PsiReference;
20 import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet;
21 import com.intellij.psi.xml.*;
22 import org.jetbrains.annotations.NonNls;
23 import org.jetbrains.annotations.Nullable;
25 /**
26 * @author mike
28 public class XmlIncludeHandler {
29 @NonNls private static final String INCLUDE_TAG_NAME = "include";
30 public static boolean isXInclude(PsiElement element) {
31 if (element instanceof XmlTag) {
32 XmlTag xmlTag = (XmlTag)element;
34 if (xmlTag.getParent() instanceof XmlDocument) return false;
36 if (xmlTag.getLocalName().equals(INCLUDE_TAG_NAME) && xmlTag.getAttributeValue("href") != null) {
37 if (xmlTag.getNamespace().equals(XmlUtil.XINCLUDE_URI)) {
38 return true;
43 return false;
46 @Nullable
47 public static XmlFile resolveXIncludeFile(XmlTag xincludeTag) {
48 final XmlAttribute hrefAttribute = xincludeTag.getAttribute("href", null);
49 if (hrefAttribute == null) return null;
51 final XmlAttributeValue xmlAttributeValue = hrefAttribute.getValueElement();
52 if (xmlAttributeValue == null) return null;
54 final FileReferenceSet referenceSet = FileReferenceSet.createSet(xmlAttributeValue, false, true, false);
56 final PsiReference reference = referenceSet.getLastReference();
57 if (reference == null) return null;
59 final PsiElement target = reference.resolve();
61 if (!(target instanceof XmlFile)) return null;
62 return (XmlFile)target;