⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 editproductcontent.bsh

📁 国外的一套开源CRM
💻 BSH
字号:
/*
 *  Copyright (c) 2003 The Open For Business Project - www.ofbiz.org
 *
 *  Permission is hereby granted, free of charge, to any person obtaining a 
 *  copy of this software and associated documentation files (the "Software"), 
 *  to deal in the Software without restriction, including without limitation 
 *  the rights to use, copy, modify, merge, publish, distribute, sublicense, 
 *  and/or sell copies of the Software, and to permit persons to whom the 
 *  Software is furnished to do so, subject to the following conditions:
 *
 *  The above copyright notice and this permission notice shall be included 
 *  in all copies or substantial portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
 *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
 *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
 *  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 
 *  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT 
 *  OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR 
 *  THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 *@author     David E. Jones
 *@author     Brad Steiner
 *@version    $Revision: 1.7 $
 *@since      2.2
 */

import java.util.*;
import java.sql.*;
import java.io.*;
import org.ofbiz.entity.*;
import org.ofbiz.base.util.*;
import org.ofbiz.content.widget.html.*;

security = request.getAttribute("security");
delegator = request.getAttribute("delegator");

if(security.hasEntityPermission("CATALOG", "_VIEW", session)) {
    context.put("hasPermission", Boolean.TRUE);
} else {
    context.put("hasPermission", Boolean.FALSE);
}    
nowTimestamp = UtilDateTime.nowTimestamp();
context.put("nowTimestamp", nowTimestamp);

String nowTimestampString = nowTimestamp.toString();
context.put("nowTimestampString", nowTimestampString);

URL catalogPropertiesURL = application.getResource("/WEB-INF/catalog.properties");
if (catalogPropertiesURL != null) context.put("catalogPropertiesURL", catalogPropertiesURL.toString());

String productId = request.getParameter("productId");
context.put("productId", productId);

GenericValue product = delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", productId));
context.put("product", product);

// Start ProductContent stuff
productContent = null;
if (product != null) productContent = product.getRelated("ProductContent", null, UtilMisc.toList("productContentId"));
context.put("productContent", productContent);

List productContentDatas = new LinkedList();
Iterator productContentIter = productContent.iterator();
while (productContentIter.hasNext()) {
    GenericValue productContent = (GenericValue) productContentIter.next();
    GenericValue content = productContent.getRelatedOne("Content");
    productContentDatas.add(UtilMisc.toMap("productContent", productContent, "content", content));
}

HtmlFormWrapper updateProductContentWrapper = new HtmlFormWrapper("/product/ProductForms.xml", "UpdateProductContentAssoc", request, response);
context.put("updateProductContentWrapper", updateProductContentWrapper);
updateProductContentWrapper.putInContext("productContentDatas", productContentDatas);

HtmlFormWrapper prepareAddProductContentWrapper = new HtmlFormWrapper("/product/ProductForms.xml", "PrepareAddProductContentAssoc", request, response);
context.put("prepareAddProductContentWrapper", prepareAddProductContentWrapper);
prepareAddProductContentWrapper.putInContext("product", product);

HtmlFormWrapper addProductContentWrapper = new HtmlFormWrapper("/product/ProductForms.xml", "AddProductContentAssoc", request, response);
context.put("addProductContentWrapper", addProductContentWrapper);
addProductContentWrapper.putInContext("product", product);

context.put("productContentList", productContentDatas);
// End ProductContent stuff

boolean tryEntity = true;
if (request.getAttribute("_ERROR_MESSAGE_") != null) tryEntity = false;
if (product == null) tryEntity = false;
if("true".equalsIgnoreCase((String) request.getParameter("tryEntity"))) tryEntity = true;
context.put("tryEntity", tryEntity);

// UPLOADING STUFF

Object forLock = new Object();
String contentType = null;
String fileType = request.getParameter("upload_file_type");
if (fileType != null) {
    context.put("fileType", fileType);

    String fileNameToUse = "product." + productId + "." + fileType;
    
    int i1;
    if (contentType != null && (i1 = contentType.indexOf("boundary=")) != -1) {
        contentType = contentType.substring(i1 + 9);
        contentType = "--" + contentType;
    }
        
    String imageServerPath = UtilProperties.getPropertyValue(catalogPropertiesURL, "image.server.path");
    context.put("imageServerPath", imageServerPath);
    String imageUrlPrefix = UtilProperties.getPropertyValue(catalogPropertiesURL, "image.url.prefix");
    context.put("imageUrlPrefix", imageUrlPrefix);

    String defaultFileName = productId;
    HttpRequestFileUpload uploadObject = new HttpRequestFileUpload();
    uploadObject.setOverrideFilename(defaultFileName);
    uploadObject.setSavePath(imageServerPath + System.getProperty("file.separator"));
    uploadObject.doUpload(request);
    
    String clientFileName = uploadObject.getFilename();
    if (clientFileName != null) context.put("clientFileName", clientFileName);
    
    if (clientFileName != null && clientFileName.length() > 0) {
        if (clientFileName.lastIndexOf(".") > 0 && clientFileName.lastIndexOf(".") < clientFileName.length()) {
            fileNameToUse += clientFileName.substring(clientFileName.lastIndexOf("."));
        } else {
            fileNameToUse += ".jpg";
        }
    
        context.put("clientFileName", clientFileName);        
        context.put("fileNameToUse", fileNameToUse);
        
        String characterEncoding = request.getCharacterEncoding();
        String imageUrl = imageUrlPrefix + "/" + java.net.URLEncoder.encode(fileNameToUse, characterEncoding);
        
        try {
            File file = new File(imageServerPath, defaultFileName);
            File file1 = new File(imageServerPath, fileNameToUse);
            try {
                file1.delete();
            } catch(Exception e) { 
                System.out.println("error deleting existing file (not neccessarily a problem)");
            }
            file.renameTo(file1);
        } catch(Exception e) { 
            e.printStackTrace();
        }
    
        if (imageUrl != null && imageUrl.length() > 0) {
            context.put("imageUrl", imageUrl);
            product.set(fileType + "ImageUrl", imageUrl);
            product.store();
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -