Mercurial > dive4elements > river
view flys-client/src/main/java/de/intevation/flys/client/server/MetaDataServiceImpl.java @ 282:e92f7ef455d6
Show rivers as links instead of a combobox.
flys-client/trunk@1911 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Thu, 12 May 2011 14:59:18 +0000 |
parents | f33af25b7490 |
children | 0fa8bf8a2295 |
line wrap: on
line source
package de.intevation.flys.client.server; import java.util.List; import java.util.ArrayList; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import com.google.gwt.user.server.rpc.RemoteServiceServlet; import de.intevation.artifacts.common.ArtifactNamespaceContext; import de.intevation.artifacts.common.utils.XMLUtils; import de.intevation.flys.client.shared.exceptions.ServerException; import de.intevation.flys.client.client.services.MetaDataService; import de.intevation.artifacts.httpclient.exceptions.ConnectionException; import de.intevation.artifacts.httpclient.http.HttpClient; import de.intevation.artifacts.httpclient.http.HttpClientImpl; import de.intevation.flys.client.shared.model.DataCageTree; import de.intevation.flys.client.shared.model.DataCageNode; public class MetaDataServiceImpl extends RemoteServiceServlet implements MetaDataService { public static final String ERROR_NO_META_DATA_FOUND = "error_no_meta_data_found"; public DataCageTree getMetaData(String url, String locale, String river) throws ServerException { System.out.println("MetaDataService.getDistanceInfo"); Document doc = XMLUtils.newDocument(); XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( doc, ArtifactNamespaceContext.NAMESPACE_URI, ArtifactNamespaceContext.NAMESPACE_PREFIX); Element riverEl = ec.create("river"); riverEl.setTextContent(river); doc.appendChild(riverEl); HttpClient client = new HttpClientImpl(url, locale); try { return convert(client.callService(url, "metadata", doc)); } catch (ConnectionException ce) { System.err.println(ce.getLocalizedMessage()); } throw new ServerException(ERROR_NO_META_DATA_FOUND); } protected static DataCageNode convert(Node node) { String name = node.getLocalName(); DataCageNode dvn = new DataCageNode(name); NodeList children = node.getChildNodes(); for (int i = 0, N = children.getLength(); i < N; ++i) { dvn.addChild(convert(children.item(i))); } return dvn; } protected static DataCageTree convert(Document document) { ArrayList<DataCageNode> roots = new ArrayList<DataCageNode>(); NodeList nodes = document.getChildNodes(); for (int i = 0, N = nodes.getLength(); i < N; ++i) { Node node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { roots.add(convert(nodes.item(i))); } } return new DataCageTree(roots.get(0)); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :