package eos.dom.client;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import eos.dom.CardId;
import eos.dom.DomGame;
public class DomSAXHandler implements ContentHandler {
public DomGame game;
public DomSAXHandler(DomGame game){
this.game = game;
}
@Override
public void characters(char[] arg0, int arg1, int arg2) throws SAXException {
}
@Override
public void endDocument() throws SAXException {
}
@Override
public void endElement(String arg0, String arg1, String arg2)
throws SAXException {
}
@Override
public void endPrefixMapping(String arg0) throws SAXException {
// TODO Auto-generated method stub
}
@Override
public void ignorableWhitespace(char[] arg0, int arg1, int arg2)
throws SAXException {
// TODO Auto-generated method stub
}
@Override
public void processingInstruction(String arg0, String arg1)
throws SAXException {
// TODO Auto-generated method stub
}
@Override
public void setDocumentLocator(Locator arg0) {
// TODO Auto-generated method stub
}
@Override
public void skippedEntity(String arg0) throws SAXException {
// TODO Auto-generated method stub
}
@Override
public void startDocument() throws SAXException {
// TODO Auto-generated method stub
}
@Override
public void startElement(String arg0, String localName, String arg2,
Attributes attr) throws SAXException {
if(localName.equals("Royaume")){
if(attr.getValue("CardId").equals(CardId.COPPER.ordinal()+"")){
game.gameInfo.setCopper(Integer.parseInt(attr.getValue("Nb")));
}else if(attr.getValue("CardId").equals(CardId.SILVER.ordinal()+"")){
game.gameInfo.setSilver(Integer.parseInt(attr.getValue("Nb")));
}else if(attr.getValue("CardId").equals(CardId.GOLD.ordinal()+"")){
game.gameInfo.setGold(Integer.parseInt(attr.getValue("Nb")));
}else if(attr.getValue("CardId").equals(CardId.ESTATE.ordinal()+"")){
game.gameInfo.setEstate(Integer.parseInt(attr.getValue("Nb")));
}else if(attr.getValue("CardId").equals(CardId.DUCHY.ordinal()+"")){
game.gameInfo.setDuchy(Integer.parseInt(attr.getValue("Nb")));
}else if(attr.getValue("CardId").equals(CardId.PROVINCE.ordinal()+"")){
game.gameInfo.setProvince(Integer.parseInt(attr.getValue("Nb")));
}else if(attr.getValue("CardId").equals(CardId.CURSE.ordinal()+"")){
game.gameInfo.setCurse(Integer.parseInt(attr.getValue("Nb")));
}else if(attr.getValue("CardId").equals(CardId.POTION.ordinal()+"")){
game.gameInfo.setPotion(Integer.parseInt(attr.getValue("Nb")));
}else{
game.gameInfo.addK(Integer.parseInt(attr.getValue("CardId")));
game.gameInfo.addKnum(Integer.parseInt(attr.getValue("Nb")));
}
}else if(localName.equals("Card")){
game.gameInfo.addHand(Integer.parseInt(attr.getValue("CardId")));
}else if(localName.equals("Player")){
game.gameInfo.addPlayer(attr.getValue("Name"), Integer.parseInt(attr.getValue("NbCard")));
}else if(localName.equals("HasToWait")){
game.gameInfo.setHasToWait(true);
}else if(localName.equals("Masquerade")){
game.gameInfo.setMasquerade(true);
}else if(localName.equals("HasToDiscard")){
game.gameInfo.setNbCardToDiscard(Integer.parseInt(attr.getValue("Value")));
}else if(localName.equals("HasToDiscardOrCurse")){
game.gameInfo.setNbCardToDiscardOrCurse(Integer.parseInt(attr.getValue("Value")));
}else if(localName.equals("GameStarted")){
game.gameInfo.setGameStarted(true);
}
}
@Override
public void startPrefixMapping(String arg0, String arg1)
throws SAXException {
// TODO Auto-generated method stub
}
}
|