update copyright
[fedora-idea.git] / xml / impl / src / com / intellij / xml / util / XIncludeProvider.java
blobdb5f372f4ccd362651ba0b1c01ba5800a8558a77
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.ide.highlighter.XmlFileType;
19 import com.intellij.openapi.vfs.VirtualFile;
20 import com.intellij.psi.impl.include.FileIncludeInfo;
21 import com.intellij.psi.impl.include.FileIncludeProvider;
22 import com.intellij.util.indexing.FileContent;
23 import com.intellij.util.xml.NanoXmlUtil;
24 import org.jetbrains.annotations.NotNull;
26 import java.io.ByteArrayInputStream;
27 import java.util.ArrayList;
29 /**
30 * @author Dmitry Avdeev
32 public class XIncludeProvider extends FileIncludeProvider {
33 @NotNull
34 @Override
35 public String getId() {
36 return "XInclude";
39 @Override
40 public boolean acceptFile(VirtualFile file) {
41 return file.getFileType() == XmlFileType.INSTANCE;
44 @NotNull
45 @Override
46 public FileIncludeInfo[] getIncludeInfos(FileContent content) {
48 final ArrayList<FileIncludeInfo> infos = new ArrayList<FileIncludeInfo>();
49 NanoXmlUtil.parse(new ByteArrayInputStream(content.getContent()), new NanoXmlUtil.IXMLBuilderAdapter() {
51 boolean isXInclude;
52 @Override
53 public void startElement(String name, String nsPrefix, String nsURI, String systemID, int lineNr) throws Exception {
54 isXInclude = XmlUtil.XINCLUDE_URI.equals(nsURI) && "include".equals(name);
57 @Override
58 public void addAttribute(String key, String nsPrefix, String nsURI, String value, String type) throws Exception {
59 if (isXInclude && "href".equals(key)) {
60 infos.add(new FileIncludeInfo(value));
64 @Override
65 public void endElement(String name, String nsPrefix, String nsURI) throws Exception {
66 isXInclude = false;
68 });
69 return infos.toArray(new FileIncludeInfo[infos.size()]);