package com.github.progval.SeenDroid.lib;

import org.w3c.dom.Element;
import org.w3c.dom.Node;

import android.util.Log;

public class Message {
	private User author;
	private int id;
	private String title, summary, content, published, updated;
	
	private String getContentFromTag(Element element, String tag) {
		// Shortcut
		try {
			return element.getElementsByTagName(tag).item(0).getTextContent();
		}
		catch (NullPointerException e) {
			Log.w("SeenDroid", String.format("Unable to find tag '%s' in element '%s'", tag, element.getTagName()));
			Log.w("SeenDroid", ((Element) element.getParentNode()).getTagName());
			throw e;
		}
	}
	
	public Message(Element element) {
		this.id = Integer.parseInt(this.getContentFromTag(element, "id") // Format: message:<id>
				.split(":")[1]);
		this.title = this.getContentFromTag(element, "title");
		this.author = new User(element.getElementsByTagName("author").item(0));
		this.summary = this.getContentFromTag(element, "summary");
		this.content = this.getContentFromTag(element, "content");
		this.published = this.getContentFromTag(element, "published");
		this.updated = this.getContentFromTag(element, "updated");
	}

	public Message(User author, String title, String content) {
		this.author = author;
		this.title = title;
		this.content = content;
	}
	
	public int getId() {
		return this.id;
	}
	public String getTitle() {
		return this.title;
	}
	public User getAuthor() {
		return this.author;
	}
	public String getSummary() {
		return this.summary;
	}
	public String getContent() {
		return this.content;
	}
	public String getPlublished() {
		return this.published;
	}
	public String getUpdated() {
		return this.updated;
	}
}

@@ -976,17 +976,189 @@
 ummary%22)
-;
+%0A%09%09%09%09.replaceAll(((Character) Character.toChars(0x275D)%5B0%5D).toString(), %22%C2%AB%22) // %E2%9D%9D to %C2%AB%0A%09%09%09%09.replaceAll(((Character) Character.toChars(0x275E)%5B0%5D).toString(), %22%C2%BB%22); // %E2%9D%9E to %C2%BB
 %0A%09%09this.

Replace Seenthis quotation characters by regular ones.