亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? contentcontainer.java

?? 使用工具jublider開發的一個聊天室實現基本功能,
?? JAVA
字號:
/**
 * Copyright (C) 2003  Manfred Andres
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

/**
 * The ContentContainer is used for delivering the entry-page, error-page, ...
 */
package freecs.content;

import freecs.*;
import freecs.interfaces.*;
import freecs.layout.*;
import freecs.util.HttpDateParser;

import java.nio.charset.Charset;
import java.nio.charset.CharacterCodingException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;


public class ContentContainer implements IResponseHeaders, IContainer {
   private ByteBuffer   buf;
   private TemplateSet  ts;
   private String 		tName;
   private Template		tpl;
   private String		cookie,
						contentType="text/html";
   
   private String       eTag;
   private boolean      notModified=false;

   private volatile boolean	chunkedHdr, 
   						nocache=false, 
   						nostore=false,
						keepAlive = false, 
						isMessages = false,
						isRedirect, 
						isHTTP11=true;

	private short 		resCode = 200;
	
   public ContentContainer () {
       if (Server.TRACE_CREATE_AND_FINALIZE)
           Server.log (this, "++++++++++++++++++++++++++++++++++++++++CREATE", Server.MSG_STATE, Server.LVL_VERY_VERBOSE);
   }

	/**
	 * wraps the cntnt param into a fully http-response with the wanted headerfields
	 * @param cntnt
	 */
   public void wrap (String cntnt) {
       wrap(cntnt, null);
   }
   public void wrap (String cntnt, String eTag) {
	   StringBuffer sb = new StringBuffer ();
	   sb.append (isHTTP11 ? "HTTP/1.1" : "HTTP/1.0");
	   switch (resCode) {
	   	case OK_CODE:
	   		sb.append (OK_HDR);
	   		break;
	   	case REDIRECT_CODE:
	   		setRedirectTo (cntnt);
	   		break;
        case NOCONTENT_CODE:
            sb.append (NOCONTENT_HDR);
            prepareForSending (CharBuffer.wrap(sb.toString()));
            return;
        case AUTHENTICATE_CODE:
        	sb.append (AUTHENTICATE_HDR);
        	contentType="text/html";
        	break;
        case NOTFOUND_CODE:
            sb.append (NOTFOUND_HDR);
            contentType="text/html";
            break;
        }
		sb.append ("Content-Type: ");
		sb.append (contentType);
		sb.append ("; charset=");
		sb.append (Server.srv.DEFAULT_CHARSET);
		if (nocache) {
			sb.append ("\r\nPragma: no-cache\r\nCache-Control: no-cache");
            sb.append ("\r\nExpires: Thu, 01 Dec 1994 16:00:00 GMT");
		} 
        if (nostore) {
			sb.append ("\r\nCache-Control: no-store");
		}
        if (eTag != null) {
            sb.append ("\r\nETag: \"").append(eTag).append("\"");
            //Server.log (this, "sending eTag: " + eTag, Server.MSG_STATE, Server.LVL_MAJOR);
        }

		sb = appendCookie (sb);

		if (!isHTTP11 || !keepAlive || isMessages) {
			sb.append ("\r\nConnection: close\r\nProxy-Connection: close");
		} else {
			sb.append ("\r\nConnection: Keep-Alive\r\nProxy-Connection: Keep-Alive");
			if (!chunkedHdr) {
				sb.append("\r\nContent-Length: ");
				sb.append (cntnt.length ());
			}
		}
		if (chunkedHdr) {
			sb.append ("\r\nTransfer-Encoding: chunked\r\n\r\n");
			sb.append (Integer.toHexString (cntnt.length ()));
			sb.append ("\r\n");
			sb.append (cntnt);
			sb.append ("\r\n");
			prepareForSending(CharBuffer.wrap (sb.toString()));
			return;
		}
		sb.append ("\r\n\r\n");
        if ("iso-8859-1".equals(Server.srv.DEFAULT_CHARSET)) {
            sb.append(cntnt);
            prepareForSending(CharBuffer.wrap(sb.toString()));
        } else {
            CharBuffer hdrChar = CharBuffer.wrap(sb.toString());
    		prepareForSending(hdrChar, CharBuffer.wrap (cntnt));
        }
   }
   
   /**
    * sets the HTTP-Response-Code
    * @param code
    */
   public void setResCode (short code) {
		resCode=code;
   }

	/**
	 * append the cookie-header-field to the given StringBuffer
	 * @param sb the stringbuffer to append the cookie-header-field
	 * @return the stringbuffer with the cookie-header-field appended
	 */
   public StringBuffer appendCookie (StringBuffer sb) {
      if (cookie == null) return sb;
      sb.append ("\r\n");
      sb.append ("Set-Cookie: FreeCSSession=");
      sb.append (cookie);
      sb.append ("; path=/;");
      if (Server.srv.COOKIE_DOMAIN != null) {
      	sb.append (" Domain=");
      	sb.append (Server.srv.COOKIE_DOMAIN);
      }
      return sb;
   }

   /**
	* causes this content-container to use a specific template-set
	* @param ts the template-set to use
	*/
   public void useTemplateSet (TemplateSet ts) {
      this.ts = ts;
   }

	/**
	 * set the template to be rendered for this content-container
	 * @param tName the name of the template
	 */
   public void setTemplate (String tName) {
      this.tName = tName;
   }

	/**
	 * renders the template and wraps it to a full httpresponse
	 */
   public void renderTemplate (IRequest req) {
      if (tpl == null) {
         if (this.ts == null) 
             ts = Server.srv.templatemanager.getTemplateSet ("default");
         tpl = ts.getTemplate (tName);
         if (tpl == null) 
             tpl = ts.getTemplate ("not_found");
      }
      if (tpl.isRedirect ()) {
         this.setRedirectTo(tpl.getDestination ());
         return;
      }
      if (!nocache && !nostore && 
              !tpl.hasToBeRendered(req.getProperty("if-none-match"), 
              HttpDateParser.parseDate(req.getProperty("if-modified-since")))) {
          StringBuffer sb = new StringBuffer ();
          sb.append (isHTTP11 ? "HTTP/1.1" : "HTTP/1.0");
          sb.append (IResponseHeaders.NOT_MODIFIED);
          prepareForSending(CharBuffer.wrap (sb.toString()));
          return;
      }
      String cntnt = tpl.render (req);
      if (cntnt==null || cntnt.length () < 1) {
         Server.log (this, "renderTemplate: rendered template has no content", Server.MSG_STATE, Server.LVL_MAJOR);
         resCode=NOCONTENT_CODE;
         StringBuffer sb = new StringBuffer ();
         sb.append ("<html><body><b>The requested page could not be displayed!<br><br>Reason:</b> ");
         if (tpl == null) {
             sb.append ("No template given");
         } else {
             sb.append ("Template '");
             sb.append (tpl.getName());
             sb.append ("' has not been found on this server.");
         }
         sb.append ("</body></html>");
         wrap (sb.toString());
         return;
      }
      nocache=tpl.notCacheable();
//      if (nocache)
//          Server.log (this, "not cacheable", Server.MSG_STATE, Server.LVL_VERY_VERBOSE);
      wrap (cntnt, tpl.getEtag());
   }

	/**
	 * causes the response to be a chunked response
	 * the calling method has to care, that the other chunks are sent correctly
	 */
   public void useChunkedHeader () {
      chunkedHdr = true;
      keepAlive = true;
   }

	/**
	 * set/unset the keep-alive header field
	 * @param b
	 */
   public void setKeepAlive (boolean b) {
      keepAlive = b;
   }

	/**
	 * mark this http-response as http11(true)/http10(false)
	 * @param b
	 */
   public void setHTTP11 (boolean b) {
      isHTTP11 = b;
      keepAlive = true;
   }

	/**
	 * check if this response is a HTTP11 response
	 * @return boolean true if response is a HTTP11 response, false if not
	 */
   public boolean isHttp11 () {
      return isHTTP11;
   }

	/**
	 * set the cookievalue to append to the response-header-fields
	 * @param cookie
	 */
   public void setCookie (String cookie) {
      this.cookie = cookie;
   }

	/**
	 * return the bytebuffer which is ready to send
	 */
   public ByteBuffer getByteBuffer () {
      return buf;
   }

   /**
    * return the content type setting
    */
   public String getContentType() {
      return contentType;
   }

   /**
    * set the content type setting
    */
   public void setContentType(String contentType) {
      this.contentType = contentType;
   }
   
	/**
	 * prepares the response for sending
	 * if a template is set, it will be rendered
	 * if no charbuffer is present, even after rendering the template, 
	 * there is nothing to send and prepareForSending will just return
	 */
   public void prepareForSending (CharBuffer cb) {
       if (cb == null || cb.length() < 1)
           return;
       try {
           buf = Charset.forName ("iso-8859-1").newEncoder().encode(cb);
           return;
       } catch (CharacterCodingException cce) {
           Server.debug (this, "prepareForSending: ", cce, Server.MSG_ERROR, Server.LVL_MINOR);
       }
   }
   
   public void prepareForSending (CharBuffer hdr, CharBuffer cntnt) {
       if (hdr == null || hdr.capacity() < 1)
           return;
       try {
           ByteBuffer hdrBytes = Charset.forName("iso-8859-1").newEncoder().encode(hdr);
           ByteBuffer cntntBytes = Charset.forName (Server.srv.DEFAULT_CHARSET).newEncoder().encode(cntnt);
           buf = ByteBuffer.allocate(hdrBytes.capacity() + cntntBytes.capacity());
           buf.put(hdrBytes);
           buf.put(cntntBytes);
           buf.flip();
       } catch (Exception e) {
           Server.debug (this, "Exception during prepareForSending(hdr/cntnt)", e, Server.MSG_ERROR, Server.LVL_MAJOR);
       }
   }


    public boolean prepareForSending (IRequest req) {
        if (tName != null || tpl != null) 
            renderTemplate (req);
        if (buf == null)
            return false;
        return true;
    }
    
    public void setContent (byte[] cntnt) throws Exception {
        StringBuffer sb = new StringBuffer();
        sb.append (isHTTP11 ? "HTTP/1.1" : "HTTP/1.0");
        sb.append (OK_HDR);
        sb.append ("Content-Type: ");
        sb.append (contentType);
        if (!isHTTP11 || !keepAlive || isMessages) {
            sb.append ("\r\nConnection: close\r\nProxy-Connection: close");
        } else {
            sb.append ("\r\nConnection: Keep-Alive\r\nProxy-Connection: Keep-Alive");
            sb.append("\r\nContent-Length: ");
            sb.append (cntnt.length);
        }
        sb.append ("\r\n\r\n");
        CharBuffer cb = CharBuffer.wrap (sb.toString());
        ByteBuffer tempBuffer;
        try {
            tempBuffer = Charset.forName ("iso-8859-1").newEncoder().encode(cb);
        } catch (CharacterCodingException cce) {
            Server.debug (this, "prepareForSending: ", cce, Server.MSG_ERROR, Server.LVL_MINOR);
            try {
                tempBuffer = ByteBuffer.wrap (cb.toString().getBytes(Server.srv.DEFAULT_CHARSET));
            } catch (Exception e) {
               Server.debug (this, "prepareForSending: ", e, Server.MSG_ERROR, Server.LVL_MAJOR);
               throw e;
            }
        }
        this.buf = ByteBuffer.allocate(tempBuffer.capacity() + cntnt.length);
        this.buf.put(tempBuffer.array());
        this.buf.put(cntnt);
        this.buf.flip();
    }

   public boolean hasContent () {
      return (buf != null);
   }

   public boolean closeSocket () {
      return (!isHTTP11 || !keepAlive) && !isMessages;
   }
   public void setIsMessages () {
	  this.isMessages = true;
   }
   public void setNoCache () {
	  nocache = true;
   }
   public void setNoStore () {
	  nostore = true;
   }

