Package org.ofbiz.entity.util

Examples of org.ofbiz.entity.util.ByteWrapper


       
        Map results = ServiceUtil.returnSuccess();
        GenericDelegator delegator = dctx.getDelegator();
        try {
            Map acroFieldMap = (Map)context.get("acroFieldMap");
            ByteWrapper byteWrapper = getInputByteWrapper(context, delegator);
            PdfReader r = new PdfReader(byteWrapper.getBytes());
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            PdfStamper s = new PdfStamper(r, baos);
            AcroFields fs = s.getAcroFields();
            Map map = fs.getFields();
           
            s.setFormFlattening(true);
           
            // Debug code to get the values for setting TDP
    //      String[] sa = fs.getAppearanceStates("TDP");
    //      for (int i=0;i<sa.length;i++)
    //          Debug.log("Appearance="+sa[i]);
           
            Iterator iter = map.keySet().iterator();
            while (iter.hasNext()) {
                String fieldName=(String)iter.next();
                String fieldValue = fs.getField(fieldName);
                Object obj = acroFieldMap.get(fieldName);
                if (obj instanceof Date) {
                    Date d=(Date)obj;
                    fieldValue=UtilDateTime.toDateString(d);
                } else if (obj instanceof Long) {
                    Long lg=(Long)obj;
                    fieldValue=lg.toString();
                } else if (obj instanceof Integer) {
                    Integer ii=(Integer)obj;
                    fieldValue=ii.toString();
                }   else {
                    fieldValue=(String)obj;
                }
           
                if (UtilValidate.isNotEmpty(fieldValue))
                    fs.setField(fieldName, fieldValue);
            }     
                
            s.close();
            baos.close();
            ByteWrapper outByteWrapper = new ByteWrapper(baos.toByteArray());
            results.put("outByteWrapper", outByteWrapper);
        } catch(DocumentException e) {
            System.err.println(e.getMessage());
            ServiceUtil.returnError(e.getMessage());
        } catch(GeneralException e) {
View Full Code Here


                }
                Chunk chunk = new Chunk(surveyQuestion.getString("question") + ": " + value);
                Paragraph p = new Paragraph(chunk);
                document.add(p);
            }
            ByteWrapper outByteWrapper = new ByteWrapper(baos.toByteArray());
            results.put("outByteWrapper", outByteWrapper);
        } catch (GenericEntityException e) {
            System.err.println(e.getMessage());
            ServiceUtil.returnError(e.getMessage());
        } catch (DocumentException e) {
View Full Code Here

                String errMsg = ServiceUtil.makeErrorMessage(map, null, null, null, null);
                System.err.println(errMsg);
                ServiceUtil.returnError(errMsg);
            }
            String pdfFileNameOut = (String)context.get("pdfFileNameOut");
            ByteWrapper outByteWrapper = (ByteWrapper)map.get("outByteWrapper");
            results.put("outByteWrapper", outByteWrapper);
            if (UtilValidate.isNotEmpty(pdfFileNameOut)) {
                FileOutputStream fos = new FileOutputStream(pdfFileNameOut);
                fos.write(outByteWrapper.getBytes());
                fos.close();
            }
        } catch(FileNotFoundException e) {
            System.err.println(e.getMessage());
            ServiceUtil.returnError(e.getMessage());
View Full Code Here

    return results;
    }
   
    public static ByteWrapper getInputByteWrapper(Map context, GenericDelegator delegator) throws GeneralException {
       
        ByteWrapper inputByteWrapper = (ByteWrapper)context.get("inputByteWrapper");
       
        if (inputByteWrapper == null) {
            String pdfFileNameIn = (String)context.get("pdfFileNameIn");
            String contentId = (String)context.get("contentId");
            if (UtilValidate.isNotEmpty(pdfFileNameIn)) {
                try {
                    FileInputStream fis = new FileInputStream(pdfFileNameIn);
                    int c;
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    while ((c = fis.read()) != -1) baos.write(c);
                    inputByteWrapper = new ByteWrapper(baos.toByteArray());
                } catch(FileNotFoundException e) {
                    throw(new GeneralException(e.getMessage()));
                } catch(IOException e) {
                    throw(new GeneralException(e.getMessage()));
                }
View Full Code Here

        return ServiceUtil.returnSuccess();
    }

    public static Map byteWrapperTest(DispatchContext dctx, Map context) {
        ByteWrapper wrapper1 = (ByteWrapper) context.get("byteWrapper1");
        ByteWrapper wrapper2 = (ByteWrapper) context.get("byteWrapper2");
        String fileName1 = (String) context.get("saveAsFileName1");
        String fileName2 = (String) context.get("saveAsFileName2");
        String ofbizHome = System.getProperty("ofbiz.home");
        String outputPath1 = ofbizHome + (fileName1.startsWith("/") ? fileName1 : "/" + fileName1);
        String outputPath2 = ofbizHome + (fileName2.startsWith("/") ? fileName2 : "/" + fileName2);

        try {
            RandomAccessFile file1 = new RandomAccessFile(outputPath1, "rw");
            RandomAccessFile file2 = new RandomAccessFile(outputPath2, "rw");
            file1.write(wrapper1.getBytes());
            file2.write(wrapper2.getBytes());
        } catch (FileNotFoundException e) {
            Debug.logError(e, module);
        } catch (IOException e) {
            Debug.logError(e, module);
        }
View Full Code Here

    public static Map uploadTest(DispatchContext dctx, Map context) {
        LocalDispatcher dispatcher = dctx.getDispatcher();
        GenericValue userLogin = (GenericValue) context.get("userLogin");

        ByteWrapper wrapper = (ByteWrapper) context.get("uploadFile");
        String fileName = (String) context.get("_uploadFile_fileName");
        String contentType = (String) context.get("_uploadFile_contentType");

        Map createCtx = new HashMap();
        createCtx.put("binData", wrapper);
View Full Code Here

                        InputStream is = part.getInputStream();
                        int c;
                        while ((c = is.read()) > -1) {
                            baos.write(c);
                        }
                        ByteWrapper imageData = new ByteWrapper(baos.toByteArray());
                        int len = imageData.getLength();
                        if (Debug.infoOn()) Debug.logInfo("imageData length: " + len, module);
                        commEventMap.put("drDataResourceName", part.getFileName());
                        commEventMap.put("imageData", imageData);
                        commEventMap.put("drDataResourceTypeId", "IMAGE_OBJECT");
                        commEventMap.put("_imageData_contentType", thisContentType);
View Full Code Here

        String contentId = request.getParameter("contentId");
        String rootContentId = request.getParameter("rootContentId");
      String dataResourceId = request.getParameter("dataResourceId");
        String contentRevisionSeqId = request.getParameter("contentRevisionSeqId");
        String mimeTypeId = request.getParameter("mimeTypeId");
        ByteWrapper byteWrapper = null;
        Locale locale = UtilHttp.getLocale(request);
        String rootDir = null;
        String webSiteId = null;
        String https = null;
       
        if (UtilValidate.isEmpty(rootDir)) {
            rootDir = servletContext.getRealPath("/");
        }
        if (UtilValidate.isEmpty(webSiteId)) {
            webSiteId = (String) servletContext.getAttribute("webSiteId");
        }
        if (UtilValidate.isEmpty(https)) {
            https = (String) servletContext.getAttribute("https");
        }
      try {
            Debug.logInfo("SCVH(0a)- dataResourceId:" + dataResourceId, module);
            GenericDelegator delegator = (GenericDelegator)request.getAttribute("delegator");
            if (UtilValidate.isEmpty(dataResourceId)) {
                if (UtilValidate.isEmpty(contentRevisionSeqId)) {
                   GenericValue content = delegator.findByPrimaryKeyCache("Content", UtilMisc.toMap("contentId", contentId));
                   dataResourceId = content.getString("dataResourceId");
                   Debug.logInfo("SCVH(0b)- dataResourceId:" + dataResourceId, module);
                } else {
                   GenericValue contentRevisionItem = delegator.findByPrimaryKeyCache("ContentRevisionItem", UtilMisc.toMap("contentId", rootContentId, "itemContentId", contentId, "contentRevisionSeqId", contentRevisionSeqId));
                   if (contentRevisionItem == null) {
                       throw new ViewHandlerException("ContentRevisionItem record not found for contentId=" + rootContentId
                                                      + ", contentRevisionSeqId=" + contentRevisionSeqId + ", itemContentId=" + contentId);
                   }
                   Debug.logInfo("SCVH(1)- contentRevisionItem:" + contentRevisionItem, module);
                   Debug.logInfo("SCVH(2)-contentId=" + rootContentId
                           + ", contentRevisionSeqId=" + contentRevisionSeqId + ", itemContentId=" + contentId, module);
                   dataResourceId = contentRevisionItem.getString("newDataResourceId");
                   Debug.logInfo("SCVH(3)- dataResourceId:" + dataResourceId, module);
                }
        }
      GenericValue dataResource = delegator.findByPrimaryKeyCache("DataResource", UtilMisc.toMap("dataResourceId", dataResourceId));
        byteWrapper = DataResourceWorker.getContentAsByteWrapper(delegator, dataResourceId, https, webSiteId, locale, rootDir);
        ByteArrayInputStream bais = new ByteArrayInputStream(byteWrapper.getBytes());
            // hack for IE and mime types
            //String userAgent = request.getHeader("User-Agent");
            //if (userAgent.indexOf("MSIE") > -1) {
            //    Debug.log("Found MSIE changing mime type from - " + mimeTypeId, module);
            //    mimeTypeId = "application/octet-stream";
            //}
            // setup chararcter encoding and content type
            String charset = dataResource.getString("characterSetId");
            mimeTypeId = dataResource.getString("mimeTypeId");
            if (UtilValidate.isEmpty(charset)) {
              charset = servletContext.getInitParameter("charset");
            }
            if (UtilValidate.isEmpty(charset)) {
              charset = "ISO-8859-1";
            }

            // setup content type
            String contentType2 = UtilValidate.isNotEmpty(mimeTypeId) ? mimeTypeId + "; charset=" +charset : contentType;

            UtilHttp.streamContentToBrowser(response, bais, byteWrapper.getLength(), contentType2);
      } catch(GenericEntityException e) {
            throw new ViewHandlerException(e.getMessage());
      } catch(IOException e) {
            throw new ViewHandlerException(e.getMessage());
      } catch(GeneralException e) {
View Full Code Here

                            }
                            if (lastIndex > -1) {
                                fileName = fileName.substring(lastIndex + 1);
                            }
                        }
                        multiPartMap.put(fieldName, new ByteWrapper(item.get()));
                        multiPartMap.put("_" + fieldName + "_size", new Long(item.getSize()));
                        multiPartMap.put("_" + fieldName + "_fileName", fileName);
                        multiPartMap.put("_" + fieldName + "_contentType", item.getContentType());
                    }
                }
View Full Code Here

      ModelService dataResourceModel = dispatcher.getDispatchContext().getModelService("updateDataResource");
      Map ctx = dataResourceModel.makeValid(dataResource, "IN");
      newDrContext.putAll(ctx);
      newDrContext.put("userLogin", userLogin);
      newDrContext.put("skipPermissionCheck", context.get("skipPermissionCheck"));
      ByteWrapper byteWrapper = (ByteWrapper)context.get("imageData");
      String mimeTypeId = (String) newDrContext.get("mimeTypeId");
      if (byteWrapper != null && (mimeTypeId == null || (mimeTypeId.indexOf("image") >= 0) || (mimeTypeId.indexOf("application") >= 0))) {
          mimeTypeId = (String) context.get("_imageData_contentType");
          if (dataResourceTypeId.equals("IMAGE_OBJECT")) {
              String fileName = (String) context.get("_imageData_fileName");
View Full Code Here

TOP

Related Classes of org.ofbiz.entity.util.ByteWrapper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.