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();
}
}
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;
}
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;
}
}
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;
}
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;
}
}
Aggregations