View Javadoc
1   package org.esigate.extension.surrogate.http;
2   
3   /**
4    * 
5    * Capability tokens indicate sets of operations (e.g., caching, processing) that a surrogate is willing to perform.
6    * They follow the form of product tokens in the HTTP;
7    * <p>
8    * capability = token [ "/" token ]
9    * <p>
10   * Capability tokens are case-sensitive.
11   * 
12   * @author Nicolas Richeton
13   * 
14   */
15  public final class Capability {
16  
17      private String id;
18      private String version;
19  
20      public String getId() {
21          return id;
22      }
23  
24      public String getVersion() {
25          return version;
26      }
27  
28      private Capability() {
29          version = null;
30          id = null;
31      }
32  
33      public static Capability fromToken(String token) {
34          Capability cap = new Capability();
35  
36          if (token == null) {
37              return cap;
38          }
39  
40          int separatorIndex = token.indexOf('/');
41          if (separatorIndex >= 0) {
42              cap.id = token.substring(0, separatorIndex).trim();
43              cap.version = token.substring(separatorIndex + 1).trim();
44          } else {
45              cap.id = token.trim();
46          }
47  
48          return cap;
49      }
50  
51      @Override
52      public String toString() {
53  
54          String token = id;
55          if (version != null) {
56              token = token + "/" + version;
57          }
58          return token;
59      }
60  }