配置jvm的代理服务器

由于代理的限制,在开发时eclipse运行时没有办法连到外部的服务器.这时就需要设置jvm的代理.

-DproxySet=true
-Dhttp.proxyHost=your.proxy.net
-Dhttp.proxyPort=8080

sample:

java YourMainClass -DproxySet=true -Dhttp.proxyHost=apacproxy.jpmchase.net -Dhttp.proxyPort=8080

eclipse里就是在run->arguments->vm arguments里填上这三个参数 ,如果是tomcat就需要修改catalina.bat/sh了.

modogen – 代码框架生成

类似springside和appfuse的东西

通过db schema生成 jsp/model类/dao类/controller类/配置文件和资源文件

应用velocity的作为模板引擎通过加入模板到代码生成引擎,可以生成任何需要的代码框架

不打算做一个完美的代码生成工具,只生成代码框架

通过一个ant任务和一个配置文件,ant任务要提供表名的pattern(如果是所有表就是%,以t_开头的就是t_%)和配置文件的名字.配置文件中要提供模板的路径,java源文件的目标路径,jsp的目标路径

通过一个配置模块来做部分定制,如权限和某些字段的显示名称,显示类型(text,hidden,select…)

对应一个数据表会生成的:
model:数据对象
dao:继承自一个基类(通过修改模板来继承任何你自己的基dao类),同时会生成单元测试类
controller:springmvc的controller类,同样继承自一个基类,同样生成单元测试类
form.jsp/view.jsp/list.jsp:分别对应表单,显示和列表页面
hibernate.xml:hibernate配置文件
servlet.xml:springmvc的controller配置文件
daos.xml:dao配置文件
menu-config.xml:生成菜单配置文件(基于struts-menu)

TODO:
1.独立的配置页面,根据每个数据表决定他的外键关联以及每个字段的生成信息(如通过那个字段关联到另一张表的哪个字段,某列是否显示于list.jsp、是否可排序、过滤)

3.权限控制,整合acegi

RSS相关资料

很久以前收集的一些关于RSS的资料

两本书:
<<Developing Feeds with RSS and Atom>> (oreilly)
<<RSS and Atom In Action>> (Manning)

文章:
oreilly相关文章:
http://www.oreillynet.com/rss/

what is rss?
http://www.xml.com/pub/a/2002/12/18/dive-into-xml.html

RDF Rich Site Summary (RSS)
http://www.oasis-open.org/cover/rss.html

RSS 2.0 Specification
http://blogs.law.harvard.edu/tech/rss

jme(j2me)的一些工具

从ee,se转到me会感觉被束缚了手脚,很多东西都需要自己写。其实不是,也有很多好用的framework可以拿来用

xml, kxml,xparser,前者是比较出名的xml处理,而后者是我在sf上偶然发现的,api比较清爽,但是需要稍微修改一下才可以用,因为他不仅仅是给me用的,所以要把source里的一些高级api(zipinputstream,bufferedinputstream)去掉。

logging, j4me,是googlecode上找到的,提供类似log4j的支持

unit test, j2meunit,没什么说的

IOC container, 没有,试图去找,结果是:IOC实现大多数严重依赖reflection,也就意味着必须要java1.3以上。而me只有1.1的级别

UI, j4me,提供一些常用的如menu和dialog的支持,没有用过

最后更新: 12-18-2007

Powered by ScribeFire.

简单的div显示,隐藏例子

<script type=”text/javascript” language=”JavaScript”><!–
function HideContent(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = “none”;
}
function ShowContent(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = “block”;
}
function ReverseContentDisplay0(d) {
if(d.length < 1) { return; }
if(document.getElementById(d).style.display == “none”) { document.getElementById(d).style.display = “block”; }
else { document.getElementById(d).style.display = “none”; }
}

function ReverseContentDisplay(d) {
if(d.length < 1) { return; }
for(i=1;i<=3;i++){
var tmp = ‘block’+i;
if(d==tmp){
if(document.getElementById(d).style.display == “none”) { document.getElementById(d).style.display = “block”; }
else { document.getElementById(d).style.display = “none”; }
}else{
document.getElementById(tmp).style.display = “none”;
}
}
}
//–></script>

<a
onclick=”javascript:ReverseContentDisplay(‘block1’); return true;”
href=”#”>
[Bid 1]
</a>
<div
id=”block1″
style=”display:none;
border-style: solid;
background-color: white;
padding: 5px;”>

bLOCK 1
</div>
<br>
<a
onclick=”javascript:ReverseContentDisplay(‘block2’); return true;”
href=”#”>
[Bid 2]
</a>
<div
id=”block2″
style=”display:none;
border-style: solid;
background-color: white;
padding: 5px;”>

