com.bsb.cms.content.service.utils.PublishUtil.java Source code

Java tutorial

Introduction

Here is the source code for com.bsb.cms.content.service.utils.PublishUtil.java

Source

/**
 * @(#)PublishUtil.java 2014-7-8
 *
 * Copyright (c) 2014-2015 BuShangBan (China) Int'l Co., Ltd
 * yongtai Road. pu dong District.Shanghai China
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of BuShangBan (China)
 *  Int'l Co., Ltd ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with BuShangBan (China).
 */
package com.bsb.cms.content.service.utils;

import java.util.Calendar;

import org.apache.commons.lang.StringUtils;

import com.bsb.cms.commons.utils.ConfigUtils;
import com.bsb.cms.commons.utils.CustomPropertyConfigurer;
import com.bsb.cms.commons.web.SpringContextUtil;
import com.bsb.cms.model.dto.content.ContContentDTO;
import com.bsb.cms.model.dto.content.ContTypeDTO;
import com.bsb.cms.model.dto.content.TmptTemplateDTO;
import com.bsb.cms.model.po.content.ContContent;
import com.bsb.cms.model.po.content.ContContentBody;

/**
 * @author hongjian.liu
 * @version 1.0.0 2014-7-8
 * @since 1.0
 */
public class PublishUtil {
    /**
     * ???. ?.
     * 
     * @param template
     * @return
     */
    public static String getTemplatePath(TmptTemplateDTO template) {
        String templatePath;
        templatePath = template.getParent_id() + "/" + template.getId() + ".ftl";

        return templatePath;
    }

    /**
     * ??
     * 
     * @param template
     */
    public static String getCreateTemplateDir(Long parentId, String fileDir) {
        String rootDir = CustomPropertyConfigurer.getProperty("cms.template.path");
        return rootDir + "\\" + parentId + "\\";
        //return URLUtils.getTemplatePath() + parentId + "/";
    }

    public static String getPublishDir(ContTypeDTO type) {
        String dir;
        if (StringUtils.isBlank(type.getFile_dir())) {
            dir = String.valueOf(type.getId());
        } else {
            dir = type.getFile_dir();
        }
        ConfigUtils config = (ConfigUtils) SpringContextUtil.getApplicationContextInstance().getBean("configUtils",
                ConfigUtils.class);
        return config.getRootPath() + dir + "/";
    }

    public static String getCtPublishPath(String contentPath) {
        ConfigUtils config = (ConfigUtils) SpringContextUtil.getApplicationContextInstance().getBean("configUtils",
                ConfigUtils.class);
        return config.getRootPath() + contentPath;
    }

    public static String getCtURL(String contentId) {
        Calendar date = Calendar.getInstance();
        int month = date.get(Calendar.MONTH) + 1;

        if (StringUtils.isNotBlank(contentId)) {
            return "/" + date.get(Calendar.YEAR) + "/" + (month < 10 ? ("0" + month) : month) + "/" + contentId
                    + ".html";
        } else {
            return "/" + date.get(Calendar.YEAR) + "/" + (month < 10 ? ("0" + month) : month) + "/";
        }

    }

    public static ContContentDTO translateContent(ContContent content, ContContentBody contContentBody) {
        ContContentDTO c = new ContContentDTO();
        c.setAbout(content.getAbout());
        c.setAttr_id(content.getAttrId());
        if (contContentBody != null) {
            c.setContent_body(contContentBody.getContentBody());
        }
        c.setContent_id(content.getId());
        c.setDefault_img(content.getDefaultImg());
        c.setDiscount(content.getDiscount());
        c.setBrand(content.getBrand());
        if (contContentBody != null) {
            c.setExt_attr(contContentBody.getExtAttrBody());
        }
        c.setGoods_url(content.getGoodsUrl());
        c.setHas_hot(content.getHasHot());
        c.setHas_latest(content.getHasLatest());
        c.setHas_top(content.getHasTop());
        c.setKeyword(content.getKeyword());
        c.setLink(content.getLink());
        c.setMeta_description(content.getMetaDescription());
        c.setMeta_keywords(content.getMetaKeywords());
        c.setMeta_title(content.getMetaTitle());
        c.setPrice(content.getPrice());
        c.setPublish_time(content.getPublishTime());
        c.setSalePrice(content.getSalePrice());
        c.setSource(content.getSource());
        c.setStock(content.getStock());
        c.setTemplate_id(content.getTemplateId());
        c.setTitle(content.getTitle());
        c.setTitle_style(content.getTitleStyle());
        c.setType_id(content.getTypeId());
        c.setUrl(content.getContentUrl());

        return c;
    }

    /*   
       public static String getTypeListTemplateView(ContTypeDTO type){
              
       }*/
}