<%@ page import="com.crystaldecisions.sdk.framework.*" %> <%@ page import="com.crystaldecisions.sdk.plugin.*" %> <%@ page import="com.businessobjects.foundation.exception.*" %> <%@ page import="com.crystaldecisions.sdk.exception.*" %> <%@ page import="com.crystaldecisions.sdk.occa.infostore.*" %> <%@ page import="com.crystaldecisions.sdk.occa.infostore.IInfoStore" %> <%@ page import="com.crystaldecisions.sdk.occa.infostore.IInfoObject" %> <%@ page import="java.io.OutputStream" %> <%@ page import="java.io.ByteArrayOutputStream" %> <%@ page import="java.io.*" %> <% //< page contentType="text/xml" > -- seems to cause problems with Xcelsius String sPrefix = request.getParameter("prefix").toUpperCase(); String sResultnametag = request.getParameter("resultnametag"); if (sResultnametag == null) { sResultnametag = "Response"; } String sShortFilename = request.getParameter("filename").toUpperCase(); String sOverride = request.getParameter("override").substring(0,1).toUpperCase(); String sServer=null; String sUsername = null; String sPassword = null; String sSuccessFailMsg="{empty}"; String sCont=""; String sErr=""; // login IEnterpriseSession eSession = null; try { final ISessionMgr sessionMgr=CrystalEnterprise.getSessionMgr(); /* eSession = ActionHelper.getEnterpriseSession(request); */ String sToken = request.getParameter("CELogonToken"); sErr="0"; if (sToken == null || sToken.equals("")) { sErr="1"; sServer=request.getParameter("CMS"); sUsername = request.getParameter("userid"); sPassword = request.getParameter("password"); sErr="2"; eSession = sessionMgr.logon(sUsername, sPassword, sServer, "secEnterprise"); } else { sErr="3"; eSession = sessionMgr.logonWithToken(sToken); } sUsername=eSession.getUserInfo().getUserName().toString(); } catch (Exception ex) { //logon problems sSuccessFailMsg="Logon error: "+ex.getMessage(); sCont = ""+sSuccessFailMsg+". Step "+sErr+""; } if (sCont.equals("")) { try { // search Infostore for user's 'Favorites' folder String query = "select * from ci_infoobjects where si_kind=\'FavoritesFolder\' and si_name=\'"+sUsername+"\'"; IInfoObjects infoobjects = null; IInfoStore myInfoStore = (IInfoStore) eSession.getService("InfoStore"); infoobjects = (IInfoObjects) myInfoStore.query(query); IInfoObject obj=(IInfoObject) infoobjects .get(0); int iFolderid = obj.getID(); String sFolderid = String.valueOf(iFolderid); // search for the file with the given name in user's "Favorites" folder String sFilename=sPrefix+"_"+sShortFilename; query = "select * from ci_infoobjects where si_kind=\'TXT\' and si_parent_folder="+sFolderid+" and si_name=\'"+sFilename+"\'"; infoobjects = (IInfoObjects) myInfoStore.query(query); int i_num_of_files = infoobjects.size(); byte[] bOut = null; String sInput = request.getParameter("filecont"); if (sInput == null) { // when calling from Xcelsius this filecont parameter will be null. It is only used for testing // Build a string from the input (this is actually the information passed to this jsp to be saved) InputStream in = request.getInputStream(); BufferedReader r = new BufferedReader(new InputStreamReader(in)); StringBuffer buf = new StringBuffer(); String line; while ((line=r.readLine()) != null) { buf.append(line+"\r\n"); } String xmlString=buf.toString(); // xmlString now contains the text to be written into an xml file (though, the extension is txt) // convert it into a byte array bOut = xmlString.getBytes(); } else { bOut = sInput.getBytes(); } if (i_num_of_files == 0) { // file with this name doesn't exist. Add the new file to the "Favorite"'s directory infoobjects=myInfoStore.newInfoObjectCollection(); obj = infoobjects.add(CeKind.TEXT); obj.setTitle(sFilename); obj.getFiles().addFile(bOut,null,"txt",sFilename,null); obj.setParentID(iFolderid); myInfoStore.commit(infoobjects); sSuccessFailMsg = "Created file "+sFilename +" in your Favorites"; } else { // file with this name already exists if (sOverride.equals("Y")) { // user asked for the file to be updated anyway sSuccessFailMsg = "There was already a file with name "+sFilename +" in your Favorites" ; obj = (IInfoObject)infoobjects.get(0); obj.setTitle(sFilename); obj.getFiles().replace(0,bOut,null,"txt",sFilename,null); obj.setParentID(iFolderid); myInfoStore.commit(infoobjects); sSuccessFailMsg = "Updated file "+sFilename +" in your Favorites"; } else { // user didn't ask for the file to be updated sSuccessFailMsg = "There was already a file with name "+sFilename +" in your Favorites"; } } } catch (Exception ex) { // some kind of an error. instead of content return the error message sSuccessFailMsg="Error: "+ex.getMessage(); } finally { //logoff if (eSession != null) { eSession.logoff(); eSession = null; session.invalidate(); } } //create a response content sCont = ""+sSuccessFailMsg+""; } response.setHeader("Cache-Control","no-cache"); response.setHeader("Pragma","no-cache"); response.setDateHeader("Expires",-1); %> <%= sCont %>