Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
CommentUtils |
|
| 5.6;5.6 |
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.shared.util; | |
20 | ||
21 | /** | |
22 | * This class contains utility methods to detect special cases to be handled on "script" or | |
23 | * "style" tags by HtmlResponseWriterImpl. | |
24 | */ | |
25 | 0 | public class CommentUtils |
26 | { | |
27 | public static final String INLINE_SCRIPT_COMMENT = "//"; | |
28 | public static final String START_SCRIPT_COMMENT = "/*"; | |
29 | public static final String END_SCRIPT_COMMENT = "*/"; | |
30 | public static final String CDATA_SIMPLE_START = "<![CDATA["; | |
31 | public static final String CDATA_SIMPLE_END = "]]>"; | |
32 | public static final String COMMENT_SIMPLE_START = "<!--"; | |
33 | public static final String COMMENT_SIMPLE_END = "-->"; | |
34 | ||
35 | public static boolean isStartMatchWithCommentedCDATA(String trimmedContent) | |
36 | { | |
37 | 13 | if (trimmedContent.startsWith(START_SCRIPT_COMMENT)) |
38 | { | |
39 | 3 | int offset = 2; |
40 | 7 | while (trimmedContent.charAt(offset) <= ' ') |
41 | { | |
42 | 4 | offset++; |
43 | } | |
44 | 3 | if (trimmedContent.startsWith(CDATA_SIMPLE_START, offset)) |
45 | { | |
46 | 3 | return true; |
47 | } | |
48 | } | |
49 | 10 | return false; |
50 | } | |
51 | ||
52 | public static boolean isEndMatchWithCommentedCDATA(String trimmedContent) | |
53 | { | |
54 | 3 | if (trimmedContent.endsWith(END_SCRIPT_COMMENT)) |
55 | { | |
56 | 3 | int offset = trimmedContent.length()-3; |
57 | 7 | while (trimmedContent.charAt(offset) <= ' ') |
58 | { | |
59 | 4 | offset--; |
60 | } | |
61 | // CDATA_SIMPLE_END.length() = 3 | |
62 | // So, -3 +1 = -2 | |
63 | 3 | if (trimmedContent.startsWith(CDATA_SIMPLE_END, offset - 2)) |
64 | { | |
65 | 3 | return true; |
66 | } | |
67 | } | |
68 | 0 | return false; |
69 | } | |
70 | ||
71 | public static boolean isEndMatchtWithInlineCommentedXmlCommentTag(String trimmedContent) | |
72 | { | |
73 | 4 | if (trimmedContent.endsWith(COMMENT_SIMPLE_END)) |
74 | { | |
75 | 4 | int offset = trimmedContent.length()-4; |
76 | 9 | while (trimmedContent.charAt(offset) <= ' ' && |
77 | trimmedContent.charAt(offset) != '\n') | |
78 | { | |
79 | 5 | offset--; |
80 | } | |
81 | // INLINE_SCRIPT_COMMENT.length() = 2 | |
82 | // So, -2 +1 = -1 | |
83 | 4 | if (trimmedContent.startsWith(INLINE_SCRIPT_COMMENT, offset - 1)) |
84 | { | |
85 | 3 | return true; |
86 | } | |
87 | } | |
88 | 1 | return false; |
89 | } | |
90 | ||
91 | public static boolean isStartMatchWithInlineCommentedCDATA(String trimmedContent) | |
92 | { | |
93 | 12 | if (trimmedContent.startsWith(INLINE_SCRIPT_COMMENT)) |
94 | { | |
95 | 4 | int offset = 2; |
96 | 8 | while (trimmedContent.charAt(offset) <= ' ' && |
97 | trimmedContent.charAt(offset) != '\n') | |
98 | { | |
99 | 4 | offset++; |
100 | } | |
101 | 4 | if (trimmedContent.startsWith(CDATA_SIMPLE_START, offset)) |
102 | { | |
103 | 3 | return true; |
104 | } | |
105 | } | |
106 | 9 | return false; |
107 | } | |
108 | ||
109 | public static boolean isEndMatchWithInlineCommentedCDATA(String trimmedContent) | |
110 | { | |
111 | 4 | if (trimmedContent.endsWith(CDATA_SIMPLE_END)) |
112 | { | |
113 | 4 | int offset = trimmedContent.length()- 4; |
114 | 9 | while (trimmedContent.charAt(offset) <= ' ' && |
115 | trimmedContent.charAt(offset) != '\n') | |
116 | { | |
117 | 5 | offset--; |
118 | } | |
119 | // INLINE_SCRIPT_COMMENT.length() = 2 | |
120 | // So, -2 +1 = -1 | |
121 | 4 | if (trimmedContent.startsWith(INLINE_SCRIPT_COMMENT, offset - 1)) |
122 | { | |
123 | 3 | return true; |
124 | } | |
125 | } | |
126 | 1 | return false; |
127 | } | |
128 | } |