Skip to content

Commit 1b0fe54

Browse files
authored
Merge pull request #584 from eclipse-mylyn/577-replace-orgapachecommonslang3stringescapeutils-with-orgapachecommonstextstringescapeutils
577 replace orgapachecommonslang3stringescapeutils with orgapachecommonstextstringescapeutils
2 parents c045def + cac5dab commit 1b0fe54

File tree

9 files changed

+55
-145
lines changed

9 files changed

+55
-145
lines changed

mylyn.commons/org.eclipse.mylyn.commons.core/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ Export-Package: org.eclipse.mylyn.commons.core,
1414
org.eclipse.mylyn.commons.core.storage;x-internal:=true,
1515
org.eclipse.mylyn.internal.commons.core;x-internal:=true,
1616
org.eclipse.mylyn.internal.commons.core.operations;x-internal:=true
17-
Import-Package: org.apache.commons.collections4.multimap;version="4.4.0"
17+
Import-Package: org.apache.commons.collections4.multimap;version="4.4.0",
18+
org.apache.commons.text;version="[1.12.0,2.0.0)"
1819
Require-Bundle: org.eclipse.core.net;bundle-version="0.0.0",
1920
org.eclipse.core.runtime;bundle-version="0.0.0"
2021
Bundle-ClassPath: .

mylyn.commons/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/HtmlStreamTokenizer.java

Lines changed: 18 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*******************************************************************************
22
* Copyright (c) 2004, 2013 Tasktop Technologies and others.
3-
*
3+
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0 which is available at
66
* https://www.eclipse.org/legal/epl-2.0
7-
*
7+
*
88
* SPDX-License-Identifier: EPL-2.0
99
*
1010
* Tasktop Technologies - initial API and implementation
@@ -20,9 +20,11 @@
2020
import java.util.HashMap;
2121
import java.util.Locale;
2222

