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@1367: import org.apache.log4j.Logger; ingo@1367: 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@217: import de.intevation.flys.client.shared.exceptions.AuthenticationException; 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@1367: private static final Logger logger = Logger.getLogger(UserServiceImpl.class); ingo@1367: ingo@1367: ingo@217: public static final String ERROR_NO_SUCH_USER = "error_no_such_user"; ingo@217: ingo@229: public User getCurrentUser(String serverUrl, String locale) ingo@217: throws AuthenticationException ingo@217: { 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@1367: logger.error(ce, ce); ingo@25: } ingo@25: ingo@1367: logger.error("No users existing in the server."); ingo@217: throw new AuthenticationException(ERROR_NO_SUCH_USER); ingo@2: } ingo@2: } ingo@2: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :