Mercurial > dive4elements > gnv-client
changeset 40:23a4f196d7d6
Adding Languagetransfer to the ArtifactDatabase to the GNV-Client
gnv/trunk@180 c6561f87-3c4e-4783-a992-168aeb5c3f6f
line wrap: on
line diff
--- a/gnv/Changelog Fri Oct 02 14:29:08 2009 +0000 +++ b/gnv/Changelog Fri Oct 02 14:55:18 2009 +0000 @@ -1,3 +1,21 @@ +2009-10-02 Tim Englich <tim.englich@intevation.de> + + * src/main/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClientFactory.java (getArtifactDatabaseClient): + Putting the ClientLanguage into the getArtifactDatabaseClient-Signature. + * src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java (setLocale) Edited, + * src/main/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClient.java (setLocale) Edited: + Added the Support of Setting the ClientLanguage to the ArtifactDatabaseClient + + * src/main/java/de/intevation/gnv/action/SelectArtifactFactoryAction.java (execute) Edited, + src/main/java/de/intevation/gnv/action/NextArtifactStepAction.java (execute) Edited, + src/main/java/de/intevation/gnv/action/FetchArtifactFactoriesAction.java (execute) Edited, + src/main/java/de/intevation/gnv/action/DoOutputAction.java (execute) Edited, + src/main/java/de/intevation/gnv/action/ChangeOptionsAction.java(execute) Edited: + Put the Locale of the Calling Client to the Communication with the ArtifactDatabase. + + * src/test/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClientTestCase.java (testArtifactDatabaseClient) Edited: + Added DefaultLocale German to the ArtfactDataBaseClient call. + 2009-10-02 Tim Englich <tim.englich@intevation.de> * src/main/webapp/WEB-INF/config/templates/describe-ui.xsl Edited,
--- a/gnv/src/main/java/de/intevation/gnv/action/ChangeOptionsAction.java Fri Oct 02 14:29:08 2009 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/action/ChangeOptionsAction.java Fri Oct 02 14:55:18 2009 +0000 @@ -73,7 +73,9 @@ ArtifactDescription ad = sm.getArtifactDescription(); ArtifactDatabaseClient adc = ArtifactDatabaseClientFactory - .getInstance().getArtifactDatabaseClient(); + .getInstance() + .getArtifactDatabaseClient(getLocale(request)); + ArtifactDescription artifactDescription = adc .getCurrentStepDescription(sm.getSelectedArtifactFactory(), sm.getCurrentArtifact());
--- a/gnv/src/main/java/de/intevation/gnv/action/DoOutputAction.java Fri Oct 02 14:29:08 2009 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/action/DoOutputAction.java Fri Oct 02 14:55:18 2009 +0000 @@ -83,7 +83,8 @@ } ArtifactDatabaseClient adc = ArtifactDatabaseClientFactory - .getInstance().getArtifactDatabaseClient(); + .getInstance() + .getArtifactDatabaseClient(getLocale(request)); this.setHeaders(target, mimeType, response, request);
--- a/gnv/src/main/java/de/intevation/gnv/action/FetchArtifactFactoriesAction.java Fri Oct 02 14:29:08 2009 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/action/FetchArtifactFactoriesAction.java Fri Oct 02 14:55:18 2009 +0000 @@ -46,7 +46,7 @@ log.debug("ArtifactDatabaseActionBase.execute"); try { Collection<ArtifactObject> artifactFactories = ArtifactDatabaseClientFactory - .getInstance().getArtifactDatabaseClient() + .getInstance().getArtifactDatabaseClient(getLocale(request)) .getArtifactFactories(); SessionModel sm = SessionModelFactory.getInstance() .getSessionModel(request);
--- a/gnv/src/main/java/de/intevation/gnv/action/NextArtifactStepAction.java Fri Oct 02 14:29:08 2009 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/action/NextArtifactStepAction.java Fri Oct 02 14:55:18 2009 +0000 @@ -73,7 +73,8 @@ } } ArtifactDatabaseClient adc = ArtifactDatabaseClientFactory - .getInstance().getArtifactDatabaseClient(); + .getInstance() + .getArtifactDatabaseClient(getLocale(request)); if (ad.getReachableStates() != null && !ad.getReachableStates().isEmpty()) { // TODO: Woher kommt der zu erreichende Status;
--- a/gnv/src/main/java/de/intevation/gnv/action/SelectArtifactFactoryAction.java Fri Oct 02 14:29:08 2009 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/action/SelectArtifactFactoryAction.java Fri Oct 02 14:55:18 2009 +0000 @@ -64,7 +64,8 @@ ArtifactObject af = sm.getSelectedArtifactFactory(); ; ArtifactDatabaseClient adc = ArtifactDatabaseClientFactory - .getInstance().getArtifactDatabaseClient(); + .getInstance() + .getArtifactDatabaseClient(getLocale(request)); ArtifactObject artifact = adc.createNewArtifact(af); sm.setCurrentArtifact(artifact);
--- a/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClient.java Fri Oct 02 14:29:08 2009 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClient.java Fri Oct 02 14:55:18 2009 +0000 @@ -5,6 +5,7 @@ import java.io.OutputStream; import java.util.Collection; +import java.util.Locale; import de.intevation.gnv.artifactdatabase.client.exception.ArtifactDatabaseClientException; import de.intevation.gnv.artifactdatabase.objects.ArtifactDescription; @@ -104,4 +105,6 @@ ArtifactObject artifactFactory, ArtifactObject currentArtifact) throws ArtifactDatabaseClientException; + + public void setLocale(Locale locale); }
--- a/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClientFactory.java Fri Oct 02 14:29:08 2009 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClientFactory.java Fri Oct 02 14:55:18 2009 +0000 @@ -5,6 +5,8 @@ import org.apache.log4j.Logger; +import java.util.Locale; + /** * @author Tim Englich <tim.englich@intevation.de> * @@ -34,7 +36,7 @@ * * @return an singleton Instance of this Class */ - public static ArtifactDatabaseClientFactory getInstance() { + public static synchronized ArtifactDatabaseClientFactory getInstance() { if (instance == null) { instance = new ArtifactDatabaseClientFactory(); } @@ -43,12 +45,15 @@ /** * Getting the ArtifactDatabaseClient - * + * @param locale teh Local that should be used for the Communication * @return the ArtifactDatabaseClient */ - public ArtifactDatabaseClient getArtifactDatabaseClient() { + public ArtifactDatabaseClient getArtifactDatabaseClient(Locale locale) { // TODO Read from Configuration? - return new DefaultArtifactDatabaseClient(); + DefaultArtifactDatabaseClient adc = new DefaultArtifactDatabaseClient(); + adc.setLocale(locale); + return adc; + } }
--- a/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java Fri Oct 02 14:29:08 2009 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java Fri Oct 02 14:55:18 2009 +0000 @@ -11,13 +11,21 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; +import java.util.List; +import java.util.Locale; import org.apache.log4j.Logger; + import org.restlet.Client; + import org.restlet.data.Method; import org.restlet.data.Protocol; import org.restlet.data.Request; import org.restlet.data.Response; +import org.restlet.data.Preference; +import org.restlet.data.Language; +import org.restlet.data.ClientInfo; + import org.restlet.representation.Representation; import org.restlet.representation.StringRepresentation; import org.w3c.dom.Document; @@ -73,10 +81,16 @@ private static boolean initialized = false; /** + * Request locale + */ + private Locale locale; + + + /** * Constructor */ public DefaultArtifactDatabaseClient() { - super(); + } /** @@ -151,6 +165,24 @@ return document; } + protected Request initialize(Request request) { + return initialize(request, locale); + } + + protected Request initialize(Request request, Locale locale) { + if (locale != null) { + ClientInfo clientInfo = request.getClientInfo(); + String lang = locale.getLanguage(); + Language language = new Language(lang); + List<Preference<Language>> acceptedLanguages = + new ArrayList<Preference<Language>>(2); + acceptedLanguages.add(new Preference(language, 1.0f)); + acceptedLanguages.add(new Preference(Language.ALL, 0.5f)); + clientInfo.setAcceptedLanguages(acceptedLanguages); + } + return request; + } + /** * @param requestUrl * @param requestBody @@ -159,7 +191,7 @@ private Representation doGetRequestInternal(String requestUrl, Document requestBody) { Client client = new Client(Protocol.HTTP); - Request request = new Request(Method.GET, requestUrl); + Request request = initialize(new Request(Method.GET, requestUrl)); if (requestBody != null) { String documentBody = new XMLUtils() .writeDocument2String(requestBody); @@ -182,7 +214,7 @@ log.debug(new XMLUtils().writeDocument2String(requestBody)); log.debug("##################################################"); Client client = new Client(Protocol.HTTP); - Request request = new Request(Method.POST, requestUrl); + Request request = initialize(new Request(Method.POST, requestUrl)); String documentBody = new XMLUtils().writeDocument2String(requestBody); Representation representation = new StringRepresentation(documentBody); request.setEntity(representation); @@ -655,4 +687,8 @@ return result; } + + public void setLocale(Locale locale) { + this.locale = locale; + } }
--- a/gnv/src/test/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClientTestCase.java Fri Oct 02 14:29:08 2009 +0000 +++ b/gnv/src/test/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClientTestCase.java Fri Oct 02 14:55:18 2009 +0000 @@ -6,6 +6,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; +import java.util.Locale; import junit.framework.TestCase; @@ -56,7 +57,7 @@ try { ArtifactDatabaseClient artifactDatabaseClient = ArtifactDatabaseClientFactory - .getInstance().getArtifactDatabaseClient(); + .getInstance().getArtifactDatabaseClient(Locale.GERMAN); Collection<ArtifactObject> factories = artifactDatabaseClient .getArtifactFactories(); if (factories != null && !factories.isEmpty()) {