r1424 - in trunk: . src/main/java/cc/kune/core/client/services src/main/java/cc/kune/core/server src/main/java/cc/kune/core/server/manager/file src/main/java/cc/kune/wave src/main/java/cc/kune/wave/client src/main/webapp/others
Author: vjrj_ Date: 2011-06-27 00:30:12 +0200 (Mon, 27 Jun 2011) New Revision: 1424 Added: trunk/src/main/java/cc/kune/core/server/manager/file/UserLogoDownloadManager.java trunk/src/main/java/cc/kune/wave/client/KuneWaveProfileManager.java trunk/src/main/webapp/others/unknown.jpg Modified: trunk/pom.xml trunk/src/main/java/cc/kune/core/client/services/FileConstants.java trunk/src/main/java/cc/kune/core/client/services/FileDownloadUtils.java trunk/src/main/java/cc/kune/core/server/KuneRackModule.java trunk/src/main/java/cc/kune/wave/KuneWave.gwt.xml trunk/src/main/java/cc/kune/wave/client/WaveClientManager.java trunk/src/main/java/cc/kune/wave/client/WaveGinModule.java trunk/src/main/java/cc/kune/wave/client/WebClient.java Log: Wave client avatar workaround Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2011-06-26 10:50:56 UTC (rev 1423) +++ trunk/pom.xml 2011-06-26 22:30:12 UTC (rev 1424) @@ -979,7 +979,7 @@ <module>${project.groupId}.Kune</module> </modules> <copyWebapp>true</copyWebapp> - <soyc>false</soyc> + <compileReport>false</compileReport> <extraJvmArgs>-Xmx1024m -Xss1024k</extraJvmArgs> </configuration> <executions> Modified: trunk/src/main/java/cc/kune/core/client/services/FileConstants.java =================================================================== --- trunk/src/main/java/cc/kune/core/client/services/FileConstants.java 2011-06-26 10:50:56 UTC (rev 1423) +++ trunk/src/main/java/cc/kune/core/client/services/FileConstants.java 2011-06-26 22:30:12 UTC (rev 1424) @@ -21,19 +21,20 @@ public final class FileConstants { - public final static String HASH = "hash"; - public final static String TOKEN = "token"; - public final static String DOWNLOAD = "download"; - public final static String IMGSIZE = "imgsize"; - public final static String FILENAME = "filename"; - public final static String TYPE_ID = "typeid"; - public final static String USER_LOGO_FIELD = "k-ulogov-ff"; - public final static String GROUP_LOGO_FIELD = "k-glogov-ff"; - public final static int LOGO_DEF_HEIGHT = 60; - public final static int LOGO_DEF_WIDTH = 468; - public final static int LOGO_MIN_HEIGHT = 28; - public final static int LOGO_MIN_WIDTH = 468; + public final static String DOWNLOAD = "download"; + public final static String FILENAME = "filename"; + public final static String GROUP_LOGO_FIELD = "k-glogov-ff"; + public final static String HASH = "hash"; + public final static String IMGSIZE = "imgsize"; + public final static int LOGO_DEF_HEIGHT = 60; + public final static int LOGO_DEF_WIDTH = 468; + public final static int LOGO_MIN_HEIGHT = 28; + public final static int LOGO_MIN_WIDTH = 468; + public final static String TOKEN = "token"; + public final static String TYPE_ID = "typeid"; + public final static String USER_LOGO_FIELD = "k-ulogov-ff"; + public final static String USERNAME = "username"; - private FileConstants() { - } + private FileConstants() { + } } Modified: trunk/src/main/java/cc/kune/core/client/services/FileDownloadUtils.java =================================================================== --- trunk/src/main/java/cc/kune/core/client/services/FileDownloadUtils.java 2011-06-26 10:50:56 UTC (rev 1423) +++ trunk/src/main/java/cc/kune/core/client/services/FileDownloadUtils.java 2011-06-26 22:30:12 UTC (rev 1424) @@ -33,6 +33,7 @@ public class FileDownloadUtils { + private static final String AVATARDOWNLOADSERVLET = "servlets/UserLogoDownloadManager"; private static final String BACKDOWNLOADSERVLET = "servlets/EntityBackgroundDownloadManager"; private static final String DOWNLOADSERVLET = "servlets/FileDownloadManager"; protected static final String GROUP_NO_AVATAR_IMAGE = "images/group-def-icon.png"; @@ -112,6 +113,11 @@ return calculateUrl(token, false, false); } + public String getUserAvatar(final String username) { + return new Url(GWT.getModuleBaseURL() + AVATARDOWNLOADSERVLET, new UrlParam(FileConstants.USERNAME, + username)).toString(); + } + public String getUserAvatar(final UserSimpleDTO user) { return user.hasLogo() ? getLogoImageUrl(user.getStateToken()) : PERSON_NO_AVATAR_IMAGE; } Modified: trunk/src/main/java/cc/kune/core/server/KuneRackModule.java =================================================================== --- trunk/src/main/java/cc/kune/core/server/KuneRackModule.java 2011-06-26 10:50:56 UTC (rev 1423) +++ trunk/src/main/java/cc/kune/core/server/KuneRackModule.java 2011-06-26 22:30:12 UTC (rev 1424) @@ -40,6 +40,7 @@ import cc.kune.core.server.manager.file.FileDownloadManager; import cc.kune.core.server.manager.file.FileGwtUploadServlet; import cc.kune.core.server.manager.file.FileUploadManager; +import cc.kune.core.server.manager.file.UserLogoDownloadManager; import cc.kune.core.server.properties.PropertiesFileName; import cc.kune.core.server.rack.RackBuilder; import cc.kune.core.server.rack.RackModule; @@ -142,7 +143,8 @@ UserJSONService.class, I18nTranslationJSONService.class, ContentJSONService.class); builder.installServlet("^/ws/servlets/", FileUploadManager.class, FileDownloadManager.class, EntityLogoUploadManager.class, EntityLogoDownloadManager.class, FileGwtUploadServlet.class, - EntityBackgroundDownloadManager.class, EntityBackgroundUploadManager.class); + EntityBackgroundDownloadManager.class, EntityBackgroundUploadManager.class, + UserLogoDownloadManager.class); builder.at("^/ws/(.*)$").install(new ForwardFilter("^/ws/(.*)$", "/ws/{0}")); } Added: trunk/src/main/java/cc/kune/core/server/manager/file/UserLogoDownloadManager.java =================================================================== --- trunk/src/main/java/cc/kune/core/server/manager/file/UserLogoDownloadManager.java (rev 0) +++ trunk/src/main/java/cc/kune/core/server/manager/file/UserLogoDownloadManager.java 2011-06-26 22:30:12 UTC (rev 1424) @@ -0,0 +1,86 @@ +/* + * + * Copyright (C) 2007-2011 The kune development team (see CREDITS for details) + * This file is part of kune. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + \*/ +package cc.kune.core.server.manager.file; + +import java.io.FileNotFoundException; +import java.io.IOException; + +import javax.persistence.NoResultException; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import cc.kune.core.client.services.FileConstants; +import cc.kune.core.server.manager.GroupManager; +import cc.kune.core.shared.domain.utils.StateToken; +import cc.kune.domain.Group; + +import com.google.inject.Inject; + +/** + * The Class UserLogoDownloadManager the difference with + * {@link EntityLogoDownloadManager} it that this class download an avatar using + * the username and if the user doesn't exits then returns the default avatar. + * + * This works only for users (right now). + */ +public class UserLogoDownloadManager extends HttpServlet { + + private static final long serialVersionUID = -1958945058088446881L; + @Inject + GroupManager groupManager; + + @Override + protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) + throws ServletException, IOException { + + final StateToken stateToken = new StateToken(req.getParameter(FileConstants.USERNAME)); + + Group group = Group.NO_GROUP; + try { + group = groupManager.findByShortName(stateToken.getGroup()); + if (group == Group.NO_GROUP) { + noResult(resp); + } else if (!group.hasLogo()) { + replyDefAvatar(resp); + } else { + // Has logo! + final byte[] logo = group.getLogo(); + resp.setContentLength(logo.length); + resp.setContentType(group.getLogoMime().toString()); + resp.setHeader("Content-Disposition", "attachment; filename=\"" + group.getShortName() + + "-logo\""); + resp.getOutputStream().write(logo); + } + } catch (final NoResultException e) { + noResult(resp); + return; + } + } + + private void noResult(final HttpServletResponse resp) throws IOException { + FileDownloadManagerUtils.returnNotFound(resp); + } + + private void replyDefAvatar(final HttpServletResponse resp) throws FileNotFoundException, IOException { + FileDownloadManagerUtils.returnFile("src/main/webapp/others/unknown.jpg", resp.getOutputStream()); + } +} Property changes on: trunk/src/main/java/cc/kune/core/server/manager/file/UserLogoDownloadManager.java ___________________________________________________________________ Name: svn:mime-type + text/plain Modified: trunk/src/main/java/cc/kune/wave/KuneWave.gwt.xml =================================================================== --- trunk/src/main/java/cc/kune/wave/KuneWave.gwt.xml 2011-06-26 10:50:56 UTC (rev 1423) +++ trunk/src/main/java/cc/kune/wave/KuneWave.gwt.xml 2011-06-26 22:30:12 UTC (rev 1424) @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <module> <inherits name='org.waveprotocol.box.webclient.WebClient' /> + <inherits name="cc.kune.core.KuneCore" /> <!-- Stack emulation is too slow to use in production. --> <set-property name="compiler.emulatedStack" value="false" /> Added: trunk/src/main/java/cc/kune/wave/client/KuneWaveProfileManager.java =================================================================== --- trunk/src/main/java/cc/kune/wave/client/KuneWaveProfileManager.java (rev 0) +++ trunk/src/main/java/cc/kune/wave/client/KuneWaveProfileManager.java 2011-06-26 22:30:12 UTC (rev 1424) @@ -0,0 +1,48 @@ +package cc.kune.wave.client; + +import org.waveprotocol.box.webclient.client.Session; +import org.waveprotocol.wave.client.account.ProfileManager; +import org.waveprotocol.wave.client.account.impl.AbstractProfileManager; +import org.waveprotocol.wave.client.account.impl.ProfileImpl; +import org.waveprotocol.wave.model.wave.ParticipantId; + +import cc.kune.core.client.services.FileDownloadUtils; + +import com.google.inject.Inject; + +/** + * The Class KuneWaveProfileManager is a workaround to show avatars in kune + * while the Wave part is more mature + * + */ +public class KuneWaveProfileManager extends AbstractProfileManager<ProfileImpl> implements + ProfileManager { + + private final FileDownloadUtils downloadUtils; + + @Inject + public KuneWaveProfileManager(final FileDownloadUtils downloadUtils) { + this.downloadUtils = downloadUtils; + } + + private void checkAvatar(final ProfileImpl profile) { + final String address = profile.getAddress(); + if (address.contains(Session.get().getDomain())) { + profile.update(profile.getFirstName(), profile.getFullName(), + downloadUtils.getUserAvatar(address.split("@")[0])); + } + } + + @Override + public ProfileImpl getProfile(final ParticipantId participantId) { + ProfileImpl profile = profiles.get(participantId.getAddress()); + + if (profile == null) { + profile = new ProfileImpl(this, participantId); + checkAvatar(profile); + profiles.put(participantId.getAddress(), profile); + } + return profile; + } + +} \ No newline at end of file Property changes on: trunk/src/main/java/cc/kune/wave/client/KuneWaveProfileManager.java ___________________________________________________________________ Name: svn:mime-type + text/plain Modified: trunk/src/main/java/cc/kune/wave/client/WaveClientManager.java =================================================================== --- trunk/src/main/java/cc/kune/wave/client/WaveClientManager.java 2011-06-26 10:50:56 UTC (rev 1423) +++ trunk/src/main/java/cc/kune/wave/client/WaveClientManager.java 2011-06-26 22:30:12 UTC (rev 1424) @@ -41,7 +41,8 @@ @Inject public WaveClientManager(final Session session, final StateManager stateManager, - final EventBus eventBus, final UserServiceAsync userService, final GSpaceArmor wsArmor) { + final EventBus eventBus, final UserServiceAsync userService, final GSpaceArmor wsArmor, + final KuneWaveProfileManager profiles) { session.onUserSignIn(true, new UserSignInHandler() { @Override public void onUserSignIn(final UserSignInEvent event) { @@ -59,7 +60,7 @@ if (userSpace.getWidgetCount() > 0) { userSpace.remove(0); } - webClient = new WebClient(eventBus); + webClient = new WebClient(eventBus, profiles); userSpace.add(webClient); } else { webClient.login(); Modified: trunk/src/main/java/cc/kune/wave/client/WaveGinModule.java =================================================================== --- trunk/src/main/java/cc/kune/wave/client/WaveGinModule.java 2011-06-26 10:50:56 UTC (rev 1423) +++ trunk/src/main/java/cc/kune/wave/client/WaveGinModule.java 2011-06-26 22:30:12 UTC (rev 1424) @@ -19,19 +19,19 @@ */ package cc.kune.wave.client; -import com.google.inject.Singleton; -import com.gwtplatform.mvp.client.gin.AbstractPresenterModule; +import cc.kune.common.client.ExtendedGinModule; -public class WaveGinModule extends AbstractPresenterModule { - /* - * (non-Javadoc) - * - * @see com.google.gwt.inject.client.AbstractGinModule#configure() - */ - @Override - protected void configure() { - bind(WaveClientManager.class).in(Singleton.class); - bind(WaveStatusIndicator.class).in(Singleton.class); - bind(WaveParts.class).asEagerSingleton(); - } +public class WaveGinModule extends ExtendedGinModule { + /* + * (non-Javadoc) + * + * @see com.google.gwt.inject.client.AbstractGinModule#configure() + */ + @Override + protected void configure() { + s(WaveClientManager.class); + s(WaveStatusIndicator.class); + eagle(WaveParts.class); + s(KuneWaveProfileManager.class); + } } Modified: trunk/src/main/java/cc/kune/wave/client/WebClient.java =================================================================== --- trunk/src/main/java/cc/kune/wave/client/WebClient.java 2011-06-26 10:50:56 UTC (rev 1423) +++ trunk/src/main/java/cc/kune/wave/client/WebClient.java 2011-06-26 22:30:12 UTC (rev 1424) @@ -198,7 +198,7 @@ // TODO (Yuri Z.) Change the implementation to RemoteProfileManagerImpl when // it will be ready. - private final ProfileManager profiles = new ProfileManagerImpl(); + private final ProfileManager profiles; @UiField SplitLayoutPanel splitPanel; @@ -216,7 +216,7 @@ private final Element loading = new LoadingIndicator().getElement(); @UiField(provided = true) - final SearchPanelWidget searchPanel = new SearchPanelWidget(new SearchPanelRenderer(profiles)); + final SearchPanelWidget searchPanel; @UiField DebugMessagePanel logPanel; @@ -241,9 +241,11 @@ * This is the entry point method. */ @Inject - public WebClient(final EventBus eventBus) { + public WebClient(final EventBus eventBus, KuneWaveProfileManager profiles) { this.eventBus = eventBus; + this.profiles = profiles; + searchPanel = new SearchPanelWidget(new SearchPanelRenderer(profiles)); ErrorHandler.install(); ClientEvents.get().addWaveCreationEventHandler( Added: trunk/src/main/webapp/others/unknown.jpg =================================================================== (Binary files differ) Property changes on: trunk/src/main/webapp/others/unknown.jpg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream
participants (1)
-
Vicente J. Ruiz Jurado