ingo@2: package de.intevation.flys.client.server; ingo@2: ingo@25: import javax.xml.xpath.XPathConstants; ingo@25: ingo@25: import org.w3c.dom.Document; ingo@25: import org.w3c.dom.Node; ingo@25: import org.w3c.dom.NodeList; ingo@25: ingo@2: import com.google.gwt.user.server.rpc.RemoteServiceServlet; ingo@2: ingo@25: import de.intevation.artifacts.common.ArtifactNamespaceContext; ingo@25: import de.intevation.artifacts.common.utils.XMLUtils; ingo@25: ingo@25: import de.intevation.artifacts.httpclient.exceptions.ConnectionException; ingo@25: import de.intevation.artifacts.httpclient.http.HttpClient; ingo@25: import de.intevation.artifacts.httpclient.http.HttpClientImpl; ingo@2: ingo@2: import de.intevation.flys.client.client.services.UserService; ingo@25: import de.intevation.flys.client.shared.model.DefaultUser; ingo@25: import de.intevation.flys.client.shared.model.User; ingo@2: ingo@2: ingo@2: /** ingo@2: * @author Ingo Weinzierl ingo@2: */ ingo@2: public class UserServiceImpl ingo@2: extends RemoteServiceServlet ingo@2: implements UserService ingo@2: { ingo@25: public User getCurrentUser(String serverUrl) { ingo@25: HttpClient client = new HttpClientImpl(serverUrl); ingo@25: ingo@25: try { ingo@25: Document users = (Document) client.listUsers(); ingo@25: ingo@25: String XPATH_USERS = "/art:users/art:user"; ingo@25: ingo@25: NodeList theUsers = (NodeList) XMLUtils.xpath( ingo@25: users, ingo@25: XPATH_USERS, ingo@25: XPathConstants.NODESET, ingo@25: ArtifactNamespaceContext.INSTANCE); ingo@25: ingo@25: if (theUsers != null && theUsers.getLength() > 0) { ingo@25: Node user = theUsers.item(0); ingo@25: ingo@25: String uuid = XMLUtils.xpathString( ingo@25: user, "@art:uuid", ArtifactNamespaceContext.INSTANCE); ingo@25: String name = XMLUtils.xpathString( ingo@25: user, "@art:name", ArtifactNamespaceContext.INSTANCE); ingo@25: ingo@25: return new DefaultUser(uuid, name); ingo@25: } ingo@25: } ingo@25: catch (ConnectionException ce) { ingo@25: System.err.println(ce.getLocalizedMessage()); ingo@25: } ingo@25: ingo@25: System.err.println("No users existing in the server."); ingo@25: return null; ingo@2: } ingo@2: } ingo@2: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :