FileDocCategorySizeDatePackage
FacebookXmlRestClient.javaAPI DocGoogle Facebook API v1.415590Fri Nov 02 14:58:22 GMT 2007com.facebook.api

FacebookXmlRestClient

public class FacebookXmlRestClient extends ExtensibleClient
A FacebookRestClient that uses the XML result format. This means results from calls to the Facebook API are returned as XML and transformed into instances of {@link org.w3c.dom.Document}.
deprecated
this is provided for legacy support only. Please use FacebookRestClient instead if you want to use the Facebook Platform XML API.

Fields Summary
Constructors Summary
public FacebookXmlRestClient(String apiKey, String secret)
Constructor. Don't use this, use FacebookRestClient instead.

param
apiKey
param
secret
deprecated
this is provided for legacy support only. Please use FacebookRestClient instead if you want to use the Facebook Platform XML API.

    this(SERVER_URL, apiKey, secret, null);
  
public FacebookXmlRestClient(String apiKey, String secret, String sessionKey)
Constructor. Don't use this, use FacebookRestClient instead.

param
serverUrl
param
apiKey
param
secret
param
sessionKey
deprecated
this is provided for legacy support only. Please use FacebookRestClient instead if you want to use the Facebook Platform XML API.

    this(SERVER_URL, apiKey, secret, sessionKey);
  
public FacebookXmlRestClient(String serverAddr, String apiKey, String secret, String sessionKey)
Constructor. Don't use this, use FacebookRestClient instead.

param
serverUrl
param
apiKey
param
secret
param
sessionKey
deprecated
this is provided for legacy support only. Please use FacebookRestClient instead if you want to use the Facebook Platform XML API.

    this(new URL(serverAddr), apiKey, secret, sessionKey);
  
public FacebookXmlRestClient(URL serverUrl, String apiKey, String secret, String sessionKey)
Constructor. Don't use this, use FacebookRestClient instead.

param
serverUrl
param
apiKey
param
secret
param
sessionKey
deprecated
this is provided for legacy support only. Please use FacebookRestClient instead if you want to use the Facebook Platform XML API.

    super(serverUrl, apiKey, secret, sessionKey);
  
Methods Summary
public java.lang.Stringauth_getSession(java.lang.String authToken)
Call this function to retrieve the session information after your user has logged in.

param
authToken the token returned by auth_createToken or passed back to your callback_url.

    if (null != this._sessionKey) {
      return this._sessionKey;
    }
    Document d =
      this.callMethod(FacebookMethod.AUTH_GET_SESSION, 
                      new Pair<String, CharSequence>("auth_token", authToken.toString()));
    this._sessionKey =
        d.getElementsByTagName("session_key").item(0).getFirstChild().getTextContent();
    this._userId = Integer.parseInt(d.getElementsByTagName("uid").item(0).getFirstChild().getTextContent());
    if (this._isDesktop) {
      this._sessionSecret =
          d.getElementsByTagName("secret").item(0).getFirstChild().getTextContent();
    }
    return this._sessionKey;
  
public java.lang.Stringdata_getUserPreference(java.lang.Integer prefId)

        throw new FacebookException(ErrorCode.GEN_UNKNOWN_METHOD, "The FacebookJsonRestClient does not support this API call.  " +
        "Please use an instance of FacebookRestClient instead.");
    
public java.util.Mapdata_getUserPreferences()

        throw new FacebookException(ErrorCode.GEN_UNKNOWN_METHOD, "The FacebookJsonRestClient does not support this API call.  " +
        "Please use an instance of FacebookRestClient instead.");
    
public voiddata_setUserPreference(java.lang.Integer prefId, java.lang.String value)

        throw new FacebookException(ErrorCode.GEN_UNKNOWN_METHOD, "The FacebookJsonRestClient does not support this API call.  " +
        "Please use an instance of FacebookRestClient instead.");
        
    
public voiddata_setUserPreferences(java.util.Map values, boolean replace)

        throw new FacebookException(ErrorCode.GEN_UNKNOWN_METHOD, "The FacebookJsonRestClient does not support this API call.  " +
        "Please use an instance of FacebookRestClient instead.");
        
    
protected intextractInt(org.w3c.dom.Document doc)
Extracts an Integer from a document that consists of an Integer only.

param
doc
return
the Integer

    return Integer.parseInt(doc.getFirstChild().getTextContent());
  
protected java.lang.LongextractLong(org.w3c.dom.Document doc)
Extracts a Long from a document that consists of a Long only.

param
doc
return
the Long

    return Long.parseLong(doc.getFirstChild().getTextContent());
  
public java.lang.StringextractString(org.w3c.dom.Document d)
Extracts a String from a T consisting entirely of a String.

param
result
return
the String

    return d.getFirstChild().getTextContent();
  
protected java.net.URLextractURL(org.w3c.dom.Document doc)
Extracts a URL from a document that consists of a URL only.

