Hello,
I am currently working on a pet servlet project (a chatroom)written in JAVA. One aspect of this project allows users to store their "preferences" for the chatroom, on the server.
When a user wishes to use the chatroom they log-in through an HTML based form containing form fields for both their chatroom handle and their password.
At this point, the servlet uses their handle to access their preferences.
Likewise, if someone is new, the servlet prompts them to create a preferences file for themselves before using the chat.
Okay, that's all pretty straightforward, but the part that gets me is the implementation of storing/accessing these preferences.
Unfortunately, I cannot hook this servlet up to any database through JDBC, so that rules that possibility out.
So, my current planned implementation involves serialized preference objects. I originally planed to base the serialized object files on the person's handle. So you would would have a file "john_doe.dat" storing John Doe's preferences.
This was all well and good, but I realized it quickly broke down in implementation. Especially if someone decides to use the handle "//Barney_The_Dinosaur\\" which contains illegal filename characters in some operating systems.
Now, I could do a simple find and replace and remove any non-filename safe characters. However, at this point if I wished to allow them to actually use "//Barney_the_Dinosaur\\" as their handle in the chat, I would have to store that name (the one with illegal characters) in their preferences file and retrieve that when the logged into the chat. Which begs the question: If I plan to do it in this manner, then why base it on handle-name at all? Perhaps adding another form field might be more appropriate.
Furthermore, I want to make sure that no two people can have the same handle anyways. So if I DO choose to base it on something other than their handle, I might have to look through all the preference files and check for duplicates whenever someone new creates their set of preferences.
So, here are a few possible solutions I have that I wanted to share here as I am not an uber-programmer and always appreciate help.
1: Don't use their actual handle at all. Perhaps use the hash-code of their handle as the filename. (Do Hash-codes contain illegal characters themselves? Furthermore, would the hash code for "John_Doe" generated at 5:15 on Sunday be exactlyt he same as the hash code for a second "John_Doe" created at 2:30 on Tuesday? If not, then people could end up having the same handles, which I want to avoid.)
2: Create an index file mapping handle names to a randomly generated unique filename I assign each handle. (This index could get quite large. Searching it would probably not prove too difficult if it was ordered correctly, however, keeping it in order when new names were added would seem (to me at least) to be difficult and computationally expensive were it to be a single file. I don't want to keep this index in memory, but rather keep it file based. Any ideas on how to keep it ordered easily would be appreciated.)
3: Use a third form field for their login name that would not allow illegal characters to begin with. This might prove a problem then of having to search all the preference files to make sure no duplicate names exist.
4: A pre-existing library to keep track of serialized objects for me? I checked sourceforge but couldn't find anything like this that wasn't an entire JAVA based database solution. Maybe I just missed it...?
So, which implementation do YOU feel is best? Or, do you have your own ideas that may be better?
As I have said, all these ideas feel soemwhat "clunky" to me, and not very elegant or necessarily efficent. Any help you could give me on the implementation would be GREATELY appreciated!
Thank you all for your time,
RAKKIR
I am currently working on a pet servlet project (a chatroom)written in JAVA. One aspect of this project allows users to store their "preferences" for the chatroom, on the server.
When a user wishes to use the chatroom they log-in through an HTML based form containing form fields for both their chatroom handle and their password.
At this point, the servlet uses their handle to access their preferences.
Likewise, if someone is new, the servlet prompts them to create a preferences file for themselves before using the chat.
Okay, that's all pretty straightforward, but the part that gets me is the implementation of storing/accessing these preferences.
Unfortunately, I cannot hook this servlet up to any database through JDBC, so that rules that possibility out.
So, my current planned implementation involves serialized preference objects. I originally planed to base the serialized object files on the person's handle. So you would would have a file "john_doe.dat" storing John Doe's preferences.
This was all well and good, but I realized it quickly broke down in implementation. Especially if someone decides to use the handle "//Barney_The_Dinosaur\\" which contains illegal filename characters in some operating systems.
Now, I could do a simple find and replace and remove any non-filename safe characters. However, at this point if I wished to allow them to actually use "//Barney_the_Dinosaur\\" as their handle in the chat, I would have to store that name (the one with illegal characters) in their preferences file and retrieve that when the logged into the chat. Which begs the question: If I plan to do it in this manner, then why base it on handle-name at all? Perhaps adding another form field might be more appropriate.
Furthermore, I want to make sure that no two people can have the same handle anyways. So if I DO choose to base it on something other than their handle, I might have to look through all the preference files and check for duplicates whenever someone new creates their set of preferences.
So, here are a few possible solutions I have that I wanted to share here as I am not an uber-programmer and always appreciate help.
1: Don't use their actual handle at all. Perhaps use the hash-code of their handle as the filename. (Do Hash-codes contain illegal characters themselves? Furthermore, would the hash code for "John_Doe" generated at 5:15 on Sunday be exactlyt he same as the hash code for a second "John_Doe" created at 2:30 on Tuesday? If not, then people could end up having the same handles, which I want to avoid.)
2: Create an index file mapping handle names to a randomly generated unique filename I assign each handle. (This index could get quite large. Searching it would probably not prove too difficult if it was ordered correctly, however, keeping it in order when new names were added would seem (to me at least) to be difficult and computationally expensive were it to be a single file. I don't want to keep this index in memory, but rather keep it file based. Any ideas on how to keep it ordered easily would be appreciated.)
3: Use a third form field for their login name that would not allow illegal characters to begin with. This might prove a problem then of having to search all the preference files to make sure no duplicate names exist.
4: A pre-existing library to keep track of serialized objects for me? I checked sourceforge but couldn't find anything like this that wasn't an entire JAVA based database solution. Maybe I just missed it...?
So, which implementation do YOU feel is best? Or, do you have your own ideas that may be better?
As I have said, all these ideas feel soemwhat "clunky" to me, and not very elegant or necessarily efficent. Any help you could give me on the implementation would be GREATELY appreciated!
Thank you all for your time,
RAKKIR