Search in sources :

Example 1 with QuestXMLWriter

use of delta.games.lotro.lore.quests.io.xml.QuestXMLWriter in project lotro-tools by dmorcellet.

the class QuestsLoader method loadQuestsDefinition.

/**
 * Load quest definitions.
 * @param key Quest key.
 * @return Number of loaded quests.
 */
private int loadQuestsDefinition(String key) {
    int nbQuests = 0;
    QuestPageParser parser = new QuestPageParser();
    String url = urlFromIdentifier(key);
    List<QuestDescription> quests = parser.parseQuestPage(url);
    if ((quests != null) && (quests.size() > 0)) {
        QuestXMLWriter writer = new QuestXMLWriter();
        for (QuestDescription quest : quests) {
            int id = quest.getIdentifier();
            String fileName = String.valueOf(id) + ".xml";
            File questFile = new File(_questsDir, fileName);
            if (!questFile.getParentFile().exists()) {
                questFile.getParentFile().mkdirs();
            }
            boolean ok = writer.write(questFile, quest, EncodingNames.UTF_8);
            if (ok) {
                nbQuests++;
            } else {
                String title = quest.getTitle();
                _logger.error("Write failed for quest [" + title + "]!");
            }
        }
    } else {
        _logger.error("Cannot parse quests [" + key + "] at URL [" + url + "]!");
    }
    return nbQuests;
}
Also used : QuestDescription(delta.games.lotro.lore.quests.QuestDescription) QuestXMLWriter(delta.games.lotro.lore.quests.io.xml.QuestXMLWriter) File(java.io.File)

Example 2 with QuestXMLWriter

use of delta.games.lotro.lore.quests.io.xml.QuestXMLWriter in project lotro-tools by dmorcellet.

the class QuestsItemsLoader method writeQuestsDatabase.

private void writeQuestsDatabase(List<QuestDescription> quests) {
    QuestsDatabaseGenerator dbBuilder = new QuestsDatabaseGenerator();
    File questsDir = dbBuilder.getQuestsDir();
    questsDir.mkdirs();
    QuestXMLWriter writer = new QuestXMLWriter();
    for (QuestDescription quest : quests) {
        int id = quest.getIdentifier();
        String fileName = String.valueOf(id) + ".xml";
        File questFile = new File(questsDir, fileName);
        writer.write(questFile, quest, EncodingNames.UTF_8);
    }
    dbBuilder.writeDatabase();
}
Also used : QuestDescription(delta.games.lotro.lore.quests.QuestDescription) QuestXMLWriter(delta.games.lotro.lore.quests.io.xml.QuestXMLWriter) File(java.io.File)

Aggregations

QuestDescription (delta.games.lotro.lore.quests.QuestDescription)2 QuestXMLWriter (delta.games.lotro.lore.quests.io.xml.QuestXMLWriter)2 File (java.io.File)2