ingo@29: package de.intevation.flys.client.server; ingo@29: ingo@29: import java.util.ArrayList; ingo@29: import java.util.List; ingo@29: ingo@29: import javax.xml.xpath.XPathConstants; ingo@29: ingo@29: import org.w3c.dom.Document; ingo@29: import org.w3c.dom.NodeList; ingo@29: import org.w3c.dom.Node; ingo@29: ingo@29: import com.google.gwt.user.server.rpc.RemoteServiceServlet; ingo@29: ingo@29: import de.intevation.artifacts.common.ArtifactNamespaceContext; ingo@29: import de.intevation.artifacts.common.utils.XMLUtils; ingo@29: ingo@29: import de.intevation.artifacts.httpclient.exceptions.ConnectionException; ingo@29: import de.intevation.artifacts.httpclient.http.HttpClient; ingo@29: import de.intevation.artifacts.httpclient.http.HttpClientImpl; ingo@29: ingo@29: import de.intevation.flys.client.shared.model.DefaultRiver; ingo@29: import de.intevation.flys.client.shared.model.River; ingo@29: import de.intevation.flys.client.client.services.RiverService; ingo@29: ingo@29: ingo@29: /** ingo@29: * This interface provides a method to list the supported rivers of the artifact ingo@29: * server. ingo@29: * ingo@29: * @author Ingo Weinzierl ingo@29: */ ingo@29: public class RiverServiceImpl ingo@29: extends RemoteServiceServlet ingo@29: implements RiverService ingo@29: { ingo@29: /** The XPath string that points to the rivers in the resulting document.*/ ingo@29: public static final String XPATH_RIVERS = "/art:rivers/art:river"; ingo@29: ingo@29: ingo@29: public River[] list(String serverUrl) { ingo@29: Document doc = XMLUtils.newDocument(); ingo@29: ingo@29: XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( ingo@29: doc, ingo@29: ArtifactNamespaceContext.NAMESPACE_URI, ingo@29: ArtifactNamespaceContext.NAMESPACE_PREFIX); ingo@29: ingo@29: doc.appendChild(ec.create("action")); ingo@29: ingo@29: HttpClient client = new HttpClientImpl(serverUrl); ingo@29: ingo@29: try { ingo@29: Document res = client.callService(serverUrl, "rivers", doc); ingo@29: ingo@29: NodeList rivers = (NodeList) XMLUtils.xpath( ingo@29: res, ingo@29: XPATH_RIVERS, ingo@29: XPathConstants.NODESET, ingo@29: ArtifactNamespaceContext.INSTANCE); ingo@29: ingo@29: int count = rivers.getLength(); ingo@29: ingo@29: List theRivers = new ArrayList(count); ingo@29: ingo@29: for (int i = 0; i < count; i++) { ingo@29: Node tmp = rivers.item(i); ingo@29: ingo@29: String name = XMLUtils.xpathString( ingo@29: tmp, "@art:name", ArtifactNamespaceContext.INSTANCE); ingo@29: ingo@29: theRivers.add(new DefaultRiver(name)); ingo@29: } ingo@29: ingo@29: return (River[]) theRivers.toArray(new River[count]); ingo@29: } ingo@29: catch (ConnectionException ce) { ingo@29: System.err.println(ce.getLocalizedMessage()); ingo@29: } ingo@29: ingo@29: return null; ingo@29: } ingo@29: } ingo@29: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :