anchor.java

来自「手机Wap浏览器源码」· Java 代码 · 共 95 行

JAVA
95
字号
package com.gameislive.browser;

import java.util.Vector;
import com.gameislive.browser.element.FormElement;

/**
 * anchor,类似超链接,用于提交FormElement的内容
 * 
 * @author pan
 *
 */
public class Anchor{
	
	Browser browser;
	
	/**
	 * 提交方法:GET or POST
	 */
	String method;
	/**
	 * 提交链接
	 */
	String href;
	/**
	 * 提交时,需要提交的元素
	 */
	Vector postfieldName = new Vector();
	/**
	 * 提交时,需要提交的元素值
	 */
	Vector postfieldValue = new Vector();
	
	public Anchor(Browser browser){
		this.browser = browser;
	}
	
	public void setMethod(String method){
		if(method==null || method.equals("")){
			this.method = "GET";
		}else{
			this.method = method.toUpperCase();
		}
	}
	
	public void setHref(String href){
		this.href = href;
	}
	
	/**
	 * 添加一个postfield字段,注意参数value可以是字符串,也可以是一个FormElement元素
	 * @param name
	 * @param value
	 */
	public void addPostfield(String name,Object value){
		postfieldName.addElement(name);
		postfieldValue.addElement(value);
	}
	
	public String getMethod(){
		return method;
	}
	
	public String getHref(){
		return href;
	}
	
	public String getAnchorString(){
		int num = postfieldName.size();
		String string = null;
		for(int i=0;i<num;i++){
			String name = (String)postfieldName.elementAt(i);
			Object value = postfieldValue.elementAt(i);
			if(value instanceof FormElement){
				if(string == null){
					string = name+"="+((FormElement)value).getValue();
				}else{
					string += "&"+name+"="+((FormElement)value).getValue();
				}
			}else{
				if(string == null){
					string = name+"="+(String)value;
				}else{
					string += "&"+name+"="+(String)value;
				}
			}
		}
		
		//#if DEBUG
		//# System.out.println("ANCHOR: "+string);
		//#endif
		
		return string;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?