Stand alone的Spring示例 (IoC)

Reference:

1. 60秒入门教程: http://gabriel.jarchitect.org/spring/index.html

必需的jar文件包括: spring-core.jar, common-logging.jar, 在IDEA中,
运行Java虚拟机的目录并不是classes目录, 因此它在当前目录中无法找到
"bean.xml"文件, 使用下面的代码:

  import org.springframework.core.io.*;
  /* Read the configuration file from classpath */
   Resource res = new ClassPathResource("bean.xml");
   XmlBeanFactory factory = new XmlBeanFactory(res);


Stand alone的Spring示例 (AOP)

Referneces:

1. An Introduction to Aspect-Oriented Programming with the Spring Framework, Part 1: http://www.onjava.com/lpt/a/4994

2. http://www.springframework.org/docs/wiki/Spring_AOP_Framework.html

3. SpringFrameWork中AOP的简单使用: http://blog.csdn.net/ylong/archive/2004/07/10/38482.aspx

I just copy the code from the onjava one, and implement a demo with
IDEA 4.5. But a minor change for the same issue in IoC example:

import org.springframework.context.support.ClassPathXmlApplicationContext;

    // Read the configuration file from classpath
    ApplicationContext ctx = new ClassPathXmlApplicationContext( "springconfig.xml");

必须的jar文件包括:
aopalliance.jar, commons-logging.jar, jakarta-oro-xxx.jar, spring-aop.jar, spring-context.jar, spring-core.jar.

GtkHTML programming

http://primates.ximian.com/~rodo/programing_with_gtkhtml_tutorial/guadec.html

Some useful functions of gtkhtml:

1. gtk_html_begin_content(), then gtk_html_write(), at last gtk_html_end().
2. gtk_html_set_base(), gtk_html_jump_to_anchor(), gtk_html_load_empty().
3. Contructor: gtk_html_new()

Signals:
“url-requested“
“obj-requested“ (embedded objects)
“load-done“
“submit“
“size-changed“
“link-clicked“
“button-press-event“
“redirect“
“title-changed“
“on-url“

The best startpoint is test/example along with gtkhtml. gtkhtml/src/testgtkhtml. It depends on 3 files: testgtkhtml.c, htmlurl.h, htmlurl.c. And these 3 files are not part of libgtkhtml.

Or, you can see chmsee's implementation http://211.92.88.40/~zhong/

How to debug shared librarys with gdb?


The simplest method is:


1. set a break point in main()

2. list the source code or symbol name of the shared library, and set the break point.

You could use add-symbol-file to load the symbols of the shared library. Use ldd, you can see the link address of this shared library, this is the address for the add-symbol-file command. But even you specify the correct address, because at that time, this library has not been loaded in memory, you can not set a break point. It will prompt such error "Cannot access memory at address 0x00xx00xx".

Another way, you can set a signal handler in gdb, e.g., (gdb) handle SIGINT stop. Then when you press Ctrl+C, the debugger will intercept the SIGINT signal to debuging application, then it will stop, you can set break point at that time. Use kill -l, you could list all signals in your system.

Use nocase string as g_hash_table's key

/* ghashtabledemo.c -- GHashTable demo */

#include <glib.h>
#include <string.h>

void print_entry(gpointer key, gpointer data, gpointer user_data)
{
  /* user_data not used */
  g_print("key: %-10s     value: %-10s\n", (gchar *)key, (gchar *)data);
}

guint g_str_case_hash (gconstpointer key) {
 gchar *upkey = g_ascii_strdown (key, strlen(key));
 guint hash = g_str_hash (upkey);
 g_free (upkey);
 return hash;
}

gboolean g_str_case_equal (gconstpointer a, gconstpointer b) {
 if (!g_ascii_strcasecmp (a, b))
  return TRUE;
 else
  return g_str_equal (a, b);
}

int main(int argc, char *argv[])
{
  GHashTable *hash1;
 
  hash1 = g_hash_table_new(g_str_case_hash, g_str_case_equal);

  /* insert a bunch of entries */
  g_hash_table_replace(hash1, g_strdup("foo"), g_strdup("bar"));
  g_hash_table_replace(hash1, g_strdup("FoO"), g_strdup("BAR"));
  g_hash_table_replace(hash1, g_strdup("more"), g_strdup("junk"));

  /* print the contents */
  g_print("Hash table entries:\n");
  g_hash_table_foreach(hash1, print_entry, NULL);

  return 0;
}

/*
 * gcc -ansi -Wall `pkg-config glib-2.0 --cflags` -o test test.c  `pkg-config glib-2.0 --libs`
 */

How to add a menuitem in Nautilus context menu.

1. In src/file-manager directory, add command section and menuitem section in nautilus-directory-view-ui.xml.

<commands>
    ...
    <cmd name=”Name Convert”
        _label=”Name _Convert”
        _tip=”Convert the file name”/>
    ...
</commands>

<popup name=“selection“ tearoff=“0“>
    ....
    <placeholder name=“File Actions“ delimit=“top“>
        ...
       <menuitem name=”Name Convert” verb=”Name Convert”/>
        ...
    </placeholder>
    ...
</popup>

2. In fm-directory-view.c:

    #define FM_DIRECTORY_VIEW_COMMAND_NAME_CONVERT    “/commands/Name Convert“

    In real_merge_menus () function, BonoboUIVerb verbs [] array, add the following item:
    BONOBO_UI_VERB (“Name Convert“, name_convert_callback),

    You could use nautilus_bonobo_set_sensitive () or nautilus_bonobo_hidden () to show or hide this menuitem.

3. How to launch the corresponding program in callback function:

    GnomeVFSMimeApplication *test;
   
    test = g_new0 (GnomeVFSMimeApplication, 1);
    test->id = g_strdup (“test“);
    test->name = g_strdup (“this is a test“);
    test->command = g_strdup (“test“);
    test->expects_uris = GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_PATHS;
   
    file = NAUTILUS_FILE (selection->data);
    nautilus_launch_application (test, file, NULL);

    g_free (test->id);
    g_free (test->name);
    g_free (test->name);
    g_free (test);

    You could use gnome_vfs-get_local_path_from_uri (nautilus_file_get_uri (file)) to get the actuall file name.