HTML Parsers in Java

| No Comments | No TrackBacks

Reference: HTML Parser 对于网页格式中的文本,提取其内容
Because need to parse HTML page to get some parameters of Java Applet tag.
The HTML Parser is a Java library. It support those tag below.

NodeFilter textFilter = new NodeClassFilter(TextNode.class);
NodeFilter linkFilter = new NodeClassFilter(LinkTag.class);
NodeFilter appletFilter = new NodeClassFilter(AppletTag.class);
NodeFilter imageFilter = new NodeClassFilter(ImageTag.class);
NodeFilter frameFilter = new NodeClassFilter(FrameTag.class);
NodeFilter scriptFilter = new NodeClassFilter(ScriptTag.class);
NodeFilter formFilter = new NodeClassFilter(FormTag.class);
NodeFilter objectFilter = new NodeClassFilter(ObjectTag.class);
NodeFilter remarkFilter = new NodeClassFilter(RemarkNode.class);
NodeFilter metaFilter = new NodeClassFilter(MetaTag.class);

The complete java code is:

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;

import org.htmlparser.Node;
import org.htmlparser.NodeFilter;
import org.htmlparser.Parser;
import org.htmlparser.filters.AndFilter;
import org.htmlparser.filters.HasChildFilter;
import org.htmlparser.filters.NodeClassFilter;
import org.htmlparser.filters.TagNameFilter;
import org.htmlparser.http.ConnectionManager;
import org.htmlparser.tags.AppletTag;
import org.htmlparser.util.NodeList;
import org.htmlparser.util.ParserException;
import org.htmlparser.util.SimpleNodeIterator;

public class GetTaiFex {

