📄 edit_image_submit.jsp
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page language="java" contentType="text/html; charset=GBK" %>
<%@ page import="com.doone.util.*"%>
<%@ page import="com.doone.data.*"%>
<%@ page import="com.doone.fj1w.bbs.*"%>
<%@ page import="com.doone.uurm.*"%>
<%@ page import="com.doone.fj1w.fjmgr.sysmgr.*"%>
<%@ page import="com.doone.fj1w.fjmgr.config.UpImageBean"%>
<%@ page import="java.util.*"%>
<%@ page import="java.io.*"%>
<%
UpImageBean contentBean = new UpImageBean();
String action = request.getParameter("ACTION");
String sParentId = request.getParameter("PARENT_ID");
String sContentId = request.getParameter("CONTENT_ID");
String sTitle = request.getParameter("TITLE");
String sContent = request.getParameter("LINK");//链接
String sAttchment = request.getParameter("ATTCHMENT");
long lboardId=Sys_Purview.getPurviewIdByCode(sParentId);//栏目ID
boolean bIsint=contentBean.is_int(sContent);
if ((sContent==null)||(sContent.trim().length()==0)||(!bIsint)){
sContent = request.getParameter("LTITLE");//自己输入的链接
}
String sAttchs[] = null;
WebAuth auth = WebAuth.getInstance(request);
if ( sAttchment != null ) {
sAttchs = sAttchment.split("::");
}
//contentBean.delContent(lboardId);
DacClient db = new DacClient();
try {
db.beginTransaction(-1);
TF_Content content = new TF_Content(db, Long.parseLong(sContentId));
// 处理附件内容。
List attchList = new ArrayList();
boolean hasAttch = false;
TF_Attchment[] aAttchList = TF_Attchment.getAttchList(db, content.getContent_ID(), null);
for ( int i=0; i<aAttchList.length; i++ ) {
// 删除已经存在,但初删除的附件。
if ( aAttchList[i].getAttch_Type().equals("2") ) {
if ( sAttchment.indexOf("::||" + aAttchList[i].getFile_Name()) == -1 &&
sAttchment.indexOf("||" + aAttchList[i].getFile_Name()) == -1 ) {
aAttchList[i].delete();
aAttchList[i].save();
}
else {
hasAttch = true;
}
}
else {
if ( sContent.indexOf("AttchMap/" + Long.toString(aAttchList[i].getAttch_ID()) + "/" + aAttchList[i].getFile_Name()) == -1 ) {
aAttchList[i].delete();
aAttchList[i].save();
}
}
}
for ( int i=0; sAttchs!=null && i<sAttchs.length; i++) {
// 添加新附件。
if ( sAttchs[i] == null ) continue;
String aAttch[] = ExtString.split(sAttchs[i],"||",null);
if ( aAttch.length != 2 ) continue;
if ( aAttch[0].length() == 0 ) continue;
String sOldFileName = aAttch[1];
String sFileName = aAttch[0];
String sPathName = "/view/bbs/UploadFile/";
String sFullName = sPathName + sFileName;
String realName = application.getRealPath(sFullName);
File file = new File(realName);
String sFullType=sFileName.substring(sFileName.lastIndexOf(".")).toUpperCase();
if ((( sFullType.indexOf("JPG"))==-1)&&(( sFullType.indexOf("GIF"))==-1)&&(( sFullType.indexOf("SWF"))==-1)){
out.write("<script language=javascript>alert('限制上传除JPG,GIF,SWF格式外的文件');history.go(-1);</script>");
}
if (file.length()>2400000){
out.write("<script language=javascript>alert('限制上传大于2M的文件');history.go(-1);</script>");
}
if ( file.exists() && file.isFile() ) {
TF_Attchment attchment = new TF_Attchment(db);
attchment.setFile_Name(sOldFileName);
attchment.setFile_Size(file.length());
String sExtName = sFileName.substring(sFileName.lastIndexOf("."));
attchment.setFile_Type(ContentType.getContentType(sExtName));
attchment.setUpLoad_Time(new Date());
attchment.setContent_ID(content.getContent_ID());
byte[] bs1 = new byte[(int)attchment.getFile_Size()+1];
FileInputStream is = new FileInputStream(file);
if ( is.read(bs1, 0, (int)attchment.getFile_Size() ) != -1 ) {
attchment.setFile_Content(bs1);
}
else {
FileLogger.getLogger().warn("文件读取数据失败。");
continue;
}
is.close();
int startIdx = sContent.indexOf( sFullName );
if ( startIdx == -1 ) {
int si = sContent.indexOf(sPathName + "/" + sFileName);
if ( si != -1 ) {
sFullName = sPathName + "/" + sFileName;
startIdx = si;
}
}
if ( startIdx != -1 ) {
attchment.setAttch_Type("1"); // 设置附件类别为嵌入内容中的附件。
// 替换文件名。
while ( startIdx != -1 ) {
int endIdx = startIdx + sFullName.length();
startIdx = sContent.lastIndexOf("=\"/", endIdx);
int startIdx1 = sContent.lastIndexOf("=\'/", endIdx);
int startIdx2 = sContent.lastIndexOf("=/", endIdx);
int startIdx3 = sContent.lastIndexOf(">/", endIdx); // Flash图片索引
startIdx = Math.max(startIdx, startIdx1);
startIdx = Math.max(startIdx, startIdx2);
startIdx = Math.max(startIdx, startIdx3);
if (startIdx == startIdx2 || startIdx == startIdx3)
startIdx++;
else
startIdx = startIdx + 2;
String sUrl = "AttchMap/" + String.valueOf(attchment.getAttch_ID());
sUrl += "/" + sOldFileName;
startIdx = sContent.indexOf(sFullName,startIdx);
}
}
else {
hasAttch = true;
// 将没有用到的附件作为独立附件处理。
attchment.setAttch_Type("2");
}
attchList.add(attchment);
if (! file.delete() ) { // 删除文件系统中的附件。
FileLogger.getLogger().warn("附件删除失败:" + sFileName);
}
}
else {
FileLogger.getLogger().info("文件不存在:" + sFileName + ",可能内容中的图片无法显示。");
continue;
}
}
ExtString.replace(sContent, "<IMG src=\"/manager/view/bbs/sysimage/","<IMG src=\"sysimage/");
ExtString.replace(sContent, "src=\"/manager/view/bbs/AttchMap/","src=\"AttchMap/");
ExtString.replace(sContent, "href=\"/manager/view/bbs/AttchMap/","href=\"AttchMap/");
// 插件新内容。
if ( hasAttch ) {
content.setExist_Attch("1");
}
else {
content.setExist_Attch("0");
}
content.setBoard_ID(lboardId);
content.setAccount_ID(auth.getUserID());
content.setAccount_Name(auth.getUserCode());
content.setUser_Name(auth.getUserName());
content.setTitle(sTitle);
content.setContent(sContent.toString());
content.setCreate_Time(new Date());
content.setTip_Order(0);
content.setExtract_Sign("0");
content.setReply_Count(0);
content.setReply_Account_ID(auth.getUserID());
content.setReply_User_Name(auth.getUserName());
content.setLast_Click_Time(new Date());
content.setLast_Reply_Time(new Date());
content.setContentType("03");
content.setDelete_Sign("E");
content.save();
// 保存嵌入内容中的附件。
StringBuffer attchName = new StringBuffer();
for ( int i=0; i< attchList.size(); i++ ) {
TF_Attchment attch = (TF_Attchment)attchList.get(i);
if ( attchName.indexOf("||" + attch.getFile_Name() + "||") != -1 ) {
throw new RuntimeException("您上传的附件有重名,请检查后重新上传。");
}
attchName.append("||").append(attch.getFile_Name()).append("||");
attch.save();
}
// 处理独立的附件。
db.endTransaction(true);
if(action!=null && action.equals("DSKZQK"))
out.write("<script language=javascript>alert('修改成功!');window.location.href='" + request.getContextPath()
+ "/view/edit_web_index/edit_webdsk_index.jsp';</script>");
else
out.write("<script language=javascript>alert('修改成功!');window.location.href='" + request.getContextPath()
+ "/view/edit_web_index/edit_web_index.jsp';</script>");
}
catch(Exception ex) {
try{
db.endTransaction(false);
}
catch(Exception e){}
out.write("<script language=javascript>window.location.href='" + request.getContextPath()
+ "/view/sysmgr/OperFailure.jsp?error=" + Util.Replace(ex.getMessage())
+ "';</script>");
FileLogger.getLogger().warn(ex.getMessage(), ex);
}
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -