Example usage for java.io StringBufferInputStream StringBufferInputStream

List of usage examples for java.io StringBufferInputStream StringBufferInputStream

Introduction

In this page you can find the example usage for java.io StringBufferInputStream StringBufferInputStream.

Prototype

public StringBufferInputStream(String s) 

Source Link

Document

Creates a string input stream to read data from the specified string.

Usage

From source file:org.kuali.kfs.module.purap.document.web.struts.ElectronicInvoiceTestAction.java

/**
 * Generates Electronic Invoice xml file from a Purchase Order, for testing purpose only.     
 *//* ww  w . ja  v a  2 s .c o m*/
public ActionForward generate(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    checkAuthorization(form, "");

    ElectronicInvoiceTestForm testForm = (ElectronicInvoiceTestForm) form;
    String poDocNumber = testForm.getPoDocNumber();
    LOG.info("Generating Electronic Invoice XML file for Purchase Order Document " + poDocNumber);
    PurchaseOrderService poService = SpringContext.getBean(PurchaseOrderService.class);
    PurchaseOrderDocument po = null;

    if (StringUtils.isBlank(poDocNumber)) {
        GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PURCHASE_ORDER_DOCUMENT_NUMBER,
                PurapKeyConstants.ERROR_ELECTRONIC_INVOICE_GENERATION_PURCHASE_ORDER_NUMBER_EMPTY,
                new String[] { poDocNumber });
        return mapping.findForward(RiceConstants.MAPPING_BASIC);
    }
    if (!getDocumentService().documentExists(poDocNumber)) {
        GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PURCHASE_ORDER_DOCUMENT_NUMBER,
                PurapKeyConstants.ERROR_ELECTRONIC_INVOICE_GENERATION_PURCHASE_ORDER_DOES_NOT_EXIST,
                poDocNumber);
        return mapping.findForward(RiceConstants.MAPPING_BASIC);
    }

    try {
        po = poService.getPurchaseOrderByDocumentNumber(poDocNumber);
    } catch (Exception e) {
        throw e;
    }

    response.setHeader("Cache-Control", "max-age=30");
    response.setContentType("application/xml");
    StringBuffer sbContentDispValue = new StringBuffer();
    String useJavascript = request.getParameter("useJavascript");
    if (useJavascript == null || useJavascript.equalsIgnoreCase("false")) {
        sbContentDispValue.append("attachment");
    } else {
        sbContentDispValue.append("inline");
    }
    StringBuffer sbFilename = new StringBuffer();
    sbFilename.append("PO_");
    sbFilename.append(poDocNumber);
    sbFilename.append(".xml");
    sbContentDispValue.append("; filename=");
    sbContentDispValue.append(sbFilename);
    response.setHeader("Content-disposition", sbContentDispValue.toString());

    // lookup the PO and fill in the XML with valid data
    if (po != null) {
        String duns = "";
        if (po.getVendorDetail() != null) {
            duns = StringUtils.defaultString(po.getVendorDetail().getVendorDunsNumber());
        }

        DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class);
        String currDate = ElectronicInvoiceUtils.getDateDisplayText(dateTimeService.getCurrentDate()); // getting date in kfs format
        String vendorNumber = po.getVendorDetail().getVendorNumber();

        String eInvoiceFile = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                + "\n<!-- ******Testing tool generated XML****** Version 1.2." + "\n\n  Generated On "
                + currDate + " for PO " + po.getPurapDocumentIdentifier() + " (Doc# " + poDocNumber
                + ") -->\n\n" + "<!-- All the cXML attributes are junk values -->\n"
                + "<cXML payloadID=\"200807260401062080.964@eai002\"\n"
                + "    timestamp=\"2008-07-26T04:01:06-08:00\"\n" + "    version=\"1.2.014\" xml:lang=\"en\" \n"
                + "    xmlns=\"http://www.kuali.org/kfs/purap/electronicInvoice\" \n"
                + "    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" + "  <Header>\n"
                + "      <From>\n" + "          <Credential domain=\"DUNS\">\n" + "              <Identity>"
                + duns + "</Identity> <!-- DUNS number from PO Vendor " + vendorNumber + "-->\n"
                + "          </Credential>\n" + "      </From>\n" + "      <To>\n"
                + "          <Credential domain=\"NetworkId\">\n" + "              <Identity>" + "IU"
                + "</Identity> <!-- Hardcoded --> \n" + "          </Credential>\n" + "      </To>\n"
                + "      <Sender>\n" + "          <Credential domain=\"DUNS\">\n" + "              <Identity>"
                + duns + "</Identity> <!-- DUNS number from PO Vendor " + vendorNumber + "-->\n"
                + "          </Credential>\n" + "          <UserAgent/>\n" + "      </Sender>\n"
                + "  </Header>\n" + "  <Request deploymentMode=\"production\">\n"
                + "      <InvoiceDetailRequest>\n" + "          <InvoiceDetailRequestHeader\n"
                + "              invoiceDate=\"" + currDate + "\" invoiceID=\"" + RandomUtils.nextInt()
                + "\" operation=\"new\" purpose=\"standard\"> <!-- invoiceID=Random unique Id, invoiceDate=Curr date -->\n"
                + "              <InvoiceDetailHeaderIndicator/>\n"
                + "              <InvoiceDetailLineIndicator/>\n" + "              <InvoicePartner>\n"
                + getContactXMLChunk("billTo", po) + "              </InvoicePartner>\n"
                + "              <InvoicePartner>\n" + "                  <Contact addressID=\""
                + RandomUtils.nextInt() + "\" role=\"remitTo\"> <!-- Vendor address -->\n"
                + "                      <Name xml:lang=\"en\">\n" + "                          "
                + po.getVendorName() + "\n" + "                      </Name>\n"
                + "                      <PostalAddress>\n" + "                          <Street>"
                + StringUtils.defaultString(po.getVendorLine1Address()) + "</Street>\n"
                + "                          <Street>" + StringUtils.defaultString(po.getVendorLine2Address())
                + "</Street>\n" + "                          <City>"
                + StringUtils.defaultString(po.getVendorCityName()) + "</City>\n"
                + "                          <State>" + StringUtils.defaultString(po.getVendorStateCode())
                + "</State>\n" + "                          <PostalCode>"
                + StringUtils.defaultString(po.getVendorPostalCode()) + "</PostalCode>\n"
                + "                          <Country isoCountryCode=\""
                + StringUtils.defaultString(po.getVendorCountryCode()) + "\">\n"
                + "                              " + StringUtils.defaultString(po.getVendorCountry().getName())
                + "\n" + "                          </Country>\n" + "                      </PostalAddress>\n"
                + "                  </Contact>\n" + "              </InvoicePartner>\n"
                + getDeliveryAddressXMLChunk("shipTo", po) + getPaymentTermXML(po)
                + "          </InvoiceDetailRequestHeader>\n" + "          <InvoiceDetailOrder>\n"
                + "              <InvoiceDetailOrderInfo>\n" + "                  <OrderReference\n"
                + "                      orderDate=\""
                + ElectronicInvoiceUtils.getDateDisplayText(dateTimeService.getCurrentDate()) + "\" orderID=\""
                + po.getPurapDocumentIdentifier() + "\"> <!--orderDate=Curr date,orderID=PO#-->\n"
                + "                      <DocumentReference payloadID=\"NA\" /> <!--HardCoded-->\n"
                + "                  </OrderReference>\n" + "              </InvoiceDetailOrderInfo>\n"
                + "              <!-- No junk values in Items-->\n";

        for (int i = 0; i < po.getItems().size(); i++) {
            List items = po.getItems();
            PurchaseOrderItem item = (PurchaseOrderItem) items.get(i);
            if (!item.getItemType().isAdditionalChargeIndicator()) {
                eInvoiceFile = eInvoiceFile + getPOItemXMLChunk(item);
            }
        }

        KualiDecimal totalDollarAmt = po.getTotalDollarAmount() == null ? KualiDecimal.ZERO
                : po.getTotalDollarAmount();
        eInvoiceFile = eInvoiceFile +

                "          </InvoiceDetailOrder>\n" + "          <InvoiceDetailSummary>\n"
                + "              <SubtotalAmount>\n" + "                  <Money currency=\"USD\">"
                + po.getTotalPreTaxDollarAmount() + "</Money>\n" + "              </SubtotalAmount>\n"
                + "              <Tax>\n" + "                  <Money currency=\"USD\">"
                + po.getTotalTaxAmount() + "</Money>\n"
                + "                  <Description xml:lang=\"en\">Total Tax</Description>\n"
                + "              </Tax>\n" + "              <SpecialHandlingAmount>\n"
                + "                  <Money currency=\"USD\">0.00</Money>\n"
                + "              </SpecialHandlingAmount>\n" + "              <ShippingAmount>\n"
                + "                  <Money currency=\"USD\">0.00</Money>\n"
                + "              </ShippingAmount>\n" + "              <GrossAmount>\n"
                + "                  <Money currency=\"USD\">" + totalDollarAmt + "</Money>\n"
                + "              </GrossAmount>\n" + "              <InvoiceDetailDiscount>\n"
                + "                  <Money currency=\"USD\">0.00</Money>\n"
                + "                  </InvoiceDetailDiscount>\n" + "              <NetAmount>\n"
                + "                  <Money currency=\"USD\">" + totalDollarAmt + "</Money>\n"
                + "              </NetAmount>\n" + "              <DepositAmount>\n"
                + "                  <Money currency=\"USD\">0.00</Money>\n"
                + "              </DepositAmount>\n" + "              <DueAmount>\n"
                + "                  <Money currency=\"USD\">" + totalDollarAmt + "</Money>\n"
                + "              </DueAmount>\n" + "          </InvoiceDetailSummary>\n"
                + "      </InvoiceDetailRequest>\n" + "  </Request>\n" + "</cXML>";

        ServletOutputStream sos;
        sos = response.getOutputStream();
        ByteArrayOutputStream baOutStream = new ByteArrayOutputStream();
        StringBufferInputStream inStream = new StringBufferInputStream(eInvoiceFile);
        convert(baOutStream, inStream);
        response.setContentLength(baOutStream.size());
        baOutStream.writeTo(sos);
        sos.flush();
    }

    return mapping.findForward(KFSConstants.MAPPING_BASIC);
}

