📄 textpartservlet.java
字号:
/*
* @(#)TextpartServlet.java
*
* Copyright (C) 2006 Sergey Bredikhin
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package olivax.webmail;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class TextpartServlet extends HttpServlet {
static final long serialVersionUID = 1675075694621323211L;
public TextpartServlet() {
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = null;
try {
request.setCharacterEncoding(Context.clntCp);
response.setContentType("text/html; charset=" + Context.clntCp);
out = response.getWriter();
HttpSession session = request.getSession();
Context myContext = (Context) session.getAttribute("myContext");
if(myContext == null) {
myContext = new Context();
session.setAttribute("myContext", myContext);
}
if(!myContext.isLoggedIn()) {
Context.forward(this, request, response, "/logon");
}
myContext.setNoCache(response);
// Get parameters
int msgno = Integer.parseInt(request.getParameter("msgno"));
int partno = Integer.parseInt(request.getParameter("partno"));
String msguid = request.getParameter("msguid");
String attFileName = request.getParameter("file");
if(attFileName == null)
attFileName = "";
String contentType = request.getParameter("ctnttype");
if(contentType == null)
contentType = "";
if(msguid == null)msguid = "";
String textPartText = myContext.getMessage(msgno, msguid, request.getParameter("cp")).getTextPart(partno);
if (textPartText == null) {
Context.forward(this, request, response, "/list");
return;
}
if(contentType.equalsIgnoreCase("text/html")) {
out.print(textPartText);
return;
}
// Main page
StringBuffer sb = new StringBuffer();
sb.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\r\n");
sb.append("<html>\r\n");
sb.append("<head>\r\n");
sb.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=").append(Context.clntCp).append("\">\r\n");
// sb.append("<meta http-equiv=\"Content-Language\" content=\"ru-RU\">\r\n");
sb.append("<meta HTTP-EQUIV=\"PRAGMA\" content=\"NO-CACHE\">\r\n");
sb.append("<title>\r\n");
sb.append(attFileName).append("\r\n");
sb.append("</title>\r\n");
sb.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"./oliva.css\">\r\n");
sb.append("</head>\r\n");
sb.append("<body link=\"#000033\" alink=\"#000033\" vlink=\"#000033\">\r\n");
out.print(sb.toString());
// Main pane
sb = new StringBuffer();
if (contentType.startsWith("text/")) {
textPartText = "<font face=\"Courier\" size=\"2\">"
+ oliva.mail.MailUtils.replaceODOA(textPartText
.replaceAll("<", "<")
.replaceAll(">", ">"), "<br/>") + "</font>";
} else if (contentType.equalsIgnoreCase("message/delivery-status"))
textPartText = "<pre>" + textPartText + "</pre>";
else if (contentType.equalsIgnoreCase("message/partial"))
textPartText = "<h3>"
+ myContext.getI18nString("_str_mb_splitted") + "</h3>";
sb.append(textPartText);
WebPage webPage = new WebPage();
WebPane webPane = new WebPane();
webPane = new WebPane();
webPane.setColor(WebPane.COLOR_9999CC);
// webPane.setHeight("200");
webPane.setContent(sb.toString());
webPage.addPane(webPane);
webPage.show(out);
sb = new StringBuffer();
sb.append("</body>\r\n");
sb.append("</html>\r\n");
out.print(sb.toString());
out.flush();
out.close();
} catch (Exception e) {
try {
Context.sendErrorRedirect(this, request, response, "/error", e);
} catch (Exception exc) {
exc.printStackTrace();
}
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -