Package org.ofbiz.entity.util

Examples of org.ofbiz.entity.util.ByteWrapper


            return (byte[]) value;
        }
        if (value instanceof ByteWrapper) {
            // NOTE DEJ20071022: the use of ByteWrapper is not recommended and is deprecated, only old data should be stored that way
            Debug.logWarning("Found a ByteWrapper object in the database for field [" + this.getEntityName() + "." + name + "]; converting to byte[] and returning, but note that you need to update your database to unwrap these objects for future compatibility", module);
            ByteWrapper wrapper = (ByteWrapper) value;
            return wrapper.getBytes();
        }
        // uh-oh, this shouldn't happen...
        throw new IllegalArgumentException("In call to getBytes the value is not a supported type, should be byte[] or ByteWrapper, is: " + value.getClass().getName());
    }
View Full Code Here


            HttpSession session = request.getSession();
            Map uploadResults = LayoutWorker.uploadImageAndParameters(request, "imageData");
            //Debug.logVerbose("in createLayoutImage(java), uploadResults:" + uploadResults, "");
            Map formInput = (Map)uploadResults.get("formInput");
            Map context = new HashMap();
            ByteWrapper byteWrap = (ByteWrapper)uploadResults.get("imageData");
            if (byteWrap == null) {
                String errMsg = UtilProperties.getMessage(LayoutEvents.err_resource, "layoutEvents.image_data_null", locale);                                                     
                request.setAttribute("_ERROR_MESSAGE_", errMsg);
                return "error";
            }
        //Debug.logVerbose("in createLayoutImage, byteWrap(0):" + byteWrap, module);
            String imageFileName = (String)uploadResults.get("imageFileName");
            //Debug.logVerbose("in createLayoutImage(java), context:" + context, "");
            String imageFileNameExt = null;
            if (UtilValidate.isNotEmpty(imageFileName)) {
                int pos = imageFileName.lastIndexOf(".");
                if (pos >= 0)
                    imageFileNameExt = imageFileName.substring(pos + 1);
            }
            String mimeTypeId = "image/" + imageFileNameExt;
            List errorMessages = new ArrayList();
            if (locale == null)
                locale = Locale.getDefault();
            context.put("locale", locale);

            try {
                SimpleMapProcessor.runSimpleMapProcessor(
                      "org/ofbiz/content/ContentManagementMapProcessors.xml", "contentIn",
                      formInput, context, errorMessages, locale);
                SimpleMapProcessor.runSimpleMapProcessor(
                      "org/ofbiz/content/ContentManagementMapProcessors.xml", "dataResourceIn",
                      formInput, context, errorMessages, locale);
                SimpleMapProcessor.runSimpleMapProcessor(
                      "org/ofbiz/content/ContentManagementMapProcessors.xml", "contentAssocIn",
                      formInput, context, errorMessages, locale);
            } catch(MiniLangException e) {
                request.setAttribute("_ERROR_MESSAGE_", e.getMessage());
                return "error";
            }

            context.put("dataResourceName", context.get("contentName"));
            context.put("userLogin", session.getAttribute("userLogin"));
            context.put("dataResourceTypeId", "IMAGE_OBJECT");
            context.put("contentAssocTypeId", "SUB_CONTENT");
            context.put("contentTypeId", "DOCUMENT");
            context.put("contentIdTo", formInput.get("contentIdTo"));
            context.put("textData", formInput.get("textData"));
            String contentPurposeTypeId = (String)formInput.get("contentPurposeTypeId");
            if (UtilValidate.isNotEmpty(contentPurposeTypeId)){
                context.put("contentPurposeList", UtilMisc.toList(contentPurposeTypeId));
            }
   
            Map result = dispatcher.runSync("persistContentAndAssoc", context);
        //Debug.logVerbose("in createLayoutImage, result:" + result, module);
   
            String dataResourceId = (String)result.get("dataResourceId");
            String activeContentId = (String)result.get("contentId");
            if (UtilValidate.isNotEmpty(activeContentId)) {
                Map context2 = new HashMap();
                context2.put("activeContentId", activeContentId);
                //context2.put("dataResourceId", dataResourceId);
                context2.put("contentAssocTypeId", result.get("contentAssocTypeId"));
                context2.put("fromDate", result.get("fromDate"));
       
                request.setAttribute("contentId", result.get("contentId"));
                request.setAttribute("drDataResourceId", dataResourceId);
                request.setAttribute("currentEntityName", "SubContentDataResourceId");
       
                context2.put("contentIdTo", formInput.get("contentIdTo"));
                context2.put("mapKey", formInput.get("mapKey"));
       
            //Debug.logVerbose("in createLayoutImage, context2:" + context2, module);
                Map result2 = dispatcher.runSync("deactivateAssocs", context2);
            }

            GenericValue dataResource = delegator.findByPrimaryKey("DataResource",
                          UtilMisc.toMap("dataResourceId", dataResourceId));
        //Debug.logVerbose("in createLayoutImage, dataResource:" + dataResource, module);
            // Use objectInfo field to store the name of the file, since there is no
            // place in ImageDataResource for it.
            if (dataResource != null) {
                dataResource.set("objectInfo", imageFileName);
                dataResource.set("mimeTypeId", mimeTypeId);
                dataResource.store();
            }

            // See if this needs to be a create or an update procedure
            GenericValue imageDataResource = delegator.findByPrimaryKey("ImageDataResource",
                          UtilMisc.toMap("dataResourceId", dataResourceId));
        //Debug.logVerbose("in createLayoutImage, imageDataResource(0):" + imageDataResource, module);
            if (imageDataResource == null) {
                imageDataResource = delegator.makeValue("ImageDataResource",
                          UtilMisc.toMap("dataResourceId", dataResourceId));
                imageDataResource.set("imageData", byteWrap.getBytes());
                imageDataResource.create();
            } else {
                imageDataResource.set("imageData", byteWrap.getBytes());
                imageDataResource.store();
            }
        } catch (GenericEntityException e3) {
            request.setAttribute("_ERROR_MESSAGE_", e3.getMessage());
            return "error";
View Full Code Here

        try {
            GenericDelegator delegator = (GenericDelegator)request.getAttribute("delegator");
            HttpSession session = request.getSession();
            Map uploadResults = LayoutWorker.uploadImageAndParameters(request, "imageData");
            Map context = (Map)uploadResults.get("formInput");
            ByteWrapper byteWrap = (ByteWrapper)uploadResults.get("imageData");
            if (byteWrap == null) {
                String errMsg = UtilProperties.getMessage(LayoutEvents.err_resource, "layoutEvents.image_data_null", locale);
                request.setAttribute("_ERROR_MESSAGE_", errMsg);
                return "error";
            }
            String imageFileName = (String)uploadResults.get("imageFileName");
            Debug.logVerbose("in createLayoutImage(java), context:" + context, "");
            context.put("userLogin", session.getAttribute("userLogin"));
            context.put("dataResourceTypeId", "IMAGE_OBJECT");
            context.put("contentAssocTypeId", "SUB_CONTENT");
            context.put("contentTypeId", "DOCUMENT");
            context.put("mimeType", context.get("drMimeType"));
            context.put("drMimeType", null);
            context.put("objectInfo", context.get("drobjectInfo"));
            context.put("drObjectInfo", null);
            context.put("drDataResourceTypeId", null);
   
            String dataResourceId = (String)context.get("drDataResourceId");
            Debug.logVerbose("in createLayoutImage(java), dataResourceId:" + dataResourceId, "");

            GenericValue dataResource = delegator.findByPrimaryKey("DataResource",
                          UtilMisc.toMap("dataResourceId", dataResourceId));
            Debug.logVerbose("in createLayoutImage(java), dataResource:" + dataResource, "");
            // Use objectInfo field to store the name of the file, since there is no
            // place in ImageDataResource for it.
            Debug.logVerbose("in createLayoutImage(java), imageFileName:" + imageFileName, "");
            if (dataResource != null) {
                //dataResource.set("objectInfo", imageFileName);
                dataResource.setNonPKFields(context);
                dataResource.store();
            }

            // See if this needs to be a create or an update procedure
            GenericValue imageDataResource = delegator.findByPrimaryKey("ImageDataResource",
                          UtilMisc.toMap("dataResourceId", dataResourceId));
            if (imageDataResource == null) {
                imageDataResource = delegator.makeValue("ImageDataResource",
                          UtilMisc.toMap("dataResourceId", dataResourceId));
                imageDataResource.set("imageData", byteWrap.getBytes());
                imageDataResource.create();
            } else {
                imageDataResource.set("imageData", byteWrap.getBytes());
                imageDataResource.store();
            }
        } catch (GenericEntityException e3) {
            request.setAttribute("_ERROR_MESSAGE_", e3.getMessage());
            return "error";
View Full Code Here

            //Debug.logWarning("[DataEvents.uploadImage] imageFi(" + imageFi + ") is null", module);
            return null;
        }

        byte[] imageBytes = imageFi.get();
        ByteWrapper byteWrap = new ByteWrapper(imageBytes);
        results.put("imageData", byteWrap);
        results.put("imageFileName", imageFi.getName());
     
        //Debug.logVerbose("in uploadAndStoreImage, results:" + results, "");
        return results;
View Full Code Here

    }


    public static ByteWrapper returnByteWrapper(Map map) {

        ByteWrapper byteWrap = (ByteWrapper)map.get("imageData");
        return byteWrap;
    }
