View Javadoc
1   /*
2    * Copyright (C) 2013 4th Line GmbH, Switzerland
3    *
4    * The contents of this file are subject to the terms of either the GNU
5    * Lesser General Public License Version 2 or later ("LGPL") or the
6    * Common Development and Distribution License Version 1 or later
7    * ("CDDL") (collectively, the "License"). You may not use this file
8    * except in compliance with the License. See LICENSE.txt for more
9    * information.
10   *
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14   */
15  
16  package org.fourthline.cling.support.lastchange;
17  
18  import org.fourthline.cling.model.types.Datatype;
19  import org.fourthline.cling.model.types.InvalidValueException;
20  import org.seamless.util.Exceptions;
21  
22  import java.net.URI;
23  import java.util.Map;
24  import java.util.logging.Logger;
25  
26  /**
27   * @author Christian Bauer
28   */
29  public class EventedValueURI extends EventedValue<URI> {
30  
31      final private static Logger log = Logger.getLogger(EventedValueURI.class.getName());
32  
33      public EventedValueURI(URI value) {
34          super(value);
35      }
36  
37      public EventedValueURI(Map.Entry<String, String>[] attributes) {
38          super(attributes);
39      }
40      
41      @Override
42      protected URI valueOf(String s) throws InvalidValueException {
43          try {
44              // These URIs are really defined as 'string' datatype in AVTransport1.0.pdf, but we can try
45              // to parse whatever devices give us, like the Roku which sends "unknown url".
46              return super.valueOf(s);
47          } catch (InvalidValueException ex) {
48              log.info("Ignoring invalid URI in evented value '" + s +"': " + Exceptions.unwrap(ex));
49              return null;
50          }
51      }
52  
53      @Override
54      protected Datatype getDatatype() {
55          return Datatype.Builtin.URI.getDatatype();
56      }
57  }