Business Objects XI Java SDK Example, Part 3

 

Continued from Business Objects XI Java SDK Example, Part 2

Using the Business Objects example applications is a good starting point for creating a first Java SDK application.

The sample applications provide some basic tasks, and an easy way to get started with the SDK is to use one of the examples, and trim out the code that you don't need.

For our application I pieced together several of the jsp's and combined them into 2 final jsps. To do this, I walked through the flow of the jsp examples and noted the dependencies, and ultimately combined them into to files (jsp's).

So in this example, there are 2 jsp's that are packaged at the root level of the web app (loginforward.jsp and data-getter.jsp). The contents are listed below:

loginforward.jsp



<!--
********************************************************************************

Adapted from WebIntelligence RE SDK JSP Tutorials 115.000.00000

Tutorials are Copyright (c) 2002-2005 Business Objects SA

********************************************************************************
-->

<%@ page language="java" errorPage="err_page.jsp"%>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="com.businessobjects.rebean.wi.ReportEngine" %>
<%@ page import="com.crystaldecisions.sdk.exception.SDKException" %>
<%@ page import="com.crystaldecisions.sdk.exception.SDKServerException" %>
<%@ page import="com.crystaldecisions.sdk.framework.CrystalEnterprise" %>
<%@ page import="com.crystaldecisions.sdk.framework.IEnterpriseSession" %>
<%@ page import="com.crystaldecisions.sdk.framework.ISessionMgr" %>
<%@ page import="com.crystaldecisions.sdk.occa.infostore.IInfoStore" %>
<%@ page import="com.crystaldecisions.sdk.occa.security.IUserInfo" %>
<%@ page import="com.crystaldecisions.sdk.occa.infostore.CeSecurityID" %>
<%@ page import="com.crystaldecisions.sdk.occa.infostore.IInfoObjects" %>
<%@ page import="com.crystaldecisions.sdk.occa.infostore.IInfoObject" %>
<%@ page import="com.crystaldecisions.sdk.plugin.desktop.server.IServer"%>
<%@ page import="com.crystaldecisions.sdk.plugin.CeKind" %>
<%@ page import="com.crystaldecisions.sdk.occa.enadmin.*" %>
<%@ page import="com.businessobjects.sdk.plugin.desktop.webintelligence.CeWebIntelligenceRightID" %>
<%@ page import="java.io.IOException" %>
<%@ page import="java.util.Hashtable" %>

<%@ include file="rights_method.jsp" %>

<%
request.setCharacterEncoding("utf-8");
String CMS = request.getParameter("CMS");
if (CMS.equals("localhost"))
response.sendRedirect("loginForm.jsp?strError=localhost");
String userName= request.getParameter("User");
String userPass = request.getParameter("Password");
String auth = request.getParameter("auth");

// doc identifier
request.setAttribute("docIdentifier",request.getParameter("docIdentifier"));

IEnterpriseSession enterpriseSession= null;
IInfoStore iStore = null;
IUserInfo userInfo = null;

try
{
//Open the session
final ISessionMgr sessionMgr = CrystalEnterprise.getSessionMgr();
enterpriseSession = sessionMgr.logon(userName, userPass, CMS, auth);

}
catch(SDKServerException ex)
{
%>
<jsp:forward page="error_wrongLogin.html" />
<%

}

catch(SDKException.SecurityError exSec)
{
%>
<jsp:forward page="error_authentication.html" />
<%
}

catch(SDKException.OCAFramework exOCA )
{
%>
<jsp:forward page="error_serverName.html" />
<%
}

catch(Exception e)
{

%>
<jsp:forward page="error_login.html" />
<%
}

try{

userInfo = enterpriseSession.getUserInfo();
iStore = (IInfoStore)enterpriseSession.getService("InfoStore");

ReportEngines reportEngines = null;
if (enterpriseSession != null)
{
reportEngines = (ReportEngines)request.getAttribute("ReportEngines");
if (reportEngines == null)
{
//Create a new ReportEngines
reportEngines = (ReportEngines)enterpriseSession.getService("ReportEngines");

request.setAttribute("ReportEngines", reportEngines);
}
}

}
catch (Exception e)
{
%>
<jsp:forward page="error_login.html" />
<%
}


String strSampleVersion = "11.5";

