Author: fdesbois Date: 2010-07-08 14:12:28 +0000 (Thu, 08 Jul 2010) New Revision: 593 Log: Evo #2352 : Cartography for contacts : - Resolve problem on using KmlLoader page - Resolve problem with chart url - Comment xpp3 code for parsing Kml Added: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/KmlStreamResponse.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/TapestryUtil.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 trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/KmlLoaderStrategyContacts.java Removed: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/AuthenticationUtil.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/ContactsKmlLoader.java Modified: trunk/changelog.txt trunk/pom.xml trunk/wao-business/pom.xml trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReaderXpp3.java trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceCartographyImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java trunk/wao-business/src/main/xmi/wao.zargo trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Cartography.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Connexion.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/ServiceChartImpl.java trunk/wao-ui/src/main/webapp/Cartography.tml Modified: trunk/changelog.txt =================================================================== --- trunk/changelog.txt 2010-07-07 17:49:30 UTC (rev 592) +++ trunk/changelog.txt 2010-07-08 14:12:28 UTC (rev 593) @@ -14,8 +14,15 @@ Mise à jour librairies ++++++++++++++++++++++ -- **mavenpom4labs** 2.2 -> 2.2.1 [http://maven-site.nuiton.org/mavenpom/mavenpom4labs] +- **OpenLayers** 2.9.1 [http://openlayers.org/] +- **Apache Xerces** 2.8.1 [http://xerces.apache.org/] +- **JAXB** 2.2 [http://java.sun.com/developer/technicalArticles/WebServices/jaxb/] +- **JavaApiforKml** 2.2.0 [http://code.google.com/p/javaapiforkml/] +- **H2** 1.2.132 -> 1.2.137 [http://www.h2database.com/html/main.html] +- **EUGene** 2.0.2 -> 2.1 [http://maven-site.nuiton.org/eugene] +- **mavenpom4labs** 2.2 -> 2.2.2.1 [http://maven-site.nuiton.org/mavenpom/mavenpom4labs] + 1.4.1 ----- Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2010-07-07 17:49:30 UTC (rev 592) +++ trunk/pom.xml 2010-07-08 14:12:28 UTC (rev 593) @@ -161,21 +161,25 @@ <artifactId>jaxb-xjc</artifactId> <version>2.2</version> </dependency> + <!-- + Note : classes used from Xerces are deprecated since 2.9 + Don't know how to replace behavior used in Kml writing. + --> <dependency> <groupId>xerces</groupId> - <artifactId>xerces</artifactId> - <version>2.4.0</version> + <artifactId>xercesImpl</artifactId> + <version>2.8.1</version> </dependency> - <dependency> - <groupId>xpp3</groupId> - <artifactId>xpp3</artifactId> - <version>1.1.4c</version> - </dependency> - <dependency> - <groupId>xpp3</groupId> - <artifactId>xpp3_xpath</artifactId> - <version>1.1.4c</version> - </dependency> + <!--<dependency>--> + <!--<groupId>xpp3</groupId>--> + <!--<artifactId>xpp3</artifactId>--> + <!--<version>1.1.4c</version>--> + <!--</dependency>--> + <!--<dependency>--> + <!--<groupId>xpp3</groupId>--> + <!--<artifactId>xpp3_xpath</artifactId>--> + <!--<version>1.1.4c</version>--> + <!--</dependency>--> <!-- Csv import/export --> <dependency> <groupId>net.sourceforge.javacsv</groupId> @@ -186,7 +190,7 @@ <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> - <version>1.2.132</version> + <version>1.2.137</version> </dependency> <dependency> <groupId>postgresql</groupId> @@ -285,7 +289,7 @@ <nuitonutils.version>1.3.1</nuitonutils.version> <nuitonweb.version>0.1</nuitonweb.version> <topia.version>2.3.5-SNAPSHOT</topia.version> - <eugene.version>2.1-SNAPSHOT</eugene.version> + <eugene.version>2.1</eugene.version> <tapestry.version>5.1.0.5</tapestry.version> </properties> Modified: trunk/wao-business/pom.xml =================================================================== --- trunk/wao-business/pom.xml 2010-07-07 17:49:30 UTC (rev 592) +++ trunk/wao-business/pom.xml 2010-07-08 14:12:28 UTC (rev 593) @@ -68,16 +68,16 @@ </dependency> <dependency> <groupId>xerces</groupId> - <artifactId>xerces</artifactId> + <artifactId>xercesImpl</artifactId> </dependency> - <dependency> - <groupId>xpp3</groupId> - <artifactId>xpp3</artifactId> - </dependency> - <dependency> - <groupId>xpp3</groupId> - <artifactId>xpp3_xpath</artifactId> - </dependency> + <!--<dependency>--> + <!--<groupId>xpp3</groupId>--> + <!--<artifactId>xpp3</artifactId>--> + <!--</dependency>--> + <!--<dependency>--> + <!--<groupId>xpp3</groupId>--> + <!--<artifactId>xpp3_xpath</artifactId>--> + <!--</dependency>--> <!-- ToPIA --> <dependency> <groupId>org.nuiton.topia</groupId> Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReaderXpp3.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReaderXpp3.java 2010-07-07 17:49:30 UTC (rev 592) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReaderXpp3.java 2010-07-08 14:12:28 UTC (rev 593) @@ -4,12 +4,12 @@ import fr.ifremer.wao.io.BoatDistrictDataImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.xmlpull.v1.builder.XmlCharacters; -import org.xmlpull.v1.builder.XmlDocument; -import org.xmlpull.v1.builder.XmlElement; -import org.xmlpull.v1.builder.XmlInfosetBuilder; -import org.xmlpull.v1.builder.xpath.Xb1XPath; -import org.xmlpull.v1.builder.xpath.jaxen.XPath; +//import org.xmlpull.v1.builder.XmlCharacters; +//import org.xmlpull.v1.builder.XmlDocument; +//import org.xmlpull.v1.builder.XmlElement; +//import org.xmlpull.v1.builder.XmlInfosetBuilder; +//import org.xmlpull.v1.builder.xpath.Xb1XPath; +//import org.xmlpull.v1.builder.xpath.jaxen.XPath; import java.io.IOException; import java.io.InputStream; @@ -35,46 +35,47 @@ private static final String ATTRIBUTE_SCHEMA_DATA_NAME = "name"; - Iterator<XmlElement> iterator; +// Iterator<XmlElement> iterator; InputStreamReader reader; @Override public void init(InputStream stream) throws IOException { - if (logger.isDebugEnabled()) { - logger.debug("Read stream Kml"); - } - - reader = new InputStreamReader(stream); - - XPath xpath = new Xb1XPath(PATH_PLACEMARK); - - XmlInfosetBuilder builder = XmlInfosetBuilder.newInstance(); - - XmlDocument doc = builder.parseReader(reader); - - if (logger.isDebugEnabled()) { - Iterator it = doc.children().iterator(); - while (it.hasNext()) { - logger.debug("onInit :: element : " + ((XmlElement)it.next()).getName()); - } - } - - List results = xpath.selectNodes(doc); - - if (logger.isDebugEnabled()) { - for (Object element : results) { - logger.debug("onInit :: element : " + ((XmlElement)element).getName()); - } - } - - iterator = results.iterator(); +// if (logger.isDebugEnabled()) { +// logger.debug("Read stream Kml"); +// } +// +// reader = new InputStreamReader(stream); +// +// XPath xpath = new Xb1XPath(PATH_PLACEMARK); +// +// XmlInfosetBuilder builder = XmlInfosetBuilder.newInstance(); +// +// XmlDocument doc = builder.parseReader(reader); +// +// if (logger.isDebugEnabled()) { +// Iterator it = doc.children().iterator(); +// while (it.hasNext()) { +// logger.debug("onInit :: element : " + ((XmlElement)it.next()).getName()); +// } +// } +// +// List results = xpath.selectNodes(doc); +// +// if (logger.isDebugEnabled()) { +// for (Object element : results) { +// logger.debug("onInit :: element : " + ((XmlElement)element).getName()); +// } +// } +// +// iterator = results.iterator(); } @Override public boolean hasNext() { - return iterator.hasNext(); +// return iterator.hasNext(); + return false; } @Override @@ -82,49 +83,49 @@ BoatDistrictData district = new BoatDistrictDataImpl(); - XmlElement element = iterator.next(); +// XmlElement element = iterator.next(); +// +// if (logger.isDebugEnabled()) { +// logger.debug("element : " + element.getName()); +// } +// +// readSchemaData(element, district); +// +// readCoordinates(element, district); - if (logger.isDebugEnabled()) { - logger.debug("element : " + element.getName()); - } - - readSchemaData(element, district); - - readCoordinates(element, district); - return district; } - protected void readSchemaData(XmlElement element, BoatDistrictData district) { - XPath xpath = new Xb1XPath(PATH_SIMPLE_DATA); - List<XmlElement> results = xpath.selectNodes(element); - for (XmlElement data : results) { +// protected void readSchemaData(XmlElement element, BoatDistrictData district) { +// XPath xpath = new Xb1XPath(PATH_SIMPLE_DATA); +// List<XmlElement> results = xpath.selectNodes(element); +// for (XmlElement data : results) { +// +// String dataLabel = data.getAttributeValue(null, ATTRIBUTE_SCHEMA_DATA_NAME); +// +// if (logger.isDebugEnabled()) { +// logger.debug("data : " + data.getName() + " _ label = " + dataLabel); +// } +// +// BoatDistrictSchemaData schemaData = +// BoatDistrictSchemaData.valueOfLabel(dataLabel); +// +// XmlCharacters chars = (XmlCharacters) data.children().next(); +// +// schemaData.setPropertyValue(district, chars.getText()); +// } +// } +// +// protected void readCoordinates(XmlElement element, BoatDistrictData district) { +// XPath xpath = new Xb1XPath(PATH_COORDINATES); +// XmlElement coordinatesElement = (XmlElement) xpath.selectSingleNode(element); +// XmlCharacters chars = (XmlCharacters) coordinatesElement.children().next(); +// String[] coordinates = chars.getText().split(","); +// +// district.setLongitude(Double.valueOf(coordinates[0])); +// district.setLatitude(Double.valueOf(coordinates[1])); +// } - String dataLabel = data.getAttributeValue(null, ATTRIBUTE_SCHEMA_DATA_NAME); - - if (logger.isDebugEnabled()) { - logger.debug("data : " + data.getName() + " _ label = " + dataLabel); - } - - BoatDistrictSchemaData schemaData = - BoatDistrictSchemaData.valueOfLabel(dataLabel); - - XmlCharacters chars = (XmlCharacters) data.children().next(); - - schemaData.setPropertyValue(district, chars.getText()); - } - } - - protected void readCoordinates(XmlElement element, BoatDistrictData district) { - XPath xpath = new Xb1XPath(PATH_COORDINATES); - XmlElement coordinatesElement = (XmlElement) xpath.selectSingleNode(element); - XmlCharacters chars = (XmlCharacters) coordinatesElement.children().next(); - String[] coordinates = chars.getText().split(","); - - district.setLongitude(Double.valueOf(coordinates[0])); - district.setLatitude(Double.valueOf(coordinates[1])); - } - @Override public void close() throws IOException { if (reader != null) { Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceCartographyImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceCartographyImpl.java 2010-07-07 17:49:30 UTC (rev 592) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceCartographyImpl.java 2010-07-08 14:12:28 UTC (rev 593) @@ -3,23 +3,21 @@ import fr.ifremer.wao.WaoContext; import fr.ifremer.wao.WaoDAOHelper; import fr.ifremer.wao.WaoException; -import fr.ifremer.wao.WaoQueryHelper; import fr.ifremer.wao.bean.ContactPieChartConstant; import fr.ifremer.wao.bean.ContactState; import fr.ifremer.wao.bean.PieChartData; +import fr.ifremer.wao.entity.BoatDistrict; +import fr.ifremer.wao.entity.BoatDistrictDAO; import fr.ifremer.wao.entity.Company; import fr.ifremer.wao.io.BoatDistrictData; -import fr.ifremer.wao.io.kml.KmlReader; -import fr.ifremer.wao.io.kml.KmlIOFactory; import fr.ifremer.wao.io.ImportResults; import fr.ifremer.wao.io.ImportResultsImpl; -import fr.ifremer.wao.entity.BoatDistrict; -import fr.ifremer.wao.entity.BoatDistrictDAO; +import fr.ifremer.wao.io.kml.KmlIOFactory; +import fr.ifremer.wao.io.kml.KmlReader; import fr.ifremer.wao.io.kml.KmlWriter; import org.apache.commons.io.FileUtils; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; -import org.nuiton.topia.framework.TopiaQuery; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -30,7 +28,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.text.NumberFormat; -import java.util.List; import java.util.Map; /** Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java 2010-07-07 17:49:30 UTC (rev 592) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java 2010-07-08 14:12:28 UTC (rev 593) @@ -584,8 +584,8 @@ addNotNull(boatDistrictProperty.latitude()). addNotNull(boatDistrictProperty.longitude()). // Don't take contacts refused by company or program - addWhere(contactProperty.validationCompany(), Op.NEQ, Boolean.FALSE). - addWhere(contactProperty.validationProgram(), Op.NEQ, Boolean.FALSE); + addNullOr(contactProperty.validationCompany(), Op.NEQ, Boolean.FALSE). + addNullOr(contactProperty.validationProgram(), Op.NEQ, Boolean.FALSE); if (company != null) { query.addEquals(contactProperty.observerProperty().company(), company); Modified: trunk/wao-business/src/main/xmi/wao.zargo =================================================================== (Binary files differ) Deleted: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/AuthenticationUtil.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/AuthenticationUtil.java 2010-07-07 17:49:30 UTC (rev 592) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/AuthenticationUtil.java 2010-07-08 14:12:28 UTC (rev 593) @@ -1,51 +0,0 @@ -/* - * #%L - * Wao :: Web Interface - * %% - * Copyright (C) 2009 - 2010 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -package fr.ifremer.wao.ui.data; - -import java.util.Arrays; - -/** - * Created: 12 juin 2010 - * - * @author fdesbois <fdesbois at codelutin.com> - * @version $Id$ - */ -public class AuthenticationUtil { - - public static String getRedirectPageName(Object[] activationContext) { - String redirectPage = null; - if (activationContext.length > 0) { - redirectPage = (String)activationContext[0]; - } - return redirectPage; - } - - public static Object[] getRedirectPageContext(Object[] activationContext) { - if (activationContext.length > 1) { - Object[] redirectPageContext = - Arrays.copyOfRange(activationContext, 1, - activationContext.length); - return redirectPageContext; - } - return null; - } -} Added: 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 (rev 0) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/KmlStreamResponse.java 2010-07-08 14:12:28 UTC (rev 593) @@ -0,0 +1,48 @@ +package fr.ifremer.wao.ui.data; + +import org.apache.commons.io.FileUtils; +import org.apache.tapestry5.StreamResponse; +import org.apache.tapestry5.services.Response; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +/** + * Created: 6 juil. 2010 + * + * @author fdesbois <fdesbois at codelutin.com> + * @version $Id$ + */ +public class KmlStreamResponse implements StreamResponse { + + private static final Logger logger = + LoggerFactory.getLogger(KmlStreamResponse.class); + + protected InputStream stream; + + protected int length; + + public KmlStreamResponse(InputStream stream) throws IOException { + this.stream = stream; + this.length = stream.available(); + } + + @Override + public String getContentType() { + return "application/vnd.google-earth.kml+xml"; + } + + @Override + public InputStream getStream() throws IOException { + return stream; + } + + @Override + public void prepareResponse(Response response) { + response.setHeader("Content-Length", "" + length); + } +} Copied: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/TapestryUtil.java (from rev 590, trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/AuthenticationUtil.java) =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/TapestryUtil.java (rev 0) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/TapestryUtil.java 2010-07-08 14:12:28 UTC (rev 593) @@ -0,0 +1,51 @@ +/* + * #%L + * Wao :: Web Interface + * %% + * Copyright (C) 2009 - 2010 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ifremer.wao.ui.data; + +import java.util.Arrays; + +/** + * Created: 12 juin 2010 + * + * @author fdesbois <fdesbois at codelutin.com> + * @version $Id$ + */ +public class TapestryUtil { + + public static String getFirstString(Object[] activationContext) { + String firstString = null; + if (activationContext.length > 0) { + firstString = (String)activationContext[0]; + } + return firstString; + } + + public static Object[] getOtherContext(Object[] activationContext) { + if (activationContext.length > 1) { + Object[] otherContext = + Arrays.copyOfRange(activationContext, 1, + activationContext.length); + return otherContext; + } + return null; + } +} Property changes on: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/TapestryUtil.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL 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-07 17:49:30 UTC (rev 592) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Cartography.java 2010-07-08 14:12:28 UTC (rev 593) @@ -4,18 +4,14 @@ import fr.ifremer.wao.entity.Company; import fr.ifremer.wao.service.ServiceCartography; import fr.ifremer.wao.ui.data.RequiresAuthentication; -import org.apache.commons.io.IOUtils; import org.apache.commons.lang.RandomStringUtils; -import org.apache.commons.lang.math.RandomUtils; import org.apache.tapestry5.Link; import org.apache.tapestry5.annotations.SessionState; import org.apache.tapestry5.ioc.annotations.Inject; import org.apache.tapestry5.services.PageRenderLinkSource; import org.slf4j.Logger; -import java.io.File; import java.io.IOException; -import java.io.InputStream; /** * Created: 6 juil. 2010 @@ -30,9 +26,6 @@ private ConnectedUser user; @Inject - private ServiceCartography serviceCartography; - - @Inject private PageRenderLinkSource pageRender; @Inject @@ -43,7 +36,7 @@ private String url; public Company getCompany() { - if (!user.isAdmin() && !user.isGuest()) { + if (company == null && !user.isAdmin() && !user.isGuest()) { company = user.getCompany(); } return company; @@ -52,7 +45,11 @@ public String getUrl() throws IOException { if (url == null) { String companyId = getCompany() != null ? getCompany().getTopiaId() : null; - Link link = pageRender.createPageRenderLinkWithContext(ContactsKmlLoader.class, companyId); + Link link = pageRender.createPageRenderLinkWithContext( + KmlLoader.class, + KmlLoader.StrategyValues.CONTACTS, + companyId + ); url = link.toURI(); } return url; Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Connexion.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Connexion.java 2010-07-07 17:49:30 UTC (rev 592) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Connexion.java 2010-07-08 14:12:28 UTC (rev 593) @@ -30,7 +30,7 @@ import fr.ifremer.wao.entity.WaoUser; import fr.ifremer.wao.service.ServiceUser; import fr.ifremer.wao.ui.components.FeedBack; -import fr.ifremer.wao.ui.data.AuthenticationUtil; +import fr.ifremer.wao.ui.data.TapestryUtil; import fr.ifremer.wao.ui.services.RequiresAuthenticationFilter; import fr.ifremer.wao.ui.services.ServiceAuthentication; import org.apache.tapestry5.Link; @@ -204,7 +204,7 @@ */ private Link getRedirectLink() { String redirectPage = - AuthenticationUtil.getRedirectPageName(activationContext); + TapestryUtil.getFirstString(activationContext); // If redirectPage is not defined, the default one is the Index page if (redirectPage == null) { @@ -212,7 +212,7 @@ } Object[] redirectPageContext = - AuthenticationUtil.getRedirectPageContext(activationContext); + TapestryUtil.getOtherContext(activationContext); if (logger.isDebugEnabled()) { logger.debug("Redirect page '" + redirectPage + "' " + Deleted: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/ContactsKmlLoader.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/ContactsKmlLoader.java 2010-07-07 17:49:30 UTC (rev 592) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/ContactsKmlLoader.java 2010-07-08 14:12:28 UTC (rev 593) @@ -1,69 +0,0 @@ -package fr.ifremer.wao.ui.pages; - -import fr.ifremer.wao.entity.Company; -import fr.ifremer.wao.service.ServiceCartography; -import fr.ifremer.wao.service.ServiceUser; -import fr.ifremer.wao.ui.data.RequiresAuthentication; -import fr.ifremer.wao.ui.services.WaoManager; -import org.apache.commons.lang.StringUtils; -import org.apache.tapestry5.EventContext; -import org.apache.tapestry5.StreamResponse; -import org.apache.tapestry5.ioc.annotations.Inject; -import org.apache.tapestry5.services.Response; - -import java.io.IOException; -import java.io.InputStream; - -/** - * Created: 6 juil. 2010 - * - * @author fdesbois <fdesbois at codelutin.com> - * @version $Id$ - */ - at RequiresAuthentication -public class ContactsKmlLoader { - - @Inject - private ServiceCartography serviceCartography; - - @Inject - private ServiceUser serviceUser; - - @Inject - private WaoManager manager; - - private String companyId; - - private Company company; - - Company getCompany() { - if (company == null && StringUtils.isNotEmpty(companyId)) { - company = serviceUser.getCompany(companyId); - } - return company; - } - - StreamResponse onActivate(EventContext ec) { - - if (ec.getCount() > 0) { - companyId = ec.get(String.class, 0); - } - - return new StreamResponse() { - - @Override - public String getContentType() { - return "application/vnd.google-earth.kml+xml"; - } - - @Override - public InputStream getStream() throws IOException { - return serviceCartography.exportContactStatisticsKml(getCompany()); - } - - @Override - public void prepareResponse(Response response) { - } - }; - } -} Copied: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/KmlLoader.java (from rev 592, trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/ContactsKmlLoader.java) =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/KmlLoader.java (rev 0) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/KmlLoader.java 2010-07-08 14:12:28 UTC (rev 593) @@ -0,0 +1,50 @@ +package fr.ifremer.wao.ui.pages; + +import fr.ifremer.wao.service.ServiceCartography; +import fr.ifremer.wao.service.ServiceUser; +import fr.ifremer.wao.ui.services.KmlLoaderStrategy; +import fr.ifremer.wao.ui.services.KmlLoaderStrategyContacts; +import fr.ifremer.wao.ui.data.RequiresAuthentication; +import fr.ifremer.wao.ui.data.TapestryUtil; +import org.apache.tapestry5.StreamResponse; +import org.apache.tapestry5.ioc.annotations.Inject; + +import java.io.IOException; + +/** + * Created: 6 juil. 2010 + * + * @author fdesbois <fdesbois at codelutin.com> + * @version $Id$ + */ + at RequiresAuthentication +public class KmlLoader { + + public enum StrategyValues { + CONTACTS; + } + + @Inject + private ServiceCartography serviceCartography; + + @Inject + private ServiceUser serviceUser; + + StreamResponse onActivate(Object... activationContext) throws IOException { + + String first = TapestryUtil.getFirstString(activationContext); + Object[] other = TapestryUtil.getOtherContext(activationContext); + + KmlLoaderStrategy strategy = getStrategy(StrategyValues.valueOf(first)); + + return strategy.getStreamResponse(other); + } + + KmlLoaderStrategy getStrategy(StrategyValues value) { + switch (value) { + case CONTACTS: + return new KmlLoaderStrategyContacts(serviceCartography, serviceUser); + } + throw new IllegalArgumentException(value + " is not supported as KmlLoaderStrategy"); + } +} Property changes on: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/KmlLoader.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: 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 (rev 0) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/KmlLoaderStrategy.java 2010-07-08 14:12:28 UTC (rev 593) @@ -0,0 +1,17 @@ +package fr.ifremer.wao.ui.services; + +import fr.ifremer.wao.entity.Company; +import org.apache.tapestry5.StreamResponse; + +import java.io.IOException; + +/** + * Created: 8 juil. 2010 + * + * @author fdesbois <fdesbois at codelutin.com> + * @version $Id$ + */ +public interface KmlLoaderStrategy { + + StreamResponse getStreamResponse(Object... context) throws IOException; +} Added: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/KmlLoaderStrategyContacts.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/KmlLoaderStrategyContacts.java (rev 0) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/KmlLoaderStrategyContacts.java 2010-07-08 14:12:28 UTC (rev 593) @@ -0,0 +1,42 @@ +package fr.ifremer.wao.ui.services; + +import fr.ifremer.wao.entity.Company; +import fr.ifremer.wao.service.ServiceCartography; +import fr.ifremer.wao.service.ServiceUser; +import fr.ifremer.wao.ui.data.KmlStreamResponse; +import org.apache.tapestry5.StreamResponse; + +import java.io.IOException; + +/** + * Created: 8 juil. 2010 + * + * @author fdesbois <fdesbois at codelutin.com> + * @version $Id$ + */ +public class KmlLoaderStrategyContacts implements KmlLoaderStrategy { + + protected ServiceCartography serviceCartography; + + protected ServiceUser serviceUser; + + public KmlLoaderStrategyContacts(ServiceCartography serviceCartography, + ServiceUser serviceUser) { + this.serviceCartography = serviceCartography; + this.serviceUser = serviceUser; + } + + @Override + public StreamResponse getStreamResponse(Object... context) throws IOException { + + Company company = null; + if (context != null && context.length > 0) { + String companyId = (String)context[0]; + company = serviceUser.getCompany(companyId); + } + + return new KmlStreamResponse( + serviceCartography.exportContactStatisticsKml(company) + ); + } +} Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/ServiceChartImpl.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/ServiceChartImpl.java 2010-07-07 17:49:30 UTC (rev 592) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/ServiceChartImpl.java 2010-07-08 14:12:28 UTC (rev 593) @@ -6,6 +6,8 @@ import fr.ifremer.wao.ui.pages.PieChart; import org.apache.tapestry5.Link; import org.apache.tapestry5.services.PageRenderLinkSource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Implementation of {@link ServiceChart} that create urls to charts. @@ -18,6 +20,8 @@ */ public class ServiceChartImpl extends ServiceChartServlet { + private static final Logger logger = LoggerFactory.getLogger(ServiceChartImpl.class); + /** Service used to create links */ private PageRenderLinkSource pageRender; @@ -32,11 +36,14 @@ Link link = pageRender.createPageRenderLinkWithContext( PieChart.class, data, thumb); - return getBaseUrl() + link.toURI(); + return getBaseUrl() + link.toAbsoluteURI(); } + @Override protected String getBaseUrl() { - return "http://" + WaoProperty.SERVER_PATH.getValue() + "/"; + // Get only the first element in the server_path which is the host name of the server + String[] res = WaoProperty.SERVER_PATH.getValue().split("/"); + return "http://" + res[0]; } } Modified: trunk/wao-ui/src/main/webapp/Cartography.tml =================================================================== --- trunk/wao-ui/src/main/webapp/Cartography.tml 2010-07-07 17:49:30 UTC (rev 592) +++ trunk/wao-ui/src/main/webapp/Cartography.tml 2010-07-08 14:12:28 UTC (rev 593) @@ -36,7 +36,7 @@ <script type="text/javascript" src="${asset:context:js/cartography.js}"/> <script type="text/javascript" src="${asset:context:js/OpenLayers/OpenLayers.js}"></script> </head> - <body id="so-cartography" onload="init('${url}?${randomCode}', '${title}');"> + <body id="so-cartography" onload="init('${url}', '${title}');"> <div id="map"></div>