UriMatcherResponse - スコープ指定
URI がスキーム、ホスト、パス、フラグメント、およびクエリパラメーターの存在について指定された条件に一致するかどうかに関する情報を返すメソッドを提供します。
この API は UriMatcher API と共に使用します。この API にはコンストラクターはありません。代わりに、 UriMatcher - match() メソッドを使用して UriMatcherResponse オブジェクトをインスタンス化します。
UriMatcherResponse API には、デフォルトで有効になっている REST API プロバイダー (com.glide.rest) プラグインが必要です。
この API は sn_ws 名前空間内で提供されます。
UriMatcherResponse - getErrorMessages()
指定された基準に対して URI をテストしたときに発生したエラーに関するメッセージを返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | 発生したエラーの説明。エラーが発生しなかった場合は、空の文字列が返されます。 |
この例では、一致基準でホストが指定されていないため、エラーが返されます。
var uri = "https://example.com";
var scheme = "https";
var matcher = new sn_ws.UriMatcher();
var resp = matcher.match(uri, scheme);
gs.info("Error occurred: " + resp.isError());
gs.info("Error message: " + resp.getErrorMessages());
出力:
Error occurred: true
Error message: Hosts rule is null or empty.
UriMatcherResponse - isError()
指定された基準に対して URI をテストするときにエラーが発生したかどうかを確認します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| ブール |
エラーが発生したかどうかを示すフラグ。 有効な値:
|
この例では、URI にクエリパラメーターが含まれているため、エラーが返されます。このエラーは、disallowQueryParameters に対して match() に渡された引数が true であるために発生します。
var uri = "https://example.com/path1/more?q=query";
var scheme = "https";
var allowedHosts = ["example.com", "sample.com"];
var allowedPaths = ["/path1/more", "/path2/less"];
var allowedFragments = ["section1", "section2"];
var noQueryParams = true;
var matcher = new sn_ws.UriMatcher();
var resp = matcher.match(uri, scheme, allowedHosts, allowedPaths, allowedFragments, noQueryParams);
gs.info("Error occurred: " + resp.isError());
gs.info("Error message: " + resp.getErrorMessages());
出力:
Error occurred: true
Error message: Query parameters are not allowed for matching.
UriMatcherResponse - isFragmentMatches()
URI がフラグメントのクライテリアに一致するかどうかを確認します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| ブール |
URI がフラグメントのクライテリアに一致するかどうかを示すフラグ。 有効な値:
|
この例は、許可されたフラグメントのリストにないフラグメントが含まれているため、URI が条件に一致しないことを示しています。
var uri = "https://example.com/path1/more#section3";
var scheme = "https";
var allowedHosts = ["example.com", "sample.com"];
var allowedPaths = ["/path1/more", "/path2/less"];
var allowedFragments = ["section1", "section2"];
var matcher = new sn_ws.UriMatcher();
var resp = matcher.match(uri, scheme, allowedHosts, allowedPaths, allowedFragments);
gs.info("Is URI a match: " + resp.isMatch());
gs.info("Is scheme a match: " + resp.isSchemeMatches());
gs.info("Is host a match: " + resp.isHostMatches());
gs.info("Is path a match: " + resp.isPathMatches());
gs.info("Is fragment a match: " + resp.isFragmentMatches());
gs.info("Error occurred: " + resp.isError());
出力:
Is URI a match: false
Is scheme a match: true
Is host a match: true
Is path a match: true
Is fragment a match: false
Error occurred: false
UriMatcherResponse - isHostMatches()
URI がホストの条件と一致するかどうかを確認します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| ブール |
URI がホストの条件に一致するかどうかを示すフラグ。 有効な値:
|
この例では、URI が指定されたスキームとホストと一致するかどうかを確認します。
var uri = "https://example.com/path?q=query";
var scheme = "https";
var allowedHosts = ["example.com"];
var matcher = new sn_ws.UriMatcher();
var resp = matcher.match(uri, scheme, allowedHosts);
gs.info("Is URI a match: " + resp.isMatch());
gs.info("Is host a match: " + resp.isHostMatches());
出力:
Is URI a match: true
Is host a match: true
UriMatcherResponse - isMatch()
URI が指定されたすべてのクライテリアに一致するかどうかを確認します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| ブール |
URI が指定されたすべての条件に一致するかどうかを示すフラグ。 有効な値:
|
この例では、URI が指定されたスキームとホストと一致するかどうかを確認します。
var uri = "https://example.com/path?q=query";
var scheme = "https";
var allowedHosts = ["example.com"];
var matcher = new sn_ws.UriMatcher();
var resp = matcher.match(uri, scheme, allowedHosts);
gs.info("Is URI a match: " + resp.isMatch());
出力:
Is URI a match: true
UriMatcherResponse - isPathMatches()
URI がパスの条件に一致するかどうかを確認します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| ブール |
URI がパスのクライテリアに一致するかどうかを示すフラグ。 有効な値:
|
この例では、URI が指定されたスキーム、ホスト、およびパスと一致するかどうかを確認します。
var uri = "https://example.com/path1/more";
var scheme = "https";
var allowedHosts = ["example.com", "sample.com"];
var allowedPaths = ["/path1/more", "/path2/less"];
var matcher = new sn_ws.UriMatcher();
var resp = matcher.match(uri, scheme, allowedHosts, allowedPaths);
gs.info("Is URI a match: " + resp.isMatch());
gs.info("Is scheme a match: " + resp.isSchemeMatches());
gs.info("Is host a match: " + resp.isHostMatches());
gs.info("Is path a match: " + resp.isPathMatches());
gs.info("Is fragment a match: " + resp.isFragmentMatches());
gs.info("Error occurred: " + resp.isError());
出力:
Is URI a match: true
Is scheme a match: true
Is host a match: true
Is path a match: true
Is fragment a match: true
Error occurred: false
UriMatcherResponse - isSchemeMatches()
URI がスキームの条件に一致するかどうかを確認します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| ブール |
URI がスキームの基準に一致するかどうかを示すフラグ。 有効な値:
|
この例では、URI が指定されたスキームとホストと一致するかどうかを確認します。
var uri = "https://example.com/path?q=query";
var scheme = "https";
var allowedHosts = ["example.com"];
var matcher = new sn_ws.UriMatcher();
var resp = matcher.match(uri, scheme, allowedHosts);
gs.info("Is URI a match: " + resp.isMatch());
gs.info("Is scheme a match: " + resp.isSchemeMatches());
出力:
Is URI a match: true
Is scheme a match: true