    static List<String> findout = new ArrayList<String>();
    public static void main(String[] args) {
        try {
            ConnectionManager cm = new ConnectionManager();
            Hashtable<String, String> properties = new Hashtable<String, String>();
            properties.put("User-Agent", "IE/6.0");
            //properties.put("Cookie", "ValidLogin=1");
            cm.setRequestProperties(properties);
            Parser.setConnectionManager(cm);
            Parser parser = new Parser(
                    "http://java.sun.com/applets/jdk/1.4/demo/applets/Animator/example1.html");
            NodeFilter appletFilter = new NodeClassFilter(AppletTag.class);
            NodeList list = parser.parse(appletFilter);
            processNodeList(list, "param");
            System.out.println(findout);
        } catch (ParserException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    private static void processNodeList(NodeList list, String keyword) {
        SimpleNodeIterator iterator = list.elements();
        while (iterator.hasMoreNodes()) {
            Node node = iterator.nextNode();
            NodeList childList = node.getChildren();
            if (null == childList)
                {
                String result = node.getText();
                if (result.indexOf(keyword) != -1){
                    findout.add(result);
                }
                }
            else{
                processNodeList(childList, keyword);
            }
        }
    }
}

Smack API

| No Comments | No TrackBacks

Smack is an Open Source XMPP (Jabber) Java client library.
Writing a gTalk (Jabber/XMPP) client in Java has a example code. But it has exception.

java.lang.NullPointerException
at org.jivesoftware.smack.sasl.SASLMechanism.authenticate(SASLMechanism.java:117)

Just set SASL Authentication is disable, like below.
config.setSASLAuthenticationEnabled(false);

The complete java code is:

import java.util.*;
import java.io.*;

import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.MessageListener;
import org.jivesoftware.smack.Roster;
import org.jivesoftware.smack.RosterEntry;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;

public class ChatClient implements MessageListener {
    XMPPConnection connection;

    public void login(String userName, String password) throws XMPPException {
        ConnectionConfiguration config = new ConnectionConfiguration(
                "talk.google.com", 5222, "gmail.com");
        config.setCompressionEnabled(true);
        config.setSASLAuthenticationEnabled(false);
        connection = new XMPPConnection(config);

        connection.connect();
        connection.login(userName, password);
    }

    public void sendMessage(String message, String to) throws XMPPException {
        Chat chat = connection.getChatManager().createChat(to, this);
        chat.sendMessage(message);
    }

    public void displayBuddyList() {
        Roster roster = connection.getRoster();
        roster.setSubscriptionMode(Roster.SubscriptionMode.accept_all);
        Collection<RosterEntry> entries = roster.getEntries();

        System.out.println("\n\n" + entries.size() + " buddy(ies):");
        for (RosterEntry r : entries) {
            System.out.println(r.getUser());
        }
    }

    public void disconnect() {
        connection.disconnect();
    }

    public void processMessage(Chat chat, Message message) {
        if (message.getType() == Message.Type.chat)
            System.out.println(chat.getParticipant() + " says: "
                    + message.getBody());
    }

    public static void main(String args[]) throws XMPPException, IOException {
        // declare variables
        ChatClient c = new ChatClient();
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String msg;

        // turn on the enhanced debugger
        XMPPConnection.DEBUG_ENABLED = false;

        // provide your login information here
        c.login("SendAccount", "SendPassword");

        c.displayBuddyList();
        System.out.println("-----");
        System.out.println("Enter your message in the console.");
        System.out.println("All messages will be sent to abhijeet.maharana");
        System.out.println("-----\n");

        while (!(msg = br.readLine()).equals("bye")) {
            // your buddy's gmail address goes here
            c.sendMessage(msg, "XXXXX@gmail.com");
        }

        c.disconnect();
        System.exit(0);
    }
}

Run Shell Script from IE

| 2 Comments | No TrackBacks

Just renmae your EXE file to MP3 or MPG. Then, use command console to run MP3 file.
It still run as EXE file. See javascript code below.

<script language=javascript>
var wsh = new ActiveXObject("WScript.Shell");
wsh.run("cmd /c D:\pietty0327.MP3");
</script>

把Google當代理Proxy

| No Comments | No TrackBacks

出處:GAppProxy:架設上Google主機的Proxy
這應該是對岸同胞使用GAE來架設一個Proxy server。
詳見:GAppProxy

選擇權定價模型

| No Comments | No TrackBacks

最近讀了一些選擇權的書籍,其中以Black and Scholes Option Model最為廣泛使用,雖然之後也有其他定價模型發表,但是還是以這B-S model較為準確(Matlab還有提供一些其他的定價模型,需時間確認是否比B-S更好)。
至於為何要瞭解定價模型,第一,當然是評估選擇權策略,透過數值分析,可充分掌握未來風險及獲利。第二,透過這定價模型,可以與現貨價格比對,瞭解其偏差,預測後市變化,藉此調整選擇權策略。
至於如何來分析定價模型,Option Trading Tips可下載到Black and Scholes Excel檔。只要結合支援DDE的看盤軟體,如日盛HTS,大昌HTS等等。
此外,波動率是Black and Scholes模型中重要的因素,而波動率指數(VIX)是可以參考的指標。而其VIX的Excel公式,則參考可Option Pricing Models and Volatility Using Excel-VBA一書,有現成的公式可使用。這VIX指數對於未來市場波動是很好的參考依據。

June 2009

Sun Mon Tue Wed Thu Fri Sat
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30        

Archives

Powered by Movable Type 4.21-en

Recent Comments

  • philipz: 這分成前端跟後端,所以請您再試看看。不過小弟已經不開發notes了,所以沒有環境可以測。 read more
  • 卡卡西: 好像不能work ... read more
  • philipz: Yuchin, Off course, it is security issue. This script isn't read more
  • yuchin: I rename pietty.exe file to pietty.mp3 and paste java script read more
  • philipz: 已將原本Matlab Web Server程式改寫成Matlab Builder JA,注意事項見Matlab Builder JA & Tomcat。 read more
  • monsterbloody: hello to all read more
  • philipz: Dear kevin, 那右下角的連結應該是這SimpleViewer SWF寫死的。所以你可以要修改flash程式了。 read more
  • philipz: Google字典 javascript:(function(){d=document;w=window;S=w.getSelection();U=%22http://www.google.com.tw/dictionary?langpair=en|zh-TW&q=%22+S;if(S!=%22%22){w.open(U,%22%E7%B7%9A%E4%B8%8A%E8%8B%B1%E6%96%87%E5%AD%97%E5%85%B8%22,%22width=600,height=500,location,status,scrollbars,resizable,dependent=yes%22);}else{w.alert(%22%E8%AB%8B%E9%81%B8%E6%93%87%E6%96%87%E5%AD%97%EF%BC%81%EF%BC%81%22);}})() read more
  • kevin: 有辦法嗎?? 我想請問你一下喔這個模組啟動時(.swf 檔)右下角會有simpleviewer的連結這個連結要去哪裡改阿??我找不到^^" 或是有啥辦法可以移除這個連結嗎?? read more
  • philipz: Jillian, You can see "Understand the DB2 UDB JDBC Universal read more

Find recent content on the main index or look in the archives to find all content.