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.EnumMap;
18  import org.fourthline.cling.model.message.header.InvalidHeaderException;
19  import org.fourthline.cling.support.model.dlna.DLNAAttribute;
20  
21  /**
22   * @author Mario Franco
23   */
24  public class ContentFeaturesHeader extends DLNAHeader<EnumMap<DLNAAttribute.Type, DLNAAttribute>> {
25  
26      public ContentFeaturesHeader() {
27          setValue(new EnumMap<DLNAAttribute.Type, DLNAAttribute>(DLNAAttribute.Type.class));
28      }
29  
30      @Override
31      public void setString(String s) throws InvalidHeaderException {
32          if (s.length() != 0) {
33              String[] atts = s.split(";");
34              for (String att : atts) {
35                  String[] attNameValue = att.split("=");
36                  if (attNameValue.length == 2) {
37                      DLNAAttribute.Type type = DLNAAttribute.Type.valueOfAttributeName(attNameValue[0]);
38                      if (type != null) {
39                          DLNAAttribute dlnaAttrinute = DLNAAttribute.newInstance(type, attNameValue[1], "");
40                          getValue().put(type, dlnaAttrinute);
41                      }
42                  }
43              }
44          }
45      }
46  
47      @Override
48      public String getString() {
49          String s = "";
50          for (DLNAAttribute.Type type : DLNAAttribute.Type.values()) {
51              String value = getValue().containsKey(type) ? getValue().get(type).getString() : null;
52              if (value != null && value.length() != 0) {
53                  s += (s.length() == 0 ? "" : ";") + type.getAttributeName() + "=" + value;
54              }
55          }
56          return s;
57      }
58  }