From source file:org.kuali.ole.module.purap.document.web.struts.ElectronicInvoiceTestAction.java

/**
 * Generates Electronic Invoice xml file from a Purchase Order, for testing purpose only.
 *//*from www.j  av  a2  s .c  o m*/
public ActionForward generate(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    checkAuthorization(form, "");

    ElectronicInvoiceTestForm testForm = (ElectronicInvoiceTestForm) form;
    String poDocNumber = testForm.getPoDocNumber();
    LOG.info("Generating Electronic Invoice XML file for Purchase Order Document " + poDocNumber);
    PurchaseOrderService poService = SpringContext.getBean(PurchaseOrderService.class);
    PurchaseOrderDocument po = null;

    if (StringUtils.isBlank(poDocNumber)) {
        GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PURCHASE_ORDER_DOCUMENT_NUMBER,
                PurapKeyConstants.ERROR_ELECTRONIC_INVOICE_GENERATION_PURCHASE_ORDER_NUMBER_EMPTY,
                new String[] { poDocNumber });
        return mapping.findForward(RiceConstants.MAPPING_BASIC);
    }
    if (!getDocumentService().documentExists(poDocNumber)) {
        GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PURCHASE_ORDER_DOCUMENT_NUMBER,
                PurapKeyConstants.ERROR_ELECTRONIC_INVOICE_GENERATION_PURCHASE_ORDER_DOES_NOT_EXIST,
                poDocNumber);
        return mapping.findForward(RiceConstants.MAPPING_BASIC);
    }

    try {
        po = poService.getPurchaseOrderByDocumentNumber(poDocNumber);
    } catch (Exception e) {
        throw e;
    }

    response.setHeader("Cache-Control", "max-age=30");
    response.setContentType("application/xml");
    StringBuffer sbContentDispValue = new StringBuffer();
    String useJavascript = request.getParameter("useJavascript");
    if (useJavascript == null || useJavascript.equalsIgnoreCase("false")) {
        sbContentDispValue.append("attachment");
    } else {
        sbContentDispValue.append("inline");
    }
    StringBuffer sbFilename = new StringBuffer();
    sbFilename.append("PO_");
    sbFilename.append(poDocNumber);
    sbFilename.append(".xml");
    sbContentDispValue.append("; filename=");
    sbContentDispValue.append(sbFilename);
    response.setHeader("Content-disposition", sbContentDispValue.toString());

    // lookup the PO and fill in the XML with valid data
    if (po != null) {
        String duns = "";
        if (po.getVendorDetail() != null) {
            duns = StringUtils.defaultString(po.getVendorDetail().getVendorDunsNumber());
        }

        DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class);
        String currDate = ElectronicInvoiceUtils.getDateDisplayText(dateTimeService.getCurrentDate()); // getting date in ole format
        String vendorNumber = po.getVendorDetail().getVendorNumber();

        String eInvoiceFile = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                + "\n<!-- ******Testing tool generated XML****** Version 1.2." + "\n\n  Generated On "
                + currDate + " for PO " + po.getPurapDocumentIdentifier() + " (Doc# " + poDocNumber
                + ") -->\n\n" + "<!-- All the cXML attributes are junk values -->\n"
                + "<cXML payloadID=\"200807260401062080.964@eai002\"\n"
                + "    timestamp=\"2008-07-26T04:01:06-08:00\"\n" + "    version=\"1.2.014\" xml:lang=\"en\" \n"
                + "    xmlns=\"http://www.kuali.org/ole/purap/electronicInvoice\" \n"
                + "    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" + "  <Header>\n"
                + "      <From>\n" + "          <Credential domain=\"DUNS\">\n" + "              <Identity>"
                + duns + "</Identity> <!-- DUNS number from PO Vendor " + vendorNumber + "-->\n"
                + "          </Credential>\n" + "      </From>\n" + "      <To>\n"
                + "          <Credential domain=\"NetworkId\">\n" + "              <Identity>" + "IU"
                + "</Identity> <!-- Hardcoded --> \n" + "          </Credential>\n" + "      </To>\n"
                + "      <Sender>\n" + "          <Credential domain=\"DUNS\">\n" + "              <Identity>"
                + duns + "</Identity> <!-- DUNS number from PO Vendor " + vendorNumber + "-->\n"
                + "          </Credential>\n" + "          <UserAgent/>\n" + "      </Sender>\n"
                + "  </Header>\n" + "  <Request deploymentMode=\"production\">\n"
                + "      <InvoiceDetailRequest>\n" + "          <InvoiceDetailRequestHeader\n"
                + "              invoiceDate=\"" + currDate + "\" invoiceID=\"" + RandomUtils.nextInt()
                + "\" operation=\"new\" purpose=\"standard\"> <!-- invoiceID=Random unique Id, invoiceDate=Curr date -->\n"
                + "              <InvoiceDetailHeaderIndicator/>\n"
                + "              <InvoiceDetailLineIndicator/>\n" + "              <InvoicePartner>\n"
                + getContactXMLChunk("billTo", po) + "              </InvoicePartner>\n"
                + "              <InvoicePartner>\n" + "                  <Contact addressID=\""
                + RandomUtils.nextInt() + "\" role=\"remitTo\"> <!-- Vendor address -->\n"
                + "                      <Name xml:lang=\"en\">\n" + "                          "
                + po.getVendorName() + "\n" + "                      </Name>\n"
                + "                      <PostalAddress>\n" + "                          <Street>"
                + StringUtils.defaultString(po.getVendorLine1Address()) + "</Street>\n"
                + "                          <Street>" + StringUtils.defaultString(po.getVendorLine2Address())
                + "</Street>\n" + "                          <City>"
                + StringUtils.defaultString(po.getVendorCityName()) + "</City>\n"
                + "                          <State>" + StringUtils.defaultString(po.getVendorStateCode())
                + "</State>\n" + "                          <PostalCode>"
                + StringUtils.defaultString(po.getVendorPostalCode()) + "</PostalCode>\n"
                + "                          <Country isoCountryCode=\""
                + StringUtils.defaultString(po.getVendorCountryCode()) + "\">\n"
                + "                              " + StringUtils.defaultString(po.getVendorCountry().getName())
                + "\n" + "                          </Country>\n" + "                      </PostalAddress>\n"
                + "                  </Contact>\n" + "              </InvoicePartner>\n"
                + getDeliveryAddressXMLChunk("shipTo", po) + getPaymentTermXML(po)
                + "          </InvoiceDetailRequestHeader>\n" + "          <InvoiceDetailOrder>\n"
                + "              <InvoiceDetailOrderInfo>\n" + "                  <OrderReference\n"
                + "                      orderDate=\""
                + ElectronicInvoiceUtils.getDateDisplayText(dateTimeService.getCurrentDate()) + "\" orderID=\""
                + po.getPurapDocumentIdentifier() + "\"> <!--orderDate=Curr date,orderID=PO#-->\n"
                + "                      <DocumentReference payloadID=\"NA\" /> <!--HardCoded-->\n"
                + "                  </OrderReference>\n" + "              </InvoiceDetailOrderInfo>\n"
                + "              <!-- No junk values in Items-->\n";

        for (int i = 0; i < po.getItems().size(); i++) {
            List items = po.getItems();
            PurchaseOrderItem item = (PurchaseOrderItem) items.get(i);
            if (!item.getItemType().isAdditionalChargeIndicator()) {
                eInvoiceFile = eInvoiceFile + getPOItemXMLChunk(item);
            }
        }

        KualiDecimal totalDollarAmt = po.getTotalDollarAmount() == null ? KualiDecimal.ZERO
                : po.getTotalDollarAmount();
        eInvoiceFile = eInvoiceFile +

                "          </InvoiceDetailOrder>\n" + "          <InvoiceDetailSummary>\n"
                + "              <SubtotalAmount>\n" + "                  <Money currency=\"USD\">"
                + po.getTotalPreTaxDollarAmount() + "</Money>\n" + "              </SubtotalAmount>\n"
                + "              <Tax>\n" + "                  <Money currency=\"USD\">"
                + po.getTotalTaxAmount() + "</Money>\n"
                + "                  <Description xml:lang=\"en\">Total Tax</Description>\n"
                + "              </Tax>\n" + "              <SpecialHandlingAmount>\n"
                + "                  <Money currency=\"USD\">0.00</Money>\n"
                + "              </SpecialHandlingAmount>\n" + "              <ShippingAmount>\n"
                + "                  <Money currency=\"USD\">0.00</Money>\n"
                + "              </ShippingAmount>\n" + "              <GrossAmount>\n"
                + "                  <Money currency=\"USD\">" + totalDollarAmt + "</Money>\n"
                + "              </GrossAmount>\n" + "              <InvoiceDetailDiscount>\n"
                + "                  <Money currency=\"USD\">0.00</Money>\n"
                + "                  </InvoiceDetailDiscount>\n" + "              <NetAmount>\n"
                + "                  <Money currency=\"USD\">" + totalDollarAmt + "</Money>\n"
                + "              </NetAmount>\n" + "              <DepositAmount>\n"
                + "                  <Money currency=\"USD\">0.00</Money>\n"
                + "              </DepositAmount>\n" + "              <DueAmount>\n"
                + "                  <Money currency=\"USD\">" + totalDollarAmt + "</Money>\n"
                + "              </DueAmount>\n" + "          </InvoiceDetailSummary>\n"
                + "      </InvoiceDetailRequest>\n" + "  </Request>\n" + "</cXML>";

        ServletOutputStream sos;
        sos = response.getOutputStream();
        ByteArrayOutputStream baOutStream = new ByteArrayOutputStream();
        StringBufferInputStream inStream = new StringBufferInputStream(eInvoiceFile);
        convert(baOutStream, inStream);
        response.setContentLength(baOutStream.size());
        baOutStream.writeTo(sos);
        sos.flush();
    }

    return mapping.findForward(OLEConstants.MAPPING_BASIC);
}

