package com.yeshi.buwan.web.action;
|
|
import java.io.UnsupportedEncodingException;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletRequest;
|
|
import org.apache.struts2.interceptor.ServletRequestAware;
|
import org.springframework.stereotype.Controller;
|
|
import com.opensymphony.xwork2.ActionSupport;
|
import com.yeshi.buwan.domain.VideoDetailInfo;
|
import com.yeshi.buwan.domain.VideoInfo;
|
import com.yeshi.buwan.domain.VideoResource;
|
import com.yeshi.buwan.domain.VideoUrl;
|
import com.yeshi.buwan.service.imp.VideoManager;
|
import com.yeshi.buwan.service.imp.VideoResourceService;
|
import com.yeshi.buwan.service.imp.VideoService;
|
import com.yeshi.buwan.util.StringUtil;
|
|
@Controller
|
public class VideoDetailAction extends ActionSupport implements ServletRequestAware {
|
@Resource
|
private VideoManager videoManager;
|
@Resource
|
private VideoService videoService;
|
@Resource
|
private VideoResourceService videoResourceService;
|
|
public VideoResourceService getVideoResourceService() {
|
return videoResourceService;
|
}
|
|
public void setVideoResourceService(VideoResourceService videoResourceService) {
|
this.videoResourceService = videoResourceService;
|
}
|
|
public VideoManager getVideoManager() {
|
return videoManager;
|
}
|
|
public void setVideoManager(VideoManager videoManager) {
|
this.videoManager = videoManager;
|
}
|
|
public VideoService getVideoService() {
|
return videoService;
|
}
|
|
public void setVideoService(VideoService videoService) {
|
this.videoService = videoService;
|
}
|
|
HttpServletRequest request;
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 1L;
|
|
/**
|
* 获取详情列表
|
*
|
* @return
|
*/
|
public String getVideoDetailList() {
|
|
if (StringUtil.isNullOrEmpty(videoId)) {
|
videoId = (String) request.getAttribute("videoId");
|
}
|
|
List<VideoDetailInfo> detailList = videoManager.getVideoDetail(videoId);
|
request.setAttribute("videoDetailList", detailList);
|
|
List<VideoResource> list = videoResourceService.getResourceList();
|
request.setAttribute("resourceList", list);
|
request.setAttribute("videoId", videoId);
|
return SUCCESS;
|
}
|
|
/**
|
* 修改详情
|
*
|
* @return
|
*/
|
public String updateVideoDetail() {
|
|
if (Long.parseLong(id) > 0) {
|
VideoDetailInfo detail = videoManager.getVideoDetailById(Long.parseLong(id));
|
detail.setIntroduction(introduction);
|
try {
|
if (!StringUtil.isNullOrEmpty(introduction))
|
detail.setIntroduction(new String(introduction.getBytes("iso-8859-1"), "UTF-8"));
|
detail.setName(new String(name.getBytes("iso-8859-1"), "UTF-8"));
|
} catch (UnsupportedEncodingException e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
detail.setTag(tag);
|
invalids = request.getParameterValues("invalids");
|
List<VideoUrl> urlList = new ArrayList<VideoUrl>();
|
if (urls != null)
|
for (int i = 0; i < urls.length; i++) {
|
VideoUrl vu = new VideoUrl();
|
vu.setVideoDetail(new VideoDetailInfo(detail.getId()));
|
vu.setUrl(urls[i]);
|
if (StringUtil.isNullOrEmpty(invalids[i]))
|
vu.setInvalid("1");// 链接无效
|
else
|
vu.setInvalid("0");// 链接有效
|
vu.setResource(new VideoResource(resources[i]));
|
vu.setVideoDetail(detail);
|
urlList.add(vu);
|
}
|
detail.setUrls(urlList);
|
request.setAttribute("videoId", detail.getVideo().getId());
|
videoManager.updateVideoDetail(detail);
|
} else {
|
VideoDetailInfo detail = new VideoDetailInfo();
|
detail.setIntroduction(introduction);
|
try {
|
if (!StringUtil.isNullOrEmpty(introduction))
|
detail.setIntroduction(new String(introduction.getBytes("iso-8859-1"), "UTF-8"));
|
detail.setName(new String(name.getBytes("iso-8859-1"), "UTF-8"));
|
} catch (UnsupportedEncodingException e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
detail.setTag(tag);
|
detail.setVideo(new VideoInfo(videoId));
|
List<VideoUrl> urlList = new ArrayList<VideoUrl>();
|
if (urls != null)
|
for (int i = 0; i < urls.length; i++) {
|
VideoUrl vu = new VideoUrl();
|
vu.setUrl(urls[i]);
|
if (StringUtil.isNullOrEmpty(invalids[i]))
|
vu.setInvalid("1");// 链接无效
|
else
|
vu.setInvalid("0");// 链接有效
|
vu.setResource(new VideoResource(resources[i]));
|
urlList.add(vu);
|
}
|
detail.setUrls(urlList);
|
request.setAttribute("videoId", videoId);
|
videoManager.addVideoDetail(detail);
|
}
|
return SUCCESS;
|
}
|
|
/**
|
* 添加详情
|
*
|
* @return
|
*/
|
public String addVideoDetail() {
|
|
VideoDetailInfo detail = new VideoDetailInfo();
|
detail.setIntroduction(introduction);
|
detail.setName(name);
|
detail.setTag(tag);
|
detail.setVideo(new VideoInfo(videoId));
|
List<VideoUrl> urlList = new ArrayList<VideoUrl>();
|
for (int i = 0; i < urls.length; i++) {
|
VideoUrl vu = new VideoUrl();
|
vu.setUrl(urls[i]);
|
if (StringUtil.isNullOrEmpty(invalids[i]))
|
vu.setInvalid("1");// 链接无效
|
else
|
vu.setInvalid("0");// 链接有效
|
vu.setResource(new VideoResource(resources[i]));
|
urlList.add(vu);
|
}
|
detail.setUrls(urlList);
|
videoManager.addVideoDetail(detail);
|
return SUCCESS;
|
}
|
|
/**
|
* 删除详情
|
*
|
* @return
|
*/
|
public String deleteVideoDetail() {
|
|
videoManager.deleteVideoDetail(new VideoDetailInfo(Long.parseLong(id)));
|
return SUCCESS;
|
}
|
|
public void setServletRequest(HttpServletRequest arg0) {
|
this.request = arg0;
|
}
|
|
private String videoId;
|
private String id;
|
private String tag;
|
private String name;
|
private String introduction;
|
private String beizhu;
|
|
public String getVideoId() {
|
return videoId;
|
}
|
|
public void setVideoId(String videoId) {
|
this.videoId = videoId;
|
}
|
|
public String getId() {
|
return id;
|
}
|
|
public void setId(String id) {
|
this.id = id;
|
}
|
|
public String getTag() {
|
return tag;
|
}
|
|
public void setTag(String tag) {
|
this.tag = tag;
|
}
|
|
public String getName() {
|
return name;
|
}
|
|
public void setName(String name) {
|
this.name = name;
|
}
|
|
public String getIntroduction() {
|
return introduction;
|
}
|
|
public void setIntroduction(String introduction) {
|
this.introduction = introduction;
|
}
|
|
public String getBeizhu() {
|
return beizhu;
|
}
|
|
public void setBeizhu(String beizhu) {
|
this.beizhu = beizhu;
|
}
|
|
private String[] resources;
|
private String[] urls;
|
private String[] invalids;
|
|
public String[] getInvalids() {
|
return invalids;
|
}
|
|
public void setInvalids(String[] invalids) {
|
this.invalids = invalids;
|
}
|
|
public String[] getResources() {
|
return resources;
|
}
|
|
public void setResources(String[] resources) {
|
this.resources = resources;
|
}
|
|
public String[] getUrls() {
|
return urls;
|
}
|
|
public void setUrls(String[] urls) {
|
this.urls = urls;
|
}
|
|
}
|