public List<ValidationError> validate() { List<ValidationError> errors = new ArrayList<>(); if (getMimeType() == null) { log.warning("UPnP specification violation of: " + getDevice()); log.warning("Invalid icon, missing mime type: " + this); if (getWidth() == 0) { log.warning("UPnP specification violation of: " + getDevice()); log.warning("Invalid icon, missing width: " + this); if (getHeight() == 0) { log.warning("UPnP specification violation of: " + getDevice()); log.warning("Invalid icon, missing height: " + this); if (getDepth() == 0) { log.warning("UPnP specification violation of: " + getDevice()); log.warning("Invalid icon, missing bitmap depth: " + this); if (getUri() == null) { errors.add(new ValidationError( getClass(), } else { try { URL testURI = getUri().toURL(); if (testURI == null) throw new MalformedURLException();
@Override public String toString() { return "Icon(" + getWidth() + "x" + getHeight() + ", MIME: " + getMimeType() + ") " + getUri(); } }
protected Icon findUsableIcon(Device device) { // Needs to be certain format and size for (Object o : device.getIcons()) { Icon icon = (Icon) o; if (icon.getWidth() <= 64 && icon.getHeight() <= 64 && isUsableImageType(icon.getMimeType())) return icon; } return null; }
public Icon build() { return new Icon(mimeType, width, height, depth, uri); } }
response = new StreamResponseMessage(icon.getData(), icon.getMimeType());
if (icon.getUri().isAbsolute()) { errors.add(new ValidationError( getClass(), "icons", "Local icon URI can not be absolute: " + icon.getUri() )); if (icon.getUri().toString().contains("../")) { errors.add(new ValidationError( getClass(), "icons", "Local icon URI must not contain '../': " + icon.getUri() )); if (icon.getUri().toString().startsWith("/")) { errors.add(new ValidationError( getClass(), "icons", "Local icon URI must not start with '/': " + icon.getUri() ));
public void onLocalDeviceComplete(@Observes @Phase.Complete LocalDeviceDiscovery discovery) { LocalDevice device = discovery.getDevice(); String[] labels = new String[]{ device.getDetails().getFriendlyName(), device.getDisplayString(), "(LOCAL) " + device.getType().getDisplayString() }; final DeviceItem deviceItem = new DeviceItem(device, labels); Icon usableIcon = findUsableIcon(device); if (usableIcon != null) { ImageIcon imageIcon = new ImageIcon(usableIcon.getData()); deviceItem.setIcon(imageIcon); } else { deviceItem.setIcon(getUnknownDeviceIcon(deviceItem.getLabel()[0])); } SwingUtilities.invokeLater(new Runnable() { public void run() { view.addDeviceItem(deviceItem); } }); }
protected Icon createDefaultDeviceIcon() { String iconPath = "img/48/mediarenderer.png"; try { return new Icon( "image/png", 48, 48, 8, MediaRenderer.class.getName(), MediaRenderer.class.getResourceAsStream(iconPath) ); } catch (IOException ex) { throw new RuntimeException("Could not load icon: " + iconPath, ex); } }
response = new StreamResponseMessage(icon.getData(), icon.getMimeType());
discovered.add(new IconResource(namespace.prefixIfRelative(this, icon.getUri()), icon));
protected Icon createDefaultDeviceIcon() { return new Icon( "image/png", 48, 48, 8,
response = new StreamResponseMessage(icon.getData(), icon.getMimeType());
new StreamRequestMessage(UpnpRequest.Method.GET, device.normalizeURI(usableIcon.getUri()));
protected void generateIconList(Namespace namespace, Device deviceModel, Document descriptor, Element deviceElement) { if (!deviceModel.hasIcons()) return; Element iconListElement = appendNewElement(descriptor, deviceElement, ELEMENT.iconList); for (Icon icon : deviceModel.getIcons()) { Element iconElement = appendNewElement(descriptor, iconListElement, ELEMENT.icon); appendNewElementIfNotNull(descriptor, iconElement, ELEMENT.mimetype, icon.getMimeType()); appendNewElementIfNotNull(descriptor, iconElement, ELEMENT.width, icon.getWidth()); appendNewElementIfNotNull(descriptor, iconElement, ELEMENT.height, icon.getHeight()); appendNewElementIfNotNull(descriptor, iconElement, ELEMENT.depth, icon.getDepth()); if (deviceModel instanceof RemoteDevice) { appendNewElementIfNotNull(descriptor, iconElement, ELEMENT.url, icon.getUri()); } else if (deviceModel instanceof LocalDevice) { appendNewElementIfNotNull(descriptor, iconElement, ELEMENT.url, namespace.getIconPath(icon)); } } }