//Test the version of the server
String strQuery = "Select SI_ID, SI_NAME, SI_SERVER_KIND from CI_SYSTEMOBJECTS where SI_KIND ='" + CeKind.SERVER + "'" + " AND SI_SERVER_KIND= 'aps'";
IInfoObjects iServers = (IInfoObjects)iStore.query(strQuery);

String strShortServerVersion ="";
if (iServers != null)
{
IServer iServer = (IServer)iServers.get(0);
IServerGeneralMetrics iServerGeneralMetrics = (IServerGeneralMetrics) iServer.getServerGeneralAdmin();
String strServerVersion = iServerGeneralMetrics.getVersion();
strShortServerVersion = strServerVersion.substring(0,4);

}//if (IServers != null)


//Test the version of the REBEAN SDK
String strSDKVersion = enterpriseSession.getClass().getPackage().getImplementationVersion();
String strShortSDKVersion = strSDKVersion.substring(0,4);


String strErrorMessage="";
if (!strShortServerVersion.equals(strShortSDKVersion))
{
strErrorMessage="Warning: SDK and backbone versions do not match </br> Please update your sdk librairies to version" + strShortServerVersion;
}
else if((Float.parseFloat(strSampleVersion)) < (Float.parseFloat(strShortSDKVersion)) )
{
strErrorMessage = "Warning: application was not tested using version " + strShortSDKVersion + "of the sdk";
}
else if((Float.parseFloat(strSampleVersion)) > (Float.parseFloat(strShortSDKVersion)) )
{
strErrorMessage="Warning: application was developed with a more recent sdk. Execution may fail.";
}

if(!strErrorMessage.equals(""))
response.sendRedirect("error_version.jsp?message=" + strErrorMessage);

request.setAttribute("EnterpriseSession", enterpriseSession);

request.setAttribute("InfoStore", iStore);

//Store user info
session.setAttribute("UserInfo",userInfo);
request.setAttribute("UserInfo",userInfo);

//Check if the password has expired
if (userInfo.getPasswordExpiry() == 0){

StringBuffer urlChgPasswd = new StringBuffer();
urlChgPasswd = urlChgPasswd.append("forceChgPassword.jsp?");
urlChgPasswd = urlChgPasswd.append("User=");
urlChgPasswd = urlChgPasswd.append(userName);
urlChgPasswd = urlChgPasswd.append("&auth=");
urlChgPasswd = urlChgPasswd.append(auth);
urlChgPasswd = urlChgPasswd.append("&CMS=");
urlChgPasswd = urlChgPasswd.append(CMS);

response.sendRedirect(urlChgPasswd.toString());
}
else
{

// Get the folder id that is root of all universes
strQuery = "SELECT SI_ID, SI_NAME, SI_PARENTID FROM CI_APPOBJECTS " +
"WHERE SI_PARENTID = '" + CeSecurityID.Folder.SEMANTIC_LAYERS + "' AND SI_KIND = '" + CeKind.FOLDER + "' AND SI_NAME = 'Universes'";

IInfoObjects iInfoObjects = iStore.query(strQuery);
String strUniverseRootFolderId = "";

if (iInfoObjects != null && iInfoObjects.size() > 0)
strUniverseRootFolderId = String.valueOf(((IInfoObject) iInfoObjects.get(0)).getID());

// Store folder id that is root of all universes
session.setAttribute("UniverseRootFolderId", strUniverseRootFolderId);

// Create a Hashtable to store the rights of the user
Hashtable userRights = new Hashtable();

strQuery = "SELECT SI_ID, SI_KIND FROM CI_APPOBJECTS " +
"WHERE SI_PARENTID = '" + CeSecurityID.Folder.APPLICATIONS + "' AND SI_KIND = '" + CeKind.WEBINTELLIGENCE + "'";
IInfoObjects iWebiAppObjects = iStore.query(strQuery);

if (iWebiAppObjects != null && iWebiAppObjects.size()>0)
{
IInfoObject iWebiAppObject = (IInfoObject) iWebiAppObjects.get(0);

// Check the some rights on the application object "Webintelligence" and store their value in the hashtable userRights
checkApplicationObjectRight(CeWebIntelligenceRightID.CREATEDOCUMENTS, iWebiAppObject, "CREATE_DOCUMENT", userRights);
checkApplicationObjectRight(CeWebIntelligenceRightID.DRILLMODE, iWebiAppObject, "DRILL_MODE", userRights);
checkApplicationObjectRight(CeWebIntelligenceRightID.EXTENDSCOPE, iWebiAppObject, "EXTEND_SCOPE", userRights);
}

session.setAttribute("userRights", userRights);


%><jsp:forward page="data-getter2.jsp" /><%
} // else of if (userInfo.getPasswordExpiry() == 0)
%>

