June 2009 Archives

HTML Parsers in Java

| 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 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 TrackBacks

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

選擇權定價模型

| 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指數對於未來市場波動是很好的參考依據。

If you want deploy Matlab java app to Tomcat.
Follow the steps below:
1. Install JAVA Runtime Environment.
2. Install Matlab MCR.
3. Install Tomcat app server.

When the error message is "java.lang.UnsatisfiedLinkError: Failed to find the library mclmcrrt710.dll, required by MATLAB Builder JA, on java.library.path". Adding path setting below in Tomcat config file.
-Djava.library.path = %Matlab_MCR_DIR%\MATLAB Compiler Runtime\v710\runtime\win64

March 2010

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 31      

Archives

Powered by Movable Type 4.34-en

Recent Comments

  • panandy: 3Q read more
  • Anonymous: philipz大 沒有邀請碼,無法註冊,致無法下載工具 請問有何方法可以解決? 感恩 read more
  • philipz: harushard, It is your java code problem. Check it and read more
  • harushard: java.lang.NoClassDefFoundError: Could not initialize class examples.ExamplesMCRFactory could you explain why read more
  • philipz: IM已經是無解了,建議可以用Plurk Api試看看。 read more
  • ann: hi,請問以上問題解決了沒?可以分享一下嗎? read more
  • Anonymous: 邀請碼沒有~無法下載工具~~怎麼辦 read more
  • Melody: test read more
  • philipz: Ginger: 您好,請您在我的噗浪上留言即可一起討論。 read more
  • Ginger: 版大您好: 在看過您做的期貨即時訊息BOT後覺得很不錯,自己也有一些想法不知能否與您交流與協助呢? 若您覺得ok的話,可以email或是噗浪(ID: king0355)與我聯繫。感謝 : ) read more

About this Archive

This page is an archive of entries from June 2009 listed from newest to oldest.

May 2009 is the previous archive.

July 2009 is the next archive.

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