Changeset 1106


Ignore:
Timestamp:
Jun 24, 2011, 9:18:41 PM (6 years ago)
Author:
stefan
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/jlatexeditor/PackagesExtractor.java

    r1105 r1106  
    11package jlatexeditor;
    22
    3 import com.sun.deploy.panel.ITreeNode;
    43import my.XML.XMLDocument;
    54import my.XML.XMLParser;
     
    87import org.xml.sax.helpers.XMLReaderFactory;
    98import util.StreamUtils;
     9import util.TrieSet;
    1010
    1111import javax.xml.parsers.SAXParserFactory;
     
    2020  private static final String FILENAME = "data/codehelper/packages.xml";
    2121
    22   private static HashMap<String, Command> commands = new HashMap<String, Command>();
    23 
    2422  public static void main(String[] args) {
    2523    XMLParser xmlParser = new XMLParser();
     
    2725    try {
    2826      long startTime = System.nanoTime();
    29       //commandsDocument = xmlParser.parse(StreamUtils.readFile(FILENAME));
     27
     28      try {
     29        XMLReader parser = XMLReaderFactory.createXMLReader();
     30        DefaultHandler handler = new DebugHandler();
     31        parser.setContentHandler(handler);
     32        parser.setErrorHandler(handler);
     33        try {
     34          parser.parse(new InputSource(StreamUtils.getInputStream(FILENAME)));
     35        } catch (IOException ioe) {
     36          ioe.printStackTrace();
     37        }
     38      } catch (SAXException se) {
     39        se.printStackTrace();
     40      }
     41
    3042      System.out.println((System.nanoTime() - startTime) / (1000 * 1000));
    3143    } catch (Exception e) {
    3244      e.printStackTrace();
    3345      return;
    34     }
    35 
    36     //This class may be any SAX parser, but the classpath
    37     // must be modified to include it.
    38 
    39     //SAXParserFactory.newInstance().newSAXParser();
    40     try {
    41       XMLReader parser = XMLReaderFactory.createXMLReader();
    42       DefaultHandler handler = new DebugHandler();
    43       parser.setContentHandler(handler);
    44       parser.setErrorHandler(handler);
    45       try {
    46         parser.parse(new InputSource(StreamUtils.getInputStream(FILENAME)));
    47       } catch (IOException ioe) {
    48         ioe.printStackTrace();
    49       }
    50     } catch (SAXException se) {
    51       se.printStackTrace();
    5246    }
    5347  }
     
    5751   */
    5852  public static class DebugHandler extends org.xml.sax.helpers.DefaultHandler implements org.xml.sax.ContentHandler {
     53    private String pack;
     54    private String debPack;
     55    private TrieSet<Command> commands = new TrieSet<Command>();
     56
    5957    public DebugHandler() {
    6058      super();
     
    6967
    7068    public void startDocument() {
    71       System.out.println("start document");
     69      //System.out.println("start document");
    7270    }
    7371
    7472    public void endDocument() {
    75       System.out.println("end document");
     73      //System.out.println("end document");
    7674    }
    7775
    7876    public void startElement(String namespaceURI, String localName, String qname, Attributes attrList) {
    79       System.out.println("start: " + localName);
     77      //System.out.println("start: " + localName);
    8078      if (localName.equals("command")) {
    8179        String name = attrList.getValue("name");
    8280        int argCount = Integer.parseInt(attrList.getValue("argCount"));
    83         Command command = new Command(name, argCount, null, null, null);
    84         commands.put(name, command);
     81        String optionalArg = attrList.getValue("optionalArg");
     82        Command command = new Command(name, argCount, optionalArg, pack, debPack);
     83        commands.add(name, command);
     84      } else
     85      if (localName.equals("package")) {
     86        pack = attrList.getValue("name");
     87        debPack = attrList.getValue("debPackage");
    8588      }
    8689    }
    8790
    8891    public void endElement(String namespaceURI, String localName, String qName) {
    89       System.out.println("end: " + localName);
     92      //System.out.println("end: " + localName);
    9093    }
    9194
    9295    @Override
    9396    public void error(SAXParseException e) throws SAXException {
    94       System.out.println(e.getLineNumber());
     97      //System.out.println(e.getLineNumber());
    9598      super.error(e);
    9699    }
     
    98101    @Override
    99102    public void fatalError(SAXParseException e) throws SAXException {
    100       System.out.println(e.getLineNumber());
     103      //System.out.println(e.getLineNumber());
    101104      super.fatalError(e);
    102105    }
     
    106109    private String name;
    107110    private int argCount;
    108     private String optionalArg = null;
     111    private String optionalArg;
    109112    private String pack;
    110113    private String debPack;
     
    117120      this.debPack = debPack;
    118121    }
     122
     123    @Override
     124    public int hashCode() {
     125      return name.hashCode() + 37*pack.hashCode();
     126    }
     127
     128    @Override
     129    public boolean equals(Object obj) {
     130      if (obj instanceof Command) {
     131        Command that = (Command) obj;
     132        return this.pack.equals(that.pack) && this.name.equals(that.name);
     133      }
     134      return false;
     135    }
    119136  }
    120137}
Note: See TracChangeset for help on using the changeset viewer.