Author: andrei_exadel
Date: 2009-03-05 09:34:46 -0500 (Thu, 05 Mar 2009)
New Revision: 12841
Added:
trunk/test-applications/realworld2/web/src/main/webapp/img/defaultavatar.jpg
Removed:
trunk/test-applications/realworld2/web/src/main/webapp/img/avatar.jpg
Modified:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/fileupload/ImageLoader.java
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/user/UserPrefsBean.java
trunk/test-applications/realworld2/web/src/main/resources/messages_en.properties
trunk/test-applications/realworld2/web/src/main/resources/messages_ru.properties
trunk/test-applications/realworld2/web/src/main/webapp/includes/register/regInfo.xhtml
trunk/test-applications/realworld2/web/src/main/webapp/includes/userPrefs/loginPrefsTab.xhtml
trunk/test-applications/realworld2/web/src/main/webapp/includes/userPrefs/userPrefs.xhtml
trunk/test-applications/realworld2/web/src/main/webapp/index.xhtml
trunk/test-applications/realworld2/web/src/main/webapp/layout/template3.xhtml
trunk/test-applications/realworld2/web/src/main/webapp/register.xhtml
Log:
Userprefs, login screen
Modified:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/fileupload/ImageLoader.java
===================================================================
---
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/fileupload/ImageLoader.java 2009-03-05
14:34:14 UTC (rev 12840)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/fileupload/ImageLoader.java 2009-03-05
14:34:46 UTC (rev 12841)
@@ -22,6 +22,7 @@
import java.awt.image.BufferedImage;
import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -39,6 +40,9 @@
import org.jboss.seam.core.Events;
import org.richfaces.realworld.service.Constants;
+import sun.awt.image.ByteInterleavedRaster;
+import sun.reflect.generics.tree.ByteSignature;
+
@Name("imageLoader")
@Scope(ScopeType.CONVERSATION)
public class ImageLoader implements Serializable{
@@ -67,7 +71,7 @@
}
stream.write(bytes);
}
- //stream.write(fileWrapper.getFiles().get(index).getData());
+ // stream.write(fileWrapper.getFiles().get(index).getData());
}
public synchronized void paintSearchImage(OutputStream stream, Object object)
@@ -121,4 +125,27 @@
}
}
}
+
+ public synchronized void paintImageFromFile(OutputStream out, Object data) throws
IOException{
+ if (null == data || !(data instanceof File)) {
+ return;
+ }
+ File file = (File) data;
+
+ FileInputStream paintData = new FileInputStream(file);
+ if (null == paintData) {
+ Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, new
Exception(FILE_PROCESSING_ERROR));
+ return;
+ }
+ try {
+ BufferedImage images = ImageIO.read(paintData);
+ ImageIO.write(images, Constants.JPEG, out);
+ } catch (Exception e) {
+ Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, new
Exception(FILE_PROCESSING_ERROR));
+ return;
+ } finally {
+ paintData.close();
+ }
+
+ }
}
Modified:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/user/UserPrefsBean.java
===================================================================
---
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/user/UserPrefsBean.java 2009-03-05
14:34:14 UTC (rev 12840)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/user/UserPrefsBean.java 2009-03-05
14:34:46 UTC (rev 12841)
@@ -3,6 +3,12 @@
*/
package org.richfaces.realworld.user;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;
@@ -10,10 +16,16 @@
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
+import org.richfaces.event.UploadEvent;
+import org.richfaces.model.UploadItem;
import org.richfaces.realworld.domain.Sex;
+import org.richfaces.realworld.domain.User;
import org.richfaces.realworld.navigation.NavigationEnum;
+import org.richfaces.realworld.service.Constants;
+import org.richfaces.realworld.service.IUserAction;
import org.richfaces.realworld.util.ConversationState;
+
/**
* @author Andrey Markavtsov
*
@@ -22,8 +34,27 @@
@Scope(ScopeType.CONVERSATION)
public class UserPrefsBean {
- @In(value="conversationState")
+ @In(value="conversationState", create=true)
ConversationState conversationState;
+
+ @In(create=true)
+ IUserAction userAction;
+
+ @In
+ User user;
+
+ String uploadRoot;
+
+ Boolean avatarModalOpened = false;
+
+ File avatarData = null;
+
+ public UserPrefsBean() {
+ FacesContext fc = FacesContext.getCurrentInstance();
+ if(fc!=null){
+ uploadRoot = fc.getExternalContext().getInitParameter(Constants.UPLOAD_ROOT);
+ }
+ }
static final SelectItem [] sexs = new SelectItem []
{
@@ -34,10 +65,69 @@
public void clickUserListener(ActionEvent event) {
conversationState.setMainArea(NavigationEnum.USER_PREFS);
- conversationState.setSelectedUser(conversationState.getUser());
+ conversationState.setSelectedUser(user);
}
+ public void uploadAvatar(UploadEvent event) {
+ UploadItem item = event.getUploadItem();
+ avatarData = item.getFile();
+ }
+
+ public void saveUser(ActionEvent event)throws IOException {
+ User user = conversationState.getSelectedUser();
+ if (avatarData != null) {
+ String fileName = uploadRoot +
+ (uploadRoot.endsWith(Constants.SLASH) ? "" : Constants.SLASH) +
+ user.getLogin() +
+ "/avatar.jpg";
+ FileOutputStream outputStream = new FileOutputStream(new File(fileName));
+
+ byte [] bytes = new byte[4096];
+ FileInputStream inputStream = new FileInputStream(avatarData);
+ int read = 0;
+ while ((read = inputStream.read(bytes)) != -1) {
+ outputStream.write(bytes, 0, read);
+ }
+ outputStream.close();
+ inputStream.close();
+ avatarData.delete();
+ avatarData = null;
+ user.setHasAvatar(true);
+
+ }
+ userAction.updateUser(user);
+ }
+
+ public void registerUser(ActionEvent event) {
+ if (user != null) {
+ userAction.register(user);
+ }
+ }
+
+ public void cancel(ActionEvent event) {
+ avatarData = null;
+
+ }
+
public SelectItem [] getSexs () {
return sexs;
}
+
+ public Boolean getAvatarModalOpened() {
+ return avatarModalOpened;
+ }
+
+ public void setAvatarModalOpened(Boolean avatarModalOpened) {
+ this.avatarModalOpened = avatarModalOpened;
+ }
+
+ public File getAvatarData() {
+ return avatarData;
+ }
+
+ public void setAvatarData(File avatarData) {
+ this.avatarData = avatarData;
+ }
+
+
}
Modified:
trunk/test-applications/realworld2/web/src/main/resources/messages_en.properties
===================================================================
---
trunk/test-applications/realworld2/web/src/main/resources/messages_en.properties 2009-03-05
14:34:14 UTC (rev 12840)
+++
trunk/test-applications/realworld2/web/src/main/resources/messages_en.properties 2009-03-05
14:34:46 UTC (rev 12841)
@@ -221,6 +221,10 @@
user.cancel=Cancel
user.exist=User with this login already exist;
user.confirm.error=Confirm Password not equals password
+user.sex=Sex
+user.dontshowmail=Do not show to others
+user.informaboutnews=Inform me about news in RealWorld Demo
+user.changeavatar=Change avatar
menu.welcome=Welcome, #{identity.username}!
menu.welcome.guest=Welcome, guest! If you want access to full version of application,
please register or login.
Modified:
trunk/test-applications/realworld2/web/src/main/resources/messages_ru.properties
===================================================================
---
trunk/test-applications/realworld2/web/src/main/resources/messages_ru.properties 2009-03-05
14:34:14 UTC (rev 12840)
+++
trunk/test-applications/realworld2/web/src/main/resources/messages_ru.properties 2009-03-05
14:34:46 UTC (rev 12841)
@@ -160,6 +160,10 @@
user.cancel=\u041E\u0442\u043C\u0435\u043D\u0430
user.exist=\u041F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u0435\u043B\u044C
\u0441 \u0442\u0430\u043A\u0438\u043C \u043B\u043E\u0433\u0438\u043D\u043E\u043C
\u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442;
user.confirm.error=\u041F\u0430\u0440\u043E\u043B\u0438
\u0434\u043E\u043B\u0436\u043D\u044B
\u0441\u043E\u0432\u043F\u0430\u0434\u0430\u0442\u044C
+user.sex=\u041F\u043E\u043B
+user.dontshowmail=\u041D\u0435
\u043F\u043E\u043A\u0430\u0437\u044B\u0432\u0430\u0442\u044C
\u0434\u0440\u0443\u0433\u0438\u043C
\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u0435\u043B\u044F\u043C
+user.informaboutnews=\u0418\u043D\u0444\u043E\u0440\u043C\u0438\u0440\u043E\u0432\u0430\u0442\u044C
\u043C\u0435\u043D\u044F \u043E \u043D\u043E\u0432\u043E\u0441\u0442\u044F\u0445
+user.changeavatar=\u0421\u043C\u0435\u043D\u0438\u0442\u044C
\u0430\u0432\u0430\u0442\u0430\u0440
menu.welcome=\u0414\u043E\u0431\u0440\u043E
\u043F\u043E\u0436\u0430\u043B\u043E\u0432\u0430\u0442\u044C, \#{identity.username}\!
menu.welcome.guest=\u0414\u043E\u0431\u0440\u043E
\u043F\u043E\u0436\u0430\u043B\u043E\u0432\u0430\u0442\u044C,
\u0433\u043E\u0441\u0442\u044C\! \u0415\u0441\u043B\u0438 \u0432\u044B
\u0445\u043E\u0442\u0438\u0442\u0435 \u0438\u043C\u0435\u0442\u044C
\u0434\u043E\u0441\u0442\u0443\u043F \u043A\u043E \u0432\u0441\u0435\u043C
\u0432\u043E\u0437\u043C\u043E\u0436\u043D\u043E\u0441\u0442\u044F\u043C
\u0441\u0438\u0441\u0442\u0435\u043C\u044B,
\u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0439\u0442\u0435\u0441\u044C
Deleted: trunk/test-applications/realworld2/web/src/main/webapp/img/avatar.jpg
===================================================================
(Binary files differ)
Added: trunk/test-applications/realworld2/web/src/main/webapp/img/defaultavatar.jpg
===================================================================
(Binary files differ)
Property changes on:
trunk/test-applications/realworld2/web/src/main/webapp/img/defaultavatar.jpg
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified:
trunk/test-applications/realworld2/web/src/main/webapp/includes/register/regInfo.xhtml
===================================================================
(Binary files differ)
Modified:
trunk/test-applications/realworld2/web/src/main/webapp/includes/userPrefs/loginPrefsTab.xhtml
===================================================================
(Binary files differ)
Modified:
trunk/test-applications/realworld2/web/src/main/webapp/includes/userPrefs/userPrefs.xhtml
===================================================================
(Binary files differ)
Modified: trunk/test-applications/realworld2/web/src/main/webapp/index.xhtml
===================================================================
(Binary files differ)
Modified: trunk/test-applications/realworld2/web/src/main/webapp/layout/template3.xhtml
===================================================================
(Binary files differ)
Modified: trunk/test-applications/realworld2/web/src/main/webapp/register.xhtml
===================================================================
(Binary files differ)