param
doc
return
the URL

    String url = doc.getFirstChild().getTextContent();
    return (null == url || "".equals(url)) ? null : new URL(url);
  
public voidfbml_setRefHandle(java.lang.String handle, java.lang.String markup)

        throw new FacebookException(ErrorCode.GEN_UNKNOWN_METHOD, "The FacebookJsonRestClient does not support this API call.  " +
        "Please use an instance of FacebookRestClient instead.");
        
    
public java.lang.StringgetResponseFormat()
The response format in which results to FacebookMethod calls are returned

return
the format: either XML, JSON, or null (API default)

    return "xml";
  
public java.util.Listmarketplace_getListings(java.util.List listingIds, java.util.List uids)

        this.marketplace_getListings(listingIds, uids);
        MarketplaceGetListingsResponse resp = (MarketplaceGetListingsResponse)this.getResponsePOJO();
        return resp.getListing();
    
public java.util.Listmarketplace_getSubCategories()

        this.marketplace_getSubCategories(null);
        MarketplaceGetSubCategoriesResponse resp = (MarketplaceGetSubCategoriesResponse)this.getResponsePOJO();
        return resp.getMarketplaceSubcategory();
    
public java.util.Listmarketplace_search(com.facebook.api.MarketListingCategory category, com.facebook.api.MarketListingSubcategory subcategory, java.lang.String searchTerm)

        this.marketplace_search(category.getName(), subcategory.getName(), searchTerm);
        MarketplaceSearchResponse resp = (MarketplaceSearchResponse)this.getResponsePOJO();
        return resp.getListing();
    
protected org.w3c.dom.DocumentparseCallResult(java.io.InputStream data, com.facebook.api.IFacebookMethod method)

    try {
      DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
      Document doc = builder.parse(data);
      doc.normalizeDocument();
      stripEmptyTextNodes(doc);

      if (isDebug()) {
        FacebookXmlRestClient.printDom(doc, method.methodName() + "| ");
      }
      NodeList errors = doc.getElementsByTagName(ERROR_TAG);
      if (errors.getLength() > 0) {
        int errorCode =
          Integer.parseInt(errors.item(0).getFirstChild().getFirstChild().getTextContent());
        String message = errors.item(0).getFirstChild().getNextSibling().getTextContent();
        throw new FacebookException(errorCode, message);
      }
      return doc;
    } catch (ParserConfigurationException ex) {
      System.err.println("huh?" + ex);
    } catch (SAXException ex) {
      throw new IOException("error parsing xml");
    }
    return null;
  
public static voidprintDom(org.w3c.dom.Node n, java.lang.String prefix)
Prints out the DOM tree.

    String outString = prefix;
    if (n.getNodeType() == Node.TEXT_NODE) {
      outString += "'" + n.getTextContent().trim() + "'";
    } else {
      outString += n.getNodeName();
    }
    System.out.println(outString);
    NodeList children = n.getChildNodes();
    int length = children.getLength();
    for (int i = 0; i < length; i++) {
      FacebookXmlRestClient.printDom(children.item(i), prefix + "  ");
    }
  
public booleansms_canSend()

        throw new FacebookException(ErrorCode.GEN_UNKNOWN_METHOD, "The FacebookJsonRestClient does not support this API call.  " +
        "Please use an instance of FacebookRestClient instead.");
    
public booleansms_canSend(java.lang.Long userId)

        throw new FacebookException(ErrorCode.GEN_UNKNOWN_METHOD, "The FacebookJsonRestClient does not support this API call.  " +
        "Please use an instance of FacebookRestClient instead.");
    
public java.lang.Integersms_send(java.lang.String message, java.lang.Integer smsSessionId, boolean makeNewSession)

        throw new FacebookException(ErrorCode.GEN_UNKNOWN_METHOD, "The FacebookJsonRestClient does not support this API call.  " +
        "Please use an instance of FacebookRestClient instead.");
    
public java.lang.Integersms_send(java.lang.Long userId, java.lang.String message, java.lang.Integer smsSessionId, boolean makeNewSession)

        throw new FacebookException(ErrorCode.GEN_UNKNOWN_METHOD, "The FacebookJsonRestClient does not support this API call.  " +
        "Please use an instance of FacebookRestClient instead.");
    
private static voidstripEmptyTextNodes(org.w3c.dom.Node n)
Hack...since DOM reads newlines as textnodes we want to strip out those nodes to make it easier to use the tree.

    NodeList children = n.getChildNodes();
    int length = children.getLength();
    for (int i = 0; i < length; i++) {
      Node c = children.item(i);
      if (!c.hasChildNodes() && c.getNodeType() == Node.TEXT_NODE &&
        c.getTextContent().trim().length() == 0) {
        n.removeChild(c);
        i--;
        length--;
        children = n.getChildNodes();
      } else {
        stripEmptyTextNodes(c);
      }
    }