Examples of ByteWrapper


Examples of org.ofbiz.entity.util.ByteWrapper

        String fileInName = "OOIN_" + uniqueSeqNum;
        String fileOutName = "OOOUT_" + uniqueSeqNum;
        File fileIn = null;
        File fileOut = null;
       
        ByteWrapper inByteWrapper = (ByteWrapper) context.get("inByteWrapper");
        String inputMimeType = (String) context.get("inputMimeType");
        String outputMimeType = (String) context.get("outputMimeType");
        String extName = OpenOfficeWorker.getExtensionFromMimeType(outputMimeType);
        fileOutName += "." + extName;

        // if these are empty don't worry, the OpenOfficeWorker down below will take care of it
        String oooHost = (String) context.get("oooHost");
        String oooPort = (String) context.get("oooPort");
       
        try {  
            xmulticomponentfactory = OpenOfficeWorker.getRemoteServer(oooHost, oooPort);
            byte[] inByteArray = inByteWrapper.getBytes();
           
            // The following line work in linux, but not Windows or Mac environment. It is preferred because it does not use temporary files
            //OpenOfficeByteArrayInputStream oobais = new OpenOfficeByteArrayInputStream(inByteArray);
            //Debug.logInfo("Doing convertDocumentByteWrapper, inBytes size is [" + inByteArray.length + "]", module);
             //OpenOfficeByteArrayOutputStream baos = OpenOfficeWorker.convertOODocByteStreamToByteStream(xmulticomponentfactory, oobais, inputMimeType, outputMimeType);
           
           
            String tempDir = UtilProperties.getPropertyValue("content", "content.temp.dir");
            fileIn = new File(tempDir + fileInName);
            FileOutputStream fos = new FileOutputStream(fileIn);
            fos.write(inByteArray);
            fos.close();
            Debug.logInfo("fileIn:" + tempDir + fileInName, module);
            OpenOfficeWorker.convertOODocToFile(xmulticomponentfactory, tempDir + fileInName, tempDir + fileOutName, outputMimeType);
            fileOut = new File(tempDir + fileOutName);
            FileInputStream fis = new FileInputStream(fileOut);
            int c;
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            while ((c=fis.read()) > -1) {
                baos.write(c);
            }
            fis.close();
           
            results.put("outByteWrapper", new ByteWrapper(baos.toByteArray()));
            baos.close();

        } catch (MalformedURLException e) {
            Debug.logError(e, module);
            return ServiceUtil.returnError(e.toString());
View Full Code Here

Examples of org.ofbiz.entity.util.ByteWrapper

                    inputMimeType = dataResource.getString("mimeTypeId");
                }
                byte [] inputByteArray = null;
                PdfReader reader = null;
                if (inputMimeType != null && inputMimeType.equals("application/pdf")) {
                    ByteWrapper byteWrapper = DataResourceWorker.getContentAsByteWrapper(delegator, thisDataResourceId, https, webSiteId, locale, rootDir);
                    inputByteArray = byteWrapper.getBytes();
                    reader = new PdfReader(inputByteArray);
                } else if (inputMimeType != null && inputMimeType.equals("text/html")) {
                    ByteWrapper byteWrapper = DataResourceWorker.getContentAsByteWrapper(delegator, thisDataResourceId, https, webSiteId, locale, rootDir);
                    inputByteArray = byteWrapper.getBytes();
                    String s = new String(inputByteArray);
                    Debug.logInfo("text/html string:" + s, module);
                    continue;
                } else if (inputMimeType != null && inputMimeType.equals("application/vnd.ofbiz.survey.response")) {
                    String surveyResponseId = dataResource.getString("relatedDetailId");
                    String surveyId = null;
                    String acroFormContentId = null;
                    GenericValue surveyResponse = null;
                    if (UtilValidate.isNotEmpty(surveyResponseId)) {
                        surveyResponse = delegator.findByPrimaryKey("SurveyResponse", UtilMisc.toMap("surveyResponseId", surveyResponseId));
                        if (surveyResponse != null) {
                            surveyId = surveyResponse.getString("surveyId");
                        }
                    }
                    if (UtilValidate.isNotEmpty(surveyId)) {
                        GenericValue survey = delegator.findByPrimaryKey("Survey", UtilMisc.toMap("surveyId", surveyId));
                        if (survey != null) {
                            acroFormContentId = survey.getString("acroFormContentId");
                            if (UtilValidate.isNotEmpty(acroFormContentId)) {
                                // TODO: is something supposed to be done here?
                            }
                        }
                    }
                    if (surveyResponse != null) {
                        if (UtilValidate.isEmpty(acroFormContentId)) {
                            // Create AcroForm PDF
                            Map survey2PdfResults = dispatcher.runSync("buildPdfFromSurveyResponse", UtilMisc.toMap("surveyResponseId", surveyId));
                            if (ServiceUtil.isError(survey2PdfResults)) {
                                return ServiceUtil.returnError("Error building PDF from SurveyResponse: ", null, null, survey2PdfResults);
                            }

                            ByteWrapper outByteWrapper = (ByteWrapper)survey2PdfResults.get("outByteWrapper");
                            inputByteArray = outByteWrapper.getBytes();
                            reader = new PdfReader(inputByteArray);
                        } else {
                            // Fill in acroForm
                            Map survey2AcroFieldResults = dispatcher.runSync("setAcroFieldsFromSurveyResponse", UtilMisc.toMap("surveyResponseId", surveyResponseId));
                            if (ServiceUtil.isError(survey2AcroFieldResults)) {
                                return ServiceUtil.returnError("Error setting AcroFields from SurveyResponse: ", null, null, survey2AcroFieldResults);
                            }

                            ByteWrapper outByteWrapper = (ByteWrapper) survey2AcroFieldResults.get("outByteWrapper");
                            inputByteArray = outByteWrapper.getBytes();
                            reader = new PdfReader(inputByteArray);
                        }
                    }
                } else {
                    ByteWrapper inByteWrapper = DataResourceWorker.getContentAsByteWrapper(delegator, thisDataResourceId, https, webSiteId, locale, rootDir);

                    Map convertInMap = UtilMisc.toMap("userLogin", userLogin, "inByteWrapper", inByteWrapper, "inputMimeType", inputMimeType, "outputMimeType", "application/pdf");
                    if (UtilValidate.isNotEmpty(oooHost)) convertInMap.put("oooHost", oooHost);
                    if (UtilValidate.isNotEmpty(oooPort)) convertInMap.put("oooPort", oooPort);

                    Map convertResult = dispatcher.runSync("convertDocumentByteWrapper", convertInMap);
                   
                    if (ServiceUtil.isError(convertResult)) {
                        return ServiceUtil.returnError("Error in Open", null, null, convertResult);
                    }

                    ByteWrapper outByteWrapper = (ByteWrapper) convertResult.get("outByteWrapper");
                    inputByteArray = outByteWrapper.getBytes();
                    reader = new PdfReader(inputByteArray);
                }
                if (reader != null) {
                    int n = reader.getNumberOfPages();
                    for (int i=0; i < n; i++) {
                        PdfImportedPage pg = writer.getImportedPage(reader, i + 1);
                        //cb.addTemplate(pg, left, height * pgCnt);
                        writer.addPage(pg);
                        pgCnt++;
                    }
                }
            }
            document.close();
            ByteWrapper outByteWrapper = new ByteWrapper(baos.toByteArray());

            Map results = ServiceUtil.returnSuccess();
            results.put("outByteWrapper", outByteWrapper);
            return results;
        } catch (GenericEntityException e) {
View Full Code Here

Examples of org.ofbiz.entity.util.ByteWrapper

            if(dataResource != null) {
                inputMimeType = dataResource.getString("mimeTypeId");
            }
            byte [] inputByteArray = null;
            if (inputMimeType != null && inputMimeType.equals("application/pdf")) {
                ByteWrapper byteWrapper = DataResourceWorker.getContentAsByteWrapper(delegator, dataResourceId, https, webSiteId, locale, rootDir);
                inputByteArray = byteWrapper.getBytes();
            } else if (inputMimeType != null && inputMimeType.equals("text/html")) {
                ByteWrapper byteWrapper = DataResourceWorker.getContentAsByteWrapper(delegator, dataResourceId, https, webSiteId, locale, rootDir);
                inputByteArray = byteWrapper.getBytes();
                String s = new String(inputByteArray);
                Debug.logInfo("text/html string:" + s, module);
            } else if (inputMimeType != null && inputMimeType.equals("application/vnd.ofbiz.survey.response")) {
                String surveyResponseId = dataResource.getString("relatedDetailId");
                String surveyId = null;
                String acroFormContentId = null;
                GenericValue surveyResponse = null;
                if (UtilValidate.isNotEmpty(surveyResponseId)) {
                    surveyResponse = delegator.findByPrimaryKey("SurveyResponse", UtilMisc.toMap("surveyResponseId", surveyResponseId));
                    if (surveyResponse != null) {
                        surveyId = surveyResponse.getString("surveyId");
                    }
                }
                if (UtilValidate.isNotEmpty(surveyId)) {
                    GenericValue survey = delegator.findByPrimaryKey("Survey", UtilMisc.toMap("surveyId", surveyId));
                    if (survey != null) {
                        acroFormContentId = survey.getString("acroFormContentId");
                        if (UtilValidate.isNotEmpty(acroFormContentId)) {
                            // TODO: is something supposed to be done here?
                        }
                    }
                }
           
                if (surveyResponse != null) {
                    if (UtilValidate.isEmpty(acroFormContentId)) {
                        // Create AcroForm PDF
                        Map survey2PdfResults = dispatcher.runSync("buildPdfFromSurveyResponse", UtilMisc.toMap("surveyResponseId", surveyResponseId));
                        if (ServiceUtil.isError(survey2PdfResults)) {
                            return ServiceUtil.returnError("Error building PDF from SurveyResponse: ", null, null, survey2PdfResults);
                        }

                        ByteWrapper outByteWrapper = (ByteWrapper)survey2PdfResults.get("outByteWrapper");
                        inputByteArray = outByteWrapper.getBytes();
                    } else {
                        // Fill in acroForm
                        Map survey2AcroFieldResults = dispatcher.runSync("setAcroFieldsFromSurveyResponse", UtilMisc.toMap("surveyResponseId", surveyResponseId));
                        if (ServiceUtil.isError(survey2AcroFieldResults)) {
                            return ServiceUtil.returnError("Error setting AcroFields from SurveyResponse: ", null, null, survey2AcroFieldResults);
                        }

                        ByteWrapper outByteWrapper = (ByteWrapper) survey2AcroFieldResults.get("outByteWrapper");
                        inputByteArray = outByteWrapper.getBytes();
                    }
                }
            } else {
                ByteWrapper inByteWrapper = DataResourceWorker.getContentAsByteWrapper(delegator, dataResourceId, https, webSiteId, locale, rootDir);
               
                Map convertInMap = UtilMisc.toMap("userLogin", userLogin, "inByteWrapper", inByteWrapper,
                        "inputMimeType", inputMimeType, "outputMimeType", "application/pdf");
                if (UtilValidate.isNotEmpty(oooHost)) convertInMap.put("oooHost", oooHost);
                if (UtilValidate.isNotEmpty(oooPort)) convertInMap.put("oooPort", oooPort);

                Map convertResult = dispatcher.runSync("convertDocumentByteWrapper", convertInMap);
               
                if (ServiceUtil.isError(convertResult)) {
                    return ServiceUtil.returnError("Error in Open", null, null, convertResult);
                }

                ByteWrapper outByteWrapper = (ByteWrapper) convertResult.get("outByteWrapper");
                inputByteArray = outByteWrapper.getBytes();
            }
           
            ByteWrapper outByteWrapper = new ByteWrapper(inputByteArray);
            results.put("outByteWrapper", outByteWrapper);
        } catch (GenericEntityException e) {
            return ServiceUtil.returnError(e.toString());
        } catch (IOException e) {
            Debug.logError(e, "Error in PDF generation: ", module);
View Full Code Here

Examples of org.ofbiz.entity.util.ByteWrapper

    public static Map createFileMethod(DispatchContext dctx, Map context) {
            //GenericValue dataResource = (GenericValue) context.get("dataResource");
            String dataResourceTypeId = (String) context.get("dataResourceTypeId");
            String objectInfo = (String) context.get("objectInfo");
            ByteWrapper binData = (ByteWrapper) context.get("binData");
            String textData = (String) context.get("textData");

            // a few place holders
            String prefix = "";
            String sep = "";

            // extended validation for binary/character data
            if (UtilValidate.isNotEmpty(textData) && binData != null) {
                return ServiceUtil.returnError("Cannot process both character and binary data in the same file");
            }

            // obtain a reference to the file
            File file = null;
            if (UtilValidate.isEmpty(dataResourceTypeId) || dataResourceTypeId.equals("LOCAL_FILE")) {
                file = new File(objectInfo);
                if (!file.isAbsolute()) {
                    return ServiceUtil.returnError("DataResource LOCAL_FILE does not point to an absolute location");
                }
            } else if (dataResourceTypeId.equals("OFBIZ_FILE")) {
                prefix = System.getProperty("ofbiz.home");
                if (objectInfo.indexOf("/") != 0 && prefix.lastIndexOf("/") != (prefix.length() - 1)) {
                    sep = "/";
                }
                file = new File(prefix + sep + objectInfo);
            } else if (dataResourceTypeId.equals("CONTEXT_FILE")) {
                prefix = (String) context.get("rootDir");
                if (objectInfo.indexOf("/") != 0 && prefix.lastIndexOf("/") != (prefix.length() - 1)) {
                    sep = "/";
                }
                file = new File(prefix + sep + objectInfo);
            }
            if (file == null) {
                return ServiceUtil.returnError("Unable to obtain a reference to file - " + objectInfo);
            }

            // write the data to the file
            if (UtilValidate.isNotEmpty(textData)) {
                try {
                    FileWriter out = new FileWriter(file);
                    out.write(textData);
                    out.close();
                } catch (IOException e) {
                    Debug.logWarning(e, module);
                    return ServiceUtil.returnError("Unable to write character data to: " + file.getAbsolutePath());
                }
            } else if (binData != null) {
                try {
                    RandomAccessFile out = new RandomAccessFile(file, "rw");
                    out.write(binData.getBytes());
                    out.close();
                } catch (FileNotFoundException e) {
                    Debug.logError(e, module);
                    return ServiceUtil.returnError("Unable to open file for writing: " + file.getAbsolutePath());
                } catch (IOException e) {
View Full Code Here

Examples of org.ofbiz.entity.util.ByteWrapper

        //Locale locale = (Locale) context.get("locale");
            //String dataResourceId = (String) dataResource.get("dataResourceId");
            String dataResourceTypeId = (String) context.get("dataResourceTypeId");
            String objectInfo = (String) context.get("objectInfo");
            String textData = (String) context.get("textData");
            ByteWrapper binData = (ByteWrapper) context.get("binData");
            String prefix = "";
            File file = null;
            String fileName = "";
            String sep = "";
            try {
                if (UtilValidate.isEmpty(dataResourceTypeId) || dataResourceTypeId.startsWith("LOCAL_FILE")) {
                    fileName = prefix + sep + objectInfo;
                    file = new File(fileName);
                    if (file == null) {
                        throw new GenericServiceException("File: " + fileName + " is null.");
                    }
                    if (!file.isAbsolute()) {
                        throw new GenericServiceException("File: " + fileName + " is not absolute.");
                    }
                } else if (dataResourceTypeId.startsWith("OFBIZ_FILE")) {
                    prefix = System.getProperty("ofbiz.home");
                    if (objectInfo.indexOf("/") != 0 && prefix.lastIndexOf("/") != (prefix.length() - 1)) {
                        sep = "/";
                    }
                    file = new File(prefix + sep + objectInfo);
                } else if (dataResourceTypeId.startsWith("CONTEXT_FILE")) {
                    prefix = (String) context.get("rootDir");
                    if (objectInfo.indexOf("/") != 0 && prefix.lastIndexOf("/") != (prefix.length() - 1)) {
                        sep = "/";
                    }
                    file = new File(prefix + sep + objectInfo);
                }
                if (file == null) {
                    throw new IOException("File: " + file + " is null");
                }
           
            // write the data to the file
            if (UtilValidate.isNotEmpty(textData)) {
                try {
                    FileWriter out = new FileWriter(file);
                    out.write(textData);
                    out.close();
                } catch (IOException e) {
                    Debug.logWarning(e, module);
                    return ServiceUtil.returnError("Unable to write character data to: " + file.getAbsolutePath());
                }
            } else if (binData != null) {
                try {
                    RandomAccessFile out = new RandomAccessFile(file, "rw");
                    out.write(binData.getBytes());
                    out.close();
                } catch (FileNotFoundException e) {
                    Debug.logError(e, module);
                    return ServiceUtil.returnError("Unable to open file for writing: " + file.getAbsolutePath());
                } catch (IOException e) {
View Full Code Here

Examples of org.ofbiz.entity.util.ByteWrapper

    public static Map updateImageMethod(DispatchContext dctx, Map context) {
        HashMap result = new HashMap();
        GenericDelegator delegator = dctx.getDelegator();
        //Locale locale = (Locale) context.get("locale");
            String dataResourceId = (String) context.get("dataResourceId");
            ByteWrapper byteWrapper = (ByteWrapper)context.get("imageData");
            if (byteWrapper != null) {
                byte[] imageBytes = byteWrapper.getBytes();
                try {
                    GenericValue imageDataResource = delegator.findByPrimaryKey("ImageDataResource", UtilMisc.toMap("dataResourceId", dataResourceId));
                    if (Debug.infoOn()) Debug.logInfo("imageDataResource(U):" + imageDataResource, module);
                    if (Debug.infoOn()) Debug.logInfo("imageBytes(U):" + imageBytes, module);
                    if (imageDataResource == null) {
View Full Code Here

Examples of org.ofbiz.entity.util.ByteWrapper

    public static Map createImageMethod(DispatchContext dctx, Map context) {
        HashMap result = new HashMap();
        GenericDelegator delegator = dctx.getDelegator();
            String dataResourceId = (String) context.get("dataResourceId");
            ByteWrapper byteWrapper = (ByteWrapper)context.get("imageData");
            if (byteWrapper != null) {
                byte[] imageBytes = byteWrapper.getBytes();
                try {
                    GenericValue imageDataResource = delegator.makeValue("ImageDataResource", UtilMisc.toMap("dataResourceId", dataResourceId));
                    //imageDataResource.set("imageData", imageBytes);
                    imageDataResource.setBytes("imageData", imageBytes);
                    if (Debug.infoOn()) Debug.logInfo("imageDataResource(C):" + imageDataResource, module);
View Full Code Here

Examples of org.ofbiz.entity.util.ByteWrapper

        Timestamp nowTimestamp = UtilDateTime.nowTimestamp();
        String surveyId = null;
        try {
            String surveyName = (String) context.get("surveyName");
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            ByteWrapper byteWrapper = getInputByteWrapper(context, delegator);
            PdfReader pdfReader = new PdfReader(byteWrapper.getBytes());
            PdfStamper pdfStamper = new PdfStamper(pdfReader, os);
            AcroFields acroFields = pdfStamper.getAcroFields();
            HashMap acroFieldMap = acroFields.getFields();
           
            String contentId = (String) context.get("contentId");
View Full Code Here

Examples of org.ofbiz.entity.util.ByteWrapper

                surveyResponse.set("lastModifiedDate", UtilDateTime.nowTimestamp());
                surveyResponse.create();
            }
           
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            ByteWrapper byteWrapper = getInputByteWrapper(context, delegator);
            PdfReader r = new PdfReader(byteWrapper.getBytes());
            PdfStamper s = new PdfStamper(r,os);
            AcroFields fs = s.getAcroFields();
            HashMap hm = fs.getFields();
           
           
View Full Code Here

Examples of org.ofbiz.entity.util.ByteWrapper

       
        Map acroFieldMap = new HashMap();
        try {
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            GenericDelegator delegator = dctx.getDelegator();
            ByteWrapper byteWrapper = getInputByteWrapper(context, delegator);
            PdfReader r = new PdfReader(byteWrapper.getBytes());
            PdfStamper s = new PdfStamper(r,os);
            AcroFields fs = s.getAcroFields();
            HashMap map = fs.getFields();
           
            s.setFormFlattening(true);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.