Simone
04/04/2022, 4:56 PMprivate static Data getdata(String url) {
if (url != null) {
String path = null;
try {
path = new URL(url).getPath().substring(1);
} catch (MalformedURLException e) {
e.printStackTrace();
}
if (path != null) {
if (path.indexOf('/') == -1) {
return getData(url, "User");
} else {
if (path.contains("music")) {
return getData(url, "Music");
} else if (path.contains("video")) {
return getData(url, "Video");
} else if (path.contains("tag")) {
return getData(url, "Tag");
}
}
}
}
return null;
}
Adam Cameron
Simone
04/04/2022, 4:59 PMSimone
04/04/2022, 4:59 PMtry {
path = new URL(url).getPath().substring(1);
} catch (MalformedURLException e) {
e.printStackTrace();
}
Simone
04/04/2022, 4:59 PMSimone
04/04/2022, 4:59 PMSimone
04/04/2022, 5:00 PMSimone
04/04/2022, 5:00 PMpath = new URL(url).getPath().substring(1)
and path.indexof('/')Adam Cameron
try
/ catch
block are you struggling with? What have you got so far?Simone
04/04/2022, 5:02 PMpath = new URL(url).getPath().substring(1)
Simone
04/04/2022, 5:02 PMAdam Cameron
Simone
04/04/2022, 5:11 PMAdam Cameron
<http://localhost:8080/website/user>
in it. And you want to get website/user
from it?Adam Cameron
[scheme]://[domain]:[port]/[the bit you want]
? I guess it won't always have the port?Adam Cameron
foundeo
Adam Cameron
Adam Cameron
foundeo
Simone
04/05/2022, 3:38 PMfoundeo
new URL()
but for someone who doesn’t know java, it’s probably not obvious what URL class that is… take a look at the import statements on the top of the file, you will probably find import java.net.URL
that tells you the full name of the class, and you can use that in CFML’s createObject()
functionfoundeo
new URL(url)
and you can write that in CFML as createObject("java", "<http://java.net|java.net>.URL").init(url)
— if you can understand how I did that, then you can understand how to convert pretty much all java code to cfmlSimone
04/05/2022, 5:27 PMSimone
04/05/2022, 5:27 PMdoc = Jsoup.connect(arguments.url).get();
now in CF i tried this but still not orking
filePaths[1] = expandPath("../cfc/jar/jsoup-1.14.3.jar");
loaderObj =createObject("component","jar.javaloader.JavaLoader").init(filePaths);
Jsoup = loaderObj.create("org.jsoup.Jsoup");
Simone
04/06/2022, 4:47 PMfoundeo