View Full Code Here

        if (ServiceUtil.isError(results)) {
            request.setAttribute("_ERROR_MESSAGE_", ServiceUtil.getErrorMessage(results));
            return "error";
        }
       
        ByteWrapper outByteWrapper = (ByteWrapper)results.get("outByteWrapper");

        // setup content type
        String contentType = "application/pdf; charset=ISO-8859-1";

        ByteArrayInputStream bais = new ByteArrayInputStream(outByteWrapper.getBytes());
       
        /*
        try {
            FileOutputStream fos = new FileOutputStream("/home/byersa/pdftest.pdf");
            fos.write(outByteWrapper.getBytes());
        } catch(FileNotFoundException e) {
        } catch(IOException e) {
        }
        */
        try {
            UtilHttp.streamContentToBrowser(response, bais, outByteWrapper.getLength(), contentType);
        } catch(IOException e) {
            request.setAttribute("_ERROR_MESSAGE_", e.toString());
            return "error";
        }
        return responseStr;
View Full Code Here

        if (ServiceUtil.isError(results)) {
            request.setAttribute("_ERROR_MESSAGE_", ServiceUtil.getErrorMessage(results));
            return "error";
        }
       
        ByteWrapper outByteWrapper = (ByteWrapper)results.get("outByteWrapper");

        // setup content type
        String contentType = "application/pdf; charset=ISO-8859-1";

        ByteArrayInputStream bais = new ByteArrayInputStream(outByteWrapper.getBytes());
       
        /*
        try {
            FileOutputStream fos = new FileOutputStream("/home/byersa/pdftest.pdf");
            fos.write(outByteWrapper.getBytes());
            fos.close();
        } catch(FileNotFoundException e) {
        } catch(IOException e) {
        }
        */
        try {
            UtilHttp.streamContentToBrowser(response, bais, outByteWrapper.getLength(), contentType);
        } catch(IOException e) {
            request.setAttribute("_ERROR_MESSAGE_", e.toString());
            return "error";
        }
        return responseStr;
