001: /*
002: * Fast Infoset ver. 0.1 software ("Software")
003: *
004: * Copyright, 2004-2005 Sun Microsystems, Inc. All Rights Reserved.
005: *
006: * Software is licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License. You may
008: * obtain a copy of the License at:
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
014: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
015: * License for the specific language governing permissions and limitations.
016: *
017: * Sun supports and benefits from the global community of open source
018: * developers, and thanks the community for its important contributions and
019: * open standards-based technology, which Sun has adopted into many of its
020: * products.
021: *
022: * Please note that portions of Software may be provided with notices and
023: * open source licenses from such communities and third parties that govern the
024: * use of those portions, and any licenses granted hereunder do not alter any
025: * rights and obligations you may have under such open source licenses,
026: * however, the disclaimer of warranty and limitation of liability provisions
027: * in this License will apply to all Software in this distribution.
028: *
029: * You acknowledge that the Software is not designed, licensed or intended
030: * for use in the design, construction, operation or maintenance of any nuclear
031: * facility.
032: *
033: * Apache License
034: * Version 2.0, January 2004
035: * http://www.apache.org/licenses/
036: *
037: */
038:
039: package com.sun.xml.fastinfoset.tools;
040:
041: import com.sun.xml.fastinfoset.QualifiedName;
042: import java.io.File;
043:
044: import javax.xml.parsers.SAXParser;
045: import javax.xml.parsers.SAXParserFactory;
046:
047: import com.sun.xml.fastinfoset.tools.VocabularyGenerator;
048: import com.sun.xml.fastinfoset.util.CharArrayArray;
049: import com.sun.xml.fastinfoset.util.ContiguousCharArrayArray;
050: import com.sun.xml.fastinfoset.util.PrefixArray;
051: import com.sun.xml.fastinfoset.util.QualifiedNameArray;
052: import com.sun.xml.fastinfoset.util.StringArray;
053: import com.sun.xml.fastinfoset.vocab.ParserVocabulary;
054:
055: public class PrintTable {
056:
057: /** Creates a new instance of PrintTable */
058: public PrintTable() {
059: }
060:
061: public static void printVocabulary(ParserVocabulary vocabulary) {
062: printArray("Attribute Name Table", vocabulary.attributeName);
063: printArray("Attribute Value Table", vocabulary.attributeValue);
064: printArray("Character Content Chunk Table",
065: vocabulary.characterContentChunk);
066: printArray("Element Name Table", vocabulary.elementName);
067: printArray("Local Name Table", vocabulary.localName);
068: printArray("Namespace Name Table", vocabulary.namespaceName);
069: printArray("Other NCName Table", vocabulary.otherNCName);
070: printArray("Other String Table", vocabulary.otherString);
071: printArray("Other URI Table", vocabulary.otherURI);
072: printArray("Prefix Table", vocabulary.prefix);
073: }
074:
075: public static void printArray(String title, StringArray a) {
076: System.out.println(title);
077:
078: for (int i = 0; i < a.getSize(); i++) {
079: System.out.println("" + (i + 1) + ": " + a.getArray()[i]);
080: }
081: }
082:
083: public static void printArray(String title, PrefixArray a) {
084: System.out.println(title);
085:
086: for (int i = 0; i < a.getSize(); i++) {
087: System.out.println("" + (i + 1) + ": " + a.getArray()[i]);
088: }
089: }
090:
091: public static void printArray(String title, CharArrayArray a) {
092: System.out.println(title);
093:
094: for (int i = 0; i < a.getSize(); i++) {
095: System.out.println("" + (i + 1) + ": " + a.getArray()[i]);
096: }
097: }
098:
099: public static void printArray(String title,
100: ContiguousCharArrayArray a) {
101: System.out.println(title);
102:
103: for (int i = 0; i < a.getSize(); i++) {
104: System.out.println("" + (i + 1) + ": " + a.getString(i));
105: }
106: }
107:
108: public static void printArray(String title, QualifiedNameArray a) {
109: System.out.println(title);
110:
111: for (int i = 0; i < a.getSize(); i++) {
112: QualifiedName name = a.getArray()[i];
113: System.out.println("" + (name.index + 1) + ": " + "{"
114: + name.namespaceName + "}" + name.prefix + ":"
115: + name.localName);
116: }
117: }
118:
119: /**
120: * @param args the command line arguments
121: */
122: public static void main(String[] args) {
123: try {
124: SAXParserFactory saxParserFactory = SAXParserFactory
125: .newInstance();
126: saxParserFactory.setNamespaceAware(true);
127:
128: SAXParser saxParser = saxParserFactory.newSAXParser();
129:
130: ParserVocabulary referencedVocabulary = new ParserVocabulary();
131:
132: VocabularyGenerator vocabularyGenerator = new VocabularyGenerator(
133: referencedVocabulary);
134: File f = new File(args[0]);
135: saxParser.parse(f, vocabularyGenerator);
136:
137: printVocabulary(referencedVocabulary);
138: } catch (Exception e) {
139: e.printStackTrace();
140: }
141: }
142: }
|