use of delta.games.lotro.character.CharacterData in project lotro-companion by dmorcellet.
the class ToonsManagementController method importToon.
private void importToon() {
FileChooserController ctrl = new FileChooserController("import", "Import character...");
Window window = _parentController.getWindow();
File fromFile = ctrl.chooseFile(window, "Import");
if (fromFile != null) {
CharacterXMLParser parser = new CharacterXMLParser();
CharacterData data = new CharacterData();
boolean ok = parser.parseXML(fromFile, data);
if (ok) {
CharactersManager manager = CharactersManager.getInstance();
CharacterFile toon = manager.getToonById(data.getServer(), data.getName());
if (toon != null) {
CharacterInfosManager infos = toon.getInfosManager();
ok = infos.writeNewCharacterData(data);
if (ok) {
CharacterEvent event = new CharacterEvent(CharacterEventType.CHARACTER_DATA_ADDED, toon, data);
EventsManager.invokeEvent(event);
}
} else {
CharacterFile newFile = manager.addToon(data);
ok = (newFile != null);
}
if (ok) {
GuiFactory.showInformationDialog(window, "Import OK!", "OK!");
} else {
GuiFactory.showErrorDialog(window, "Import failed!", "Error!");
}
} else {
GuiFactory.showErrorDialog(window, "Import failed (bad XML file)!", "Error!");
}
}
}
use of delta.games.lotro.character.CharacterData in project lotro-tools by dmorcellet.
the class CharacterPageParser method parseMainPage.
/**
* Parse the character page at the given URL.
* @param name Toon name.
* @param url URL of character page.
* @return A character or <code>null</code> if an error occurred..
*/
public CharacterData parseMainPage(String name, String url) {
CharacterData ret = null;
int maxTries = 3;
int retryNumber = 0;
while (retryNumber < maxTries) {
CharacterData subRet = parseMainPage(name, url, retryNumber);
if (subRet != null) {
ret = subRet;
break;
}
retryNumber++;
}
if (ret == null) {
if (_logger.isEnabledFor(Level.ERROR)) {
_logger.error("Cannot parse character description page url=[" + url + "] name=[" + name + "]");
}
}
return ret;
}
use of delta.games.lotro.character.CharacterData in project lotro-tools by dmorcellet.
the class CharacterPageParser method parseMainPage.
/**
* Parse the character page at the given URL.
* @param name Toon name.
* @param url URL of character page.
* @param retryNumber Number of previous tries.
* @return A character or <code>null</code> if an error occurred..
*/
private CharacterData parseMainPage(String name, String url, int retryNumber) {
if (_logger.isInfoEnabled()) {
_logger.info("Character description page parsing for toon [" + name + "] " + ((retryNumber > 0) ? " try #" + retryNumber : ""));
}
CharacterData ret = null;
try {
DownloadService downloader = DownloadService.getInstance();
String page = downloader.getPage(url);
Source source = new Source(page);
_character = null;
// <table class="char_panel freep">
Element charPanel = JerichoHtmlUtils.findElementByTagNameAndAttributeValue(source, HTMLElementName.TABLE, "class", "char_panel freep");
if (charPanel != null) {
_character = new CharacterData();
parseCharacterDescription(charPanel);
parseStats(charPanel);
}
ret = _character;
_character = null;
} catch (Exception e) {
if (_logger.isInfoEnabled()) {
_logger.info("Cannot parse character page [" + url + "]", e);
}
}
return ret;
}
use of delta.games.lotro.character.CharacterData in project lotro-tools by dmorcellet.
the class DataLotroCharacterPageParser method parseMainPage.
/**
* Parse the character page at the given URL.
* @param name Toon name.
* @param url URL of character page.
* @param retryNumber Number of previous tries.
* @return A character or <code>null</code> if an error occurred..
*/
private CharacterData parseMainPage(String name, String url, int retryNumber) {
if (_logger.isInfoEnabled()) {
_logger.info("Character description page parsing for toon [" + name + "] " + ((retryNumber > 0) ? " try #" + retryNumber : ""));
}
CharacterData ret = null;
try {
DownloadService downloader = DownloadService.getInstance();
byte[] page = downloader.getBuffer(url);
ret = parseCharacter(page);
} catch (Exception e) {
if (_logger.isInfoEnabled()) {
_logger.info("Cannot parse character page [" + url + "]", e);
}
}
return ret;
}
use of delta.games.lotro.character.CharacterData in project lotro-tools by dmorcellet.
the class DataLotroCharacterPageParser method parseMainPage.
/**
* Parse the character page at the given URL.
* @param name Toon name.
* @param url URL of character page.
* @return A character or <code>null</code> if an error occurred..
*/
public CharacterData parseMainPage(String name, String url) {
CharacterData ret = null;
int maxTries = 3;
int retryNumber = 0;
while (retryNumber < maxTries) {
CharacterData subRet = parseMainPage(name, url, retryNumber);
if (subRet != null) {
ret = subRet;
break;
}
retryNumber++;
}
if (ret == null) {
if (_logger.isEnabledFor(Level.ERROR)) {
_logger.error("Cannot parse character description page url=[" + url + "] name=[" + name + "]");
}
}
return ret;
}
Aggregations