### Inline Java Ext Library jSoup/1

B4J UI Application - Inline Java jSoup showing WikiPedia Headlines in HTML Browser.
Reference jSoup: http://www.jsoup.org
Region Project Notes
'Add the library JavaObject
'Additional jar to include: jsoup-1.8.1
'Add the external jar jsoup-1.8.1.jar to the external libraries folder
'The version of the additional Jar might have changed. Lookup the related website
'jSoup Reference: http://www.jsoup.org
End Region
Region Project ToDo
End Region
Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 400
'External lib
#AdditionalJar: jsoup-1.8.1
End Region
`Sub Process_Globals
Private Const CAPPINFO As String = "B4JHowTo - Inline Java jSoupEx v20150224"
Private fx As JFX
Public joInlineJava As JavaObject = Me
End Sub`
'Start the app
'Get the wikipedia headlines as a list
'Build a list holding html tags inclusing the headlines (note that these are slightly modified)
'Save the list using textwriter in a html file and show the file in the default browser
`Sub AppStart (Form1 As Form, Args() As String)
Log(CAPPINFO)
Dim h As List : h.Initialize : h.AddAll(joInlineJava.RunMethod("getHeadlines", Null))
Dim l As List : l.Initialize
l.Add("

# WikiPedia In the News Headlines @ " & DateTime.Date(DateTime.Now) & "

")
For i = 0 To h.Size - 1
Dim hr As String = h.Get(i)
l.Add("
- " & hr.Replace("href=""", "href=""http://en.wikipedia.org") & "
")
Next
l.Add("

")
Dim tw As TextWriter
tw.Initialize(File.OpenOutput(File.DirApp, "headlines.html", False))
tw.WriteList(l)
tw.Flush
tw.Close
fx.ShowExternalDocument(File.GetUri(File.DirApp, "headlines.html"))
End Sub`
'Example from jSoup homepage
'Fetch the Wikipedia homepage, parse it to a DOM, and select the headlines from the In the news section into a list of Elements
If JAVA
import java.util.List;
import org.jsoup.Jsoup;
import org.jsoup.helper.Validate;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.IOException;
//Get the headlines as a list
public static List getHeadlines() throws IOException {
Document doc = Jsoup.connect("http://en.wikipedia.org/").get();
Elements newsHeadlines = doc.select("#mp-itn b a");
return newsHeadlines;
}
End If

Changed: , Category: Inline Java, File: T6C201M1473.htm, ID: 1473