bLOCK 2
</div>
<br>
<a
onclick=”javascript:ReverseContentDisplay(‘block3’); return true;”
href=”#”>
[Bid 3]
</a>
<div
id=”block3″
style=”display:none;
border-style: solid;
background-color: white;
padding: 5px;”>

bLOCK 3
</div>

Spring的FactoryBean和InitializingBean

刚刚“领略”了一些spring-modules的源代码看到了FactoryBean和InitiliazingBean的用处。记在这里

  • InitializingBean.afterPropertiesSet()

这个方法比较容易理解,是在spring根据配置文件设置了bean的属性后调用的,一般这里会做一些初始化的工作。比如,xml配置中只是提供了resource的路径,在这个方法里 就要根据resource的路径初始化一些成员变量(那些不能被注入或者没有被注入的成员变量)。

public void afterPropertiesSet() throws Exception {
if (this.definitionLocation == null) {
throw new FatalBeanException(“Property [definitionLocation] of class [”
+ ProcessDefinitionFactoryBean.class.getName()
+ “] is required.”);
}

InputStream inputStream = null;
try {
inputStream = this.definitionLocation.getInputStream();
this.processDefinition = ProcessDefinition.parseXmlInputStream(inputStream);
//       这里就是初始化的地方,spring的配置文件中只配置了definitionLocation的信息,其他的事就在这里做

}
finally {
if (inputStream != null) {
inputStream.close();
}
}
}

  • FactoryBean.getObject & getObjectType

在比较配置文件和源代码的时候我很疑惑,为什么类型都不对头,怎么可以注入的?答案就在FactoryBean的这两个方法里

public Object getObject() throws Exception {
return this.processDefinition;
}

public Class getObjectType() {
return (processDefinition == null) ? ProcessDefinition.class : processDefinition.getClass();
}

getObject返回的是成员变量processDefinition,getObjectType返回的也不是this.class,而是processDefinition.getClass();spring在加载这样的factorybean的时候就会根据这两个方法来决定类型和实例。比如在xml中配置了ref=”someFactoryBean”的 时候,实际的引用可以是任意的,只要你提供了这两个方法。-好像有点表达不清楚。

xmpp的验证流程

来自 www.xmpp.org

Step 1: Client initiates stream to server:

 

<stream:stream
    xmlns='jabber:client'
    xmlns:stream='http://etherx.jabber.org/streams'
    to='example.com'
    version='1.0'>

Step 2: Server responds with a stream tag sent to client:

 

<stream:stream
    xmlns='jabber:client'
    xmlns:stream='http://etherx.jabber.org/streams'
    id='c2s_234'
    from='example.com'
    version='1.0'>

Step 3: Server informs client of available authentication mechanisms:

 

<stream:features>
  <mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
    <mechanism>DIGEST-MD5</mechanism>
    <mechanism>PLAIN</mechanism>
  </mechanisms>
</stream:features>

Step 4: Client selects an authentication mechanism:

 

<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl'
      mechanism='DIGEST-MD5'/>

Step 5: Server sends a [BASE64] (Josefsson, S., “The Base16, Base32, and Base64 Data Encodings,” July 2003.) encoded challenge to client:

 

<challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
cmVhbG09InNvbWVyZWFsbSIsbm9uY2U9Ik9BNk1HOXRFUUdtMmhoIixxb3A9ImF1dGgi
LGNoYXJzZXQ9dXRmLTgsYWxnb3JpdGhtPW1kNS1zZXNzCg==
</challenge>

The decoded challenge is:

 

realm="somerealm",nonce="OA6MG9tEQGm2hh",
qop="auth",charset=utf-8,algorithm=md5-sess

Step 5 (alt): Server returns error to client:

 

<failure xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
  <incorrect-encoding/>
</failure>
</stream:stream>

Step 6: Client sends a [BASE64] (Josefsson, S., “The Base16, Base32, and Base64 Data Encodings,” July 2003.) encoded response to the challenge:

 

<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
dXNlcm5hbWU9InNvbWVub2RlIixyZWFsbT0ic29tZXJlYWxtIixub25jZT0i
T0E2TUc5dEVRR20yaGgiLGNub25jZT0iT0E2TUhYaDZWcVRyUmsiLG5jPTAw
MDAwMDAxLHFvcD1hdXRoLGRpZ2VzdC11cmk9InhtcHAvZXhhbXBsZS5jb20i
LHJlc3BvbnNlPWQzODhkYWQ5MGQ0YmJkNzYwYTE1MjMyMWYyMTQzYWY3LGNo
YXJzZXQ9dXRmLTgK
</response>

The decoded response is:

 

username="somenode",realm="somerealm",
nonce="OA6MG9tEQGm2hh",cnonce="OA6MHXh6VqTrRk",
nc=00000001,qop=auth,digest-uri="xmpp/example.com",
response=d388dad90d4bbd760a152321f2143af7,charset=utf-8

Step 7: Server sends another [BASE64] (Josefsson, S., “The Base16, Base32, and Base64 Data Encodings,” July 2003.) encoded challenge to client:

 

<challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
cnNwYXV0aD1lYTQwZjYwMzM1YzQyN2I1NTI3Yjg0ZGJhYmNkZmZmZAo=
</challenge>

The decoded challenge is:

 

rspauth=ea40f60335c427b5527b84dbabcdfffd

Step 7 (alt): Server returns error to client:

 

<failure xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
  <temporary-auth-failure/>
</failure>
</stream:stream>

Step 8: Client responds to the challenge:

 

<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>

Step 9: Server informs client of successful authentication:

 

<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>

Step 9 (alt): Server informs client of failed authentication:

 

<failure xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
  <temporary-auth-failure/>
</failure>
</stream:stream>

Step 10: Client initiates a new stream to server:

 

<stream:stream
    xmlns='jabber:client'
    xmlns:stream='http://etherx.jabber.org/streams'
    to='example.com'
    version='1.0'>

Step 11: Server responds by sending a stream header to client along with any additional features (or an empty features element):

 

<stream:stream
    xmlns='jabber:client'
    xmlns:stream='http://etherx.jabber.org/streams'
    id='c2s_345'
    from='example.com'
    version='1.0'>
<stream:features>
  <bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/>
  <session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>
</stream:features>

tooling aspects [mindmap]

其实就是一个brainstorm的整理

MoBarbr – 记账

这个是前一阵子有空的时候用swing写的一个简单的记账软件。很简单的功能,无非就是记账,添加顾客,充值,修改,报表。用Spring来管理swing ui组件之间的依赖,发现也很方便,而且看起来更清晰,不像以前那种panel,frame,dialog的引用传来传去。本来还准备用thinlet重写一遍,后来因为thinlet只支持awt而没做。同时还试了一些方法来发布这个桌面应用,见Java桌面应用程序发布 截图: 下载 源代码

使用canvas画的一个登录的Form

<!–code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }– 使用canvas也就是通常说的低级组件(low-level user interface api)画了一个登录的form,这个用high-level的form很简单,但是自己写确实很麻烦。因为所有的控制都要自己写:键盘输入(输入框),组件绘制,动画线程(光标闪烁), 输入框长度控制, 组件焦点, 密码mask. 刚刚开始接触wtk,练习一下.

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
public class LoginForm extends Canvas implements CommandListener {

private Image img;
private Font font;
public int currentPosX, currentPosY;
public int width, height;
public int inputBoxWidth = 150;

public int offset = 5;
public int curX = 0, curY = 0;

static final int USER_INPUT = 1, PASS_INPUT = 2, REMEMBER_CHECK = 3;

public String username = “”, password = “”;
public String usernameShow = “”,passwordShow=“”;//the display part of these two fields
public int userInputLimitation = 0,passInputLimitation = 0; //characters limitation of input box

public int userInputX, userInputY;
public int passInputX, passInputY;
public int remeCheckX, remeCheckY;
public int curSel = USER_INPUT;

public int cursorX,cursorY;
public int cursorColor = 0x00000000;
public CursorBlink cursorBlink;

private StringBuffer input = new StringBuffer(“default input”);
boolean initialized = false;

public LoginForm() {
setCommandListener(this);
width = getWidth();
height = getHeight();
// The current cursor position for the text
currentPosX = width / 2;
currentPosY = height / 2;
// The text font
font = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN,
Font.SIZE_LARGE);

// setFullScreenMode (true);
// Cursor blink thread
cursorBlink = new CursorBlink(this);
Thread blinkThrd = new Thread(cursorBlink);
blinkThrd.start();

setCommandListener(this);

try {
img = Image.createImage(“/imgs/” + “gtalk.jpg”);
} catch (Exception e) {
e.printStackTrace();
img = null;
}
}

protected void paint(Graphics g) {
if (!initialized) {
// Fill a white background
g.setColor(0xffffff);

g.fillRect(0, 0, width, height);
// Draw logo image
g.drawImage(img, curX, curY, Graphics.TOP | Graphics.LEFT);

// Draw form
// set font and color-black
g.setFont(font);
g.setColor(0, 0, 0);
// Draw name label and box
curY += img.getHeight() + offset;
g.drawString(“Username “, curX, curY, Graphics.TOP | Graphics.LEFT);
curY += offset + font.getHeight();
userInputX = curX;
userInputY = curY;
g.drawRect(curX, curY, inputBoxWidth, font.getHeight());
curY += offset / 2 + font.getHeight();
g
.drawString(“@gmail.com”, curX, curY, Graphics.TOP
| Graphics.LEFT);
// Draw password label and box
curY += offset + font.getHeight();
g.drawString(“Password “, curX, curY, Graphics.TOP | Graphics.LEFT);
curY += offset + font.getHeight();
passInputX = curX;
passInputY = curY;
g.drawRect(curX, curY, inputBoxWidth, font.getHeight());

cursorX = userInputX;
cursorY = userInputY;

initialized =true;
}else{
update(g);
}

}

public void update(Graphics g) {
highLightSelection(g);
//remove previous input
g.setColor(255, 255, 255);
//1px offset for the 1px border
g.fillRect(userInputX+1, userInputY+1, inputBoxWidth-1, font.getHeight()1);
g.fillRect(passInputX+1, passInputY+1, inputBoxWidth-1, font.getHeight()1);
//draw the input again
drawInput(g);
showCursor(g);
}

private void drawInput(Graphics g) {
g.setColor(0,0,0);
g.setFont(font);
usernameShow = username;
//add a blank space to avoid the char cross line, as the space available is not enough for a char like “k”, but enough for “l”
if(font.stringWidth(usernameShow+” “) >= inputBoxWidth){
if(userInputLimitation == 0) userInputLimitation = username.length();
usernameShow = username.substring(username.length()-userInputLimitation);
}
passwordShow = mask(password);
if(font.stringWidth(passwordShow+” “) >= inputBoxWidth){
if(passInputLimitation == 0) passInputLimitation = password.length();
passwordShow = password.substring(password.length()-passInputLimitation);
}

g.drawString(usernameShow, userInputX, userInputY, Graphics.TOP
| Graphics.LEFT);
g.drawString(mask(passwordShow), passInputX, passInputY, Graphics.TOP
| Graphics.LEFT);
}

private void showCursor(Graphics g) {
g.setColor(cursorColor);
if(curSel == USER_INPUT){
g.drawLine(userInputX+font.stringWidth(usernameShow),userInputY+1,userInputX+font.stringWidth(usernameShow),userInputY+font.getHeight()1);
}else if(curSel == PASS_INPUT){
g.drawLine(passInputX+font.stringWidth(mask(passwordShow)),passInputY+1,passInputX+font.stringWidth(mask(passwordShow)),passInputY+font.getHeight()1);
}

}

private String mask(String pass){
StringBuffer sb = new StringBuffer();
int le = pass.length();
for(int i=0;i<le;i++){
sb.append(‘*’);
}
return sb.toString();
}

private void highLightSelection(Graphics g) {
// set blue background
g.setColor(0, 0, 255);
if (curSel == USER_INPUT) {
g.drawRect(userInputX, userInputY, inputBoxWidth, font.getHeight());
g.setColor(0, 0, 0);
g.drawRect(passInputX, passInputY, inputBoxWidth, font.getHeight());

} else if (curSel == PASS_INPUT) {
g.drawRect(passInputX, passInputY, inputBoxWidth, font.getHeight());
g.setColor(0, 0, 0);
g.drawRect(userInputX, userInputY, inputBoxWidth, font.getHeight());

}
}

public void keyPressed(int keyCode) {
int gameCode = getGameAction(keyCode);
if (gameCode == UP) {
curSel = USER_INPUT;
} else if (gameCode == DOWN) {
curSel = PASS_INPUT;
} else if (gameCode == LEFT) {
//TODO move cursor
} else if (gameCode == RIGHT) {
//TODO move cursor
} else if (keyCode == –8 || keyCode == 8) { // -8 clear key, 8 backspace
if (curSel == USER_INPUT) {
if(“”.equals(username))return;
username = username.substring(0, username.length()1);
} else if (curSel == PASS_INPUT) {
if(“”.equals(password))return;
password = password.substring(0,password.length()1);
}
} else {
char c = (char) keyCode;
if (curSel == USER_INPUT) {
username += c;
} else if (curSel == PASS_INPUT) {
password += c;
}
}
repaint();
}

public void commandAction(Command c, Displayable d) {
System.out.println(c);
}

class CursorBlink implements Runnable {
LoginForm form;

public CursorBlink (LoginForm form) {
this.form = form;
}
public void run () {
int seed=0;
while (true) {
seed++;
if( seed%2 == 0){
cursorColor = 0x00ffffff; //white
}else{
cursorColor = 0x00000000; //black
}
form.repaint();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}