Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

Writing ASP Chat using JavaScript and XML (Part 4)

, 21 Jan 2004
The last part of the ASP chat series. This article explains how to provide a chat with multiple rooms.
// RoomsDataXML class.
/**
 *  Manages rooms information persistence and quick accessing.
 */
function RoomsDataXML() {
	this.getRoomsList = RoomsDataXML_getRoomsList;
	this.createRoom = RoomsDataXML_createRoom;
	this.findRoom = RoomsDataXML_findRoom;
	this.save = UsersDataXML_save; // Reused from UsersDataXML.
	this.initialize = UsersDataXML_initialize; // Reused from UsersDataXML.
	this.autoSave = UsersDataXML_autoSave; // Reused from UsersDataXML.
	this.filePath = getRoomsDataPath();
	this.autoSaveInterval = getAutoSaveInterval();// In seconds.
	this.identifier = "RoomsStore";
}

/**
 *  Retraives rooms nodes list.
 */
function RoomsDataXML_getRoomsList() {
	var roomsStore = new SharedXML(this.identifier);
	return roomsStore.getItems();
}

/**
 *  Creates new room.
 *  @param roomName the room title.
 *  @return Newly created roomID.
 */
function RoomsDataXML_createRoom(roomName) {
	var room = this.findRoom(roomName);
	if(typeof(room) != "undefined") {
		// Room already exists.
		return -1;
	}
	var roomsStore = new SharedXML(this.identifier);
	var xmlNode = roomsStore.addNode();
	var newRoom = new RoomInfo(xmlNode);
	newRoom.setRoomName(roomName);
	var id = newRoom.getRoomID();
	this.autoSave();
	return id;
}

/**
 *  Searches for room by name.
 *  @return RoomInfo class if found, owervize undefined.
 */
function RoomsDataXML_findRoom(roomName) {
	var roomsStore = new SharedXML(this.identifier);
	var xmlNode = roomsStore.findNodeByName(roomName);
	if(xmlNode != null)
	{
		var room = new RoomInfo(xmlNode);
		return room;
	}
}
// RoomsDataXML class.

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Alexander Fedorenko
Web Developer
Ukraine Ukraine
Alexander Fedorenko is a professional C++ developer since 1996. He completed many custom and shareware projects. One of the successful projects is DevPlanner - tool for personal planning and time management.

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 22 Jan 2004
Article Copyright 2004 by Alexander Fedorenko
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid