org.fourthline.cling.model.types.InvalidValueException Java Examples

The following examples show how to use org.fourthline.cling.model.types.InvalidValueException. 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: DLNAPlaySpeedAttribute.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
public void setString(String s, String cf) throws InvalidDLNAProtocolAttributeException {
    TransportPlaySpeed[] value = null;
    if (s != null && s.length() != 0) {
        String[] speeds = s.split(",");
        try {
            value = new TransportPlaySpeed[speeds.length]; 
            for (int i = 0; i < speeds.length; i++) {
                value[i] = new TransportPlaySpeed(speeds[i]);
            }
        } catch (InvalidValueException invalidValueException) {
            value = null;
        }
    }
    if (value == null) {
        throw new InvalidDLNAProtocolAttributeException("Can't parse DLNA play speeds from: " + s);
    }
    setValue(value);
}
 
Example #2
Source File: TimeSeekRangeHeader.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void setString(String s) throws InvalidHeaderException {
    if (s.length() != 0) {
        String[] params = s.split(" ");
        if (params.length>0) {
            try {
                TimeSeekRangeType t = new TimeSeekRangeType(NormalPlayTimeRange.valueOf(params[0]));
                if (params.length > 1) {
                    t.setBytesRange(BytesRange.valueOf(params[1]));
                }
                setValue(t);
                return;
            } catch (InvalidValueException invalidValueException) {
                throw new InvalidHeaderException("Invalid TimeSeekRange header value: " + s + "; "+invalidValueException.getMessage());
            }
        }
    }
    throw new InvalidHeaderException("Invalid TimeSeekRange header value: " + s);
}
 
Example #3
Source File: NormalPlayTimeRange.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
public static NormalPlayTimeRange valueOf(String s, boolean mandatoryTimeEnd) throws InvalidValueException {
    if (s.startsWith(PREFIX)) {
        NormalPlayTime timeStart, timeEnd = null, timeDuration = null;
        String[] params = s.substring(PREFIX.length()).split("[-/]");
        switch (params.length) {
            case 3:
                if (params[2].length() != 0 && !params[2].equals("*")) {
                    timeDuration = NormalPlayTime.valueOf(params[2]);
                }
            case 2:
                if (params[1].length() != 0) {
                    timeEnd = NormalPlayTime.valueOf(params[1]);
                }
            case 1:
                if (params[0].length() != 0 && (!mandatoryTimeEnd || ( mandatoryTimeEnd && params.length>1))) {
                    timeStart = NormalPlayTime.valueOf(params[0]);
                    return new NormalPlayTimeRange(timeStart, timeEnd, timeDuration);
                }
            default:
                break;
        }
    }
    throw new InvalidValueException("Can't parse NormalPlayTimeRange: " + s);
}
 
Example #4
Source File: ProtocolFactoryImpl.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
protected boolean isSupportedServiceAdvertisement(IncomingDatagramMessage message) {
    ServiceType[] exclusiveServiceTypes = getUpnpService().getConfiguration().getExclusiveServiceTypes();
    if (exclusiveServiceTypes == null) return false; // Discovery is disabled
    if (exclusiveServiceTypes.length == 0) return true; // Any advertisement is fine

    String usnHeader = message.getHeaders().getFirstHeader(UpnpHeader.Type.USN.getHttpName());
    if (usnHeader == null) return false; // Not a service advertisement, drop it

    try {
        NamedServiceType nst = NamedServiceType.valueOf(usnHeader);
        for (ServiceType exclusiveServiceType : exclusiveServiceTypes) {
            if (nst.getServiceType().implementsVersion(exclusiveServiceType))
                return true;
        }
    } catch (InvalidValueException ex) {
        log.finest("Not a named service type header value: " + usnHeader);
    }
    log.fine("Service advertisement not supported, dropping it: " + usnHeader);
    return false;
}
 
Example #5
Source File: NormalPlayTime.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
public static NormalPlayTime valueOf(String s) throws InvalidValueException {
    Matcher matcher = pattern.matcher(s);
    if (matcher.matches()) {
        int msMultiplier = 0;
        try {
            if (matcher.group(1) != null) {
                msMultiplier = (int) Math.pow(10, 3 - matcher.group(5).length());
                return new NormalPlayTime(
                        Long.parseLong(matcher.group(1)),
                        Long.parseLong(matcher.group(2)),
                        Long.parseLong(matcher.group(3)),
                        Long.parseLong(matcher.group(5))*msMultiplier);
            } else {
                msMultiplier = (int) Math.pow(10, 3 - matcher.group(8).length());
                return new NormalPlayTime(
                        Long.parseLong(matcher.group(6)) * 1000 + Long.parseLong(matcher.group(8))*msMultiplier);
            }
        } catch (NumberFormatException ex1) {
        }
    }
    throw new InvalidValueException("Can't parse NormalPlayTime: " + s);
}
 
Example #6
Source File: ProtocolInfo.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
public ProtocolInfo(String s) throws InvalidValueException {
	if (s == null)
		throw new NullPointerException();
	s = s.trim();
	String[] split = s.split(":");
	
	//TODO
	//XGF
	// if (split.length != 4) {
	// throw new InvalidValueException("Can't parse ProtocolInfo string: " +
	// s);
	// }
	this.protocol = Protocol.valueOrNullOf(split[0]);
	this.network = split[1];
	this.contentFormat = split[2];
	if (split.length == 4) {
		this.additionalInfo = split[3];
	}
}
 
Example #7
Source File: TimeSeekRangeHeader.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void setString(String s) throws InvalidHeaderException {
    if (s.length() != 0) {
        String[] params = s.split(" ");
        if (params.length>0) {
            try {
                TimeSeekRangeType t = new TimeSeekRangeType(NormalPlayTimeRange.valueOf(params[0]));
                if (params.length > 1) {
                    t.setBytesRange(BytesRange.valueOf(params[1]));
                }
                setValue(t);
                return;
            } catch (InvalidValueException invalidValueException) {
                throw new InvalidHeaderException("Invalid TimeSeekRange header value: " + s + "; "+invalidValueException.getMessage());
            }
        }
    }
    throw new InvalidHeaderException("Invalid TimeSeekRange header value: " + s);
}
 
Example #8
Source File: BufferInfoType.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
public static BufferInfoType valueOf(String s) throws InvalidValueException {
    Matcher matcher = pattern.matcher(s);
    if (matcher.matches()) {
        try {
            Long dejitterSize = Long.parseLong(matcher.group(1));
            CodedDataBuffer cdb = null;
            Long targetDuration = null;
            Boolean fullnessReports = null;

            if (matcher.group(2) != null) {
                cdb = new CodedDataBuffer(Long.parseLong(matcher.group(3)),
                        TransferMechanism.values()[Integer.parseInt(matcher.group(4))]);
            }
            if (matcher.group(5) != null) {
                targetDuration = Long.parseLong(matcher.group(6));
            }
            if (matcher.group(7) != null) {
                fullnessReports = matcher.group(8).equals("1");
            }
            return new BufferInfoType(dejitterSize, cdb, targetDuration, fullnessReports);
        } catch (NumberFormatException ex1) {
        }
    }
    throw new InvalidValueException("Can't parse BufferInfoType: " + s);
}
 
Example #9
Source File: NormalPlayTime.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
public NormalPlayTime(long hours, long minutes, long seconds, long milliseconds) throws InvalidValueException {
    if (hours < 0) {
        throw new InvalidValueException("Invalid parameter hours: " + hours);
    }

    if (minutes < 0 || minutes > 59) {
        throw new InvalidValueException("Invalid parameter minutes: " + hours);
    }

    if (seconds < 0 || seconds > 59) {
        throw new InvalidValueException("Invalid parameter seconds: " + hours);
    }
    if (milliseconds < 0 || milliseconds > 999) {
        throw new InvalidValueException("Invalid parameter milliseconds: " + milliseconds);
    }

    this.milliseconds = (hours * 60 * 60 + minutes * 60 + seconds) * 1000 + milliseconds;
}
 
Example #10
Source File: NormalPlayTime.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
public static NormalPlayTime valueOf(String s) throws InvalidValueException {
    Matcher matcher = pattern.matcher(s);
    if (matcher.matches()) {
        int msMultiplier = 0;
        try {
            if (matcher.group(1) != null) {
                msMultiplier = (int) Math.pow(10, 3 - matcher.group(5).length());
                return new NormalPlayTime(
                        Long.parseLong(matcher.group(1)),
                        Long.parseLong(matcher.group(2)),
                        Long.parseLong(matcher.group(3)),
                        Long.parseLong(matcher.group(5))*msMultiplier);
            } else {
                msMultiplier = (int) Math.pow(10, 3 - matcher.group(8).length());
                return new NormalPlayTime(
                        Long.parseLong(matcher.group(6)) * 1000 + Long.parseLong(matcher.group(8))*msMultiplier);
            }
        } catch (NumberFormatException ex1) {
        }
    }
    throw new InvalidValueException("Can't parse NormalPlayTime: " + s);
}
 
Example #11
Source File: NormalPlayTimeRange.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
public static NormalPlayTimeRange valueOf(String s, boolean mandatoryTimeEnd) throws InvalidValueException {
    if (s.startsWith(PREFIX)) {
        NormalPlayTime timeStart, timeEnd = null, timeDuration = null;
        String[] params = s.substring(PREFIX.length()).split("[-/]");
        switch (params.length) {
            case 3:
                if (params[2].length() != 0 && !params[2].equals("*")) {
                    timeDuration = NormalPlayTime.valueOf(params[2]);
                }
            case 2:
                if (params[1].length() != 0) {
                    timeEnd = NormalPlayTime.valueOf(params[1]);
                }
            case 1:
                if (params[0].length() != 0 && (!mandatoryTimeEnd || ( mandatoryTimeEnd && params.length>1))) {
                    timeStart = NormalPlayTime.valueOf(params[0]);
                    return new NormalPlayTimeRange(timeStart, timeEnd, timeDuration);
                }
            default:
                break;
        }
    }
    throw new InvalidValueException("Can't parse NormalPlayTimeRange: " + s);
}
 
Example #12
Source File: DLNAPlaySpeedAttribute.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
public void setString(String s, String cf) throws InvalidDLNAProtocolAttributeException {
    TransportPlaySpeed[] value = null;
    if (s != null && s.length() != 0) {
        String[] speeds = s.split(",");
        try {
            value = new TransportPlaySpeed[speeds.length]; 
            for (int i = 0; i < speeds.length; i++) {
                value[i] = new TransportPlaySpeed(speeds[i]);
            }
        } catch (InvalidValueException invalidValueException) {
            value = null;
        }
    }
    if (value == null) {
        throw new InvalidDLNAProtocolAttributeException("Can't parse DLNA play speeds from: " + s);
    }
    setValue(value);
}
 
Example #13
Source File: NormalPlayTime.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
public NormalPlayTime(long hours, long minutes, long seconds, long milliseconds) throws InvalidValueException {
    if (hours < 0) {
        throw new InvalidValueException("Invalid parameter hours: " + hours);
    }

    if (minutes < 0 || minutes > 59) {
        throw new InvalidValueException("Invalid parameter minutes: " + hours);
    }

    if (seconds < 0 || seconds > 59) {
        throw new InvalidValueException("Invalid parameter seconds: " + hours);
    }
    if (milliseconds < 0 || milliseconds > 999) {
        throw new InvalidValueException("Invalid parameter milliseconds: " + milliseconds);
    }

    this.milliseconds = (hours * 60 * 60 + minutes * 60 + seconds) * 1000 + milliseconds;
}
 
Example #14
Source File: EventedValueChannelMute.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected ChannelMute valueOf(Map.Entry<String, String>[] attributes) throws InvalidValueException {
    Channel channel = null;
    Boolean mute = null;
    for (Map.Entry<String, String> attribute : attributes) {
        if (attribute.getKey().equals("channel"))
            channel = Channel.valueOf(attribute.getValue());
        if (attribute.getKey().equals("val"))
            mute = new BooleanDatatype().valueOf(attribute.getValue());
    }
    return channel != null && mute != null ? new ChannelMute(channel, mute) : null;
}
 
Example #15
Source File: EventedValueChannelVolumeDB.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected ChannelVolumeDB valueOf(Map.Entry<String, String>[] attributes) throws InvalidValueException {
    Channel channel = null;
    Integer volumeDB = null;
    for (Map.Entry<String, String> attribute : attributes) {
        if (attribute.getKey().equals("channel"))
            channel = Channel.valueOf(attribute.getValue());
        if (attribute.getKey().equals("val"))
            volumeDB = (new UnsignedIntegerTwoBytesDatatype()
                    .valueOf(attribute.getValue()))
                    .getValue().intValue(); // Java is fun!
    }
    return channel != null && volumeDB != null ? new ChannelVolumeDB(channel, volumeDB) : null;
}
 
