1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.view.facelets;
20
21 import java.io.Writer;
22 import java.util.Comparator;
23
24
25
26
27
28 public class FaceletsVDLUtils
29 {
30
31
32
33
34
35
36
37
38 public static boolean matchPattern(String path, String pattern)
39 {
40
41 if ((path == null) || (path.length() == 0))
42 {
43 path = "*";
44 }
45 if ((pattern == null) || (pattern.length() == 0))
46 {
47 pattern = "*";
48 }
49
50
51 if (path.equals(pattern))
52 {
53 return (true);
54 }
55
56
57 if (pattern.startsWith("/") && pattern.endsWith("/*"))
58 {
59 pattern = pattern.substring(0, pattern.length() - 2);
60 if (pattern.length() == 0)
61 {
62 return (true);
63 }
64 if (path.endsWith("/"))
65 {
66 path = path.substring(0, path.length() - 1);
67 }
68 while (true)
69 {
70 if (pattern.equals(path))
71 {
72 return (true);
73 }
74 int slash = path.lastIndexOf('/');
75 if (slash <= 0)
76 {
77 break;
78 }
79 path = path.substring(0, slash);
80 }
81 return (false);
82 }
83
84
85 if (pattern.equals("*"))
86 {
87 return (true);
88 }
89
90 return (false);
91 }
92
93 public static final class KeyComparator implements Comparator<String>
94 {
95 public int compare(String s1, String s2)
96 {
97 return -s1.compareTo(s2);
98 }
99 }
100
101 public static class NullWriter extends Writer
102 {
103
104 static final NullWriter INSTANCE = new NullWriter();
105
106 public void write(char[] buffer)
107 {
108 }
109
110 public void write(char[] buffer, int off, int len)
111 {
112 }
113
114 public void write(String str)
115 {
116 }
117
118 public void write(int c)
119 {
120 }
121
122 public void write(String str, int off, int len)
123 {
124 }
125
126 public void close()
127 {
128 }
129
130 public void flush()
131 {
132 }
133 }
134 }