Francesco Furfari | ec7e175 | 2006-10-02 13:37:04 +0000 | [diff] [blame] | 1 | /*
|
| 2 | * Licensed to the Apache Software Foundation (ASF) under one
|
| 3 | * or more contributor license agreements. See the NOTICE file
|
| 4 | * distributed with this work for additional information
|
| 5 | * regarding copyright ownership. The ASF licenses this file
|
| 6 | * to you under the Apache License, Version 2.0 (the
|
| 7 | * "License"); you may not use this file except in compliance
|
| 8 | * with the License. You may obtain a copy of the License at
|
Francesco Furfari | d8bdb64 | 2006-04-04 23:33:40 +0000 | [diff] [blame] | 9 | *
|
Francesco Furfari | ec7e175 | 2006-10-02 13:37:04 +0000 | [diff] [blame] | 10 | * http://www.apache.org/licenses/LICENSE-2.0
|
Francesco Furfari | d8bdb64 | 2006-04-04 23:33:40 +0000 | [diff] [blame] | 11 | *
|
Francesco Furfari | ec7e175 | 2006-10-02 13:37:04 +0000 | [diff] [blame] | 12 | * Unless required by applicable law or agreed to in writing,
|
| 13 | * software distributed under the License is distributed on an
|
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
| 15 | * KIND, either express or implied. See the License for the
|
| 16 | * specific language governing permissions and limitations
|
| 17 | * under the License.
|
Francesco Furfari | d8bdb64 | 2006-04-04 23:33:40 +0000 | [diff] [blame] | 18 | */
|
| 19 |
|
Francesco Furfari | d8bdb64 | 2006-04-04 23:33:40 +0000 | [diff] [blame] | 20 | package org.apache.felix.upnp.basedriver.controller.impl;
|
| 21 |
|
| 22 | import org.apache.felix.upnp.extra.controller.DevicesInfo;
|
| 23 | import org.apache.felix.upnp.extra.controller.DriverController;
|
| 24 |
|
| 25 | import org.cybergarage.upnp.Device;
|
| 26 | import org.cybergarage.upnp.Service;
|
| 27 |
|
| 28 | import org.apache.felix.upnp.basedriver.Activator;
|
| 29 | import org.apache.felix.upnp.basedriver.importer.core.MyCtrlPoint;
|
| 30 | import org.apache.felix.upnp.basedriver.tool.Logger;
|
| 31 |
|
Francesco Furfari | f2a6791 | 2006-07-17 17:08:02 +0000 | [diff] [blame] | 32 | /*
|
Karl Pauls | d312acc | 2007-06-18 20:38:33 +0000 | [diff] [blame^] | 33 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
|
Francesco Furfari | f2a6791 | 2006-07-17 17:08:02 +0000 | [diff] [blame] | 34 | */
|
Francesco Furfari | d8bdb64 | 2006-04-04 23:33:40 +0000 | [diff] [blame] | 35 | public class DriverControllerImpl implements DriverController, DevicesInfo{
|
| 36 | private MyCtrlPoint myCtrl;
|
| 37 | private Logger logger = Activator.logger;
|
| 38 |
|
| 39 | public DriverControllerImpl(MyCtrlPoint myCtrl){
|
| 40 | this.myCtrl = myCtrl;
|
| 41 |
|
| 42 | }
|
| 43 |
|
| 44 | public void setLogLevel(int n) {
|
| 45 | logger.setLogLevel(n);
|
| 46 | }
|
| 47 |
|
| 48 | public int getLogLevel() {
|
| 49 | return logger.getLogLevel();
|
| 50 | }
|
| 51 |
|
| 52 | public void setCyberDebug(boolean b) {
|
| 53 | logger.setCyberDebug(b);
|
| 54 | }
|
| 55 |
|
| 56 | public boolean getCyberDebug() {
|
| 57 | return logger.getCyberDebug();
|
| 58 | }
|
| 59 |
|
| 60 | public String getLocationURL(String udn) {
|
| 61 | if (udn == null || udn.equals("")) throw new IllegalArgumentException("Invalid udn paramenter");
|
| 62 | Device device = myCtrl.getDevice(udn);
|
| 63 | if (device == null) logger.WARNING("getLocationURL():: No device data available for UDN:"+udn);
|
| 64 | return myCtrl.getDevice(udn).getLocation();
|
| 65 | }
|
| 66 |
|
| 67 | public String getSCPDURL(String udn, String serviceId) {
|
| 68 | if (udn == null || udn.equals("") ) throw new IllegalArgumentException("Invalid udn paramenter");
|
| 69 | if (serviceId == null || serviceId.equals("") ) throw new IllegalArgumentException("Invalid serviceId paramenter");
|
| 70 | Device device= myCtrl.getDevice(udn);
|
| 71 | if (device == null) {
|
| 72 | logger.WARNING("getSCPDURL():: No device data available for UDN: "+udn);
|
| 73 | return null;
|
| 74 | }
|
| 75 | Service service = device.getService(serviceId);
|
| 76 | if (service == null) {
|
| 77 | logger.WARNING("getSCPDURL():: No service data available for serviceId:"+serviceId + " of UDN " + udn);
|
| 78 | return null;
|
| 79 | }
|
| 80 | String scpd = service.getSCPDURL().trim();
|
| 81 | return resolveRelativeLink(device,scpd);
|
| 82 | }
|
| 83 |
|
| 84 | public String resolveRelativeUrl(String udn, String link) {
|
| 85 | if (udn == null || udn.equals("")) throw new IllegalArgumentException("Invalid udn paramenter");
|
| 86 | Device device = myCtrl.getDevice(udn);
|
| 87 | return resolveRelativeLink(device,link);
|
| 88 | }
|
| 89 |
|
| 90 | private String resolveRelativeLink(Device device, String link) {
|
| 91 | if ( device == null || link == null) return null;
|
| 92 | if (link.startsWith("http:"))
|
| 93 | return link;
|
| 94 | else {
|
| 95 | String hostname = "";
|
| 96 | String location = "";
|
| 97 | String urlBase = device.getURLBase().trim();
|
| 98 | //TODO Check if is more important URLBase or location
|
| 99 | if (urlBase.equals("")){
|
| 100 | location = device.getLocation().trim();
|
| 101 | int endHostnameIdx = location.indexOf("/",7);
|
| 102 | if (endHostnameIdx!=-1)
|
| 103 | hostname=location.substring(0,endHostnameIdx);
|
| 104 | else
|
| 105 | hostname = location;
|
| 106 | if (link.startsWith("/")){
|
| 107 | return hostname+link;
|
| 108 | }else{
|
| 109 | //TODO Check for link start with .. or /
|
| 110 | return location +link;
|
| 111 | }
|
| 112 | }
|
| 113 | else {
|
| 114 | return urlBase+link;
|
| 115 | }
|
| 116 | }
|
| 117 | }
|
| 118 |
|
| 119 | public void search(String target) {
|
| 120 | myCtrl.search(target);
|
| 121 | }
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 | }
|