Advertisement
Guest User

jsonUI.java

a guest
Jun 23rd, 2012
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.81 KB | None | 0 0
  1. /**
  2.  * Copyright (c) 2005-2012, KoLmafia development team
  3.  * http://kolmafia.sourceforge.net/
  4.  * All rights reserved.
  5.  *
  6.  * Redistribution and use in source and binary forms, with or without
  7.  * modification, are permitted provided that the following conditions
  8.  * are met:
  9.  *
  10.  *  [1] Redistributions of source code must retain the above copyright
  11.  *      notice, this list of conditions and the following disclaimer.
  12.  *  [2] Redistributions in binary form must reproduce the above copyright
  13.  *      notice, this list of conditions and the following disclaimer in
  14.  *      the documentation and/or other materials provided with the
  15.  *      distribution.
  16.  *  [3] Neither the name "KoLmafia" nor the names of its contributors may
  17.  *      be used to endorse or promote products derived from this software
  18.  *      without specific prior written permission.
  19.  *
  20.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  23.  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  24.  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  25.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  26.  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  27.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  28.  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  30.  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  31.  * POSSIBILITY OF SUCH DAMAGE.
  32.  */
  33.  
  34. package net.sourceforge.kolmafia.webui;
  35.  
  36. import net.sourceforge.kolmafia.persistence.AdventureDatabase;
  37. import net.sourceforge.kolmafia.utilities.StringArray;
  38.  
  39. import org.json.*;
  40. import java.io.*;
  41.  
  42. import javax.swing.JOptionPane;
  43.  
  44. public class jsonWebUI
  45. {
  46.     private static StringArray[] adventureTableJSON = new StringArray[ 2 ];
  47.    
  48.     public static final void makeAdventuresJSON()
  49.     {
  50.     adventureTableJSON[0] = AdventureDatabase.adventureTable[0];
  51.     adventureTableJSON[1] = AdventureDatabase.adventureTable[3];
  52.    
  53.     JSONStringer mJSONAdventures = new JSONStringer();
  54.     try {
  55.         mJSONAdventures.array();
  56.     } catch (JSONException e) {
  57.         e.printStackTrace();
  58.     }
  59.     for (int i = 0; i < adventureTableJSON[0].size(); i++)
  60.     {
  61.         try {
  62.             mJSONAdventures.object()
  63.                 .key("Zone")
  64.                 .value(adventureTableJSON[0].get(i))
  65.                 .key("Location")
  66.                 .value(adventureTableJSON[1].get(i))
  67.                 .endObject();
  68.         } catch (JSONException e) { }
  69.     }
  70.     try {
  71.         mJSONAdventures.endArray();
  72.     } catch (JSONException e) { }
  73.     String JSONdata = mJSONAdventures.toString();
  74.    
  75.     try {
  76.         FileWriter fstream = new FileWriter("relay/adventures.json");
  77.         BufferedWriter out = new BufferedWriter(fstream);
  78.         out.write(JSONdata);
  79.         out.close();
  80.     } catch (IOException e) {
  81.         JOptionPane.showMessageDialog(null, "problem making relay/adventure.json" );
  82.         e.printStackTrace();
  83.     }
  84.        
  85.     }
  86.     public static final void buildInvJSON()
  87.     {
  88.     JSONStringer mJSONInv = new JSONStringer();
  89.     try {
  90.         mJSONInv.array();
  91.     } catch (JSONException e) {
  92.         e.printStackTrace();
  93.     }
  94. //  for (int i = 0; i < adventureTableJSON[0].size(); i++)
  95.     {
  96.         try {
  97.             mJSONInv.object()
  98.                 .key("Item")
  99. //              .value(adventureTableJSON[0].get(i))
  100.                 .key("Quanity")
  101. //              .value(adventureTableJSON[1].get(i))
  102.                 .endObject();
  103.         } catch (JSONException e) { }
  104.     }
  105.     try {
  106.         mJSONInv.endArray();
  107.     } catch (JSONException e) { }
  108.     String JSONdata = mJSONInv.toString();
  109.    
  110.     try {
  111.         FileWriter fstream = new FileWriter("relay/Inv.json");
  112.         BufferedWriter out = new BufferedWriter(fstream);
  113.         out.write(JSONdata);
  114.         out.close();
  115.     } catch (IOException e) {
  116.         JOptionPane.showMessageDialog(null, "problem making relay/inv.json" );
  117.     }
  118.     }
  119.  
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement