Skip to content

Commit 516fcd4

Browse files
committed
添加Video项目。
1 parent caeec58 commit 516fcd4

26 files changed

+749
-14
lines changed

.classpath

+4
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@
158158
<classpathentry kind="lib" path="C:/Program Files/Java/jdk1.8.0_31/lib/jconsole.jar"/>
159159
<classpathentry kind="lib" path="C:/Program Files/Java/jdk1.8.0_31/lib/tools.jar"/>
160160
<classpathentry kind="lib" path="src/main/resources/lib/ocr_sdk-1.3.6.jar"/>
161+
<classpathentry kind="lib" path="C:/Program Files/Java/jdk1.8.0_31/lib/jconsole.jar"/>
162+
<classpathentry kind="lib" path="C:/Program Files/Java/jdk1.8.0_31/lib/tools.jar"/>
161163
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/Maven: org.springframework.boot:spring-boot-starter-web:1.5.1.RELEASE"/>
162164
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/Maven: org.springframework.boot:spring-boot-starter:1.5.1.RELEASE"/>
163165
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/Maven: org.springframework.boot:spring-boot-starter-logging:1.5.1.RELEASE"/>
@@ -284,6 +286,8 @@
284286
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/Maven: javax.transaction:jta:1.1"/>
285287
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/Maven: org.quartz-scheduler:quartz:2.2.2"/>
286288
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/Maven: c3p0:c3p0:0.9.1.1"/>
289+
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/Maven: org.dom4j:dom4j:2.1.0"/>
290+
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/Maven: jaxen:jaxen:1.1.6"/>
287291
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/Maven: com.sun.mail:javax.mail:1.5.6"/>
288292
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/Maven: javax.activation:activation:1.1"/>
289293
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/Maven: com.itextpdf.tool:xmlworker:5.5.11"/>

SpringBootWiki.eml

+2
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@
208208
<level name="Maven: javax.transaction:jta:1.1" value="project"/>
209209
<level name="Maven: org.quartz-scheduler:quartz:2.2.2" value="project"/>
210210
<level name="Maven: c3p0:c3p0:0.9.1.1" value="project"/>
211+
<level name="Maven: org.dom4j:dom4j:2.1.0" value="project"/>
212+
<level name="Maven: jaxen:jaxen:1.1.6" value="project"/>
211213
<level name="Maven: com.sun.mail:javax.mail:1.5.6" value="project"/>
212214
<level name="Maven: javax.activation:activation:1.1" value="project"/>
213215
<level name="Maven: com.itextpdf.tool:xmlworker:5.5.11" value="project"/>

pom.xml

+9
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,15 @@
376376
<artifactId>quartz</artifactId>
377377
<version>2.2.2</version>
378378
</dependency>
379+
380+
<!-- https://mvnrepository.com/artifact/org.dom4j/dom4j -->
381+
<!--xml-->
382+
<dependency>
383+
<groupId>org.dom4j</groupId>
384+
<artifactId>dom4j</artifactId>
385+
<version>2.1.0</version>
386+
</dependency>
387+
379388
<!--邮件-->
380389
<dependency>
381390
<groupId>com.sun.mail</groupId>

src/main/java/net/liuxuan/SprKi/controller/CommonController.java

+2
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ public void getFile2(HttpServletRequest request, HttpServletResponse response, M
160160

161161
}
162162

