/**
   * method to stream the byte array to response object
   *
   * @param fileContents
   * @param fileName
   * @param fileContentType
   * @param response
   * @throws Exception
   */
  protected void streamToResponse(
      org.kuali.kra.proposaldevelopment.bo.AttachmentDataSource attachmentDataSource,
      HttpServletResponse response)
      throws Exception {
    byte[] xbts = attachmentDataSource.getContent();
    ByteArrayOutputStream baos = null;
    try {
      baos = new ByteArrayOutputStream(xbts.length);
      baos.write(xbts);

      WebUtils.saveMimeOutputStreamAsFile(
          response,
          attachmentDataSource.getContentType(),
          baos,
          attachmentDataSource.getFileName());

    } finally {
      try {
        if (baos != null) {
          baos.close();
          baos = null;
        }
      } catch (IOException ioEx) {
        LOG.error("Error while downloading attachment");
        throw new RuntimeException("IOException occurred while downloading attachment", ioEx);
      }
    }
  }
Beispiel #2
0
  /**
   * Handy method to stream the byte array to response object
   *
   * @param attachmentDataSource
   * @param response
   * @throws Exception
   */
  public void streamToResponse(
      AttachmentDataSource attachmentDataSource, HttpServletResponse response) throws Exception {
    byte[] xbts = attachmentDataSource.getContent();

    ByteArrayOutputStream baos = null;
    if (xbts != null)
      try {
        baos = new ByteArrayOutputStream(xbts.length);
        baos.write(xbts);

        WebUtils.saveMimeOutputStreamAsFile(
            response,
            attachmentDataSource.getContentType(),
            baos,
            attachmentDataSource.getFileName());
      } finally {
        try {
          if (baos != null) {
            baos.close();
            baos = null;
          }
        } catch (IOException ioEx) {
          LOG.warn(ioEx.getMessage(), ioEx);
        }
      }
  }
Beispiel #3
0
 protected void saveGrantsGovXml(
     ProposalDevelopmentDocument pdDoc,
     boolean formEntryFlag,
     XmlObject formObject,
     List<AttachmentData> attachmentList,
     List<S2sAppAttachments> attachmentLists)
     throws Exception {
   String loggingDirectory =
       KraServiceLocator.getService(ConfigurationService.class)
           .getPropertyValueAsString(Constants.PRINT_XML_DIRECTORY);
   String opportunityId = pdDoc.getDevelopmentProposal().getS2sOpportunity().getOpportunityId();
   String proposalnumber = pdDoc.getDevelopmentProposal().getProposalNumber();
   String exportDate =
       StringUtils.replaceChars(
           (pdDoc.getDevelopmentProposal().getUpdateTimestamp().toString()), ":", "_");
   exportDate = StringUtils.replaceChars(exportDate, " ", ".");
   if (grantsGovXmlDirectoryFile == null) {
     grantsGovXmlDirectoryFile = new File(loggingDirectory + proposalnumber);
   }
   File newgrantsGovXmlDirectoryFile = null;
   int suffix = 1;
   while (grantsGovXmlDirectoryFile.exists() && formEntryFlag) {
     grantsGovXmlDirectoryFile = new File(loggingDirectory + proposalnumber);
     String filename = String.valueOf(suffix);
     newgrantsGovXmlDirectoryFile = new File(loggingDirectory + proposalnumber + "-" + filename);
     if (!newgrantsGovXmlDirectoryFile.exists()) {
       grantsGovXmlDirectoryFile = newgrantsGovXmlDirectoryFile;
       break;
     }
     suffix++;
   }
   if (formEntryFlag) {
     grantsGovXmlDirectoryFile.mkdir();
   }
   pdDoc.setSaveXmlFolderName(grantsGovXmlDirectoryFile.getName());
   for (AttachmentData attachmentData : attachmentList) {
     File attachmentFile = new File(grantsGovXmlDirectoryFile, "Attachments");
     attachmentFile.mkdir();
     File attachedFile = new File(attachmentFile, attachmentData.getFileName());
     FileOutputStream output = new FileOutputStream(attachedFile);
     output.write(attachmentData.getContent());
     output.close();
   }
   for (S2sAppAttachments attAppAttachments : attachmentLists) {
     File attachmentFile = new File(grantsGovXmlDirectoryFile, "Attachments");
     attachmentFile.mkdir();
     AttachmentDataSource ads = getAttributeContent(pdDoc, attAppAttachments.getContentId());
     File attachedFile = new File(attachmentFile, ads.getFileName());
     FileOutputStream output = new FileOutputStream(attachedFile);
     output.write(getAttContent(pdDoc, attAppAttachments.getContentId()));
     output.close();
   }
   File xmlFile =
       new File(
           grantsGovXmlDirectoryFile,
           opportunityId + "." + proposalnumber + "." + exportDate + ".xml");
   BufferedWriter out = new BufferedWriter(new FileWriter(xmlFile));
   out.write(formObject.xmlText());
   out.close();
   ZipOutputStream zipOutputStream = null;
   FileOutputStream fileOutputStream = new FileOutputStream(grantsGovXmlDirectoryFile + ".zip");
   zipOutputStream = new ZipOutputStream(fileOutputStream);
   addFolderToZip("", grantsGovXmlDirectoryFile.getPath(), zipOutputStream);
   zipOutputStream.flush();
   zipOutputStream.close();
 }