Search in sources :

Example 96 with MagicCard

use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.

the class CSVExport method export.

@Override
public void export(MagicDeck deck, File f) throws IOException {
    exportedDeckProperties = getString("exportedDeckProperties").split(",");
    try (BufferedWriter bw = new BufferedWriter(new FileWriter(f))) {
        bw.write("Main list\n");
        bw.write("Qte;");
        for (String k : exportedDeckProperties) bw.write(k + ";");
        bw.write("\n");
        for (MagicCard mc : deck.getMap().keySet()) {
            bw.write(deck.getMap().get(mc) + ";");
            for (String k : exportedDeckProperties) {
                String val = null;
                try {
                    val = BeanUtils.getProperty(mc, k);
                } catch (Exception e) {
                    logger.error("Error reading bean", e);
                }
                if (val == null)
                    val = "";
                bw.write(val.replaceAll("\n", "") + ";");
            }
            bw.write("\n");
        }
        bw.write("SideBoard\n");
        bw.write("Qte;");
        for (String k : exportedDeckProperties) bw.write(k + ";");
        bw.write("\n");
        for (MagicCard mc : deck.getMapSideBoard().keySet()) {
            bw.write(deck.getMapSideBoard().get(mc) + ";");
            for (String k : exportedDeckProperties) {
                String val = null;
                try {
                    val = BeanUtils.getProperty(mc, k);
                } catch (Exception e) {
                    logger.error("Error reading bean ", e);
                }
                if (val == null)
                    val = "";
                bw.write(val.replaceAll("\n", "") + ";");
            }
            bw.write("\n");
        }
    }
}
Also used : MagicCard(org.magic.api.beans.MagicCard) FileWriter(java.io.FileWriter) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) BufferedWriter(java.io.BufferedWriter)

Example 97 with MagicCard

use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.

the class CSVExport method export.

@Override
public void export(List<MagicCard> cards, File f) throws IOException {
    exportedProperties = getString("exportedProperties").split(",");
    try (BufferedWriter bw = new BufferedWriter(new FileWriter(f))) {
        for (String k : exportedProperties) bw.write(k + ";");
        bw.write("\n");
        for (MagicCard mc : cards) {
            for (String k : exportedProperties) {
                String val = BeanUtils.getProperty(mc, k);
                if (val == null)
                    val = "";
                bw.write(val.replaceAll("\n", "") + ";");
            }
            bw.write("\n");
        }
    } catch (Exception e) {
        throw new IOException(e);
    }
}
Also used : MagicCard(org.magic.api.beans.MagicCard) FileWriter(java.io.FileWriter) IOException(java.io.IOException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) BufferedWriter(java.io.BufferedWriter)

Example 98 with MagicCard

use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.

the class JsonExport method export.

@Override
public void export(MagicDeck deck, File dest) throws IOException {
    JsonObject json = new JsonObject();
    json.addProperty("name", deck.getName());
    json.addProperty("description", deck.getDescription());
    json.addProperty("colors", deck.getColors());
    json.addProperty("averagePrice", deck.getAveragePrice());
    JsonArray tags = new JsonArray();
    for (String s : deck.getTags()) tags.add(s);
    json.add("tags", tags);
    JsonArray main = new JsonArray();
    for (MagicCard mc : deck.getMap().keySet()) {
        JsonObject card = new JsonObject();
        card.addProperty("qty", (Number) deck.getMap().get(mc));
        card.add("card", new Gson().toJsonTree(mc));
        main.add(card);
    }
    JsonArray side = new JsonArray();
    for (MagicCard mc : deck.getMapSideBoard().keySet()) {
        JsonObject card = new JsonObject();
        card.addProperty("qty", (Number) deck.getMapSideBoard().get(mc));
        card.add("card", new Gson().toJsonTree(mc));
        side.add(card);
    }
    json.add("main", main);
    json.add("side", side);
    FileUtils.writeStringToFile(dest, json.toString(), "UTF-8");
}
Also used : JsonArray(com.google.gson.JsonArray) MagicCard(org.magic.api.beans.MagicCard) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson)

Example 99 with MagicCard

use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.

the class MagicWorkStationDeckExport method export.

@Override
public void export(MagicDeck deck, File dest) throws IOException {
    StringBuilder temp = new StringBuilder();
    temp.append("// MAIN\n");
    for (MagicCard mc : deck.getMap().keySet()) {
        temp.append("    ");
        temp.append(deck.getMap().get(mc));
        temp.append(" ");
        temp.append("[").append(mc.getEditions().get(0).getId().toUpperCase()).append("]");
        temp.append(mc.getName());
        temp.append("\n");
    }
    temp.append("// Sideboard\n");
    for (MagicCard mc : deck.getMapSideBoard().keySet()) {
        temp.append("SB: ");
        temp.append(deck.getMap().get(mc));
        temp.append(" ");
        temp.append("[").append(mc.getEditions().get(0).getId()).append("]");
        temp.append(mc.getName());
        temp.append("\n");
    }
    try (FileWriter out = new FileWriter(dest)) {
        out.write(temp.toString());
    }
}
Also used : MagicCard(org.magic.api.beans.MagicCard) FileWriter(java.io.FileWriter)

Example 100 with MagicCard

use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.

the class MkmOnlineExport method export.

@Override
public void export(List<MagicCard> cards, File f) throws IOException {
    MagicDeck d = new MagicDeck();
    for (MagicCard mc : cards) d.getMap().put(mc, Integer.parseInt(getString("DEFAULT_QTE")));
    d.setName(f.getName());
    export(d, f);
}
Also used : MagicCard(org.magic.api.beans.MagicCard) MagicDeck(org.magic.api.beans.MagicDeck)

Aggregations

MagicCard (org.magic.api.beans.MagicCard)106 MagicEdition (org.magic.api.beans.MagicEdition)40 ArrayList (java.util.ArrayList)31 IOException (java.io.IOException)28 MagicDeck (org.magic.api.beans.MagicDeck)21 MagicCollection (org.magic.api.beans.MagicCollection)14 SQLException (java.sql.SQLException)12 Date (java.util.Date)11 MagicCardStock (org.magic.api.beans.MagicCardStock)10 DisplayableCard (org.magic.game.gui.components.DisplayableCard)10 JsonArray (com.google.gson.JsonArray)8 List (java.util.List)8 FileReader (java.io.FileReader)7 Before (org.junit.Before)7 BufferedReader (java.io.BufferedReader)6 File (java.io.File)6 FileWriter (java.io.FileWriter)6 MalformedURLException (java.net.MalformedURLException)6 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6