Search in sources :

Example 26 with CharacterData

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!");
        }
    }
}
Also used : Window(java.awt.Window) CharactersManager(delta.games.lotro.character.CharactersManager) CharacterEvent(delta.games.lotro.character.events.CharacterEvent) CharacterData(delta.games.lotro.character.CharacterData) FileChooserController(delta.games.lotro.utils.gui.filechooser.FileChooserController) CharacterXMLParser(delta.games.lotro.character.io.xml.CharacterXMLParser) CharacterInfosManager(delta.games.lotro.character.CharacterInfosManager) CharacterFile(delta.games.lotro.character.CharacterFile) File(java.io.File) CharacterFile(delta.games.lotro.character.CharacterFile)

Example 27 with CharacterData

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;
}
Also used : CharacterData(delta.games.lotro.character.CharacterData)

Example 28 with CharacterData

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;
}
Also used : CharacterData(delta.games.lotro.character.CharacterData) Element(net.htmlparser.jericho.Element) DownloadService(delta.games.lotro.utils.DownloadService) Source(net.htmlparser.jericho.Source)

Example 29 with CharacterData

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;
}
Also used : CharacterData(delta.games.lotro.character.CharacterData) DownloadService(delta.games.lotro.utils.DownloadService)

Example 30 with CharacterData

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;
}
Also used : CharacterData(delta.games.lotro.character.CharacterData)

Aggregations

CharacterData (delta.games.lotro.character.CharacterData)31 CharacterGenerationTools (delta.games.lotro.character.stats.CharacterGenerationTools)8 JFrame (javax.swing.JFrame)7 CharacterFile (delta.games.lotro.character.CharacterFile)6 CharacterGeneratorMeva (delta.games.lotro.character.stats.CharacterGeneratorMeva)6 BasicStatsSet (delta.games.lotro.character.stats.BasicStatsSet)5 CharacterStatsComputer (delta.games.lotro.character.stats.CharacterStatsComputer)5 CharacterInfosManager (delta.games.lotro.character.CharacterInfosManager)4 CharacterEvent (delta.games.lotro.character.events.CharacterEvent)4 CharacterEventType (delta.games.lotro.character.events.CharacterEventType)4 DefaultWindowController (delta.common.ui.swing.windows.DefaultWindowController)3 EQUIMENT_SLOT (delta.games.lotro.character.CharacterEquipment.EQUIMENT_SLOT)3 CharacterClass (delta.games.lotro.common.CharacterClass)3 File (java.io.File)3 JPanel (javax.swing.JPanel)3 WindowController (delta.common.ui.swing.windows.WindowController)2 CharacterEquipment (delta.games.lotro.character.CharacterEquipment)2 CharactersManager (delta.games.lotro.character.CharactersManager)2 LotroTestUtils (delta.games.lotro.character.log.LotroTestUtils)2 CharacterGeneratorGiswald (delta.games.lotro.character.stats.CharacterGeneratorGiswald)2