Search in sources :

Example 1 with CmsPlaceMetadata

use of com.publiccms.views.pojo.entities.CmsPlaceMetadata in project PublicCMS-preview by sanluan.

the class CmsTemplateAdminController method savePlace.

/**
 * @param path
 * @param content
 * @param request
 * @param session
 * @param model
 * @return view name
 */
@RequestMapping("savePlace")
public String savePlace(String path, String content, HttpServletRequest request, HttpSession session, ModelMap model) {
    SysSite site = getSite(request);
    if (CommonUtils.notEmpty(path)) {
        try {
            String filePath = siteComponent.getWebTemplateFilePath(site, TemplateComponent.INCLUDE_DIRECTORY + path);
            File templateFile = new File(filePath);
            if (CommonUtils.notEmpty(templateFile)) {
                fileComponent.updateFile(templateFile, content);
                logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "update.place.template", RequestUtils.getIpAddress(request), CommonUtils.getDate(), path));
            } else {
                fileComponent.createFile(templateFile, content);
                logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "save.place.template", RequestUtils.getIpAddress(request), CommonUtils.getDate(), path));
            }
            templateComponent.clearTemplateCache();
            if (site.isUseSsi()) {
                CmsPlaceMetadata metadata = metadataComponent.getPlaceMetadata(filePath);
                templateComponent.staticPlace(site, path, metadata);
            }
        } catch (IOException | TemplateException e) {
            model.addAttribute(ERROR, e.getMessage());
            log.error(e.getMessage(), e);
            return TEMPLATE_ERROR;
        }
    }
    return TEMPLATE_DONE;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) TemplateException(freemarker.template.TemplateException) CmsPlaceMetadata(com.publiccms.views.pojo.entities.CmsPlaceMetadata) IOException(java.io.IOException) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with CmsPlaceMetadata

use of com.publiccms.views.pojo.entities.CmsPlaceMetadata in project PublicCMS-preview by sanluan.

the class PublishPlaceDirective method deal.

private Map<String, Boolean> deal(SysSite site, String path) {
    path = path.replace("\\", SEPARATOR).replace("//", SEPARATOR);
    Map<String, Boolean> map = new LinkedHashMap<>();
    List<FileInfo> list = fileComponent.getFileList(siteComponent.getWebTemplateFilePath(site, TemplateComponent.INCLUDE_DIRECTORY + SEPARATOR + path));
    Map<String, CmsPlaceMetadata> metadataMap = metadataComponent.getPlaceMetadataMap(siteComponent.getWebTemplateFilePath(site, path));
    for (FileInfo fileInfo : list) {
        String filePath = path + fileInfo.getFileName();
        if (fileInfo.isDirectory()) {
            map.putAll(deal(site, filePath + SEPARATOR));
        } else {
            try {
                CmsPlaceMetadata metadata = metadataMap.get(fileInfo.getFileName());
                if (null == metadata) {
                    metadata = new CmsPlaceMetadata();
                }
                templateComponent.staticPlace(site, filePath, metadata);
                map.put(filePath, true);
            } catch (IOException | TemplateException e) {
                map.put(filePath, false);
            }
        }
    }
    return map;
}
Also used : FileInfo(com.publiccms.logic.component.site.FileComponent.FileInfo) TemplateException(freemarker.template.TemplateException) CmsPlaceMetadata(com.publiccms.views.pojo.entities.CmsPlaceMetadata) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with CmsPlaceMetadata

use of com.publiccms.views.pojo.entities.CmsPlaceMetadata in project PublicCMS-preview by sanluan.

the class MetadataComponent method updatePlaceMetadata.

/**
 * 更新推荐位元数据
 *
 * @param filePath
 * @param metadata
 * @return whether the update is successful
 */
public boolean updatePlaceMetadata(String filePath, CmsPlaceMetadata metadata) {
    File file = new File(filePath);
    String dirPath = file.getParent();
    Map<String, CmsPlaceMetadata> metadataMap = getPlaceMetadataMap(dirPath);
    metadataMap.put(file.getName(), metadata);
    try {
        savePlaceMetadata(dirPath, metadataMap);
        return true;
    } catch (IOException e) {
        return false;
    }
}
Also used : CmsPlaceMetadata(com.publiccms.views.pojo.entities.CmsPlaceMetadata) IOException(java.io.IOException) File(java.io.File)

Example 4 with CmsPlaceMetadata

use of com.publiccms.views.pojo.entities.CmsPlaceMetadata in project PublicCMS-preview by sanluan.

the class MetadataComponent method getPlaceMetadata.

/**
 * 获取推荐位元数据
 *
 * @param filePath
 * @return place metadata
 */
public CmsPlaceMetadata getPlaceMetadata(String filePath) {
    File file = new File(filePath);
    CmsPlaceMetadata pageMetadata = getPlaceMetadataMap(file.getParent()).get(file.getName());
    if (null != pageMetadata) {
        return pageMetadata;
    }
    return new CmsPlaceMetadata();
}
Also used : CmsPlaceMetadata(com.publiccms.views.pojo.entities.CmsPlaceMetadata) File(java.io.File)

Example 5 with CmsPlaceMetadata

use of com.publiccms.views.pojo.entities.CmsPlaceMetadata in project PublicCMS-preview by sanluan.

the class MetadataComponent method deletePlaceMetadata.

/**
 * 删除推荐位元数据
 *
 * @param filePath
 * @return whether the delete is successful
 */
public boolean deletePlaceMetadata(String filePath) {
    File file = new File(filePath);
    String dirPath = file.getParent();
    Map<String, CmsPlaceMetadata> metadataMap = getPlaceMetadataMap(dirPath);
    metadataMap.remove(file.getName());
    try {
        savePlaceMetadata(dirPath, metadataMap);
        return true;
    } catch (IOException e) {
        return false;
    }
}
Also used : CmsPlaceMetadata(com.publiccms.views.pojo.entities.CmsPlaceMetadata) IOException(java.io.IOException) File(java.io.File)

Aggregations

CmsPlaceMetadata (com.publiccms.views.pojo.entities.CmsPlaceMetadata)12 SysSite (com.publiccms.entities.sys.SysSite)7 IOException (java.io.IOException)7 File (java.io.File)6 LogOperate (com.publiccms.entities.log.LogOperate)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 TemplateException (freemarker.template.TemplateException)4 CmsPlace (com.publiccms.entities.cms.CmsPlace)3 SysUser (com.publiccms.entities.sys.SysUser)3 LinkedHashMap (java.util.LinkedHashMap)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 FileInfo (com.publiccms.logic.component.site.FileComponent.FileInfo)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 MultipartFile (org.springframework.web.multipart.MultipartFile)1