Example #16
Source File: EventedValueChannelVolume.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected ChannelVolume valueOf(Map.Entry<String, String>[] attributes) throws InvalidValueException {
    Channel channel = null;
    Integer volume = null;
    for (Map.Entry<String, String> attribute : attributes) {
        if (attribute.getKey().equals("channel"))
            channel = Channel.valueOf(attribute.getValue());
        if (attribute.getKey().equals("val"))
            volume = (new UnsignedIntegerTwoBytesDatatype()
                    .valueOf(attribute.getValue()))
                    .getValue().intValue(); // Java is fun!
    }
    return channel != null && volume != null ? new ChannelVolume(channel, volume) : null;
}
 
Example #17
Source File: NormalPlayTime.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public NormalPlayTime(long milliseconds) {
    if (milliseconds < 0) {
        throw new InvalidValueException("Invalid parameter milliseconds: " + milliseconds);
    }

    this.milliseconds = milliseconds;
}
 
Example #18
Source File: EventedValue.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public EventedValue(Map.Entry<String,String>[] attributes) {
    try {
        this.value = valueOf(attributes);
    } catch (InvalidValueException ex) {
        throw new RuntimeException(ex);
    }
}
 
Example #19
Source File: EventedValue.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
protected V valueOf(Map.Entry<String,String>[] attributes) throws InvalidValueException {
    V v = null;
    for (Map.Entry<String, String> attribute : attributes) {
        if (attribute.getKey().equals("val")) v = valueOf(attribute.getValue());
    }
    return v;
}
 
Example #20
Source File: SempDeviceType.java    From SmartApplianceEnabler with GNU General Public License v2.0 5 votes vote down vote up
public static SempDeviceType valueOf(String s) throws InvalidValueException {
    Matcher matcher = PATTERN.matcher(s);
    
    try {
        if (matcher.matches())
            return new SempDeviceType(matcher.group(1), Integer.valueOf(matcher.group(2)));
    } catch(RuntimeException e) {
        throw new InvalidValueException(String.format(
            "Can't parse device SEMP type string (namespace/type/version) '%s': %s", s, e.toString()
        ));
    }
    throw new InvalidValueException("Can't parse SEMP device type string (namespace/type/version): " + s);
}
 
Example #21
Source File: EventedValueURI.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected URI valueOf(String s) throws InvalidValueException {
    try {
        // These URIs are really defined as 'string' datatype in AVTransport1.0.pdf, but we can try
        // to parse whatever devices give us, like the Roku which sends "unknown url".
        return super.valueOf(s);
    } catch (InvalidValueException ex) {
        log.info("Ignoring invalid URI in evented value '" + s +"': " + Exceptions.unwrap(ex));
        return null;
    }
}
 
Example #22
Source File: EventedValueChannelLoudness.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected ChannelLoudness valueOf(Map.Entry<String, String>[] attributes) throws InvalidValueException {
    Channel channel = null;
    Boolean loudness = null;
    for (Map.Entry<String, String> attribute : attributes) {
        if (attribute.getKey().equals("channel"))
            channel = Channel.valueOf(attribute.getValue());
        if (attribute.getKey().equals("val"))
            loudness = new BooleanDatatype().valueOf(attribute.getValue());
    }
    return channel != null && loudness != null ? new ChannelLoudness(channel, loudness) : null;
}
 
Example #23
Source File: DLNAPlaySpeedAttribute.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public DLNAPlaySpeedAttribute(String[] speeds) {
    TransportPlaySpeed[] sp = new TransportPlaySpeed[speeds.length]; 
    try {
        for (int i = 0; i < speeds.length; i++) {
            sp[i] = new TransportPlaySpeed(speeds[i]);
        }
    } catch (InvalidValueException invalidValueException) {
        throw new InvalidDLNAProtocolAttributeException("Can't parse DLNA play speeds.");
    }
    setValue(sp);
}
 
Example #24
Source File: ContentRangeHeader.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public void setString(String s) throws InvalidHeaderException {
    try {
        setValue(BytesRange.valueOf(s,PREFIX));
    } catch (InvalidValueException invalidValueException) {
        throw new InvalidHeaderException("Invalid Range Header: " + invalidValueException.getMessage());
    }
}
 
