Commits

Anonymous committed 3975d51

image uploading is OK

Comments (0)

Files changed (30)

src/info/mrchen/gae/blog/Dao.java

 import java.util.List;
 
 import javax.jdo.annotations.Transactional;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
 
-import org.springframework.orm.jpa.JpaTemplate;
+import org.springframework.orm.jpa.support.JpaDaoSupport;
 import org.springframework.stereotype.Component;
 
 @Component
-public abstract class Dao<T> {
-	protected EntityManager entityManager;
-
-	JpaTemplate jpaTemplate;
+public abstract class Dao<T> extends JpaDaoSupport {
 
 	public Dao() {
-		this.entityManager = EMF.get().createEntityManager();
-		jpaTemplate = new JpaTemplate(entityManager);
-	}
-
-	public void setEntityManager(EntityManager entityManager) {
-		this.entityManager = entityManager;
-		jpaTemplate = new JpaTemplate(entityManager);
+		this.setEntityManager(EMF.getEntityManager());
 	}
 
 	protected Class<T> persistanceClass;
 
 	public void Delete(T object) {
-		jpaTemplate.remove(object);
+		getJpaTemplate().remove(object);
 	}
 
 	public void delete(Long id) {
-		Object obj = jpaTemplate.find(getPersistanceClass(), id);
+		Object obj = getJpaTemplate().find(getPersistanceClass(), id);
 		if (obj != null)
-			jpaTemplate.remove(obj);
+			getJpaTemplate().remove(obj);
 	}
 
-	public List getAll() {
-
-		return entityManager.createQuery(
-				"SELECT  FROM " + getPersistanceClass().getName())
-				.getResultList();
-
+	public List<T> getAll() {
+		return getByQueryString("SELECT  FROM " + getPersistanceClass().getName());
 	}
 
 	@Transactional
 	public T save(T object) {
-		object = entityManager.merge(object);
-		entityManager.persist(object);
+		object = getJpaTemplate().merge(object);
+		getJpaTemplate().persist(object);
 		return object;
 
 	}
 
 	public List getByQueryString(String queryString) {
-		return entityManager.createQuery(queryString).getResultList();
+		return getJpaTemplate().find(queryString);
 	}
 
 	public T get(Long id) {
-		return (T) jpaTemplate.find(getPersistanceClass(), id);
+		return (T) getJpaTemplate().find(getPersistanceClass(), id);
 	}
 
-	private Class getPersistanceClass() {
+	protected Class getPersistanceClass() {
 		if (persistanceClass == null)
-			persistanceClass = (Class) ((ParameterizedType) getClass()
-					.getGenericSuperclass()).getActualTypeArguments()[0];
+			persistanceClass = (Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
 
 		return persistanceClass;
 	}

src/info/mrchen/gae/blog/EMF.java

 package info.mrchen.gae.blog;
 
+import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.Persistence;
 
 public final class EMF {
-    private static final EntityManagerFactory emfInstance =
-        Persistence.createEntityManagerFactory("transactions-optional");
+	private static final EntityManagerFactory emfInstance = Persistence.createEntityManagerFactory("transactions-optional");
 
-    private EMF() {}
+	private static EntityManager em;
 
-    public static EntityManagerFactory get() {
-        return emfInstance;
-    }
+	private EMF() {
+	}
+
+	public static EntityManagerFactory get() {
+		return emfInstance;
+	}
+
+	public static EntityManager getEntityManager() {
+
+		if (em != null) {
+			return em;
+		} else {
+			em = get().createEntityManager();
+			return em;
+		}
+	}
 }

src/info/mrchen/gae/blog/controller/MediaObjectController.java

+package info.mrchen.gae.blog.controller;
+
+import info.mrchen.gae.blog.pojo.MediaObject;
+import info.mrchen.gae.blog.service.MediaObjectService;
+
+import java.io.IOException;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+@Controller
+public class MediaObjectController {
+	@Autowired
+	MediaObjectService mediaObjectService;
+
+	@RequestMapping("/MediaObject-Show-{mediaObjectID}.do")
+	public void show(@PathVariable Long mediaObjectID, HttpServletResponse response) {
+		try {
+			response.reset();
+			response.resetBuffer();
+			MediaObject mo = mediaObjectService.get(mediaObjectID);
+			response.getOutputStream().write(mo.getBits().getBytes());
+			response.flushBuffer();
+		} catch (IOException e) {
+		}
+	}
+}

src/info/mrchen/gae/blog/controller/UserProfileController.java

 package info.mrchen.gae.blog.controller;
 
-import info.mrchen.gae.blog.dao.UserInfoService;
+import info.mrchen.gae.blog.service.UserInfoService;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 
 import com.google.appengine.api.users.UserService;
 import com.google.appengine.api.users.UserServiceFactory;
 
 	@RequestMapping("/profile/index.do")
 	public void show(Model model) {
-		model.addAttribute("MyProfile", userInfoService.getMyProfile(userService.getCurrentUser()));
+		model.addAttribute("MY_USERINFO", userInfoService.getUserInfo(userService.getCurrentUser()));
+	}
+
+	@RequestMapping("/profile/update.do")
+	public String update(Model model, @RequestParam("username") String username, @RequestParam("password") String newPassword) {
+		userInfoService.changeUsername(userService.getCurrentUser(), username);
+		userInfoService.changePassword(userService.getCurrentUser(), newPassword);
+
+		return "redirect:index.do";
 	}
 }

src/info/mrchen/gae/blog/controller/admin/MediaFileController.java

+package info.mrchen.gae.blog.controller.admin;
+
+import info.mrchen.gae.blog.service.MediaFileService;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+@Controller
+public class MediaFileController {
+
+	@Autowired
+	private MediaFileService mediaFileService;
+
+	@RequestMapping("/admin" + "/Media/List.do")
+	public void list(Model model, Integer offset, Integer length) {
+		if (offset == null || offset < 0) {
+			offset = 0;
+		}
+		if (length == null || length < 1) {
+			length = 20;
+		}
+		model.addAttribute("LIST", mediaFileService.get(offset, length));
+	}
+
+	@RequestMapping(value = "/admin" + "/Media/Add.do", method = RequestMethod.GET)
+	public void add1(Model model) {
+	}
+
+	@RequestMapping(value = "/admin" + "/Media/Add.do", method = RequestMethod.POST)
+	public void add2(Model model) {
+	}
+}

src/info/mrchen/gae/blog/dao/ArticleDao.java

 public class ArticleDao extends Dao<Article> {
 
 	public void update(Article a) {
-		// TODO Auto-generated method stub
-		
+
 	}
 
 }

src/info/mrchen/gae/blog/dao/MediaFileDao.java

+package info.mrchen.gae.blog.dao;
+
+import info.mrchen.gae.blog.Dao;
+import info.mrchen.gae.blog.pojo.MediaFile;
+
+import org.springframework.stereotype.Component;
+
+@Component
+public class MediaFileDao extends Dao<MediaFile> {
+
+}

src/info/mrchen/gae/blog/dao/MediaObjectDao.java

+package info.mrchen.gae.blog.dao;
+
+import info.mrchen.gae.blog.Dao;
+import info.mrchen.gae.blog.pojo.MediaObject;
+
+import org.springframework.stereotype.Component;
+
+@Component
+public class MediaObjectDao extends Dao<MediaObject> {
+
+}

src/info/mrchen/gae/blog/dao/UserAndUserInfoDao.java

+package info.mrchen.gae.blog.dao;
+
+import info.mrchen.gae.blog.Dao;
+import info.mrchen.gae.blog.pojo.UserAndUserInfo;
+
+import java.util.List;
+
+import org.springframework.stereotype.Component;
+
+import com.google.appengine.api.users.User;
+
+@Component
+public class UserAndUserInfoDao extends Dao<UserAndUserInfo> {
+
+	public Long getUserInfo(User user) {
+		String queryString = "select from " + getPersistanceClass().getName() + " where gaeUser=?1";
+		List<UserAndUserInfo> l = getJpaTemplate().find(queryString, user);
+		return (l.isEmpty() ? null : l.get(0).getUserInfo());
+	}
+}

src/info/mrchen/gae/blog/dao/UserInfoDao.java

 
 import java.util.List;
 
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import com.google.appengine.api.users.User;
 
 @Component
 public class UserInfoDao extends Dao<UserInfo> {
+
+	@Autowired
+	UserAndUserInfoDao userAndUserInfoDao;
+
 	public boolean checkPassword(String username, String password) {
 		if (password == null || username == null || password.length() < 1 || username.length() < 1) {
 			return false;
 		}
-		String queryString = "from " + UserInfo.class.getName() + " where username='" + username + "'";
+		String queryString = "select from " + UserInfo.class.getName() + " where username='" + username + "'";
 		List<UserInfo> l = this.getByQueryString(queryString);
 		return l.size() > 0 && password.equals(l.get(0).getPassword());
 	}
 
-	public UserInfo get(User user) {
-		entityManager.createNamedQuery("from " + UserInfo.class.getName() + "");
+	public Long get(final User user) {
+		return userAndUserInfoDao.getUserInfo(user);
+	}
 
-		return null;
+	public void changeUsername(UserInfo userInfo, String newUsername) {
+		if (userInfo == null && userInfo.getId() == null) {
+			return;
+		}
+		userInfo.setUsername(newUsername);
+		this.save(userInfo);
+	}
+
+	public void changePassword(UserInfo userInfo, String newPassword) {
+		if (userInfo == null && userInfo.getId() == null) {
+			return;
+		}
+		userInfo.setPassword(newPassword);
+		this.save(userInfo);
 	}
 }

src/info/mrchen/gae/blog/dao/UserInfoService.java

-package info.mrchen.gae.blog.dao;
-
-import java.util.ArrayList;
-
-import info.mrchen.gae.blog.pojo.UserInfo;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-import com.google.appengine.api.users.User;
-
-@Component
-public class UserInfoService {
-
-	@Autowired
-	UserInfoDao UserInfoDao;
-
-	public boolean checkPassword(String username, String password) {
-		if (username == null || username.length() < 1) {
-			return false;
-		}
-		return UserInfoDao.checkPassword(username, password);
-
-	}
-
-	public UserInfo getMyProfile(User user) {
-		UserInfo existUserInfo = UserInfoDao.get(user);
-		if (existUserInfo == null) {
-			UserInfo newUserInfo = new UserInfo();
-			if (newUserInfo.getUser() == null) {
-				newUserInfo.setUser(new ArrayList<User>());
-			}
-			newUserInfo.getUser().add(user);
-			UserInfoDao.save(newUserInfo);
-			return newUserInfo;
-		} else {
-			return existUserInfo;
-		}
-	}
-}

src/info/mrchen/gae/blog/dao/jdo/PMF.java

+package info.mrchen.gae.blog.dao.jdo;
+
+import javax.jdo.JDOHelper;
+import javax.jdo.PersistenceManagerFactory;
+
+public final class PMF {
+	private static final PersistenceManagerFactory pmfInstance = JDOHelper.getPersistenceManagerFactory("transactions-optional");
+
+	private PMF() {
+	}
+
+	public static PersistenceManagerFactory get() {
+		return pmfInstance;
+	}
+}

src/info/mrchen/gae/blog/pojo/Article.java

 package info.mrchen.gae.blog.pojo;
 
+import java.io.Serializable;
 import java.util.Date;
 
 import javax.jdo.annotations.IdGeneratorStrategy;
 import com.google.appengine.api.datastore.Text;
 
 @PersistenceCapable(identityType = IdentityType.APPLICATION)
-public class Article {
+public class Article implements Serializable {
 	@PrimaryKey
 	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
 	private Long id;
 
-	@Persistent
 	private String title;
 
-	@Persistent
 	private Date date;
 
 	public Long getId() {
 		this.content = content;
 	}
 
-	@Persistent
 	private Text content;
 
 }

src/info/mrchen/gae/blog/pojo/Category.java

 package info.mrchen.gae.blog.pojo;
 
+import java.io.Serializable;
+
 import javax.jdo.annotations.IdGeneratorStrategy;
 import javax.jdo.annotations.IdentityType;
 import javax.jdo.annotations.PersistenceCapable;
 import javax.jdo.annotations.PrimaryKey;
 
 @PersistenceCapable(identityType = IdentityType.APPLICATION)
-public class Category {
+public class Category implements Serializable {
 	@PrimaryKey
 	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
-	Long categoryid;
-	
+	private Long categoryid;
+
 	@Persistent
-	String description;
-	
+	private String description;
+
 	@Persistent
-	String title;
+	private String title;
 
 	public Long getCategoryid() {
 		return categoryid;
 		this.categoryid = categoryid;
 	}
 
-
 	public String getDescription() {
 		return description;
 	}

src/info/mrchen/gae/blog/pojo/Comment.java

 package info.mrchen.gae.blog.pojo;
 
 import javax.jdo.annotations.IdGeneratorStrategy;
-import javax.jdo.annotations.IdentityType;
 import javax.jdo.annotations.PersistenceCapable;
 import javax.jdo.annotations.Persistent;
 import javax.jdo.annotations.PrimaryKey;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
 
-@PersistenceCapable(identityType = IdentityType.APPLICATION)
-
+@PersistenceCapable
 public class Comment {
 
 	@PrimaryKey
 	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
 	private Long id;
-	
+
 }

src/info/mrchen/gae/blog/pojo/MediaFile.java

+package info.mrchen.gae.blog.pojo;
+
+import java.util.Date;
+
+import javax.jdo.annotations.IdGeneratorStrategy;
+import javax.jdo.annotations.PersistenceCapable;
+import javax.jdo.annotations.Persistent;
+import javax.jdo.annotations.PrimaryKey;
+import javax.persistence.Lob;
+
+@PersistenceCapable
+public class MediaFile {
+	@PrimaryKey
+	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
+	private String id;
+
+	@Persistent
+	private UserInfo uploader;
+	@Persistent
+	private String filename;
+	@Persistent
+	private Date datetime;
+
+	@Persistent
+	private String mimeType;
+
+	@Lob
+	@Persistent
+	private byte[] content;
+
+	public String getId() {
+		return id;
+	}
+
+	public void setId(String id) {
+		this.id = id;
+	}
+
+	public UserInfo getUploader() {
+		return uploader;
+	}
+
+	public void setUploader(UserInfo uploader) {
+		this.uploader = uploader;
+	}
+
+	public String getFilename() {
+		return filename;
+	}
+
+	public void setFilename(String filename) {
+		this.filename = filename;
+	}
+
+	public Date getDatetime() {
+		return datetime;
+	}
+
+	public void setDatetime(Date datetime) {
+		this.datetime = datetime;
+	}
+
+	public String getMimeType() {
+		return mimeType;
+	}
+
+	public void setMimeType(String mimeType) {
+		this.mimeType = mimeType;
+	}
+
+	public byte[] getContent() {
+		return content;
+	}
+
+	public void setContent(byte[] content) {
+		this.content = content;
+	}
+
+}

src/info/mrchen/gae/blog/pojo/MediaObject.java

+package info.mrchen.gae.blog.pojo;
+
+import java.io.Serializable;
+
+import javax.jdo.annotations.IdGeneratorStrategy;
+import javax.jdo.annotations.IdentityType;
+import javax.jdo.annotations.PersistenceCapable;
+import javax.jdo.annotations.Persistent;
+import javax.jdo.annotations.PrimaryKey;
+
+@PersistenceCapable(identityType = IdentityType.APPLICATION)
+public class MediaObject implements Serializable {
+	@PrimaryKey
+	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
+	private Long id;
+
+	private String name;
+	private String type;
+	private com.google.appengine.api.datastore.Blob bits;
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public String getType() {
+		return type;
+	}
+
+	public void setType(String type) {
+		this.type = type;
+	}
+
+	public com.google.appengine.api.datastore.Blob getBits() {
+		return bits;
+	}
+
+	public void setBits(com.google.appengine.api.datastore.Blob bits) {
+		this.bits = bits;
+	}
+
+}

src/info/mrchen/gae/blog/pojo/SysConf.java

 package info.mrchen.gae.blog.pojo;
 
+import java.io.Serializable;
+
 import javax.jdo.annotations.IdGeneratorStrategy;
 import javax.jdo.annotations.IdentityType;
 import javax.jdo.annotations.PersistenceCapable;
 import javax.jdo.annotations.PrimaryKey;
 
 @PersistenceCapable(identityType = IdentityType.APPLICATION)
-public class SysConf {
+public class SysConf implements Serializable {
 	@PrimaryKey
 	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
 	private Long id;

src/info/mrchen/gae/blog/pojo/UserAndUserInfo.java

+package info.mrchen.gae.blog.pojo;
+
+import java.io.Serializable;
+
+import javax.jdo.annotations.IdGeneratorStrategy;
+import javax.jdo.annotations.IdentityType;
+import javax.jdo.annotations.PersistenceCapable;
+import javax.jdo.annotations.Persistent;
+import javax.jdo.annotations.PrimaryKey;
+
+import com.google.appengine.api.datastore.Key;
+import com.google.appengine.api.users.User;
+
+@PersistenceCapable(identityType = IdentityType.APPLICATION)
+public class UserAndUserInfo implements Serializable {
+
+	@PrimaryKey
+	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
+	private Key id;
+
+	private User gaeUser;
+
+	private Long userInfo;
+
+	public Key getId() {
+		return id;
+	}
+
+	public void setId(Key id) {
+		this.id = id;
+	}
+
+	public User getGaeUser() {
+		return gaeUser;
+	}
+
+	public void setGaeUser(User gaeUser) {
+		this.gaeUser = gaeUser;
+	}
+
+	public Long getUserInfo() {
+		return userInfo;
+	}
+
+	public void setUserInfo(Long userInfo) {
+		this.userInfo = userInfo;
+	}
+}

src/info/mrchen/gae/blog/pojo/UserInfo.java

 package info.mrchen.gae.blog.pojo;
 
-import java.util.List;
-
 import javax.jdo.annotations.IdGeneratorStrategy;
-import javax.jdo.annotations.IdentityType;
 import javax.jdo.annotations.PersistenceCapable;
 import javax.jdo.annotations.Persistent;
 import javax.jdo.annotations.PrimaryKey;
 
-import com.google.appengine.api.users.User;
+@PersistenceCapable
+public class UserInfo {
 
-@PersistenceCapable(identityType = IdentityType.APPLICATION)
-public class UserInfo {
+	// http://code.google.com/appengine/docs/java/datastore/dataclasses.html#Class_and_Field_Annotations
+
 	@PrimaryKey
 	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
 	private Long id;
 
 	@Persistent
-	private List<User> user;
+	private String username;
 
 	@Persistent
-	private String username;
-	@Persistent
 	private String password;
 
 	public Long getId() {
 	public void setPassword(String password) {
 		this.password = password;
 	}
-
-	public List<User> getUser() {
-		return user;
-	}
-
-	public void setUser(List<User> user) {
-		this.user = user;
-	}
 }

src/info/mrchen/gae/blog/service/MediaFileService.java

+package info.mrchen.gae.blog.service;
+
+import java.util.List;
+
+import info.mrchen.gae.blog.dao.MediaFileDao;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class MediaFileService {
+	@Autowired
+	private MediaFileDao mediaFileDao;
+
+	public List get(Integer offset, Integer length) {
+		return mediaFileDao.getAll();
+	}
+
+}

src/info/mrchen/gae/blog/service/MediaObjectService.java

+package info.mrchen.gae.blog.service;
+
+import info.mrchen.gae.blog.dao.MediaObjectDao;
+import info.mrchen.gae.blog.pojo.MediaObject;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import com.google.appengine.api.datastore.Blob;
+
+@Component
+public class MediaObjectService {
+
+	@Autowired
+	MediaObjectDao mediaObjectDao;
+
+	public Long save(String name, String type, byte[] bits) {
+
+		MediaObject mediaObject = new MediaObject();
+
+		mediaObject.setBits(new Blob(bits));
+		mediaObject.setName(name);
+		mediaObject.setType(type);
+		mediaObjectDao.save(mediaObject);
+		return mediaObject.getId();
+	}
+
+	public MediaObject get(Long mediaObjectID) {
+
+		return mediaObjectDao.get(mediaObjectID);
+	}
+
+}

src/info/mrchen/gae/blog/service/UserAndUserInfoService.java

+package info.mrchen.gae.blog.service;
+
+import info.mrchen.gae.blog.dao.UserAndUserInfoDao;
+import info.mrchen.gae.blog.pojo.UserInfo;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import com.google.appengine.api.users.User;
+
+@Component
+public class UserAndUserInfoService {
+	@Autowired
+	UserAndUserInfoDao userAndUserInfoDao;
+
+}

src/info/mrchen/gae/blog/service/UserInfoService.java

+package info.mrchen.gae.blog.service;
+
+import info.mrchen.gae.blog.dao.UserAndUserInfoDao;
+import info.mrchen.gae.blog.dao.UserInfoDao;
+import info.mrchen.gae.blog.pojo.UserAndUserInfo;
+import info.mrchen.gae.blog.pojo.UserInfo;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import com.google.appengine.api.users.User;
+import java.util.logging.Logger;
+import java.util.logging.Logger;
+
+@Component
+public class UserInfoService {
+	private static final Logger log = Logger.getLogger(UserInfoService.class.getName());
+
+	@Autowired
+	UserInfoDao userInfoDao;
+
+	@Autowired
+	UserAndUserInfoDao userAndUserInfoDao;
+
+	@Autowired
+	private UserAndUserInfoDao userAndUserInfoService;
+
+	public boolean checkPassword(String username, String password) {
+		if (username == null || username.length() < 1) {
+			return false;
+		}
+		return userInfoDao.checkPassword(username, password);
+
+	}
+
+	public UserInfo getUserInfo(User gaeUser) {
+
+		Long existUserInfo = userAndUserInfoService.getUserInfo(gaeUser);
+
+		if (existUserInfo == null) {
+			UserInfo userInfo = new UserInfo();
+			userInfo.setUsername(gaeUser.getUserId());
+			userInfo.setPassword("" + Math.random());
+			UserInfo savedUserInfo = userInfoDao.save(userInfo);
+
+			UserAndUserInfo userAndUserInfo = new UserAndUserInfo();
+			userAndUserInfo.setGaeUser(gaeUser);
+			userAndUserInfo.setUserInfo(userInfo.getId());
+			userAndUserInfoDao.save(userAndUserInfo);
+
+			log.info(userInfo.getId().toString());
+
+			return savedUserInfo;
+
+		} else {
+			return userInfoDao.get(existUserInfo);
+		}
+	}
+
+	public void changeUsername(User currentUser, String newUsername) {
+		userInfoDao.changeUsername(getUserInfo(currentUser), newUsername);
+	}
+
+	public void changePassword(User currentUser, String newPassword) {
+		userInfoDao.changePassword(getUserInfo(currentUser), newPassword);
+	}
+}

src/info/mrchen/gae/blog/xmlrpc/MetaweblogApiField.java

 	final String POST_DATECREATED = "dateCreated";
 	final String POST_POSTID = "postid";
 
+	final String MEDIAOBJECT_URL = "url";
+	final Object MEDIAOBJECT_NAME = "name";
+	final Object MEDIAOBJECT_TYPE = "type";
+	final Object MEDIAOBJECT_BITS = "bits";
+
 }

src/info/mrchen/gae/blog/xmlrpc/handder/MetaWeblogHandler.java

 package info.mrchen.gae.blog.xmlrpc.handder;
 
-import info.mrchen.gae.blog.dao.UserInfoDao;
-import info.mrchen.gae.blog.dao.UserInfoService;
 import info.mrchen.gae.blog.pojo.Category;
 import info.mrchen.gae.blog.service.ArticleService;
 import info.mrchen.gae.blog.service.CategoryService;
+import info.mrchen.gae.blog.service.MediaObjectService;
 import info.mrchen.gae.blog.service.SysConfService;
+import info.mrchen.gae.blog.service.UserInfoService;
 import info.mrchen.gae.blog.xmlrpc.MetaweblogApiField;
 
-import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 	@Autowired
 	UserInfoService userInfoService;
 
+	@Autowired
+	MediaObjectService mediaObjectService;
+
 	public Map<String, Object>[] getUsersBlogs(String appkey, String username, String password) {
 		Map<String, Object> blog = new HashMap<String, Object>();
 		if (userInfoService.checkPassword(username, password)) {
 
 	public Map<String, Object>[] getCategories(String blogid, String username, String password) {
 		List<Category> categoryList = categoryService.get(0, Integer.MAX_VALUE);
-		List<Map<String, Object>> map = new ArrayList<Map<String, Object>>();
-		for (Category c : categoryList) {
-			Map<String, Object> aC = new HashMap<String, Object>();
-			aC.put(CATEGORY_ID, c.getCategoryid());
-			aC.put(CATEGORY_TITLE, c.getTitle());
-			aC.put(CATEGORY_DESCRIPTION, c.getDescription());
-			map.add(aC);
+		Map<String, Object>[] maps = new HashMap[categoryList.size()];
+		for (int i = 0; i < categoryList.size(); i++) {
+			Category c = categoryList.get(i);
+			Map<String, Object> _map = new HashMap<String, Object>();
+			_map.put(CATEGORY_ID, c.getCategoryid());
+			_map.put(CATEGORY_TITLE, c.getTitle());
+			_map.put(CATEGORY_DESCRIPTION, c.getDescription());
+			maps[i] = _map;
 		}
-		return (Map<String, Object>[]) map.toArray();
+		return maps;
 	}
 
 	public String newPost(String blogid, String username, String password, HashMap<String, Object> content, boolean publish) {
 	public HashMap<String, Object> getPost(String blogid, String username, String password) {
 		return null;
 	}
+
+	public HashMap<String, Object> newMediaObject(String blogid, String username, String password, HashMap<String, Object> content) {
+		HashMap<String, Object> hashMap = new HashMap<String, Object>();
+		// name, type and bits
+
+		String name = (String) content.get(MEDIAOBJECT_NAME);
+		String type = (String) content.get(MEDIAOBJECT_TYPE);
+		byte[] bits = (byte[]) content.get(MEDIAOBJECT_BITS);
+
+		Long mediaObjectID = mediaObjectService.save(name, type, bits);
+		String url = "/MediaObject-Show-" + mediaObjectID + ".do";
+		hashMap.put(MEDIAOBJECT_URL, url);
+		return hashMap;
+	}
 }
Add a comment to this file

war/WEB-INF/lib/org.springframework.jdbc-3.0.3.RELEASE.jar

Binary file added.

war/WEB-INF/views/profile/index.jsp

 
 <body>
 <jsp:include page="/Navi.jsp" />
-${MyProfile.user}
+<form action="update.do" method="post">
+<table>
+	<tr>
+		<td>用户名</td>
+		<td><input type="text" name="username"
+			value="${MY_USERINFO.username}"></td>
+	</tr>
+	<tr>
+		<td>密码</td>
+		<td><input type="text" name="password"
+			value="${MY_USERINFO.password}"></td>
+	</tr>
+	<tr>
+		<td>&nbsp;</td>
+		<td><input type="submit" value="保存"></td>
+	</tr>
+</table>
+</form>
+
+
 <pre>
 <%
 	UserService userService = UserServiceFactory.getUserService();

war/admin/AdminNavi.jsp

 	<tr>
 		<td><a href="/">Top</a>&nbsp;<a href="/admin">Admin Top</a></td>
 		<td><a href="/admin/Article-List.do">文章管理</a></td>
+		<td><a href="/admin/Media/List.do">文件管理</a></td>
 		<td><a href="/admin/SysConf.do">系统设置</a></td>
 		<td><a href="/admin/Feed.do">RSS/Atom</a></td>
 		<td><a href="/admin/Rpc.do">Rpc</a></td>
 <html>
 <head>
 <meta http-equiv="content-type" content="text/html; charset=UTF-8">
-<META http-equiv="refresh" CONTENT="0;/Article-List.do">
 <link rel="icon" href="/Images/favicon.ico">
 <title>mrchen-gae-blog</title>
 </head>
 
-<body>
+<body onload="window.location='Article-List.do'">
 <%--
 <h1>Hello App Engine!</h1>
 <table>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.