📄 dloglogaction.java
字号:
user.getDisplayName());
old.setContent(reply.getContent() + append_text);
}
else
old.setContent(reply.getContent());
old.setShowFormerly(reply.getShowFormerly());
ssn.update(old);
SearchProxy proxy = SearchProxy.getReplyQuery();
proxy.updateIndex(old);
}
}catch(HibernateException e) {
}finally{
commitSession(ssn,true);
}
else
return mapping.findForward("fail_to_reply");
StringBuffer forward = new StringBuffer();
forward.append(mapping.getInput());
forward.append("?log_id=");
forward.append(reply.getLogId());
forward.append("&cat_id=");
forward.append(reply.getLog().getCategoryId());
forward.append('#');
forward.append(reply.getId());
return new ActionForward(forward.toString(), true);
}
/**
* 根据编辑模式决定如何处理修改戳
* @param req
* @param html
* @param userName
* @return
*/
protected String getModifyAppendMessage(HttpServletRequest req, boolean html, String loginName,String userName) {
Object[] args = new String[] {Globals.FORMAT_DT.format(new Date()),loginName,userName};
String append_text = getResources(req).getMessage(req.getLocale(),MODIFY_APPEND_FORMAT,args);
if(!html) {
try {
Parser p = Parser.createParser(new String(append_text.getBytes(),"8859_1"));
NodeIterator nodes = p.elements();
while(nodes.hasMoreNodes()) {
Node node = nodes.nextNode();
append_text = node.toPlainTextString().trim();
append_text = "\r\n\r\n"+new String(StringUtils.replace(append_text," "," ").getBytes("8859_1"));
break;
}
}catch(Exception e) {}
}
return append_text;
}
/**
* 日志删除
* @param ActionMapping mapping
* @param ActionForm form
* @param HttpServletRequest request
* @param HttpServletResponse response
* @return ActionForward
* @throws Exception
*/
public ActionForward doDeleteLog(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
String forward = "home";
LogForm log = (LogForm) form;
//判断用户是否已登录
UserForm user = UserForm.getLoginUser(request);
if (user != null && user.isLogin()) {
Session ssn = getSession();
LogForm old = (LogForm) ssn.load(LogForm.class, new Integer(log.getId()));
if(old!=null)
try {
old.setStatus(LogForm.STATUS_DELETED);
old.setDeleteTime(new Date());
ssn.update(old);
SearchProxy proxy = SearchProxy.getLogQuery();
proxy.deleteIndex(new int[] {old.getId()});
} finally {
commitSession(ssn, true);
}
}
return new ActionForward(mapping.findForward(forward).getPath()+"?cat_id="+log.getCategoryId(), true);
}
/**
* 删除草稿
* @param ActionMapping mapping
* @param ActionForm form
* @param HttpServletRequest request
* @param HttpServletResponse response
* @return ActionForward
* @throws Exception
*/
public ActionForward doDeleteDraft(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
String forward = "draft";
LogForm log = (LogForm) form;
//判断用户是否已登录
UserForm user = UserForm.getLoginUser(request);
if (user != null && user.isLogin() && (user.isAdmin() || user.isFriend())) {
Session ssn = null;
try {
ssn = getSession();
int draft_id = Integer.parseInt(request.getParameter(PARAM_DRAFT));
DraftForm draft = (DraftForm)ssn.load(DraftForm.class,new Integer(draft_id));
ssn.delete(draft);
} finally {
commitSession(ssn, true);
}
} else
forward = "home";
return mapping.findForward(forward);
}
/**
* 更新草稿
* @param ActionMapping mapping
* @param ActionForm form
* @param HttpServletRequest request
* @param HttpServletResponse response
* @return ActionForward
* @throws Exception
*/
public ActionForward doUpdateDraft(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
String forward = "draft";
LogForm log = (LogForm) form;
//判断用户是否已登录
UserForm user = UserForm.getLoginUser(request);
if(user==null||!user.isLogin())
forward = "home";
else
if (user.isAdmin() || user.isFriend()) {
Session ssn = null;
try {
ssn = getSession();
int draft_id = Integer.parseInt(request.getParameter(PARAM_DRAFT));
DraftForm draft = (DraftForm)ssn.load(DraftForm.class,new Integer(draft_id));
if(!user.isAdmin() && draft.getOwner().getId()!=user.getId()) {
ActionErrors errors = new ActionErrors();
errors.add("updateDraft",new ActionError("operation_not_allow"));
if(!errors.isEmpty())
saveErrors(request,errors);
}
else {
draft.setAuthor(log.getAuthor());
draft.setAuthorUrl(log.getAuthorUrl());
draft.setContent(log.getContent());
draft.setLogTime(new Date());
draft.setMoodLevel(log.getMoodLevel());
draft.setOwner(user);
draft.setRefUrl(log.getRefUrl());
draft.setShowFormerly(log.getShowFormerly());
draft.setSite(SiteManager.getCurrentSite(request));
draft.setTitle(log.getTitle());
draft.setUseFace(log.getUseFace());
draft.setUseUbb(log.getUseUbb());
draft.setWeather(log.getWeather());
ssn.update(draft);
}
} finally {
commitSession(ssn, true);
}
} else
forward = "home";
return mapping.findForward(forward);
}
/**
* 日志保存为草稿
* @param ActionMapping mapping
* @param ActionForm form
* @param HttpServletRequest request
* @param HttpServletResponse response
* @return ActionForward
* @throws Exception
*/
public ActionForward doSaveDraft(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
String forward = "draft";
LogForm log = (LogForm) form;
//判断用户是否已登录
UserForm user = UserForm.getLoginUser(request);
if (user != null && user.isLogin() && (user.isAdmin() || user.isFriend())) {
Session ssn = null;
DraftForm draft = new DraftForm();
draft.setAuthor(log.getAuthor());
draft.setAuthorUrl(log.getAuthorUrl());
draft.setContent(log.getContent());
draft.setLogTime(new Date());
draft.setMoodLevel(log.getMoodLevel());
draft.setOwner(user);
draft.setRefUrl(log.getRefUrl());
draft.setShowFormerly(log.getShowFormerly());
draft.setSite(SiteManager.getCurrentSite(request));
draft.setTitle(log.getTitle());
draft.setUseFace(log.getUseFace());
draft.setUseUbb(log.getUseUbb());
draft.setWeather(log.getWeather());
try {
ssn = getSession();
ssn.save(draft);
} finally {
commitSession(ssn, true);
}
} else{
forward = "fail_to_save";
}
return mapping.findForward(forward);
}
/**
* 日志修改
* @param ActionMapping mapping
* @param ActionForm form
* @param HttpServletRequest request
* @param HttpServletResponse response
* @return ActionForward
* @throws Exception
*/
public ActionForward doEditLog(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
String forward = "showlog";
LogForm log = (LogForm) form;
//判断用户是否已登录
UserForm user = UserForm.getLoginUser(request);
if (user != null && user.isLogin()) {
Session ssn = getSession();
LogForm old = (LogForm) ssn.load(LogForm.class, new Integer(log.getId()));
old.setTitle(log.getTitle());
boolean needModifier = true;
if(old.getOwner().getId()==user.getId()){
long ct = System.currentTimeMillis();
long interval = (ct - old.getLogTime().getTime())/3600000;
if(interval < 6)
needModifier = false;
}
if(needModifier){
String append_text = getModifyAppendMessage(request,log.getShowFormerly()!=1,
user.getLoginName(),user.getDisplayName());
old.setContent(log.getContent()+append_text);
}
else
old.setContent(log.getContent());
old.setAuthor(log.getAuthor());
old.setAuthorUrl(log.getAuthorUrl());
old.setMoodLevel(log.getMoodLevel());
old.setRefUrl(log.getRefUrl());
old.setWeather(log.getWeather());
old.setUseUbb(log.getUseUbb());
old.setUseFace(log.getUseFace());
old.setShowFormerly(log.getShowFormerly());
old.setSearchKey(log.getSearchKey());
old.setReplyNotify(log.getReplyNotify());
if (log.getCategoryId() != old.getCategoryId()) {
CategoryForm cat =
(CategoryForm) ssn.load(
CategoryForm.class,
new Integer(log.getCategoryId()));
old.setCategory(cat);
}
try {
ssn.update(old);
SearchProxy proxy = SearchProxy.getLogQuery();
proxy.updateIndex(old);
} finally {
commitSession(ssn, true);
}
} else{
return mapping.findForward("fail_to_save");
}
return new ActionForward(mapping.findForward(forward).getPath()+"?log_id=" + log.getId(),true);
}
/**
* 日志添加
* @param ActionMapping mapping
* @param ActionForm form
* @param HttpServletRequest request
* @param HttpServletResponse response
* @return ActionForward
* @throws Exception
*/
public ActionForward doAddLog(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
String forward = "home";
LogForm log = (LogForm) form;
//判断用户是否已登录
UserForm user = UserForm.getLoginUser(request);
if (user!=null && user.isLogin()) {
log.setOwner(user);
if (log.getLogTime() == null)
log.setLogTime(new Date());
Session ssn = getSession();
try {
SiteForm site = SiteManager.getCurrentSite(request);
log.setSite(site);
ssn.save(log);
int draftId = -1;
try {
draftId = Integer.parseInt(request.getParameter(PARAM_DRAFT));
}catch(Exception e) {}
if(draftId!=-1) {
DraftForm draft = (DraftForm)ssn.load(DraftForm.class,new Integer(draftId));
if(draft!=null)
ssn.delete(draft);
}
//判断是否添加书签
if("1".equals(request.getParameter("bookmark"))) {
BookMarkBean bmb = new BookMarkBean(log.getSite(),user,log);
bmb.setCreateTime(new Date());
bmb.setType(BookMarkBean.BM_LOG);
ssn.save(bmb);
}
if(StringUtils.isNotEmpty(log.getRefUrl())){
//启动TrackBack线程
final LogForm logForm = log;
final SiteForm siteForm = site;
final String log_url = RequestUtils.getBaseURL(request);
final Action action = this;
new Thread(){
public void run(){
try{
TrackBackResp resp = BlogTrackBack.track(logForm.getRefUrl(),
log_url+"/showlog.jspe?log_id="+logForm.getId(),
siteForm.getDisplayName(),
logForm.getTitle(),
"");
}catch(Exception e){
action.getServlet().log("TrackBack Failed. url="+logForm.getRefUrl(),e);
}
}
}.start();
}
} finally {
commitSession(ssn, true);
}
}
else{
//用户在操作时会话已经超时,显示刚才添加的信息给用户避免丢失。
return mapping.findForward("fail_to_save");
}
return new ActionForward(mapping.findForward(forward).getPath()+"?cat_id="+log.getCategoryId(),true);
}
/**
* 得到一个唯一的文件名
* @param extName
* @return
*/
protected String getUniqueFileName(String extName) {
final SimpleDateFormat sdf =
new SimpleDateFormat("yyyyMMddHHmmssSSSS.");
String fn = null;
do {
fn = sdf.format(new Date()) + extName;
if (new File(uploadDir + fn).exists())
continue;
break;
} while (true);
return fn;
}
/**
* 获取文件的扩展名
* @param file
* @return
*/
protected static String getFileExtendName(String file) {
int idx = file.lastIndexOf('.');
return (idx == -1 || idx == (file.length() - 1))
? ""
: file.substring(idx + 1).toLowerCase();
}
/**
* 获取上传文件保存的目录全路径
* @return
*/
protected String getUploadDir() {
String path = servlet.getServletContext().getInitParameter("uploadDir");
if (path == null)
path = "uploads";
String webpath = servlet.getServletContext().getRealPath(path);
if (webpath.endsWith(File.separator))
webpath += File.separator;
return webpath;
}
public static void main(String[] args) {
//System.out.println("EXTEND:"+getUniqueFileName("jpg"));
}
/**
* 获得忘记密码提示内容的模板
* @return
* @throws IOException
*/
protected String getContentTemplate() throws IOException{
ServletContext sc = getServlet().getServletContext();
InputStream in = sc.getResourceAsStream("/WEB-INF/template/reply_tip.html");
StringBuffer template = new StringBuffer(512);
BufferedReader reader = null;
try{
reader = new BufferedReader(new InputStreamReader(in));
do{
String line = reader.readLine();
if(line==null)
break;
template.append(line);
template.append("\r\n");
}while(true);
}finally{
in.close();
}
return template.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -