Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
FaceletsVDLUtils |
|
| 3.0;3 | ||||
FaceletsVDLUtils$KeyComparator |
|
| 3.0;3 | ||||
FaceletsVDLUtils$NullWriter |
|
| 3.0;3 |
1 | /* | |
2 | * Licensed to the Apache Software Foundation (ASF) under one | |
3 | * or more contributor license agreements. See the NOTICE file | |
4 | * distributed with this work for additional information | |
5 | * regarding copyright ownership. The ASF licenses this file | |
6 | * to you under the Apache License, Version 2.0 (the | |
7 | * "License"); you may not use this file except in compliance | |
8 | * with the License. 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, | |
13 | * software distributed under the License is distributed on an | |
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
15 | * KIND, either express or implied. See the License for the | |
16 | * specific language governing permissions and limitations | |
17 | * under the License. | |
18 | */ | |
19 | package org.apache.myfaces.view.facelets; | |
20 | ||
21 | import java.io.Writer; | |
22 | import java.util.Comparator; | |
23 | ||
24 | /** | |
25 | * | |
26 | * @author lu4242 | |
27 | */ | |
28 | 0 | public class FaceletsVDLUtils |
29 | { | |
30 | /** | |
31 | * As specified in JSF 2.2 section 11.4.2.1, note it is different from the | |
32 | * allowed format in xml url-pattern type. | |
33 | * | |
34 | * @param path | |
35 | * @param pattern | |
36 | * @return A | |
37 | */ | |
38 | public static boolean matchPattern(String path, String pattern) | |
39 | { | |
40 | // Normalize the argument strings | |
41 | 0 | if ((path == null) || (path.length() == 0)) |
42 | { | |
43 | 0 | path = "*"; |
44 | } | |
45 | 0 | if ((pattern == null) || (pattern.length() == 0)) |
46 | { | |
47 | 0 | pattern = "*"; |
48 | } | |
49 | ||
50 | // Check for exact match | |
51 | 0 | if (path.equals(pattern)) |
52 | { | |
53 | 0 | return (true); |
54 | } | |
55 | ||
56 | // Check for path prefix matching | |
57 | 0 | if (pattern.startsWith("/") && pattern.endsWith("/*")) |
58 | { | |
59 | 0 | pattern = pattern.substring(0, pattern.length() - 2); |
60 | 0 | if (pattern.length() == 0) |
61 | { | |
62 | 0 | return (true); // "/*" is the same as "/" |
63 | } | |
64 | 0 | if (path.endsWith("/")) |
65 | { | |
66 | 0 | path = path.substring(0, path.length() - 1); |
67 | } | |
68 | while (true) | |
69 | { | |
70 | 0 | if (pattern.equals(path)) |
71 | { | |
72 | 0 | return (true); |
73 | } | |
74 | 0 | int slash = path.lastIndexOf('/'); |
75 | 0 | if (slash <= 0) |
76 | { | |
77 | 0 | break; |
78 | } | |
79 | 0 | path = path.substring(0, slash); |
80 | 0 | } |
81 | 0 | return (false); |
82 | } | |
83 | ||
84 | // Check for universal mapping | |
85 | 0 | if (pattern.equals("*")) |
86 | { | |
87 | 0 | return (true); |
88 | } | |
89 | ||
90 | 0 | return (false); |
91 | } | |
92 | ||
93 | 0 | public static final class KeyComparator implements Comparator<String> |
94 | { | |
95 | public int compare(String s1, String s2) | |
96 | { | |
97 | 0 | return -s1.compareTo(s2); |
98 | } | |
99 | } | |
100 | ||
101 | 0 | public static class NullWriter extends Writer |
102 | { | |
103 | ||
104 | 0 | static final NullWriter INSTANCE = new NullWriter(); |
105 | ||
106 | public void write(char[] buffer) | |
107 | { | |
108 | 0 | } |
109 | ||
110 | public void write(char[] buffer, int off, int len) | |
111 | { | |
112 | 0 | } |
113 | ||
114 | public void write(String str) | |
115 | { | |
116 | 0 | } |
117 | ||
118 | public void write(int c) | |
119 | { | |
120 | 0 | } |
121 | ||
122 | public void write(String str, int off, int len) | |
123 | { | |
124 | 0 | } |
125 | ||
126 | public void close() | |
127 | { | |
128 | 0 | } |
129 | ||
130 | public void flush() | |
131 | { | |
132 | 0 | } |
133 | } | |
134 | } |