1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.fourthline.cling.model.message.header;
17
18 import org.fourthline.cling.model.Constants;
19
20 import java.util.regex.Matcher;
21 import java.util.regex.Pattern;
22 import java.util.Locale;
23
24
25
26
27 public class MaxAgeHeader extends UpnpHeader<Integer> {
28
29
30 public static final Pattern MAX_AGE_REGEX = Pattern.compile(".*max-age\\s*=\\s*([0-9]+).*");
31
32 public MaxAgeHeader(Integer maxAge) {
33 setValue(maxAge);
34 }
35
36 public MaxAgeHeader() {
37 setValue(Constants.MIN_ADVERTISEMENT_AGE_SECONDS);
38 }
39
40 public void setString(String s) throws InvalidHeaderException {
41
42 Matcher matcher = MAX_AGE_REGEX.matcher(s.toLowerCase(Locale.ROOT));
43 if (!matcher.matches()){
44 throw new InvalidHeaderException("Invalid cache-control value, can't parse max-age seconds: " + s);
45 }
46
47 Integer maxAge = Integer.parseInt(matcher.group(1));
48 setValue(maxAge);
49 }
50
51 public String getString() {
52 return "max-age="+getValue().toString();
53 }
54 }