blob: a772516b56f743d2d3db99cac2fab96fb3213a90 [file] [log] [blame]
Francesco Furfariec7e1752006-10-02 13:37:04 +00001/*
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 Furfarid8bdb642006-04-04 23:33:40 +00009 *
Francesco Furfariec7e1752006-10-02 13:37:04 +000010 * http://www.apache.org/licenses/LICENSE-2.0
Francesco Furfarid8bdb642006-04-04 23:33:40 +000011 *
Francesco Furfariec7e1752006-10-02 13:37:04 +000012 * 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 Furfarid8bdb642006-04-04 23:33:40 +000018 */
19
Francesco Furfarid8bdb642006-04-04 23:33:40 +000020package org.apache.felix.upnp.basedriver.controller.impl;
21
22import org.apache.felix.upnp.extra.controller.DevicesInfo;
23import org.apache.felix.upnp.extra.controller.DriverController;
24
25import org.cybergarage.upnp.Device;
26import org.cybergarage.upnp.Service;
27
28import org.apache.felix.upnp.basedriver.Activator;
29import org.apache.felix.upnp.basedriver.importer.core.MyCtrlPoint;
30import org.apache.felix.upnp.basedriver.tool.Logger;
31
Francesco Furfarif2a67912006-07-17 17:08:02 +000032/*
Karl Paulsd312acc2007-06-18 20:38:33 +000033* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
Francesco Furfarif2a67912006-07-17 17:08:02 +000034*/
Francesco Furfarid8bdb642006-04-04 23:33:40 +000035public 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}