<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %><% /* * ==================================================================== * Project: opencrx, http://www.opencrx.org/ * Name: $Id: Sample-RTFdocument.jsp,v 1.1 2007/02/28 08:53:19 cmu Exp $ * Description: sample wizard: create RTF document * Revision: $Revision: 1.1 $ * Owner: CRIXP Corp., Switzerland, http://www.crixp.com * Date: $Date: 2007/02/28 08:53:19 $ * ==================================================================== * * This software is published under the BSD license * as listed below. * * Copyright (c) 2004, CRIXP Corp., Switzerland * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of CRIXP Corp. nor the names of the contributors * to openCRX may be used to endorse or promote products derived * from this software without specific prior written permission * * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * ------------------ * * This product includes software developed by the Apache Software * Foundation (http://www.apache.org/). * * This product includes software developed by contributors to * openMDX (http://www.openmdx.org/) */ %><%@ page session="true" import=" com.itseasy.rtf.*, com.itseasy.rtf.text.*, java.util.*, java.io.*, java.text.*, java.math.*, java.net.*, java.sql.*, javax.naming.Context, javax.naming.InitialContext, org.openmdx.base.accessor.generic.cci.Object_1_0, org.openmdx.base.accessor.jmi.cci.*, org.openmdx.base.exception.*, org.openmdx.kernel.id.*, org.openmdx.portal.servlet.*, org.openmdx.portal.servlet.attribute.*, org.openmdx.portal.servlet.view.*, org.openmdx.portal.servlet.texts.*, org.openmdx.portal.servlet.control.*, org.openmdx.portal.servlet.reports.*, org.openmdx.portal.servlet.wizards.*, org.openmdx.compatibility.base.naming.*, org.openmdx.compatibility.base.dataprovider.cci.*, org.openmdx.compatibility.base.query.*, org.openmdx.application.log.* " %><% request.setCharacterEncoding("UTF-8"); ApplicationContext app = (ApplicationContext)session.getValue("ObjectInspectorServlet.ApplicationContext"); //System.out.println("original URL = " + request.getRequestURL().toString()); if (app == null) { response.sendRedirect( request.getContextPath() + "/ObjectInspectorServlet" ); return; } ShowObjectView view = (ShowObjectView)session.getValue("ObjectInspectorServlet.View"); Texts_1_0 texts = app.getTexts(); Context initialContext = new InitialContext(); %> openCRX Sample Wizard - RTF Document <% String documentName = "sample-letter.rtf"; try { Codes codes = app.getCodes(); RefPackage_1_0 dataPkg = app.getDataPackage(); // Get account1 package org.opencrx.kernel.account1.cci.account1Package accountPkg = (org.opencrx.kernel.account1.cci.account1Package)dataPkg.refPackage( org.opencrx.kernel.account1.cci.account1Package.class.getName() ); org.opencrx.kernel.account1.cci.Contact contact = (org.opencrx.kernel.account1.cci.Contact)dataPkg.refObject(view.getObjectReference().refMofId()); // Generate document RTFTemplate document = new RTFTemplate(new File(getServletContext().getRealPath("/documents/" + documentName))); MultiTextParts mtpWarning = new MultiTextParts(); mtpWarning.addText(TextPart.NEWLINE); // replace template bookmarks with actual values // ----- contact if (contact != null) { try { document.setBookmarkContent("firstName", contact.getFirstName() == null ? "" : contact.getFirstName()); } catch (Exception e) {}; try { document.setBookmarkContent("middleName", contact.getMiddleName() == null ? "" : contact.getMiddleName()); } catch (Exception e) {}; try { document.setBookmarkContent("lastName", contact.getLastName() == null ? "" : contact.getLastName()); } catch (Exception e) {}; try { document.setBookmarkContent("nickName", contact.getNickName() == null ? "" : contact.getNickName()); } catch (Exception e) {}; try { document.setBookmarkContent("aliasName", contact.getAliasName() == null ? "" : contact.getAliasName()); } catch (Exception e) {}; try { document.setBookmarkContent("jobTitle", contact.getJobTitle() == null ? "" : contact.getJobTitle()); } catch (Exception e) {}; try { document.setBookmarkContent("jobRole", contact.getJobRole() == null ? "" : contact.getJobRole()); } catch (Exception e) {}; try { document.setBookmarkContent("organization", contact.getOrganization() == null ? "" : contact.getOrganization()); } catch (Exception e) {}; try { document.setBookmarkContent("department", contact.getDepartment() == null ? "" : contact.getDepartment()); } catch (Exception e) {}; } else { mtpWarning.addText(new TextPart("WARNING: Contact == null")); mtpWarning.addText(TextPart.NEWLINE); } try {document.setBookmarkContent("WARNING", mtpWarning);} catch (Exception e) {}; // send document to browser String location = UUIDs.getGenerator().next().toString(); File f = new File( app.getTempFileName(location, "") ); FileOutputStream os = new FileOutputStream(f); os.write(document.getDocument()); os.flush(); os.close(); Action downloadAction = new Action( Action.EVENT_DOWNLOAD_FROM_LOCATION, new Action.Parameter[]{ new Action.Parameter(Action.PARAMETER_LOCATION, location), new Action.Parameter(Action.PARAMETER_NAME, documentName), new Action.Parameter(Action.PARAMETER_MIME_TYPE, "text/rtf") }, app.getTexts().getClickToDownloadText() + " " + documentName, true ); response.sendRedirect( request.getContextPath() + "/" + view.getEncodedHRef(downloadAction) ); %> Download report from here <% } catch(Exception e) { AppLog.warning("Error creating rtf document", documentName); AppLog.warning(e.getMessage(), e.getCause(), 1); // Go back to previous view Action nextAction = new Action( Action.EVENT_SELECT_OBJECT, new Action.Parameter[]{ new Action.Parameter(Action.PARAMETER_OBJECTXRI, view.getObjectReference().refMofId()) }, "", true ); response.sendRedirect( request.getContextPath() + "/" + view.getEncodedHRef(nextAction) ); } %>