Example #25
Source File: EventedValue.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public EventedValue(Map.Entry<String,String>[] attributes) {
    try {
        this.value = valueOf(attributes);
    } catch (InvalidValueException ex) {
        throw new RuntimeException(ex);
    }
}
 
Example #26
Source File: PragmaHeader.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public void setString(String s) throws InvalidHeaderException {
    try {
        setValue(PragmaType.valueOf(s));
    } catch (InvalidValueException invalidValueException) {
        throw new InvalidHeaderException("Invalid Range Header: " + invalidValueException.getMessage());
    }
}
 
Example #27
Source File: NormalPlayTime.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public NormalPlayTime(long milliseconds) {
    if (milliseconds < 0) {
        throw new InvalidValueException("Invalid parameter milliseconds: " + milliseconds);
    }

    this.milliseconds = milliseconds;
}
 
Example #28
Source File: VariableValue.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
/**
   * Creates and validates a variable value.
   * <p>
   * If the given value is a <code>String</code>, it will be converted
   * with {@link org.fourthline.cling.model.types.Datatype#valueOf(String)}. Any
   * other value will be checked, whether it matches the datatype and if its
   * string representation is valid in XML documents (unicode character test).
   * </p>
   * <p>
   * Note that for performance reasons, validation of a non-string value
   * argument is skipped if executed on an Android runtime!
   * </p>
   *
   * @param datatype The type of the variable.
   * @param value The value of the variable.
   * @throws InvalidValueException If the value is invalid for the given datatype, or if
   *         its string representation is invalid in XML.
   */
  public VariableValue(Datatype datatype, Object value) throws InvalidValueException {
      this.datatype = datatype;
      this.value = value instanceof String ? datatype.valueOf((String) value) : value;

if (ModelUtil.ANDROID_RUNTIME) return; // Skipping validation on Android

      // We can skip this validation because we can catch invalid values
      // of any remote service (action invocation, event value) before, they are
      // strings. The datatype's valueOf() will take care of that. The validations
      // are really only used when a developer prepares input arguments for an action
      // invocation or when a local service returns a wrong value.

      // In the first case the developer will get an exception when executing the
      // action, if his action input argument value was of the wrong type. Or,
      // an XML processing error will occur as soon as the SOAP message is handled,
      // if the value contained invalid characters.

      // The second case indicates a bug in the local service, either metadata (state
      // variable type) or implementation (action method return value). This will
      // most likely be caught by the metadata/annotation binder when the service is
      // created.

      if (!getDatatype().isValid(getValue()))
          throw new InvalidValueException("Invalid value for " + getDatatype() +": " + getValue());
      
      logInvalidXML(toString());
  }
 
Example #29
Source File: AbstractActionExecutor.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the output argument value on the {@link org.fourthline.cling.model.action.ActionInvocation}, considers string conversion.
 */
protected void setOutputArgumentValue(ActionInvocation<LocalService> actionInvocation, ActionArgument<LocalService> argument, Object result)
        throws ActionException {

    LocalService service = actionInvocation.getAction().getService();

    if (result != null) {
        try {
            if (service.isStringConvertibleType(result)) {
                log.fine("Result of invocation matches convertible type, setting toString() single output argument value");
                actionInvocation.setOutput(new ActionArgumentValue(argument, result.toString()));
            } else {
                log.fine("Result of invocation is Object, setting single output argument value");
                actionInvocation.setOutput(new ActionArgumentValue(argument, result));
            }
        } catch (InvalidValueException ex) {
            throw new ActionException(
                    ErrorCode.ARGUMENT_VALUE_INVALID,
                    "Wrong type or invalid value for '" + argument.getName() + "': " + ex.getMessage(),
                    ex
            );
        }
    } else {

        log.fine("Result of invocation is null, not setting any output argument value(s)");
    }

}
 
Example #30
Source File: ContentRangeHeader.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public void setString(String s) throws InvalidHeaderException {
    try {
        setValue(BytesRange.valueOf(s,PREFIX));
    } catch (InvalidValueException invalidValueException) {
        throw new InvalidHeaderException("Invalid Range Header: " + invalidValueException.getMessage());
    }
}