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  package org.fourthline.cling.support.model.dlna.message.header;
16  
17  import org.fourthline.cling.model.message.header.InvalidHeaderException;
18  import org.fourthline.cling.model.types.BytesRange;
19  import org.fourthline.cling.model.types.InvalidValueException;
20  import org.fourthline.cling.support.model.dlna.types.NormalPlayTimeRange;
21  import org.fourthline.cling.support.model.dlna.types.TimeSeekRangeType;
22  
23  /**
24   * @author Mario Franco
25   */
26  public class TimeSeekRangeHeader extends DLNAHeader<TimeSeekRangeType> {
27  
28      public TimeSeekRangeHeader() {
29      }
30  
31      public TimeSeekRangeHeader(TimeSeekRangeType timeSeekRange) {
32          setValue(timeSeekRange);
33      }
34      @Override
35      public void setString(String s) throws InvalidHeaderException {
36          if (s.length() != 0) {
37              String[] params = s.split(" ");
38              if (params.length>0) {
39                  try {
40                      TimeSeekRangeType t = new TimeSeekRangeType(NormalPlayTimeRange.valueOf(params[0]));
41                      if (params.length > 1) {
42                          t.setBytesRange(BytesRange.valueOf(params[1]));
43                      }
44                      setValue(t);
45                      return;
46                  } catch (InvalidValueException invalidValueException) {
47                      throw new InvalidHeaderException("Invalid TimeSeekRange header value: " + s + "; "+invalidValueException.getMessage());
48                  }
49              }
50          }
51          throw new InvalidHeaderException("Invalid TimeSeekRange header value: " + s);
52      }
53  
54      @Override
55      public String getString() {
56          TimeSeekRangeType t = getValue();
57          String s = t.getNormalPlayTimeRange().getString();
58          if (t.getBytesRange()!=null) s+= " "+t.getBytesRange().getString(true);
59          return s;
60      }
61      
62  }