|
|
@ -135,11 +135,18 @@ public class UPNPRootDevice extends UPNPDevice {
|
|
|
|
creationTime = System.currentTimeMillis();
|
|
|
|
creationTime = System.currentTimeMillis();
|
|
|
|
|
|
|
|
|
|
|
|
JXPathContext context = JXPathContext.newContext( this );
|
|
|
|
JXPathContext context = JXPathContext.newContext( this );
|
|
|
|
Pointer rootPtr = context.getPointer( "UPNPDevice/root" );
|
|
|
|
|
|
|
|
|
|
|
|
// registering this namespace because JxPath 1.3 is namespace aware per default - 2010-07-17 MiB
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context.registerNamespace("upnp", "urn:schemas-upnp-org:device-1-0");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Pointer rootPtr = context.getPointer( "UPNPDevice/upnp:root" );
|
|
|
|
JXPathContext rootCtx = context.getRelativeContext( rootPtr );
|
|
|
|
JXPathContext rootCtx = context.getRelativeContext( rootPtr );
|
|
|
|
|
|
|
|
rootCtx.setNamespaceContextPointer(rootPtr);
|
|
|
|
|
|
|
|
// rootCtx.registerNamespace(null, "urn:schemas-upnp-org:device-1-0");
|
|
|
|
|
|
|
|
|
|
|
|
specVersionMajor = Integer.parseInt( (String)rootCtx.getValue( "specVersion/major" ) );
|
|
|
|
specVersionMajor = Integer.parseInt( (String)rootCtx.getValue( "upnp:specVersion/upnp:major" ) );
|
|
|
|
specVersionMinor = Integer.parseInt( (String)rootCtx.getValue( "specVersion/minor" ) );
|
|
|
|
specVersionMinor = Integer.parseInt( (String)rootCtx.getValue( "upnp:specVersion/upnp:minor" ) );
|
|
|
|
|
|
|
|
|
|
|
|
if ( !( specVersionMajor == 1 && specVersionMinor == 0 ) ) {
|
|
|
|
if ( !( specVersionMajor == 1 && specVersionMinor == 0 ) ) {
|
|
|
|
throw new IllegalStateException( "Unsupported device version (" + specVersionMajor + "." + specVersionMinor + ")" );
|
|
|
|
throw new IllegalStateException( "Unsupported device version (" + specVersionMajor + "." + specVersionMinor + ")" );
|
|
|
@ -147,7 +154,7 @@ public class UPNPRootDevice extends UPNPDevice {
|
|
|
|
boolean buildURLBase = true;
|
|
|
|
boolean buildURLBase = true;
|
|
|
|
String base = null;
|
|
|
|
String base = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
base = (String)rootCtx.getValue( "URLBase" );
|
|
|
|
base = (String)rootCtx.getValue( "upnp:URLBase" );
|
|
|
|
if ( base != null && base.trim().length() > 0 ) {
|
|
|
|
if ( base != null && base.trim().length() > 0 ) {
|
|
|
|
URLBase = new URL( base );
|
|
|
|
URLBase = new URL( base );
|
|
|
|
if ( log.isDebugEnabled() ) log.debug( "device URLBase " + URLBase );
|
|
|
|
if ( log.isDebugEnabled() ) log.debug( "device URLBase " + URLBase );
|
|
|
@ -170,8 +177,9 @@ public class UPNPRootDevice extends UPNPDevice {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
URLBase = new URL( URL );
|
|
|
|
URLBase = new URL( URL );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Pointer devicePtr = rootCtx.getPointer( "device" );
|
|
|
|
Pointer devicePtr = rootCtx.getPointer( "upnp:device" );
|
|
|
|
JXPathContext deviceCtx = rootCtx.getRelativeContext( devicePtr );
|
|
|
|
JXPathContext deviceCtx = rootCtx.getRelativeContext( devicePtr );
|
|
|
|
|
|
|
|
deviceCtx.registerNamespace("upnp", "urn:schemas-upnp-org:device-1-0");
|
|
|
|
|
|
|
|
|
|
|
|
fillUPNPDevice( this, null, deviceCtx, URLBase );
|
|
|
|
fillUPNPDevice( this, null, deviceCtx, URLBase );
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -243,29 +251,29 @@ public class UPNPRootDevice extends UPNPDevice {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void fillUPNPDevice( UPNPDevice device, UPNPDevice parent, JXPathContext deviceCtx, URL baseURL ) throws MalformedURLException {
|
|
|
|
private void fillUPNPDevice( UPNPDevice device, UPNPDevice parent, JXPathContext deviceCtx, URL baseURL ) throws MalformedURLException {
|
|
|
|
|
|
|
|
|
|
|
|
device.deviceType = getMandatoryData( deviceCtx, "deviceType" );
|
|
|
|
device.deviceType = getMandatoryData( deviceCtx, "upnp:deviceType" );
|
|
|
|
if ( log.isDebugEnabled() ) log.debug( "parsing device " + device.deviceType );
|
|
|
|
if ( log.isDebugEnabled() ) log.debug( "parsing device " + device.deviceType );
|
|
|
|
device.friendlyName = getMandatoryData( deviceCtx, "friendlyName" );
|
|
|
|
device.friendlyName = getMandatoryData( deviceCtx, "upnp:friendlyName" );
|
|
|
|
device.manufacturer = getNonMandatoryData( deviceCtx, "manufacturer" );
|
|
|
|
device.manufacturer = getNonMandatoryData( deviceCtx, "upnp:manufacturer" );
|
|
|
|
String base = getNonMandatoryData( deviceCtx, "manufacturerURL" );
|
|
|
|
String base = getNonMandatoryData( deviceCtx, "upnp:manufacturerURL" );
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if ( base != null ) device.manufacturerURL = new URL( base );
|
|
|
|
if ( base != null ) device.manufacturerURL = new URL( base );
|
|
|
|
} catch ( java.net.MalformedURLException ex ) {
|
|
|
|
} catch ( java.net.MalformedURLException ex ) {
|
|
|
|
// crappy data provided, keep the field null
|
|
|
|
// crappy data provided, keep the field null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
device.presentationURL = getURL( getNonMandatoryData( deviceCtx, "presentationURL" ), URLBase );
|
|
|
|
device.presentationURL = getURL( getNonMandatoryData( deviceCtx, "upnp:presentationURL" ), URLBase );
|
|
|
|
} catch ( java.net.MalformedURLException ex ) {
|
|
|
|
} catch ( java.net.MalformedURLException ex ) {
|
|
|
|
// crappy data provided, keep the field null
|
|
|
|
// crappy data provided, keep the field null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
device.modelDescription = getNonMandatoryData( deviceCtx, "modelDescription" );
|
|
|
|
device.modelDescription = getNonMandatoryData( deviceCtx, "upnp:modelDescription" );
|
|
|
|
device.modelName = getMandatoryData( deviceCtx, "modelName" );
|
|
|
|
device.modelName = getMandatoryData( deviceCtx, "upnp:modelName" );
|
|
|
|
device.modelNumber = getNonMandatoryData( deviceCtx, "modelNumber" );
|
|
|
|
device.modelNumber = getNonMandatoryData( deviceCtx, "upnp:modelNumber" );
|
|
|
|
device.modelURL = getNonMandatoryData( deviceCtx, "modelURL" );
|
|
|
|
device.modelURL = getNonMandatoryData( deviceCtx, "upnp:modelURL" );
|
|
|
|
device.serialNumber = getNonMandatoryData( deviceCtx, "serialNumber" );
|
|
|
|
device.serialNumber = getNonMandatoryData( deviceCtx, "upnp:serialNumber" );
|
|
|
|
device.UDN = getMandatoryData( deviceCtx, "UDN" );
|
|
|
|
device.UDN = getMandatoryData( deviceCtx, "upnp:UDN" );
|
|
|
|
device.USN = UDN.concat( "::" ).concat( deviceType );
|
|
|
|
device.USN = UDN.concat( "::" ).concat( deviceType );
|
|
|
|
String tmp = getNonMandatoryData( deviceCtx, "UPC" );
|
|
|
|
String tmp = getNonMandatoryData( deviceCtx, "upnp:UPC" );
|
|
|
|
if ( tmp != null ) {
|
|
|
|
if ( tmp != null ) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
device.UPC = Long.parseLong( tmp );
|
|
|
|
device.UPC = Long.parseLong( tmp );
|
|
|
@ -280,19 +288,21 @@ public class UPNPRootDevice extends UPNPDevice {
|
|
|
|
|
|
|
|
|
|
|
|
Pointer deviceListPtr;
|
|
|
|
Pointer deviceListPtr;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
deviceListPtr = deviceCtx.getPointer( "deviceList" );
|
|
|
|
deviceListPtr = deviceCtx.getPointer( "upnp:deviceList" );
|
|
|
|
} catch ( JXPathException ex ) {
|
|
|
|
} catch ( JXPathException ex ) {
|
|
|
|
// no pointers for this device list, this can happen
|
|
|
|
// no pointers for this device list, this can happen
|
|
|
|
// if the device has no child devices, simply returning
|
|
|
|
// if the device has no child devices, simply returning
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
JXPathContext deviceListCtx = deviceCtx.getRelativeContext( deviceListPtr );
|
|
|
|
JXPathContext deviceListCtx = deviceCtx.getRelativeContext( deviceListPtr );
|
|
|
|
Double arraySize = (Double)deviceListCtx.getValue( "count( device )" );
|
|
|
|
deviceListCtx.registerNamespace("upnp", "urn:schemas-upnp-org:device-1-0");
|
|
|
|
|
|
|
|
Double arraySize = (Double)deviceListCtx.getValue( "count( upnp:device )" );
|
|
|
|
device.childDevices = new ArrayList();
|
|
|
|
device.childDevices = new ArrayList();
|
|
|
|
if ( log.isDebugEnabled() ) log.debug( "child devices count is " + arraySize );
|
|
|
|
if ( log.isDebugEnabled() ) log.debug( "child devices count is " + arraySize );
|
|
|
|
for ( int i = 1; i <= arraySize.intValue(); i++ ) {
|
|
|
|
for ( int i = 1; i <= arraySize.intValue(); i++ ) {
|
|
|
|
Pointer devicePtr = deviceListCtx.getPointer( "device[" + i + "]" );
|
|
|
|
Pointer devicePtr = deviceListCtx.getPointer( "upnp:device[" + i + "]" );
|
|
|
|
JXPathContext childDeviceCtx = deviceListCtx.getRelativeContext( devicePtr );
|
|
|
|
JXPathContext childDeviceCtx = deviceListCtx.getRelativeContext( devicePtr );
|
|
|
|
|
|
|
|
childDeviceCtx.registerNamespace("upnp", "urn:schemas-upnp-org:device-1-0");
|
|
|
|
UPNPDevice childDevice = new UPNPDevice();
|
|
|
|
UPNPDevice childDevice = new UPNPDevice();
|
|
|
|
fillUPNPDevice( childDevice, device, childDeviceCtx, baseURL );
|
|
|
|
fillUPNPDevice( childDevice, device, childDeviceCtx, baseURL );
|
|
|
|
if ( log.isDebugEnabled() ) log.debug( "adding child device " + childDevice.getDeviceType() );
|
|
|
|
if ( log.isDebugEnabled() ) log.debug( "adding child device " + childDevice.getDeviceType() );
|
|
|
@ -329,15 +339,17 @@ public class UPNPRootDevice extends UPNPDevice {
|
|
|
|
* file for a service entry is invalid
|
|
|
|
* file for a service entry is invalid
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void fillUPNPServicesList( UPNPDevice device, JXPathContext deviceCtx ) throws MalformedURLException {
|
|
|
|
private void fillUPNPServicesList( UPNPDevice device, JXPathContext deviceCtx ) throws MalformedURLException {
|
|
|
|
Pointer serviceListPtr = deviceCtx.getPointer( "serviceList" );
|
|
|
|
Pointer serviceListPtr = deviceCtx.getPointer( "upnp:serviceList" );
|
|
|
|
JXPathContext serviceListCtx = deviceCtx.getRelativeContext( serviceListPtr );
|
|
|
|
JXPathContext serviceListCtx = deviceCtx.getRelativeContext( serviceListPtr );
|
|
|
|
Double arraySize = (Double)serviceListCtx.getValue( "count( service )" );
|
|
|
|
serviceListCtx.registerNamespace("upnp", "urn:schemas-upnp-org:device-1-0");
|
|
|
|
|
|
|
|
Double arraySize = (Double)serviceListCtx.getValue( "count( upnp:service )" );
|
|
|
|
if ( log.isDebugEnabled() ) log.debug( "device services count is " + arraySize );
|
|
|
|
if ( log.isDebugEnabled() ) log.debug( "device services count is " + arraySize );
|
|
|
|
device.services = new ArrayList();
|
|
|
|
device.services = new ArrayList();
|
|
|
|
for ( int i = 1; i <= arraySize.intValue(); i++ ) {
|
|
|
|
for ( int i = 1; i <= arraySize.intValue(); i++ ) {
|
|
|
|
|
|
|
|
|
|
|
|
Pointer servicePtr = serviceListCtx.getPointer( "service["+i+"]" );
|
|
|
|
Pointer servicePtr = serviceListCtx.getPointer( "upnp:service["+i+"]" );
|
|
|
|
JXPathContext serviceCtx = serviceListCtx.getRelativeContext( servicePtr );
|
|
|
|
JXPathContext serviceCtx = serviceListCtx.getRelativeContext( servicePtr );
|
|
|
|
|
|
|
|
serviceCtx.registerNamespace("upnp", "urn:schemas-upnp-org:device-1-0");
|
|
|
|
// TODO possibility of bugs if deviceDefLoc contains a file name
|
|
|
|
// TODO possibility of bugs if deviceDefLoc contains a file name
|
|
|
|
URL base = URLBase != null ? URLBase : deviceDefLoc;
|
|
|
|
URL base = URLBase != null ? URLBase : deviceDefLoc;
|
|
|
|
UPNPService service = new UPNPService( serviceCtx, base, this );
|
|
|
|
UPNPService service = new UPNPService( serviceCtx, base, this );
|
|
|
@ -356,24 +368,25 @@ public class UPNPRootDevice extends UPNPDevice {
|
|
|
|
private void fillUPNPDeviceIconsList( UPNPDevice device, JXPathContext deviceCtx, URL baseURL ) throws MalformedURLException {
|
|
|
|
private void fillUPNPDeviceIconsList( UPNPDevice device, JXPathContext deviceCtx, URL baseURL ) throws MalformedURLException {
|
|
|
|
Pointer iconListPtr;
|
|
|
|
Pointer iconListPtr;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
iconListPtr = deviceCtx.getPointer( "iconList" );
|
|
|
|
iconListPtr = deviceCtx.getPointer( "upnp:iconList" );
|
|
|
|
} catch ( JXPathException ex ) {
|
|
|
|
} catch ( JXPathException ex ) {
|
|
|
|
// no pointers for icons list, this can happen
|
|
|
|
// no pointers for icons list, this can happen
|
|
|
|
// simply returning
|
|
|
|
// simply returning
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
JXPathContext iconListCtx = deviceCtx.getRelativeContext( iconListPtr );
|
|
|
|
JXPathContext iconListCtx = deviceCtx.getRelativeContext( iconListPtr );
|
|
|
|
Double arraySize = (Double)iconListCtx.getValue( "count( icon )" );
|
|
|
|
iconListCtx.registerNamespace("upnp", "urn:schemas-upnp-org:device-1-0");
|
|
|
|
|
|
|
|
Double arraySize = (Double)iconListCtx.getValue( "count( upnp:icon )" );
|
|
|
|
if ( log.isDebugEnabled() ) log.debug( "device icons count is " + arraySize );
|
|
|
|
if ( log.isDebugEnabled() ) log.debug( "device icons count is " + arraySize );
|
|
|
|
device.deviceIcons = new ArrayList();
|
|
|
|
device.deviceIcons = new ArrayList();
|
|
|
|
for ( int i = 1; i <= arraySize.intValue(); i++ ) {
|
|
|
|
for ( int i = 1; i <= arraySize.intValue(); i++ ) {
|
|
|
|
|
|
|
|
|
|
|
|
DeviceIcon ico = new DeviceIcon();
|
|
|
|
DeviceIcon ico = new DeviceIcon();
|
|
|
|
ico.mimeType = (String)iconListCtx.getValue( "icon["+i+"]/mimetype" );
|
|
|
|
ico.mimeType = (String)iconListCtx.getValue( "upnp:icon["+i+"]/upnp:mimetype" );
|
|
|
|
ico.width = Integer.parseInt( (String)iconListCtx.getValue( "icon["+i+"]/width" ) );
|
|
|
|
ico.width = Integer.parseInt( (String)iconListCtx.getValue( "upnp:icon["+i+"]/upnp:width" ) );
|
|
|
|
ico.height = Integer.parseInt( (String)iconListCtx.getValue( "icon["+i+"]/height" ) );
|
|
|
|
ico.height = Integer.parseInt( (String)iconListCtx.getValue( "upnp:icon["+i+"]/upnp:height" ) );
|
|
|
|
ico.depth = Integer.parseInt( (String)iconListCtx.getValue( "icon["+i+"]/depth" ) );
|
|
|
|
ico.depth = Integer.parseInt( (String)iconListCtx.getValue( "upnp:icon["+i+"]/upnp:depth" ) );
|
|
|
|
ico.url = getURL( (String)iconListCtx.getValue( "icon["+i+"]/url" ), baseURL );
|
|
|
|
ico.url = getURL( (String)iconListCtx.getValue( "upnp:icon["+i+"]/upnp:url" ), baseURL );
|
|
|
|
if ( log.isDebugEnabled() ) log.debug( "icon URL is " + ico.url );
|
|
|
|
if ( log.isDebugEnabled() ) log.debug( "icon URL is " + ico.url );
|
|
|
|
device.deviceIcons.add( ico );
|
|
|
|
device.deviceIcons.add( ico );
|
|
|
|
}
|
|
|
|
}
|
|
|
|