update copyright
[fedora-idea.git] / xml / impl / src / com / intellij / xml / index / XsdTagNameBuilder.java
blob7295dbd7c396488203f75520bebcece9d46d950c
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.index;
18 import com.intellij.util.xml.NanoXmlUtil;
19 import com.intellij.util.NullableFunction;
20 import com.intellij.openapi.vfs.VirtualFile;
21 import com.intellij.openapi.vfs.VfsUtil;
22 import org.jetbrains.annotations.NonNls;
23 import org.jetbrains.annotations.Nullable;
25 import java.io.IOException;
26 import java.io.InputStream;
27 import java.util.ArrayList;
28 import java.util.Collection;
30 /**
31 * @author Dmitry Avdeev
33 public class XsdTagNameBuilder extends NanoXmlUtil.IXMLBuilderAdapter {
35 @Nullable
36 public static Collection<String> computeTagNames(final InputStream is) {
37 try {
38 final XsdTagNameBuilder builder = new XsdTagNameBuilder();
39 NanoXmlUtil.parse(is, builder);
40 return builder.myTagNames;
42 finally {
43 try {
44 if (is != null) {
45 is.close();
48 catch (IOException e) {
49 // can never happen
54 @Nullable
55 public static Collection<String> computeTagNames(final VirtualFile file) {
56 return VfsUtil.processInputStream(file, new NullableFunction<InputStream, Collection<String>>() {
57 public Collection<String> fun(final InputStream inputStream) {
58 return computeTagNames(inputStream);
60 });
63 private final Collection<String> myTagNames = new ArrayList<String>();
64 private boolean myElementStarted;
66 public void startElement(@NonNls final String name, @NonNls final String nsPrefix, @NonNls final String nsURI, final String systemID, final int lineNr)
67 throws Exception {
69 myElementStarted = nsPrefix != null && nsURI.equals("http://www.w3.org/2001/XMLSchema") && name.equals("element");
72 public void addAttribute(@NonNls final String key, final String nsPrefix, final String nsURI, final String value, final String type)
73 throws Exception {
74 if (myElementStarted && key.equals("name")) {
75 myTagNames.add(value);
76 myElementStarted = false;