Changeset 9303

Show
Ignore:
Timestamp:
05/14/08 20:49:54 (3 months ago)
Author:
dfhuynh
Message:

Switched to using org.json parsing code from Rhino since Rhino doesn't deal with really long source files, apparently.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • collector/trunk/src/main/java/ScrapeReferrers.java

    r9302 r9303  
    1515import java.util.Set; 
    1616 
     17import org.json.JSONArray; 
     18import org.json.JSONException; 
     19import org.json.JSONObject; 
     20import org.json.JSONTokener; 
    1721import org.mozilla.javascript.Context; 
    1822import org.mozilla.javascript.Scriptable; 
     
    107111                         
    108112                        StringBuffer sb = new StringBuffer(); 
    109                         sb.append('('); 
    110                          
    111113                        try { 
    112114                                Writer fileWriter = new BufferedWriter(new FileWriter(outFile)); 
     
    119121                                        } 
    120122                                         
    121                                         sb.append(')'); 
    122                                          
    123123                                        success = true; 
    124124                                         
    125                                         Scriptable o = evaluateJsonStringToObject(sb.toString(), outFile); 
    126                                         Scriptable statsO = (Scriptable) o.get("_stats", o); 
    127                                         title = (String) statsO.get("title", statsO); 
    128                                         error = (String) statsO.get("error", statsO); 
     125                                        JSONObject o = evaluateJsonStringToObject(sb.toString()); 
     126                                        JSONObject statsO = o.getJSONObject("_stats"); 
     127                                        title = statsO.getString("title"); 
     128                                        error = statsO.getString("error"); 
    129129                                         
    130                                         success = (Boolean) statsO.get("success", statsO); 
    131                                         exhibitDetected = (Boolean) statsO.get("detectsExhibit", statsO); 
    132                                         lastModified = (String) statsO.get("lastModified", statsO); 
    133                                         version = ((Number) statsO.get("version", statsO)).intValue(); 
     130                                        success = statsO.getBoolean("success"); 
     131                                        exhibitDetected = statsO.getBoolean("detectsExhibit"); 
     132                                        lastModified = statsO.getString("lastModified"); 
     133                                        version = statsO.getInt("version"); 
    134134                                                 
    135135                                        if (exhibitDetected) { 
    136                                                 Scriptable itemsO = (Scriptable) o.get("items", o); 
     136                                                JSONArray itemsO = o.getJSONArray("items"); 
    137137                                                 
    138                                                 itemCount = ((Number) itemsO.get("length", itemsO)).intValue(); 
     138                                                itemCount = itemsO.length(); 
    139139                                        } 
    140140                                } finally { 
     
    168168    } 
    169169     
    170     static private Scriptable evaluateJsonStringToObject(String s, File file) throws IOException { 
    171         return (Scriptable) _context.evaluateString(_scope, s, file.getAbsolutePath(), 1, null); 
     170    static private JSONObject evaluateJsonStringToObject(String s) throws JSONException { 
     171        JSONTokener t = new JSONTokener(s); 
     172        JSONObject o = (JSONObject) t.nextValue(); 
     173        return o; 
    172174    } 
    173175}