From source file:org.opencustomer.connector.webdav.WebdavFileStore.java

/**
 * generates dynamically the iCalendar files.
 * @return the iCalendar file//w  w  w  .  java2s . c  o m
 */
public InputStream getResourceContent(String resourceUri)
        throws ServiceAccessException, AccessDeniedException, ObjectNotFoundException {

    if (calendarmap.containsKey(resourceUri)) {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try {
            if (log.isInfoEnabled())
                log.info("calendar export [" + resourceUri + "]");

            Ical.getInstance().exportIcal(calendarmap.get(resourceUri), user, out);
        } catch (IOException e) {
            throw new ServiceAccessException(service, e);
        } catch (ValidationException e) {
            throw new ServiceAccessException(service, e);
        } catch (ParseException e) {
            throw new ServiceAccessException(service, e);
        }
        return new ByteArrayInputStream(out.toByteArray());
    }
    return new StringBufferInputStream("");
}

From source file:org.totschnig.sendwithftp.FtpTransfer.java

private void handleSendText(Intent intent) {
    String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
    if (sharedText != null) {
        is = new StringBufferInputStream(sharedText);
        fileName = intent.getStringExtra(Intent.EXTRA_SUBJECT);
        fileType = FTP.ASCII_FILE_TYPE;/*www .j  a va2 s .c  o m*/
    }
}

