package com.ramostear.unaboot.service.impl;
import com.ramostear.unaboot.common.Constants;
import com.ramostear.unaboot.domain.entity.Theme;
import com.ramostear.unaboot.domain.vo.ThemeFolder;
import com.ramostear.unaboot.exception.BadRequestException;
import com.ramostear.unaboot.exception.NotFoundException;
import com.ramostear.unaboot.repository.ThemeRepository;
import com.ramostear.unaboot.service.ThemeService;
import com.ramostear.unaboot.util.DateTimeUtils;
import com.ramostear.unaboot.util.ThemeUtils;
import com.ramostear.unaboot.util.UnaBootUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/**
* @author : ramostear/树下魅狐
* @version : Una-Boot-1.3.0
* <p>This java file was created by ramostear in 2020/6/1 0001 18:44.
* The following is the description information about this file:</p>
* <p>description:</p>
*/
@Service("themeService")
public class ThemeServiceImpl extends BaseServiceImpl<Theme,Integer> implements ThemeService {
private final ThemeRepository themeRepository;
@Autowired
public ThemeServiceImpl(ThemeRepository themeRepository) {
super(themeRepository);
this.themeRepository = themeRepository;
}
@Override
@Transactional
public Theme upload(HttpServletRequest request, CommonsMultipartFile multipartFile) {
Theme theme = ThemeUtils.upload(request,multipartFile);
Assert.notNull(theme,"Failed to upload theme file.");
return themeRepository.save(theme);
}
@Deprecated
@Override
public List<ThemeFolder> loadAllFiles(String folder, boolean page) {
if(StringUtils.isBlank(folder)){
folder = "themes";
}
String fullName = Constants.UNABOOT_STORAGE_DIR+folder;
List<ThemeFolder> list = new ArrayList<>();
if(folder.equals("themes") && !page){
ThemeFolder root = new ThemeFolder();
root.setId("themes");
root.setPid("-1");
root.setName("主题列表");
root.setFolder(true);
list.add(root);
}
File targetFile = new File(fullName);
if(targetFile.exists() && !targetFile.isFile()){
File[] subFiles = targetFile.listFiles();
if(subFiles != null && subFiles.length>0){
for(File file : subFiles){
ThemeFolder subfolder = new ThemeFolder();
subfolder.setName(file.getName());
subfolder.setPid(folder);
subfolder.setId(folder+Constants.SEPARATOR+file.getName());
subfolder.setSize(UnaBootUtils.fileSize(file.length()));
subfolder.setModifyDate(new Date(file.lastModified()));
if(file.isDirectory()){
subfolder.setFolder(true);
}else{
subfolder.setFolder(false);
}
list.add(subfolder);
}
}
}
return list;
}
@Override
public List<ThemeFolder> findAllByParent(String parent) {
if(StringUtils.isBlank(parent)){
parent = "themes";
}
String fullName = Constants.UNABOOT_STORAGE_DIR+parent;
List<ThemeFolder> list = new ArrayList<>();
File targetFile = new File(fullName);
if(targetFile.exists()&& targetFile.isDirectory()){
File[] subFiles = targetFile.listFiles();
if(subFiles != null && subFiles.length > 0){
String pid = parent;
List<ThemeFolder> data = Arrays.stream(subFiles)
.map(item->{
ThemeFolder file = new ThemeFolder();
file.setName(item.getName());
file.setPid(pid);
String id = pid+Constants.SEPARATOR+item.getName();
file.setId(id.replace("\\","/"));
file.setFolder(item.isDirectory());
file.setSize(UnaBootUtils.fileSize(item.length()));
file.setModifyDate(new Date(item.lastModified()));
return file;
}).collect(Collectors.toList());
list.addAll(data);
}
}
return list;
}
@Override
public List<String> filter(String theme, String filter) {
String fullPath = Constants.UNABOOT_STORAGE_DIR+"themes"+Constants.SEPARATOR+theme;
File file = new File(fullPath);
if(!file.exists() || file.isFile()){
return Collections.emptyList();
}
File[] subFiles = file.listFiles();
if(subFiles != null && subFiles.length > 0){
return Arrays.stream(subFiles).filter(item->item.isFile() && item.getName().endsWith(filter))
.map(File::getName).collect(Collectors.toList());
}else{
return Collections.emptyList();
}
}
@Override
public ThemeFolder loadByUrl(String url) {
String fullPath = Constants.UNABOOT_STORAGE_DIR+url;
fullPath = fullPath.replace("\\","/");
File file = new File(fullPath);
if(!file.exists() || !file.isFile()){
throw new BadRequestException("文件不存在或文件格式不正确");
}
ThemeFolder themeFolder = new ThemeFolder();
themeFolder.setPid(url.substring(0,url.lastIndexOf("/")));
themeFolder.setId(url);
themeFolder.setName(file.getName());
themeFolder.setFolder(false);
themeFolder.setSize(UnaBootUtils.fileSize(file.length()));
themeFolder.setModifyDate(new Date(file.lastModified()));
return themeFolder;
}
@Override
public String read(String name) {
if(StringUtils.isBlank(name)){
return "";
}
String fullPath = Constants.UNABOOT_STORAGE_DIR+name;
File file = new File(fullPath);
if(!file.exists() || file.isDirectory()){
return "";
}
InputStreamReader reader = null;
BufferedReader bufferedReader = null;
StringBuilder builder = new StringBuilder();
String content;
try {
reader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);
bufferedReader = new BufferedReader(reader);
while ((content = bufferedReader.readLine()) != null){
builder.append(content).append("\n");
}
return builder.toString();
} catch (IOException e) {
e.printStackTrace();
return "";
}finally {
if(bufferedReader != null){
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(reader != null){
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
@Override
public boolean write(String name, String content) {
String fullPath = Constants.UNABOOT_STORAGE_DIR+name;
File file = new File(fullPath);
if(!file
没有合适的资源?快使用搜索试试~ 我知道了~
UnaBoot(尤娜)Java博客系统.zip
共1424个文件
js:555个
java:183个
html:153个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 46 浏览量
2022-11-16
02:21:12
上传
评论
收藏 17.82MB ZIP 举报
温馨提示
UnaBoot(尤娜)Java博客系统.zip
资源推荐
资源详情
资源评论
收起资源包目录
UnaBoot(尤娜)Java博客系统.zip (1424个子文件)
AUTHORS 6KB
mvnw.cmd 6KB
adminlte.css 734KB
adminlte.css 734KB
adminlte.min.css 638KB
adminlte.core.css 329KB
adminlte.core.css 329KB
adminlte.core.min.css 276KB
adminlte.core.min.css 276KB
adminlte.plugins.css 180KB
adminlte.plugins.css 180KB
adminlte.plugins.min.css 162KB
adminlte.plugins.min.css 162KB
adminlte.components.css 135KB
adminlte.components.css 135KB
adminlte.components.min.css 121KB
adminlte.components.min.css 121KB
material-design-iconic-font.css 83KB
material-design-iconic-font.css 83KB
editormd.css 76KB
material-design-iconic-font.min.css 69KB
material-design-iconic-font.min.css 69KB
all.css 69KB
fontawesome.css 67KB
editormd.min.css 60KB
ionicons.css 56KB
ionicons.css 56KB
all.min.css 56KB
editormd.preview.css 55KB
fontawesome.min.css 54KB
editormd.preview.min.css 44KB
v4-shims.css 40KB
font-awesome.css 37KB
font-awesome.css 37KB
v4-shims.min.css 26KB
ambiance.css 26KB
adminlte.extra-components.css 21KB
adminlte.extra-components.css 21KB
md-preview.css 20KB
adminlte.extra-components.min.css 17KB
adminlte.extra-components.min.css 17KB
layer.css 17KB
unaboot.css 14KB
bootstrap-datetimepicker.css 13KB
unaboot-install.css 13KB
awesome.css 8KB
codemirror.css 8KB
unaboot-admin.css 8KB
svg-with-js.css 8KB
styles.css 8KB
adminlte.pages.css 7KB
adminlte.pages.css 7KB
metroStyle.css 6KB
svg-with-js.min.css 6KB
adminlte.pages.min.css 6KB
adminlte.pages.min.css 6KB
zTreeStyle.css 6KB
codemirror.min.css 5KB
mdn-like.css 5KB
solarized.css 5KB
nouislider.min.css 4KB
merge.css 3KB
lint.css 3KB
xq-dark.css 3KB
lesser-dark.css 2KB
pastel-on-dark.css 2KB
xq-light.css 2KB
unaboot-login.css 2KB
tomorrow-night-eighties.css 2KB
editormd.logo.css 2KB
erlang-dark.css 2KB
zenburn.css 2KB
twilight.css 2KB
midnight.css 2KB
vibrant-ink.css 2KB
mbo.css 2KB
base16-dark.css 2KB
base16-light.css 2KB
tern.css 2KB
3024-night.css 2KB
paraiso-dark.css 2KB
paraiso-light.css 2KB
tomorrow-night-bright.css 2KB
3024-day.css 2KB
blackboard.css 2KB
colorforth.css 2KB
editormd.logo.min.css 2KB
the-matrix.css 2KB
unaboot-login.min.css 2KB
night.css 2KB
rubyblue.css 2KB
monokai.css 1KB
cobalt.css 1KB
simplescrollbars.css 1KB
bootstrap-tagsinput.css 1KB
eclipse.css 1KB
neo.css 932B
elegant.css 768B
regular.css 733B
solid.css 726B
共 1424 条
- 1
- 2
- 3
- 4
- 5
- 6
- 15
资源评论
毕业_设计
- 粉丝: 1936
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功