package org.couchbase.mock.views;
import java.util.ArrayList;
import java.util.Set;
import javax.script.ScriptException;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
private String body;
private String id;
private ArrayList<View> views;
try {
this.body = body;
JsonConfig cfg = new JsonConfig();
cfg.clearJsonValueProcessors();
JSONObject json = (JSONObject) JSONObject.fromObject(body, cfg);
this.id = json.getString("_id");
this.views = new ArrayList<View>();
JSONObject viewsJson = (JSONObject) json.getJSONObject("views");
for (String viewName : (Set<String>) viewsJson.keySet()) {
JSONObject view = (JSONObject) viewsJson.getJSONObject(viewName);
String mapSrc = view.getString("map");
String reduceSrc = null;
try {
reduceSrc = view.getString("reduce");
} catch (JSONException _) {
}
views.add(new View(viewName, mapSrc, reduceSrc));
}
} catch (ScriptException ex) {
} catch (JSONException ex) {
throw new IllegalArgumentException("Incomplete document body", ex);
}
}
return body;
}
return id;
}
return views;
}
}