cronapp-cordova-plugin-ionic-webview 4.4.0-RC.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,183 @@
1
+ package com.ionicframework.cordova.webview;
2
+
3
+ /*
4
+ * Copyright (C) 2006 The Android Open Source Project
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ //package com.google.webviewlocalserver.third_party.android;
19
+
20
+ import android.net.Uri;
21
+
22
+ import java.util.ArrayList;
23
+ import java.util.List;
24
+ import java.util.regex.Pattern;
25
+
26
+ public class UriMatcher {
27
+ /**
28
+ * Creates the root node of the URI tree.
29
+ *
30
+ * @param code the code to match for the root URI
31
+ */
32
+ public UriMatcher(Object code) {
33
+ mCode = code;
34
+ mWhich = -1;
35
+ mChildren = new ArrayList<UriMatcher>();
36
+ mText = null;
37
+ }
38
+
39
+ private UriMatcher() {
40
+ mCode = null;
41
+ mWhich = -1;
42
+ mChildren = new ArrayList<UriMatcher>();
43
+ mText = null;
44
+ }
45
+
46
+ /**
47
+ * Add a URI to match, and the code to return when this URI is
48
+ * matched. URI nodes may be exact match string, the token "*"
49
+ * that matches any text, or the token "#" that matches only
50
+ * numbers.
51
+ * <p>
52
+ * Starting from API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2},
53
+ * this method will accept a leading slash in the path.
54
+ *
55
+ * @param authority the authority to match
56
+ * @param path the path to match. * may be used as a wild card for
57
+ * any text, and # may be used as a wild card for numbers.
58
+ * @param code the code that is returned when a URI is matched
59
+ * against the given components. Must be positive.
60
+ */
61
+ public void addURI(String scheme, String authority, String path, Object code) {
62
+ if (code == null) {
63
+ throw new IllegalArgumentException("Code can't be null");
64
+ }
65
+
66
+ String[] tokens = null;
67
+ if (path != null) {
68
+ String newPath = path;
69
+ // Strip leading slash if present.
70
+ if (path.length() > 0 && path.charAt(0) == '/') {
71
+ newPath = path.substring(1);
72
+ }
73
+ tokens = PATH_SPLIT_PATTERN.split(newPath);
74
+ }
75
+
76
+ int numTokens = tokens != null ? tokens.length : 0;
77
+ UriMatcher node = this;
78
+ for (int i = -2; i < numTokens; i++) {
79
+ String token;
80
+ if (i == -2)
81
+ token = scheme;
82
+ else if (i == -1)
83
+ token = authority;
84
+ else
85
+ token = tokens[i];
86
+ ArrayList<UriMatcher> children = node.mChildren;
87
+ int numChildren = children.size();
88
+ UriMatcher child;
89
+ int j;
90
+ for (j = 0; j < numChildren; j++) {
91
+ child = children.get(j);
92
+ if (token.equals(child.mText)) {
93
+ node = child;
94
+ break;
95
+ }
96
+ }
97
+ if (j == numChildren) {
98
+ // Child not found, create it
99
+ child = new UriMatcher();
100
+ if (token.equals("**")) {
101
+ child.mWhich = REST;
102
+ } else if (token.equals("*")) {
103
+ child.mWhich = TEXT;
104
+ } else {
105
+ child.mWhich = EXACT;
106
+ }
107
+ child.mText = token;
108
+ node.mChildren.add(child);
109
+ node = child;
110
+ }
111
+ }
112
+ node.mCode = code;
113
+ }
114
+
115
+ static final Pattern PATH_SPLIT_PATTERN = Pattern.compile("/");
116
+
117
+ /**
118
+ * Try to match against the path in a url.
119
+ *
120
+ * @param uri The url whose path we will match against.
121
+ * @return The code for the matched node (added using addURI),
122
+ * or null if there is no matched node.
123
+ */
124
+ public Object match(Uri uri) {
125
+ final List<String> pathSegments = uri.getPathSegments();
126
+ final int li = pathSegments.size();
127
+
128
+ UriMatcher node = this;
129
+
130
+ if (li == 0 && uri.getAuthority() == null) {
131
+ return this.mCode;
132
+ }
133
+
134
+ for (int i = -2; i < li; i++) {
135
+ String u;
136
+ if (i == -2)
137
+ u = uri.getScheme();
138
+ else if (i == -1)
139
+ u = uri.getAuthority();
140
+ else
141
+ u = pathSegments.get(i);
142
+ ArrayList<UriMatcher> list = node.mChildren;
143
+ if (list == null) {
144
+ break;
145
+ }
146
+ node = null;
147
+ int lj = list.size();
148
+ for (int j = 0; j < lj; j++) {
149
+ UriMatcher n = list.get(j);
150
+ which_switch:
151
+ switch (n.mWhich) {
152
+ case EXACT:
153
+ if (n.mText.equals(u)) {
154
+ node = n;
155
+ }
156
+ break;
157
+ case TEXT:
158
+ node = n;
159
+ break;
160
+ case REST:
161
+ return n.mCode;
162
+ }
163
+ if (node != null) {
164
+ break;
165
+ }
166
+ }
167
+ if (node == null) {
168
+ return null;
169
+ }
170
+ }
171
+
172
+ return node.mCode;
173
+ }
174
+
175
+ private static final int EXACT = 0;
176
+ private static final int TEXT = 1;
177
+ private static final int REST = 2;
178
+
179
+ private Object mCode;
180
+ private int mWhich;
181
+ private String mText;
182
+ private ArrayList<UriMatcher> mChildren;
183
+ }