data-getter.jsp





<!--
********************************************************************************

Adapted from WebIntelligence RE SDK JSP Tutorials 115.000.00000

Tutorials are Copyright (c) 2002-2005 Business Objects SA

********************************************************************************
-->


<%@ page language="java" errorPage="../err_page.jsp"%>
<%@ page import="com.businessobjects.rebean.wi.*,java.io.*" %>
<%@ page import="java.util.BitSet, java.util.Enumeration, java.util.StringTokenizer, java.util.Date" %><%@ page import="java.text.ParseException, java.text.SimpleDateFormat, java.io.IOException" %><%!
// =============================================================================

// The separator between the different selected values of a list
static final String C_STR_SEPARATOR = ";";

// =============================================================================

static final int iCaseDiff = ('a' - 'A');

// =============================================================================

// The list of characters that are not encoded have been determined
// by referencing O'Reilly's "HTML: The Definitive Guide" (page 164).
static BitSet objBitSetCharactersNotToEncode;

static
{
int iCharIndex;

objBitSetCharactersNotToEncode = new BitSet(256);

for (iCharIndex = 'a'; iCharIndex <= 'z'; iCharIndex++)
objBitSetCharactersNotToEncode.set(iCharIndex);

for (iCharIndex = 'A'; iCharIndex <= 'Z'; iCharIndex++)
objBitSetCharactersNotToEncode.set(iCharIndex);

for (iCharIndex = '0'; iCharIndex <= '9'; iCharIndex++)
objBitSetCharactersNotToEncode.set(iCharIndex);

// A space needs a special encoding: it should be transformed into a '+'
// this is done in the method URLEncodeUTF8 below
objBitSetCharactersNotToEncode.set(' ');
objBitSetCharactersNotToEncode.set('-');
objBitSetCharactersNotToEncode.set('_');
objBitSetCharactersNotToEncode.set('.');
objBitSetCharactersNotToEncode.set('*');
} // static code

// =============================================================================

// Tell if the given value is an item of the array of the selected values
public String isValuePartOfTheSelection(String strValue, String[] astrSelectedValues)
{
if (astrSelectedValues == null)
return "";

for (int iSelectedIndex = 0; iSelectedIndex < astrSelectedValues.length; iSelectedIndex++)
if (strValue.equals(astrSelectedValues[iSelectedIndex]))
return " selected";

return "";
} // method isValuePartOfTheSelection

// =============================================================================

// Concatenate the given value to the list of the selected values
public void addToList(String strItem, StringBuffer objStringBufferItemList)
{
if (objStringBufferItemList.length() != 0)
objStringBufferItemList.append(C_STR_SEPARATOR);

objStringBufferItemList.append(strItem);
} // method addToList

// =============================================================================

// Return a string listing the different values of the given array
// Known limitation: value should not include C_STR_SEPARATOR
public String convertArrayToString(String[] astr)
{
if ((astr == null) || (astr.length == 0))
return "";

StringBuffer objStringBuffer = new StringBuffer("");

for (int iIndex = 0; iIndex < astr.length; iIndex++)
{
if (iIndex != 0)
objStringBuffer.append(C_STR_SEPARATOR);

objStringBuffer.append(astr[iIndex]);
} // for (iIndex)

return objStringBuffer.toString();
} // method convertArrayToString

// =============================================================================

// Split delimited string of values into an array
public String[] splitValues(String strValueList)
{
if (strValueList == null)
return null;

StringTokenizer strTokenizer = new StringTokenizer(strValueList, C_STR_SEPARATOR);
int iValueCount = strTokenizer.countTokens();
String[] astrValues = new String[iValueCount];

for (int iValueIndex = 0; iValueIndex < iValueCount; iValueIndex++)
astrValues[iValueIndex] = strTokenizer.nextToken();

return astrValues;
} // method splitValues

// =============================================================================

// Return a non null value for the given string
public String getNonNullValue(String strParameterValue, String strDefaultValue)
{
if (strParameterValue == null)
strParameterValue = strDefaultValue;
else if (strParameterValue.equals("null"))
strParameterValue = strDefaultValue;

return strParameterValue;
} // method getNonNullValue

