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 java.util.ArrayList;
18  import java.util.List;
19  import org.fourthline.cling.model.message.header.InvalidHeaderException;
20  import org.fourthline.cling.model.types.PragmaType;
21  
22  /**
23   * DLNA Pragma tokens:
24   *  - getIfoFileURI.dlna.org
25   *  - ifoFileURI.dlna.org
26   * 
27   * @author Mario Franco
28   */
29  public class PragmaHeader extends DLNAHeader<List<PragmaType>> {
30      
31      public PragmaHeader() {
32          setValue(new ArrayList<PragmaType>());
33      }
34      
35      @Override
36      public void setString(String s) throws InvalidHeaderException {
37          if (s.length() != 0) {
38              if (s.endsWith(";")) {
39                  s = s.substring(0, s.length() - 1);
40              }
41              String[] list = s.split("\\s*;\\s*");
42              List<PragmaType> value = new ArrayList<>();
43              for (String pragma : list) {
44                  value.add(PragmaType.valueOf(pragma));
45              }
46              return;
47          }
48          throw new InvalidHeaderException("Invalid Pragma header value: " + s);
49      }
50      
51      @Override
52      public String getString() {
53          List<PragmaType> v = getValue();
54          String r = "";
55          for (PragmaType pragma : v) {
56              r += (r.length() == 0 ? "": "," )+  pragma.getString();
57          }
58          return r;
59      }
60  }