001 /* 002 * To change this template, choose Tools | Templates 003 * and open the template in the editor. 004 */ 005 006 package org.util.xml.parse; 007 008 import org.util.xml.element.Attribute; 009 import org.util.xml.parse.ElementParser; 010 011 /** 012 * 013 * @author masaru 014 */ 015 public class AttributeParser extends ParseElement { 016 017 private NameParser name_parser_; 018 private EqParser eq_parser_; 019 private AttValueParser attvalue_parser_; 020 private SpaceParser space_parser_; 021 private Attribute attribute_; 022 023 public AttributeParser() { 024 name_parser_ = new NameParser(); 025 eq_parser_ = new EqParser(); 026 attvalue_parser_ = new AttValueParser(); 027 space_parser_ = new SpaceParser(); 028 } 029 public boolean match(char c) { 030 return name_parser_.allow(c); 031 } 032 033 public int parse(int next, ElementParser parser) throws Exception { 034 String name = null, value = null; 035 036 if(next==-1) throw new Exception("end of line"); 037 next = name_parser_.parse((char)next, parser); 038 name = name_parser_.getReturnValue(); 039 040 if(next==-1) throw new Exception("end of line"); 041 042 // next = eq_parser_.parse((char)next, parser); 043 044 // System.out.print("<"+name+":"+(char)next); 045 if(space_parser_.match((char)next)) 046 next = space_parser_.parse(next, parser); 047 048 if(next==-1) throw new Exception("end of line"); 049 050 if(next=='=') { 051 next = parser.getChar(); 052 if(space_parser_.match((char)next)) 053 next = space_parser_.parse(next, parser); 054 if(next==-1) throw new Exception("end of line"); 055 next = attvalue_parser_.parse(next, parser); 056 value = attvalue_parser_.getReturnValue(); 057 attribute_ = new Attribute(name, value); 058 } else { 059 attribute_ = new Attribute(name, ""); 060 attribute_.setNoValue(true); 061 } 062 063 // System.out.println((char)next+">"); 064 065 066 return next; 067 } 068 public Attribute getAttribute() { 069 return attribute_; 070 } 071 }