Listing Folders From WebFOCUS

In this section:

This section provides code examples that demonstrate how to retrieve a list of the top-level folders from WebFOCUS. A successful sign-on request is a prerequisite for running this example, including retrieving the HTTP Header cookies from its response.


Top of page

x
Visual Basic .NET Example
Imports System.Net
Imports System.IO
Imports System.Text
Dim request3 As HttpWebRequest
Dim response3 As HttpWebResponse
Dim webStream3 As Stream
Dim webResponse3 As String = ""
Dim tempfile As String
request3 = WebRequest.Create("http://localhost:8080/ibi_apps/rs/ibfs/WFC/
Repository?IBIRS_action=get")
request3.Method = "GET"
'cookies is defined as CookieContainer in the Signing-On to WebFOCUS example
request3.CookieContainer = cookies
response3 = request3.GetResponse()
webStream3 = response3.GetResponseStream()
Dim webStreamReader3 As New StreamReader(webStream3)
tempfile = "c:\temp\Folders.xml"
FileOpen(1, tempfile, OpenMode.Output)
While webStreamReader3.Peek >= 0
     webResponse3 = webStreamReader3.ReadToEnd()
     PrintLine(1, webResponse3)
End While
FileClose(1)
Dim xmlElem = XElement.Parse(webResponse3)

Top of page

x
Java Example
import java.awt.Frame;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import org.apache.commons.httpclient.*; 
import org.apache.commons.httpclient.methods.*;
String request3 = "http://localhost:8080/ibi_apps/rs/ibfs/WFC/Repository?IBIRS_action=get";
						
GetMethod method_getFolders = new GetMethod(request3);
// cookies is defined as Header[] in the Signing-On to WebFOCUS example			
for(int h=0; h<cookies.length; h++){
       method_getFolders.addRequestHeader(cookies[h].getName(), cookies[h].getValue());
}
// client is defined as HttpClient in the Signing-On to WebFOCUS example 			
int statusCode3 = client.executeMethod(method_getFolders);
					
InputStream rstream3 = null;
rstream3 = method_getFolders.getResponseBodyAsStream();
File tempfile = new File("c:\\temp\\Folders.xml");
FileOutputStream fos = new FileOutputStream(tempfile);
PrintWriter out=new PrintWriter(fos);
BufferedReader br3 = new BufferedReader(new InputStreamReader(rstream3));
String line3;
String newOutput = null;
while ((line3 = br3.readLine()) != null) {
	newOutput = line3;
	out.println(newOutput);
	System.out.println(line3);
}
br3.close();
out.close();

Top of page

x
HTML and jQuery Example
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8" />
    <script type="text/javascript" src="http://code.jquery.com/jquery-3.1.0.js"> </script>
    <script type='text/javascript' src="http://cdnjs.cloudflare.com/ajax/libs/jquery-ajaxtransport-xdomainrequest/1.0.1/
jquery.xdomainrequest.min.js"></script>
    <script type="text/javascript">
        var csrf_name;
        var csrf_value;
        var frameToBeWorkedOn = "#AjaxPlaceHolder";
        var contentType = "application/x-www-form-urlencoded; charset=utf-8";
        $(document).ready(function (IBIRS_action, IBIRS_userName, IBIRS_password) {
            if (window.XDomainRequest)
                contentType = "text/plain";
            var webMethod = "http://machine:port/ibi_apps/rs/ibfs";
            var IBIRS_action = "signOn";
            var IBIRS_userName = "admin";
            var IBIRS_password = "admin";
            var parameters = 'IBIRS_action=' + IBIRS_action + '&IBIRS_userName=' + IBIRS_userName + '&IBIRS_password=' + IBIRS_password;
            $.ajax({
                type: "POST",
                url: webMethod,
                data: parameters,
                dataType: "xml",
                xhrFields: {
                    withCredentials: true
                },
                crossDomain: true,
                contentType: contentType,
                success: listFolders,
                error:function(jqXHR,textStatus,errorThrown)
                  {
                    alert("You can not send Cross Domain AJAX requests: " + errorThrown);
                  }
            })
        });
        function listFolders() {
            if (window.XDomainRequest)
                contentType = "text";
            var webMethod = "http://machine:port/ibi_apps/rs/ibfs/WFC/Repository";
            var IBIRS_action = "get";
            var parameters = 'IBIRS_action=' + IBIRS_action;
                       
            $.ajax({
                type: "GET",
                url: webMethod,
                data: parameters,
                dataType: "xml",
                xhrFields: {
                    withCredentials: true
                },
                crossDomain: true,
                success: xmlParse,
                //complete: function(xhr,status) {
                                   
                //   alert(xhr.responseText);
                //    AjaxPlaceHolder.innerText = xhr.responseText;
                //},
                error: function (jqXHR, textStatus, errorThrown) {
                    alert("You can not send Cross Domain AJAX requests: " + errorThrown);
                }
            })
        }
        
        function xmlParse(xml) {
            $(xml).find("item").each(function () {
                if ($(this).attr("type") == "MRFolder") {
                    folder_name = $(this).attr("name");
                    AjaxPlaceHolder.appendChild(document.createTextNode(folder_name  + "\n"));
                }
               
            });
           
        }
   </script>
</head>
<body>
    <h1>These are the top-level folders under the Respository</h1>
        <textarea id="AjaxPlaceHolder" name="AjaxPlaceHolder" style="position:absolute; width:500px; height:500px;" ></textarea> 
</body>
</html>

Information Builders