diff --git a/router/java/src/org/cybergarage/http/Date.java b/router/java/src/org/cybergarage/http/Date.java index a3424eb570e766a4d0c880763906d9b712e56581..117964d34b49b326059d9eeab0ae057cf4c362b9 100644 --- a/router/java/src/org/cybergarage/http/Date.java +++ b/router/java/src/org/cybergarage/http/Date.java @@ -1,8 +1,8 @@ /****************************************************************** * -* CyberHTTP for Java -* -* Copyright (C) Satoshi Konno 2002-2003 +* CyberHTTP for Java +* +* Copyright (C) Satoshi Konno 2002-2003 * * File : Date.java * @@ -16,7 +16,7 @@ * getHour(), getDateString() getTimeString() * - Fixed getInstance() to return GMT instance. * -******************************************************************/ +******************************************************************/ package org.cybergarage.http; @@ -136,15 +136,15 @@ public class Date public String getDateString() { // Thanks for Theo Beisch (10/20/04) - Calendar _cal = getCalendar(); + Calendar cal = getCalendar(); return - toWeekString(_cal.get(Calendar.DAY_OF_WEEK)) +", " + - toTimeString(_cal.get(Calendar.DATE)) + " " + - toMonthString(_cal.get(Calendar.MONTH)) + " " + - Integer.toString(_cal.get(Calendar.YEAR)) + " " + - toTimeString(_cal.get(Calendar.HOUR_OF_DAY)) + ":" + - toTimeString(_cal.get(Calendar.MINUTE)) + ":" + - toTimeString(_cal.get(Calendar.SECOND)) + " GMT"; + toWeekString(cal.get(Calendar.DAY_OF_WEEK)) +", " + + toTimeString(cal.get(Calendar.DATE)) + " " + + toMonthString(cal.get(Calendar.MONTH)) + " " + + Integer.toString(cal.get(Calendar.YEAR)) + " " + + toTimeString(cal.get(Calendar.HOUR_OF_DAY)) + ":" + + toTimeString(cal.get(Calendar.MINUTE)) + ":" + + toTimeString(cal.get(Calendar.SECOND)) + " GMT"; } //////////////////////////////////////////////// @@ -154,11 +154,11 @@ public class Date public String getTimeString() { // Thanks for Theo Beisch (10/20/04) - Calendar _cal = getCalendar(); + Calendar cal = getCalendar(); return - toDateString(_cal.get(Calendar.HOUR_OF_DAY)) + - (((_cal.get(Calendar.SECOND) % 2) == 0) ? ":" : " ") + - toDateString(_cal.get(Calendar.MINUTE)); + toDateString(cal.get(Calendar.HOUR_OF_DAY)) + + (((cal.get(Calendar.SECOND) % 2) == 0) ? ":" : " ") + + toDateString(cal.get(Calendar.MINUTE)); } } diff --git a/router/java/src/org/cybergarage/http/HTTPHeader.java b/router/java/src/org/cybergarage/http/HTTPHeader.java index 9ea1610e9def0510b6e1234acd6894a91f3f5dcc..d09446bdc6ef934dca1f75dbf2cf596611caa839 100644 --- a/router/java/src/org/cybergarage/http/HTTPHeader.java +++ b/router/java/src/org/cybergarage/http/HTTPHeader.java @@ -5,33 +5,33 @@ * Copyright (C) Satoshi Konno 2002 * * File: HTTPHeader.java -* -* Revision; -* -* 11/19/02 -* - first revision. +* +* Revision; +* +* 11/19/02 +* - first revision. * 05/26/04 * - Jan Newmarch <jan.newmarch@infotech.monash.edu.au> (05/26/04) * - Fixed getValue() to compare using String::equals() instead of String::startWidth(). * ******************************************************************/ - + package org.cybergarage.http; - -import java.io.*; + +import java.io.*; import org.cybergarage.util.*; - -public class HTTPHeader -{ - private String name; - private String value; - - public HTTPHeader(String name, String value) - { - setName(name); - setValue(value); - } + +public class HTTPHeader +{ + private String name; + private String value; + + public HTTPHeader(String name, String value) + { + setName(name); + setValue(value); + } public HTTPHeader(String lineStr) { @@ -42,35 +42,35 @@ public class HTTPHeader int colonIdx = lineStr.indexOf(':'); if (colonIdx < 0) return; - String _name = new String(lineStr.getBytes(), 0, colonIdx); - String _value = new String(lineStr.getBytes(), colonIdx+1, lineStr.length()-colonIdx-1); - setName(_name.trim()); - setValue(_value.trim()); + String name = new String(lineStr.getBytes(), 0, colonIdx); + String value = new String(lineStr.getBytes(), colonIdx+1, lineStr.length()-colonIdx-1); + setName(name.trim()); + setValue(value.trim()); } - + //////////////////////////////////////////////// // Member //////////////////////////////////////////////// - public void setName(String name) - { - this.name = name; - } - - public void setValue(String value) - { - this.value = value; - } - - public String getName() - { - return name; - } - - public String getValue() - { - return value; - } + public void setName(String name) + { + this.name = name; + } + + public void setValue(String value) + { + this.value = value; + } + + public String getName() + { + return name; + } + + public String getValue() + { + return value; + } public boolean hasName() { @@ -78,67 +78,67 @@ public class HTTPHeader return false; return true; } - - //////////////////////////////////////////////// - // static methods - //////////////////////////////////////////////// - - public final static String getValue(LineNumberReader reader, String name) - { - String bigName = name.toUpperCase(); - try { - String lineStr = reader.readLine(); - while (lineStr != null && 0 < lineStr.length()) { + + //////////////////////////////////////////////// + // static methods + //////////////////////////////////////////////// + + public final static String getValue(LineNumberReader reader, String name) + { + String bigName = name.toUpperCase(); + try { + String lineStr = reader.readLine(); + while (lineStr != null && 0 < lineStr.length()) { HTTPHeader header = new HTTPHeader(lineStr); - if (header.hasName() == false) { - lineStr = reader.readLine(); - continue; - } + if (header.hasName() == false) { + lineStr = reader.readLine(); + continue; + } String bigLineHeaderName = header.getName().toUpperCase(); - // Thanks for Jan Newmarch <jan.newmarch@infotech.monash.edu.au> (05/26/04) - if (bigLineHeaderName.equals(bigName) == false) { - lineStr = reader.readLine(); - continue; - } - return header.getValue(); - } - } + // Thanks for Jan Newmarch <jan.newmarch@infotech.monash.edu.au> (05/26/04) + if (bigLineHeaderName.equals(bigName) == false) { + lineStr = reader.readLine(); + continue; + } + return header.getValue(); + } + } catch (IOException e) { - Debug.warning(e); - return ""; - } - return ""; - } - - public final static String getValue(String data, String name) - { - StringReader strReader = new StringReader(data); - LineNumberReader lineReader = new LineNumberReader(strReader); - return getValue(lineReader, name); - } - - public final static String getValue(byte[] data, String name) - { - return getValue(new String(data), name); - } - - public final static int getIntegerValue(String data, String name) + Debug.warning(e); + return ""; + } + return ""; + } + + public final static String getValue(String data, String name) + { + StringReader strReader = new StringReader(data); + LineNumberReader lineReader = new LineNumberReader(strReader); + return getValue(lineReader, name); + } + + public final static String getValue(byte[] data, String name) + { + return getValue(new String(data), name); + } + + public final static int getIntegerValue(String data, String name) { try { return Integer.parseInt(getValue(data, name)); } catch (Exception e) { return 0; - } - } - - public final static int getIntegerValue(byte[] data, String name) - { + } + } + + public final static int getIntegerValue(byte[] data, String name) + { try { return Integer.parseInt(getValue(data, name)); } catch (Exception e) { return 0; } - } + } } diff --git a/router/java/src/org/cybergarage/http/HTTPPacket.java b/router/java/src/org/cybergarage/http/HTTPPacket.java index 7a5ea924d60cf22d2e7c636b955780346847c4cf..3c0c78e63e732253f7be3033ac62067b2113066c 100644 --- a/router/java/src/org/cybergarage/http/HTTPPacket.java +++ b/router/java/src/org/cybergarage/http/HTTPPacket.java @@ -5,11 +5,11 @@ * Copyright (C) Satoshi Konno 2002-2004 * * File: HTTPConnection.java -* -* Revision; -* -* 11/18/02 -* - first revision. +* +* Revision; +* +* 11/18/02 +* - first revision. * 09/02/03 * - Giordano Sassaroli <sassarol@cefriel.it> * - Problem : The API is unable to receive responses from the Microsoft UPnP stack @@ -64,24 +64,24 @@ package org.cybergarage.http; -import java.io.*; -import java.util.*; - +import java.io.*; +import java.util.*; + import org.cybergarage.net.*; -import org.cybergarage.util.*; -import java.util.Calendar; - -public class HTTPPacket -{ - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public HTTPPacket() +import org.cybergarage.util.*; +import java.util.Calendar; + +public class HTTPPacket +{ + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public HTTPPacket() { setVersion(HTTP.VERSION); - setContentInputStream(null); - } + setContentInputStream(null); + } public HTTPPacket(HTTPPacket httpPacket) { @@ -134,13 +134,13 @@ public class HTTPPacket try { BufferedReader reader = new BufferedReader(new InputStreamReader(in)); - String _firstLine = reader.readLine(); - if (_firstLine == null || _firstLine.length() <= 0) + String firstLine = reader.readLine(); + if (firstLine == null || firstLine.length() <= 0) return false; - setFirstLine(_firstLine); + setFirstLine(firstLine); // Thanks for Giordano Sassaroli <sassarol@cefriel.it> (09/03/03) - HTTPStatus httpStatus = new HTTPStatus(_firstLine); + HTTPStatus httpStatus = new HTTPStatus(firstLine); int statCode = httpStatus.getStatusCode(); if (statCode == HTTPStatus.CONTINUE){ //ad hoc code for managing iis non-standard behaviour @@ -186,7 +186,7 @@ public class HTTPPacket String chunkSizeLine = reader.readLine(); contentLen = Long.parseLong(new String(chunkSizeLine.getBytes(), 0, chunkSizeLine.length()-2)); } - catch (Exception e) {} + catch (Exception e) {}; } else contentLen = getContentLength(); @@ -231,7 +231,7 @@ public class HTTPPacket } catch (Exception e) { contentLen = 0; - } + }; } else contentLen = 0; @@ -312,47 +312,47 @@ public class HTTPPacket public boolean hasFirstLine() { - return (0 < firstLine.length()) ? true : false; - } - - //////////////////////////////////////////////// - // Header - //////////////////////////////////////////////// - - private Vector httpHeaderList = new Vector(); - - public int getNHeaders() - { - return httpHeaderList.size(); - } - - public void addHeader(HTTPHeader header) - { - httpHeaderList.add(header); - } - - public void addHeader(String name, String value) - { - HTTPHeader header = new HTTPHeader(name, value); - httpHeaderList.add(header); - } - - public HTTPHeader getHeader(int n) - { - return (HTTPHeader)httpHeaderList.get(n); - } - - public HTTPHeader getHeader(String name) - { - int nHeaders = getNHeaders(); - for (int n=0; n<nHeaders; n++) { - HTTPHeader header = getHeader(n); - String headerName = header.getName(); - if (headerName.equalsIgnoreCase(name) == true) - return header; - } - return null; - } + return (0 < firstLine.length()) ? true : false; + } + + //////////////////////////////////////////////// + // Header + //////////////////////////////////////////////// + + private Vector httpHeaderList = new Vector(); + + public int getNHeaders() + { + return httpHeaderList.size(); + } + + public void addHeader(HTTPHeader header) + { + httpHeaderList.add(header); + } + + public void addHeader(String name, String value) + { + HTTPHeader header = new HTTPHeader(name, value); + httpHeaderList.add(header); + } + + public HTTPHeader getHeader(int n) + { + return (HTTPHeader)httpHeaderList.get(n); + } + + public HTTPHeader getHeader(String name) + { + int nHeaders = getNHeaders(); + for (int n=0; n<nHeaders; n++) { + HTTPHeader header = getHeader(n); + String headerName = header.getName(); + if (headerName.equalsIgnoreCase(name) == true) + return header; + } + return null; + } public void clearHeaders() { @@ -364,16 +364,16 @@ public class HTTPPacket { return (getHeader(name) != null) ? true : false; } - - public void setHeader(String name, String value) - { - HTTPHeader header = getHeader(name); - if (header != null) { - header.setValue(value); - return; - } - addHeader(name, value); - } + + public void setHeader(String name, String value) + { + HTTPHeader header = getHeader(name); + if (header != null) { + header.setValue(value); + return; + } + addHeader(name, value); + } public void setHeader(String name, int value) { @@ -384,19 +384,19 @@ public class HTTPPacket { setHeader(name, Long.toString(value)); } - - public void setHeader(HTTPHeader header) - { - setHeader(header.getName(), header.getValue()); - } - - public String getHeaderValue(String name) - { - HTTPHeader header = getHeader(name); - if (header == null) - return ""; - return header.getValue(); - } + + public void setHeader(HTTPHeader header) + { + setHeader(header.getName(), header.getValue()); + } + + public String getHeaderValue(String name) + { + HTTPHeader header = getHeader(name); + if (header == null) + return ""; + return header.getValue(); + } //////////////////////////////////////////////// // set*Value @@ -431,7 +431,7 @@ public class HTTPPacket { return getStringHeaderValue(name, "\"", "\""); } - + public void setIntegerHeader(String name, int value) { setHeader(name, Integer.toString(value)); @@ -442,13 +442,13 @@ public class HTTPPacket setHeader(name, Long.toString(value)); } - public int getIntegerHeaderValue(String name) - { - HTTPHeader header = getHeader(name); - if (header == null) - return 0; - return StringUtil.toInteger(header.getValue()); - } + public int getIntegerHeaderValue(String name) + { + HTTPHeader header = getHeader(name); + if (header == null) + return 0; + return StringUtil.toInteger(header.getValue()); + } public long getLongHeaderValue(String name) { @@ -457,7 +457,7 @@ public class HTTPPacket return 0; return StringUtil.toLong(header.getValue()); } - + //////////////////////////////////////////////// // getHeader //////////////////////////////////////////////// @@ -475,48 +475,48 @@ public class HTTPPacket return str.toString(); } - //////////////////////////////////////////////// - // Contents - //////////////////////////////////////////////// - - private byte content[] = new byte[0]; - - public void setContent(byte data[], boolean updateWithContentLength) - { + //////////////////////////////////////////////// + // Contents + //////////////////////////////////////////////// + + private byte content[] = new byte[0]; + + public void setContent(byte data[], boolean updateWithContentLength) + { content = data; - if (updateWithContentLength == true) - setContentLength(data.length); - } - + if (updateWithContentLength == true) + setContentLength(data.length); + } + public void setContent(byte data[]) { setContent(data, true); } - public void setContent(String data, boolean updateWithContentLength) - { - setContent(data.getBytes(), updateWithContentLength); - } - + public void setContent(String data, boolean updateWithContentLength) + { + setContent(data.getBytes(), updateWithContentLength); + } + public void setContent(String data) { setContent(data, true); } - public byte []getContent() - { - return content; - } - - public String getContentString() - { - return new String(content); + public byte []getContent() + { + return content; + } + + public String getContentString() + { + return new String(content); } public boolean hasContent() { return (content.length > 0) ? true : false; - } + } //////////////////////////////////////////////// // Contents (InputStream) @@ -538,35 +538,35 @@ public class HTTPPacket { return (contentInput != null) ? true : false; } - - //////////////////////////////////////////////// - // ContentType - //////////////////////////////////////////////// - - public void setContentType(String type) - { - setHeader(HTTP.CONTENT_TYPE, type); - } - - public String getContentType() - { - return getHeaderValue(HTTP.CONTENT_TYPE); - } - - //////////////////////////////////////////////// - // ContentLength - //////////////////////////////////////////////// - - public void setContentLength(long len) - { - setLongHeader(HTTP.CONTENT_LENGTH, len); - } - - public long getContentLength() - { - return getLongHeaderValue(HTTP.CONTENT_LENGTH); - } - + + //////////////////////////////////////////////// + // ContentType + //////////////////////////////////////////////// + + public void setContentType(String type) + { + setHeader(HTTP.CONTENT_TYPE, type); + } + + public String getContentType() + { + return getHeaderValue(HTTP.CONTENT_TYPE); + } + + //////////////////////////////////////////////// + // ContentLength + //////////////////////////////////////////////// + + public void setContentLength(long len) + { + setLongHeader(HTTP.CONTENT_LENGTH, len); + } + + public long getContentLength() + { + return getLongHeaderValue(HTTP.CONTENT_LENGTH); + } + //////////////////////////////////////////////// // Connection //////////////////////////////////////////////// @@ -650,21 +650,21 @@ public class HTTPPacket try { range[0] = Long.parseLong(firstPosStr); } - catch (NumberFormatException e) {} + catch (NumberFormatException e) {}; if (strToken.hasMoreTokens() == false) return range; String lastPosStr = strToken.nextToken("-/"); try { range[1] = Long.parseLong(lastPosStr); } - catch (NumberFormatException e) {} + catch (NumberFormatException e) {}; if (strToken.hasMoreTokens() == false) return range; String lengthStr = strToken.nextToken("/"); try { range[2] = Long.parseLong(lengthStr); } - catch (NumberFormatException e) {} + catch (NumberFormatException e) {}; return range; } @@ -686,10 +686,10 @@ public class HTTPPacket return range[2]; } - //////////////////////////////////////////////// - // CacheControl - //////////////////////////////////////////////// - + //////////////////////////////////////////////// + // CacheControl + //////////////////////////////////////////////// + public void setCacheControl(String directive) { setHeader(HTTP.CACHE_CONTROL, directive); @@ -701,29 +701,29 @@ public class HTTPPacket setHeader(HTTP.CACHE_CONTROL, strVal); } - public void setCacheControl(int value) - { + public void setCacheControl(int value) + { setCacheControl(HTTP.MAX_AGE, value); - } - - public String getCacheControl() - { - return getHeaderValue(HTTP.CACHE_CONTROL); - } - - //////////////////////////////////////////////// - // Server - //////////////////////////////////////////////// - - public void setServer(String name) - { - setHeader(HTTP.SERVER, name); - } - - public String getServer() - { - return getHeaderValue(HTTP.SERVER); - } + } + + public String getCacheControl() + { + return getHeaderValue(HTTP.CACHE_CONTROL); + } + + //////////////////////////////////////////////// + // Server + //////////////////////////////////////////////// + + public void setServer(String name) + { + setHeader(HTTP.SERVER, name); + } + + public String getServer() + { + return getHeaderValue(HTTP.SERVER); + } //////////////////////////////////////////////// // Host @@ -742,21 +742,21 @@ public class HTTPPacket return getHeaderValue(HTTP.HOST); } - - //////////////////////////////////////////////// - // Date - //////////////////////////////////////////////// - - public void setDate(Calendar cal) - { - Date date = new Date(cal); - setHeader(HTTP.DATE, date.getDateString()); - } - - public String getDate() - { - return getHeaderValue(HTTP.DATE); - } + + //////////////////////////////////////////////// + // Date + //////////////////////////////////////////////// + + public void setDate(Calendar cal) + { + Date date = new Date(cal); + setHeader(HTTP.DATE, date.getDateString()); + } + + public String getDate() + { + return getHeaderValue(HTTP.DATE); + } //////////////////////////////////////////////// // Connection @@ -804,5 +804,5 @@ public class HTTPPacket return false; } */ -} - +} + diff --git a/router/java/src/org/cybergarage/http/HTTPRequest.java b/router/java/src/org/cybergarage/http/HTTPRequest.java index c1c3b50f6ce6ed81c6faa3ead33ff63ad105334d..9e03adc895e4905305df10cfd5a5e33767c292dc 100644 --- a/router/java/src/org/cybergarage/http/HTTPRequest.java +++ b/router/java/src/org/cybergarage/http/HTTPRequest.java @@ -5,11 +5,11 @@ * Copyright (C) Satoshi Konno 2002-2004 * * File: HTTPRequest.java -* -* Revision; -* -* 11/18/02 -* - first revision. +* +* Revision; +* +* 11/18/02 +* - first revision. * 05/23/03 * - Giordano Sassaroli <sassarol@cefriel.it> * - Add a relative URL check to setURI(). @@ -46,24 +46,24 @@ * - Changed post() to suppot chunked stream. * ******************************************************************/ - + package org.cybergarage.http; - -import java.io.*; -import java.net.*; + +import java.io.*; +import java.net.*; import java.util.*; import org.cybergarage.util.Debug; - -public class HTTPRequest extends HTTPPacket -{ - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public HTTPRequest() - { - } + +public class HTTPRequest extends HTTPPacket +{ + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public HTTPRequest() + { + } public HTTPRequest(InputStream in) { @@ -76,23 +76,23 @@ public class HTTPRequest extends HTTPPacket setSocket(httpSock); } - //////////////////////////////////////////////// - // Method - //////////////////////////////////////////////// - - private String method = null; - - public void setMethod(String value) - { - method = value; - } - - public String getMethod() - { - if (method != null) + //////////////////////////////////////////////// + // Method + //////////////////////////////////////////////// + + private String method = null; + + public void setMethod(String value) + { + method = value; + } + + public String getMethod() + { + if (method != null) return method; - return getFirstLineToken(0); - } + return getFirstLineToken(0); + } public boolean isMethod(String method) { @@ -101,16 +101,16 @@ public class HTTPRequest extends HTTPPacket return false; return headerMethod.equalsIgnoreCase(method); } - - public boolean isGetRequest() - { - return isMethod(HTTP.GET); - } - - public boolean isPostRequest() + + public boolean isGetRequest() { + return isMethod(HTTP.GET); + } + + public boolean isPostRequest() + { return isMethod(HTTP.POST); - } + } public boolean isHeadRequest() { @@ -132,33 +132,33 @@ public class HTTPRequest extends HTTPPacket return isMethod(HTTP.NOTIFY); } - //////////////////////////////////////////////// - // URI - //////////////////////////////////////////////// - - private String uri = null; - - public void setURI(String value, boolean isCheckRelativeURL) - { + //////////////////////////////////////////////// + // URI + //////////////////////////////////////////////// + + private String uri = null; + + public void setURI(String value, boolean isCheckRelativeURL) + { uri = value; if (isCheckRelativeURL == false) return; // Thanks for Giordano Sassaroli <sassarol@cefriel.it> (09/02/03) uri = HTTP.toRelativeURL(uri); - } + } public void setURI(String value) { setURI(value, false); } - public String getURI() + public String getURI() { - if (uri != null) - return uri; + if (uri != null) + return uri; return getFirstLineToken(1); - } - + } + //////////////////////////////////////////////// // URI Parameter //////////////////////////////////////////////// @@ -166,17 +166,17 @@ public class HTTPRequest extends HTTPPacket public ParameterList getParameterList() { ParameterList paramList = new ParameterList(); - String _uri = getURI(); - if (_uri == null) + String uri = getURI(); + if (uri == null) return paramList; - int paramIdx = _uri.indexOf('?'); + int paramIdx = uri.indexOf('?'); if (paramIdx < 0) return paramList; while (0 < paramIdx) { - int eqIdx = _uri.indexOf('=', (paramIdx+1)); - String name = _uri.substring(paramIdx+1, eqIdx); - int nextParamIdx = _uri.indexOf('&', (eqIdx+1)); - String value = _uri.substring(eqIdx+1, (0 < nextParamIdx) ? nextParamIdx : _uri.length()); + int eqIdx = uri.indexOf('=', (paramIdx+1)); + String name = uri.substring(paramIdx+1, eqIdx); + int nextParamIdx = uri.indexOf('&', (eqIdx+1)); + String value = uri.substring(eqIdx+1, (0 < nextParamIdx) ? nextParamIdx : uri.length()); Parameter param = new Parameter(name, value); paramList.add(param); paramIdx = nextParamIdx; @@ -227,21 +227,21 @@ public class HTTPRequest extends HTTPPacket return requestPort; } - //////////////////////////////////////////////// - // Socket - //////////////////////////////////////////////// - - private HTTPSocket httpSocket = null; - - public void setSocket(HTTPSocket value) - { - httpSocket = value; - } - - public HTTPSocket getSocket() - { - return httpSocket; - } + //////////////////////////////////////////////// + // Socket + //////////////////////////////////////////////// + + private HTTPSocket httpSocket = null; + + public void setSocket(HTTPSocket value) + { + httpSocket = value; + } + + public HTTPSocket getSocket() + { + return httpSocket; + } /////////////////////////// ///////////////////// // local address/port @@ -256,25 +256,25 @@ public class HTTPRequest extends HTTPPacket { return getSocket().getLocalPort(); } - - //////////////////////////////////////////////// - // parseRequest - //////////////////////////////////////////////// - - public boolean parseRequestLine(String lineStr) - { - StringTokenizer st = new StringTokenizer(lineStr, HTTP.REQEST_LINE_DELIM); - if (st.hasMoreTokens() == false) - return false; - setMethod(st.nextToken()); - if (st.hasMoreTokens() == false) - return false; - setURI(st.nextToken()); - if (st.hasMoreTokens() == false) - return false; - setVersion(st.nextToken()); - return true; - } + + //////////////////////////////////////////////// + // parseRequest + //////////////////////////////////////////////// + + public boolean parseRequestLine(String lineStr) + { + StringTokenizer st = new StringTokenizer(lineStr, HTTP.REQEST_LINE_DELIM); + if (st.hasMoreTokens() == false) + return false; + setMethod(st.nextToken()); + if (st.hasMoreTokens() == false) + return false; + setURI(st.nextToken()); + if (st.hasMoreTokens() == false) + return false; + setVersion(st.nextToken()); + return true; + } //////////////////////////////////////////////// // First Line @@ -292,22 +292,22 @@ public class HTTPRequest extends HTTPPacket return getMethod() + " " + getURI() + " " + getHTTPVersion() + HTTP.CRLF; } - //////////////////////////////////////////////// - // getHeader - //////////////////////////////////////////////// - - public String getHeader() - { - StringBuilder str = new StringBuilder(); - - str.append(getFirstLineString()); - + //////////////////////////////////////////////// + // getHeader + //////////////////////////////////////////////// + + public String getHeader() + { + StringBuilder str = new StringBuilder(); + + str.append(getFirstLineString()); + String headerString = getHeaderString(); str.append(headerString); - - return str.toString(); - } - + + return str.toString(); + } + //////////////////////////////////////////////// // isKeepAlive //////////////////////////////////////////////// @@ -334,9 +334,9 @@ public class HTTPRequest extends HTTPPacket return super.read(getSocket()); } - //////////////////////////////////////////////// - // POST (Response) - //////////////////////////////////////////////// + //////////////////////////////////////////////// + // POST (Response) + //////////////////////////////////////////////// public boolean post(HTTPResponse httpRes) { @@ -361,15 +361,15 @@ public class HTTPRequest extends HTTPPacket return httpSock.post(httpRes, offset, length, isHeadRequest()); //httpSock.close(); } - + //////////////////////////////////////////////// // POST (Request) //////////////////////////////////////////////// private Socket postSocket = null; - public HTTPResponse post(String host, int port, boolean isKeepAlive) - { + public HTTPResponse post(String host, int port, boolean isKeepAlive) + { HTTPResponse httpRes = new HTTPResponse(); setConnection((isKeepAlive == true) ? HTTP.KEEP_ALIVE : HTTP.CLOSE); @@ -396,9 +396,9 @@ public class HTTPRequest extends HTTPPacket postSocket.connect(sa, 3000); } - out = postSocket.getOutputStream(); - PrintStream pout = new PrintStream(out); - pout.print(getHeader()); + out = postSocket.getOutputStream(); + PrintStream pout = new PrintStream(out); + pout.print(getHeader()); pout.print(HTTP.CRLF); boolean isChunkedRequest = isChunked(); @@ -407,7 +407,7 @@ public class HTTPRequest extends HTTPPacket int contentLength = 0; if (content != null) contentLength = content.length(); - + if (0 < contentLength) { if (isChunkedRequest == true) { String chunSizeBuf = Long.toString(contentLength); @@ -424,34 +424,34 @@ public class HTTPRequest extends HTTPPacket pout.print(HTTP.CRLF); } - pout.flush(); + pout.flush(); in = postSocket.getInputStream(); httpRes.set(in, isHeaderRequest); - } + } catch (Exception e) { - httpRes.setStatusCode(HTTPStatus.INTERNAL_SERVER_ERROR); + httpRes.setStatusCode(HTTPStatus.INTERNAL_SERVER_ERROR); // I2P addition Debug.warning(e); } finally { if (isKeepAlive == false) { try { in.close(); - } catch (Exception e) {} + } catch (Exception e) {}; if (in != null) try { out.close(); - } catch (Exception e) {} + } catch (Exception e) {}; if (out != null) try { postSocket.close(); - } catch (Exception e) {} + } catch (Exception e) {}; postSocket = null; } } return httpRes; - } + } public HTTPResponse post(String host, int port) { @@ -490,21 +490,20 @@ public class HTTPRequest extends HTTPPacket return returnResponse(HTTPStatus.BAD_REQUEST); } - //////////////////////////////////////////////// - // toString - //////////////////////////////////////////////// - - @Override - public String toString() - { - StringBuilder str = new StringBuilder(); - - str.append(getHeader()); - str.append(HTTP.CRLF); - str.append(getContentString()); - - return str.toString(); - } + //////////////////////////////////////////////// + // toString + //////////////////////////////////////////////// + + public String toString() + { + StringBuilder str = new StringBuilder(); + + str.append(getHeader()); + str.append(HTTP.CRLF); + str.append(getContentString()); + + return str.toString(); + } public void print() { diff --git a/router/java/src/org/cybergarage/http/HTTPResponse.java b/router/java/src/org/cybergarage/http/HTTPResponse.java index 9d681808365d3154bd71e19166abd1dca3cc81ae..fd5700c265872c3fb97b3562776b56076674b9c1 100644 --- a/router/java/src/org/cybergarage/http/HTTPResponse.java +++ b/router/java/src/org/cybergarage/http/HTTPResponse.java @@ -5,11 +5,11 @@ * Copyright (C) Satoshi Konno 2002-2003 * * File: HTTPResponse.java -* -* Revision; -* -* 11/18/02 -* - first revision. +* +* Revision; +* +* 11/18/02 +* - first revision. * 10/22/03 * - Changed to initialize a content length header. * 10/22/04 @@ -17,23 +17,23 @@ * ******************************************************************/ -package org.cybergarage.http; +package org.cybergarage.http; import java.io.*; import org.cybergarage.util.Debug; - -public class HTTPResponse extends HTTPPacket -{ - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public HTTPResponse() - { + +public class HTTPResponse extends HTTPPacket +{ + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public HTTPResponse() + { setContentType(HTML.CONTENT_TYPE); setServer(HTTPServer.getName()); setContent(""); - } + } public HTTPResponse(HTTPResponse httpRes) { @@ -49,25 +49,25 @@ public class HTTPResponse extends HTTPPacket { this(httpSock.getInputStream()); } - - //////////////////////////////////////////////// - // Status Line - //////////////////////////////////////////////// + + //////////////////////////////////////////////// + // Status Line + //////////////////////////////////////////////// private int statusCode = 0; - - public void setStatusCode(int code) + + public void setStatusCode(int code) { - statusCode = code; - } - - public int getStatusCode() + statusCode = code; + } + + public int getStatusCode() { if (statusCode != 0) - return statusCode; + return statusCode; HTTPStatus httpStatus = new HTTPStatus(getFirstLine()); - return httpStatus.getStatusCode(); - } + return httpStatus.getStatusCode(); + } public boolean isSuccessful() { @@ -78,26 +78,25 @@ public class HTTPResponse extends HTTPPacket { return "HTTP/" + getVersion() + " " + getStatusCode() + " " + HTTPStatus.code2String(statusCode) + HTTP.CRLF; } - - //////////////////////////////////////////////// - // getHeader - //////////////////////////////////////////////// - - public String getHeader() - { - StringBuilder str = new StringBuilder(); - - str.append(getStatusLineString()); + + //////////////////////////////////////////////// + // getHeader + //////////////////////////////////////////////// + + public String getHeader() + { + StringBuilder str = new StringBuilder(); + + str.append(getStatusLineString()); str.append(getHeaderString()); - - return str.toString(); - } + + return str.toString(); + } //////////////////////////////////////////////// // toString //////////////////////////////////////////////// - @Override public String toString() { StringBuilder str = new StringBuilder(); diff --git a/router/java/src/org/cybergarage/http/HTTPServerThread.java b/router/java/src/org/cybergarage/http/HTTPServerThread.java index ea385401073dd78f87870126ff251fd6e5ad3923..40351ecaf0b91c84e21eeb36df4be7cc128aceac 100644 --- a/router/java/src/org/cybergarage/http/HTTPServerThread.java +++ b/router/java/src/org/cybergarage/http/HTTPServerThread.java @@ -37,7 +37,6 @@ public class HTTPServerThread extends Thread // run //////////////////////////////////////////////// - @Override public void run() { HTTPSocket httpSock = new HTTPSocket(sock); diff --git a/router/java/src/org/cybergarage/http/HTTPSocket.java b/router/java/src/org/cybergarage/http/HTTPSocket.java index e75573356c0781930eea8d41bfefc4317d4498f7..6709aa41a4c1f036aa25ced2606f0f30be68ab40 100644 --- a/router/java/src/org/cybergarage/http/HTTPSocket.java +++ b/router/java/src/org/cybergarage/http/HTTPSocket.java @@ -5,11 +5,11 @@ * Copyright (C) Satoshi Konno 2002-2004 * * File: HTTPSocket.java -* -* Revision; -* -* 12/12/02 -* - first revision. +* +* Revision; +* +* 12/12/02 +* - first revision. * 03/11/04 * - Added the following methods about chunk size. * setChunkSize(), getChunkSize(). @@ -19,24 +19,24 @@ * - Changed post() to suppot chunked stream. * ******************************************************************/ - -package org.cybergarage.http; - -import java.io.*; -import java.net.*; + +package org.cybergarage.http; + +import java.io.*; +import java.net.*; import java.util.*; - -public class HTTPSocket -{ - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public HTTPSocket(Socket socket) - { - setSocket(socket); + +public class HTTPSocket +{ + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public HTTPSocket(Socket socket) + { + setSocket(socket); open(); - } + } public HTTPSocket(HTTPSocket socket) { @@ -45,12 +45,11 @@ public class HTTPSocket setOutputStream(socket.getOutputStream()); } - @Override - public void finalize() - { - close(); - } - + public void finalize() + { + close(); + } + //////////////////////////////////////////////// // Socket //////////////////////////////////////////////// @@ -87,27 +86,27 @@ public class HTTPSocket private InputStream sockIn = null; private OutputStream sockOut = null; - + private void setInputStream(InputStream in) { sockIn = in; } - public InputStream getInputStream() - { - return sockIn; - } + public InputStream getInputStream() + { + return sockIn; + } private void setOutputStream(OutputStream out) { sockOut = out; } - - private OutputStream getOutputStream() - { - return sockOut; - } - + + private OutputStream getOutputStream() + { + return sockOut; + } + //////////////////////////////////////////////// // open/close //////////////////////////////////////////////// @@ -141,20 +140,20 @@ public class HTTPSocket return true; } - //////////////////////////////////////////////// - // post - //////////////////////////////////////////////// - - private boolean post(HTTPResponse httpRes, byte content[], long contentOffset, long contentLength, boolean isOnlyHeader) - { + //////////////////////////////////////////////// + // post + //////////////////////////////////////////////// + + private boolean post(HTTPResponse httpRes, byte content[], long contentOffset, long contentLength, boolean isOnlyHeader) + { httpRes.setDate(Calendar.getInstance()); - OutputStream out = getOutputStream(); - + OutputStream out = getOutputStream(); + try { httpRes.setContentLength(contentLength); - - out.write(httpRes.getHeader().getBytes()); - out.write(HTTP.CRLF.getBytes()); + + out.write(httpRes.getHeader().getBytes()); + out.write(HTTP.CRLF.getBytes()); if (isOnlyHeader == true) { out.flush(); return true; @@ -175,17 +174,17 @@ public class HTTPSocket out.write("0".getBytes()); out.write(HTTP.CRLF.getBytes()); } - - out.flush(); - } - catch (Exception e) { - //Debug.warning(e); + + out.flush(); + } + catch (Exception e) { + //Debug.warning(e); return false; } - return true; + return true; } - + private boolean post(HTTPResponse httpRes, InputStream in, long contentOffset, long contentLength, boolean isOnlyHeader) { httpRes.setDate(Calendar.getInstance()); diff --git a/router/java/src/org/cybergarage/net/HostInterface.java b/router/java/src/org/cybergarage/net/HostInterface.java index 237dfb640119d14c04164d6bf010a6c0e49da698..798f33dcac61cdbf01ecc2ce491c763d87492eec 100644 --- a/router/java/src/org/cybergarage/net/HostInterface.java +++ b/router/java/src/org/cybergarage/net/HostInterface.java @@ -5,11 +5,11 @@ * Copyright (C) Satoshi Konno 2002-2003 * * File: HostInterface.java -* -* Revision; -* -* 05/12/03 -* - first revision. +* +* Revision; +* +* 05/12/03 +* - first revision. * 05/13/03 * - Added support for IPv6 and loopback address. * 02/15/04 @@ -22,14 +22,14 @@ * - Changed isUseAddress() to isUsableAddress(). * ******************************************************************/ - -package org.cybergarage.net; - -import java.net.*; + +package org.cybergarage.net; + +import java.net.*; import java.util.*; - -public class HostInterface -{ + +public class HostInterface +{ //////////////////////////////////////////////// // Constants //////////////////////////////////////////////// @@ -101,7 +101,7 @@ public class HostInterface } } } - catch(Exception e){} + catch(Exception e){}; return nHostAddrs; } @@ -131,7 +131,7 @@ public class HostInterface } } } - catch(Exception e){} + catch(Exception e){}; return ""; } diff --git a/router/java/src/org/cybergarage/soap/SOAPRequest.java b/router/java/src/org/cybergarage/soap/SOAPRequest.java index 7fa54871ce1cf08a3a401cfa72ef4d5b08183dbc..35d31345fe84cc2aa1b7062251d60a55da10ba02 100644 --- a/router/java/src/org/cybergarage/soap/SOAPRequest.java +++ b/router/java/src/org/cybergarage/soap/SOAPRequest.java @@ -5,11 +5,11 @@ * Copyright (C) Satoshi Konno 2002 * * File: SOAPRequest.java -* -* Revision; -* -* 12/11/02 -* - first revision. +* +* Revision; +* +* 12/11/02 +* - first revision. * 02/13/04 * - Ralf G. R. Bergs <Ralf@Ber.gs>, Inma Marin Lopez <inma@dif.um.es>. * - Added XML header, <?xml version=\"1.0\"?> to setContent(). @@ -17,28 +17,28 @@ * - Changed the XML header to <?xml version="1.0" encoding="utf-8"?> in setContent(). * ******************************************************************/ - -package org.cybergarage.soap; - -import java.io.*; - -import org.cybergarage.http.*; -import org.cybergarage.xml.*; -import org.cybergarage.util.*; - -public class SOAPRequest extends HTTPRequest + +package org.cybergarage.soap; + +import java.io.*; + +import org.cybergarage.http.*; +import org.cybergarage.xml.*; +import org.cybergarage.util.*; + +public class SOAPRequest extends HTTPRequest { private final static String SOAPACTION = "SOAPACTION"; - - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public SOAPRequest() + + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public SOAPRequest() { - setContentType(SOAP.CONTENT_TYPE); - setMethod(HTTP.POST); - } + setContentType(SOAP.CONTENT_TYPE); + setMethod(HTTP.POST); + } public SOAPRequest(HTTPRequest httpReq) { @@ -71,33 +71,33 @@ public class SOAPRequest extends HTTPRequest return false; return soapAction.equals(value); } - - //////////////////////////////////////////////// - // post - //////////////////////////////////////////////// - - public SOAPResponse postMessage(String host, int port) - { - HTTPResponse httpRes = post(host, port); + + //////////////////////////////////////////////// + // post + //////////////////////////////////////////////// + + public SOAPResponse postMessage(String host, int port) + { + HTTPResponse httpRes = post(host, port); - SOAPResponse soapRes = new SOAPResponse(httpRes); - - byte content[] = soapRes.getContent(); - if (content.length <= 0) - return soapRes; - - try { - ByteArrayInputStream byteIn = new ByteArrayInputStream(content); - Parser xmlParser = SOAP.getXMLParser(); - Node _rootNode = xmlParser.parse(byteIn); - soapRes.setEnvelopeNode(_rootNode); - } - catch (Exception e) { - Debug.warning(e); - } - - return soapRes; - } + SOAPResponse soapRes = new SOAPResponse(httpRes); + + byte content[] = soapRes.getContent(); + if (content.length <= 0) + return soapRes; + + try { + ByteArrayInputStream byteIn = new ByteArrayInputStream(content); + Parser xmlParser = SOAP.getXMLParser(); + Node rootNode = xmlParser.parse(byteIn); + soapRes.setEnvelopeNode(rootNode); + } + catch (Exception e) { + Debug.warning(e); + } + + return soapRes; + } //////////////////////////////////////////////// // Node @@ -170,7 +170,6 @@ public class SOAPRequest extends HTTPRequest // print //////////////////////////////////////////////// - @Override public void print() { Debug.message(toString()); diff --git a/router/java/src/org/cybergarage/soap/SOAPResponse.java b/router/java/src/org/cybergarage/soap/SOAPResponse.java index 51f0abf73ef23e5f6032d607e9c15a7b563be794..d21ac857fe58805b8683fdee23f228a39254af79 100644 --- a/router/java/src/org/cybergarage/soap/SOAPResponse.java +++ b/router/java/src/org/cybergarage/soap/SOAPResponse.java @@ -5,11 +5,11 @@ * Copyright (C) Satoshi Konno 2002 * * File: SOAPResponse.java -* -* Revision; -* -* 12/17/02 -* - first revision. +* +* Revision; +* +* 12/17/02 +* - first revision. * 02/13/04 * - Ralf G. R. Bergs <Ralf@Ber.gs>, Inma Marin Lopez <inma@dif.um.es>. * - Added XML header, <?xml version="1.0"?> to setContent(). @@ -17,24 +17,24 @@ * - Changed the XML header to <?xml version="1.0" encoding="utf-8"?> in setContent(). * ******************************************************************/ - -package org.cybergarage.soap; - -import org.cybergarage.http.*; + +package org.cybergarage.soap; + +import org.cybergarage.http.*; import org.cybergarage.util.Debug; -import org.cybergarage.xml.*; - -public class SOAPResponse extends HTTPResponse -{ - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public SOAPResponse() +import org.cybergarage.xml.*; + +public class SOAPResponse extends HTTPResponse +{ + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public SOAPResponse() { setRootNode(SOAP.createEnvelopeBodyNode()); setContentType(XML.CONTENT_TYPE); - } + } public SOAPResponse(HTTPResponse httpRes) { @@ -50,25 +50,25 @@ public class SOAPResponse extends HTTPResponse setContentType(XML.CONTENT_TYPE); } - //////////////////////////////////////////////// - // Node - //////////////////////////////////////////////// - - private Node rootNode; - - private void setRootNode(Node node) - { + //////////////////////////////////////////////// + // Node + //////////////////////////////////////////////// + + private Node rootNode; + + private void setRootNode(Node node) + { rootNode = node; - } - - private Node getRootNode() - { - return rootNode; - } - - //////////////////////////////////////////////// - // SOAP Basic - //////////////////////////////////////////////// + } + + private Node getRootNode() + { + return rootNode; + } + + //////////////////////////////////////////////// + // SOAP Basic + //////////////////////////////////////////////// public void setEnvelopeNode(Node node) { @@ -79,88 +79,88 @@ public class SOAPResponse extends HTTPResponse { return getRootNode(); } - - public Node getBodyNode() - { - Node envNode = getEnvelopeNode(); - if (envNode == null) - return null; - return envNode.getNodeEndsWith(SOAP.BODY); - } - - public Node getMethodResponseNode(String name) - { - Node bodyNode = getBodyNode(); - if (bodyNode == null) - return null; - String methodResName = name + SOAP.RESPONSE; - return bodyNode.getNodeEndsWith(methodResName); - } - - public Node getFaultNode() - { - Node bodyNode = getBodyNode(); - if (bodyNode == null) - return null; - return bodyNode.getNodeEndsWith(SOAP.FAULT); - } - - public Node getFaultCodeNode() - { - Node faultNode = getFaultNode(); - if (faultNode == null) - return null; - return faultNode.getNodeEndsWith(SOAP.FAULT_CODE); - } - - public Node getFaultStringNode() - { - Node faultNode = getFaultNode(); - if (faultNode == null) - return null; - return faultNode.getNodeEndsWith(SOAP.FAULT_STRING); - } - - public Node getFaultActorNode() - { - Node faultNode = getFaultNode(); - if (faultNode == null) - return null; - return faultNode.getNodeEndsWith(SOAP.FAULTACTOR); - } - - public Node getFaultDetailNode() - { - Node faultNode = getFaultNode(); - if (faultNode == null) - return null; - return faultNode.getNodeEndsWith(SOAP.DETAIL); - } - - public String getFaultCode() - { - Node node = getFaultCodeNode(); - if (node == null) - return ""; - return node.getValue(); - } - - public String getFaultString() - { - Node node = getFaultStringNode(); - if (node == null) - return ""; - return node.getValue(); - } - - public String getFaultActor() - { - Node node = getFaultActorNode(); - if (node == null) - return ""; - return node.getValue(); - } - + + public Node getBodyNode() + { + Node envNode = getEnvelopeNode(); + if (envNode == null) + return null; + return envNode.getNodeEndsWith(SOAP.BODY); + } + + public Node getMethodResponseNode(String name) + { + Node bodyNode = getBodyNode(); + if (bodyNode == null) + return null; + String methodResName = name + SOAP.RESPONSE; + return bodyNode.getNodeEndsWith(methodResName); + } + + public Node getFaultNode() + { + Node bodyNode = getBodyNode(); + if (bodyNode == null) + return null; + return bodyNode.getNodeEndsWith(SOAP.FAULT); + } + + public Node getFaultCodeNode() + { + Node faultNode = getFaultNode(); + if (faultNode == null) + return null; + return faultNode.getNodeEndsWith(SOAP.FAULT_CODE); + } + + public Node getFaultStringNode() + { + Node faultNode = getFaultNode(); + if (faultNode == null) + return null; + return faultNode.getNodeEndsWith(SOAP.FAULT_STRING); + } + + public Node getFaultActorNode() + { + Node faultNode = getFaultNode(); + if (faultNode == null) + return null; + return faultNode.getNodeEndsWith(SOAP.FAULTACTOR); + } + + public Node getFaultDetailNode() + { + Node faultNode = getFaultNode(); + if (faultNode == null) + return null; + return faultNode.getNodeEndsWith(SOAP.DETAIL); + } + + public String getFaultCode() + { + Node node = getFaultCodeNode(); + if (node == null) + return ""; + return node.getValue(); + } + + public String getFaultString() + { + Node node = getFaultStringNode(); + if (node == null) + return ""; + return node.getValue(); + } + + public String getFaultActor() + { + Node node = getFaultActorNode(); + if (node == null) + return ""; + return node.getValue(); + } + //////////////////////////////////////////////// // XML Contents //////////////////////////////////////////////// @@ -179,7 +179,6 @@ public class SOAPResponse extends HTTPResponse // print //////////////////////////////////////////////// - @Override public void print() { Debug.message(toString()); diff --git a/router/java/src/org/cybergarage/upnp/Action.java b/router/java/src/org/cybergarage/upnp/Action.java index 84fcb33d86bed708f51c652be5990f4d7b2854c7..b58c1132a1bb67a012c6bf54c7fa1d1884a396bf 100644 --- a/router/java/src/org/cybergarage/upnp/Action.java +++ b/router/java/src/org/cybergarage/upnp/Action.java @@ -5,11 +5,11 @@ * Copyright (C) Satoshi Konno 2002-2004 * * File: Action.java -* -* Revision; -* -* 12/05/02 -* - first revision. +* +* Revision; +* +* 12/05/02 +* - first revision. * 08/30/03 * - Gordano Sassaroli <sassarol@cefriel.it> * - Problem : When invoking an action that has at least one out parameter, an error message is returned @@ -24,61 +24,61 @@ * - Changed postControlAction() to set the status code to the UPnPStatus. * ******************************************************************/ - -package org.cybergarage.upnp; + +package org.cybergarage.upnp; import org.cybergarage.xml.*; import org.cybergarage.util.*; - -import org.cybergarage.upnp.xml.*; + +import org.cybergarage.upnp.xml.*; import org.cybergarage.upnp.control.*; - -public class Action -{ - //////////////////////////////////////////////// - // Constants - //////////////////////////////////////////////// - - public final static String ELEM_NAME = "action"; - - //////////////////////////////////////////////// - // Member - //////////////////////////////////////////////// - - private Node serviceNode; - private Node actionNode; - - private Node getServiceNode() - { - return serviceNode; - } - - public Service getService() - { - return new Service(getServiceNode()); - } - - public Node getActionNode() - { - return actionNode; - } - - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public Action(Node serviceNode, Node actionNode) - { - this.serviceNode = serviceNode; - this.actionNode = actionNode; - } + +public class Action +{ + //////////////////////////////////////////////// + // Constants + //////////////////////////////////////////////// + + public final static String ELEM_NAME = "action"; + + //////////////////////////////////////////////// + // Member + //////////////////////////////////////////////// + + private Node serviceNode; + private Node actionNode; + + private Node getServiceNode() + { + return serviceNode; + } + + public Service getService() + { + return new Service(getServiceNode()); + } + + public Node getActionNode() + { + return actionNode; + } + + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public Action(Node serviceNode, Node actionNode) + { + this.serviceNode = serviceNode; + this.actionNode = actionNode; + } public Action(Action action) { this.serviceNode = action.getServiceNode(); this.actionNode = action.getActionNode(); } - + //////////////////////////////////////////////// // Mutex //////////////////////////////////////////////// @@ -95,50 +95,50 @@ public class Action mutex.unlock(); } - //////////////////////////////////////////////// - // isActionNode - //////////////////////////////////////////////// - - public static boolean isActionNode(Node node) - { - return Action.ELEM_NAME.equals(node.getName()); - } - - //////////////////////////////////////////////// - // name - //////////////////////////////////////////////// - - private final static String NAME = "name"; - - public void setName(String value) - { - getActionNode().setNode(NAME, value); - } - - public String getName() - { - return getActionNode().getNodeValue(NAME); - } - - //////////////////////////////////////////////// - // argumentList - //////////////////////////////////////////////// - - public ArgumentList getArgumentList() - { - ArgumentList argumentList = new ArgumentList(); - Node argumentListNode = getActionNode().getNode(ArgumentList.ELEM_NAME); - if (argumentListNode == null) - return argumentList; - int nodeCnt = argumentListNode.getNNodes(); - for (int n=0; n<nodeCnt; n++) { - Node node = argumentListNode.getNode(n); - if (Argument.isArgumentNode(node) == false) - continue; - Argument argument = new Argument(getServiceNode(), node); - argumentList.add(argument); - } - return argumentList; + //////////////////////////////////////////////// + // isActionNode + //////////////////////////////////////////////// + + public static boolean isActionNode(Node node) + { + return Action.ELEM_NAME.equals(node.getName()); + } + + //////////////////////////////////////////////// + // name + //////////////////////////////////////////////// + + private final static String NAME = "name"; + + public void setName(String value) + { + getActionNode().setNode(NAME, value); + } + + public String getName() + { + return getActionNode().getNodeValue(NAME); + } + + //////////////////////////////////////////////// + // argumentList + //////////////////////////////////////////////// + + public ArgumentList getArgumentList() + { + ArgumentList argumentList = new ArgumentList(); + Node argumentListNode = getActionNode().getNode(ArgumentList.ELEM_NAME); + if (argumentListNode == null) + return argumentList; + int nodeCnt = argumentListNode.getNNodes(); + for (int n=0; n<nodeCnt; n++) { + Node node = argumentListNode.getNode(n); + if (Argument.isArgumentNode(node) == false) + continue; + Argument argument = new Argument(getServiceNode(), node); + argumentList.add(argument); + } + return argumentList; } public ArgumentList getInputArgumentList() @@ -179,7 +179,7 @@ public class Action if (argName == null) continue; if (name.equals(argName) == true) - return arg; + return arg; } return null; } @@ -272,8 +272,8 @@ public class Action actionRes.setResponse(this); } else { - UPnPStatus _upnpStatus = getStatus(); - actionRes.setFaultResponse(_upnpStatus.getCode(), _upnpStatus.getDescription()); + UPnPStatus upnpStatus = getStatus(); + actionRes.setFaultResponse(upnpStatus.getCode(), upnpStatus.getDescription()); } if (Debug.isOn() == true) actionRes.print(); diff --git a/router/java/src/org/cybergarage/upnp/ControlPoint.java b/router/java/src/org/cybergarage/upnp/ControlPoint.java index b2def6408241633550652cec51795679efbf5b8a..d66209f974fe6382fd357f2f0be0a09fee041c9e 100644 --- a/router/java/src/org/cybergarage/upnp/ControlPoint.java +++ b/router/java/src/org/cybergarage/upnp/ControlPoint.java @@ -5,11 +5,11 @@ * Copyright (C) Satoshi Konno 2002-2004 * * File: ControlPoint.java -* -* Revision: -* -* 11/18/02 -* - first revision. +* +* Revision: +* +* 11/18/02 +* - first revision. * 05/13/03 * - Changed to create socket threads each local interfaces. * (HTTP, SSDPNotiry, SSDPSerachResponse) @@ -56,35 +56,35 @@ * - Changed addDevice() to use Parser::parse(URL). * *******************************************************************/ - -package org.cybergarage.upnp; - + +package org.cybergarage.upnp; + import org.cybergarage.net.*; import org.cybergarage.util.*; import org.cybergarage.xml.*; import org.cybergarage.http.*; import org.cybergarage.upnp.control.*; -import org.cybergarage.upnp.ssdp.*; +import org.cybergarage.upnp.ssdp.*; import org.cybergarage.upnp.device.*; -import org.cybergarage.upnp.event.*; +import org.cybergarage.upnp.event.*; import java.net.*; - -public class ControlPoint implements HTTPRequestListener -{ + +public class ControlPoint implements HTTPRequestListener +{ private final static int DEFAULT_EVENTSUB_PORT = 8058; private final static int DEFAULT_SSDP_PORT = 8008; private final static int DEFAULT_EXPIRED_DEVICE_MONITORING_INTERVAL = 60; private final static String DEFAULT_EVENTSUB_URI = "/evetSub"; - //////////////////////////////////////////////// - // Member - //////////////////////////////////////////////// - - private SSDPNotifySocketList ssdpNotifySocketList; - private SSDPSearchResponseSocketList ssdpSearchResponseSocketList; + //////////////////////////////////////////////// + // Member + //////////////////////////////////////////////// + + private SSDPNotifySocketList ssdpNotifySocketList; + private SSDPSearchResponseSocketList ssdpSearchResponseSocketList; private SSDPNotifySocketList getSSDPNotifySocketList() { @@ -105,12 +105,12 @@ public class ControlPoint implements HTTPRequestListener UPnP.initialize(); } - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public ControlPoint(int ssdpPort, int httpPort) - { + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public ControlPoint(int ssdpPort, int httpPort) + { ssdpNotifySocketList = new SSDPNotifySocketList(); ssdpSearchResponseSocketList = new SSDPSearchResponseSocketList(); @@ -124,14 +124,13 @@ public class ControlPoint implements HTTPRequestListener setNMPRMode(false); setRenewSubscriber(null); - } + } public ControlPoint() { this(DEFAULT_SSDP_PORT, DEFAULT_EVENTSUB_PORT); } - @Override public void finalize() { stop(); @@ -180,7 +179,7 @@ public class ControlPoint implements HTTPRequestListener public void setHTTPPort(int port) { httpPort = port; } - + //////////////////////////////////////////////// // NMPR //////////////////////////////////////////////// @@ -197,35 +196,35 @@ public class ControlPoint implements HTTPRequestListener return nmprMode; } - //////////////////////////////////////////////// - // Device List - //////////////////////////////////////////////// - - private NodeList devNodeList = new NodeList(); - - private void addDevice(Node rootNode) - { - devNodeList.add(rootNode); - } - - private synchronized void addDevice(SSDPPacket ssdpPacket) + //////////////////////////////////////////////// + // Device List + //////////////////////////////////////////////// + + private NodeList devNodeList = new NodeList(); + + private void addDevice(Node rootNode) + { + devNodeList.add(rootNode); + } + + private synchronized void addDevice(SSDPPacket ssdpPacket) { if (ssdpPacket.isRootDevice() == false) return; - String usn = ssdpPacket.getUSN(); - String udn = USN.getUDN(usn); - Device dev = getDevice(udn); + String usn = ssdpPacket.getUSN(); + String udn = USN.getUDN(usn); + Device dev = getDevice(udn); if (dev != null) { dev.setSSDPPacket(ssdpPacket); - return; + return; } - String location = ssdpPacket.getLocation(); - try { + String location = ssdpPacket.getLocation(); + try { URL locationUrl = new URL(location); Parser parser = UPnP.getXMLParser(); - Node rootNode = parser.parse(locationUrl); + Node rootNode = parser.parse(locationUrl); Device rootDev = getDevice(rootNode); if (rootDev == null) return; @@ -238,16 +237,16 @@ public class ControlPoint implements HTTPRequestListener // control point application must implement the DeviceChangeListener interface // to receive the notifications) performAddDeviceListener( rootDev ); - } + } catch (MalformedURLException me) { Debug.warning(ssdpPacket.toString()); Debug.warning(me); } - catch (ParserException pe) { + catch (ParserException pe) { Debug.warning(ssdpPacket.toString()); - Debug.warning(pe); - } - } + Debug.warning(pe); + } + } private Device getDevice(Node rootNode) { @@ -258,30 +257,30 @@ public class ControlPoint implements HTTPRequestListener return null; return new Device(rootNode, devNode); } - - public DeviceList getDeviceList() - { - DeviceList devList = new DeviceList(); - int nRoots = devNodeList.size(); - for (int n=0; n<nRoots; n++) { + + public DeviceList getDeviceList() + { + DeviceList devList = new DeviceList(); + int nRoots = devNodeList.size(); + for (int n=0; n<nRoots; n++) { Node rootNode = devNodeList.getNode(n); Device dev = getDevice(rootNode); - if (dev == null) - continue; - devList.add(dev); - } - return devList; - } - - public Device getDevice(String name) - { - int nRoots = devNodeList.size(); - for (int n=0; n<nRoots; n++) { + if (dev == null) + continue; + devList.add(dev); + } + return devList; + } + + public Device getDevice(String name) + { + int nRoots = devNodeList.size(); + for (int n=0; n<nRoots; n++) { // AIOOB was thrown from here, maybe would be better to // copy the list before traversal? Node rootNode; try { - rootNode = devNodeList.getNode(n); + rootNode = devNodeList.getNode(n); } catch (ArrayIndexOutOfBoundsException aioob) { break; } @@ -292,18 +291,18 @@ public class ControlPoint implements HTTPRequestListener return dev; Device cdev = dev.getDevice(name); if (cdev != null) - return cdev; - } - return null; - } - - public boolean hasDevice(String name) - { - return (getDevice(name) != null) ? true : false; - } - - private void removeDevice(Node rootNode) - { + return cdev; + } + return null; + } + + public boolean hasDevice(String name) + { + return (getDevice(name) != null) ? true : false; + } + + private void removeDevice(Node rootNode) + { // Thanks for Oliver Newell (2004/10/16) // Invoke device removal listener prior to actual removal so Device node // remains valid for the duration of the listener (application may want @@ -312,9 +311,9 @@ public class ControlPoint implements HTTPRequestListener if( dev != null && dev.isRootDevice() ) performRemoveDeviceListener( dev ); - devNodeList.remove(rootNode); - } - + devNodeList.remove(rootNode); + } + private void removeDevice(Device dev) { if (dev == null) @@ -322,19 +321,19 @@ public class ControlPoint implements HTTPRequestListener removeDevice(dev.getRootNode()); } - private void removeDevice(String name) - { - Device dev = getDevice(name); - removeDevice(dev); - } - - private void removeDevice(SSDPPacket packet) - { - if (packet.isByeBye() == false) - return; - String usn = packet.getUSN(); - String udn = USN.getUDN(usn); - removeDevice(udn); + private void removeDevice(String name) + { + Device dev = getDevice(name); + removeDevice(dev); + } + + private void removeDevice(SSDPPacket packet) + { + if (packet.isByeBye() == false) + return; + String usn = packet.getUSN(); + String udn = USN.getUDN(usn); + removeDevice(udn); } //////////////////////////////////////////////// @@ -361,7 +360,7 @@ public class ControlPoint implements HTTPRequestListener public void setExpiredDeviceMonitoringInterval(long interval) { - expiredDeviceMonitoringInterval = interval; + expiredDeviceMonitoringInterval = interval; } public long getExpiredDeviceMonitoringInterval() @@ -379,9 +378,9 @@ public class ControlPoint implements HTTPRequestListener return deviceDisposer; } - //////////////////////////////////////////////// + //////////////////////////////////////////////// // Notify - //////////////////////////////////////////////// + //////////////////////////////////////////////// private ListenerList deviceNotifyListenerList = new ListenerList(); @@ -403,7 +402,7 @@ public class ControlPoint implements HTTPRequestListener listener.deviceNotifyReceived(ssdpPacket); } } - + //////////////////////////////////////////////// // SearchResponse //////////////////////////////////////////////// @@ -487,12 +486,12 @@ public class ControlPoint implements HTTPRequestListener addDevice(packet); performSearchResponseListener(packet); } + + //////////////////////////////////////////////// + // M-SEARCH + //////////////////////////////////////////////// - //////////////////////////////////////////////// - // M-SEARCH - //////////////////////////////////////////////// - - private int searchMx = SSDP.DEFAULT_MSEARCH_MX; + private int searchMx = SSDP.DEFAULT_MSEARCH_MX; public int getSearchMx() { @@ -507,8 +506,8 @@ public class ControlPoint implements HTTPRequestListener public void search(String target, int mx) { SSDPSearchRequest msReq = new SSDPSearchRequest(target, mx); - SSDPSearchResponseSocketList _ssdpSearchResponseSocketList = getSSDPSearchResponseSocketList(); - _ssdpSearchResponseSocketList.post(msReq); + SSDPSearchResponseSocketList ssdpSearchResponseSocketList = getSSDPSearchResponseSocketList(); + ssdpSearchResponseSocketList.post(msReq); } public void search(String target) @@ -719,7 +718,7 @@ public class ControlPoint implements HTTPRequestListener } return null; } - + //////////////////////////////////////////////// // getSubscriberService //////////////////////////////////////////////// @@ -777,11 +776,11 @@ public class ControlPoint implements HTTPRequestListener return renewSubscriber; } - //////////////////////////////////////////////// - // run - //////////////////////////////////////////////// - - public boolean start(String target, int mx) + //////////////////////////////////////////////// + // run + //////////////////////////////////////////////// + + public boolean start(String target, int mx) { stop(); @@ -791,8 +790,8 @@ public class ControlPoint implements HTTPRequestListener int retryCnt = 0; int bindPort = getHTTPPort(); - HTTPServerList _httpServerList = getHTTPServerList(); - while (_httpServerList.open(bindPort) == false) { + HTTPServerList httpServerList = getHTTPServerList(); + while (httpServerList.open(bindPort) == false) { retryCnt++; if (UPnP.SERVER_RETRY_COUNT < retryCnt) { Debug.warning("Failed to open HTTP event listener port " + bindPort); @@ -803,40 +802,40 @@ public class ControlPoint implements HTTPRequestListener setHTTPPort(bindPort - 1); bindPort = getHTTPPort(); } - _httpServerList.addRequestListener(this); - _httpServerList.start(); + httpServerList.addRequestListener(this); + httpServerList.start(); //////////////////////////////////////// // Notify Socket //////////////////////////////////////// - SSDPNotifySocketList _ssdpNotifySocketList = getSSDPNotifySocketList(); - if (_ssdpNotifySocketList.open() == false) { + SSDPNotifySocketList ssdpNotifySocketList = getSSDPNotifySocketList(); + if (ssdpNotifySocketList.open() == false) { Debug.warning("Failed to open SSDP notify port 1900"); return false; } - _ssdpNotifySocketList.setControlPoint(this); - _ssdpNotifySocketList.start(); - + ssdpNotifySocketList.setControlPoint(this); + ssdpNotifySocketList.start(); + //////////////////////////////////////// // SeachResponse Socket //////////////////////////////////////// - int _ssdpPort = getSSDPPort(); + int ssdpPort = getSSDPPort(); retryCnt = 0; - SSDPSearchResponseSocketList _ssdpSearchResponseSocketList = getSSDPSearchResponseSocketList(); - while (_ssdpSearchResponseSocketList.open(_ssdpPort) == false) { + SSDPSearchResponseSocketList ssdpSearchResponseSocketList = getSSDPSearchResponseSocketList(); + while (ssdpSearchResponseSocketList.open(ssdpPort) == false) { retryCnt++; if (UPnP.SERVER_RETRY_COUNT < retryCnt) { - Debug.warning("Failed to open SSDP search response port " + _ssdpPort); + Debug.warning("Failed to open SSDP search response port " + ssdpPort); return false; } // I2P go down not up so we don't run into other I2P things - setSSDPPort(_ssdpPort - 1); - _ssdpPort = getSSDPPort(); + setSSDPPort(ssdpPort - 1); + ssdpPort = getSSDPPort(); } - _ssdpSearchResponseSocketList.setControlPoint(this); - _ssdpSearchResponseSocketList.start(); + ssdpSearchResponseSocketList.setControlPoint(this); + ssdpSearchResponseSocketList.start(); //////////////////////////////////////// // search root devices @@ -862,9 +861,9 @@ public class ControlPoint implements HTTPRequestListener renewSub.start(); } - return true; - } - + return true; + } + public boolean start(String target) { return start(target, SSDP.DEFAULT_MSEARCH_MX); @@ -875,24 +874,24 @@ public class ControlPoint implements HTTPRequestListener return start(ST.ROOT_DEVICE, SSDP.DEFAULT_MSEARCH_MX); } - public boolean stop() + public boolean stop() { unsubscribe(); + + SSDPNotifySocketList ssdpNotifySocketList = getSSDPNotifySocketList(); + ssdpNotifySocketList.stop(); + ssdpNotifySocketList.close(); + ssdpNotifySocketList.clear(); - SSDPNotifySocketList _ssdpNotifySocketList = getSSDPNotifySocketList(); - _ssdpNotifySocketList.stop(); - _ssdpNotifySocketList.close(); - _ssdpNotifySocketList.clear(); - - SSDPSearchResponseSocketList _ssdpSearchResponseSocketList = getSSDPSearchResponseSocketList(); - _ssdpSearchResponseSocketList.stop(); - _ssdpSearchResponseSocketList.close(); - _ssdpSearchResponseSocketList.clear(); - - HTTPServerList _httpServerList = getHTTPServerList(); - _httpServerList.stop(); - _httpServerList.close(); - _httpServerList.clear(); + SSDPSearchResponseSocketList ssdpSearchResponseSocketList = getSSDPSearchResponseSocketList(); + ssdpSearchResponseSocketList.stop(); + ssdpSearchResponseSocketList.close(); + ssdpSearchResponseSocketList.clear(); + + HTTPServerList httpServerList = getHTTPServerList(); + httpServerList.stop(); + httpServerList.close(); + httpServerList.clear(); //////////////////////////////////////// // Disposer @@ -914,8 +913,8 @@ public class ControlPoint implements HTTPRequestListener setRenewSubscriber(null); } - return true; - } + return true; + } //////////////////////////////////////////////// // print diff --git a/router/java/src/org/cybergarage/upnp/Device.java b/router/java/src/org/cybergarage/upnp/Device.java index ea4923a34fda62cd2aa0c0a111a36820732c7d7c..9dd9c15f30a9418bfb6a030cd61553b977d8d2d3 100644 --- a/router/java/src/org/cybergarage/upnp/Device.java +++ b/router/java/src/org/cybergarage/upnp/Device.java @@ -5,11 +5,11 @@ * Copyright (C) Satoshi Konno 2002-2004 * * File: Device.java -* -* Revision: -* -* 11/28/02 -* - first revision. +* +* Revision: +* +* 11/28/02 +* - first revision. * 02/26/03 * - URLBase is updated automatically. * - Description of a root device is returned from the XML node tree. @@ -84,62 +84,62 @@ * - Added a new setActionListener() and serQueryListner() to include the sub devices. * ******************************************************************/ - -package org.cybergarage.upnp; - -import java.net.*; -import java.io.*; -import java.util.*; + +package org.cybergarage.upnp; + +import java.net.*; +import java.io.*; +import java.util.*; import org.cybergarage.net.*; import org.cybergarage.http.*; import org.cybergarage.util.*; import org.cybergarage.xml.*; import org.cybergarage.soap.*; - -import org.cybergarage.upnp.ssdp.*; -import org.cybergarage.upnp.device.*; + +import org.cybergarage.upnp.ssdp.*; +import org.cybergarage.upnp.device.*; import org.cybergarage.upnp.control.*; import org.cybergarage.upnp.event.*; -import org.cybergarage.upnp.xml.*; - -public class Device implements org.cybergarage.http.HTTPRequestListener, SearchListener -{ - //////////////////////////////////////////////// - // Constants - //////////////////////////////////////////////// - - public final static String ELEM_NAME = "device"; +import org.cybergarage.upnp.xml.*; + +public class Device implements org.cybergarage.http.HTTPRequestListener, SearchListener +{ + //////////////////////////////////////////////// + // Constants + //////////////////////////////////////////////// + + public final static String ELEM_NAME = "device"; public final static String UPNP_ROOTDEVICE = "upnp:rootdevice"; - + public final static int DEFAULT_STARTUP_WAIT_TIME = 1000; public final static int DEFAULT_DISCOVERY_WAIT_TIME = 300; - public final static int DEFAULT_LEASE_TIME = 30 * 60; + public final static int DEFAULT_LEASE_TIME = 30 * 60; public final static int HTTP_DEFAULT_PORT = 4004; public final static String DEFAULT_DESCRIPTION_URI = "/description.xml"; - //////////////////////////////////////////////// - // Member - //////////////////////////////////////////////// - - private Node rootNode; - private Node deviceNode; - - public Node getRootNode() - { + //////////////////////////////////////////////// + // Member + //////////////////////////////////////////////// + + private Node rootNode; + private Node deviceNode; + + public Node getRootNode() + { if (rootNode != null) return rootNode; if (deviceNode == null) return null; - return deviceNode.getRootNode(); - } - - public Node getDeviceNode() - { - return deviceNode; - } + return deviceNode.getRootNode(); + } + + public Node getDeviceNode() + { + return deviceNode; + } public void setRootNode(Node node) { @@ -150,7 +150,7 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL { deviceNode = node; } - + //////////////////////////////////////////////// // Initialize //////////////////////////////////////////////// @@ -160,33 +160,33 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL UPnP.initialize(); } - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public Device(Node root, Node device) - { - rootNode = root; + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public Device(Node root, Node device) + { + rootNode = root; deviceNode = device; setUUID(UPnP.createUUID()); setWirelessMode(false); - } - - public Device() - { - this(null, null); - } - - public Device(Node device) - { - this(null, device); - } - - public Device(File descriptionFile) throws InvalidDescriptionException - { - this(null, null); - loadDescription(descriptionFile); - } + } + + public Device() + { + this(null, null); + } + + public Device(Node device) + { + this(null, device); + } + + public Device(File descriptionFile) throws InvalidDescriptionException + { + this(null, null); + loadDescription(descriptionFile); + } public Device(String descriptionFileName) throws InvalidDescriptionException { @@ -285,13 +285,13 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL public Device getRootDevice() { - Node _rootNode = getRootNode(); - if (_rootNode == null) + Node rootNode = getRootNode(); + if (rootNode == null) return null; - Node devNode = _rootNode.getNode(Device.ELEM_NAME); + Node devNode = rootNode.getNode(Device.ELEM_NAME); if (devNode == null) return null; - return new Device(_rootNode, devNode); + return new Device(rootNode, devNode); } //////////////////////////////////////////////// @@ -326,46 +326,46 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL return userData; } - //////////////////////////////////////////////// - // Description - //////////////////////////////////////////////// + //////////////////////////////////////////////// + // Description + //////////////////////////////////////////////// private void setDescriptionFile(File file) { getDeviceData().setDescriptionFile(file); } - - public File getDescriptionFile() - { - return getDeviceData().getDescriptionFile(); - } - - private void setDescriptionURI(String uri) - { - getDeviceData().setDescriptionURI(uri); - } - - private String getDescriptionURI() - { - return getDeviceData().getDescriptionURI(); - } - - private boolean isDescriptionURI(String uri) - { - String descriptionURI = getDescriptionURI(); - if (uri == null || descriptionURI == null) - return false; - return descriptionURI.equals(uri); - } - - public String getDescriptionFilePath() - { - File descriptionFile = getDescriptionFile(); - if (descriptionFile == null) - return ""; - return descriptionFile.getAbsoluteFile().getParent(); - } - + + public File getDescriptionFile() + { + return getDeviceData().getDescriptionFile(); + } + + private void setDescriptionURI(String uri) + { + getDeviceData().setDescriptionURI(uri); + } + + private String getDescriptionURI() + { + return getDeviceData().getDescriptionURI(); + } + + private boolean isDescriptionURI(String uri) + { + String descriptionURI = getDescriptionURI(); + if (uri == null || descriptionURI == null) + return false; + return descriptionURI.equals(uri); + } + + public String getDescriptionFilePath() + { + File descriptionFile = getDescriptionFile(); + if (descriptionFile == null) + return ""; + return descriptionFile.getAbsoluteFile().getParent(); + } + public boolean loadDescription(String descString) throws InvalidDescriptionException { try { @@ -389,28 +389,28 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL return true; } - public boolean loadDescription(File file) throws InvalidDescriptionException - { - try { + public boolean loadDescription(File file) throws InvalidDescriptionException + { + try { Parser parser = UPnP.getXMLParser(); - rootNode = parser.parse(file); - if (rootNode == null) - throw new InvalidDescriptionException(Description.NOROOT_EXCEPTION, file); - deviceNode = rootNode.getNode(Device.ELEM_NAME); - if (deviceNode == null) - throw new InvalidDescriptionException(Description.NOROOTDEVICE_EXCEPTION, file); - } - catch (ParserException e) { - throw new InvalidDescriptionException(e); - } + rootNode = parser.parse(file); + if (rootNode == null) + throw new InvalidDescriptionException(Description.NOROOT_EXCEPTION, file); + deviceNode = rootNode.getNode(Device.ELEM_NAME); + if (deviceNode == null) + throw new InvalidDescriptionException(Description.NOROOTDEVICE_EXCEPTION, file); + } + catch (ParserException e) { + throw new InvalidDescriptionException(e); + } if (initializeLoadedDescription() == false) - return false; + return false; setDescriptionFile(file); - - return true; - } + + return true; + } private boolean initializeLoadedDescription() { @@ -425,95 +425,95 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL return true; } - //////////////////////////////////////////////// - // isDeviceNode - //////////////////////////////////////////////// - - public static boolean isDeviceNode(Node node) - { - return Device.ELEM_NAME.equals(node.getName()); + //////////////////////////////////////////////// + // isDeviceNode + //////////////////////////////////////////////// + + public static boolean isDeviceNode(Node node) + { + return Device.ELEM_NAME.equals(node.getName()); + } + + //////////////////////////////////////////////// + // Root Device + //////////////////////////////////////////////// + + public boolean isRootDevice() + { + return (getRootNode() != null) ? true : false; } - //////////////////////////////////////////////// - // Root Device - //////////////////////////////////////////////// - - public boolean isRootDevice() - { - return (getRootNode() != null) ? true : false; - } - - //////////////////////////////////////////////// - // Root Device - //////////////////////////////////////////////// + //////////////////////////////////////////////// + // Root Device + //////////////////////////////////////////////// public void setSSDPPacket(SSDPPacket packet) { getDeviceData().setSSDPPacket(packet); } - public SSDPPacket getSSDPPacket() - { - if (isRootDevice() == false) + public SSDPPacket getSSDPPacket() + { + if (isRootDevice() == false) return null; return getDeviceData().getSSDPPacket(); - } - - //////////////////////////////////////////////// - // Location - //////////////////////////////////////////////// - - public void setLocation(String value) - { - getDeviceData().setLocation(value); - } - - public String getLocation() - { - SSDPPacket packet = getSSDPPacket(); - if (packet != null) - return packet.getLocation(); - return getDeviceData().getLocation(); - } - - //////////////////////////////////////////////// - // LeaseTime - //////////////////////////////////////////////// - - public void setLeaseTime(int value) - { + } + + //////////////////////////////////////////////// + // Location + //////////////////////////////////////////////// + + public void setLocation(String value) + { + getDeviceData().setLocation(value); + } + + public String getLocation() + { + SSDPPacket packet = getSSDPPacket(); + if (packet != null) + return packet.getLocation(); + return getDeviceData().getLocation(); + } + + //////////////////////////////////////////////// + // LeaseTime + //////////////////////////////////////////////// + + public void setLeaseTime(int value) + { getDeviceData().setLeaseTime(value); Advertiser adv = getAdvertiser(); if (adv != null) { announce(); adv.restart(); } - } - - public int getLeaseTime() - { - SSDPPacket packet = getSSDPPacket(); - if (packet != null) - return packet.getLeaseTime(); - return getDeviceData().getLeaseTime(); - } - - //////////////////////////////////////////////// - // TimeStamp - //////////////////////////////////////////////// - - public long getTimeStamp() - { - SSDPPacket packet = getSSDPPacket(); - if (packet != null) - return packet.getTimeStamp(); - return 0; - } - - public long getElapsedTime() - { - return (System.currentTimeMillis() - getTimeStamp()) / 1000; - } + } + + public int getLeaseTime() + { + SSDPPacket packet = getSSDPPacket(); + if (packet != null) + return packet.getLeaseTime(); + return getDeviceData().getLeaseTime(); + } + + //////////////////////////////////////////////// + // TimeStamp + //////////////////////////////////////////////// + + public long getTimeStamp() + { + SSDPPacket packet = getSSDPPacket(); + if (packet != null) + return packet.getTimeStamp(); + return 0; + } + + public long getElapsedTime() + { + return (System.currentTimeMillis() - getTimeStamp()) / 1000; + } public boolean isExpired() { @@ -523,15 +523,15 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL return true; return false; } - - //////////////////////////////////////////////// - // URL Base - //////////////////////////////////////////////// - - private final static String URLBASE_NAME = "URLBase"; - - private void setURLBase(String value) - { + + //////////////////////////////////////////////// + // URL Base + //////////////////////////////////////////////// + + private final static String URLBASE_NAME = "URLBase"; + + private void setURLBase(String value) + { if (isRootDevice() == true) { Node node = getRootNode().getNode(URLBASE_NAME); if (node != null) { @@ -544,37 +544,37 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL if (getRootNode().hasNodes() == false) index = 1; getRootNode().insertNode(node, index); - } - } - + } + } + private void updateURLBase(String host) { String urlBase = HostInterface.getHostURL(host, getHTTPPort(), ""); setURLBase(urlBase); } - public String getURLBase() - { - if (isRootDevice() == true) - return getRootNode().getNodeValue(URLBASE_NAME); - return ""; - } - - //////////////////////////////////////////////// - // deviceType - //////////////////////////////////////////////// - - private final static String DEVICE_TYPE = "deviceType"; - - public void setDeviceType(String value) - { - getDeviceNode().setNode(DEVICE_TYPE, value); - } - - public String getDeviceType() - { - return getDeviceNode().getNodeValue(DEVICE_TYPE); - } + public String getURLBase() + { + if (isRootDevice() == true) + return getRootNode().getNodeValue(URLBASE_NAME); + return ""; + } + + //////////////////////////////////////////////// + // deviceType + //////////////////////////////////////////////// + + private final static String DEVICE_TYPE = "deviceType"; + + public void setDeviceType(String value) + { + getDeviceNode().setNode(DEVICE_TYPE, value); + } + + public String getDeviceType() + { + return getDeviceNode().getNodeValue(DEVICE_TYPE); + } public boolean isDeviceType(String value) { @@ -582,211 +582,211 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL return false; return value.equals(getDeviceType()); } - - //////////////////////////////////////////////// - // friendlyName - //////////////////////////////////////////////// - - private final static String FRIENDLY_NAME = "friendlyName"; - - public void setFriendlyName(String value) - { - getDeviceNode().setNode(FRIENDLY_NAME, value); - } - - public String getFriendlyName() - { - return getDeviceNode().getNodeValue(FRIENDLY_NAME); - } - - //////////////////////////////////////////////// - // manufacture - //////////////////////////////////////////////// - - private final static String MANUFACTURE = "manufacture"; - - public void setManufacture(String value) - { - getDeviceNode().setNode(MANUFACTURE, value); - } - - public String getManufacture() - { - return getDeviceNode().getNodeValue(MANUFACTURE); - } - - //////////////////////////////////////////////// - // manufactureURL - //////////////////////////////////////////////// - - private final static String MANUFACTURE_URL = "manufactureURL"; - - public void setManufactureURL(String value) - { - getDeviceNode().setNode(MANUFACTURE_URL, value); - } - - public String getManufactureURL() - { - return getDeviceNode().getNodeValue(MANUFACTURE_URL); - } - - //////////////////////////////////////////////// - // modelDescription - //////////////////////////////////////////////// - - private final static String MODEL_DESCRIPTION = "modelDescription"; - - public void setModelDescription(String value) - { - getDeviceNode().setNode(MODEL_DESCRIPTION, value); - } - - public String getModelDescription() - { - return getDeviceNode().getNodeValue(MODEL_DESCRIPTION); - } - - //////////////////////////////////////////////// - // modelName - //////////////////////////////////////////////// - - private final static String MODEL_NAME = "modelName"; - - public void setModelName(String value) - { - getDeviceNode().setNode(MODEL_NAME, value); - } - - public String getModelName() - { - return getDeviceNode().getNodeValue(MODEL_NAME); - } - - //////////////////////////////////////////////// - // modelNumber - //////////////////////////////////////////////// - - private final static String MODEL_NUMBER = "modelNumber"; - - public void setModelNumber(String value) - { - getDeviceNode().setNode(MODEL_NUMBER, value); - } - - public String getModelNumber() - { - return getDeviceNode().getNodeValue(MODEL_NUMBER); - } - - //////////////////////////////////////////////// - // modelURL - //////////////////////////////////////////////// - - private final static String MODEL_URL = "modelURL"; - - public void setModelURL(String value) - { - getDeviceNode().setNode(MODEL_URL, value); - } - - public String getModelURL() - { - return getDeviceNode().getNodeValue(MODEL_URL); - } - - //////////////////////////////////////////////// - // serialNumber - //////////////////////////////////////////////// - - private final static String SERIAL_NUMBER = "serialNumber"; - - public void setSerialNumber(String value) - { - getDeviceNode().setNode(SERIAL_NUMBER, value); - } - - public String getSerialNumber() - { - return getDeviceNode().getNodeValue(SERIAL_NUMBER); - } - - //////////////////////////////////////////////// - // UDN - //////////////////////////////////////////////// - - private final static String UDN = "UDN"; - - public void setUDN(String value) - { - getDeviceNode().setNode(UDN, value); - } - - public String getUDN() - { - return getDeviceNode().getNodeValue(UDN); - } + + //////////////////////////////////////////////// + // friendlyName + //////////////////////////////////////////////// + + private final static String FRIENDLY_NAME = "friendlyName"; + + public void setFriendlyName(String value) + { + getDeviceNode().setNode(FRIENDLY_NAME, value); + } + + public String getFriendlyName() + { + return getDeviceNode().getNodeValue(FRIENDLY_NAME); + } + + //////////////////////////////////////////////// + // manufacture + //////////////////////////////////////////////// + + private final static String MANUFACTURE = "manufacture"; + + public void setManufacture(String value) + { + getDeviceNode().setNode(MANUFACTURE, value); + } + + public String getManufacture() + { + return getDeviceNode().getNodeValue(MANUFACTURE); + } + + //////////////////////////////////////////////// + // manufactureURL + //////////////////////////////////////////////// + + private final static String MANUFACTURE_URL = "manufactureURL"; + + public void setManufactureURL(String value) + { + getDeviceNode().setNode(MANUFACTURE_URL, value); + } + + public String getManufactureURL() + { + return getDeviceNode().getNodeValue(MANUFACTURE_URL); + } + + //////////////////////////////////////////////// + // modelDescription + //////////////////////////////////////////////// + + private final static String MODEL_DESCRIPTION = "modelDescription"; + + public void setModelDescription(String value) + { + getDeviceNode().setNode(MODEL_DESCRIPTION, value); + } + + public String getModelDescription() + { + return getDeviceNode().getNodeValue(MODEL_DESCRIPTION); + } + + //////////////////////////////////////////////// + // modelName + //////////////////////////////////////////////// + + private final static String MODEL_NAME = "modelName"; + + public void setModelName(String value) + { + getDeviceNode().setNode(MODEL_NAME, value); + } + + public String getModelName() + { + return getDeviceNode().getNodeValue(MODEL_NAME); + } + + //////////////////////////////////////////////// + // modelNumber + //////////////////////////////////////////////// + + private final static String MODEL_NUMBER = "modelNumber"; + + public void setModelNumber(String value) + { + getDeviceNode().setNode(MODEL_NUMBER, value); + } + + public String getModelNumber() + { + return getDeviceNode().getNodeValue(MODEL_NUMBER); + } + + //////////////////////////////////////////////// + // modelURL + //////////////////////////////////////////////// + + private final static String MODEL_URL = "modelURL"; + + public void setModelURL(String value) + { + getDeviceNode().setNode(MODEL_URL, value); + } + + public String getModelURL() + { + return getDeviceNode().getNodeValue(MODEL_URL); + } + + //////////////////////////////////////////////// + // serialNumber + //////////////////////////////////////////////// + + private final static String SERIAL_NUMBER = "serialNumber"; + + public void setSerialNumber(String value) + { + getDeviceNode().setNode(SERIAL_NUMBER, value); + } + + public String getSerialNumber() + { + return getDeviceNode().getNodeValue(SERIAL_NUMBER); + } + + //////////////////////////////////////////////// + // UDN + //////////////////////////////////////////////// + + private final static String UDN = "UDN"; + + public void setUDN(String value) + { + getDeviceNode().setNode(UDN, value); + } + + public String getUDN() + { + return getDeviceNode().getNodeValue(UDN); + } public boolean hasUDN() { String udn = getUDN(); if (udn == null || udn.length() <= 0) return false; - return true; - } - - //////////////////////////////////////////////// - // UPC - //////////////////////////////////////////////// - - private final static String UPC = "UPC"; - - public void setUPC(String value) - { - getDeviceNode().setNode(UPC, value); - } - - public String getUPC() - { - return getDeviceNode().getNodeValue(UPC); + return true; } - - //////////////////////////////////////////////// - // presentationURL - //////////////////////////////////////////////// - - private final static String presentationURL = "presentationURL"; - public void setPresentationURL(String value) - { - getDeviceNode().setNode(presentationURL, value); - } - - public String getPresentationURL() - { - return getDeviceNode().getNodeValue(presentationURL); - } - - //////////////////////////////////////////////// - // deviceList - //////////////////////////////////////////////// - - public DeviceList getDeviceList() - { - DeviceList devList = new DeviceList(); - Node devListNode = getDeviceNode().getNode(DeviceList.ELEM_NAME); - if (devListNode == null) - return devList; - int nNode = devListNode.getNNodes(); - for (int n=0; n<nNode; n++) { - Node node = devListNode.getNode(n); - if (Device.isDeviceNode(node) == false) - continue; - Device dev = new Device(node); - devList.add(dev); - } - return devList; - } + //////////////////////////////////////////////// + // UPC + //////////////////////////////////////////////// + + private final static String UPC = "UPC"; + + public void setUPC(String value) + { + getDeviceNode().setNode(UPC, value); + } + + public String getUPC() + { + return getDeviceNode().getNodeValue(UPC); + } + + //////////////////////////////////////////////// + // presentationURL + //////////////////////////////////////////////// + + private final static String presentationURL = "presentationURL"; + + public void setPresentationURL(String value) + { + getDeviceNode().setNode(presentationURL, value); + } + + public String getPresentationURL() + { + return getDeviceNode().getNodeValue(presentationURL); + } + + //////////////////////////////////////////////// + // deviceList + //////////////////////////////////////////////// + + public DeviceList getDeviceList() + { + DeviceList devList = new DeviceList(); + Node devListNode = getDeviceNode().getNode(DeviceList.ELEM_NAME); + if (devListNode == null) + return devList; + int nNode = devListNode.getNNodes(); + for (int n=0; n<nNode; n++) { + Node node = devListNode.getNode(n); + if (Device.isDeviceNode(node) == false) + continue; + Device dev = new Device(node); + devList.add(dev); + } + return devList; + } public boolean isDevice(String name) { @@ -831,26 +831,26 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL return null; } - //////////////////////////////////////////////// - // serviceList - //////////////////////////////////////////////// - - public ServiceList getServiceList() - { - ServiceList serviceList = new ServiceList(); - Node serviceListNode = getDeviceNode().getNode(ServiceList.ELEM_NAME); - if (serviceListNode == null) - return serviceList; - int nNode = serviceListNode.getNNodes(); - for (int n=0; n<nNode; n++) { - Node node = serviceListNode.getNode(n); - if (Service.isServiceNode(node) == false) - continue; - Service service = new Service(node); - serviceList.add(service); - } - return serviceList; - } + //////////////////////////////////////////////// + // serviceList + //////////////////////////////////////////////// + + public ServiceList getServiceList() + { + ServiceList serviceList = new ServiceList(); + Node serviceListNode = getDeviceNode().getNode(ServiceList.ELEM_NAME); + if (serviceListNode == null) + return serviceList; + int nNode = serviceListNode.getNNodes(); + for (int n=0; n<nNode; n++) { + Node node = serviceListNode.getNode(n); + if (Service.isServiceNode(node) == false) + continue; + Service service = new Service(node); + serviceList.add(service); + } + return serviceList; + } public Service getService(String name) { @@ -1037,25 +1037,25 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL return null; } - //////////////////////////////////////////////// - // iconList - //////////////////////////////////////////////// - - public IconList getIconList() - { - IconList iconList = new IconList(); - Node iconListNode = getDeviceNode().getNode(IconList.ELEM_NAME); - if (iconListNode == null) - return iconList; - int nNode = iconListNode.getNNodes(); - for (int n=0; n<nNode; n++) { - Node node = iconListNode.getNode(n); - if (Icon.isIconNode(node) == false) - continue; - Icon icon = new Icon(node); - iconList.add(icon); - } - return iconList; + //////////////////////////////////////////////// + // iconList + //////////////////////////////////////////////// + + public IconList getIconList() + { + IconList iconList = new IconList(); + Node iconListNode = getDeviceNode().getNode(IconList.ELEM_NAME); + if (iconListNode == null) + return iconList; + int nNode = iconListNode.getNNodes(); + for (int n=0; n<nNode; n++) { + Node node = iconListNode.getNode(n); + if (Icon.isIconNode(node) == false) + continue; + Icon icon = new Icon(node); + iconList.add(icon); + } + return iconList; } public Icon getIcon(int n) @@ -1064,7 +1064,7 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL if (n < 0 && (iconList.size()-1) < n) return null; return iconList.getIcon(n); - } + } //////////////////////////////////////////////// // Notify @@ -1218,10 +1218,10 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL byebye(bindAddr); } } - - //////////////////////////////////////////////// - // Search - //////////////////////////////////////////////// + + //////////////////////////////////////////////// + // Search + //////////////////////////////////////////////// public boolean postSearchResponse(SSDPPacket ssdpPacket, String st, String usn) { @@ -1314,29 +1314,29 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL // HTTP Server //////////////////////////////////////////////// - public void setHTTPPort(int port) - { + public void setHTTPPort(int port) + { getDeviceData().setHTTPPort(port); - } - - public int getHTTPPort() - { - return getDeviceData().getHTTPPort(); - } - - public void httpRequestRecieved(HTTPRequest httpReq) + } + + public int getHTTPPort() + { + return getDeviceData().getHTTPPort(); + } + + public void httpRequestRecieved(HTTPRequest httpReq) { if (Debug.isOn() == true) httpReq.print(); - if (httpReq.isGetRequest() == true) { - httpGetRequestRecieved(httpReq); + if (httpReq.isGetRequest() == true) { + httpGetRequestRecieved(httpReq); return; - } - if (httpReq.isPostRequest() == true) { - httpPostRequestRecieved(httpReq); - return; - } + } + if (httpReq.isPostRequest() == true) { + httpPostRequestRecieved(httpReq); + return; + } if (httpReq.isSubscribeRequest() == true || httpReq.isUnsubscribeRequest() == true) { SubscriptionRequest subReq = new SubscriptionRequest(httpReq); @@ -1345,11 +1345,11 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL } httpReq.returnBadRequest(); - } + } private synchronized byte[] getDescriptionData(String host) { - if (isNMPRMode() == false) + if (isNMPRMode() == false) updateURLBase(host); Node rootNode = getRootNode(); if (rootNode == null) @@ -1362,19 +1362,19 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL return desc.getBytes(); } - private void httpGetRequestRecieved(HTTPRequest httpReq) + private void httpGetRequestRecieved(HTTPRequest httpReq) { String uri = httpReq.getURI(); Debug.message("httpGetRequestRecieved = " + uri); - if (uri == null) { + if (uri == null) { httpReq.returnBadRequest(); - return; - } + return; + } Device embDev; Service embService; - byte fileByte[] = new byte[0]; + byte fileByte[] = new byte[0]; if (isDescriptionURI(uri) == true) { String localAddr = httpReq.getLocalAddress(); fileByte = getDescriptionData(localAddr); @@ -1390,17 +1390,17 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL httpReq.returnBadRequest(); return; } - + HTTPResponse httpRes = new HTTPResponse(); if (FileUtil.isXMLFileName(uri) == true) - httpRes.setContentType(XML.CONTENT_TYPE); - httpRes.setStatusCode(HTTPStatus.OK); - httpRes.setContent(fileByte); - - httpReq.post(httpRes); - } - - private void httpPostRequestRecieved(HTTPRequest httpReq) + httpRes.setContentType(XML.CONTENT_TYPE); + httpRes.setStatusCode(HTTPStatus.OK); + httpRes.setContent(fileByte); + + httpReq.post(httpRes); + } + + private void httpPostRequestRecieved(HTTPRequest httpReq) { if (httpReq.isSOAPAction() == true) { //SOAPRequest soapReq = new SOAPRequest(httpReq); @@ -1408,7 +1408,7 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL return; } httpReq.returnBadRequest(); - } + } //////////////////////////////////////////////// // SOAP @@ -1607,9 +1607,9 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL subRes.print(); } - //////////////////////////////////////////////// - // Thread - //////////////////////////////////////////////// + //////////////////////////////////////////////// + // Thread + //////////////////////////////////////////////// private HTTPServerList getHTTPServerList() { @@ -1631,10 +1631,10 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL return getDeviceData().getAdvertiser(); } - public boolean start() + public boolean start() { stop(true); - + //////////////////////////////////////// // HTTP Server //////////////////////////////////////// @@ -1676,8 +1676,8 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL setAdvertiser(adv); adv.start(); - return true; - } + return true; + } private boolean stop(boolean doByeBye) { @@ -1702,12 +1702,12 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL return true; } - - public boolean stop() + + public boolean stop() { - return stop(true); - } - + return stop(true); + } + //////////////////////////////////////////////// // Interface Address //////////////////////////////////////////////// @@ -1776,34 +1776,34 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL } } - //////////////////////////////////////////////// - // output - //////////////////////////////////////////////// - -/* - public void output(PrintWriter ps) - { - ps.println("deviceType = " + getDeviceType()); - ps.println("freindlyName = " + getFriendlyName()); - ps.println("presentationURL = " + getPresentationURL()); - - DeviceList devList = getDeviceList(); - ps.println("devList = " + devList.size()); - - ServiceList serviceList = getServiceList(); - ps.println("serviceList = " + serviceList.size()); - - IconList iconList = getIconList(); - ps.println("iconList = " + iconList.size()); - } - - public void print() - { - PrintWriter pr = new PrintWriter(System.out); - output(pr); - pr.flush(); - } -*/ + //////////////////////////////////////////////// + // output + //////////////////////////////////////////////// + +/* + public void output(PrintWriter ps) + { + ps.println("deviceType = " + getDeviceType()); + ps.println("freindlyName = " + getFriendlyName()); + ps.println("presentationURL = " + getPresentationURL()); + + DeviceList devList = getDeviceList(); + ps.println("devList = " + devList.size()); + + ServiceList serviceList = getServiceList(); + ps.println("serviceList = " + serviceList.size()); + + IconList iconList = getIconList(); + ps.println("iconList = " + iconList.size()); + } + + public void print() + { + PrintWriter pr = new PrintWriter(System.out); + output(pr); + pr.flush(); + } +*/ } diff --git a/router/java/src/org/cybergarage/upnp/Service.java b/router/java/src/org/cybergarage/upnp/Service.java index e588feba69b490121d33dfa95da3d6185a581be8..2febe00df46e7528bfe904138015ec9f06875def 100644 --- a/router/java/src/org/cybergarage/upnp/Service.java +++ b/router/java/src/org/cybergarage/upnp/Service.java @@ -5,11 +5,11 @@ * Copyright (C) Satoshi Konno 2002-2003 * * File: Service.java -* -* Revision; -* -* 11/28/02 -* - first revision. +* +* Revision; +* +* 11/28/02 +* - first revision. * 04/12/02 * - Holmes, Arran C <acholm@essex.ac.uk> * - Fixed SERVICE_ID constant instead of "serviceId". @@ -63,12 +63,12 @@ * ******************************************************************/ -package org.cybergarage.upnp; - +package org.cybergarage.upnp; + import java.io.*; -import java.net.*; - -import org.cybergarage.http.*; +import java.net.*; + +import org.cybergarage.http.*; import org.cybergarage.xml.*; import org.cybergarage.util.*; @@ -77,35 +77,35 @@ import org.cybergarage.upnp.xml.*; import org.cybergarage.upnp.device.*; import org.cybergarage.upnp.control.*; import org.cybergarage.upnp.event.*; - -public class Service -{ - //////////////////////////////////////////////// - // Constants - //////////////////////////////////////////////// - - public final static String ELEM_NAME = "service"; - - //////////////////////////////////////////////// - // Member - //////////////////////////////////////////////// - - private Node serviceNode; - - public Node getServiceNode() - { - return serviceNode; - } - - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public Service(Node node) - { - serviceNode = node; - } - + +public class Service +{ + //////////////////////////////////////////////// + // Constants + //////////////////////////////////////////////// + + public final static String ELEM_NAME = "service"; + + //////////////////////////////////////////////// + // Member + //////////////////////////////////////////////// + + private Node serviceNode; + + public Node getServiceNode() + { + return serviceNode; + } + + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public Service(Node node) + { + serviceNode = node; + } + //////////////////////////////////////////////// // Mutex //////////////////////////////////////////////// @@ -122,78 +122,78 @@ public class Service mutex.unlock(); } - //////////////////////////////////////////////// - // isServiceNode - //////////////////////////////////////////////// - - public static boolean isServiceNode(Node node) - { - return Service.ELEM_NAME.equals(node.getName()); - } - - //////////////////////////////////////////////// - // Device/Root Node - //////////////////////////////////////////////// - - private Node getDeviceNode() - { - Node node = getServiceNode().getParentNode(); - if (node == null) - return null; - return node.getParentNode(); - } - - private Node getRootNode() - { - return getServiceNode().getRootNode(); - } - - //////////////////////////////////////////////// - // Device - //////////////////////////////////////////////// - - public Device getDevice() - { - return new Device(getRootNode(), getDeviceNode()); - } + //////////////////////////////////////////////// + // isServiceNode + //////////////////////////////////////////////// + + public static boolean isServiceNode(Node node) + { + return Service.ELEM_NAME.equals(node.getName()); + } + + //////////////////////////////////////////////// + // Device/Root Node + //////////////////////////////////////////////// + + private Node getDeviceNode() + { + Node node = getServiceNode().getParentNode(); + if (node == null) + return null; + return node.getParentNode(); + } + + private Node getRootNode() + { + return getServiceNode().getRootNode(); + } + + //////////////////////////////////////////////// + // Device + //////////////////////////////////////////////// + + public Device getDevice() + { + return new Device(getRootNode(), getDeviceNode()); + } public Device getRootDevice() { return getDevice().getRootDevice(); } - //////////////////////////////////////////////// - // serviceType - //////////////////////////////////////////////// - - private final static String SERVICE_TYPE = "serviceType"; - - public void setServiceType(String value) - { - getServiceNode().setNode(SERVICE_TYPE, value); - } - - public String getServiceType() - { - return getServiceNode().getNodeValue(SERVICE_TYPE); - } - - //////////////////////////////////////////////// - // serviceID - //////////////////////////////////////////////// - - private final static String SERVICE_ID = "serviceId"; - - public void setServiceID(String value) - { - getServiceNode().setNode(SERVICE_ID, value); - } - - public String getServiceID() - { - return getServiceNode().getNodeValue(SERVICE_ID); - } - + //////////////////////////////////////////////// + // serviceType + //////////////////////////////////////////////// + + private final static String SERVICE_TYPE = "serviceType"; + + public void setServiceType(String value) + { + getServiceNode().setNode(SERVICE_TYPE, value); + } + + public String getServiceType() + { + return getServiceNode().getNodeValue(SERVICE_TYPE); + } + + //////////////////////////////////////////////// + // serviceID + //////////////////////////////////////////////// + + private final static String SERVICE_ID = "serviceId"; + + public void setServiceID(String value) + { + getServiceNode().setNode(SERVICE_ID, value); + } + + public String getServiceID() + { + return getServiceNode().getNodeValue(SERVICE_ID); + } + //////////////////////////////////////////////// // isURL //////////////////////////////////////////////// @@ -213,73 +213,73 @@ public class Service return false; } - //////////////////////////////////////////////// - // SCPDURL - //////////////////////////////////////////////// - - private final static String SCPDURL = "SCPDURL"; - - public void setSCPDURL(String value) - { - getServiceNode().setNode(SCPDURL, value); - } - - public String getSCPDURL() - { - return getServiceNode().getNodeValue(SCPDURL); - } - + //////////////////////////////////////////////// + // SCPDURL + //////////////////////////////////////////////// + + private final static String SCPDURL = "SCPDURL"; + + public void setSCPDURL(String value) + { + getServiceNode().setNode(SCPDURL, value); + } + + public String getSCPDURL() + { + return getServiceNode().getNodeValue(SCPDURL); + } + public boolean isSCPDURL(String url) { return isURL(getSCPDURL(), url); } - //////////////////////////////////////////////// - // controlURL - //////////////////////////////////////////////// - - private final static String CONTROL_URL = "controlURL"; - - public void setControlURL(String value) - { - getServiceNode().setNode(CONTROL_URL, value); - } - - public String getControlURL() - { - return getServiceNode().getNodeValue(CONTROL_URL); - } + //////////////////////////////////////////////// + // controlURL + //////////////////////////////////////////////// + + private final static String CONTROL_URL = "controlURL"; + + public void setControlURL(String value) + { + getServiceNode().setNode(CONTROL_URL, value); + } + + public String getControlURL() + { + return getServiceNode().getNodeValue(CONTROL_URL); + } public boolean isControlURL(String url) { return isURL(getControlURL(), url); } - - //////////////////////////////////////////////// - // eventSubURL - //////////////////////////////////////////////// - - private final static String EVENT_SUB_URL = "eventSubURL"; - - public void setEventSubURL(String value) - { - getServiceNode().setNode(EVENT_SUB_URL, value); - } - - public String getEventSubURL() - { - return getServiceNode().getNodeValue(EVENT_SUB_URL); - } + + //////////////////////////////////////////////// + // eventSubURL + //////////////////////////////////////////////// + + private final static String EVENT_SUB_URL = "eventSubURL"; + + public void setEventSubURL(String value) + { + getServiceNode().setNode(EVENT_SUB_URL, value); + } + + public String getEventSubURL() + { + return getServiceNode().getNodeValue(EVENT_SUB_URL); + } public boolean isEventSubURL(String url) { return isURL(getEventSubURL(), url); } - - //////////////////////////////////////////////// - // SCPD node - //////////////////////////////////////////////// - + + //////////////////////////////////////////////// + // SCPD node + //////////////////////////////////////////////// + public boolean loadSCPD(String scpdStr) throws InvalidDescriptionException { try { @@ -307,32 +307,32 @@ public class Service return true; } - private Node getSCPDNode(URL scpdUrl) throws ParserException - { + private Node getSCPDNode(URL scpdUrl) throws ParserException + { Parser parser = UPnP.getXMLParser(); - return parser.parse(scpdUrl); + return parser.parse(scpdUrl); } - + private Node getSCPDNode(File scpdFile) throws ParserException { Parser parser = UPnP.getXMLParser(); return parser.parse(scpdFile); } - - private Node getSCPDNode() - { - ServiceData data = getServiceData(); - Node scpdNode = data.getSCPDNode(); - if (scpdNode != null) - return scpdNode; - - String scpdURLStr = getSCPDURL(); - try { + + private Node getSCPDNode() + { + ServiceData data = getServiceData(); + Node scpdNode = data.getSCPDNode(); + if (scpdNode != null) + return scpdNode; + + String scpdURLStr = getSCPDURL(); + try { URL scpdUrl = new URL(scpdURLStr); - scpdNode = getSCPDNode(scpdUrl); - } + scpdNode = getSCPDNode(scpdUrl); + } catch (Exception e1) { - Device rootDev = getRootDevice(); + Device rootDev = getRootDevice(); String urlBaseStr = rootDev.getURLBase(); // Thanks for Steven Yen (2003/09/03) if (urlBaseStr == null || urlBaseStr.length() <= 0) { @@ -341,35 +341,35 @@ public class Service int locationPort = HTTP.getPort(location); urlBaseStr = HTTP.getRequestHostURL(locationHost, locationPort); } - scpdURLStr = HTTP.toRelativeURL(scpdURLStr); - String newScpdURLStr = urlBaseStr + scpdURLStr; - try { + scpdURLStr = HTTP.toRelativeURL(scpdURLStr); + String newScpdURLStr = urlBaseStr + scpdURLStr; + try { URL newScpdURL = new URL(newScpdURLStr); - scpdNode = getSCPDNode(newScpdURL); - } - catch (Exception e2) { - newScpdURLStr = HTTP.getAbsoluteURL(urlBaseStr, scpdURLStr); - try { + scpdNode = getSCPDNode(newScpdURL); + } + catch (Exception e2) { + newScpdURLStr = HTTP.getAbsoluteURL(urlBaseStr, scpdURLStr); + try { URL newScpdURL = new URL(newScpdURLStr); - scpdNode = getSCPDNode(newScpdURL); - } - catch (Exception e3) { + scpdNode = getSCPDNode(newScpdURL); + } + catch (Exception e3) { newScpdURLStr = rootDev.getDescriptionFilePath() + scpdURLStr; try { scpdNode = getSCPDNode(new File(newScpdURLStr)); } catch (Exception e4) { Debug.warning(e4); - } + } } - } - } - - data.setSCPDNode(scpdNode); - - return scpdNode; - } - + } + } + + data.setSCPDNode(scpdNode); + + return scpdNode; + } + public byte[] getSCPDData() { Node scpdNode = getSCPDNode(); @@ -383,30 +383,30 @@ public class Service return desc.getBytes(); } - //////////////////////////////////////////////// - // actionList - //////////////////////////////////////////////// - - public ActionList getActionList() - { - ActionList actionList = new ActionList(); - Node scdpNode = getSCPDNode(); - if (scdpNode == null) - return actionList; - Node actionListNode = scdpNode.getNode(ActionList.ELEM_NAME); - if (actionListNode == null) - return actionList; - Node _serviceNode = getServiceNode(); - int nNode = actionListNode.getNNodes(); - for (int n=0; n<nNode; n++) { - Node node = actionListNode.getNode(n); - if (Action.isActionNode(node) == false) - continue; - Action action = new Action(_serviceNode, node); - actionList.add(action); - } - return actionList; - } + //////////////////////////////////////////////// + // actionList + //////////////////////////////////////////////// + + public ActionList getActionList() + { + ActionList actionList = new ActionList(); + Node scdpNode = getSCPDNode(); + if (scdpNode == null) + return actionList; + Node actionListNode = scdpNode.getNode(ActionList.ELEM_NAME); + if (actionListNode == null) + return actionList; + Node serviceNode = getServiceNode(); + int nNode = actionListNode.getNNodes(); + for (int n=0; n<nNode; n++) { + Node node = actionListNode.getNode(n); + if (Action.isActionNode(node) == false) + continue; + Action action = new Action(serviceNode, node); + actionList.add(action); + } + return actionList; + } public Action getAction(String actionName) { @@ -422,28 +422,28 @@ public class Service } return null; } - - //////////////////////////////////////////////// - // serviceStateTable - //////////////////////////////////////////////// - - public ServiceStateTable getServiceStateTable() - { - ServiceStateTable stateTable = new ServiceStateTable(); - Node stateTableNode = getSCPDNode().getNode(ServiceStateTable.ELEM_NAME); - if (stateTableNode == null) + + //////////////////////////////////////////////// + // serviceStateTable + //////////////////////////////////////////////// + + public ServiceStateTable getServiceStateTable() + { + ServiceStateTable stateTable = new ServiceStateTable(); + Node stateTableNode = getSCPDNode().getNode(ServiceStateTable.ELEM_NAME); + if (stateTableNode == null) return stateTable; - Node _serviceNode = getServiceNode(); - int nNode = stateTableNode.getNNodes(); - for (int n=0; n<nNode; n++) { - Node node = stateTableNode.getNode(n); - if (StateVariable.isStateVariableNode(node) == false) - continue; - StateVariable serviceVar = new StateVariable(_serviceNode, node); - stateTable.add(serviceVar); - } - return stateTable; - } + Node serviceNode = getServiceNode(); + int nNode = stateTableNode.getNNodes(); + for (int n=0; n<nNode; n++) { + Node node = stateTableNode.getNode(n); + if (StateVariable.isStateVariableNode(node) == false) + continue; + StateVariable serviceVar = new StateVariable(serviceNode, node); + stateTable.add(serviceVar); + } + return stateTable; + } public StateVariable getStateVariable(String name) { diff --git a/router/java/src/org/cybergarage/upnp/ServiceList.java b/router/java/src/org/cybergarage/upnp/ServiceList.java index cb7da35488c4dba9ad0aa86f85b479710bb3af6e..0a23154ebffc66331ede6cef2e566fe863a5dba3 100644 --- a/router/java/src/org/cybergarage/upnp/ServiceList.java +++ b/router/java/src/org/cybergarage/upnp/ServiceList.java @@ -3,7 +3,7 @@ * CyberUPnP for Java * * Copyright (C) Satoshi Konno 2002 -* +* * File: ServiceList.java * * Revision; @@ -14,7 +14,7 @@ * - Added caching a ArrayIndexOfBound exception. * ******************************************************************/ - + package org.cybergarage.upnp; import java.util.*; @@ -46,7 +46,7 @@ public class ServiceList extends Vector try { obj = get(n); } - catch (Exception e) {} + catch (Exception e) {}; return (Service)obj; } } diff --git a/router/java/src/org/cybergarage/upnp/StateVariable.java b/router/java/src/org/cybergarage/upnp/StateVariable.java index c75625e28b79951aad83ca6a1f29637041ea7f80..45b5e301ad51a75c1e5ac5d19534def0d7dcf01b 100644 --- a/router/java/src/org/cybergarage/upnp/StateVariable.java +++ b/router/java/src/org/cybergarage/upnp/StateVariable.java @@ -5,10 +5,10 @@ * Copyright (C) Satoshi Konno 2002 * * File: StateVariable.java -* -* Revision; -* -* 12/06/02 +* +* Revision; +* +* 12/06/02 * - first revision. * 06/17/03 * - Added setSendEvents(), isSendEvents(). @@ -41,28 +41,28 @@ * - Changed getAllowedValueList() to use AllowedValue instead of String as the member. * ******************************************************************/ - -package org.cybergarage.upnp; - -import org.cybergarage.xml.*; + +package org.cybergarage.upnp; + +import org.cybergarage.xml.*; import org.cybergarage.util.*; import org.cybergarage.upnp.control.*; import org.cybergarage.upnp.xml.*; - -public class StateVariable extends NodeData -{ - //////////////////////////////////////////////// - // Constants - //////////////////////////////////////////////// - - public final static String ELEM_NAME = "stateVariable"; - - //////////////////////////////////////////////// - // Member - //////////////////////////////////////////////// - - private Node stateVariableNode; + +public class StateVariable extends NodeData +{ + //////////////////////////////////////////////// + // Constants + //////////////////////////////////////////////// + + public final static String ELEM_NAME = "stateVariable"; + + //////////////////////////////////////////////// + // Member + //////////////////////////////////////////////// + + private Node stateVariableNode; private Node serviceNode; public Node getServiceNode() @@ -72,73 +72,73 @@ public class StateVariable extends NodeData public Service getService() { - Node _serviceNode = getServiceNode(); - if (_serviceNode == null) + Node serviceNode = getServiceNode(); + if (serviceNode == null) return null; - return new Service(_serviceNode); - } - - public Node getStateVariableNode() - { - return stateVariableNode; - } - - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - + return new Service(serviceNode); + } + + public Node getStateVariableNode() + { + return stateVariableNode; + } + + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + public StateVariable() { this.serviceNode = null; this.stateVariableNode = new Node(); } - public StateVariable(Node serviceNode, Node stateVarNode) - { - this.serviceNode = serviceNode; - this.stateVariableNode = stateVarNode; - } - - //////////////////////////////////////////////// - // isStateVariableNode - //////////////////////////////////////////////// - - public static boolean isStateVariableNode(Node node) - { - return StateVariable.ELEM_NAME.equals(node.getName()); - } - - //////////////////////////////////////////////// - // name - //////////////////////////////////////////////// - - private final static String NAME = "name"; - - public void setName(String value) - { - getStateVariableNode().setNode(NAME, value); - } - - public String getName() - { - return getStateVariableNode().getNodeValue(NAME); - } - - //////////////////////////////////////////////// - // dataType - //////////////////////////////////////////////// - - private final static String DATATYPE = "dataType"; - - public void setDataType(String value) - { - getStateVariableNode().setNode(DATATYPE, value); - } - - public String getDataType() - { - return getStateVariableNode().getNodeValue(DATATYPE); - } + public StateVariable(Node serviceNode, Node stateVarNode) + { + this.serviceNode = serviceNode; + this.stateVariableNode = stateVarNode; + } + + //////////////////////////////////////////////// + // isStateVariableNode + //////////////////////////////////////////////// + + public static boolean isStateVariableNode(Node node) + { + return StateVariable.ELEM_NAME.equals(node.getName()); + } + + //////////////////////////////////////////////// + // name + //////////////////////////////////////////////// + + private final static String NAME = "name"; + + public void setName(String value) + { + getStateVariableNode().setNode(NAME, value); + } + + public String getName() + { + return getStateVariableNode().getNodeValue(NAME); + } + + //////////////////////////////////////////////// + // dataType + //////////////////////////////////////////////// + + private final static String DATATYPE = "dataType"; + + public void setDataType(String value) + { + getStateVariableNode().setNode(DATATYPE, value); + } + + public String getDataType() + { + return getStateVariableNode().getNodeValue(DATATYPE); + } //////////////////////////////////////////////// // dataType @@ -301,8 +301,8 @@ public class StateVariable extends NodeData queryRes.setResponse(retVar); } else { - UPnPStatus _upnpStatus = retVar.getStatus(); - queryRes.setFaultResponse(_upnpStatus.getCode(), _upnpStatus.getDescription()); + UPnPStatus upnpStatus = retVar.getStatus(); + queryRes.setFaultResponse(upnpStatus.getCode(), upnpStatus.getDescription()); } queryReq.post(queryRes); return true; diff --git a/router/java/src/org/cybergarage/upnp/control/RenewSubscriber.java b/router/java/src/org/cybergarage/upnp/control/RenewSubscriber.java index 6b5fef987128a65baa314856b37784855e2a6855..7b8d2e05907caf7372a34d72347871b5f58769d6 100644 --- a/router/java/src/org/cybergarage/upnp/control/RenewSubscriber.java +++ b/router/java/src/org/cybergarage/upnp/control/RenewSubscriber.java @@ -51,7 +51,6 @@ public class RenewSubscriber extends ThreadCore // Thread //////////////////////////////////////////////// - @Override public void run() { ControlPoint ctrlp = getControlPoint(); diff --git a/router/java/src/org/cybergarage/upnp/device/Advertiser.java b/router/java/src/org/cybergarage/upnp/device/Advertiser.java index 58b5dd61047fd9e46bd9086d36dfec49e33d8e0a..373fea82d93c55ff64223e6c15fd4d54cad28bfb 100644 --- a/router/java/src/org/cybergarage/upnp/device/Advertiser.java +++ b/router/java/src/org/cybergarage/upnp/device/Advertiser.java @@ -51,7 +51,6 @@ public class Advertiser extends ThreadCore // Thread //////////////////////////////////////////////// - @Override public void run() { Device dev = getDevice(); diff --git a/router/java/src/org/cybergarage/upnp/device/Disposer.java b/router/java/src/org/cybergarage/upnp/device/Disposer.java index e76befec3a8934612c1a586eaba164cb5c142043..1de8ceb3b93027cc1b40d4c3a09de65a104e018c 100644 --- a/router/java/src/org/cybergarage/upnp/device/Disposer.java +++ b/router/java/src/org/cybergarage/upnp/device/Disposer.java @@ -49,7 +49,6 @@ public class Disposer extends ThreadCore // Thread //////////////////////////////////////////////// - @Override public void run() { Thread.currentThread().setName("UPnP-Disposer"); diff --git a/router/java/src/org/cybergarage/upnp/ssdp/HTTPMUSocket.java b/router/java/src/org/cybergarage/upnp/ssdp/HTTPMUSocket.java index 80e58967838ba31c3b2fd9072426c931922efc3b..4f6361f59410e412b065c54abab0c4f97ca09e42 100644 --- a/router/java/src/org/cybergarage/upnp/ssdp/HTTPMUSocket.java +++ b/router/java/src/org/cybergarage/upnp/ssdp/HTTPMUSocket.java @@ -5,11 +5,11 @@ * Copyright (C) Satoshi Konno 2002-2004 * * File: HTTPMU.java -* -* Revision; -* -* 11/18/02 -* - first revision. +* +* Revision; +* +* 11/18/02 +* - first revision. * 09/03/03 * - Changed to open the socket using setReuseAddress(). * 12/10/03 @@ -21,39 +21,38 @@ * - Changed send() to set the TTL as 4. * ******************************************************************/ - -package org.cybergarage.upnp.ssdp; - -import java.net.*; + +package org.cybergarage.upnp.ssdp; + +import java.net.*; import java.util.*; -import org.cybergarage.http.*; -import org.cybergarage.util.*; - -public class HTTPMUSocket -{ - //////////////////////////////////////////////// - // Member - //////////////////////////////////////////////// - - private InetSocketAddress ssdpMultiGroup = null; - private MulticastSocket ssdpMultiSock = null; +import org.cybergarage.http.*; +import org.cybergarage.util.*; + +public class HTTPMUSocket +{ + //////////////////////////////////////////////// + // Member + //////////////////////////////////////////////// + + private InetSocketAddress ssdpMultiGroup = null; + private MulticastSocket ssdpMultiSock = null; private NetworkInterface ssdpMultiIf = null; - - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - + + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + public HTTPMUSocket() { } - public HTTPMUSocket(String addr, int port, String bindAddr) - { - open(addr, port, bindAddr); - } + public HTTPMUSocket(String addr, int port, String bindAddr) + { + open(addr, port, bindAddr); + } - @Override protected void finalize() { close(); @@ -91,52 +90,52 @@ public class HTTPMUSocket return getMulticastInetAddress().getHostAddress(); } - //////////////////////////////////////////////// - // open/close - //////////////////////////////////////////////// - - public boolean open(String addr, int port, String bindAddr) - { - try { + //////////////////////////////////////////////// + // open/close + //////////////////////////////////////////////// + + public boolean open(String addr, int port, String bindAddr) + { + try { ssdpMultiSock = new MulticastSocket(null); ssdpMultiSock.setReuseAddress(true); InetSocketAddress bindSockAddr = new InetSocketAddress(port); ssdpMultiSock.bind(bindSockAddr); ssdpMultiGroup = new InetSocketAddress(InetAddress.getByName(addr), port); - ssdpMultiIf = NetworkInterface.getByInetAddress(InetAddress.getByName(bindAddr)); + ssdpMultiIf = NetworkInterface.getByInetAddress(InetAddress.getByName(bindAddr)); ssdpMultiSock.joinGroup(ssdpMultiGroup, ssdpMultiIf); - } - catch (Exception e) { - Debug.warning(e); - return false; - } - - return true; - } - - public boolean close() - { - if (ssdpMultiSock == null) - return true; - - try { - ssdpMultiSock.leaveGroup(ssdpMultiGroup, ssdpMultiIf); + } + catch (Exception e) { + Debug.warning(e); + return false; + } + + return true; + } + + public boolean close() + { + if (ssdpMultiSock == null) + return true; + + try { + ssdpMultiSock.leaveGroup(ssdpMultiGroup, ssdpMultiIf); ssdpMultiSock = null; - } - catch (Exception e) { - //Debug.warning(e); - return false; - } - - return true; - } - - //////////////////////////////////////////////// - // send - //////////////////////////////////////////////// - - public boolean send(String msg, String bindAddr, int bindPort) - { + } + catch (Exception e) { + //Debug.warning(e); + return false; + } + + return true; + } + + //////////////////////////////////////////////// + // send + //////////////////////////////////////////////// + + public boolean send(String msg, String bindAddr, int bindPort) + { try { MulticastSocket msock; if ((bindAddr) != null && (0 < bindPort)) { @@ -150,50 +149,50 @@ public class HTTPMUSocket msock.setTimeToLive(4); msock.send(dgmPacket); msock.close(); - } - catch (Exception e) { - Debug.warning(e); - return false; - } - return true; - } - - public boolean send(String msg) - { - return send(msg, null, -1); - } - - //////////////////////////////////////////////// - // post (HTTPRequest) - //////////////////////////////////////////////// - - public boolean post(HTTPRequest req, String bindAddr, int bindPort) - { + } + catch (Exception e) { + Debug.warning(e); + return false; + } + return true; + } + + public boolean send(String msg) + { + return send(msg, null, -1); + } + + //////////////////////////////////////////////// + // post (HTTPRequest) + //////////////////////////////////////////////// + + public boolean post(HTTPRequest req, String bindAddr, int bindPort) + { return send(req.toString(), bindAddr, bindPort); - } + } public boolean post(HTTPRequest req) { return send(req.toString(), null, -1); } - - //////////////////////////////////////////////// - // reveive - //////////////////////////////////////////////// - - public SSDPPacket receive() - { - byte ssdvRecvBuf[] = new byte[SSDP.RECV_MESSAGE_BUFSIZE]; + + //////////////////////////////////////////////// + // reveive + //////////////////////////////////////////////// + + public SSDPPacket receive() + { + byte ssdvRecvBuf[] = new byte[SSDP.RECV_MESSAGE_BUFSIZE]; SSDPPacket recvPacket = new SSDPPacket(ssdvRecvBuf, ssdvRecvBuf.length); recvPacket.setLocalAddress(getLocalAddress()); try { ssdpMultiSock.receive(recvPacket.getDatagramPacket()); - recvPacket.setTimeStamp(System.currentTimeMillis()); + recvPacket.setTimeStamp(System.currentTimeMillis()); + } + catch (Exception e) { + //Debug.warning(e); } - catch (Exception e) { - //Debug.warning(e); - } - return recvPacket; - } + return recvPacket; + } } - + diff --git a/router/java/src/org/cybergarage/upnp/ssdp/HTTPUSocket.java b/router/java/src/org/cybergarage/upnp/ssdp/HTTPUSocket.java index 04a21c70ec35aaa934a5f1a019429f1bcdd58fcf..221311c554888397b8892a683f11a92aed599cc9 100644 --- a/router/java/src/org/cybergarage/upnp/ssdp/HTTPUSocket.java +++ b/router/java/src/org/cybergarage/upnp/ssdp/HTTPUSocket.java @@ -5,11 +5,11 @@ * Copyright (C) Satoshi Konno 2002-2003 * * File: HTTPMU.java -* -* Revision; -* -* 11/20/02 -* - first revision. +* +* Revision; +* +* 11/20/02 +* - first revision. * 12/12/03 * - Inma Mar?n <inma@DIF.UM.ES> * - Changed open(addr, port) to send IPv6 SSDP packets. @@ -20,47 +20,46 @@ * - Added to set a current timestamp when the packet are received. * ******************************************************************/ - -package org.cybergarage.upnp.ssdp; - -import java.net.*; - -import org.cybergarage.util.*; - -public class HTTPUSocket -{ - //////////////////////////////////////////////// - // Member - //////////////////////////////////////////////// - - private DatagramSocket ssdpUniSock = null; + +package org.cybergarage.upnp.ssdp; + +import java.net.*; + +import org.cybergarage.util.*; + +public class HTTPUSocket +{ + //////////////////////////////////////////////// + // Member + //////////////////////////////////////////////// + + private DatagramSocket ssdpUniSock = null; //private MulticastSocket ssdpUniSock = null; - - public DatagramSocket getDatagramSocket() - { - return ssdpUniSock; - } - - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public HTTPUSocket() + + public DatagramSocket getDatagramSocket() + { + return ssdpUniSock; + } + + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public HTTPUSocket() { open(); - } - - public HTTPUSocket(String bindAddr, int bindPort) + } + + public HTTPUSocket(String bindAddr, int bindPort) { open(bindAddr, bindPort); - } + } public HTTPUSocket(int bindPort) { open(bindPort); } - - @Override + protected void finalize() { close(); @@ -142,66 +141,66 @@ public class HTTPUSocket return true; } - //////////////////////////////////////////////// - // close - //////////////////////////////////////////////// - - public boolean close() - { - if (ssdpUniSock == null) - return true; - - try { + //////////////////////////////////////////////// + // close + //////////////////////////////////////////////// + + public boolean close() + { + if (ssdpUniSock == null) + return true; + + try { ssdpUniSock.close(); - ssdpUniSock = null; - } - catch (Exception e) { - Debug.warning(e); - return false; - } - - return true; - } - - //////////////////////////////////////////////// - // send - //////////////////////////////////////////////// - - public boolean post(String addr, int port, String msg) - { - try { - InetAddress inetAddr = InetAddress.getByName(addr); - DatagramPacket dgmPacket = new DatagramPacket(msg.getBytes(), msg.length(), inetAddr, port); + ssdpUniSock = null; + } + catch (Exception e) { + Debug.warning(e); + return false; + } + + return true; + } + + //////////////////////////////////////////////// + // send + //////////////////////////////////////////////// + + public boolean post(String addr, int port, String msg) + { + try { + InetAddress inetAddr = InetAddress.getByName(addr); + DatagramPacket dgmPacket = new DatagramPacket(msg.getBytes(), msg.length(), inetAddr, port); ssdpUniSock.send(dgmPacket); - } + } catch (Exception e) { - Debug.warning("addr = " +ssdpUniSock.getLocalAddress().getHostName()); + Debug.warning("addr = " +ssdpUniSock.getLocalAddress().getHostName()); Debug.warning("port = " + ssdpUniSock.getLocalPort()); - Debug.warning(e); - return false; - } - return true; - } - - //////////////////////////////////////////////// - // reveive - //////////////////////////////////////////////// - - public SSDPPacket receive() - { - byte ssdvRecvBuf[] = new byte[SSDP.RECV_MESSAGE_BUFSIZE]; - SSDPPacket recvPacket = new SSDPPacket(ssdvRecvBuf, ssdvRecvBuf.length); + Debug.warning(e); + return false; + } + return true; + } + + //////////////////////////////////////////////// + // reveive + //////////////////////////////////////////////// + + public SSDPPacket receive() + { + byte ssdvRecvBuf[] = new byte[SSDP.RECV_MESSAGE_BUFSIZE]; + SSDPPacket recvPacket = new SSDPPacket(ssdvRecvBuf, ssdvRecvBuf.length); recvPacket.setLocalAddress(getLocalAddress()); - try { - ssdpUniSock.receive(recvPacket.getDatagramPacket()); + try { + ssdpUniSock.receive(recvPacket.getDatagramPacket()); recvPacket.setTimeStamp(System.currentTimeMillis()); - } - catch (Exception e) { + } + catch (Exception e) { //Debug.warning(e); - return null; - } - return recvPacket; - } + return null; + } + return recvPacket; + } //////////////////////////////////////////////// // join/leave @@ -236,5 +235,5 @@ public class HTTPUSocket return true; } */ -} - +} + diff --git a/router/java/src/org/cybergarage/upnp/ssdp/SSDPNotifySocket.java b/router/java/src/org/cybergarage/upnp/ssdp/SSDPNotifySocket.java index ad5c26f75c11e27b2c285b1f18ba4ce976cecb6a..75484bd1640c3ed168d8add1f529516413f66594 100644 --- a/router/java/src/org/cybergarage/upnp/ssdp/SSDPNotifySocket.java +++ b/router/java/src/org/cybergarage/upnp/ssdp/SSDPNotifySocket.java @@ -5,11 +5,11 @@ * Copyright (C) Satoshi Konno 2002-2003 * * File: SSDPNotifySocket.java -* -* Revision; -* -* 11/20/02 -* - first revision. +* +* Revision; +* +* 11/20/02 +* - first revision. * 05/13/03 * - Added support for IPv6. * 02/20/04 @@ -21,24 +21,25 @@ * - Added close() in stop(). * ******************************************************************/ + +package org.cybergarage.upnp.ssdp; -package org.cybergarage.upnp.ssdp; - -import java.net.*; +import java.net.*; import org.cybergarage.net.*; +import org.cybergarage.util.*; import org.cybergarage.http.*; -import org.cybergarage.upnp.*; - -public class SSDPNotifySocket extends HTTPMUSocket implements Runnable +import org.cybergarage.upnp.*; + +public class SSDPNotifySocket extends HTTPMUSocket implements Runnable { private boolean useIPv6Address; - - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public SSDPNotifySocket(String bindAddr) + + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public SSDPNotifySocket(String bindAddr) { String addr = SSDP.ADDRESS; useIPv6Address = false; @@ -47,24 +48,24 @@ public class SSDPNotifySocket extends HTTPMUSocket implements Runnable useIPv6Address = true; } open(addr, SSDP.PORT, bindAddr); - setControlPoint(null); - } - - //////////////////////////////////////////////// - // ControlPoint - //////////////////////////////////////////////// - - private ControlPoint controlPoint = null; - - public void setControlPoint(ControlPoint ctrlp) - { - this.controlPoint = ctrlp; - } - - public ControlPoint getControlPoint() - { - return controlPoint; - } + setControlPoint(null); + } + + //////////////////////////////////////////////// + // ControlPoint + //////////////////////////////////////////////// + + private ControlPoint controlPoint = null; + + public void setControlPoint(ControlPoint ctrlp) + { + this.controlPoint = ctrlp; + } + + public ControlPoint getControlPoint() + { + return controlPoint; + } //////////////////////////////////////////////// // post (SSDPNotifySocket) @@ -79,20 +80,20 @@ public class SSDPNotifySocket extends HTTPMUSocket implements Runnable return post((HTTPRequest)req); } - //////////////////////////////////////////////// - // run - //////////////////////////////////////////////// - - private Thread deviceNotifyThread = null; - - public void run() - { + //////////////////////////////////////////////// + // run + //////////////////////////////////////////////// + + private Thread deviceNotifyThread = null; + + public void run() + { Thread thisThread = Thread.currentThread(); - + ControlPoint ctrlPoint = getControlPoint(); - - while (deviceNotifyThread == thisThread) { - Thread.yield(); + + while (deviceNotifyThread == thisThread) { + Thread.yield(); SSDPPacket packet = receive(); // Thanks for Mikael Hakman (04/20/05) @@ -109,23 +110,23 @@ public class SSDPNotifySocket extends HTTPMUSocket implements Runnable } if (ctrlPoint != null) - ctrlPoint.notifyReceived(packet); - } - } - - public void start() - { + ctrlPoint.notifyReceived(packet); + } + } + + public void start() + { deviceNotifyThread = new Thread(this, "UPnP-SSDPNotifySocket"); - deviceNotifyThread.setDaemon(true); - deviceNotifyThread.start(); - } - - public void stop() - { + deviceNotifyThread.setDaemon(true); + deviceNotifyThread.start(); + } + + public void stop() + { // Thanks for Mikael Hakman (04/20/05) close(); - deviceNotifyThread = null; - } + deviceNotifyThread = null; + } } - + diff --git a/router/java/src/org/cybergarage/upnp/ssdp/SSDPPacket.java b/router/java/src/org/cybergarage/upnp/ssdp/SSDPPacket.java index 717856f937cbb756153b62817af7ff4ca19b14db..d2e0f2770566a632f222363193163785cb75f1ab 100644 --- a/router/java/src/org/cybergarage/upnp/ssdp/SSDPPacket.java +++ b/router/java/src/org/cybergarage/upnp/ssdp/SSDPPacket.java @@ -5,11 +5,11 @@ * Copyright (C) Satoshi Konno 2002-2003 * * File: SSDPPacket.java -* -* Revision; -* -* 11/18/02 -* - first revision. +* +* Revision; +* +* 11/18/02 +* - first revision. * 05/13/03 * - Added getLocalAddress(). * 11/01/04 @@ -20,25 +20,25 @@ * - Changed getRemoteAddress() to return the adresss instead of the host name. * ******************************************************************/ - -package org.cybergarage.upnp.ssdp; - -import java.net.*; - + +package org.cybergarage.upnp.ssdp; + +import java.net.*; + import org.cybergarage.http.*; -import org.cybergarage.upnp.device.*; - -public class SSDPPacket -{ - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public SSDPPacket(byte[] buf, int length) - { - dgmPacket = new DatagramPacket(buf, length); - } +import org.cybergarage.upnp.device.*; + +public class SSDPPacket +{ + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public SSDPPacket(byte[] buf, int length) + { + dgmPacket = new DatagramPacket(buf, length); + } //////////////////////////////////////////////// // DatagramPacket @@ -68,115 +68,115 @@ public class SSDPPacket } - //////////////////////////////////////////////// - // Time - //////////////////////////////////////////////// - - private long timeStamp; - - public void setTimeStamp(long value) - { - timeStamp = value; - } - - public long getTimeStamp() - { - return timeStamp; - } - - //////////////////////////////////////////////// - // Remote host - //////////////////////////////////////////////// + //////////////////////////////////////////////// + // Time + //////////////////////////////////////////////// + + private long timeStamp; + + public void setTimeStamp(long value) + { + timeStamp = value; + } + + public long getTimeStamp() + { + return timeStamp; + } + + //////////////////////////////////////////////// + // Remote host + //////////////////////////////////////////////// public InetAddress getRemoteInetAddress() { return getDatagramPacket().getAddress(); } - public String getRemoteAddress() - { + public String getRemoteAddress() + { // Thanks for Theo Beisch (11/09/04) - return getDatagramPacket().getAddress().getHostAddress(); - } - - public int getRemotePort() - { - return getDatagramPacket().getPort(); - } - - //////////////////////////////////////////////// - // Access Methods - //////////////////////////////////////////////// - - public byte[] packetBytes = null; - - public byte[] getData() - { - if (packetBytes != null) - return packetBytes; - - DatagramPacket packet = getDatagramPacket(); - int packetLen = packet.getLength(); - String packetData = new String(packet.getData(), 0, packetLen); - packetBytes = packetData.getBytes(); - - return packetBytes; - } - - //////////////////////////////////////////////// - // Access Methods - //////////////////////////////////////////////// - - public String getHost() - { - return HTTPHeader.getValue(getData(), HTTP.HOST); - } - - public String getCacheControl() - { - return HTTPHeader.getValue(getData(), HTTP.CACHE_CONTROL); - } - - public String getLocation() - { - return HTTPHeader.getValue(getData(), HTTP.LOCATION); - } - - public String getMAN() - { - return HTTPHeader.getValue(getData(), HTTP.MAN); - } + return getDatagramPacket().getAddress().getHostAddress(); + } + + public int getRemotePort() + { + return getDatagramPacket().getPort(); + } + + //////////////////////////////////////////////// + // Access Methods + //////////////////////////////////////////////// + + public byte[] packetBytes = null; + + public byte[] getData() + { + if (packetBytes != null) + return packetBytes; + + DatagramPacket packet = getDatagramPacket(); + int packetLen = packet.getLength(); + String packetData = new String(packet.getData(), 0, packetLen); + packetBytes = packetData.getBytes(); + + return packetBytes; + } + + //////////////////////////////////////////////// + // Access Methods + //////////////////////////////////////////////// + + public String getHost() + { + return HTTPHeader.getValue(getData(), HTTP.HOST); + } + + public String getCacheControl() + { + return HTTPHeader.getValue(getData(), HTTP.CACHE_CONTROL); + } + + public String getLocation() + { + return HTTPHeader.getValue(getData(), HTTP.LOCATION); + } + + public String getMAN() + { + return HTTPHeader.getValue(getData(), HTTP.MAN); + } public String getST() { return HTTPHeader.getValue(getData(), HTTP.ST); } - - public String getNT() - { - return HTTPHeader.getValue(getData(), HTTP.NT); - } - - public String getNTS() - { - return HTTPHeader.getValue(getData(), HTTP.NTS); - } - - public String getServer() - { - return HTTPHeader.getValue(getData(), HTTP.SERVER); - } - - public String getUSN() - { - return HTTPHeader.getValue(getData(), HTTP.USN); - } - - public int getMX() - { - return HTTPHeader.getIntegerValue(getData(), HTTP.MX); - } - + + public String getNT() + { + return HTTPHeader.getValue(getData(), HTTP.NT); + } + + public String getNTS() + { + return HTTPHeader.getValue(getData(), HTTP.NTS); + } + + public String getServer() + { + return HTTPHeader.getValue(getData(), HTTP.SERVER); + } + + public String getUSN() + { + return HTTPHeader.getValue(getData(), HTTP.USN); + } + + public int getMX() + { + return HTTPHeader.getIntegerValue(getData(), HTTP.MX); + } + //////////////////////////////////////////////// // Access Methods //////////////////////////////////////////////// @@ -197,48 +197,47 @@ public class SSDPPacket return isockaddr.getAddress(); } - //////////////////////////////////////////////// - // Access Methods (Extension) - //////////////////////////////////////////////// - - public boolean isRootDevice() - { - if (NT.isRootDevice(getNT()) == true) + //////////////////////////////////////////////// + // Access Methods (Extension) + //////////////////////////////////////////////// + + public boolean isRootDevice() + { + if (NT.isRootDevice(getNT()) == true) return true; - // Thanks for Theo Beisch (11/01/04) + // Thanks for Theo Beisch (11/01/04) if (ST.isRootDevice(getST()) == true) return true; - return USN.isRootDevice(getUSN()); - } - - public boolean isDiscover() - { - return MAN.isDiscover(getMAN()); - } - - public boolean isAlive() - { - return NTS.isAlive(getNTS()); - } - - public boolean isByeBye() - { - return NTS.isByeBye(getNTS()); - } - - public int getLeaseTime() - { - return SSDP.getLeaseTime(getCacheControl()); - } + return USN.isRootDevice(getUSN()); + } + + public boolean isDiscover() + { + return MAN.isDiscover(getMAN()); + } + + public boolean isAlive() + { + return NTS.isAlive(getNTS()); + } + + public boolean isByeBye() + { + return NTS.isByeBye(getNTS()); + } + + public int getLeaseTime() + { + return SSDP.getLeaseTime(getCacheControl()); + } //////////////////////////////////////////////// // toString //////////////////////////////////////////////// - @Override public String toString() { return new String(getData()); } } - + diff --git a/router/java/src/org/cybergarage/upnp/ssdp/SSDPResponse.java b/router/java/src/org/cybergarage/upnp/ssdp/SSDPResponse.java index 3bbbfcbb822af62d5fd70abf972a62743c13d3fc..31b4ed280ec9178940aabbba7c615c649ed1a5a6 100644 --- a/router/java/src/org/cybergarage/upnp/ssdp/SSDPResponse.java +++ b/router/java/src/org/cybergarage/upnp/ssdp/SSDPResponse.java @@ -112,7 +112,6 @@ public class SSDPResponse extends HTTPResponse // getHeader (Override) //////////////////////////////////////////////// - @Override public String getHeader() { StringBuilder str = new StringBuilder(); diff --git a/router/java/src/org/cybergarage/util/ListenerList.java b/router/java/src/org/cybergarage/util/ListenerList.java index b02c0ddc8c3eae2fc9670675c9e103fea35e94ff..afdeff0d65804d322a00d2e8eb55d4b0080438a9 100644 --- a/router/java/src/org/cybergarage/util/ListenerList.java +++ b/router/java/src/org/cybergarage/util/ListenerList.java @@ -3,7 +3,7 @@ * CyberUtil for Java * * Copyright (C) Satoshi Konno 2002 -* +* * File: ListenerList.java * * Revision; @@ -12,16 +12,15 @@ * - first revision. * ******************************************************************/ - + package org.cybergarage.util; import java.util.*; - + public class ListenerList extends Vector { private static final long serialVersionUID = 8039231561720446173L; - @Override public boolean add(Object obj) { if (0 <= indexOf(obj)) diff --git a/router/java/src/org/cybergarage/util/Mutex.java b/router/java/src/org/cybergarage/util/Mutex.java index aa13afe6274e76b1a098ce40eed51fad6d93d18a..f26351271c317a5906d20e6666dc3072b8f97342 100644 --- a/router/java/src/org/cybergarage/util/Mutex.java +++ b/router/java/src/org/cybergarage/util/Mutex.java @@ -40,7 +40,7 @@ public class Mutex } catch (Exception e) { Debug.warning(e); - } + }; } syncLock = true; } diff --git a/router/java/src/org/cybergarage/xml/Node.java b/router/java/src/org/cybergarage/xml/Node.java index 4fee0fdee1a12ea00aa033b5efd4a87246421d66..93ca5aa0b38b351edb7b75243ecfb700239e3f40 100644 --- a/router/java/src/org/cybergarage/xml/Node.java +++ b/router/java/src/org/cybergarage/xml/Node.java @@ -74,10 +74,10 @@ public class Node public Node getRootNode() { Node rootNode = null; - Node _parentNode = getParentNode(); - while (_parentNode != null) { - rootNode = _parentNode; - _parentNode = rootNode.getParentNode(); + Node parentNode = getParentNode(); + while (parentNode != null) { + rootNode = parentNode; + parentNode = rootNode.getParentNode(); } return rootNode; } @@ -338,24 +338,24 @@ public class Node { String indentString = getIndentLevelString(indentLevel); - String _name = getName(); - String _value = getValue(); + String name = getName(); + String value = getValue(); if (hasNodes() == false || hasChildNode == false) { - ps.print(indentString + "<" + _name); + ps.print(indentString + "<" + name); outputAttributes(ps); // Thnaks for Tho Beisch (11/09/04) - if (_value == null || _value.length() == 0) { + if (value == null || value.length() == 0) { // No value, so use short notation <node /> ps.println(" />"); } else { - ps.println(">" + XML.escapeXMLChars(_value) + "</" + _name + ">"); + ps.println(">" + XML.escapeXMLChars(value) + "</" + name + ">"); } return; } - ps.print(indentString + "<" + _name); + ps.print(indentString + "<" + name); outputAttributes(ps); ps.println(">"); @@ -365,7 +365,7 @@ public class Node cnode.output(ps, indentLevel+1, true); } - ps.println(indentString +"</" + _name + ">"); + ps.println(indentString +"</" + name + ">"); } public String toString(boolean hasChildNode)