163+
164+
163165
/**
164166
* 为所有的用户加上头像
165167
*

src/main/java/net/liuxuan/SprKi/controller/utils/FileUploadUtil.java

+54-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828
public class FileUploadUtil {
2929
private static Logger log = LoggerFactory.getLogger(FileUploadUtil.class);
3030

31+
/**
32+
* 上传文件处理
33+
* @param request request 对象
34+
* @param filePath 文件路径
35+
* @param filePathUrl 文件URL访问地址
36+
* @return 列表 内容为URL访问地址
37+
* @throws FileNotFoundException
38+
*/
3139
public static List<String> uploadFile(HttpServletRequest request, String filePath, String filePathUrl) throws FileNotFoundException {
3240
List<String> filePathList = new ArrayList<String>();
3341

@@ -42,8 +50,6 @@ public static List<String> uploadFile(HttpServletRequest request, String filePat
4250
String newfilepath;
4351
newfilepath = filePath + File.separatorChar + fileName;
4452

45-
46-
System.out.println("newfilepath=" + newfilepath);
4753
File dest = new File(filePath);
4854
if (!dest.exists()) {
4955
dest.mkdirs();
@@ -57,14 +63,58 @@ public static List<String> uploadFile(HttpServletRequest request, String filePat
5763
log.info("start upload file: " + fileName);
5864
FileCopyUtils.copy(mf.getBytes(), uploadFile);
5965
} catch (IOException e) {
60-
// TODO Auto-generated catch block
6166
// e.printStackTrace();
62-
log.info("upload failed. filename: " + fileName + e.getMessage());
67+
log.error("upload failed. filename: " + fileName + e.getMessage());
6368
return null;
6469
}
6570
filePathList.add(filePathUrl+"/"+fileName);
6671
}
6772

6873
return filePathList;
6974
}
75+
76+
/**
77+
* 上传非URL直接访问的文件处理
78+
* @param request request 对象
79+
* @param filePath 文件路径
80+
* @return 列表 内容为URL访问地址
81+
* @throws FileNotFoundException
82+
*/
83+
public static List<String> uploadRestricedFile(HttpServletRequest request, String filePath) throws FileNotFoundException {
84+
List<String> filePathList = new ArrayList<String>();
85+
86+
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
87+
88+
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
89+
String fileName = null;
90+
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
91+
92+
MultipartFile mf = entity.getValue();
93+
fileName = mf.getOriginalFilename();
94+
String newfilepath;
95+
newfilepath = filePath + File.separatorChar + fileName;
96+
97+
//check directory exists
98+
File dest = new File(filePath);
99+
if (!dest.exists()) {
100+
dest.mkdirs();
101+
}
102+
//overwrite dest file
103+
File uploadFile = new File(newfilepath);
104+
if (uploadFile.exists()) {
105+
uploadFile.delete();
106+
}
107+
try {
108+
log.info("start upload file: " + fileName);
109+
FileCopyUtils.copy(mf.getBytes(), uploadFile);
110+
} catch (IOException e) {
111+
log.error("upload failed. filename: " + fileName + e.getMessage());
112+
return null;
113+
}
114+
filePathList.add(newfilepath);
115+
}
116+
117+
return filePathList;
118+
}
119+
70120
}

src/main/java/net/liuxuan/SprKi/controller/utils/UploadFileController.java

+32
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ public class UploadFileController {
5858
@Value("${SprKi.upload.accesspath}")
5959
private String picAccessPath;
6060

61+
@Value("${SprKi.upload.videoPath}")
62+
private String videoPath;
63+
6164
@Autowired
6265
private ObjectMapper objectMapper;
6366
/**
@@ -222,4 +225,33 @@ public void uploadFile(HttpServletRequest request, HttpServletResponse response)
222225
ResponseHelper.writeObjectToResponseAsJson(response,filePathList);
223226
}
224227

228+
/**
229+
* Uploadifive 对应的
230+
*
231+
* @param request
232+
* @return
233+
*/
234+
@RequestMapping(value = "/uploadVideos",method = RequestMethod.POST)
235+
@ResponseBody
236+
public void uploadVideos(HttpServletRequest request, HttpServletResponse response) throws IOException {
237+
238+
Calendar calendar = Calendar.getInstance();
239+
List<String> filePathList =null;
240+
String filePath = videoPath + "/";
241+
String filePathUrl = picAccessPath + calendar.get(Calendar.YEAR) + calendar.get(Calendar.MONTH);
242+
filePath = filePath + File.separatorChar + calendar.get(Calendar.YEAR) + calendar.get(Calendar.MONTH);
243+
try {
244+
filePathList = FileUploadUtil.uploadRestricedFile(request, filePath);
245+
} catch (FileNotFoundException e) {
246+
e.printStackTrace();
247+
} catch (Exception ex) {
248+
ex.printStackTrace();
249+
}
250+
251+
if (filePathList==null||filePathList.size() == 0) {
252+
//return "系统错误";
253+
}
254+
ResponseHelper.writeObjectToResponseAsJson(response,filePathList);
255+
}
256+
225257
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
package net.liuxuan.SprKi.controller.videos;
2+
3+
import net.liuxuan.SprKi.entity.CMSVideo;
4+
import net.liuxuan.SprKi.service.CMSVideoService;
5+
import net.liuxuan.spring.Helper.SystemHelper;
6+
import org.dom4j.Document;
7+
import org.dom4j.DocumentException;
8+
import org.dom4j.DocumentHelper;
9+
import org.slf4j.Logger;
10+
import org.slf4j.LoggerFactory;
11+
import org.springframework.beans.factory.annotation.Autowired;
12+
import org.springframework.security.access.prepost.PreAuthorize;
13+
import org.springframework.stereotype.Controller;
14+
import org.springframework.util.FileCopyUtils;
15+
import org.springframework.web.bind.annotation.PathVariable;
16+
import org.springframework.web.bind.annotation.RequestMapping;
17+
import org.springframework.web.bind.annotation.RequestMethod;
18+
import org.springframework.web.bind.annotation.ResponseBody;
19+
20+
import javax.servlet.ServletOutputStream;
21+
import javax.servlet.http.HttpServletRequest;
22+
import javax.servlet.http.HttpServletResponse;
23+
import java.io.*;
24+
import java.net.URLConnection;
25+
import java.nio.charset.Charset;
26+
import java.util.List;
27+
import java.util.Map;
28+
29+
/**
30+
* Copyright (c) 2010-2016. by Liuxuan All rights reserved. <br/>
31+
* ***************************************************************************
32+
* 源文件名: net.liuxuan.SprKi.controller.ticket.TicketController
33+
* 功能:
34+
* 版本: @version 1.0
35+
* 编制日期: 2017/9/30 11:27
36+
* 修改历史: (主要历史变动原因及说明)
37+
* YYYY-MM-DD | Author | Change Description
38+
* 2017/9/30 | Moses | Created
39+
*/
40+
@Controller
41+
@PreAuthorize("hasRole('ROLE_USER')")
42+
public class VideoController {
43+
private static Logger log = LoggerFactory.getLogger(VideoController.class);
44+
45+
@Autowired
46+
CMSVideoService cmsVideoService;
47+
48+
49+
@RequestMapping(value = "/video/list", method = RequestMethod.GET)
50+
public String getVideoList(HttpServletRequest request, HttpServletResponse response, Map<String, Object> model) {
51+
List<CMSVideo> allContents = cmsVideoService.getAllCMSVideo();
52+
log.info("video list size is {}", allContents.size());
53+
model.put("alllist", allContents);
54+
return "video/video_list";
55+
}
56+
57+
@RequestMapping(value = "/video/{id}", method = RequestMethod.GET)
58+
public String getVideoById(@PathVariable Long id, HttpServletRequest request, HttpServletResponse response, Map<String, Object> model) {
59+
60+
CMSVideo content = cmsVideoService.findCMSVideoById(id);
61+
model.put("content", content);
62+
return "video/video_show";
63+
64+
}
65+
66+
@RequestMapping(value = "/video/videoxml/{id}", method = RequestMethod.GET)
67+
public @ResponseBody
68+
String getVideoXml(@PathVariable Long id, HttpServletRequest request, HttpServletResponse response) {
69+
70+
String originxml =
71+
"<vcastr>" +
72+
//channel
73+
"<channel> <item>" +
74+
"<source>http://vcastr.ruochi.com/video/happy_feet.flv</source>" +
75+
"<duration></duration>" + //对应影片的总时间, 单位是秒,由于有些影片在制作过程中时间信息丢失,可以通过这里来设置
76+
"<title></title>" + //对应影片的标题
77+
"</item> </channel>" +
78+
//config
79+
"<config>" +
80+
"<bufferTime>4</bufferTime>" + //在缓存区影片的时间,单位是秒
81+
"<contralPanelAlpha>0.75</contralPanelAlpha>" + //控制栏的透明度,在 0 — 1 之间
82+
"<controlPanelBgColor>0xff6600</controlPanelBgColor>" + //控制栏背景的颜色
83+
"<controlPanelBtnColor>0xffffff</controlPanelBtnColor>" + //控制按钮的颜色
84+
"<contralPanelBtnGlowColro>0xffff00</contralPanelBtnGlowColro>" + //控制按钮光晕的颜色
85+
//控制栏的显示模式,
86+
// "float": 默认的浮动模式,鼠标移除播放器就会隐藏掉
87+
// "normal": 正常模式,任何时候都在影片的下部浮动显示
88+
// "bottom": 下部模式,不浮动在影片之上,而是显示在影片下方
89+
// "none": 不显示播放器控制栏
90+
"<controlPanelMode>float</controlPanelMode>" +
91+
"<defautVolume>0.8</defautVolume>" +//默认的声音大小,最大为1,最小为0
92+
"<isAutoPlay>true</isAutoPlay>" +//是否影片自动开始播放,默认是true
93+
"<isLoadBegin>true</isLoadBegin>" + //是否一开始就读取影片,默认是true
94+
"<isRepeat>false</isRepeat>" +//是否循环播放影片,默然是false
95+
"<isShowAbout>true</isShowAbout>" + // 是否显示关于信息
96+
// 影片放缩模式:
97+
//"showAll": 可以看到全部影片,保持比例,可能上下或者左右
98+
//"exactFil": 放缩影片到播放器的尺寸,可能比例失调
99+
//"noScale": 影片的原始尺寸,无放缩
100+
//"noBorder": 影片充满播放器,保持比例,可能会被裁剪
101+
"<scaleMode>showAll</scaleMode>" +
102+
"</config>" +
103+
//plugIns
104+
"<plugIns>" +
105+
"<logoPlugIn>" +
106+
"<url>/ui/mosesadd/vcastr/logoPlugIn.swf</url>" +
107+
"<logoText>www.ruochi.com</logoText>" +
108+
"<logoTextAlpha>0.75</logoTextAlpha>" +
109+
"<logoTextFontSize>30</logoTextFontSize>" +
110+
"<logoTextLink>http://192.168.7.202</logoTextLink>" +
111+
"<logoTextColor>0xffffff</logoTextColor>" +
112+
"<textMargin>20 20 auto auto</textMargin>" +
113+
"</logoPlugIn>" +
114+
//end of plugIns
115+
"</plugIns>" +
116+
"</vcastr>";
117+
118+
119+
try {
120+
Document document = DocumentHelper.parseText(originxml);
121+
document.getRootElement().element("channel").element("item").element("source").setText("/video/getVideo/" + id);
122+
//Not Support Chinese
123+
String username = SystemHelper.GetCurrentUserName();
124+
document.getRootElement().element("plugIns").element("logoPlugIn").element("logoText").setText(username);
125+
return document.asXML();
126+
} catch (DocumentException e) {
127+
e.printStackTrace();
128+
}
129+
return "";
130+
131+
}
132+
133+
@RequestMapping(value = "/video/getVideo/{id}", method = RequestMethod.GET)
134+
// @ResponseBody
135+
public void getMediaFile(@PathVariable Long id, HttpServletRequest request, HttpServletResponse response, Map<String, Object> model) throws IOException {
136+
137+
CMSVideo content = cmsVideoService.findCMSVideoById(id);
138+
if (content == null) {
139+
//todo do sth
140+
}
141+
String path = content.getCmsVideoFilepath();
142+
// Path p = Paths.get(path);
143+
144+
File f = new File(path);
145+
String rtn;
146+
if (f.exists() && (!f.isDirectory())) {
147+
rtn = path;
148+
} else {
149+
String errorMessage = "Sorry. The file you are looking for does not exist";
150+
// System.out.println(errorMessage);
151+
ServletOutputStream outputStream = response.getOutputStream();
152+
outputStream.write(errorMessage.getBytes(Charset.forName("UTF-8")));
153+
outputStream.close();
154+
return;
155+
}
156+
157+
String mimeType = URLConnection.guessContentTypeFromName(f.getName());
158+
if (mimeType == null) {
159+
System.out.println("mimetype is not detectable, will take default");
160+
mimeType = "application/octet-stream";
161+
}
162+
163+
System.out.println("mimetype : " + mimeType);
164+
// mimeType = "application/force-download";
165+
response.setContentType(mimeType);
166+
/* "Content-Disposition : inline" will show viewable types [like images/text/pdf/anything viewable by browser] right on browser
167+
while others(zip e.g) will be directly downloaded [may provide save as popup, based on your browser setting.]*/
168+
response.setHeader("Content-Disposition", String.format("inline; filename=\"" + f.getName() + "\""));
169+
// response.setHeader("Content-Disposition", String.format("attachment; filename=\"" + f.getName() +"\""));
170+
171+
172+
/* "Content-Disposition : attachment" will be directly download, may provide save as popup, based on your browser setting*/
173+
//response.setHeader("Content-Disposition", String.format("attachment; filename=\"%s\"", file.getName()));
174+
175+
response.setContentLength((int) f.length());
176+
177+
InputStream inputStream = new BufferedInputStream(new FileInputStream(f));
178+
179+
//Copy bytes from source to destination(outputstream in this example), closes both streams.
180+
FileCopyUtils.copy(inputStream, response.getOutputStream());
181+
182+
}
183+
184+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package net.liuxuan.SprKi.controller.videos;
2+
3+
/**
4+
* Copyright (c) 2010-2017. by Liuxuan All rights reserved. <br/>
5+
* ***************************************************************************
6+
* 源文件名: net.liuxuan.SprKi.controller.videos.VideoFlvXml
7+
* 功能:
8+
* 版本: @version 1.0
9+
* 编制日期: 2017/10/20 9:48
10+
* 修改历史: (主要历史变动原因及说明)
11+
* YYYY-MM-DD | Author | Change Description
12+
* 2017/10/20 | Moses | Created
13+
*/
14+
public class VideoFlvXml {
15+
16+
}

src/main/java/net/liuxuan/spring/Helper/SystemHelper.java

+5
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ public static DbUser getCurrentUser() {
212212
return getCurrentUsersFromDb();
213213
}
214214

215+
public static String GetCurrentUserName(){
216+
return ((User) SecurityContextHolder.getContext()
217+
.getAuthentication().getPrincipal()).getUsername();
218+
}
219+
215220
public static DbUser getCurrentUsersFromDb() {
216221
User ui = (User) SecurityContextHolder.getContext()
217222
.getAuthentication().getPrincipal();

0 commit comments

Comments
 (0)