use of com.publiccms.views.pojo.entities.CmsPageMetadata in project PublicCMS-preview by sanluan.
the class MetadataComponent method getTemplateMetadata.
/**
* 获取模板元数据
*
* @param filePath
* @return template metadata
*/
public CmsPageMetadata getTemplateMetadata(String filePath) {
File file = new File(filePath);
CmsPageMetadata pageMetadata = getTemplateMetadataMap(file.getParent()).get(file.getName());
if (null == pageMetadata) {
pageMetadata = new CmsPageMetadata();
pageMetadata.setUseDynamic(true);
}
return pageMetadata;
}
use of com.publiccms.views.pojo.entities.CmsPageMetadata in project PublicCMS-preview by sanluan.
the class IndexController method getViewName.
private String getViewName(Long id, Integer pageIndex, String requestPath, String body, HttpServletRequest request, HttpServletResponse response, ModelMap model) {
SysDomain domain = getDomain(request);
SysSite site = getSite(request);
String fullRequestPath = siteComponent.getViewNamePrefix(site, domain) + requestPath;
String templatePath = siteComponent.getWebTemplateFilePath() + fullRequestPath;
CmsPageMetadata metadata = metadataComponent.getTemplateMetadata(templatePath);
if (metadata.isUseDynamic()) {
if (metadata.isNeedLogin() && null == getUserFromSession(request.getSession())) {
Map<String, String> config = configComponent.getConfigData(site.getId(), Config.CONFIG_CODE_SITE);
String loginPath = config.get(LoginConfigComponent.CONFIG_LOGIN_PATH);
StringBuilder sb = new StringBuilder(REDIRECT);
if (CommonUtils.notEmpty(loginPath)) {
return sb.append(loginPath).append("?returnUrl=").append(RequestUtils.getEncodePath(requestPath, request.getQueryString())).toString();
} else {
return sb.append(site.getDynamicPath()).toString();
}
}
String[] acceptParamters = StringUtils.split(metadata.getAcceptParamters(), COMMA_DELIMITED);
if (CommonUtils.notEmpty(acceptParamters)) {
billingRequestParamtersToModel(request, acceptParamters, model);
if (null != id && ArrayUtils.contains(acceptParamters, "id")) {
model.addAttribute("id", id.toString());
if (null != pageIndex && ArrayUtils.contains(acceptParamters, "pageIndex")) {
model.addAttribute("pageIndex", pageIndex.toString());
}
}
}
model.addAttribute("metadata", metadata);
if (metadata.isNeedBody()) {
model.addAttribute("body", body);
}
if (CommonUtils.notEmpty(metadata.getContentType())) {
response.setContentType(metadata.getContentType());
}
if (CommonUtils.notEmpty(metadata.getCacheTime()) && 0 < metadata.getCacheTime()) {
int cacheMillisTime = metadata.getCacheTime() * 1000;
String cacheControl = request.getHeader("Cache-Control");
String pragma = request.getHeader("Pragma");
if (CommonUtils.notEmpty(cacheControl) && "no-cache".equalsIgnoreCase(cacheControl) || CommonUtils.notEmpty(pragma) && "no-cache".equalsIgnoreCase(pragma)) {
cacheMillisTime = 0;
}
return templateCacheComponent.getCachedPath(requestPath, fullRequestPath, cacheMillisTime, acceptParamters, request, model);
}
} else {
try {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
} catch (IOException e) {
}
}
return requestPath;
}
use of com.publiccms.views.pojo.entities.CmsPageMetadata in project PublicCMS-preview by sanluan.
the class CmsPageAdminController method saveMetadata.
/**
* @param path
* @param placeParamters
* @param request
* @param session
* @param model
* @return view name
*/
@RequestMapping("save")
public String saveMetadata(String path, @ModelAttribute CmsPlaceParamters placeParamters, HttpServletRequest request, HttpSession session, ModelMap model) {
if (CommonUtils.notEmpty(path)) {
SysSite site = getSite(request);
String filePath = siteComponent.getWebTemplateFilePath(site, path);
CmsPageMetadata oldmetadata = metadataComponent.getTemplateMetadata(filePath);
oldmetadata.setExtendDataList(placeParamters.getExtendDataList());
metadataComponent.updateTemplateMetadata(filePath, oldmetadata);
logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "update.template.data", RequestUtils.getIpAddress(request), CommonUtils.getDate(), path));
}
return TEMPLATE_DONE;
}
use of com.publiccms.views.pojo.entities.CmsPageMetadata in project PublicCMS-preview by sanluan.
the class CmsTemplateAdminController method upload.
/**
* @param file
* @param path
* @param request
* @param session
* @param model
* @return view name
*/
@RequestMapping("doUpload")
public String upload(MultipartFile file, String path, HttpServletRequest request, HttpSession session, ModelMap model) {
if (null != file && !file.isEmpty()) {
try {
SysSite site = getSite(request);
path = path + SEPARATOR + file.getOriginalFilename();
fileComponent.upload(file, siteComponent.getWebTemplateFilePath(site, path));
CmsPageMetadata metadata = new CmsPageMetadata();
metadata.setUseDynamic(true);
metadataComponent.updateTemplateMetadata(path, metadata);
templateComponent.clearTemplateCache();
cacheComponent.clearViewCache();
logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "upload.web.template", RequestUtils.getIpAddress(request), CommonUtils.getDate(), path));
} catch (IOException e) {
model.addAttribute(ERROR, e.getMessage());
log.error(e.getMessage(), e);
return TEMPLATE_ERROR;
}
}
return TEMPLATE_DONE;
}
use of com.publiccms.views.pojo.entities.CmsPageMetadata in project PublicCMS-preview by sanluan.
the class CmsTemplateAdminController method save.
/**
* @param path
* @param content
* @param request
* @param session
* @param model
* @return view name
*/
@RequestMapping("save")
public String save(String path, String content, HttpServletRequest request, HttpSession session, ModelMap model) {
SysSite site = getSite(request);
if (CommonUtils.notEmpty(path)) {
try {
String filePath = siteComponent.getWebTemplateFilePath(site, path);
File templateFile = new File(filePath);
CmsPageMetadata metadata = metadataComponent.getTemplateMetadata(filePath);
if (CommonUtils.notEmpty(templateFile)) {
fileComponent.updateFile(templateFile, content);
if (CommonUtils.notEmpty(metadata.getCacheTime()) && metadata.getCacheTime() > 0) {
templateCacheComponent.deleteCachedFile(SiteComponent.getFullFileName(site, path));
}
logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "update.web.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.web.template", RequestUtils.getIpAddress(request), CommonUtils.getDate(), path));
}
templateComponent.clearTemplateCache();
cacheComponent.clearViewCache();
if (CommonUtils.notEmpty(metadata.getPublishPath())) {
publish(site, path);
}
} catch (IOException | TemplateException e) {
model.addAttribute(ERROR, e.getMessage());
log.error(e.getMessage(), e);
return TEMPLATE_ERROR;
}
}
return TEMPLATE_DONE;
}
Aggregations