CPS - Delete validate

package com.cemso.action; import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; import java.util.List; import javax.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.struts2.ServletActionContext; import org.jdom.JDOMException; import com.cemso.dto.ResourceDTO; import com.cemso.service.ResourceService; import com.cemso.util.FileOperationTool; import com.cemso.util.XmlOperationTool; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; public class ResourceAction extends ActionSupport { /** * */ private static final Log log = LogFactory.getLog(ResourceAction.class); private static final long serialVersionUID = 1L; private ResourceService resourceService; private List<ResourceDTO> resourceList; private List<ResourceDTO> videoList; private List<ResourceDTO> imageList; private List<ResourceDTO> audioList; private List<ResourceDTO> textList; public String execute() { ActionContext context = ActionContext.getContext(); HttpServletRequest request = (HttpServletRequest)context.get(ServletActionContext.HTTP_REQUEST); String resourceType = request.getParameter("type"); imageList = new ArrayList<ResourceDTO>(); videoList = new ArrayList<ResourceDTO>(); audioList = new ArrayList<ResourceDTO>(); textList = new ArrayList<ResourceDTO>(); try { resourceList = resourceService.getResourceList(); for(ResourceDTO resource : resourceList){ if(XmlOperationTool.nodeIsExist(XmlOperationTool.PROGRAMXMLPATH, "onebyone", "resource", resource.getId())){ resource.setCanBeDelete(false); }else{ resource.setCanBeDelete(true); } if(resource.getResourceType().equals("video")){ videoList.add(resource); } if(resource.getResourceType().equals("audio")){ audioList.add(resource); } if(resource.getResourceType().equals("image")){ imageList.add(resource); } if(resource.getResourceType().equals("text")){ textList.add(resource); } } // text if(resourceType.equals("#box-1")){ return "textpage"; } // audio if(resourceType.equals("#box-2")){ return "audiopage"; } // image if(resourceType.equals("#box-3")){ return "imagepage"; } // video if(resourceType.equals("#box-4")){ return "videopage"; } // upload if(resourceType.equals("#box-5")){ return "uploadpage"; } } catch (JDOMException e) { if(log.isErrorEnabled()){ log.error("ResourceAction --> execute() occurs an exception : JDOMException"); log.error(e.getMessage()); } return ERROR; } catch (IOException e) { if(log.isErrorEnabled()){ log.error("ResourceAction --> execute() occurs an exception : IOException"); log.error(e.getMessage()); } return ERROR; } return ERROR; } // del resource public String delResourceAction(){ try { ActionContext context = ActionContext.getContext(); HttpServletRequest request = (HttpServletRequest)context.get(ServletActionContext.HTTP_REQUEST); // resource id String id = request.getParameter("id"); // resource name String name = request.getParameter("name"); // IMAGETYPE VIDEOTYPE AUDIOTYPE TEXTTYPE String type = request.getParameter("type"); System.out.println(id); System.out.println(type); // delete content in xml file XmlOperationTool.del(XmlOperationTool.DB_TYPE_RESOURCE, id); boolean flag1 = FileOperationTool.del(name, type); if(type.equals("IMAGETYPE")){ String previewImagePath = ServletActionContext.getServletContext().getRealPath("/images/preview/")+"/"+name; boolean flag = FileOperationTool.del(previewImagePath); if(flag){ }else{ return ERROR; } } return flag1 ? SUCCESS : ERROR; } catch (FileNotFoundException e) { if(log.isErrorEnabled()){ log.error("ResourceAction --> delResourceAction() occurs an exception : FileNotFoundException"); log.error(e.getMessage()); } return ERROR; } catch (JDOMException e) { if(log.isErrorEnabled()){ log.error("ResourceAction --> delResourceAction() occurs an exception : JDOMException"); log.error(e.getMessage()); } return ERROR; } catch (IOException e) { if(log.isErrorEnabled()){ log.error("ResourceAction --> delResourceAction() occurs an exception : IOException"); log.error(e.getMessage()); } return ERROR; } } public String delSelectedResource(){ try { ActionContext context = ActionContext.getContext(); HttpServletRequest request = (HttpServletRequest)context.get(ServletActionContext.HTTP_REQUEST); // IMAGETYPE VIDEOTYPE AUDIOTYPE TEXTTYPE String type = request.getParameter("type"); // resource ids String selectedIDs = request.getParameter("selectedIDs"); // resource names String selectedNames = request.getParameter("selectedNames"); String[] ids = selectedIDs.split(","); String[] names = selectedNames.split("\\|"); int size = names.length; System.out.println(ids.length); System.out.println(names.length); if(type.equals("IMAGETYPE")){ String previewImagePath = null; boolean flag = true; for(int i = 0; i < size; i++){ previewImagePath = ServletActionContext.getServletContext().getRealPath("/images/preview/")+"/"+names[i]; XmlOperationTool.del(XmlOperationTool.DB_TYPE_RESOURCE, ids[i]); flag = flag && FileOperationTool.del(previewImagePath) && FileOperationTool.del(names[i], type); } if(flag){ return SUCCESS; }else{ return ERROR; } }else{ boolean flag = true; for(int i = 0; i < size; i++){ // delete content in xml file XmlOperationTool.del(XmlOperationTool.DB_TYPE_RESOURCE, ids[i]); // delete file in disk flag = flag && FileOperationTool.del(names[i], type); } if(flag){ return SUCCESS; }else{ return ERROR; } } } catch (FileNotFoundException e) { if(log.isErrorEnabled()){ log.error("ResourceAction --> delSelectedResource() occurs an exception : FileNotFoundException"); log.error(e.getMessage()); } return ERROR; } catch (JDOMException e) { if(log.isErrorEnabled()){ log.error("ResourceAction --> delSelectedResource() occurs an exception : JDOMException"); log.error(e.getMessage()); } return ERROR; } catch (IOException e) { if(log.isErrorEnabled()){ log.error("ResourceAction --> delSelectedResource() occurs an exception : IOException"); log.error(e.getMessage()); } return ERROR; } } // redirect to manage_resource.jsp public String displayCategory(){ return "manageResourcePage"; } public ResourceService getResourceService() { return resourceService; } public void setResourceService(ResourceService resourceService) { this.resourceService = resourceService; } public List<ResourceDTO> getResourceList() { return resourceList; } public void setResourceList(List<ResourceDTO> resourceList) { this.resourceList = resourceList; } public List<ResourceDTO> getVideoList() { return videoList; } public void setVideoList(List<ResourceDTO> videoList) { this.videoList = videoList; } public List<ResourceDTO> getImageList() { return imageList; } public void setImageList(List<ResourceDTO> imageList) { this.imageList = imageList; } public List<ResourceDTO> getAudioList() { return audioList; } public void setAudioList(List<ResourceDTO> audioList) { this.audioList = audioList; } public List<ResourceDTO> getTextList() { return textList; } public void setTextList(List<ResourceDTO> textList) { this.textList = textList; } }


package com.cemso.dto; public class ResourceDTO { private String id; private String resourceName; private String resourceType; private String paramRemark; private String paramCreatetime; private String paramCreateby; private boolean canBeDelete; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getResourceName() { return resourceName; } public void setResourceName(String resourceName) { this.resourceName = resourceName; } public String getResourceType() { return resourceType; } public void setResourceType(String resourceType) { this.resourceType = resourceType; } public String getParamRemark() { return paramRemark; } public void setParamRemark(String paramRemark) { this.paramRemark = paramRemark; } public String getParamCreatetime() { return paramCreatetime; } public void setParamCreatetime(String paramCreatetime) { this.paramCreatetime = paramCreatetime; } public String getParamCreateby() { return paramCreateby; } public void setParamCreateby(String paramCreateby) { this.paramCreateby = paramCreateby; } public String getFlvname(){ return resourceName.substring(0,resourceName.lastIndexOf("."))+".flv"; } public boolean isCanBeDelete() { return canBeDelete; } public void setCanBeDelete(boolean canBeDelete) { this.canBeDelete = canBeDelete; } }

package com.cemso.action; import java.io.FileNotFoundException; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.struts2.ServletActionContext; import org.jdom.JDOMException; import com.cemso.dto.TemplateDTO; import com.cemso.dto.TemplateModelDTO; import com.cemso.dto.UserDTO; import com.cemso.service.TemplateService; import com.cemso.util.XmlOperationTool; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; public class TemplateAction extends ActionSupport { /** * */ private static final long serialVersionUID = 1L; private TemplateService templateService; private List<TemplateDTO> templateList; private static final Log log = LogFactory.getLog(TemplateAction.class); public String addTemplate() { ActionContext context = ActionContext.getContext(); HttpServletRequest request = (HttpServletRequest) context.get(ServletActionContext.HTTP_REQUEST); String model = request.getParameter("model"); String templateName = request.getParameter("templateName"); String tempalteRemark = request.getParameter("tempalteRemark"); String templateSize = request.getParameter("templateSize"); TemplateDTO template = parseJsonObj(templateName, tempalteRemark,templateSize, model); try { return templateService.addTemlate(template)?SUCCESS:ERROR; } catch (FileNotFoundException e) { if(log.isErrorEnabled()){ log.error("TemplateAction --> addTemplate() occurs an exception : FileNotFoundException"); log.error(e.getMessage()); } return ERROR; } catch (JDOMException e) { if(log.isErrorEnabled()){ log.error("TemplateAction --> addTemplate() occurs an exception : JDOMException"); log.error(e.getMessage()); } return ERROR; } catch (IOException e) { if(log.isErrorEnabled()){ log.error("TemplateAction --> addTemplate() occurs an exception : IOException"); log.error(e.getMessage()); } return ERROR; } } public String getTemplates(){ try { templateList = templateService.getTemlates(); // filter the templates witch can not be deleted for(int i = 0; i < templateList.size(); i++){ TemplateDTO template = templateList.get(i); if(XmlOperationTool.nodeIsExist(XmlOperationTool.PROGRAMXMLPATH, "param", "name", "template", template.getId())){ template.setCanBeDelete(false); }else{ template.setCanBeDelete(true); } templateList.add(i, template); } return "templatepage"; } catch (JDOMException e) { if(log.isErrorEnabled()){ log.error("TemplateAction --> getTemplates() occurs an exception : JDOMException"); log.error(e.getMessage()); } return ERROR; } catch (IOException e) { if(log.isErrorEnabled()){ log.error("TemplateAction --> getTemplates() occurs an exception : IOException"); log.error(e.getMessage()); } return ERROR; } } // delete template public String delTemplateAction(){ try { ActionContext context = ActionContext.getContext(); HttpServletRequest request = (HttpServletRequest)context.get(ServletActionContext.HTTP_REQUEST); // template id String id = request.getParameter("id"); XmlOperationTool.del(XmlOperationTool.DB_TYPE_TEMPLATE, id); return SUCCESS; } catch (JDOMException e) { if(log.isErrorEnabled()){ log.error("TemplateAction --> delTemplateAction() occurs an exception : JDOMException"); log.error(e.getMessage()); } return ERROR; } catch (IOException e) { if(log.isErrorEnabled()){ log.error("TemplateAction --> delTemplateAction() occurs an exception : IOException"); log.error(e.getMessage()); } return ERROR; } } // delete selected template public String delSelectedTemplate(){ try { ActionContext context = ActionContext.getContext(); HttpServletRequest request = (HttpServletRequest)context.get(ServletActionContext.HTTP_REQUEST); // template ids String ids = request.getParameter("ids"); String[] id = ids.split(","); int size = id.length; for(int i=0;i<size;i++){ XmlOperationTool.del(XmlOperationTool.DB_TYPE_TEMPLATE, id[i]); } return SUCCESS; } catch (JDOMException e) { if(log.isErrorEnabled()){ log.error("TemplateAction --> delSelectedTemplate() occurs an exception : JDOMException"); log.error(e.getMessage()); } return ERROR; } catch (IOException e) { if(log.isErrorEnabled()){ log.error("TemplateAction --> delSelectedTemplate() occurs an exception : IOException"); log.error(e.getMessage()); } return ERROR; } } public String templateDesign(){ return "templateDesignPage"; } private TemplateDTO parseJsonObj(String temmlateNameValue, String tempalteRemark,String templateSize, String modelValue) { TemplateDTO template = new TemplateDTO(); List<TemplateModelDTO> modelList = new ArrayList<TemplateModelDTO>(); // modelValue:video1_1_0_0_279_150,image2_2_426_0_596_127,audio3_3_0_254_254_394, String[] modelArray = modelValue.split(","); int modelSize = modelArray.length; for (int i = 0; i < modelSize; i++) { TemplateModelDTO model = new TemplateModelDTO(); String modelString = modelArray[i]; String[] modelDetails = modelString.split("_"); model.setName(modelDetails[0]); if (modelDetails[0].startsWith("video")) { model.setType("video"); } if (modelDetails[0].startsWith("image")) { model.setType("image"); } if (modelDetails[0].startsWith("text")) { model.setType("text"); } if (modelDetails[0].startsWith("audio")) { model.setType("audio"); } if (modelDetails[0].startsWith("weather")) { model.setType("weather"); } if (modelDetails[0].startsWith("clock")) { model.setType("clock"); } model.setId(String.valueOf(System.currentTimeMillis())+"_"+model.getName()); model.setGradation(modelDetails[1]); model.setDimension(modelDetails[2]+","+modelDetails[3]+","+modelDetails[4]+","+modelDetails[5]); modelList.add(model); } Date date = Calendar.getInstance().getTime(); template.setName(temmlateNameValue); Map<String,Object> session = ActionContext.getContext().getSession(); template.setCreateBy(((UserDTO)session.get("user")).getId()); template.setCreateTime(new SimpleDateFormat("yyyy-mm-dd HH:mm:ss") .format(date)); template.setId("template_" + date.getTime()); template.setRemark(tempalteRemark); template.setSize(templateSize); template.setModels(modelList); return template; } public TemplateService getTemplateService() { return templateService; } public void setTemplateService(TemplateService templateService) { this.templateService = templateService; } public List<TemplateDTO> getTemplateList() { return templateList; } public void setTemplateList(List<TemplateDTO> templateList) { this.templateList = templateList; } }

package com.cemso.dto; import java.util.List; public class TemplateDTO { private String id; private String name; private String remark; private String size; private String createTime; private String createBy; private List<TemplateModelDTO> models; private boolean canBeDelete; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getRemark() { return remark; } public void setRemark(String remark) { this.remark = remark; } public String getCreateTime() { return createTime; } public void setCreateTime(String createTime) { this.createTime = createTime; } public String getCreateBy() { return createBy; } public void setCreateBy(String createBy) { this.createBy = createBy; } public List<TemplateModelDTO> getModels() { return models; } public void setModels(List<TemplateModelDTO> models) { this.models = models; } public String getSize() { return size; } public void setSize(String size) { this.size = size; } public boolean isCanBeDelete() { return canBeDelete; } public void setCanBeDelete(boolean canBeDelete) { this.canBeDelete = canBeDelete; } }
package com.cemso.action; import java.io.FileNotFoundException; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.struts2.ServletActionContext; import org.jdom.JDOMException; import com.cemso.dto.OnebyoneDTO; import com.cemso.dto.ProgramDTO; import com.cemso.dto.ResourceDTO; import com.cemso.dto.TemplateDTO; import com.cemso.dto.UserDTO; import com.cemso.service.ProgramService; import com.cemso.service.ResourceService; import com.cemso.service.TemplateService; import com.cemso.util.XmlOperationTool; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; public class ProgramAction extends ActionSupport { /** * */ private final Log log = LogFactory.getLog(com.cemso.action.LoginAction.class); private static final long serialVersionUID = 1L; private ProgramService programService; private TemplateService templateService; private ResourceService resourceService; private List<ProgramDTO> programList; private List<TemplateDTO> templateList; private List<ResourceDTO> resourceList; private List<ResourceDTO> videoList; private List<ResourceDTO> imageList; private List<ResourceDTO> audioList; private List<ResourceDTO> textList; // 编辑program返回的对象 private ProgramDTO programDTO; public String getProgram(){ try { programList = programService.getProgramList(); templateList = templateService.getTemlates(); resourceList = resourceService.getResourceList(); imageList = new ArrayList<ResourceDTO>(); videoList = new ArrayList<ResourceDTO>(); audioList = new ArrayList<ResourceDTO>(); textList = new ArrayList<ResourceDTO>(); for(ResourceDTO resource : resourceList){ if(resource.getResourceType().equals("video")){ videoList.add(resource); } if(resource.getResourceType().equals("audio")){ audioList.add(resource); } if(resource.getResourceType().equals("image")){ imageList.add(resource); } if(resource.getResourceType().equals("text")){ textList.add(resource); } } // filter the programs witch can not be delete for(int i=0; i < programList.size();i++){ ProgramDTO program = programList.get(i); if(XmlOperationTool.nodeIsExist(XmlOperationTool.PLAYLISTXMLPATH, "program", "id", program.getId())){ program.setCanBeDelete(false); }else{ program.setCanBeDelete(true); } programList.set(i, program); } return "programpage"; } catch (JDOMException e) { e.printStackTrace(); return ERROR; } catch (IOException e) { e.printStackTrace(); return ERROR; } } // add program public String addProgram(){ ProgramDTO program = new ProgramDTO(); List<OnebyoneDTO> onebyoneList = new ArrayList<OnebyoneDTO>(); ActionContext context = ActionContext.getContext(); HttpServletRequest request = (HttpServletRequest)context.get(ServletActionContext.HTTP_REQUEST); Map<String, Object> session = context.getSession(); SimpleDateFormat formate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // set program attribute String createtime = formate.format(System.currentTimeMillis()); String createby = ((UserDTO)session.get("user")).getId(); String programName = request.getParameter("programName"); String programRemark = request.getParameter("programRemark"); String length = request.getParameter("length"); String relation = request.getParameter("relation"); String[] onebyones = relation.split("\\|"); // "|" // get template id String templateId = "template_" + relation.split("_")[0]; program.setId("program_"+System.currentTimeMillis()); program.setName(programName); program.setRemark(programRemark); program.setCreateby(createby); program.setCreatetime(createtime); program.setTemplateId(templateId); program.setLength(length); for(int i = 0;i<onebyones.length;i++){ String[] onebyone = onebyones[i].split(":"); OnebyoneDTO onebyoneDTO = new OnebyoneDTO(); onebyoneDTO.setDimension(onebyone[1]); onebyoneDTO.setGradation(onebyone[2]); onebyoneDTO.setResource(onebyone[3]); onebyoneDTO.setResourceName(onebyone[4]); onebyoneList.add(onebyoneDTO); } program.setOnebyoneList(onebyoneList); try { return programService.addProgram(program)? SUCCESS:ERROR; } catch (FileNotFoundException e) { if(log.isErrorEnabled()){ log.error(e.getStackTrace()); } return ERROR; } catch (JDOMException e) { if(log.isErrorEnabled()){ log.error(e.getStackTrace()); } return ERROR; } catch (IOException e) { if(log.isErrorEnabled()){ log.error(e.getStackTrace()); } return ERROR; } } // delete program public String delProgram(){ try { ActionContext context = ActionContext.getContext(); HttpServletRequest request = (HttpServletRequest)context.get(ServletActionContext.HTTP_REQUEST); // program id String id = request.getParameter("id"); XmlOperationTool.del(XmlOperationTool.DB_TYPE_PROGRAM, id); return SUCCESS; } catch (JDOMException e) { e.printStackTrace(); return ERROR; } catch (IOException e) { e.printStackTrace(); return ERROR; } } // delete selected program public String delSelectedProgram(){ try { ActionContext context = ActionContext.getContext(); HttpServletRequest request = (HttpServletRequest)context.get(ServletActionContext.HTTP_REQUEST); // program id String ids = request.getParameter("ids"); String[] id = ids.split(","); int size = id.length; for(int i=0; i <size;i++){ XmlOperationTool.del(XmlOperationTool.DB_TYPE_PROGRAM, id[i]); } return SUCCESS; } catch (JDOMException e) { e.printStackTrace(); return ERROR; } catch (IOException e) { e.printStackTrace(); return ERROR; } } // 编辑更新program public String editProgram(){ ProgramDTO program = new ProgramDTO(); List<OnebyoneDTO> onebyoneList = new ArrayList<OnebyoneDTO>(); ActionContext context = ActionContext.getContext(); HttpServletRequest request = (HttpServletRequest)context.get(ServletActionContext.HTTP_REQUEST); Map<String, Object> session = context.getSession(); SimpleDateFormat formate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // set program attribute String createtime = formate.format(System.currentTimeMillis()); String createby = ((UserDTO)session.get("user")).getId(); String programId = request.getParameter("programId"); String programName = request.getParameter("programName"); String programRemark = request.getParameter("programRemark"); String length = request.getParameter("length"); String relation = request.getParameter("relation"); String[] onebyones = relation.split("\\|"); // "|" // get template id String templateId = "template_" + relation.split("_")[0]; program.setId(programId); program.setName(programName); program.setRemark(programRemark); program.setCreateby(createby); program.setCreatetime(createtime); program.setTemplateId(templateId); program.setLength(length); for(int i = 0;i<onebyones.length;i++){ String[] onebyone = onebyones[i].split(":"); OnebyoneDTO onebyoneDTO = new OnebyoneDTO(); onebyoneDTO.setDimension(onebyone[1]); onebyoneDTO.setGradation(onebyone[2]); onebyoneDTO.setResource(onebyone[3]); onebyoneDTO.setResourceName(onebyone[4]); onebyoneList.add(onebyoneDTO); } program.setOnebyoneList(onebyoneList); try { XmlOperationTool.edit(program); return SUCCESS; } catch (FileNotFoundException e) { if(log.isErrorEnabled()){ log.error(e.getStackTrace()); } return ERROR; } catch (JDOMException e) { if(log.isErrorEnabled()){ log.error(e.getStackTrace()); } return ERROR; } catch (IOException e) { if(log.isErrorEnabled()){ log.error(e.getStackTrace()); } return ERROR; } } // 获取待编辑的program对象 public String editGetProgram(){ try { ActionContext context = ActionContext.getContext(); HttpServletRequest request = (HttpServletRequest)context.get(ServletActionContext.HTTP_REQUEST); String id = request.getParameter("id"); System.out.println(id); programList = programService.getProgramList(); for(ProgramDTO program : programList){ if(program.getId().equals(id)){ programDTO = program; } } return "programObject"; } catch (JDOMException e) { e.printStackTrace(); return ERROR; } catch (IOException e) { e.printStackTrace(); return ERROR; } } public ProgramService getProgramService() { return programService; } public void setProgramService(ProgramService programService) { this.programService = programService; } public TemplateService getTemplateService() { return templateService; } public void setTemplateService(TemplateService templateService) { this.templateService = templateService; } public ResourceService getResourceService() { return resourceService; } public void setResourceService(ResourceService resourceService) { this.resourceService = resourceService; } public List<TemplateDTO> getTemplateList() { return templateList; } public void setTemplateList(List<TemplateDTO> templateList) { this.templateList = templateList; } public List<ResourceDTO> getResourceList() { return resourceList; } public void setResourceList(List<ResourceDTO> resourceList) { this.resourceList = resourceList; } public List<ProgramDTO> getProgramList() { return programList; } public void setProgramList(List<ProgramDTO> programList) { this.programList = programList; } public List<ResourceDTO> getVideoList() { return videoList; } public void setVideoList(List<ResourceDTO> videoList) { this.videoList = videoList; } public List<ResourceDTO> getImageList() { return imageList; } public void setImageList(List<ResourceDTO> imageList) { this.imageList = imageList; } public List<ResourceDTO> getAudioList() { return audioList; } public void setAudioList(List<ResourceDTO> audioList) { this.audioList = audioList; } public List<ResourceDTO> getTextList() { return textList; } public void setTextList(List<ResourceDTO> textList) { this.textList = textList; } public ProgramDTO getProgramDTO() { return programDTO; } public void setProgramDTO(ProgramDTO programDTO) { this.programDTO = programDTO; } }

package com.cemso.dto; import java.util.List; public class ProgramDTO { private String id; private String name; private String remark; private String length; private String createtime; private String createby; private String templateId; private List<OnebyoneDTO> onebyoneList; // for playlist private String index; private boolean canBeDelete; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getRemark() { return remark; } public void setRemark(String remark) { this.remark = remark; } public String getLength() { return length; } public void setLength(String length) { this.length = length; } public String getCreatetime() { return createtime; } public void setCreatetime(String createtime) { this.createtime = createtime; } public String getCreateby() { return createby; } public void setCreateby(String createby) { this.createby = createby; } public String getTemplateId() { return templateId; } public void setTemplateId(String templateId) { this.templateId = templateId; } public List<OnebyoneDTO> getOnebyoneList() { return onebyoneList; } public void setOnebyoneList(List<OnebyoneDTO> onebyoneList) { this.onebyoneList = onebyoneList; } public String getIndex() { return index; } public void setIndex(String index) { this.index = index; } public boolean isCanBeDelete() { return canBeDelete; } public void setCanBeDelete(boolean canBeDelete) { this.canBeDelete = canBeDelete; } }

XmlOperationTool.java

/** * @param xmlPath * @param nodeName * @param attrName * @param attrValue * @return boolean */ // search one node with attribute value public static boolean nodeIsExist(String xmlPath, String nodeName, String attrName, String attrValue){ boolean flag = false; try { SAXBuilder builder = new SAXBuilder(); Document document = builder.build(xmlPath); Element root = document.getRootElement(); XPath xpath = XPath.newInstance("//" + nodeName + "[@" + attrName + "='" + attrValue + "']"); Element e = (Element) xpath.selectSingleNode(root); if(e != null){ flag = true; } } catch (JDOMException e) { if(log.isErrorEnabled()){ log.error("XmlOperationTool --> nodeIsExist throw an exception : JDOMException"); log.error(e.getMessage()); } } catch (IOException e) { if(log.isErrorEnabled()){ log.error("XmlOperationTool --> nodeIsExist throw an exception : IOException"); log.error(e.getMessage()); } } return flag; } /** * @param xmlPath xml file path * @param nodeName node name * @param attrName attribute name * @param attrValue attribute value * @param nodeText node text * @return boolean */ // search one node with node text @SuppressWarnings("unchecked") public static boolean nodeIsExist(String xmlPath, String nodeName, String attrName, String attrValue, String nodeText){ boolean flag = false; try { SAXBuilder builder = new SAXBuilder(); Document document = builder.build(xmlPath); Element root = document.getRootElement(); XPath xpath = XPath.newInstance("//" + nodeName + "[@" + attrName + "='" + attrValue + "']"); List<Element> elist = (List<Element>) xpath.selectNodes(root); for(Element e : elist){ if(e.getText().equals(nodeText)){ flag = true; break; } } } catch (JDOMException e) { if(log.isErrorEnabled()){ log.error("XmlOperationTool --> nodeIsExist throw an exception : JDOMException"); log.error(e.getMessage()); } } catch (IOException e) { if(log.isErrorEnabled()){ log.error("XmlOperationTool --> nodeIsExist throw an exception : IOException"); log.error(e.getMessage()); } } return flag; }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值