Search in sources :

Example 1 with RecipeXMLWriter

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

the class RecipesLoader method loadRecipeDefinition.

/**
 * Load recipe definition.
 * @param key Recipe key.
 * @return Number of loaded recipes.
 */
private int loadRecipeDefinition(String key) {
    int nbRecipes = 0;
    RecipePageParser parser = new RecipePageParser();
    String escapedKey = Escapes.escapeIdentifier(key);
    String url = "http://lorebook.lotro.com/wiki/Recipe:" + escapedKey;
    List<Recipe> recipes = parser.parseRecipePage(url);
    if ((recipes != null) && (recipes.size() > 0)) {
        RecipeXMLWriter writer = new RecipeXMLWriter();
        for (Recipe recipe : recipes) {
            // Write recipe
            int id = recipe.getIdentifier();
            String fileName = String.valueOf(id) + ".xml";
            File recipeFile = new File(_recipesDir, fileName);
            if (!recipeFile.getParentFile().exists()) {
                recipeFile.getParentFile().mkdirs();
            }
            String name = recipe.getName();
            boolean ok = writer.write(recipeFile, recipe, EncodingNames.UTF_8);
            if (ok) {
                System.out.println("Wrote recipe [" + name + "]");
                nbRecipes++;
            } else {
                _logger.error("Write failed for recipe [" + name + "] (id=" + id + ")!");
            }
        }
    } else {
        _logger.error("No recipe for URL [" + url + "]");
    }
    return nbRecipes;
}
Also used : Recipe(delta.games.lotro.lore.crafting.recipes.Recipe) RecipeXMLWriter(delta.games.lotro.lore.crafting.recipes.io.xml.RecipeXMLWriter) File(java.io.File)

Aggregations

Recipe (delta.games.lotro.lore.crafting.recipes.Recipe)1 RecipeXMLWriter (delta.games.lotro.lore.crafting.recipes.io.xml.RecipeXMLWriter)1 File (java.io.File)1