In your user interface, you might want to display information about a user, such as a name, during the user’s login session.
See the sample files XMLApiAdapter.java, UserInfo.java, and header.jsp.
You can retrieve simple information about the user by calling common-info after the user logs in, like this:
https://example.com/api/xml?action=common-info
The response has a user element with information you can display or store in variables to use later:
<user user-id="2006258745" type="user"> <name>Joy Smith</name> <login>joy@acme.com</login> </user>
If you call common-info before the user logs in, the response does not have a user element.
Get information about the user
In the sample, the getUserInfo method calls common-info and parses the response for the values of name, login, and user-id. The method then stores information about the user in an instance of the UserInfo class, which is a standard bean class with getter and setter methods.
public UserInfo getUserInfo(String login, String password) throws XMLApiException { try { Element e = request("common-info", "login=" + login + "&password=" + password); XPath name = XPath.newInstance("//user/name"); XPath log = XPath.newInstance("//user/login"); XPath id = XPath.newInstance("//user/@user-id"); UserInfo user = new UserInfo(); user.setLogin(log.valueOf(e)); user.setName(name.valueOf(e)); user.setUserId(id.valueOf(e)); return user; } catch (JDOMException jde) { throw new XMLApiException(PARSE_ERROR, jde); } }