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.model.message.header;
17  
18  import org.seamless.util.MimeType;
19  
20  /**
21   * @author Christian Bauer
22   */
23  public class ContentTypeHeader extends UpnpHeader<MimeType> {
24  
25      public static final MimeType DEFAULT_CONTENT_TYPE = MimeType.valueOf("text/xml");
26      public static final MimeType DEFAULT_CONTENT_TYPE_UTF8 = MimeType.valueOf("text/xml;charset=\"utf-8\"");
27  
28      public ContentTypeHeader() {
29          setValue(DEFAULT_CONTENT_TYPE);
30      }
31  
32      public ContentTypeHeader(MimeType contentType) {
33          setValue(contentType);
34      }
35  
36      public ContentTypeHeader(String s) throws InvalidHeaderException{
37          setString(s);
38      }
39  
40      public void setString(String s) throws InvalidHeaderException {
41          setValue(MimeType.valueOf(s));
42      }
43  
44      public String getString() {
45          return getValue().toString();
46      }
47  
48      public boolean isUDACompliantXML() {
49          // UDA spec says "must be text/xml", however, sometimes you get a charset token as well...
50          return isText() && getValue().getSubtype().equals(DEFAULT_CONTENT_TYPE.getSubtype());
51      }
52  
53      public boolean isText() {
54          return getValue() != null && getValue().getType().equals(DEFAULT_CONTENT_TYPE.getType());
55      }
56  }