Search in sources :

Example 1 with RecipesIndexXMLWriter

use of delta.games.lotro.lore.crafting.recipes.index.io.xml.RecipesIndexXMLWriter in project lotro-tools by dmorcellet.

the class RecipesIndexBuilder method doIt.

/**
 * Do build recipes index.
 * @return <code>true</code> if it was done, <code>false</code> otherwise.
 */
public boolean doIt() {
    boolean ret = false;
    if (_recipesDir.exists()) {
        RecipesIndex index = new RecipesIndex();
        ExtensionPredicate extFilter = new ExtensionPredicate(".xml");
        File[] recipeFiles = _recipesDir.listFiles(extFilter);
        if (recipeFiles != null) {
            RecipeXMLParser parser = new RecipeXMLParser();
            for (File recipeFile : recipeFiles) {
                Recipe recipe = parser.parseXML(recipeFile);
                String profession = recipe.getProfession();
                String key = recipe.getKey();
                String name = recipe.getName();
                // int id=recipe.getIdentifier();
                int tier = recipe.getTier();
                index.addRecipe(key, name, profession, tier);
            }
            RecipesIndexXMLWriter writer = new RecipesIndexXMLWriter();
            ret = writer.write(_indexFile, index, EncodingNames.UTF_8);
        }
    }
    return ret;
}
Also used : RecipesIndexXMLWriter(delta.games.lotro.lore.crafting.recipes.index.io.xml.RecipesIndexXMLWriter) RecipesIndex(delta.games.lotro.lore.crafting.recipes.index.RecipesIndex) Recipe(delta.games.lotro.lore.crafting.recipes.Recipe) ExtensionPredicate(delta.common.utils.files.filter.ExtensionPredicate) RecipeXMLParser(delta.games.lotro.lore.crafting.recipes.io.xml.RecipeXMLParser) File(java.io.File)

Example 2 with RecipesIndexXMLWriter

use of delta.games.lotro.lore.crafting.recipes.index.io.xml.RecipesIndexXMLWriter in project lotro-tools by dmorcellet.

the class RecipesIndexLoader method doIt.

/**
 * Load recipes index for my.lotro.com and write it to a file.
 * @param indexFile Target file.
 * @return <code>true</code> if it was done, <code>false</code> otherwise.
 */
public boolean doIt(File indexFile) {
    boolean ret = false;
    RecipesIndexJSONParser parser = new RecipesIndexJSONParser();
    RecipesIndex index = parser.parseRecipesIndex();
    if (index != null) {
        RecipesIndexXMLWriter writer = new RecipesIndexXMLWriter();
        ret = writer.write(indexFile, index, "UTF-8");
        if (!ret) {
            _logger.error("Cannot write recipes index file [" + indexFile + "]");
        }
        String[] keys = index.getKeys();
        for (String key : keys) {
            RecipeSummary summary = index.getRecipe(key);
            System.out.println(summary);
        }
        ret = true;
    } else {
        _logger.error("Recipes index is null");
    }
    return ret;
}
Also used : RecipesIndexXMLWriter(delta.games.lotro.lore.crafting.recipes.index.io.xml.RecipesIndexXMLWriter) RecipesIndex(delta.games.lotro.lore.crafting.recipes.index.RecipesIndex) RecipeSummary(delta.games.lotro.lore.crafting.recipes.index.RecipeSummary)

Aggregations

RecipesIndex (delta.games.lotro.lore.crafting.recipes.index.RecipesIndex)2 RecipesIndexXMLWriter (delta.games.lotro.lore.crafting.recipes.index.io.xml.RecipesIndexXMLWriter)2 ExtensionPredicate (delta.common.utils.files.filter.ExtensionPredicate)1 Recipe (delta.games.lotro.lore.crafting.recipes.Recipe)1 RecipeSummary (delta.games.lotro.lore.crafting.recipes.index.RecipeSummary)1 RecipeXMLParser (delta.games.lotro.lore.crafting.recipes.io.xml.RecipeXMLParser)1 File (java.io.File)1