📄 softwarejsfbean.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package org.openacs.web;import java.io.File;import java.io.FileOutputStream;import java.util.ArrayList;import java.util.Collection;import java.util.Map;import org.openacs.SoftwareLocal;import java.util.logging.Level;import java.util.logging.Logger;import javax.ejb.CreateException;import javax.ejb.EJBException;import javax.ejb.FinderException;import javax.ejb.RemoveException;import javax.faces.application.FacesMessage;import javax.faces.context.FacesContext;import javax.faces.model.SelectItem;import org.openacs.SoftwarePK;import org.openacs.Util;import org.openacs.utils.Ejb;import org.richfaces.event.UploadEvent;import org.richfaces.model.UploadItem;import javax.faces.component.html.HtmlInputText;/** * * @author Administrator */public class SoftwareJsfBean { /** Creates a new instance of ConfigJsfBean */ public SoftwareJsfBean () { Map <String, String> rpm = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); String hwid = rpm.get("hwid"); String version = rpm.get("swver");// System.out.println ("SoftwareJsfBean.constructor hwid="+hwid+" version="+version); if (hwid != null) { this.hwid = Integer.parseInt(hwid); } this.version = version; if (hwid != null && version != null) { try { SoftwareLocal s = Ejb.lookupSoftwareBean().findByPrimaryKey (new SoftwarePK(this.hwid, version)); this.version = s.getVersion(); this.filename = s.getFilename(); } catch (FinderException ex) { //Logger.getLogger(ScriptJsfBean.class.getName()).log(Level.SEVERE, null, ex); } } } private HtmlInputText version_in = null; public void setVersionin (HtmlInputText version_in) { this.version_in = version_in; } public HtmlInputText getVersionin () { return version_in; } private Object[] array = null; public Object[] getAll() throws FinderException {// System.out.println ("SoftwareJsfBean.getAll hwid="+hwid); if (array != null) { return array; } else { array = Ejb.lookupSoftwareBean().findByHardware(hwid).toArray();/* for (Object o : array) { System.out.println (o); } */ return array; } } private String filename; public String getFilename () { return filename; } public void setFilename (String filename) { System.out.println ("Software.setFilename: "+filename); this.filename = filename; } private String version; public String getVersion () { return version; } public void setVersion (String version) { System.out.println ("Software.setVersion: "+version); this.version = version; } private Integer hwid; public Integer getHwid () { return hwid; } public void setHwid (Integer hwid) { System.out.println ("Software.hwid: "+hwid); this.hwid = hwid; } public boolean isNew () { System.out.println ("Software.isNew: "+(version == null || version.equals(""))); return version == null || version.equals(""); } public String Save () {// System.out.println ("Software.Save: hwid="+hwid+" version="+version+" filename="+filename); try { SoftwareLocal s = Ejb.lookupSoftwareBean().findByPrimaryKey(new SoftwarePK(hwid, version)); File f = new File (getFwPath()+filename); s.setFilename(filename); s.setSize(f.length()); } catch (FinderException ex) { Logger.getLogger(ScriptJsfBean.class.getName()).log(Level.SEVERE, null, ex); } return null; } public String Create () { System.out.println ("Software.Create: hwid="+hwid+" version="+version+" filename="+filename); try { SoftwareLocal s = Ejb.lookupSoftwareBean().create(hwid, version, null, null); File f = new File (getFwPath()+filename); s.setFilename(filename); s.setSize(f.length()); } catch (CreateException ex) { Logger.getLogger(ScriptJsfBean.class.getName()).log(Level.SEVERE, null, ex); } return null; } public String Delete () { try { Ejb.lookupSoftwareBean().findByPrimaryKey(new SoftwarePK(hwid, version)).remove(); } catch (FinderException ex) { Logger.getLogger(ScriptJsfBean.class.getName()).log(Level.SEVERE, null, ex); } catch (EJBException ex) { Logger.getLogger(ScriptJsfBean.class.getName()).log(Level.SEVERE, null, ex); } catch (RemoveException ex) { Logger.getLogger(ScriptJsfBean.class.getName()).log(Level.SEVERE, null, ex); } version = filename = null; return null; } public String getFwPath() { return Util.getFirmwarePath(FacesContext.getCurrentInstance().getExternalContext()); } public String deleteFwFile () { File f = new File (getFwPath()+filename); f.delete(); return null; } public void uploadListener(UploadEvent event) { UploadItem item = event.getUploadItem();/* System.out.println("item : '" + item); System.out.println("File : '" + item.getFileName() + "' was uploaded"); System.out.println("Content-type : '" + item.getContentType()); System.out.println("Data : '" + item.getData()); System.out.println("IsTemporary : '" + item.isTempFile());// System.out.println("Length : '" + item.getData().length); System.out.println("javaFile : '" + item.getFile()); */ if (item.isTempFile()) { } else { try { String fname = item.getFileName(); int i = fname.lastIndexOf('/'); if (i == -1) i = fname.lastIndexOf('\\'); if (i != -1) fname = fname.substring(i); FileOutputStream fout = new FileOutputStream(getFwPath () +fname); fout.write(item.getData()); fout.close(); } catch (Exception e) { // TODO: handle exception } } } public Collection getFiles() { ArrayList<SelectItem> a = new ArrayList<SelectItem>(); try { File fwdir = new File(getFwPath()); for (File f : fwdir.listFiles()) { if (!f.isDirectory()) { a.add(new SelectItem(f.getName())); } } } catch (Exception e) { FacesContext ctx = FacesContext.getCurrentInstance(); ctx.addMessage(null, new FacesMessage (FacesMessage.SEVERITY_ERROR, e.getMessage(), "")); } return a; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -