Search in sources :

Example 6 with CmsPlaceMetadata

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

the class PlaceController method check.

/**
 * @param id
 * @param returnUrl
 * @param request
 * @param session
 * @param response
 * @param model
 * @return view name
 */
@RequestMapping("check")
public String check(Long id, String returnUrl, HttpServletRequest request, HttpSession session, HttpServletResponse response, ModelMap model) {
    SysSite site = getSite(request);
    if (CommonUtils.empty(returnUrl)) {
        returnUrl = site.getDynamicPath();
    }
    CmsPlace entity = service.getEntity(id);
    SysUser user = getUserFromSession(session);
    String filePath = siteComponent.getWebTemplateFilePath(site, TemplateComponent.INCLUDE_DIRECTORY + entity.getPath());
    CmsPlaceMetadata metadata = metadataComponent.getPlaceMetadata(filePath);
    if (ControllerUtils.verifyCustom("manage", null == entity || null == user || CommonUtils.empty(metadata.getAdminIds()) || !ArrayUtils.contains(metadata.getAdminIds(), user.getId()), model) || ControllerUtils.verifyNotEquals("siteId", site.getId(), entity.getSiteId(), model)) {
        return REDIRECT + returnUrl;
    } else {
        service.check(id);
        logOperateService.save(new LogOperate(site.getId(), user.getId(), LogLoginService.CHANNEL_WEB, "check.place", RequestUtils.getIpAddress(request), CommonUtils.getDate(), id.toString()));
        return REDIRECT + returnUrl;
    }
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) CmsPlace(com.publiccms.entities.cms.CmsPlace) SysUser(com.publiccms.entities.sys.SysUser) CmsPlaceMetadata(com.publiccms.views.pojo.entities.CmsPlaceMetadata) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with CmsPlaceMetadata

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

the class MetadataComponent method getPlaceMetadataMap.

/**
 * 获取目录元数据
 *
 * @param dirPath
 * @return place metadata map
 */
public Map<String, CmsPlaceMetadata> getPlaceMetadataMap(String dirPath) {
    Map<String, CmsPlaceMetadata> metadataMap = placeCache.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, CmsPlaceMetadata>>() {
                });
            } catch (IOException | ClassCastException e) {
                metadataMap = new HashMap<>();
            }
        } else {
            metadataMap = new HashMap<>();
        }
        placeCache.put(dirPath, metadataMap);
    }
    return metadataMap;
}
Also used : HashMap(java.util.HashMap) CmsPlaceMetadata(com.publiccms.views.pojo.entities.CmsPlaceMetadata) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException) File(java.io.File)

Example 8 with CmsPlaceMetadata

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

the class PlaceController method delete.

/**
 * @param id
 * @param returnUrl
 * @param request
 * @param session
 * @param response
 * @param model
 * @return view name
 */
@RequestMapping("delete")
public String delete(Long id, String returnUrl, HttpServletRequest request, HttpSession session, HttpServletResponse response, ModelMap model) {
    SysSite site = getSite(request);
    if (CommonUtils.empty(returnUrl)) {
        returnUrl = site.getDynamicPath();
    }
    CmsPlace entity = service.getEntity(id);
    SysUser user = getUserFromSession(session);
    String filePath = siteComponent.getWebTemplateFilePath(site, TemplateComponent.INCLUDE_DIRECTORY + entity.getPath());
    CmsPlaceMetadata metadata = metadataComponent.getPlaceMetadata(filePath);
    if (ControllerUtils.verifyCustom("manage", null == entity || null == user || CommonUtils.empty(metadata.getAdminIds()) || !ArrayUtils.contains(metadata.getAdminIds(), user.getId()), model) || ControllerUtils.verifyNotEquals("siteId", site.getId(), entity.getSiteId(), model)) {
        return REDIRECT + returnUrl;
    } else {
        service.delete(id);
        logOperateService.save(new LogOperate(site.getId(), user.getId(), LogLoginService.CHANNEL_WEB, "delete.place", RequestUtils.getIpAddress(request), CommonUtils.getDate(), id.toString()));
        return REDIRECT + returnUrl;
    }
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) CmsPlace(com.publiccms.entities.cms.CmsPlace) SysUser(com.publiccms.entities.sys.SysUser) CmsPlaceMetadata(com.publiccms.views.pojo.entities.CmsPlaceMetadata) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with CmsPlaceMetadata

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

the class PlaceController method save.

/**
 * @param entity
 * @param returnUrl
 * @param placeParamters
 * @param request
 * @param session
 * @param response
 * @param model
 * @return view name
 */
@RequestMapping(value = "save")
public String save(CmsPlace entity, String returnUrl, @ModelAttribute CmsPlaceParamters placeParamters, HttpServletRequest request, HttpSession session, HttpServletResponse response, ModelMap model) {
    SysSite site = getSite(request);
    if (CommonUtils.empty(returnUrl)) {
        returnUrl = site.getDynamicPath();
    }
    if (null != entity && CommonUtils.notEmpty(entity.getPath())) {
        entity.setPath(entity.getPath().replace("//", SEPARATOR));
        String filePath = siteComponent.getWebTemplateFilePath(site, TemplateComponent.INCLUDE_DIRECTORY + entity.getPath());
        CmsPlaceMetadata metadata = metadataComponent.getPlaceMetadata(filePath);
        SysUser user = getUserFromSession(session);
        if (ControllerUtils.verifyCustom("contribute", null == metadata || !metadata.isAllowContribute() || 0 >= metadata.getSize() || (null == user && !metadata.isAllowAnonymous()), model)) {
            return REDIRECT + returnUrl;
        }
        if (null != entity.getId()) {
            CmsPlace oldEntity = service.getEntity(entity.getId());
            if (null == oldEntity || CommonUtils.empty(oldEntity.getUserId()) || null == user || ControllerUtils.verifyNotEquals("siteId", site.getId(), oldEntity.getSiteId(), model) || ControllerUtils.verifyNotEquals("siteId", user.getId(), oldEntity.getUserId(), model)) {
                return REDIRECT + returnUrl;
            }
            entity = service.update(entity.getId(), entity, ignoreProperties);
            logOperateService.save(new LogOperate(site.getId(), user.getId(), LogLoginService.CHANNEL_WEB, "update.place", RequestUtils.getIpAddress(request), CommonUtils.getDate(), entity.getPath()));
        } else {
            entity.setSiteId(site.getId());
            Long userId = null;
            if (null != user) {
                userId = user.getId();
                entity.setUserId(user.getId());
            }
            service.save(entity);
            logOperateService.save(new LogOperate(site.getId(), userId, LogLoginService.CHANNEL_WEB, "save.place", RequestUtils.getIpAddress(request), CommonUtils.getDate(), entity.getPath()));
        }
        Map<String, String> map = ExtendUtils.getExtentDataMap(placeParamters.getExtendDataList(), metadataComponent.getPlaceMetadata(filePath).getExtendList());
        String extentString = ExtendUtils.getExtendString(map);
        attributeService.updateAttribute(entity.getId(), extentString);
    }
    return REDIRECT + returnUrl;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) CmsPlace(com.publiccms.entities.cms.CmsPlace) SysUser(com.publiccms.entities.sys.SysUser) CmsPlaceMetadata(com.publiccms.views.pojo.entities.CmsPlaceMetadata) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with CmsPlaceMetadata

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

the class PublishPlaceDirective method execute.

@Override
public void execute(RenderHandler handler) throws IOException, Exception {
    String path = handler.getString("path", SEPARATOR);
    SysSite site = getSite(handler);
    if (site.isUseSsi()) {
        String fullPath = siteComponent.getWebTemplateFilePath(site, TemplateComponent.INCLUDE_DIRECTORY + SEPARATOR + path);
        File file = new File(fullPath);
        if (file.isFile()) {
            Map<String, Boolean> map = new LinkedHashMap<>();
            CmsPlaceMetadata metadata = metadataComponent.getPlaceMetadata(fullPath);
            try {
                if (null == metadata) {
                    metadata = new CmsPlaceMetadata();
                }
                templateComponent.staticPlace(site, path, metadata);
                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 : TemplateException(freemarker.template.TemplateException) CmsPlaceMetadata(com.publiccms.views.pojo.entities.CmsPlaceMetadata) IOException(java.io.IOException) File(java.io.File) SysSite(com.publiccms.entities.sys.SysSite) LinkedHashMap(java.util.LinkedHashMap)

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