// =============================================================================

// Return a non null value for the given string
// (considering that default value is an empty string)
public String getNonNullValue(String strParameterValue)
{
return getNonNullValue(strParameterValue, "");
} // method getNonNullValue

// =============================================================================

// Return an array of non null values for the given string array
public String[] getNonNullValues(String[] astrParameterValues)
{
if (astrParameterValues == null)
astrParameterValues = new String[0];

return astrParameterValues;
} // method getNonNullValues

String URLEncodeUTF8(String strToEncode)
{
try
{
byte[] abyUTF8 = strToEncode.getBytes("UTF-8");
// The maximal size should be string length * 3 (%XX instead of a single char)
StringBuffer objStringBuffer = new StringBuffer(abyUTF8.length * 3);

for (int iByteIndex = 0; iByteIndex < abyUTF8.length; iByteIndex++)
{
int iChar = (int) abyUTF8[iByteIndex];

if (iChar < 0)
iChar += 256; // get an unsigned byte value in [0,256[

// If the character doesn't need encoding,
if (objBitSetCharactersNotToEncode.get(iChar))
{
if (iChar == 0x20)
// ' ' replaced by '+'
iChar = 0x2B;

objStringBuffer.append((char) iChar);
}
// Else, the character needs encoding,
else
{
// It should be escaped by %XX (XX is the hex value of the byte)
objStringBuffer.append('%');

char cChar = Character.forDigit((abyUTF8[iByteIndex] >> 4) & 0xF, 16);

if (Character.isLetter(cChar))
// convert the character to upper case (ex: 'a' -> 'A') as part of the hex value
cChar -= iCaseDiff;

objStringBuffer.append(cChar);

cChar = Character.forDigit(abyUTF8[iByteIndex] & 0xF, 16);

if (Character.isLetter(cChar))
// convert the character to upper case (ex: 'a' -> 'A') as part of the hex value
cChar -= iCaseDiff;

objStringBuffer.append(cChar);
} // else of if (objBitSetCharactersNotToEncode.get(iChar))
} // for (iByteIndex)

return objStringBuffer.toString();
}
catch (java.io.UnsupportedEncodingException objUnsupportedEncodingException)
{
System.out.println("UnsupportedEncodingException on " + strToEncode);
return (java.net.URLEncoder.encode(strToEncode));
} // catch (java.io.UnsupportedEncodingException)
} // method URLEncodeUTF8

// ============================================================================= end useful methods
%>


<%@ page import="com.crystaldecisions.sdk.framework.IEnterpriseSession" %>
<%

// The session attribute, used for displaying user messages
final String C_STR_INFORMATION_SESSION_ATTRIBUTE = "informationMessage";

// The different values of the page parameter, used for navigating into documents
final String C_STR_PAGE_FIRST = "first";
final String C_STR_PAGE_PREVIOUS = "prev";
final String C_STR_PAGE_NEXT = "next";
final String C_STR_PAGE_LAST = "last";

// The display of the particular values of a list
final String C_STR_ALL = "*";
final String C_STR_NOTHING = "Nothing";

//Retrieve the Object Session
IEnterpriseSession enterpriseSession = (IEnterpriseSession)request.getAttribute("EnterpriseSession");

// Get the locale of the server
String strLocale = request.getLocale().getLanguage();


%>


<%@ page import="com.crystaldecisions.sdk.occa.infostore.IInfoStore" %>
<%@ page import="com.crystaldecisions.sdk.occa.security.IUserInfo" %>
<%@ page import="com.crystaldecisions.sdk.occa.infostore.IInfoObjects" %>
<%@ page import="com.crystaldecisions.sdk.occa.infostore.IInfoObject" %>
<%@ page import="com.crystaldecisions.sdk.exception.SDKException" %>
<%@ page import="com.crystaldecisions.sdk.occa.infostore.ISecurityInfo" %>
<%@ page import="java.util.Locale" %>
<%@ page import="java.io.IOException" %>

<%

ReportEngines reportEngines = (ReportEngines) request.getAttribute("ReportEngines");

IInfoStore iStore = (IInfoStore) request.getAttribute("InfoStore");

String strDocUID = (String) request.getAttribute("docIdentifier");


String strDocUIDType = "id";
String strEntry = getNonNullValue(request.getParameter("entry"));
String strDocId = null;

if (strDocUID.length() != 0)
if (strDocUIDType.equals("id"))
strDocId = strDocUID;
else
strEntry = strDocUID;


DocumentInstance document = null;

// If a storage token has been given
if (! strEntry.equals(""))
{
try{
// Retrieve the correct ReportEngine from the storage token
ReportEngine reportEngine = reportEngines.getServiceFromStorageToken(strEntry);

// Retrieve the document using its storage token
document = reportEngine.getDocumentFromStorageToken(strEntry);
}catch(Exception ex){
response.sendRedirect("../error_token.html");
}

}
// Else if a document id or a document name has been given
else if (! strDocId.equals(""))
{
//Check the SI_KIND of the Document to instanciate the correct reportEngine
String strQuery = "Select SI_KIND from CI_INFOOBJECTS where SI_ID=" + strDocId;
IInfoObjects iDocObjects = iStore.query(strQuery);
IInfoObject iDocObject = null;

String strQuery2 = "Select * from CI_INFOOBJECTS where SI_ID=" + strDocId;
IInfoObjects iDocObjects2 = iStore.query(strQuery2);


IInfoObject iDocObject2 = null;

try{

iDocObject = (IInfoObject) iDocObjects.get(0);

iDocObject2 = (IInfoObject) iDocObjects2.get(0);
}
catch(Exception ex)
{
response.sendRedirect("../error_documentNotFound.html");
}

String strKind = iDocObject.getKind();
com.crystaldecisions.sdk.occa.infostore.ISchedulable iDocObject3 = (com.crystaldecisions.sdk.occa.infostore.ISchedulable) iDocObject2;

IInfoObject iDocObject4 = iDocObject3.getLatestInstance();

int latestInstanceID = iDocObject4.getID();


ReportEngine reportEngine = null;


if(strKind.equalsIgnoreCase("Webi"))
{
reportEngine = reportEngines.getService(ReportEngines.ReportEngineType.WI_REPORT_ENGINE);
reportEngine.setLocale(strLocale);
}
else
{
reportEngine = reportEngines.getService(ReportEngines.ReportEngineType.FC_REPORT_ENGINE);
reportEngine.setLocale(strLocale);
}


// Open the document from its identifiers
// document = reportEngine.openDocument(Integer.parseInt(strDocId));
try{
document = reportEngine.openDocument( latestInstanceID );
}catch(Exception e9){
e9.printStackTrace();
}


} // if (! strEntry.equals(""))

// *****************************************************************************
%>


<%

// Retrieve parameters
String strDataProviderIndex = getNonNullValue(request.getParameter("dataprovider"), "0");
int iDataProvider = Integer.parseInt(strDataProviderIndex);

DataProviders dataProviders = document.getDataProviders();
int iDataProviderCount = dataProviders.getCount();


// If document is empty
if (iDataProviderCount <= 0)
{
%><%@ include file="../error_noDataProvider.html" %><%

return;
} // if (iDataProvider <= 0)

// Set dataprovider
DataProvider dataProvider = dataProviders.getItem(iDataProvider);

// *****************************************************************************
%>

<%
response.setDateHeader("expires", 0);

%>

<%


if (strEntry.equals(""))
// Get storage token
strEntry = document.getStorageToken();

out.clearBuffer();
CharacterView cvOutput;
InputStream isXML;
int available;
byte[] data;
int nbBytes;
StringBuffer sbResult = new StringBuffer();

cvOutput = dataProvider.getResultAsCSV(-1); //cih
out.print(cvOutput.getContent()); //cih

%>



<%
if (enterpriseSession != null){
enterpriseSession.logoff();
}
// *****************************************************************************
%>

Spread the word

del.icio.us Digg Furl Reddit

Permalink • Print • Comment

Trackback uri

http://www.boguru.com/business-objects-xi-sdk-example-1-part-3/trackback/

WordPress database error: [Table './boguru/wp_comments' is marked as crashed and last (automatic?) repair failed]
SELECT * FROM wp_comments WHERE comment_post_ID = '19' AND comment_approved = '1' ORDER BY comment_date

Leave a Comment




WordPress database error: [Table './boguru/wp_ras_image' is marked as crashed and last (automatic?) repair failed]
INSERT INTO wp_ras_image (id, createtime, word) VALUES (697197, 1711640630, 'f6bpsyy')

*
To prove you're a person (not a spam script), type the security text shown in the picture. Click here to regenerate some new text.
Click to hear an audio file of the anti-spam word