23+
import org.apache.commons.text.StringEscapeUtils;
24+
2325
/**
2426
* Parses HTML into tokens.
25-
*
27+
*
2628
* @author Shawn Minto
2729
* @since 3.7
2830
*/
@@ -61,7 +63,7 @@ public class HtmlStreamTokenizer {
6163

6264
/**
6365
* Constructor.
64-
*
66+
*
6567
* @param in
6668
* reader for the HTML document to tokenize
6769
* @param base
@@ -286,7 +288,7 @@ private static void parseAttributes(HtmlTag tag, String s, int i, boolean escape
286288
return; // shouldn't happen if input returned by nextToken
287289
}
288290
if (escapeValues) {
289-
attributeValue = unescape(s.substring(start, i));
291+
attributeValue = StringEscapeUtils.unescapeHtml4(s.substring(start, i));
290292
} else {
291293
attributeValue = s.substring(start, i);
292294
}
@@ -299,7 +301,7 @@ private static void parseAttributes(HtmlTag tag, String s, int i, boolean escape
299301
if (i == s.length()) {
300302
return; // shouldn't happen if input returned by nextToken
301303
}
302-
attributeValue = unescape(s.substring(start, i));
304+
attributeValue = StringEscapeUtils.unescapeHtml4(s.substring(start, i));
303305
i++;
304306
} else {
305307
start = i;
@@ -314,70 +316,22 @@ private static void parseAttributes(HtmlTag tag, String s, int i, boolean escape
314316

315317
/**
316318
* Returns a string with HTML escapes changed into their corresponding characters.
317-
*
318-
* @deprecated use {@link StringEscapeUtils#unescapeHtml(String)} instead
319+
*
320+
* @deprecated use {@link StringEscapeUtils#unescapeHtml4(String)} instead
319321
*/
320-
@Deprecated
322+
@Deprecated(forRemoval = true, since = "4.4.0")
321323
public static String unescape(String s) {
322-
if (s.indexOf('&') == -1) {
323-
return s;
324-
} else {
325-
StringBuffer sb = new StringBuffer(s);
326-
unescape(sb);
327-
return sb.toString();
328-
}
324+
return StringEscapeUtils.unescapeHtml4(s);
329325
}
330326

331327
/**
332328
* Replaces (in-place) HTML escapes in a StringBuffer with their corresponding characters.
333-
*
334-
* @deprecated use {@link StringEscapeUtils#unescapeHtml(String)} instead
329+
*
330+
* @deprecated use {@link StringEscapeUtils#unescapeHtml4(String)} instead
335331
*/
336-
@Deprecated
332+
@Deprecated(forRemoval = true, since = "4.4.0")
337333
public static StringBuffer unescape(StringBuffer sb) {
338-
int i = 0; // index into the unprocessed section of the buffer
339-
int j = 0; // index into the processed section of the buffer
340-
341-
while (i < sb.length()) {
342-
char ch = sb.charAt(i);
343-
if (ch == '&') {
344-
int start = i;
345-
String escape = null;
346-
for (i = i + 1; i < sb.length(); i++) {
347-
ch = sb.charAt(i);
348-
if (!Character.isLetterOrDigit(ch) && !(ch == '#' && i == start + 1)) {
349-
escape = sb.substring(start + 1, i);
350-
break;
351-
}
352-
}
353-
if (i == sb.length() && i != start + 1) {
354-
escape = sb.substring(start + 1);
355-
}
356-
if (escape != null) {
357-
Character character = parseReference(escape);
358-
if (character != null && !(0x0A == character || 0x0D == character || 0x09 == ch
359-
|| character >= 0x20 && character <= 0xD7FF || character >= 0xE000 && character <= 0xFFFD
360-
|| character >= 0x10000 && character <= 0x10FFFF)) {
361-
// Character is an invalid xml character
362-
// http://www.w3.org/TR/REC-xml/#charsets
363-
character = null;
364-
}
365-
if (character != null) {
366-
ch = character;
367-
} else {
368-
// not an HTML escape; rewind
369-
i = start;
370-
ch = '&';
371-
}
372-
}
373-
}
374-
sb.setCharAt(j, ch);
375-
i++;
376-
j++;
377-
}
378-
379-
sb.setLength(j);
380-
return sb;
334+
return sb.replace(0, sb.length(), StringEscapeUtils.unescapeHtml4(sb.toString()));
381335
}
382336

383337
/**
@@ -555,12 +509,12 @@ private State() {
555509

556510
/*
557511
* Based on ISO 8879.
558-
*
512+
*
559513
* Portions (c) International Organization for Standardization 1986
560514
* Permission to copy in any form is granted for use with conforming SGML
561515
* systems and applications as defined in ISO 8879, provided this notice is
562516
* included in all copies.
563-
*
517+
*
564518
*/
565519
static {
566520
entities = new HashMap<>();

mylyn.commons/org.eclipse.mylyn.commons.net/META-INF/MANIFEST.MF

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ Import-Package: org.apache.commons.httpclient;version="3.1.0",
2424
org.apache.commons.httpclient.params;version="3.1.0",
2525
org.apache.commons.httpclient.protocol;version="3.1.0",
2626
org.apache.commons.httpclient.util;version="3.1.0",
27-
org.apache.commons.lang3;version="3.0.0",
28-
org.apache.commons.logging;version="[1.0.4,2.0.0)"
27+
org.apache.commons.logging;version="[1.0.4,2.0.0)",
28+
org.apache.commons.text;version="[1.12.0,2.0.0)"

mylyn.commons/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/commons/net/HtmlStreamTokenizer.java

Lines changed: 17 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*******************************************************************************
22
* Copyright (c) 2004, 2011 Tasktop Technologies and others.
3-
*
3+
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0 which is available at
66
* https://www.eclipse.org/legal/epl-2.0
7-
*
7+
*
88
* SPDX-License-Identifier: EPL-2.0
99
*
1010
* Tasktop Technologies - initial API and implementation
@@ -20,11 +20,11 @@
2020
import java.util.HashMap;
2121
import java.util.Locale;
2222

23-
import org.apache.commons.lang3.StringEscapeUtils;
23+
import org.apache.commons.text.StringEscapeUtils;
2424

2525
/**
2626
* Parses HTML into tokens.
27-
*
27+
*
2828
* @author Shawn Minto
2929
* @since 2.0
3030
* @deprecated use org.eclipse.mylyn.commons.core.HtmlStreamTokenizer instead.
@@ -65,7 +65,7 @@ public class HtmlStreamTokenizer {
6565

6666
/**
6767
* Constructor.
68-
*
68+
*
6969
* @param in
7070
* reader for the HTML document to tokenize
7171
* @param base
@@ -283,7 +283,7 @@ private static void parseAttributes(HtmlTag tag, String s, int i, boolean escape
283283
return; // shouldn't happen if input returned by nextToken
284284
}
285285
if (escapeValues) {
286-
attributeValue = unescape(s.substring(start, i));
286+
attributeValue = StringEscapeUtils.unescapeHtml4(s.substring(start, i));
287287
} else {
288288
attributeValue = s.substring(start, i);
289289
}
@@ -296,7 +296,7 @@ private static void parseAttributes(HtmlTag tag, String s, int i, boolean escape
296296
if (i == s.length()) {
297297
return; // shouldn't happen if input returned by nextToken
298298
}
299-
attributeValue = unescape(s.substring(start, i));
299+
attributeValue = StringEscapeUtils.unescapeHtml4(s.substring(start, i));
300300
i++;
301301
} else {
302302
start = i;
@@ -311,70 +311,22 @@ private static void parseAttributes(HtmlTag tag, String s, int i, boolean escape
311311

312312
/**
313313
* Returns a string with HTML escapes changed into their corresponding characters.
314-
*
315-
* @deprecated use {@link StringEscapeUtils#unescapeHtml(String)} instead
314+
*
315+
* @deprecated use {@link StringEscapeUtils#unescapeHtml4(String)} instead
316316
*/
317-
@Deprecated
317+
@Deprecated(forRemoval = true, since = "4.4.0")
318318
public static String unescape(String s) {
319-
if (s.indexOf('&') == -1) {
320-
return s;
321-
} else {
322-
StringBuffer sb = new StringBuffer(s);
323-
unescape(sb);
324-
return sb.toString();
325-
}
319+
return StringEscapeUtils.unescapeHtml4(s);
326320
}
327321

328322
/**
329323
* Replaces (in-place) HTML escapes in a StringBuffer with their corresponding characters.
330-
*
331-
* @deprecated use {@link StringEscapeUtils#unescapeHtml(String)} instead
324+
*
325+
* @deprecated use {@link StringEscapeUtils#unescapeHtml4(String)} instead
332326
*/
333-
@Deprecated
327+
@Deprecated(forRemoval = true, since = "4.4.0")
334328
public static StringBuffer unescape(StringBuffer sb) {
335-
int i = 0; // index into the unprocessed section of the buffer
336-
int j = 0; // index into the processed section of the buffer
337-
338-
while (i < sb.length()) {
339-
char ch = sb.charAt(i);
340-
if (ch == '&') {
341-
int start = i;
342-
String escape = null;
343-
for (i = i + 1; i < sb.length(); i++) {
344-
ch = sb.charAt(i);
345-
if (!Character.isLetterOrDigit(ch) && !(ch == '#' && i == start + 1)) {
346-
escape = sb.substring(start + 1, i);
347-
break;
348-
}
349-
}
350-
if (i == sb.length() && i != start + 1) {
351-
escape = sb.substring(start + 1);
352-
}
353-
if (escape != null) {
354-
Character character = parseReference(escape);
355-
if (character != null && !(0x0A == character || 0x0D == character || 0x09 == ch
356-
|| character >= 0x20 && character <= 0xD7FF || character >= 0xE000 && character <= 0xFFFD
357-
|| character >= 0x10000 && character <= 0x10FFFF)) {
358-
// Character is an invalid xml character
359-
// http://www.w3.org/TR/REC-xml/#charsets
360-
character = null;
361-
}
362-
if (character != null) {
363-
ch = character;
364-
} else {
365-
// not an HTML escape; rewind
366-
i = start;
367-
ch = '&';
368-
}
369-
}
370-
}
371-
sb.setCharAt(j, ch);
372-
i++;
373-
j++;
374-
}
375-
376-
sb.setLength(j);
377-
return sb;
329+
return sb.replace(0, sb.length(), StringEscapeUtils.unescapeHtml4(sb.toString()));
378330
}
379331

380332
/**
@@ -552,12 +504,12 @@ private State() {
552504

553505
/*
554506
* Based on ISO 8879.
555-
*
507+
*
556508
* Portions (c) International Organization for Standardization 1986
557509
* Permission to copy in any form is granted for use with conforming SGML
558510
* systems and applications as defined in ISO 8879, provided this notice is
559511
* included in all copies.
560-
*
512+
*
561513
*/
562514
static {
563515
entities = new HashMap<>();

mylyn.commons/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/commons/net/WebUtil.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*******************************************************************************
22
* Copyright (c) 2004, 2024 Tasktop Technologies and others.
3-
*
3+
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0 which is available at
66
* https://www.eclipse.org/legal/epl-2.0
7-
*
7+
*
88
* SPDX-License-Identifier: EPL-2.0
99
*
1010
* Tasktop Technologies - initial API and implementation
@@ -55,7 +55,7 @@
5555
import org.apache.commons.httpclient.protocol.Protocol;
5656
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
5757
import org.apache.commons.httpclient.util.IdleConnectionTimeoutThread;
58-
import org.apache.commons.lang3.StringEscapeUtils;
58+
import org.apache.commons.text.StringEscapeUtils;
5959
import org.eclipse.core.net.proxy.IProxyData;
6060
import org.eclipse.core.net.proxy.IProxyService;
6161
import org.eclipse.core.runtime.Assert;
@@ -515,7 +515,7 @@ public static int getSocketTimeout() {
515515

516516
/**
517517
* Returns the title of a web page.
518-
*
518+
*
519519
* @throws IOException
520520
* if a network occurs
521521
* @return the title; null, if the title could not be determined;
@@ -589,7 +589,7 @@ private static String getText(HtmlStreamTokenizer tokenizer) throws IOException,
589589
* <li>Headless: <code>Mylyn MyProduct HttpClient/3.1 Java/1.5.0_13 (Sun) Linux/2.6.22-14-generic (i386)</code>
590590
* <li>Eclipse:
591591
* <code>Mylyn/2.2.0 Eclipse/3.4.0 (org.eclipse.sdk.ide) HttpClient/3.1 Java/1.5.0_13 (Sun) Linux/2.6.22-14-generic (i386; en_CA)</code>
592-
*
592+
*
593593
* @param product
594594
* an identifier that is inserted into the returned user agent string
595595
* @return a user agent string
@@ -641,7 +641,7 @@ private static String stripQualifier(String longVersion) {
641641

642642
/**
643643
* For standalone applications that want to provide a global proxy service.
644-
*
644+
*
645645
* @param proxyService
646646
* the proxy service
647647
* @since 3.0
@@ -736,7 +736,7 @@ public static Proxy getProxy(String host, String proxyType) {
736736

737737
/**
738738
* Returns the platform default proxy for <code>url</code> or <code>null</code> if none.
739-
*
739+
*
740740
* @since 3.5
741741
*/
742742
public static Proxy getProxyForUrl(String url) {
@@ -793,7 +793,7 @@ public static Proxy createProxy(String proxyHost, int proxyPort, AuthenticationC
793793
/**
794794
* Releases the connection used by <code>method</code>. If <code>monitor</code> is cancelled the connection is aborted to avoid
795795
* blocking.
796-
*
796+
*
797797
* @since 3.4
798798
*/
799799
public static void releaseConnection(HttpMethodBase method, IProgressMonitor monitor) {

mylyn.reviews/org.eclipse.mylyn.gerrit.core/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@ Import-Package: com.github.benmanes.caffeine.cache;version="3.1.8",
5151
org.apache.commons.httpclient.methods;version="3.1.0",
5252
org.apache.commons.httpclient.util;version="3.1.0",
5353
org.apache.commons.io;version="1.4.0",
54-
org.apache.commons.lang3;version="3.12.0"
54+
org.apache.commons.lang3;version="3.12.0",
55+
org.apache.commons.text;version="[1.12.0,2.0.0)"

0 commit comments

Comments
 (0)