From source file:org.webcurator.core.archive.oms.OMSArchive.java

/**
 * @param targetInstanceOID The target instance oid 
 * @param SIP The METS xml structure for completion and archival
 * @param xAttributes Any extra attributes that may be required for archival (generally contains parameters for OMS meta-data)
 * @param files A list of files (@see org.webcurator.core.archive.ArchiveFile) to archive 
 * @return A unique archive identifier (IID returned form the OMS system)
 * @throws OMSArchiveException/*  w  w  w .  j a  va  2s . c  o m*/
 */
public String submitToArchive(String targetInstanceOID, String SIP, Map xAttributes, List<ArchiveFile> files)
        throws OMSUploadException {
    String IID = null;
    if (targetInstanceOID != null) {
        OMSUploadUtil uploader = new OMSUploadUtil(targetInstanceOID);
        try {
            populateUploader(uploader, xAttributes);
            for (ArchiveFile f : files) {
                FileInputStream fis = new FileInputStream(f.getFile());
                f.setMd5(uploader.uploadContent(fis, f.getFile().getName(), f.getFile().length()));
                fis.close();
            }
            // TODO finish SIP METS xml based on files
            String finalSIP = getFinalSIP(SIP, targetInstanceOID, files);
            InputStream sipIS = new StringBufferInputStream(finalSIP);
            String metsFileName = "METS-" + targetInstanceOID + ".xml";
            uploader.uploadContent(sipIS, metsFileName, finalSIP.length());
            IID = uploader.uploadPub();
        } catch (FileNotFoundException fnfe) {
            // TODO Auto-generated catch block
            log.error("Content file not found", fnfe);
            throw new OMSUploadException(fnfe);
        } catch (OMSUploadException oue) {
            // TODO Auto-generated catch block
            log.error("Error submitting to archive", oue);
            throw new OMSUploadException(oue);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            log.error("Error submiting to archive", e);
            throw new OMSUploadException(e);
        }
    }
    return IID;
}