org.fourthline.cling.model.ModelUtil Java Examples
The following examples show how to use
org.fourthline.cling.model.ModelUtil.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StateVariable.java From DroidDLNA with GNU General Public License v3.0 | 6 votes |
public List<ValidationError> validate() { List<ValidationError> errors = new ArrayList(); if (getName() == null || getName().length() == 0) { errors.add(new ValidationError( getClass(), "name", "StateVariable without name of: " + getService() )); } else if (!ModelUtil.isValidUDAName(getName())) { log.warning("UPnP specification violation of: " + getService().getDevice()); log.warning("Invalid state variable name: " + this); } errors.addAll(getTypeDetails().validate()); return errors; }
Example #2
Source File: OutgoingNotificationRequest.java From DroidDLNA with GNU General Public License v3.0 | 6 votes |
protected OutgoingNotificationRequest(Location location, LocalDevice device, NotificationSubtype type) { super( new UpnpRequest(UpnpRequest.Method.NOTIFY), ModelUtil.getInetAddressByName(Constants.IPV4_UPNP_MULTICAST_GROUP), Constants.UPNP_MULTICAST_PORT ); this.type = type; getHeaders().add(UpnpHeader.Type.MAX_AGE, new MaxAgeHeader(device.getIdentity().getMaxAgeSeconds())); getHeaders().add(UpnpHeader.Type.LOCATION, new LocationHeader(location.getURL())); getHeaders().add(UpnpHeader.Type.SERVER, new ServerHeader()); getHeaders().add(UpnpHeader.Type.HOST, new HostHeader()); getHeaders().add(UpnpHeader.Type.NTS, new NTSHeader(type)); }
Example #3
Source File: StateVariable.java From TVRemoteIME with GNU General Public License v2.0 | 6 votes |
public List<ValidationError> validate() { List<ValidationError> errors = new ArrayList(); if (getName() == null || getName().length() == 0) { errors.add(new ValidationError( getClass(), "name", "StateVariable without name of: " + getService() )); } else if (!ModelUtil.isValidUDAName(getName())) { log.warning("UPnP specification violation of: " + getService().getDevice()); log.warning("Invalid state variable name: " + this); } errors.addAll(getTypeDetails().validate()); return errors; }
Example #4
Source File: DefaultUpnpServiceConfiguration.java From DroidDLNA with GNU General Public License v3.0 | 6 votes |
protected DefaultUpnpServiceConfiguration(int streamListenPort, boolean checkRuntime) { if (checkRuntime && ModelUtil.ANDROID_RUNTIME) { throw new Error("Unsupported runtime environment, use org.fourthline.cling.android.AndroidUpnpServiceConfiguration"); } this.streamListenPort = streamListenPort; defaultExecutorService = createDefaultExecutorService(); datagramProcessor = createDatagramProcessor(); soapActionProcessor = createSOAPActionProcessor(); genaEventProcessor = createGENAEventProcessor(); deviceDescriptorBinderUDA10 = createDeviceDescriptorBinderUDA10(); serviceDescriptorBinderUDA10 = createServiceDescriptorBinderUDA10(); namespace = createNamespace(); }
Example #5
Source File: OutgoingNotificationRequest.java From TVRemoteIME with GNU General Public License v2.0 | 6 votes |
protected OutgoingNotificationRequest(Location location, LocalDevice device, NotificationSubtype type) { super( new UpnpRequest(UpnpRequest.Method.NOTIFY), ModelUtil.getInetAddressByName(Constants.IPV4_UPNP_MULTICAST_GROUP), Constants.UPNP_MULTICAST_PORT ); this.type = type; getHeaders().add(UpnpHeader.Type.MAX_AGE, new MaxAgeHeader(device.getIdentity().getMaxAgeSeconds())); getHeaders().add(UpnpHeader.Type.LOCATION, new LocationHeader(location.getURL())); getHeaders().add(UpnpHeader.Type.SERVER, new ServerHeader()); getHeaders().add(UpnpHeader.Type.HOST, new HostHeader()); getHeaders().add(UpnpHeader.Type.NTS, new NTSHeader(type)); }
Example #6
Source File: DefaultUpnpServiceConfiguration.java From TVRemoteIME with GNU General Public License v2.0 | 6 votes |
protected DefaultUpnpServiceConfiguration(int streamListenPort, boolean checkRuntime) { if (checkRuntime && ModelUtil.ANDROID_RUNTIME) { throw new Error("Unsupported runtime environment, use org.fourthline.cling.android.AndroidUpnpServiceConfiguration"); } this.streamListenPort = streamListenPort; defaultExecutorService = createDefaultExecutorService(); datagramProcessor = createDatagramProcessor(); soapActionProcessor = createSOAPActionProcessor(); genaEventProcessor = createGENAEventProcessor(); deviceDescriptorBinderUDA10 = createDeviceDescriptorBinderUDA10(); serviceDescriptorBinderUDA10 = createServiceDescriptorBinderUDA10(); namespace = createNamespace(); }
Example #7
Source File: AndroidRouter.java From TVRemoteIME with GNU General Public License v2.0 | 5 votes |
public AndroidRouter(UpnpServiceConfiguration configuration, ProtocolFactory protocolFactory, Context context) throws InitializationException { super(configuration, protocolFactory); this.context = context; this.wifiManager = ((WifiManager) context.getSystemService(Context.WIFI_SERVICE)); this.networkInfo = NetworkUtils.getConnectedNetworkInfo(context); // Only register for network connectivity changes if we are not running on emulator if (!ModelUtil.ANDROID_EMULATOR) { this.broadcastReceiver = new ConnectivityBroadcastReceiver(); context.registerReceiver(broadcastReceiver, new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE")); } }
Example #8
Source File: RemoteDeviceIdentity.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
@Override public String toString() { // Performance optimization, so we don't have to wrap all log("foo " + device) calls with isLoggable if(ModelUtil.ANDROID_RUNTIME) { return "(RemoteDeviceIdentity) UDN: " + getUdn() + ", Descriptor: " + getDescriptorURL(); } return "(" + getClass().getSimpleName() + ") UDN: " + getUdn() + ", Descriptor: " + getDescriptorURL(); }
Example #9
Source File: AnnotationActionBinder.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
protected void validateType(StateVariable stateVariable, Class type) throws LocalServiceBindingException { // Validate datatype as good as we can // (for enums and other convertible types, the state variable type should be STRING) Datatype.Default expectedDefaultMapping = ModelUtil.isStringConvertibleType(getStringConvertibleTypes(), type) ? Datatype.Default.STRING : Datatype.Default.getByJavaType(type); log.finer("Expecting '" + stateVariable + "' to match default mapping: " + expectedDefaultMapping); if (expectedDefaultMapping != null && !stateVariable.getTypeDetails().getDatatype().isHandlingJavaType(expectedDefaultMapping.getJavaType())) { // TODO: Consider custom types?! throw new LocalServiceBindingException( "State variable '" + stateVariable + "' datatype can't handle action " + "argument's Java type (change one): " + expectedDefaultMapping.getJavaType() ); } else if (expectedDefaultMapping == null && stateVariable.getTypeDetails().getDatatype().getBuiltin() != null) { throw new LocalServiceBindingException( "State variable '" + stateVariable + "' should be custom datatype " + "(action argument type is unknown Java type): " + type.getSimpleName() ); } log.finer("State variable matches required argument datatype (or can't be validated because it is custom)"); }
Example #10
Source File: AnnotationActionBinder.java From TVRemoteIME with GNU General Public License v2.0 | 5 votes |
protected void validateType(StateVariable stateVariable, Class type) throws LocalServiceBindingException { // Validate datatype as good as we can // (for enums and other convertible types, the state variable type should be STRING) Datatype.Default expectedDefaultMapping = ModelUtil.isStringConvertibleType(getStringConvertibleTypes(), type) ? Datatype.Default.STRING : Datatype.Default.getByJavaType(type); log.finer("Expecting '" + stateVariable + "' to match default mapping: " + expectedDefaultMapping); if (expectedDefaultMapping != null && !stateVariable.getTypeDetails().getDatatype().isHandlingJavaType(expectedDefaultMapping.getJavaType())) { // TODO: Consider custom types?! throw new LocalServiceBindingException( "State variable '" + stateVariable + "' datatype can't handle action " + "argument's Java type (change one): " + expectedDefaultMapping.getJavaType() ); } else if (expectedDefaultMapping == null && stateVariable.getTypeDetails().getDatatype().getBuiltin() != null) { throw new LocalServiceBindingException( "State variable '" + stateVariable + "' should be custom datatype " + "(action argument type is unknown Java type): " + type.getSimpleName() ); } log.finer("State variable matches required argument datatype (or can't be validated because it is custom)"); }
Example #11
Source File: MediaResourceDao.java From BeyondUPnP with Apache License 2.0 | 5 votes |
public static List<Item> getAudioList(String serverUrl, String parentId) { List<Item> items = new ArrayList<>(); //Query all track,add to items Cursor c = BeyondApplication.getApplication().getContentResolver() .query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Audio.Media.TITLE); c.moveToFirst(); while (!c.isAfterLast()) { long id = c.getLong(c.getColumnIndex(MediaStore.Audio.Media._ID)); String title = c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE)); String creator = c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST)); String album = c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM)); String data = c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA)); //Remove SDCard path data = data.replaceFirst(storageDir, ""); //Replace file name by "id.ext" String fileName = data.substring(data.lastIndexOf(File.separator)); String ext = fileName.substring(fileName.lastIndexOf(".")); data = data.replace(fileName, File.separator + id + ext); String mimeType = c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.Media.MIME_TYPE)); long size = c.getLong(c.getColumnIndexOrThrow(MediaStore.Audio.Media.SIZE)); long duration = c.getLong(c.getColumnIndexOrThrow(MediaStore.Audio.Media.DURATION)); //Get duration string String durationStr = ModelUtil.toTimeString(duration); //Compose audio url String url = serverUrl + File.separator + "audio" + File.separator + data; Res res = new Res(mimeType, size, durationStr, null, url); items.add(new MusicTrack(String.valueOf(id), parentId, title, creator, album, new PersonWithRole(creator), res)); c.moveToNext(); } return items; }
Example #12
Source File: ZxtMediaPlayer.java From TVRemoteIME with GNU General Public License v2.0 | 5 votes |
public void durationChanged(int duration) { log.fine("Duration Changed event received: " + duration); synchronized (ZxtMediaPlayer.this) { String newValue = ModelUtil.toTimeString(duration/1000); currentMediaInfo = new MediaInfo(currentMediaInfo.getCurrentURI(), "", new UnsignedIntegerFourBytes(1), newValue, StorageMedium.NETWORK); getAvTransportLastChange().setEventedValue(getInstanceId(), new AVTransportVariable.CurrentTrackDuration(newValue), new AVTransportVariable.CurrentMediaDuration(newValue)); } }
Example #13
Source File: ZxtMediaPlayer.java From TVRemoteIME with GNU General Public License v2.0 | 5 votes |
public void positionChanged(int position) { log.fine("Position Changed event received: " + position); synchronized (ZxtMediaPlayer.this) { currentPositionInfo = new PositionInfo(1, currentMediaInfo.getMediaDuration(), currentMediaInfo.getCurrentURI(), ModelUtil.toTimeString(position/1000), ModelUtil.toTimeString(position/1000)); } }
Example #14
Source File: CSV.java From TVRemoteIME with GNU General Public License v2.0 | 5 votes |
protected List parseString(String s) throws InvalidValueException { String[] strings = ModelUtil.fromCommaSeparatedList(s); List values = new ArrayList(); for (String string : strings) { values.add(datatype.getDatatype().valueOf(string)); } return values; }
Example #15
Source File: AVTransportLastChangeParser.java From TVRemoteIME with GNU General Public License v2.0 | 5 votes |
@Override protected Source[] getSchemaSources() { // TODO: Android 2.2 has a broken SchemaFactory, we can't validate // http://code.google.com/p/android/issues/detail?id=9491&q=schemafactory&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars if (!ModelUtil.ANDROID_RUNTIME) { return new Source[]{new StreamSource( Thread.currentThread().getContextClassLoader().getResourceAsStream(SCHEMA_RESOURCE) )}; } return null; }
Example #16
Source File: CSV.java From TVRemoteIME with GNU General Public License v2.0 | 5 votes |
@Override public String toString() { List<String> stringValues = new ArrayList(); for (T t : this) { stringValues.add(datatype.getDatatype().getString(t)); } return ModelUtil.toCommaSeparatedList(stringValues.toArray(new Object[stringValues.size()])); }
Example #17
Source File: AbstractAVTransportService.java From TVRemoteIME with GNU General Public License v2.0 | 5 votes |
@UpnpAction(name = "GetCurrentTransportActions", out = @UpnpOutputArgument(name = "Actions", stateVariable = "CurrentTransportActions")) public String getCurrentTransportActionsString(@UpnpInputArgument(name = "InstanceID") UnsignedIntegerFourBytes instanceId) throws AVTransportException { try { return ModelUtil.toCommaSeparatedList(getCurrentTransportActions(instanceId)); } catch (Exception ex) { return ""; // TODO: Empty string is not defined in spec but seems reasonable for no available action? } }
Example #18
Source File: MediaResourceDao.java From BeyondUPnP with Apache License 2.0 | 5 votes |
public static List<Item> getVideoList(String serverUrl, String parentId) { List<Item> items = new ArrayList<>(); Cursor c = BeyondApplication.getApplication().getContentResolver() .query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Video.Media.TITLE); c.moveToFirst(); while (!c.isAfterLast()) { long id = c.getLong(c.getColumnIndex(MediaStore.Audio.Media._ID)); String title = c.getString(c.getColumnIndexOrThrow(MediaStore.Video.Media.TITLE)); String creator = c.getString(c.getColumnIndexOrThrow(MediaStore.Video.Media.ARTIST)); String data = c.getString(c.getColumnIndexOrThrow(MediaStore.Video.Media.DATA)); //Remove SDCard path data = data.replaceFirst(storageDir, ""); //Replace file name by "id.ext" String fileName = data.substring(data.lastIndexOf(File.separator)); String ext = fileName.substring(fileName.lastIndexOf(".")); data = data.replace(fileName, File.separator + id + ext); String mimeType = c.getString(c.getColumnIndexOrThrow(MediaStore.Video.Media.MIME_TYPE)); long size = c.getLong(c.getColumnIndexOrThrow(MediaStore.Video.Media.SIZE)); long duration = c.getLong(c.getColumnIndexOrThrow(MediaStore.Video.Media.DURATION)); //Get duration string String durationStr = ModelUtil.toTimeString(duration); //Compose audio url String url = serverUrl + File.separator + "video" + File.separator + data; Res res = new Res(mimeType, size, durationStr, null, url); items.add(new Movie(String.valueOf(id), parentId, title, creator, res)); c.moveToNext(); } return items; }
Example #19
Source File: ActionArgument.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
public List<ValidationError> validate() { List<ValidationError> errors = new ArrayList(); if (getName() == null || getName().length() == 0) { errors.add(new ValidationError( getClass(), "name", "Argument without name of: " + getAction() )); } else if (!ModelUtil.isValidUDAName(getName())) { log.warning("UPnP specification violation of: " + getAction().getService().getDevice()); log.warning("Invalid argument name: " + this); } else if (getName().length() > 32) { log.warning("UPnP specification violation of: " + getAction().getService().getDevice()); log.warning("Argument name should be less than 32 characters: " + this); } if (getDirection() == null) { errors.add(new ValidationError( getClass(), "direction", "Argument '"+getName()+"' requires a direction, either IN or OUT" )); } if (isReturnValue() && getDirection() != ActionArgument.Direction.OUT) { errors.add(new ValidationError( getClass(), "direction", "Return value argument '" + getName() + "' must be direction OUT" )); } return errors; }
Example #20
Source File: OutgoingSearchRequest.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
public OutgoingSearchRequest(UpnpHeader searchTarget, int mxSeconds) { super( new UpnpRequest(UpnpRequest.Method.MSEARCH), ModelUtil.getInetAddressByName(Constants.IPV4_UPNP_MULTICAST_GROUP), Constants.UPNP_MULTICAST_PORT ); this.searchTarget = searchTarget; getHeaders().add(UpnpHeader.Type.MAN, new MANHeader(NotificationSubtype.DISCOVER.getHeaderString())); getHeaders().add(UpnpHeader.Type.MX, new MXHeader(mxSeconds)); getHeaders().add(UpnpHeader.Type.ST, searchTarget); getHeaders().add(UpnpHeader.Type.HOST, new HostHeader()); }
Example #21
Source File: SoapActionType.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
public SoapActionType(String namespace, String type, Integer version, String actionName) { this.namespace = namespace; this.type = type; this.version = version; this.actionName = actionName; if (actionName != null && !ModelUtil.isValidUDAName(actionName)) { throw new IllegalArgumentException("Action name contains illegal characters: " + actionName); } }
Example #22
Source File: CSV.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
protected List parseString(String s) throws InvalidValueException { String[] strings = ModelUtil.fromCommaSeparatedList(s); List values = new ArrayList(); for (String string : strings) { values.add(datatype.getDatatype().valueOf(string)); } return values; }
Example #23
Source File: CSV.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
@Override public String toString() { List<String> stringValues = new ArrayList(); for (T t : this) { stringValues.add(datatype.getDatatype().getString(t)); } return ModelUtil.toCommaSeparatedList(stringValues.toArray(new Object[stringValues.size()])); }
Example #24
Source File: AbstractAVTransportService.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
@UpnpAction(name = "GetCurrentTransportActions", out = @UpnpOutputArgument(name = "Actions", stateVariable = "CurrentTransportActions")) public String getCurrentTransportActionsString(@UpnpInputArgument(name = "InstanceID") UnsignedIntegerFourBytes instanceId) throws AVTransportException { try { return ModelUtil.toCommaSeparatedList(getCurrentTransportActions(instanceId)); } catch (Exception ex) { return ""; // TODO: Empty string is not defined in spec but seems reasonable for no available action? } }
Example #25
Source File: AVTransportLastChangeParser.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
@Override protected Source[] getSchemaSources() { // TODO: Android 2.2 has a broken SchemaFactory, we can't validate // http://code.google.com/p/android/issues/detail?id=9491&q=schemafactory&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars if (!ModelUtil.ANDROID_RUNTIME) { return new Source[]{new StreamSource( Thread.currentThread().getContextClassLoader().getResourceAsStream(SCHEMA_RESOURCE) )}; } return null; }
Example #26
Source File: PositionInfo.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
public PositionInfo(PositionInfo copy, long relTimeSeconds, long absTimeSeconds) { this.track = copy.track; this.trackDuration = copy.trackDuration; this.trackMetaData = copy.trackMetaData; this.trackURI = copy.trackURI; this.relTime = ModelUtil.toTimeString(relTimeSeconds); this.absTime = ModelUtil.toTimeString(absTimeSeconds); this.relCount = copy.relCount; this.absCount = copy.absCount; }
Example #27
Source File: RenderingControlLastChangeParser.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
@Override protected Source[] getSchemaSources() { // TODO: Android 2.2 has a broken SchemaFactory, we can't validate // http://code.google.com/p/android/issues/detail?id=9491&q=schemafactory&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars if (!ModelUtil.ANDROID_RUNTIME) { return new Source[]{new StreamSource( Thread.currentThread().getContextClassLoader().getResourceAsStream(SCHEMA_RESOURCE) )}; } return null; }
Example #28
Source File: AndroidRouter.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
public AndroidRouter(UpnpServiceConfiguration configuration, ProtocolFactory protocolFactory, Context context) throws InitializationException { super(configuration, protocolFactory); this.context = context; this.wifiManager = ((WifiManager) context.getSystemService(Context.WIFI_SERVICE)); this.networkInfo = NetworkUtils.getConnectedNetworkInfo(context); // Only register for network connectivity changes if we are not running on emulator if (!ModelUtil.ANDROID_EMULATOR) { this.broadcastReceiver = new ConnectivityBroadcastReceiver(); context.registerReceiver(broadcastReceiver, new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE")); } }
Example #29
Source File: ZxtMediaPlayer.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
public void positionChanged(int position) { log.fine("Position Changed event received: " + position); synchronized (ZxtMediaPlayer.this) { currentPositionInfo = new PositionInfo(1, currentMediaInfo.getMediaDuration(), currentMediaInfo.getCurrentURI(), ModelUtil.toTimeString(position/1000), ModelUtil.toTimeString(position/1000)); } }
Example #30
Source File: ZxtMediaPlayer.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
public void durationChanged(int duration) { log.fine("Duration Changed event received: " + duration); synchronized (ZxtMediaPlayer.this) { String newValue = ModelUtil.toTimeString(duration/1000); currentMediaInfo = new MediaInfo(currentMediaInfo.getCurrentURI(), "", new UnsignedIntegerFourBytes(1), newValue, StorageMedium.NETWORK); getAvTransportLastChange().setEventedValue(getInstanceId(), new AVTransportVariable.CurrentTrackDuration(newValue), new AVTransportVariable.CurrentMediaDuration(newValue)); } }