📄 template.java
字号:
package com.easyjf.news.business;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import com.easyjf.dbo.EasyJDB;
import com.easyjf.dbo.IObject;
import com.easyjf.web.Globals;
public class Template implements IObject {
private String cid;
private String title;
private String path;//模板路径
private String url;
private Date modifyTime;
private String content;
private Integer types;
private Integer status;
public static Template read(String cid)
{
EasyJDB db=EasyJDB.getInstance();
return (Template)db.get(Template.class,cid);
}
public static Template readByPath(String path)
{
EasyJDB db=EasyJDB.getInstance();
Collection paras=new ArrayList();
paras.add(path);
return (Template)db.read(Template.class,"path=?",paras);
}
public String showPic()
{
if(this.getTypes()!=null && (this.getTypes().intValue()==1))return "folder.gif";
else return "page.gif";
}
public Integer childNum()
{
Integer num=null;
File f=new File(Globals.APP_BASE_DIR+this.path);
if(f.exists())
{
if(f.isDirectory())num=new Integer(f.list().length);
}
return num;
}
public String getTableName() {
// TODO Auto-generated method stub
return "Template";
}
public String getKeyField() {
// TODO Auto-generated method stub
return "cid";
}
public String getKeyGenerator() {
// TODO Auto-generated method stub
return "com.easyjf.dbo.RandomIdGenerator";
}
public boolean save()
{
EasyJDB db=EasyJDB.getInstance();
return db.add(this);
}
public boolean update()
{
EasyJDB db=EasyJDB.getInstance();
return db.update(this);
}
public boolean del()
{
EasyJDB db=EasyJDB.getInstance();
return db.del(this);
}
public boolean delFile()
{
boolean ret=false;
File f=new File(Globals.APP_BASE_DIR+this.path);
if(f.exists())ret=f.delete();
return ret;
}
public boolean saveToFile()
{
boolean ret=false;
File f=new File(Globals.APP_BASE_DIR+this.path);
if(this.getTypes().intValue()==1 && (!f.exists()))f.mkdirs();
else if(!f.isDirectory())
{
try{
if(!f.exists())f.createNewFile();
OutputStream o=new FileOutputStream(f);
OutputStreamWriter out=new OutputStreamWriter(o,"utf-8");
out.write(this.content);
out.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
return ret;
}
public String readFromFile()
{
String c="";
File f=new File(Globals.APP_BASE_DIR+this.path);
if(f.isFile() && f.exists())
{
try{
FileInputStream fin=new FileInputStream(f);
byte[] b=new byte[fin.available()];
fin.read(b);
c=new String(b,"utf-8");
fin.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
return c;
}
public String getCid() {
return cid;
}
public void setCid(String cid) {
this.cid = cid;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public Date getModifyTime() {
return modifyTime;
}
public void setModifyTime(Date modifyTime) {
this.modifyTime = modifyTime;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public Integer getTypes() {
return types;
}
public void setTypes(Integer types) {
this.types = types;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -