The following script shows how you can call the FOP server from a Visual
Basic 6 program:
Dim inet
Dim xml As String
Dim Chunk() As Byte
Dim Size As Long
Dim Remaining As Long
'Create instance of object
Set inet = CreateObject("InetCtls.Inet")
'Set timeout to say 20 secs
inet.RequestTimeout = 20
'input XML data
xml = "<?xml version=""1.0"" encoding=""iso-8859-1""?> <departments><department><departmentName>R&D</departmentName> <person> <name>John Schmidt</name> "
xml = xml & "<address>Red street 3</address> <status>A</status> </person> <person> <name>Paul Bones</name> <address>White street 5</address> <status>A</status> "
xml = xml & "</person> <person> <name>Mark Mayer</name> <address>Blue street 5</address> <status>A</status> </person> <person> <name>Janet Black</name> "
xml = xml & "<address>Black street 8</address> <status>I</status> </person></department><department> <departmentName>Sales</departmentName> <person> "
xml = xml & "<name>Juan Gomez</name> <address>Green street 3</address> <status>A</status> </person> <person> <name>Juliet Bones</name> <address>White street 5</address> "
xml = xml & " <status>A</status> </person></department></departments>"
'Call the FOP Server, passing the name of the template in
the URL
inet.Execute "http://localhost:8087/J4LFOPServer/servlet?TEMPLATE=departmentEmployees.fo", "post", xml, "Content-Type: text/xml"
Do While inet.StillExecuting
DoEvents
Loop
' read output size
Size = CLng(inet.GetHeader("Content-Length"))
Remaining = Size
Dim filename As String
Dim fnum As Long
filename = "output.pdf"
fnum = FreeFile
Open filename For Binary Access Write As #fnum
' read all bytes of the http response and save them to a file
Do Until Remaining = 0
If Remaining > 1024
Then
Chunk = inet.GetChunk(1024, icByteArray)
Remaining = Remaining - 1024
Else
Chunk = inet.GetChunk(Remaining, icByteArray)
Remaining = 0
End If
Put #fnum, , Chunk
Loop
Close #fnum
|