1 // Copyright 2011 Google Inc. All Rights Reserved.
3 package com
.google
.apphosting
.base
;
5 import java
.util
.regex
.Matcher
;
6 import java
.util
.regex
.Pattern
;
9 * Class used for parsing the various components of the AppId.
13 private static final int APP_ID_MAX_LEN
= 100;
14 private static final Pattern DISPLAY_APP_ID_RE
=
15 Pattern
.compile("[a-z\\d\\-]{1," + APP_ID_MAX_LEN
+ "}", Pattern
.CASE_INSENSITIVE
);
16 private static final Pattern DOMAIN_RE
=
17 Pattern
.compile("([a-z\\d\\-\\.]{1," + APP_ID_MAX_LEN
+ "})?\\:", Pattern
.CASE_INSENSITIVE
);
18 private static final Pattern PARTITION_RE
=
19 Pattern
.compile("([a-z\\d\\-]{1," + APP_ID_MAX_LEN
+ "})?\\~", Pattern
.CASE_INSENSITIVE
);
20 private static final Pattern APP_ID_RE
=
22 "(?:" + PARTITION_RE
+ ")?((?:" + DOMAIN_RE
+ ")?(" + DISPLAY_APP_ID_RE
+ "))",
23 Pattern
.CASE_INSENSITIVE
);
25 private String domain
;
26 private String longAppId
;
27 private String displayAppId
;
28 private String partition
;
31 * Create a new AppId based on an appId formatted as follows:
33 * [(partition)~][(domain):](display-app-id)
35 * @param appId The appId to parse.
37 private AppId(String appId
) {
39 if (appId
== null || appId
.length() == 0) {
42 Matcher matcher
= APP_ID_RE
.matcher(appId
);
43 if (!matcher
.matches()) {
46 this.partition
= matcher
.group(1);
47 this.longAppId
= matcher
.group(2);
48 this.domain
= matcher
.group(3);
49 this.displayAppId
= matcher
.group(4);
53 * @return The full appId.
55 public String
getAppId() {
60 * @return The domain component of this appId.
62 public String
getDomain() {
67 * @return The display-app-id component of this appId.
69 public String
getDisplayAppId() {
74 * @return The partition component of the appId.
76 public String
getPartition() {
81 * @return The appId without the partition component.
83 public String
getLongAppId() {
88 * Returns a new AppId object based on an appId formatted as follows:
90 * [(partition)~][(domain):](display-app-id)
92 * @param appId The appId to parse.
94 * @return AppId object with the parsed appid components.
96 public static AppId
parse(String appId
) {
97 return new AppId(appId
);