Mercurial > dive4elements > river
view flys-client/src/main/java/de/intevation/flys/client/server/FeedServiceImpl.java @ 894:5341be7dec7a
Removed the table listener for "Q" input. The table is no longer used
for input assistance.
(Issue203)
flys-client/trunk@2739 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Wed, 14 Sep 2011 11:07:19 +0000 |
parents | 3d379e6b9a5f |
children | ab8eb2f544f2 |
line wrap: on
line source
package de.intevation.flys.client.server; import org.w3c.dom.Document; import com.google.gwt.user.server.rpc.RemoteServiceServlet; import de.intevation.artifacts.common.ArtifactNamespaceContext; import de.intevation.artifacts.common.utils.ClientProtocolUtils; import de.intevation.artifacts.common.utils.XMLUtils; import de.intevation.artifacts.httpclient.exceptions.ConnectionException; import de.intevation.artifacts.httpclient.http.HttpClient; import de.intevation.artifacts.httpclient.http.HttpClientImpl; import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; import de.intevation.flys.client.shared.exceptions.ServerException; import de.intevation.flys.client.shared.model.Artifact; import de.intevation.flys.client.shared.model.Data; import de.intevation.flys.client.shared.model.DataItem; import de.intevation.flys.client.client.services.FeedService; /** * This interface provides a method that bundles the artifact specific * operation FEED. */ public class FeedServiceImpl extends RemoteServiceServlet implements FeedService { /** XPath that points to the result type of a feed or advance operation.*/ public static final String XPATH_RESULT = "/art:result/@art:type"; /** XPath that points to the result type of a feed or advance operation.*/ public static final String XPATH_RESULT_MSG = "/art:result/text()"; /** A constant that marks errors.*/ public static final String OPERATION_FAILURE = "FAILURE"; /** The error message key that is thrown if an error occured while feeding * new data.*/ public static final String ERROR_FEED_DATA = "error_feed_data"; /** * This method triggers the FEED operation. * * @param url The url of the artifact server. * @param artifact The artifact that needs to be fed. * @param data An array of Data objects that contain the information that * are used for the FEED operation. * * @return a new artifact parsed from the description of FEED. */ public Artifact feed( String url, String locale, Artifact artifact, Data[] data) throws ServerException { System.out.println("StepForwardServiceImpl.feed"); Document feed = ClientProtocolUtils.newFeedDocument( artifact.getUuid(), artifact.getHash(), createKVP(data)); HttpClient client = new HttpClientImpl(url, locale); try { Document description = (Document) client.feed( new de.intevation.artifacts.httpclient.objects.Artifact( artifact.getUuid(), artifact.getHash()), feed, new DocumentResponseHandler()); if (description == null) { System.err.println("StepForwardService.feed() - FAILED"); throw new ServerException(ERROR_FEED_DATA); } String result = XMLUtils.xpathString( description, XPATH_RESULT, ArtifactNamespaceContext.INSTANCE); if (result == null || !result.equals(OPERATION_FAILURE)) { System.out.println("StepForwardService.feed() - SUCCESS"); return (Artifact) new FLYSArtifactCreator().create(description); } else if (result != null && result.equals(OPERATION_FAILURE)) { String msg = XMLUtils.xpathString( description, XPATH_RESULT_MSG, ArtifactNamespaceContext.INSTANCE); throw new ServerException(msg); } } catch (ConnectionException ce) { System.err.println(ce.getLocalizedMessage()); } System.err.println("StepForwardService.feed() - FAILED"); throw new ServerException(ERROR_FEED_DATA); } /** * This method creates an array of key/value pairs from an array of Data * objects. The string array is used as parameter for the feed() operation. * * @param data The data that should be transformed into the string array. * * @return a string array that contains key/value pairs. */ protected String[][] createKVP(Data[] data) { String[][] kvp = new String[data.length][]; int i = 0; for (Data d: data) { DataItem[] items = d.getItems(); String key = d.getLabel(); String value = items[0].getStringValue(); kvp[i++] = new String[] { key, value }; } return kvp; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :