88250

Java

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  82 随笔 :: 0 文章 :: 5 评论 :: 0 Trackbacks

#

好久没贴过代码了,心血来潮。

/*
 * Copyright (c) 2009, 2010, B3log Team
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.b3log.latke.servlet.filter;

import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.GZIPOutputStream;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;

/**
 * Abstract HTTP response GZIP filter.
 *
 * @author Liang Ding
 * @version 1.0.0.1, Dec 16, 2010
 */
public abstract class AbstractGZIPFilter implements Filter {

    /**
     * Logger.
     */
    private static final Logger LOGGER =
            Logger.getLogger(AbstractGZIPFilter.class.getName());

    @Override
    public void init(final FilterConfig cfg) throws ServletException {
    }

    /**
     * Wraps the http servlet response with GZIP if could.
     *
     * @param request the specified request
     * @param response the specified response
     * @param chain filter chain
     * @throws IOException io exception
     * @throws ServletException servlet exception
     */
    @Override
    public void doFilter(final ServletRequest request,
                         final ServletResponse response,
                         final FilterChain chain) throws IOException,
                                                         ServletException {
        final HttpServletRequest httpServletRequest =
                (HttpServletRequest) request;
        final String requestURI = httpServletRequest.getRequestURI();
        if (shouldSkip(requestURI)) {
            LOGGER.log(Level.FINEST, "Skip GZIP filter request[URI={0}]",
                       requestURI);
            chain.doFilter(request, response);

            return;
        }

        final String acceptEncoding =
                httpServletRequest.getHeader("Accept-Encoding");
        boolean supportGZIP = false;
        if (null != acceptEncoding
            && 0 <= acceptEncoding.indexOf("gzip")) {
            supportGZIP = true;
        }

        if (!supportGZIP) {
            LOGGER.info("Gzip NOT be supported");
            chain.doFilter(request, response);

            return;
        }

        final HttpServletResponse httpServletResponse =
                (HttpServletResponse) response;
        httpServletResponse.addHeader("Content-Encoding", "gzip");
        httpServletResponse.addHeader("Vary", "Accept-Encoding");
        chain.doFilter(request,
                       new GZIPServletResponseWrapper(httpServletResponse));
    }

    /**
     * Determines whether the specified request URI should be skipped filter.
     *
     * 

* Note: This method SHOULD be invoked for all filters with pattern * "/*". *

* * @param requestURI the specified request URI * @return {@code true} if should be skipped, {@code false} otherwise */ public abstract boolean shouldSkip(final String requestURI); @Override public void destroy() { } /** * HTTP response wrapper for GZIP. * * @author Liang Ding * @version 1.0.0.0, Dec 16, 2010 */ private class GZIPServletResponseWrapper extends HttpServletResponseWrapper { /** * GZIP output stream. */ private GZIPOutputStream gzipStream; /** * Servlet output stream. */ private ServletOutputStream servletOutputStream; /** * Print writer. */ private PrintWriter printWriter; /** * Constructs an {@link GZIPServletResponseWrapper} object with the * specified http servlet response. * * @param httpServletResponse the specified http servlet response * @throws IOException io exception */ GZIPServletResponseWrapper(final HttpServletResponse httpServletResponse) throws IOException { super(httpServletResponse); } @Override public ServletOutputStream getOutputStream() throws IOException { if (null == servletOutputStream) { servletOutputStream = createOutputStream(); } return servletOutputStream; } @Override public PrintWriter getWriter() throws IOException { if (null == printWriter) { printWriter = new PrintWriter( new OutputStreamWriter(getOutputStream(), getCharacterEncoding())); } return printWriter; } /** * Creates output stream with GZIP delegation. * * @return servlet output stream * @throws IOException io exception */ private ServletOutputStream createOutputStream() throws IOException { final ServletResponse servletResponse = this.getResponse(); gzipStream = new GZIPOutputStream(servletResponse.getOutputStream()); return new ServletOutputStream() { @Override public void write(final int b) throws IOException { gzipStream.write(b); } @Override public void flush() throws IOException { gzipStream.flush(); } @Override public void close() throws IOException { gzipStream.close(); } /* * These two are not absolutely needed. They are here simply * because they were overriden by GZIPOutputStream. */ @Override public void write(final byte[] b) throws IOException { gzipStream.write(b); } @Override public void write(final byte[] b, final int off, final int len) throws IOException { gzipStream.write(b, off, len); } }; } } }



本文是使用 B3log Solo简约设计の艺术 进行同步发布的
原文地址:http://88250.b3log.org/articles/2010/12/16/1292515963081.html
posted @ 2010-12-17 00:13 88250 阅读(573) | 评论 (0)编辑 收藏



本文是使用 B3log Solo简约设计の艺术 进行同步发布的
原文地址:http://88250.b3log.org/netbeans-chinese-newsletter-129.html
posted @ 2010-12-14 22:59 88250 阅读(183) | 评论 (0)编辑 收藏

 



本文是使用 B3log Solo简约设计の艺术 进行同步发布的
原文地址:http://88250.b3log.org/netbeans-chinese-newsletter-128.html
posted @ 2010-12-11 11:33 88250 阅读(223) | 评论 (0)编辑 收藏

WebSocket 协议是实现了浏览器与服务器全双工通信的 HTML5 新协议之一。传统浏览器只允许通过 HTTP 与网站互动,然而对于富 Web 应用 如聊天和游戏,HTTP 的效率不太高,因此HTML5 提供了socket API,只需一个握手动作就能在浏览器和服务器之间建立快速通道。

然而在 11 月 26 日,安全研究人员发表一篇研究报告(PDF),他们发现 WebSocket 和透明代理存在严重安全问题,他们演示了基于 Upgrade 和 CONNECT 的缓存中毒攻击,研究人员提议修改握手方式。在 Bugzilla 上,Firefox 开发者讨论了该问题,他们最后决定Firefox 4 将默认不启用 WebSockets,从 Firefox 4 beta 8 开始用户将需要修改设置才能启用 WebSockets。未来在解决安全问题后,Firefox 会选择默认启用。

转自:http://www.oschina.net/news/13668/disabling-websockets-for-firefox-4



本文是使用 B3log Solo简约设计の艺术 进行同步发布的
原文地址:http://88250.b3log.org/articles/2010/12/10/1291942973503.html
posted @ 2010-12-10 09:03 88250 阅读(154) | 评论 (0)编辑 收藏

自从发布第一个版本来,大家给了很多建议,谢谢了 :-)

下个版本 0.2.5 将于明年 2 月 14 日发布,其中加入两个大的特性:

  • 多用户
    Solo 不再是单用户博客了。多人可以一起在一个博客里进行文章撰写,非常适合团队博客。另外,如果是情侣博客的话,哼哼....
  • 草稿夹
    想发布再发布吧!当然,发布了也可以再草稿化....

这个版本的改变比较大(数据存储、逻辑控制、视图),除了 Solo 上述两个大特性的加入,还有 Latke 框架上的增强:

  • 存储缓存
    本地测试可以提升单一实体按 Key 访问时速度 400 倍左右。当然,部署到 GAE 后可能没这么好的效果 - -~

(广告:Latke 是 GAE 上的一个应用框架,主要整合了 Guice、FreeMarker、Jabsorb,数据模型从视图到存储都以 JSON 贯穿

下个版本是 B3log Solo 的第一个正式版吧 :-)

P.S. 情侣博客?两个人也是多用户嘛,0.2.5 中将加入一款皮肤,非常适合情侣写作!谢谢 Lamb 这么给力!

 



本文是使用 B3log Solo简约设计の艺术 进行同步发布的
原文地址:http://88250.b3log.org/articles/2010/12/08/1291818048978.html
posted @ 2010-12-08 22:21 88250 阅读(170) | 评论 (0)编辑 收藏

那大爷买西红柿来着的,挑了三个放到秤盘里,摊主秤了下说:“一斤半,三块七。”

大爷说:“我就做个汤,用不着那么多。”说完就去掉了个儿最大的那个西红柿。

摊主迅速又瞧一眼秤子,“一斤二两,三块。”

正当我看不过去想提醒大爷注意摊主的秤子时,大爷从容的掏出了七毛钱,拿起刚刚去掉的那个大的西红柿,扭头就走了……

摊主当场就风中凌乱了,我憋成内伤,把头扭向一边……

 

转自:http://www.douban.com/group/topic/16089209/



本文是使用 B3log Solo简约设计の艺术 进行同步发布的
原文地址:http://88250.b3log.org/articles/2010/12/03/1291338840521.html
posted @ 2010-12-03 09:14 88250 阅读(179) | 评论 (0)编辑 收藏

 



本文是使用 B3log Solo简约设计の艺术 进行同步发布的
原文地址:http://88250.b3log.org/netbeans-chinese-newsletter-127.html
posted @ 2010-12-01 21:06 88250 阅读(240) | 评论 (0)编辑 收藏

B3log LogoGAE 博客 —— B3LOG Solo 0.2.1 正式发布了。

该版本除了修复 Bugs,还增加了自定义文章/页面链接,改进了缓存,以及加入了新皮肤 favourite。

在 0.2.1 开发之际,Lamb 童鞋加入了 B3LOG Solo 开发团队(成员列表),并给我们带来了新皮肤 favourite。

新特性

  • 评论表情
  • 自定义文章链接
  • 自定义页面链接
  • 新皮肤——favourite
  • 加入了“初始化”功能(/init.do)

Bug 修复

  • 修复了偏好设定与统计数据丢失
  • 修复了皮肤显示错误
  • 修复了按标签/存档查看文章时排序的错误
  • 修复了站外相关阅读显示站内文章问题

改进

  • 提交评论/回复后只刷新评论列表
  • ”最新评论“/统计信息使用模板生成
  • 编辑器加入了中文配置
  • 调整一些页面链接后缀为 .html
  • 改进了页面缓存

具体改动看这里

升级

如果您是 0.2.0 的用户,那么请在部署完 0.2.1 后登录后台,访问 http://${application-id}.appspot.com/upgrade/v020-v021.do 进行升级。

该升级程序主要是对页面自定义链接特性进行数据一致性升级。

项目

如果在使用、测试中发现任何问题,如果您有任何意见或建议,请告知我们 :-)

作者博客

发布历史

  1. GAE 博客——B3log Solo 0.2.0 发布了!
  2. GAE 博客——B3log Solo 0.1.1 发布了!
  3. B3log Solo 0.1.0 发布了!
  4. B3log Solo 0.1.0-preview2 发布了!
  5. Solo 0.1.0-Preview1 发布了


本文是使用 B3log Solo简约设计の艺术 进行同步发布的
原文地址:http://88250.b3log.org/b3log-solo-release-021.html
posted @ 2010-12-01 12:34 88250 阅读(139) | 评论 (0)编辑 收藏

B3log LogoGAE 博客 ——  B3LOG Solo 下周将发布 0.2.1。

该版本除了修复 Bugs,还增加了自定义文章/页面链接,改进了缓存,以及加入了新皮肤 favourite。

在 0.2.1 开发之际,Lamb 童鞋加入了 B3LOG Solo 开发团队(成员列表),并给我们带来了新皮肤 favourite。

0.2.1 具体改动可以看这里,发布日期定为 12 月 1 日。



本文是使用 B3log Solo简约设计の艺术 进行同步发布的
原文地址:http://88250.b3log.org/articles/2010/11/28/1290918173803.html
posted @ 2010-11-28 12:23 88250 阅读(149) | 评论 (0)编辑 收藏

随着 Web2.0 的风靡,JavaScript 已经成为一门被人们重新认识的编程语言,由于大量 JS 开源框架的出现,利用 JavaScript 开发 的项目越来越多,越来越大。同时,也有越来越多JavaScript 开发问题暴露出来,如性能、网页加载速度等,其中,JavaScript 文档维护也成 为了开发者亟待解决的一个难题。

许多现代编程语言都有自己的集成化文档生成工具,像 Java 有 JavaDoc,.NET有 NDoc,PHP有 PHPDoc,这些自动化文档工具可以根据代码中的注释自动生成代码文档。

JsDoc Toolkit 就是这样一个自动化文档工具,它是发布在 Google code 上的一个开源项目,和其他语言的文档工具一样,它可以自动从 JavaScript 代码中提取注释生成格式化文档。 

下载地址

http://code.google.com/p/jsdoc-toolkit/downloads/list

运行环境

JsDoc Toolkit是用Java开发的,运行时需要 Java 1.5+。

用法

在运行之前,你需要把当前的工作目录切换到JsDoc Toolkit目录,并确保将java.exe所在目录添加到环境变量中。

java -jar jsrun.jar app\run.js -a -t=templates\jsdoc mycode.js

mycode.js是需要生成文档的js代码,如果mycode.js和JsDoc不在同一目录,请加上文件的绝对或者相对路径。如果项目中有多个js, 可以使用通配符*来指定多个js文件(*.js)。-e参数指定文档编码,-t参数指定文档模板位置(可以新建或修改模板文件让输出的代码文件更具特 色),生成的文档文件在JsDoc目录下的out目录中。为了使用方便,我写了一个批处理文件,你可以将代码保存为run.bat,放到JsDoc目录 下:

::run.bat
@echo off
::js文件名(换成你的js文件名)
set jsname=jquery.js
::js文件路径(换成你的js文件路径)
set jspath=C:\test\
echo start...
java -jar jsrun.jar app\run.js -a -e=GBK -t=templates\jsdoc "%jspath%%jsname%.js"
::out\%jsname%\index.html
echo finished.
pause

常用关键字

author 标识代码作者
class 标识该函数是一个类的构造函数
constant 声明常量
constructor 同class
default 默认值
deprecated 声明已弃用的对象
description 对象描述
event 事件函数
example 例子代码
fileOverview Javascript文件总体描述
ignore 忽略有这个标记的函数
link 与其他JsDoc对象关联
name 显示声明JsDoc不能自动检测的对象
namespace 声明命名空间
param 参数
private 声明私有对象
property 显式声明一个属性
public 声明公开对象
requires 声明所依赖的对象或文件
returns 返回值
see 声明可参考的其它对象
since 声明对象从指定版本开始生效
static 显式声明一个静态对象
throws 声明函数执行过程中可能抛出的异常
type 声明变量类型或者函数返回值类型
version 版本号

详细语法请参阅:JsDoc Toolkit Wiki

整理自:http://blog.tugai.net/2010/01/08/jsdoc-toolkit-usage/



本文是使用 B3log Solo简约设计の艺术 进行同步发布的
原文地址:http://88250.b3log.org/articles/2010/11/26/jsdoc-toolkit-usage.html
posted @ 2010-11-26 10:47 88250 阅读(400) | 评论 (0)编辑 收藏

仅列出标题
共9页: 上一页 1 2 3 4 5 6 7 8 9 下一页