/*
 *  (c) 2012 University of Bolton
 *  
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 * limitations under the License.
 */
package uk.ac.bolton.spaws.model.util;

import org.json.JSONException;
import org.json.JSONObject;

import uk.ac.bolton.spaws.model.impl.Actor;

public class ActorFactory {

	public static Actor createActor(JSONObject document) throws JSONException{
		
		if (document.has("resource_data")){
			if (document.getJSONObject("resource_data").has("activity")){
				JSONObject activity = document.getJSONObject("resource_data").getJSONObject("activity");
				if (activity.has("actor")){
					Actor actor = new Actor();
					actor.setName(activity.getJSONObject("actor").getString("displayName"));
					actor.setUrl(activity.getJSONObject("actor").getString("url"));
					return actor;
				}
			}
		}
		return null;
		
	}
	
}

@@ -1124,22 +1124,31 @@
 %09%09%09%09
-actor.setName(
+JSONObject jsonActor = 
 acti
@@ -1166,32 +1166,62 @@
 NObject(%22actor%22)
+;%0A%09%09%09%09%09actor.setName(jsonActor
 .getString(%22disp
@@ -1241,52 +1241,62 @@
 %09%09%09%09
-actor.setUrl(activity.getJSONObject(%22a
+if(jsonActor.has(%22url%22))%7B%0A%09%09%09%09%09%09actor.setUrl(jsonA
 ctor
-%22)
 .get
@@ -1307,24 +1307,31 @@
 ng(%22url%22));%0A
+%09%09%09%09%09%7D%0A
 %09%09%09%09%09return 

Check for existence of URL when parsing actor info