Mercurial > hg > RemoteEditor > REPSessionManager
diff rep/xml/SessionXMLDecoder.java @ 386:bba62c4ac323
sync-option
author | one@firefly.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Mon, 10 Nov 2008 22:19:34 +0900 |
parents | 1fca50ce3508 |
children | 6f356d160e58 |
line wrap: on
line diff
--- a/rep/xml/SessionXMLDecoder.java Mon Nov 10 22:18:14 2008 +0900 +++ b/rep/xml/SessionXMLDecoder.java Mon Nov 10 22:19:34 2008 +0900 @@ -9,6 +9,8 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.InputSource; import org.xml.sax.SAXException; @@ -22,15 +24,13 @@ DocumentBuilderFactory factory; DocumentBuilder builder; - public SessionXMLDecoder(String string) throws SAXException, IOException { - decode(string); - } public SessionXMLDecoder() { factory = DocumentBuilderFactory.newInstance(); try { - factory.newDocumentBuilder(); + builder = factory.newDocumentBuilder(); } catch (ParserConfigurationException e) { + assert false; } } @@ -65,9 +65,9 @@ SessionList sessionlist = new SessionList(); NodeList nodelistSession = element.getElementsByTagName("Session"); for(int i = 0; i < nodelistSession.getLength(); i++){ - Element elementSession = (Element) nodelistSession.item(i); - int sid = Integer.parseInt(elementSession.getAttribute("sid")); - NodeList nodelistEditor = elementSession.getElementsByTagName("Editor"); + Node elementSession = nodelistSession.item(i); + int sid = getIntValue(elementSession,"sid"); + NodeList nodelistEditor = ((Element)elementSession).getElementsByTagName("Editor"); Session session = null; for(int j = 0; j < nodelistEditor.getLength(); j++){ @@ -76,7 +76,8 @@ Element elementEditor = (Element) nodelistEditor.item(j); NodeList nodelistEditorHost = elementEditor.getElementsByTagName("host"); Element elementHost = (Element) nodelistEditorHost.item(0); - String host = elementHost.getFirstChild().getNodeValue(); + Node hostValue = elementHost.getFirstChild(); + String host = hostValue==null?"":hostValue.getNodeValue(); if(elementEditor.getChildNodes().getLength() > 2){ NodeList nodelistEditorFile = elementEditor.getElementsByTagName("file"); @@ -100,5 +101,18 @@ } return sessionlist; } + + private int getIntValue(Node elementSession, String attrName) { + NamedNodeMap attr = elementSession.getAttributes(); + Node sidNode = attr.getNamedItem(attrName); + int sid = Integer.parseInt(sidNode.getNodeValue()); + return sid; + } +// +// private String getString(Node elementSession, String attrName) { +// NamedNodeMap attr = elementSession.getAttributes(); +// Node sidNode = attr.getNamedItem(attrName); +// return sidNode.getNodeValue(); +// } }