1 10 11 package freeforums.jspbeans; 12 13 import javax.naming.*; 14 import java.util.Hashtable ; 15 import javax.rmi.PortableRemoteObject ; 16 import java.util.Properties ; 17 import java.io.FileInputStream ; 18 import java.util.Properties ; 19 20 import freeforums.user.UserHome; 21 import freeforums.user.User; 22 import freeforums.user.UserManagerHome; 23 import freeforums.user.UserManager; 24 25 import java.util.List ; 26 27 import org.jdom.*; 28 29 public class UserController extends Object { 30 31 34 35 public void UserController() { 36 37 39 } 40 41 public boolean isSuperUser(Document UserDocument) { 42 43 Element userListElement = UserDocument.getRootElement(); 44 List userElementList = userListElement.getChildren(); 45 Element [] userElements = (Element[])userElementList.toArray(new Element[0]); 46 47 String SuperUser = userElements[0].getChild("SuperUser").getText(); 48 49 if(SuperUser.equals("Yes")) return true; return false; 52 } 53 54 public Document authenticateSession(Document userDocument) { 55 56 63 64 Element userListElement = userDocument.getRootElement(); 65 List userElementList = userListElement.getChildren(); 66 Element [] userElements = (Element[])userElementList.toArray(new Element[0]); 67 68 String userName = userElements[0].getChild("UserName").getText(); 69 String password = userElements[0].getChild("Password").getText(); 70 71 Element responseElement = new Element("Response"); 72 73 if(userName.equals("") || password.equals("")) responseElement.addContent("Not Verified"); 74 else responseElement.addContent("Verified"); 75 76 return (new Document(responseElement)); 77 78 } 79 80 public Document getUserList() { 81 82 try { 83 UserManagerHome home = (UserManagerHome) new InitialContext().lookup("UserManagerBean"); 85 UserManager manager = home.create(); 87 return manager.findAll(); 88 } 89 catch(Exception e) { 90 return null; 92 } 93 94 } 95 96 public Document addUser(Document xmlUserList) { 97 98 try { 99 UserManagerHome home = (UserManagerHome) new InitialContext().lookup("UserManagerBean"); 101 UserManager manager = home.create(); 103 return manager.addUser(xmlUserList); 104 } 105 catch(Exception e) { 106 return (new Document(new Element("Response").addContent("Failed"))); 108 } 109 110 } 111 112 public Document loginUser(Document loginDocument) { 113 114 try { 115 UserManagerHome home = (UserManagerHome) new InitialContext().lookup("UserManagerBean"); 117 UserManager manager = home.create(); 119 return manager.loginUser(loginDocument); 120 } 121 catch(Exception e) { 122 Element responseElement = new Element("Response"); 124 responseElement.addContent("Failed"); 125 return (new Document(responseElement)); 126 } 127 128 } 129 130 public Document getUserDetails(Document loginDocument) { 131 132 Element UserListElement = loginDocument.getRootElement(); 133 List UserElementList = UserListElement.getChildren(); 134 Element [] UserElements = (Element[])UserElementList.toArray(new Element[0]); 135 136 String UserName = UserElements[0].getChild("UserName").getText(); 137 138 try { 139 UserManagerHome home = (UserManagerHome) new InitialContext().lookup("UserManagerBean"); 141 UserManager manager = home.create(); 143 return manager.getUser(new Document(new Element("UserName").addContent(UserName))); 144 } 145 catch(Exception e) { 146 Element responseElement = new Element("Response"); 148 responseElement.addContent("Failed"); 149 return (new Document(responseElement)); 150 } 151 } 152 153 155 public Document modifyUserDetails(Document UserDocument) { 156 157 try { 158 UserManagerHome home = (UserManagerHome) new InitialContext().lookup("UserManagerBean"); 160 UserManager manager = home.create(); 162 return manager.modifyUser(UserDocument); 163 } 164 catch(Exception e) { 165 Element responseElement = new Element("Response"); 167 responseElement.addContent("Failed"); 168 return (new Document(responseElement)); 169 } 170 171 } 172 173 175 public Document addUserToForum(Document UserDocument) { 176 177 try { 178 UserManagerHome home = (UserManagerHome) new InitialContext().lookup("UserManagerBean"); 180 UserManager manager = home.create(); 182 return manager.addUserToForum(UserDocument); 183 } 184 catch(Exception e) { 185 Element responseElement = new Element("Response"); 187 responseElement.addContent("Failed"); 188 return (new Document(responseElement)); 189 } 190 191 } 192 193 } 195 | Popular Tags |