Search in sources :

Example 1 with CmsPageMetadata

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

the class PublishPageDirective method execute.

@Override
public void execute(RenderHandler handler) throws IOException, Exception {
    String path = handler.getString("path", SEPARATOR);
    SysSite site = getSite(handler);
    String fullPath = siteComponent.getWebTemplateFilePath(site, path);
    File file = new File(fullPath);
    if (file.isFile()) {
        Map<String, Boolean> map = new LinkedHashMap<>();
        CmsPageMetadata metadata = metadataComponent.getTemplateMetadata(fullPath);
        if (CommonUtils.notEmpty(metadata.getPublishPath())) {
            try {
                templateComponent.createStaticFile(site, SiteComponent.getFullFileName(site, path), metadata.getPublishPath(), null, metadata, null);
                map.put(path, true);
            } catch (IOException | TemplateException e) {
                map.put(path, false);
            }
            handler.put("map", map).render();
        }
    } else if (file.isDirectory()) {
        handler.put("map", deal(site, path)).render();
    }
}
Also used : CmsPageMetadata(com.publiccms.views.pojo.entities.CmsPageMetadata) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException) File(java.io.File) SysSite(com.publiccms.entities.sys.SysSite) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with CmsPageMetadata

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

the class PublishPageDirective method deal.

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

Example 3 with CmsPageMetadata

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

the class MetadataComponent method updateTemplateMetadata.

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

Example 4 with CmsPageMetadata

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

the class MetadataComponent method getTemplateMetadataMap.

/**
 * 获取目录元数据
 *
 * @param dirPath
 * @return template metadata map
 */
public Map<String, CmsPageMetadata> getTemplateMetadataMap(String dirPath) {
    Map<String, CmsPageMetadata> metadataMap = pageCache.get(dirPath);
    if (null == metadataMap) {
        File file = new File(dirPath + SEPARATOR + METADATA_FILE);
        if (CommonUtils.notEmpty(file)) {
            try {
                metadataMap = objectMapper.readValue(file, new TypeReference<Map<String, CmsPageMetadata>>() {
                });
            } catch (IOException | ClassCastException e) {
                metadataMap = new HashMap<>();
            }
        } else {
            metadataMap = new HashMap<>();
        }
        pageCache.put(dirPath, metadataMap);
    }
    return metadataMap;
}
Also used : CmsPageMetadata(com.publiccms.views.pojo.entities.CmsPageMetadata) HashMap(java.util.HashMap) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException) File(java.io.File)

Example 5 with CmsPageMetadata

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

the class MetadataComponent method deleteTemplateMetadata.

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

Aggregations

CmsPageMetadata (com.publiccms.views.pojo.entities.CmsPageMetadata)12 IOException (java.io.IOException)9 SysSite (com.publiccms.entities.sys.SysSite)7 File (java.io.File)7 LogOperate (com.publiccms.entities.log.LogOperate)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 TemplateException (freemarker.template.TemplateException)4 LinkedHashMap (java.util.LinkedHashMap)2 MultipartFile (org.springframework.web.multipart.MultipartFile)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 SysDomain (com.publiccms.entities.sys.SysDomain)1 FileInfo (com.publiccms.logic.component.site.FileComponent.FileInfo)1 HashMap (java.util.HashMap)1