package net.traviangui.hostInterface;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import net.traviangui.model.MapSquareType;
import org.htmlcleaner.CleanerProperties;
import org.htmlcleaner.HtmlCleaner;
import org.htmlcleaner.TagNode;
public class IOMap
{
public static URL getSquareUrl( int coordX, int coordY) throws Exception
{
// 1. get standard map
// 2. goto (x,y)
// String page = HttpServer.getHttpServer().getMapPage( coordX, coordY);
HtmlCleaner cleaner = new HtmlCleaner();
CleanerProperties props = cleaner.getProperties();
props.setRecognizeUnicodeChars( true);
TagNode node = cleaner.clean( new File("tests/karte.htm"));
// TagNode node = cleaner.clean( page);
return getSquareUrl2( node);
}
private static URL getSquareUrl2( TagNode node) throws Exception
{
// Object[] dom = node.evaluateXPath( "//div[@id='mid']//div[@id='content']/h1/text()");
Object[] domUrl = node.evaluateXPath( "//area[@id='a_3_3']/@href");
return new URL( HttpServer.getFullUrl( (String)domUrl[0]));
}
public static MapSquareType getSquareType( URL url) throws Exception
{
// 1. get overview/innerview pantalla actual
// String page = HttpServer.getHttpServer().httpGetPage( url.toString().replace( "&", "&"));
Thread.sleep( (long) (1000 + 2000*Math.random()));
HtmlCleaner cleaner = new HtmlCleaner();
CleanerProperties props = cleaner.getProperties();
props.setRecognizeUnicodeChars( true);
TagNode node = cleaner.clean( new File("tests/karte_village.htm"));
// TagNode node = cleaner.clean( page);
return getSquareType2( node);
}
private static MapSquareType getSquareType2( TagNode node) throws Exception
{
// Object[] dom = node.evaluateXPath( "//div[@id='mid']//div[@id='content']/h1/text()");
Object[] domType = node.evaluateXPath( "//img[@id='detailed_map']/@title");
return MapSquareType.getByType( (String)domType[0]);
}
}