⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pdatextpartservlet.java

📁 一个简单的java邮件系统
💻 JAVA
字号:
/*
 * @(#)PdaTextpartServlet.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 PdaTextpartServlet extends HttpServlet {

	static final long serialVersionUID = 1675075694621323211L;	
	
	public PdaTextpartServlet() {
	}

	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, "/pda_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;
			  }

			    PdaPage pdaPage = new PdaPage();
			    pdaPage.setTitle(attFileName);
			    
			    //Logo		    		    
			    pdaPage.addPane(myContext.getPdaLogo());
			    
			    //Title
			    PdaPane pdaPane = new PdaPane();
			    pdaPane.setColor(PdaPane.COLOR_CCCCCC);
			    pdaPane.setHeight("20");
			    pdaPane.setContent("<font size=\"3\" face=\"arial, tahoma, verdana\"><strong>" +
			    		attFileName + "</strong></font>");
			    pdaPage.addPane(pdaPane);		    
			  
			  
			// Main page
			StringBuffer sb = new StringBuffer();
			if (contentType.startsWith("text/")) {
				textPartText = "<font face=\"Courier\" size=\"3\">"
						+ oliva.mail.MailUtils.replaceODOA(textPartText
								.replaceAll("<", "&lt;")
								.replaceAll(">", "&gt;"), "<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);
			
		    pdaPane = new PdaPane();
		    pdaPane.setColor(PdaPane.COLOR_9999CC);
		    pdaPane.setContent(sb.toString());
		    pdaPage.addPane(pdaPane);		    		    

		    //Sublogo
		    pdaPane = new PdaPane();
		    pdaPane.setColor(PdaPane.COLOR_CCFF99);
		    pdaPane.setHeight("20");
		    pdaPane.setContent("<font size=\"3\" color=\"#999966\" face=\"arial, tahoma, verdana\"><strong><i>"
		    		+ myContext.getSenderDomain() + "</i></strong></font>");
		    pdaPage.addPane(pdaPane);		    		    		    
		    
		    pdaPage.show(out);

		    out.flush();
		    out.close();	    		    						
		} catch (Exception e) {
			try {
				Context.sendErrorRedirect(this, request, response, "/pda_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 + -