package twitter4j;

import org.w3c.dom.Element;

/**
 * Super class of Twitter Response objects.
 * @see twitter4j.DirectMessage
 * @see twitter4j.Status
 * @see twitter4j.User
 * @see twitter4j.UserWithStatus
 */
public class TwitterResponse implements java.io.Serializable {
    protected final Element elem;
    protected Twitter twitter;
    public TwitterResponse(Element elem, Twitter twitter) {
        this.elem = elem;
        this.twitter = twitter;
    }
    protected void ensureRootNodeNameIs(String rootName) throws TwitterException{
        if(!rootName.equals(elem.getNodeName())){
            throw new TwitterException("Unexpected root node name:"+elem.getNodeName()+". Expected:"+rootName+". Check Twitter service availability.");
        }
    }
    protected static void ensureRootNodeNameIs(String rootName,Element elem) throws TwitterException{
        if(!rootName.equals(elem.getNodeName())){
            throw new TwitterException("Unexpected root node name:"+elem.getNodeName()+". Expected:"+rootName+". Check Twitter service availability.");
        }
    }

    protected String getChildText(String str) {
        return elem.getElementsByTagName(str).item(0).getTextContent();
    }

    protected int getChildInt(String str) {
        return Integer.valueOf(elem.getElementsByTagName(str).item(0).
                               getTextContent());
    }

    @Override public int hashCode() {
        return elem.hashCode();
    }

    @Override public boolean equals(Object obj) {
        if (null == obj) {
            return false;
        }
        if (this == obj) {
            return true;
        }
        if (obj instanceof TwitterResponse) {
            ( (TwitterResponse) obj).elem.equals(this.elem);
        }
        return false;
    }
}

@@ -40,16 +40,261 @@
 Element;
+%0Aimport org.w3c.dom.Document;%0A%0Aimport javax.xml.transform.dom.DOMSource;%0Aimport javax.xml.transform.TransformerFactory;%0Aimport javax.xml.transform.TransformerException;%0Aimport javax.xml.transform.stream.StreamResult;%0Aimport java.io.StringWriter;
 %0A%0A/**%0A *
@@ -976,33 +976,50 @@
 ce availability.
-%22
+%5Cn%22+toString(elem)
 );%0A        %7D%0A   
@@ -1325,10 +1325,371 @@
 ity.
+%5Cn%22+toString(elem));%0A        %7D%0A    %7D%0A%0A    private static String toString(Element doc) %7B%0A        try%7B%0A        StringWriter output = new StringWriter();%0A        TransformerFactory.newInstance().newTransformer().transform(new DOMSource(doc), new StreamResult(output));%0A        return output.toString();%0A        %7Dcatch(TransformerException tfe)%7B%0A            return %22
 %22
-)
 ;%0A  

fix for TFJ-6 http://yusuke.homeip.net/jira/browse/TFJ-6