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 java.util.ArrayList; 009 import org.util.xml.parse.ElementParser; 010 011 /** 012 * 013 * @author masaru 014 */ 015 public class EqParser extends ParseElement { 016 017 private SpaceParser space_parser_; 018 019 @Override 020 public boolean match(char c) { 021 return (isSpace(c) || c=='='); 022 } 023 024 @Override 025 public int parse(int c, ElementParser parser) throws Exception { 026 if(space_parser_==null) space_parser_ = new SpaceParser(); 027 int next_word_ = -1; 028 int state = 0; 029 while(true) { 030 if(state == 0) { 031 if(isSpace(c)) ; 032 else if(c=='=') state = 1; 033 else { 034 parser.error(this); 035 return escape(parser, "cannot read = ("+(char)c+")"); 036 } 037 }else if(state == 1) { 038 if(isSpace(c)) ; 039 else { 040 next_word_ = c; 041 break; 042 } 043 } 044 c = parser.getChar(); 045 } 046 return next_word_; 047 } 048 049 @Override 050 public void listDependentParser(ArrayList<ParseElement> list) { 051 for(int i=0;i<list.size();i++) 052 if(list.get(i) instanceof SpaceParser) { 053 space_parser_ = (SpaceParser)list.get(i); 054 return; 055 } 056 space_parser_ = new SpaceParser(); 057 list.add(space_parser_); 058 } 059 public int escape (ElementParser parser,String message) throws Exception { 060 try{throw new Exception("mark");}catch(Exception e){e.printStackTrace();} 061 System.out.println("this documents has error."+message); 062 System.out.println("skip---------------------"); 063 int c = parser.get(); 064 while(c!='>' && c!=-1) System.out.print((char)(c=parser.get())); 065 System.out.println("\n-------------------------"); 066 return parser.get(); 067 } 068 }