View Full Code Here

    }
   
    public static ByteWrapper getContentAsByteWrapper(GenericDelegator delegator, String dataResourceId, String https, String webSiteId, Locale locale, String rootDir) throws IOException, GeneralException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        streamDataResource(baos, delegator, dataResourceId, https, webSiteId, locale, rootDir);
        ByteWrapper byteWrapper = new ByteWrapper(baos.toByteArray());
        return byteWrapper;
    }
View Full Code Here

                    //dataResourceTypeId = "IMAGE_OBJECT";
                String dataResourceTypeId = "IMAGE_OBJECT";
                imgContext.put("dataResourceTypeId", dataResourceTypeId);
                imgContext.put("contentIdTo", ftlContentId);
                imgContext.put("contentAssocTypeId", "SUB_CONTENT");
                imgContext.put("imageData", new ByteWrapper(imageBytes));
                imgContext.put("mapKey", "IMAGE");
                imgContext.put("dataTemplateTypeId", "NONE");
                String rootDir = request.getSession().getServletContext().getRealPath("/");
                imgContext.put("rootDir", "rootDir");
                if (Debug.infoOn()) Debug.logInfo("[UploadContentAndImage]imgContext " + imgContext, module);
View Full Code Here

            }


            ftlContext.put("textData", passedParams.get("textData" + suffix));
            byte[] bytes = (byte[])passedParams.get("imageData" + suffix);
            ByteWrapper byteWrapper = new ByteWrapper(bytes);
            ftlContext.put("imageData", byteWrapper);
            if (Debug.infoOn()) Debug.logInfo("[UploadContentStuff]byteWrapper:" + byteWrapper, module);
            //contentAssocDataResourceViewFrom.setAllFields(ftlContext2, true, null, null);
            //ftlContext.putAll(ftlContext2);            
            if (Debug.infoOn()) Debug.logInfo("[UploadContentStuff]ftlContext:" + ftlContext, module);
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.