Author: fdesbois Date: 2010-07-08 14:24:16 +0000 (Thu, 08 Jul 2010) New Revision: 594 Log: Evo #2352 : Cartography for contacts : - Add some javadoc Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/KmlStreamResponse.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Cartography.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/KmlLoader.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/KmlLoaderStrategy.java Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/KmlStreamResponse.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/KmlStreamResponse.java 2010-07-08 14:12:28 UTC (rev 593) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/KmlStreamResponse.java 2010-07-08 14:24:16 UTC (rev 594) @@ -1,5 +1,7 @@ package fr.ifremer.wao.ui.data; +import fr.ifremer.wao.ui.pages.KmlLoader; +import fr.ifremer.wao.ui.services.KmlLoaderStrategy; import org.apache.commons.io.FileUtils; import org.apache.tapestry5.StreamResponse; import org.apache.tapestry5.services.Response; @@ -12,10 +14,14 @@ import java.io.InputStream; /** + * StreamResponse for Kml files. + * <p /> * Created: 6 juil. 2010 * * @author fdesbois <fdesbois at codelutin.com> * @version $Id$ + * @see KmlLoaderStrategy + * @see KmlLoader */ public class KmlStreamResponse implements StreamResponse { @@ -33,6 +39,7 @@ @Override public String getContentType() { + // official mime-type for Kml file return "application/vnd.google-earth.kml+xml"; } @@ -43,6 +50,7 @@ @Override public void prepareResponse(Response response) { - response.setHeader("Content-Length", "" + length); + // need to specify the Content-Length to avoid auto chunked Transfer-Encoding + response.setHeader("Content-Length", String.valueOf(length)); } } Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Cartography.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Cartography.java 2010-07-08 14:12:28 UTC (rev 593) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Cartography.java 2010-07-08 14:24:16 UTC (rev 594) @@ -58,8 +58,4 @@ public String getTitle() { return "Contacts"; } - - public String getRandomCode() { - return RandomStringUtils.randomAlphanumeric(8); - } } Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/KmlLoader.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/KmlLoader.java 2010-07-08 14:12:28 UTC (rev 593) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/KmlLoader.java 2010-07-08 14:24:16 UTC (rev 594) @@ -12,6 +12,10 @@ import java.io.IOException; /** + * Page used directly as url for OpenLayers Kml reference. The activate method + * will return the StreamResponse with Kml data depends on {@link StrategyValues} + * defined as first element in page context. + * * Created: 6 juil. 2010 * * @author fdesbois <fdesbois at codelutin.com> @@ -20,6 +24,7 @@ @RequiresAuthentication public class KmlLoader { + /** Strategy values for loading Kml */ public enum StrategyValues { CONTACTS; } @@ -30,17 +35,37 @@ @Inject private ServiceUser serviceUser; + /** + * This method will directly return the correct Kml file depends on strategy + * from {@code activationContext}. Other elements used by strategies can + * be passed to the context (like filter values). Available strategies are + * defined in {@link StrategyValues} enumeration. + * + * @param activationContext Context of the page. + * @return the StreamResponse that contains Kml data. + * @throws IOException + * @see KmlLoaderStrategy#getStreamResponse(Object...) + */ StreamResponse onActivate(Object... activationContext) throws IOException { - + // Retrive context data String first = TapestryUtil.getFirstString(activationContext); Object[] other = TapestryUtil.getOtherContext(activationContext); - KmlLoaderStrategy strategy = getStrategy(StrategyValues.valueOf(first)); + // Create strategy depends on first value in page context. + KmlLoaderStrategy strategy = createStrategy(StrategyValues.valueOf(first)); + // Return the StreamResponse from the Strategy return strategy.getStreamResponse(other); } - KmlLoaderStrategy getStrategy(StrategyValues value) { + /** + * Instantiate the strategy depends on {@code value}. + * + * @param value StrategyValues to define wich implementation to choose. + * @return the KmlLoaderStrategy to use + * @throws IllegalArgumentException if the strategy is not supported + */ + KmlLoaderStrategy createStrategy(StrategyValues value) throws IllegalArgumentException { switch (value) { case CONTACTS: return new KmlLoaderStrategyContacts(serviceCartography, serviceUser); Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/KmlLoaderStrategy.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/KmlLoaderStrategy.java 2010-07-08 14:12:28 UTC (rev 593) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/KmlLoaderStrategy.java 2010-07-08 14:24:16 UTC (rev 594) @@ -1,17 +1,28 @@ package fr.ifremer.wao.ui.services; import fr.ifremer.wao.entity.Company; +import fr.ifremer.wao.ui.pages.KmlLoader; import org.apache.tapestry5.StreamResponse; import java.io.IOException; /** + * This Service is used to retrieve StreamResponse for KmlLoader page. + * * Created: 8 juil. 2010 * * @author fdesbois <fdesbois at codelutin.com> * @version $Id$ + * @see KmlLoader */ public interface KmlLoaderStrategy { + /** + * Retrieve the StreamResponse for this Strategy. + * + * @param context Strategy context + * @return the StreamResponse to use in KmlLoader + * @throws IOException for error on StreamResponse creation + */ StreamResponse getStreamResponse(Object... context) throws IOException; }