diff rep/xml/SessionXMLDecoder.java @ 77:eb78312ea831

*** empty log message ***
author pin
date Tue, 11 Dec 2007 09:01:06 +0900
parents 391d44c94799
children f7a9b323458b
line wrap: on
line diff
--- a/rep/xml/SessionXMLDecoder.java	Tue Dec 04 10:33:06 2007 +0900
+++ b/rep/xml/SessionXMLDecoder.java	Tue Dec 11 09:01:06 2007 +0900
@@ -48,18 +48,73 @@
 			Document doc = builder.parse(source);
 			Element root = doc.getDocumentElement();
 			
-			//System.out.println(root.getTagName());
+			//sessionlist = createSessionList(root);
+			sessionlist = generateSessionList(root);
+			sessionlist.setHost(getSessionManagerHost(root));
 			
-			sessionlist = createSessionList(root);
-
-
 		} catch (Exception e) {
 			e.printStackTrace();
 		}
 		return sessionlist;
 	}
 	
-	SessionList createSessionList(Element root){
+	private String getSessionManagerHost(Element root) {
+		NodeList nodelist = root.getChildNodes();
+		String host = null;
+		for(int i = 0; i < nodelist.getLength(); i++){
+			if(nodelist.item(i).getNodeName().equals("host")){
+				host = nodelist.item(i).getTextContent();
+			}
+		}
+		return host;
+	}
+	
+	private SessionList generateSessionList(Element element){
+		SessionList sessionlist = new SessionList();
+		NodeList nodelistSession = element.getElementsByTagName("Session");
+		
+		for(int i = 0; i < nodelistSession.getLength(); i++){
+			Element elementSession = (Element) nodelistSession.item(i);
+			NodeList nodelistEditor = elementSession.getElementsByTagName("Editor");
+			
+			Session session = null;
+			for(int j = 0; j < nodelistEditor.getLength(); j++){
+				String eid = ((Element)nodelistEditor.item(j)).getAttribute("eid");
+				
+				Element elementEditor = (Element) nodelistEditor.item(j);
+				NodeList nodelistEditorHost = elementEditor.getElementsByTagName("host");
+				Element elementHost = (Element) nodelistEditorHost.item(0); 
+				String host = elementHost.getFirstChild().getNodeValue();
+				
+				NodeList nodelistEditorPort = elementEditor.getElementsByTagName("port");
+				Element elementPort = (Element) nodelistEditorPort.item(0);
+				String port = elementPort.getFirstChild().getNodeValue();
+				
+				if(elementEditor.getChildNodes().getLength() > 2){
+					NodeList nodelistEditorFile = elementEditor.getElementsByTagName("file");
+					Element elementFile = (Element) nodelistEditorFile.item(0); 
+					String file = elementFile.getFirstChild().getNodeValue();
+					
+					Editor editor = new Editor();
+					editor.setHost(host); editor.setPort(port); editor.setName(file); editor.setEID(Integer.parseInt(eid)); 
+					session = new Session(editor);
+					session.addEditor(editor);
+					sessionlist.addSession(session);
+					
+				}else {
+					Editor editor = new Editor();
+					editor.setHost(host); editor.setPort(port); editor.setName(null); editor.setEID(Integer.parseInt(eid));
+					if(session != null){
+						session.addEditor(editor);
+						//sessionlist.addSession(session);
+					}
+				}
+			}
+		}
+		return sessionlist;
+	}
+
+	private SessionList createSessionList(Element root){
 		NodeList nodelistSession = root.getChildNodes();
 		SessionList sessionlist = new SessionList();