public class BrowseConfig extends Config {
	public String type;
	public String typeFilter;
	public String category;
	public String tag;
	public String filter;
	public String sort;
	
	public String toXML() {
		StringWriter writer = new StringWriter();
		writer.write("<browse");
		writeCredentials(writer);
		writer.write(" type=\"" + this.type + "\"");
		if (this.typeFilter != null) {
			writer.write(" typeFilter=\"" + this.typeFilter + "\"");
		}
		if (this.sort != null) {
			writer.write(" sort=\"" + this.sort + "\"");
		}
		if ((this.category != null) && !this.category.equals("")) {
			writer.write(" category=\"" + this.category + "\"");
		}
		if ((this.tag != null) && !this.tag.equals("")) {
			writer.write(" tag=\"" + this.tag + "\"");
		}
		if ((this.filter != null) && !this.filter.equals("")) {
			writer.write(" filter=\"" + this.filter + "\"");
		}
		writer.write("/>");
		return writer.toString();
	}
} public class ChannelConfig extends WebMediumConfig {
	public String type;
	public String messages;
	public String usersOnline;
	public String adminsOnline;
	
	public String getType() {
		return "channel";
	}

	@Override
	public String stats() {
		return this.usersOnline + " users online, " + this.adminsOnline + " admins";
	}
	
	public WebMediumConfig credentials() {
		ChannelConfig config = new ChannelConfig();
		config.id = this.id;
		return config;
	}
	
	public String toXML() {
		StringWriter writer = new StringWriter();
		writer.write("<channel");
		if (this.type != null && !this.type.equals("")) {
			writer.write(" type=\"" + this.type + "\"");
		}
		writeXML(writer);
		writer.write("</channel>");
		return writer.toString();
	}
	
	public void parseXML(Element element) {
		super.parseXML(element);
		this.type = element.getAttribute("type");
		this.messages = element.getAttribute("messages");
		this.usersOnline = element.getAttribute("usersOnline");
		this.adminsOnline = element.getAttribute("adminsOnline");
	}
} public class ChatConfig extends Config {	
	public String conversation;
	public boolean correction;
	public boolean offensive;
	public boolean disconnect;
	public String emote;
	public String action;
	public String message;
	public boolean speak;
	public boolean includeQuestion;
	
	public String toXML() {
		StringWriter writer = new StringWriter();
		writer.write("<chat");
		writeCredentials(writer);
		if (this.conversation != null) {
			writer.write(" conversation=\"" + this.conversation + "\"");
		}
		if (this.emote != null) {
			writer.write(" emote=\"" + this.emote + "\"");
		}
		if (this.action != null) {
			writer.write(" action=\"" + this.action + "\"");
		}
		if (this.correction) {
			writer.write(" correction=\"" + this.correction + "\"");
		}
		if (this.offensive) {
			writer.write(" offensive=\"" + this.offensive + "\"");
		}
		if (this.speak) {
			writer.write(" speak=\"" + this.speak + "\"");
		}
		if (this.includeQuestion) {
			writer.write(" includeQuestion=\"" + this.includeQuestion + "\"");
		}
		if (this.disconnect) {
			writer.write(" disconnect=\"" + this.disconnect + "\"");
		}
		writer.write(">");
		
		if (this.message != null) {
			writer.write("<message>");
			writer.write(this.message);
			writer.write("</message>");
		}
		writer.write("</chat>");
		return writer.toString();
	}
} public class ChatResponse extends Config {	
	public String conversation;
	public String message;
	public String question;
	public String emote;
	public String action;
	public String pose;
	public String avatar;
	public String avatarType;
	public String avatarTalk;
	public String avatarTalkType;
	public String avatarAction;
	public String avatarActionType;
	public String avatarActionAudio;
	public String avatarActionAudioType;
	public String avatarAudio;
	public String avatarAudioType;
	public String avatarBackground;
	public String speech;
	
	public boolean isVideo() {
		return this.avatarType != null && this.avatarType.indexOf("video") != -1;
	}

	public void parseXML(Element element) {
		this.conversation = element.getAttribute("conversation");
		this.emote = element.getAttribute("emote");
		this.action = element.getAttribute("action");
		this.pose = element.getAttribute("pose");
		this.avatar = element.getAttribute("avatar");
		this.avatarType = element.getAttribute("avatarType");
		this.avatarTalk = element.getAttribute("avatarTalk");
		this.avatarTalkType = element.getAttribute("avatarTalkType");
		this.avatarAction = element.getAttribute("avatarAction");
		this.avatarActionType = element.getAttribute("avatarActionType");
		this.avatarActionAudio = element.getAttribute("avatarActionAudio");
		this.avatarActionAudioType = element.getAttribute("avatarActionAudioType");
		this.avatarAudio = element.getAttribute("avatarAudio");
		this.avatarAudioType = element.getAttribute("avatarAudioType");
		this.avatarBackground = element.getAttribute("avatarBackground");
		this.speech = element.getAttribute("speech");

		Node node = element.getElementsByTagName("message").item(0);
		if (node != null) {
			this.message = node.getTextContent();
		}
		node = element.getElementsByTagName("question").item(0);
		if (node != null) {
			this.question = node.getTextContent();
		}
	}
} public class ContentConfig extends Config {
	
	public String type;	
	
	public void parseXML(Element element) {
		super.parseXML(element);
		
		this.type = element.getAttribute("type");
	}

	
	public String toXML() {
		StringWriter writer = new StringWriter();
		writer.write("<content");
		writeCredentials(writer);

		if (this.type != null) {
			writer.write(" type=\"" + this.type + "\"");
		}
		
		writer.write("/>");
		return writer.toString();
	}
} public class DomainConfig extends WebMediumConfig {
	public String creationMode;
	
	public String getType() {
		return "domain";
	}
	
	public WebMediumConfig credentials() {
		DomainConfig config = new DomainConfig();
		config.id = this.id;
		return config;
	}
	
	public String toXML() {
		StringWriter writer = new StringWriter();
		writer.write("<domain");
		if (this.creationMode != null && !this.creationMode.equals("")) {
			writer.write(" creationMode=\"" + this.creationMode + "\"");
		}
		writeXML(writer);
		writer.write("</domain>");
		return writer.toString();
	}
	
	public void parseXML(Element element) {
		super.parseXML(element);
		this.creationMode = element.getAttribute("creationMode");
	}
} public class ForumConfig extends WebMediumConfig {
	public String replyAccessMode;
	public String postAccessMode;
	public String posts;
	
	public String getType() {
		return "forum";
	}

	@Override
	public String stats() {
		return this.posts + " posts";
	}
	
	public WebMediumConfig credentials() {
		ForumConfig config = new ForumConfig();
		config.id = this.id;
		return config;
	}
	
	public String toXML() {
		StringWriter writer = new StringWriter();
		writer.write("<forum");
		if (this.replyAccessMode != null && !this.replyAccessMode.equals("")) {
			writer.write(" replyAccessMode=\"" + this.replyAccessMode + "\"");
		}
		if (this.postAccessMode != null && !this.postAccessMode.equals("")) {
			writer.write(" postAccessMode=\"" + this.postAccessMode + "\"");
		}
		writeXML(writer);
		writer.write("</forum>");
		return writer.toString();
	}
	
	public void parseXML(Element element) {
		super.parseXML(element);
		this.replyAccessMode = element.getAttribute("replyAccessMode");
		this.postAccessMode = element.getAttribute("postAccessMode");
		this.posts = element.getAttribute("posts");
	}
} public class ForumPostConfig extends Config {	
	public String id;
	public String topic;
	public String summary;
	public String details;
	public String detailsText;
	public String forum;
	public String tags;
	public boolean isAdmin;
	public boolean isFlagged;
	public String flaggedReason;
	public boolean isFeatured;
	public String creator;
	public String creationDate;
	public String views;
	public String dailyViews;
	public String weeklyViews;
	public String monthlyViews;
	public String replyCount;
	public String parent;
	public String avatar;
	public List<ForumPostConfig> replies;
	
	public boolean equals(Object object) {
		if (object instanceof ForumPostConfig) {
			if (this.id == null) {
				return super.equals(object);
			}
			return this.id.equals(((ForumPostConfig)object).id);
		}
		return false;
	}
	
	public String toXML() {
		StringWriter writer = new StringWriter();
		writeXML(writer);
		return writer.toString();
	}

	public void writeXML(StringWriter writer) {
		writer.write("<forum-post");
		writeCredentials(writer);
		if (this.id != null) {
			writer.write(" id=\"" + this.id + "\"");
		}
		if (this.parent != null) {
			writer.write(" parent=\"" + this.parent + "\"");
		}
		if (this.forum != null) {
			writer.write(" forum=\"" + this.forum + "\"");
		}
		if (this.isFeatured) {
			writer.write(" isFeatured=\"true\"");
		}
		writer.write(">");
		if (this.topic != null) {
			writer.write("<topic>");
			writer.write(this.topic);
			writer.write("</topic>");
		}
		if (this.details != null) {
			String text = this.details;
			text = text.replace("<", "&lt;");
			text = text.replace(">", "&gt;");
			writer.write("<details>");
			writer.write(text);
			writer.write("</details>");
		}
		if (this.tags != null) {
			writer.write("<tags>");
			writer.write(this.tags);
			writer.write("</tags>");
		}
		writer.write("</forum-post>");
	}
	
	public void parseXML(Element element) {
		this.id = element.getAttribute("id");
		this.parent = element.getAttribute("parent");
		this.forum = element.getAttribute("forum");
		this.views = element.getAttribute("views");
		this.dailyViews = element.getAttribute("dailyViews");
		this.weeklyViews = element.getAttribute("weeklyViews");
		this.monthlyViews = element.getAttribute("monthlyViews");
		this.isAdmin = Boolean.valueOf(element.getAttribute("isAdmin"));
		this.replyCount = element.getAttribute("replyCount");
		this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged"));
		this.isFeatured = Boolean.valueOf(element.getAttribute("isFeatured"));
		this.creator = element.getAttribute("creator");
		this.creationDate = element.getAttribute("creationDate");
		
		Node node = element.getElementsByTagName("summary").item(0);
		if (node != null) {
			this.summary = node.getTextContent();
		}
		node = element.getElementsByTagName("details").item(0);
		if (node != null) {
			this.details = node.getTextContent();
		}
		node = element.getElementsByTagName("detailsText").item(0);
		if (node != null) {
			this.detailsText = node.getTextContent();
		}
		node = element.getElementsByTagName("topic").item(0);
		if (node != null) {
			this.topic = node.getTextContent();
		}
		node = element.getElementsByTagName("tags").item(0);
		if (node != null) {
			this.tags = node.getTextContent();
		}
		node = element.getElementsByTagName("flaggedReason").item(0);
		if (node != null) {
			this.flaggedReason = node.getTextContent();
		}
		node = element.getElementsByTagName("avatar").item(0);
		if (node != null) {
			this.avatar = node.getTextContent();
		}
		NodeList nodes = element.getElementsByTagName("replies");
		if (nodes != null && nodes.getLength() > 0) {
			this.replies = new ArrayList<ForumPostConfig>();
			for (int index = 0; index < nodes.getLength(); index++) {
				Element reply = (Element)nodes.item(index);
				ForumPostConfig config = new ForumPostConfig();
				config.parseXML(reply);
				this.replies.add(config);
			}
		}
	}
} public class InstanceConfig extends WebMediumConfig {
	public String size;
	public boolean allowForking;
	public String template;
	
	public String getType() {
		return "instance";
	}

	@Override
	public String stats() {
		return this.connects + " connects, " + this.dailyConnects + " today, " + this.weeklyConnects + " week, " + this.monthlyConnects + " month";
	}
	
	public InstanceConfig credentials() {
		InstanceConfig config = new InstanceConfig();
		config.id = this.id;
		return config;
	}
	
	public String toXML() {
		StringWriter writer = new StringWriter();
		writer.write("<instance");
		if (this.allowForking) {
			writer.write(" allowForking=\"true\"");
		}
		writeXML(writer);
		if (this.template != null) {
			writer.write("<template>");
			writer.write(this.template);
			writer.write("</template>");
		}
		writer.write("</instance>");
		return writer.toString();
	}
	
	public void parseXML(Element element) {
		super.parseXML(element);
		this.allowForking = Boolean.valueOf(element.getAttribute("allowForking"));
		this.size = element.getAttribute("size");
		
		Node node = element.getElementsByTagName("template").item(0);
		if (node != null) {
			this.template = node.getTextContent();
		}
	}
} public class MediaConfig extends Config {
	public long id;
	public String name;
	public String type;
	public String file;
	public String key;
	
	public void parseXML(Element element) {
		super.parseXML(element);
		
		this.id = Long.valueOf(element.getAttribute("id"));
		this.name = element.getAttribute("name");
		this.type = element.getAttribute("type");
		this.file = element.getAttribute("file");
		this.key = element.getAttribute("key");
	}

	
	public String toXML() {
		StringWriter writer = new StringWriter();
		writer.write("<media");
		writeCredentials(writer);

		if (this.id != 0) {
			writer.write(" id=\"" + this.id + "\"");
		}
		if (this.name != null) {
			writer.write(" name=\"" + this.name + "\"");
		}
		if (this.type != null) {
			writer.write(" type=\"" + this.type + "\"");
		}
		if (this.file != null) {
			writer.write(" file=\"" + this.file + "\"");
		}
		if (this.key != null) {
			writer.write(" key=\"" + this.key + "\"");
		}
		
		writer.write("/>");
		return writer.toString();
	}
} public class TrainingConfig extends Config {	
	public String operation;	
	public String question;	
	public String response;
	
	public String toXML() {
		StringWriter writer = new StringWriter();
		writer.write("<training");
		writeCredentials(writer);
		
		if (this.operation != null) {
			writer.write(" operation=\"" + this.operation + "\"");
		}
		
		writer.write(">");

		if (this.question != null) {
			writer.write("<question>");
			writer.write(this.question);
			writer.write("</question>");
		}
		if (this.response != null) {
			writer.write("<response>");
			writer.write(this.response);
			writer.write("</response>");
		}
		
		writer.write("</training>");
		return writer.toString();
	}
} public class UserAdminConfig extends Config {	
	public String operation;
	public String operationUser;
	
	public void parseXML(Element element) {
		super.parseXML(element);
		
		this.operation = element.getAttribute("operation");
		this.operationUser = element.getAttribute("operationUser");
	}

	
	public String toXML() {
		StringWriter writer = new StringWriter();
		writer.write("<user-admin");
		writeCredentials(writer);
		
		if (this.operation != null) {
			writer.write(" operation=\"" + this.operation + "\"");
		}
		if (this.operationUser != null) {
			writer.write(" operationUser=\"" + this.operationUser + "\"");
		}
		
		writer.write("/>");
		return writer.toString();
	}
} public class UserConfig extends Config {
	public String password;
	public String newPassword;
	public String hint;
	public String name;
	public boolean showName;
	public String email;
	public String website;
	public String bio;
	public boolean over18;
	public String avatar;
	
	public String connects;
	public String bots;
	public String posts;
	public String messages;
	public String forums;
	public String scripts;
	public String avatars;
	public String domains;
	public String channels;
	
	public String joined;
	public String lastConnect;

	
	public void addCredentials(SDKConnection connection) {
		this.application = connection.getCredentials().getApplicationId();
		if (connection.getDomain() != null) {
			this.domain = connection.getDomain().id;
		}
	}

	public void parseXML(Element element) {
		this.user = element.getAttribute("user");
		this.name = element.getAttribute("name");
		this.showName = Boolean.valueOf(element.getAttribute("showName"));
		this.token = element.getAttribute("token");
		this.email = element.getAttribute("email");
		this.hint = element.getAttribute("hint");
		this.website = element.getAttribute("website");
		this.connects = element.getAttribute("connects");
		this.bots = element.getAttribute("bots");
		this.posts = element.getAttribute("posts");
		this.messages = element.getAttribute("messages");
		this.avatars = element.getAttribute("avatars");
		this.scripts = element.getAttribute("scripts");
		this.domains = element.getAttribute("domains");
		this.joined = element.getAttribute("joined");
		this.lastConnect = element.getAttribute("lastConnect");
		
		Node node = element.getElementsByTagName("bio").item(0);
		if (node != null) {
			this.bio = node.getTextContent();
		}
		node = element.getElementsByTagName("avatar").item(0);
		if (node != null) {
			this.avatar = node.getTextContent();
		}
	}
	
	public String toXML() {
		StringWriter writer = new StringWriter();
		writer.write("<user");
		writeCredentials(writer);
		if (this.password != null) {
			writer.write(" password=\"" + this.password + "\"");
		}
		if (this.newPassword != null) {
			writer.write(" newPassword=\"" + this.newPassword + "\"");
		}
		if (this.hint != null) {
			writer.write(" hint=\"" + this.hint + "\"");
		}
		if (this.name != null) {
			writer.write(" name=\"" + this.name + "\"");
		}
		if (this.showName) {
			writer.write(" showName=\"" + this.showName + "\"");
		}
		if (this.email != null) {
			writer.write(" email=\"" + this.email + "\"");
		}
		if (this.website != null) {
			writer.write(" website=\"" + this.website + "\"");
		}
		if (this.over18) {
			writer.write(" over18=\"" + this.over18 + "\"");
		}
		writer.write(">");
		
		if (this.bio != null) {
			writer.write("<bio>");
			writer.write(this.bio);
			writer.write("</bio>");
		}
		writer.write("</user>");
		return writer.toString();
	}
		
} public class VoiceConfig extends Config {
	
	public String language;	
	public String pitch;
	public String speechRate;
	
	public void parseXML(Element element) {
		super.parseXML(element);
		
		this.language = element.getAttribute("language");
		this.pitch = element.getAttribute("pitch");
		this.speechRate = element.getAttribute("speechRate");
	}

	
	public String toXML() {
		StringWriter writer = new StringWriter();
		writer.write("<voice");
		writeCredentials(writer);

		if (this.language != null) {
			writer.write(" language=\"" + this.language + "\"");
		}
		if (this.pitch != null) {
			writer.write(" pitch=\"" + this.pitch + "\"");
		}
		if (this.speechRate != null) {
			writer.write(" speechRate=\"" + this.speechRate + "\"");
		}
		
		writer.write("/>");
		return writer.toString();
	}
} public abstract class WebMediumConfig extends Config {
	public String id;
	public String name;
	public boolean isAdmin;
	public boolean isAdult;
	public boolean isPrivate;
	public boolean isHidden;
	public String accessMode;
	public boolean isFlagged;
	public boolean isExternal;
	public boolean isPaphus;
	public boolean showAds = true;
	public String description;
	public String details;
	public String disclaimer;
	public String website;
	public String tags;
	public String categories;
	public String flaggedReason;
	public String creator;
	public String creationDate;
	public String lastConnectedUser;
	public String license;
	public String avatar;
	public String connects;
	public String dailyConnects;
	public String weeklyConnects;
	public String monthlyConnects;
	
	public abstract String toXML();
	
	public abstract String getType();
	
	public abstract WebMediumConfig credentials();
	
	public String stats() {
		return "";
	}
	
	public boolean equals(Object object) {
		if (object instanceof WebMediumConfig) {
			if (this.id == null) {
				return super.equals(object);
			}
			return this.id.equals(((WebMediumConfig)object).id);
		}
		return false;
	}
	
	public long getToken() {
		long token = 0;
		if ((this.token != null) && (this.token.equals(""))) {
			token = Long.valueOf(this.token);
		}
		return token;
	}

	public void writeXML(StringWriter writer) {
		writeCredentials(writer);
		if (this.id != null) {
			writer.write(" id=\"" + this.id + "\"");
		}
		if (this.name != null) {
			writer.write(" name=\"" + this.name + "\"");
		}
		if (this.isPrivate) {
			writer.write(" isPrivate=\"true\"");
		}
		if (this.isHidden) {
			writer.write(" isHidden=\"true\"");
		}
		if (this.accessMode != null && !this.accessMode.equals("")) {
			writer.write(" accessMode=\"" + this.accessMode + "\"");
		}
		if (this.isAdult) {
			writer.write(" isAdult=\"true\"");
		}
		if (this.isFlagged) {
			writer.write(" isFlagged=\"true\"");
		}
		if (this.isExternal) {
			writer.write(" isExternal=\"true\"");
		}
		if (this.showAds) {
			writer.write(" showAds=\"true\"");
		}
		writer.write(">");
		if (this.description != null) {
			writer.write("<description>");
			writer.write(this.description);
			writer.write("</description>");
		}
		if (this.details != null) {
			writer.write("<details>");
			writer.write(this.details);
			writer.write("</details>");
		}
		if (this.disclaimer != null) {
			writer.write("<disclaimer>");
			writer.write(this.disclaimer);
			writer.write("</disclaimer>");
		}
		if (this.categories != null) {
			writer.write("<categories>");
			writer.write(this.categories);
			writer.write("</categories>");
		}
		if (this.tags != null) {
			writer.write("<tags>");
			writer.write(this.tags);
			writer.write("</tags>");
		}
		if (this.license != null) {
			writer.write("<license>");
			writer.write(this.license);
			writer.write("</license>");
		}
		if (this.website != null) {
			writer.write("<website>");
			writer.write(this.website);
			writer.write("</website>");
		}
		if (this.flaggedReason != null) {
			writer.write("<flaggedReason>");
			writer.write(this.flaggedReason);
			writer.write("</flaggedReason>");
		}
	}
	
	public void parseXML(Element element) {
		this.id = element.getAttribute("id");
		this.name = element.getAttribute("name");
		this.creationDate = element.getAttribute("creationDate");
		this.isPrivate = Boolean.valueOf(element.getAttribute("isPrivate"));
		this.isHidden = Boolean.valueOf(element.getAttribute("isHidden"));
		this.accessMode = element.getAttribute("accessMode");
		this.isAdmin = Boolean.valueOf(element.getAttribute("isAdmin"));
		this.isAdult = Boolean.valueOf(element.getAttribute("isAdult"));
		this.isFlagged = Boolean.valueOf(element.getAttribute("isFlagged"));
		this.isExternal = Boolean.valueOf(element.getAttribute("isExternal"));
		this.creator = element.getAttribute("creator");
		this.creationDate = element.getAttribute("creationDate");
		this.connects = element.getAttribute("connects");
		this.dailyConnects = element.getAttribute("dailyConnects");
		this.weeklyConnects = element.getAttribute("weeklyConnects");
		this.showAds = Boolean.valueOf(element.getAttribute("showAds"));
		this.monthlyConnects = element.getAttribute("monthlyConnects");
		
		Node node = element.getElementsByTagName("description").item(0);
		if (node != null) {
			this.description = node.getTextContent();
		}
		node = element.getElementsByTagName("details").item(0);
		if (node != null) {
			this.details = node.getTextContent();
		}
		node = element.getElementsByTagName("disclaimer").item(0);
		if (node != null) {
			this.disclaimer = node.getTextContent();
		}
		node = element.getElementsByTagName("categories").item(0);
		if (node != null) {
			this.categories = node.getTextContent();
		}
		node = element.getElementsByTagName("tags").item(0);
		if (node != null) {
			this.tags = node.getTextContent();
		}
		node = element.getElementsByTagName("flaggedReason").item(0);
		if (node != null) {
			this.flaggedReason = node.getTextContent();
		}
		node = element.getElementsByTagName("lastConnectedUser").item(0);
		if (node != null) {
			this.lastConnectedUser = node.getTextContent();
		}
		node = element.getElementsByTagName("license").item(0);
		if (node != null) {
			this.license = node.getTextContent();
		}
		node = element.getElementsByTagName("avatar").item(0);
		if (node != null) {
			this.avatar = node.getTextContent();
		}
	}
}
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.StringReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.ByteArrayBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import com.paphus.sdk.config.BrowseConfig;
import com.paphus.sdk.config.ChannelConfig;
import com.paphus.sdk.config.ChatConfig;
import com.paphus.sdk.config.ChatResponse;
import com.paphus.sdk.config.ContentConfig;
import com.paphus.sdk.config.DomainConfig;
import com.paphus.sdk.config.ForumConfig;
import com.paphus.sdk.config.ForumPostConfig;
import com.paphus.sdk.config.InstanceConfig;
import com.paphus.sdk.config.MediaConfig;
import com.paphus.sdk.config.TrainingConfig;
import com.paphus.sdk.config.UserAdminConfig;
import com.paphus.sdk.config.UserConfig;
import com.paphus.sdk.config.VoiceConfig;
import com.paphus.sdk.config.WebMediumConfig;
		try {
			MediaConfig media = new MediaConfig();
			media.parseXML(root);
			return media;
		} catch (Exception exception) {
			this.exception = SDKException.parseFailure(exception);
			throw this.exception;
		}
	}
	
	/**
	 * Create a reply to a forum post.
	 * You must set the parent id for the post replying to.
	 */
	public ForumPostConfig createReply(ForumPostConfig config) {
		config.addCredentials(this);
		String xml = POST(this.url + "/create-reply", config.toXML());
		Element root = parse(xml);
		if (root == null) {
			return null;
		}
		try {
			ForumPostConfig reply = new ForumPostConfig();
			reply.parseXML(root);
			return reply;
		} catch (Exception exception) {
			this.exception = SDKException.parseFailure(exception);
			throw this.exception;
		}
	}
	
	/**
	 * Fetch the content details from the server.
	 * The id or name and domain of the object must be set.
	 */
	@SuppressWarnings("unchecked")
	public <T extends WebMediumConfig> T fetch(T config) {
		config.addCredentials(this);
		String xml = POST(this.url + "/check-" + config.getType(), config.toXML());
		Element root = parse(xml);
		if (root == null) {
			return null;
		}
		try {
			config = (T)config.getClass().newInstance();
			config.parseXML(root);
			return config;
		} catch (Exception exception) {
			this.exception = SDKException.parseFailure(exception);
			throw this.exception;
		}
	}
	
	/**
	 * Update the forum post.
	 */
	public ForumPostConfig update(ForumPostConfig config) {
		config.addCredentials(this);
		String xml = POST(this.url + "/update-forum-post", config.toXML());
		Element root = parse(xml);
		if (root == null) {
			return null;
		}
		try {
			config = new ForumPostConfig();
			config.parseXML(root);
			return config;
		} catch (Exception exception) {
			this.exception = SDKException.parseFailure(exception);
			throw this.exception;
		}
	}
	
	/**
	 * Update the user details.
	 * The password must be passed to allow the update.
	 */
	public UserConfig update(UserConfig config) {
		config.addCredentials(this);
		POST(this.url + "/update-user", config.toXML());
		return config;
	}
	
	/**
	 * Permanently delete the forum post with the id.
	 */
	public void delete(ForumPostConfig config) {
		config.addCredentials(this);
		POST(this.url + "/delete-forum-post", config.toXML());
	}
	
	/**
	 * Flag the content as offensive, a reason is required.
	 */
	public void flag(WebMediumConfig config) {
		config.addCredentials(this);
		POST(this.url + "/flag-" + config.getType(), config.toXML());
	}
	
	/**
	 * Flag the forum post as offensive, a reason is required.
	 */
	public void flag(ForumPostConfig config) {
		config.addCredentials(this);
		POST(this.url + "/flag-forum-post", config.toXML());
	}
	
	/**
	 * Flag the user post as offensive, a reason is required.
	 */
	public void flag(UserConfig config) {
		config.addCredentials(this);
		POST(this.url + "/flag-user", config.toXML());
	}
	
	/**
	 * Process the bot chat message and return the bot's response.
	 * The ChatConfig should contain the conversation id if part of a conversation.
	 * If a new conversation the conversation id is returned in the response. 
	 */
	public ChatResponse chat(ChatConfig config) {