   /**
    * construct a HTTP-Redirect-Response
    * 
    * @param dest the destination to redirect to
    */
    public void setRedirectTo(String dest) {
        StringBuffer cntnt = new StringBuffer();
        cntnt.append("<html><head><title>redirection</title><head><body>Redirected to <a href=\"");
        cntnt.append(dest);
        cntnt.append("\">");
        cntnt.append(dest);
        cntnt.append("</a>");
        cntnt.append("</body></html>");
        int len = cntnt.length();
        StringBuffer sb = new StringBuffer();
        sb.append(isHTTP11 ? "HTTP/1.1" : "HTTP/1.0");
        sb.append(REDIRECT_HDR);
        sb.append(Server.srv.DEFAULT_CHARSET);
        sb.append("\r\nLocation: ");
        sb.append(dest);
        sb.append("\r\nContent-Length: ");
        sb.append(len);
        sb = appendCookie(sb);
        sb.append("\r\n\r\n");
        if ("iso-8859-1".equals(Server.srv.DEFAULT_CHARSET)) {
            sb.append(cntnt);
            prepareForSending(CharBuffer.wrap(sb.toString()));
        } else {
            CharBuffer hdrChar = CharBuffer.wrap(sb.toString());
            prepareForSending(hdrChar, CharBuffer.wrap(cntnt));
        }
        isRedirect = true;
    }
  
    public void finalize() {
        if (Server.TRACE_CREATE_AND_FINALIZE)
            Server.log(this, "----------------------------------------FINALIZED", Server.MSG_STATE, Server.LVL_VERY_VERBOSE);
    }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
99久久99久久精品国产片果冻| 美女网站色91| 欧美性做爰猛烈叫床潮| 亚洲午夜免费电影| 欧美巨大另类极品videosbest | 日韩国产欧美在线观看| 这里只有精品免费| 精品一区二区三区在线观看| 国产视频在线观看一区二区三区 | 精品一区二区三区免费播放| 日韩精品一区在线观看| 成人av资源站| 亚洲777理论| 久久一区二区三区四区| 91丨九色丨国产丨porny| 五月天视频一区| 久久看人人爽人人| 在线中文字幕一区| 极品美女销魂一区二区三区| 国产精品久久久久久久蜜臀| 欧美午夜精品久久久久久孕妇| 久久精品99久久久| 最新国产精品久久精品| 91精品国模一区二区三区| 豆国产96在线|亚洲| 亚洲最大色网站| 久久久亚洲高清| 欧美在线观看视频在线| 国产麻豆精品在线| 亚洲mv在线观看| 国产精品免费人成网站| 欧美一区二区三区视频在线 | 在线欧美日韩国产| 久久aⅴ国产欧美74aaa| 亚洲日本在线天堂| 久久久久久日产精品| 欧美性大战xxxxx久久久| 国产suv精品一区二区883| 性做久久久久久免费观看 | 亚洲一区二区三区自拍| 久久品道一品道久久精品| 欧美日韩色一区| 91日韩精品一区| 国产精品99久久久久久有的能看| 亚洲成人激情av| 成人免费视频在线观看| 久久久国产精品不卡| 制服丝袜av成人在线看| 在线一区二区三区四区| 99精品黄色片免费大全| 国产毛片精品视频| 久久99深爱久久99精品| 五月婷婷另类国产| 亚洲伊人色欲综合网| 国产精品美女一区二区三区| 精品国产成人系列| 51精品国自产在线| 精品视频在线免费看| 99精品黄色片免费大全| 成人夜色视频网站在线观看| 激情综合色丁香一区二区| 日韩影院精彩在线| 五月天一区二区三区| 夜夜嗨av一区二区三区四季av| 欧美国产乱子伦| 国产亚洲精久久久久久| 欧美精品一区二| 精品福利在线导航| 精品美女一区二区| 欧美大白屁股肥臀xxxxxx| 91麻豆精品国产91久久久使用方法| 一本一本大道香蕉久在线精品 | 欧美天天综合网| 91精彩视频在线观看| 色综合 综合色| 在线中文字幕一区二区| 欧美三级视频在线观看| 欧美精品九九99久久| 56国语精品自产拍在线观看| 日韩一区和二区| 日韩精品一区在线观看| 久久久久久久综合| 中文av一区特黄| 亚洲欧洲www| 夜夜精品视频一区二区| 图片区小说区国产精品视频| 三级久久三级久久| 国产中文一区二区三区| 国产一区视频在线看| 国产91丝袜在线播放| 91网上在线视频| 欧美日韩国产综合一区二区三区| 7777精品伊人久久久大香线蕉最新版 | 色综合 综合色| 欧美另类高清zo欧美| 欧美成人伊人久久综合网| 国产性天天综合网| 亚洲欧美怡红院| 视频一区欧美日韩| 国产在线播精品第三| 91亚洲精品久久久蜜桃| 欧美私人免费视频| 久久综合久久鬼色中文字| 中文字幕日韩精品一区| 亚洲国产日韩精品| 国产剧情一区在线| 欧美性大战久久久| 精品日韩欧美一区二区| 亚洲日本丝袜连裤袜办公室| 首页国产丝袜综合| 国产成人精品免费看| 欧美色男人天堂| 国产欧美视频一区二区三区| 亚洲乱码国产乱码精品精可以看| 免费观看在线色综合| av不卡在线观看| 欧美一级高清大全免费观看| 中文字幕不卡在线播放| 午夜在线电影亚洲一区| 成人激情免费网站| 91精品国产一区二区人妖| 国产精品色在线| 另类的小说在线视频另类成人小视频在线 | 欧美α欧美αv大片| 国产精品国产自产拍高清av王其| 香蕉av福利精品导航| 成人白浆超碰人人人人| 日韩免费视频一区| 亚洲福中文字幕伊人影院| 成人激情午夜影院| 日韩欧美二区三区| 亚洲国产一区二区三区 | 亚洲午夜一区二区| 波多野结衣精品在线| 精品久久久久久无| 日韩极品在线观看| 在线亚洲高清视频| 国产精品成人在线观看| 国产精品自拍av| 日韩视频一区在线观看| 亚洲成人中文在线| 91小视频免费看| 国产精品日韩成人| 国产福利一区在线观看| 精品欧美一区二区在线观看| 香蕉影视欧美成人| 欧美三级三级三级| 亚洲制服欧美中文字幕中文字幕| 成人av电影免费在线播放| 久久综合视频网| 极品少妇一区二区三区精品视频| 欧美高清激情brazzers| 午夜精品一区在线观看| 欧美日韩国产高清一区二区三区| 亚洲精品免费一二三区| 99久久精品免费精品国产| 欧美韩国一区二区| 精品无码三级在线观看视频| 欧美日韩国产电影| 一区二区三区久久| 99视频国产精品| 国产精品久久久久久久久久久免费看 | 国产精品欧美久久久久无广告| 国产精品一级片在线观看| 欧美tk—视频vk| 黄色精品一二区| 久久精品人人爽人人爽| 国产成人av电影免费在线观看| 久久一二三国产| 国产成人精品三级麻豆| 国产精品网站一区| 99久久99久久精品国产片果冻| 1区2区3区国产精品| 91在线播放网址| 亚洲国产精品一区二区尤物区| 欧美日韩国产一区| 轻轻草成人在线| 日韩精品一区二区三区三区免费 | 久久成人羞羞网站| 久久只精品国产| 成人av午夜电影| 亚洲乱码国产乱码精品精的特点| 91色porny在线视频| 午夜精品福利一区二区三区蜜桃| 日韩三级中文字幕| 国产成人高清在线| 亚洲精品免费在线观看| 555夜色666亚洲国产免| 国产一区二区三区电影在线观看| 欧美激情综合在线| 欧美无乱码久久久免费午夜一区| 天堂影院一区二区| 久久先锋资源网| 91小视频免费观看| 日韩在线卡一卡二| 中文字幕第一区第二区| 欧美日韩中文精品| 国产精品 日产精品 欧美精品| 亚洲乱码中文字幕| 日韩精品一区二区三区中文精品 |