introduce URLUtil.decode as a solution for non-modern JDK API

To avoid ugly code in each client of URLDecoder.decode

GitOrigin-RevId: 290792e688fc8d7a126305196a0b621701e097eb
This commit is contained in:
Vladimir Krivosheev
2019-04-30 14:04:06 +02:00
committed by intellij-monorepo-bot
parent 1de1a89309
commit 01e2a00a03
9 changed files with 36 additions and 73 deletions

View File

@@ -1,18 +1,16 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.python.debugger;
import com.intellij.util.io.URLUtil;
import com.jetbrains.python.console.pydev.AbstractPyCodeCompletion;
import com.jetbrains.python.console.pydev.PydevCompletionVariant;
import org.jetbrains.annotations.Nullable;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import java.io.ByteArrayInputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
@@ -31,8 +29,7 @@ public class PydevXmlUtils {
}
static SAXParser getSAXParser() throws Exception {
SAXParser parser = null;
SAXParser parser;
synchronized (parserFactory) {
parser = parserFactory.newSAXParser();
}
@@ -43,12 +40,7 @@ public class PydevXmlUtils {
@Nullable
private static String decode(String value) {
if (value != null) {
try {
return URLDecoder.decode(value, "UTF-8");
}
catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
return URLUtil.decode(value);
}
return null;
}
@@ -115,8 +107,7 @@ public class PydevXmlUtils {
}
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
public void startElement(String uri, String localName, String qName, Attributes attributes) {
// <comp p0="%s" p1="%s" p2="%s" p3="%s"/>
if (qName.equals("comp")) {

View File

@@ -1,5 +1,7 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.python.debugger.pydev;
import com.intellij.util.io.URLUtil;
import com.jetbrains.python.debugger.PyDebugValue;
import com.jetbrains.python.debugger.PyDebuggerException;
import com.jetbrains.python.debugger.PyReferringObjectsValue;
@@ -21,7 +23,7 @@ public class GetReferrersCommand extends RunCustomOperationCommand<List<PyDebugV
return new ResponseProcessor<List<PyDebugValue>>() {
@Override
protected List<PyDebugValue> parseResponse(ProtocolFrame response) throws PyDebuggerException {
return ProtocolParser.parseReferrers(decode(response.getPayload()), getDebugger().getDebugProcess());
return ProtocolParser.parseReferrers(URLUtil.decode(response.getPayload()), getDebugger().getDebugProcess());
}
};
}

View File

@@ -1,5 +1,7 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.python.debugger.pydev;
import com.intellij.util.io.URLUtil;
import com.jetbrains.python.debugger.PyDebuggerException;
import org.jetbrains.annotations.NotNull;
@@ -26,7 +28,7 @@ public class ProtocolFrame {
myCommand = Integer.parseInt(parts[0]);
mySequence = Integer.parseInt(parts[1]);
myPayload = (parts.length == 3 && !parts[2].isEmpty() ? ProtocolParser.decode(parts[2]) : "").trim();
myPayload = (parts.length == 3 && !parts[2].isEmpty() ? URLUtil.decode(parts[2]) : "").trim();
}
public int getCommand() {

View File

@@ -1,9 +1,10 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.python.debugger.pydev;
import com.google.common.collect.Lists;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.io.URLUtil;
import com.jetbrains.python.debugger.*;
import com.thoughtworks.xstream.io.naming.NoNameCoder;
import com.thoughtworks.xstream.io.xml.XppReader;
@@ -12,8 +13,6 @@ import org.jetbrains.annotations.NotNull;
import org.xmlpull.mxp1.MXParser;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.LinkedList;
import java.util.List;
@@ -156,15 +155,6 @@ public class ProtocolParser {
return payload;
}
public static String decode(final String value) throws PyDebuggerException {
try {
return URLDecoder.decode(value, "UTF-8");
}
catch (UnsupportedEncodingException e) {
throw new PyDebuggerException("Unable to decode: " + value + ", reason: " + e.getMessage());
}
}
public static String encodeExpression(final String expression) {
return StringUtil.replace(expression, "\n", "@LINE@");
}
@@ -435,6 +425,6 @@ public class ProtocolParser {
if (value == null && isRequired) {
throw new PyDebuggerException("Attribute not found: " + name);
}
return value == null ? null : decode(value);
return value == null ? null : URLUtil.decode(value);
}
}

View File

@@ -1,9 +1,9 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.python.debugger.pydev;
import com.intellij.openapi.diagnostic.Logger;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
@@ -71,15 +71,5 @@ public class RunCustomOperationCommand<T> extends AbstractCommand<T> {
return "";
}
}
protected static String decode(String in) {
try {
return URLDecoder.decode(in, "UTF-8");
} catch (UnsupportedEncodingException e) {
LOG.error("Unreachable? UTF-8 is always supported.", e);
return "";
}
}
}