OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.distiller; | 5 package org.chromium.distiller; |
6 | 6 |
7 import com.google.gwt.dom.client.AnchorElement; | 7 import com.google.gwt.dom.client.AnchorElement; |
8 import com.google.gwt.dom.client.Document; | 8 import com.google.gwt.dom.client.Document; |
9 import com.google.gwt.dom.client.Element; | 9 import com.google.gwt.dom.client.Element; |
10 import com.google.gwt.dom.client.HeadingElement; | 10 import com.google.gwt.dom.client.HeadingElement; |
11 import com.google.gwt.dom.client.IFrameElement; | 11 import com.google.gwt.dom.client.IFrameElement; |
12 import com.google.gwt.dom.client.ImageElement; | 12 import com.google.gwt.dom.client.ImageElement; |
13 import com.google.gwt.dom.client.MetaElement; | 13 import com.google.gwt.dom.client.MetaElement; |
14 import com.google.gwt.dom.client.Text; | 14 import com.google.gwt.dom.client.Text; |
15 import com.google.gwt.dom.client.TitleElement; | 15 import com.google.gwt.dom.client.TitleElement; |
| 16 import com.google.gwt.dom.client.NodeList; |
16 import com.google.gwt.user.client.Random; | 17 import com.google.gwt.user.client.Random; |
17 import com.google.gwt.user.client.Window; | 18 import com.google.gwt.user.client.Window; |
18 | 19 |
19 import java.util.ArrayList; | 20 import java.util.ArrayList; |
20 import java.util.Collections; | 21 import java.util.Collections; |
21 import java.util.List; | 22 import java.util.List; |
22 | 23 |
23 /** | 24 /** |
24 * A mixed bag of stuff used in tests. | 25 * A mixed bag of stuff used in tests. |
25 */ | 26 */ |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 if (!strToAppend.isEmpty() && !StringUtil.match(noUrlParams, "\\/$")) { | 155 if (!strToAppend.isEmpty() && !StringUtil.match(noUrlParams, "\\/$")) { |
155 noUrlParams += "/"; | 156 noUrlParams += "/"; |
156 } | 157 } |
157 return noUrlParams + strToAppend; | 158 return noUrlParams + strToAppend; |
158 } | 159 } |
159 | 160 |
160 public static String removeAllDirAttributes(String originalHtml) { | 161 public static String removeAllDirAttributes(String originalHtml) { |
161 return originalHtml.replaceAll(" dir=\\\"(ltr|rtl|inherit|auto)\\\"","")
; | 162 return originalHtml.replaceAll(" dir=\\\"(ltr|rtl|inherit|auto)\\\"","")
; |
162 } | 163 } |
163 | 164 |
| 165 public static List<Element> nodeListToList(NodeList<Element> nodeList) { |
| 166 List<Element> elements = new ArrayList<>(); |
| 167 for (int i = 0; i < nodeList.getLength(); i++) { |
| 168 elements.add(nodeList.getItem(i)); |
| 169 } |
| 170 return elements; |
| 171 } |
| 172 |
164 /** | 173 /** |
165 * Randomly shuffle the list in-place. | 174 * Randomly shuffle the list in-place. |
166 */ | 175 */ |
167 public static void shuffle(List<?> list) { | 176 public static void shuffle(List<?> list) { |
168 int size = list.size(); | 177 int size = list.size(); |
169 for (int i=size; i>1; i--) { | 178 for (int i=size; i>1; i--) { |
170 Collections.swap(list, i-1, Random.nextInt(i)); | 179 Collections.swap(list, i-1, Random.nextInt(i)); |
171 } | 180 } |
172 } | 181 } |
173 } | 182 } |
OLD | NEW |