Электронный магазин на Java и XML

         

Завершение кода...



Листинг 7.19. Завершение кода класса Interpreter (Interpreter.Java)

private Node setQnodeInBlock( int n ){ Element E = (Element) nowBlock ; NodeList nl = E.getElementsByTagName("Ques");
nowNode = nl.item( n );
return nowNode ; } //public String getTitle(){return title;} //public String getCSS(){return css ; } public String getIntro() { Element E = theDom.getDocumentElement();
// the root NodeList nl = E.getElementsByTagName("Intro");
Element I = (Element)nl.item(0);
nl = I.getChildNodes();
int ct = nl.getLength();
if( ct == 0 ) return "Bad Intro Data<br>
" ; return nl.item(0).getNodeValue();
} // return String if any chosen opt has a branch="", else null private String branchLookUp( NodeList oplist,String[] optS ){ if( optS == null || optS.length == 0 ) return null ; Hashtable opHash = new Hashtable();
int i, ct = oplist.getLength();
String val, branch ; for( i = 0 ; i < ct ;i++ ){ val = ((Element)oplist.item(i)).getAttribute("val");
branch = ((Element)oplist.item(i)).getAttribute("branch");
opHash.put( val, branch );
// branch = "" if no attribute } if( opHash.size() == 0 ) return null ; // branch not possible for( i = 0 ; i < optS.length ; i++ ){ branch = (String)opHash.get( optS[i] );
if( branch != null && branch.length() >
0 ) return branch ; } return null ; } public String toString() { StringBuffer sb = new StringBuffer("Interpreter ");
return sb.toString() ; } }



Содержание раздела