Skip to content

Commit 6966183

Browse files
convert URLTools to Java
1 parent 6c94bf8 commit 6966183

1 file changed

Lines changed: 60 additions & 59 deletions

File tree

Lines changed: 60 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/* Copyright 2018 Philipp Salvisberg <philipp.salvisberg@trivadis.com>
1+
/*
2+
* Copyright 2018 Philipp Salvisberg <philipp.salvisberg@trivadis.com>
23
*
34
* Licensed under the Apache License, Version 2.0 (the "License");
45
* you may not use this file except in compliance with the License.
@@ -12,63 +13,63 @@
1213
* See the License for the specific language governing permissions and
1314
* limitations under the License.
1415
*/
15-
package org.utplsql.sqldev.model
16+
package org.utplsql.sqldev.model;
1617

17-
import java.net.URL
18-
import java.util.regex.Pattern
18+
import java.net.URL;
19+
import java.util.regex.Matcher;
20+
import java.util.regex.Pattern;
1921

20-
class URLTools {
21-
def replaceHexChars(String input) {
22-
var String output = input;
23-
val p = Pattern.compile("%([0-9A-F]{2})")
24-
val m = p.matcher(input)
25-
while (m.find) {
26-
val what = m.group(0);
27-
val decimal = Integer.parseInt(m.group(1), 16)
28-
val with = String.valueOf(decimal as char)
29-
output = output.replace(what, with)
30-
}
31-
return output
32-
}
33-
34-
def getConnectionName(URL url) {
35-
val p = Pattern.compile("(sqldev.nav:)([^/]+)(//)?")
36-
val m = p.matcher(url.toString)
37-
if (m.find) {
38-
return m.group(2).replace("IdeConnections%2523", "IdeConnections%23").replaceHexChars
39-
} else {
40-
return ""
41-
}
42-
}
43-
44-
def getSchema(URL url) {
45-
val p = Pattern.compile("(//)([^/]+)")
46-
val m = p.matcher(url.toString)
47-
if (m.find) {
48-
return m.group(2)
49-
} else {
50-
return ""
51-
}
52-
}
53-
54-
def getObjectType(URL url) {
55-
val p = Pattern.compile("(//)([^/]+)(/)([^/]+)")
56-
val m = p.matcher(url.toString)
57-
if (m.find) {
58-
return m.group(4)
59-
} else {
60-
return ""
61-
}
62-
}
63-
64-
def getMemberObject(URL url) {
65-
val p = Pattern.compile("(/)([^/]+)(#MEMBER)")
66-
val m = p.matcher(url.toString)
67-
68-
if (m.find) {
69-
return m.group(2)
70-
} else {
71-
return ""
72-
}
73-
}
74-
}
22+
public class URLTools {
23+
public String replaceHexChars(final String input) {
24+
String output = input;
25+
final Pattern p = Pattern.compile("%([0-9A-F]{2})");
26+
final Matcher m = p.matcher(input);
27+
while (m.find()) {
28+
final String what = m.group(0);
29+
final int decimal = Integer.parseInt(m.group(1), 16);
30+
final String with = String.valueOf((char) decimal);
31+
output = output.replace(what, with);
32+
}
33+
return output;
34+
}
35+
36+
public String getConnectionName(final URL url) {
37+
final Pattern p = Pattern.compile("(sqldev.nav:)([^/]+)(//)?");
38+
final Matcher m = p.matcher(url.toString());
39+
if (m.find()) {
40+
return replaceHexChars(m.group(2).replace("IdeConnections%2523", "IdeConnections%23"));
41+
} else {
42+
return "";
43+
}
44+
}
45+
46+
public String getSchema(final URL url) {
47+
final Pattern p = Pattern.compile("(//)([^/]+)");
48+
final Matcher m = p.matcher(url.toString());
49+
if (m.find()) {
50+
return m.group(2);
51+
} else {
52+
return "";
53+
}
54+
}
55+
56+
public String getObjectType(final URL url) {
57+
final Pattern p = Pattern.compile("(//)([^/]+)(/)([^/]+)");
58+
final Matcher m = p.matcher(url.toString());
59+
if (m.find()) {
60+
return m.group(4);
61+
} else {
62+
return "";
63+
}
64+
}
65+
66+
public String getMemberObject(final URL url) {
67+
final Pattern p = Pattern.compile("(/)([^/]+)(#MEMBER)");
68+
final Matcher m = p.matcher(url.toString());
69+
if (m.find()) {
70+
return m.group(2);
71+
} else {
72+
return "";
73+
}
74+
}
75+
}

0 commit comments

Comments
 (0)