Archive for July, 2008

Digg Digg Wordpress Plugin

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (9 votes, average: 8.44 out of 10)
Loading ... Loading ...

This is a very simple digg button plugin. This plugin is use to add digg button into wordpress content. Just like how it look like in this website.

Features
Add Digg Button Into Wordpress Content

Download Here
Digg Digg v1.2
Digg Digg v1.1

Change Log
Digg Digg v1.2 - 05/09/2008 Updated
Add Digg Button Control Display function Setup Screen.
-Display at Home page
-Display at Static page
-Display at Post Page
-Display at Category Page
-Display at Archive Page

Digg Digg v1.1 - 31/07/2008 Updated
Add Setup screen (Setting–>DiggDigg) to let user choose where user want to display Digg button.
1)Append Digg Button with Left Float Content
2)Append Digg Button with Right Float Content
3)Append Digg Button Before Content
4)Append Digg Button After Content

How to Install
Copy Digg Digg plugin folder to wordpress plugin folder and activate it.

How to use

Add Digg button with prefix template
1) After activated, click “setting –> Digg Digg” to access Digg Digg setup screen.
2) Choose how you want Digg button append into WordPress content
3) Control Digg button only display at Home page, Static page, Post Page, Category Page or Archive Page
4) Saved.

Add Digg button to anywhere you like
Add following code to where you want digg vote button to display. like Single Post (single.php)

<?php if(function_exists('digg_digg_generate')) { digg_digg_generate(); } ?>

For example, below is code that use in this website

<div style="position:absolute; left:650px; top:50px;">
<?php if(function_exists('digg_digg_generate')) { digg_digg_generate(); } ?>
</div>

or

<div style=”float:right”>
<?php if(function_exists('digg_digg_generate')) { digg_digg_generate(); } ?>
</div>

If you have any idea , please share it to me if you do not mind.

Tomcat 5.5.25 is suck… Give Up

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (1 votes, average: 4 out of 10)
Loading ... Loading ...

Ah………After upgraded to Tomcat 5.5.25, i just feel suck, it cause so many errors in my web applications, which didnt happened in my previous Tomcat 5.5.23 deployment.

For Example

1) java.security.AccessControlException: access denied (logging.properties read)


2) java.security.AccessControlException: access denied (java.lang.RuntimePermission accessDeclaredMembers)

3) Caused by: org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Something unusual has occured to cause the driver to fail. Please report this exception.)
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Something unusual has occured to cause the driver to fail. Please report this exception.)

I decided to give up Tomcat 5.5, and install Tomcat 6.x. Great my web application deployed without any error at Tomcat6.x. So Just said sorry to Tomcat 5.5.25…cause you are to difficult to configure for me ~

As i said in previously post, Tomcat 5.5.25 made a lot modified at policy file, which may enchance security on web application but it cause a lot work from deployment work. I hit another error


SEVERE: Context initialization failed java.security.AccessControlException: access denied (java.lang.RuntimePermission accessDeclaredMembers) at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)

vi 04webapps.policy which usually located at policy.d folder

mkyong@mkyong-desktop:/etc/tomcat5.5/policy.d$ 04webapps.policy

add following statement in policy file

permission java.lang.RuntimePermission "accessDeclaredMembers";

For example,

  // JVM properties to allow read access
    permission java.util.PropertyPermission "java.version", "read";
    permission java.util.PropertyPermission "java.vendor", "read";
    permission java.util.PropertyPermission "java.vendor.url", "read";
    permission java.util.PropertyPermission "java.class.version", "read";
        permission java.util.PropertyPermission "java.specification.version", "read";
        permission java.util.PropertyPermission "java.specification.vendor", "read";
        permission java.util.PropertyPermission "java.specification.name", "read";
 
        permission java.util.PropertyPermission "java.vm.specification.version", "read";
        permission java.util.PropertyPermission "java.vm.specification.vendor", "read";
        permission java.util.PropertyPermission "java.vm.specification.name", "read";
        permission java.util.PropertyPermission "java.vm.version", "read";
        permission java.util.PropertyPermission "java.vm.vendor", "read";
        permission java.util.PropertyPermission "java.vm.name", "read";
 
    // Required for OpenJMX
    permission java.lang.RuntimePermission "getAttribute";
 
        // Allow read of JAXP compliant XML parser debug
        permission java.util.PropertyPermission "jaxp.debug", "read";
 
    // Precompiled JSPs need access to this package.
    permission java.lang.RuntimePermission "accessClassInPackage.org.apache.jasper.runtime";
    permission java.lang.RuntimePermission "accessClassInPackage.org.apache.jasper.runtime.*";
 
    permission java.lang.RuntimePermission "accessDeclaredMembers";
 
};

Saved it, restart Tomcat and Done.

How to check Tomcat version Installed

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (1 votes, average: 2 out of 10)
Loading ... Loading ...

Sometime we need to find out what is our Tomcat version installed in our server. We can check Tomcat version with following command sh version.sh, this version.sh is located at tomcat bin folder

mkyong@mkyong-desktop:/usr/share/tomcat5.5/bin$ sh version.sh
Using CATALINA_BASE:   /usr/share/tomcat5.5
Using CATALINA_HOME:   /usr/share/tomcat5.5
Using CATALINA_TMPDIR: /usr/share/tomcat5.5/temp
Using JRE_HOME:       /usr/lib/jvm/java-6-sun
Server version: Apache Tomcat/5.5
Server built:   Jan 3 2008 11:42:45
Server number:  5.5.25.0
OS Name:        Linux
OS Version:     2.6.24-19-generic
Architecture:   i386
JVM Version:    1.6.0_06-b02
JVM Vendor:     Sun Microsystems Inc.
mkyong@mkyong-desktop:/usr/share/tomcat5.5/bin$

Got it, Tomcat version is 5.5.25.0.

P.S Tomcat version.sh required we set up JAVA_HOME properly, please issue following command if hanvt set up JAVA_HOME environment.

export JAVA_HOME=<java jdk path>

Tomcat - java.security.AccessControlException: access denied (logging.properties read)

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (2 votes, average: 6.5 out of 10)
Loading ... Loading ...

After upgraded to Tomcat version 5.5.25, it hit a lot errors in security policy path.

Caused by: java.security.AccessControlException: access denied (java.io.FilePermission /usr/share/tomcat5.5-webapps/jsp-examples/WEB-INF/classes/logging.properties read)

Above error is cause by policy file, Tomcat 5.5.25 made a lot modified at policy file, we need to modify policy file(03catalina.policy) file to fix it.

vi 03catalina.policy which usually located at policy.d folder

mkyong@mkyong-desktop:/etc/tomcat5.5/policy.d$ vi 03catalina.policy

find below

grant codeBase "file:${catalina.home}/bin/tomcat-juli.jar" {
        permission java.util.PropertyPermission "java.util.logging.config.class", "read";
        permission java.util.PropertyPermission "java.util.logging.config.file", "read";
        permission java.lang.RuntimePermission "shutdownHooks";
        permission java.io.FilePermission "${catalina.base}${file.separator}conf${file.separator}logging.properties", "read";
        permission java.util.PropertyPermission "catalina.base", "read";
        permission java.util.logging.LoggingPermission "control";
        permission java.io.FilePermission "${catalina.base}${file.separator}logs", "read, write";
        permission java.io.FilePermission "${catalina.base}${file.separator}logs${file.separator}*", "read, write";
        permission java.lang.RuntimePermission "getClassLoader";
        // To enable per context logging configuration, permit read access to the appropriate file.
        // Be sure that the logging configuration is secure before enabling such access
        // eg for the examples web application:
        //permission java.io.FilePermission "${catalina.base}${file.separator}webapps${file.separator}examples${file.separator}WEB-INF${file.separator}classes${file.separator}logging.properties", "read";
};

CHANGED TO below to allow all permission like before

grant codeBase "file:${catalina.home}/bin/tomcat-juli.jar" {
        permission java.security.AllPermission;
};

OR enable permission explicitly to your web app path

permission java.io.FilePermission “${catalina.base}${file.separator}webapps${file.separator}YOUR_PATH_HERE
${file.separator}WEB-INF${file.separator}classes${file.separator}logging.properties”, “read”;

full command is

grant codeBase "file:${catalina.home}/bin/tomcat-juli.jar" {
        permission java.util.PropertyPermission "java.util.logging.config.class", "read";
        permission java.util.PropertyPermission "java.util.logging.config.file", "read";
        permission java.lang.RuntimePermission "shutdownHooks";
        permission java.io.FilePermission "${catalina.base}${file.separator}conf${file.separator}logging.properties", "read";
        permission java.util.PropertyPermission "catalina.base", "read";
        permission java.util.logging.LoggingPermission "control";
        permission java.io.FilePermission "${catalina.base}${file.separator}logs", "read, write";
        permission java.io.FilePermission "${catalina.base}${file.separator}logs${file.separator}*", "read, write";
        permission java.lang.RuntimePermission "getClassLoader";
        // To enable per context logging configuration, permit read access to the appropriate file.
        // Be sure that the logging configuration is secure before enabling such access
        // eg for the examples web application:
        permission java.io.FilePermission "${catalina.base}${file.separator}webapps${file.separator}YOUR_PATH_HERE${file.separator}WEB-INF${file.separator}classes${file.separator}logging.properties", "read";
};

Done, restart Tomcat.

Tomcat Default Administrator Password?

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (1 votes, average: 2 out of 10)
Loading ... Loading ...

Tomcat5.5 do not enable admin or manager access by default. We have to manully edit tomcat-users.xml to allow admin access. VI your tomcat-users.xml in tomcat conf folder, content is something like following

<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
  <role rolename="tomcat"/>
  <role rolename="role1"/>
  <user username="tomcat" password="tomcat" roles="tomcat"/>
  <user username="both" password="tomcat" roles="tomcat,role1"/>
  <user username="role1" password="tomcat" roles="role1"/>
</tomcat-users>

Tomcat only create a tomcat user for normal access, we have to modify a bit like following

<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
  <role rolename="manager"/>
  <role rolename="tomcat"/>
  <role rolename="admin"/>
  <role rolename="role1"/>
  <user username="both" password="tomcat" roles="tomcat,role1"/>
  <user username="tomcat" password="tomcat" roles="tomcat"/>
  <user username="admin" password="admin" roles="admin,manager"/>
  <user username="role1" password="tomcat" roles="role1"/>
</tomcat-users>

Saved it and restart tomcat, now we can access tomcat admin or maneger page with user:admin password:admin.

If statement Becareful !!!

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (1 votes, average: 1 out of 10)
Loading ... Loading ...

Becareful!!, this is what i encounter today, what a stupid “If statement” i created….ai..do you seen what error below?

1
2
3
4
5
if(this.putNode(estraierFts, ftsUrlSync));
{
	//delete record after update
	ftsUrlSyncBO.deleteFtsUrlSync(ftsUrlSync.getId());
}

Above statement compile successfully in Java, what i trying want to do is , when condition true, it will delete my records. However with above statement, it will delete my record no matter condition true or false. This is funny, did you notice what error above? …. haha notice carefully , “;” after a “If statement”..what a stupid mistake i made.. TT…. my eyes are blur…take a rest first

Correct statement should be following

1
2
3
4
5
if(this.putNode(estraierFts, ftsUrlSync))
{
	//delete record after update
	ftsUrlSyncBO.deleteFtsUrlSync(ftsUrlSync.getId());
}

Hyper Estraier Node API Demo

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (1 votes, average: 8 out of 10)
Loading ... Loading ...

My project decided to use Hyper Estraier as Full Text Search Engine. Here i created a simple interface to demonstrate how to program Hyper Estraier with Node API in C.

This program is very simple
1) Ask user to key in insert(1), update(2), delete(3) or list(4) existing indexed
2) Key in URI (Unique ID) and URL for indexed

How to compile — please change according to your library path

gcc -o HyperIndex HyperIndex.c -L/usr/local/lib -lestraier -lresolv -lnsl -lpthread -lqdbm -lz -liconv -lm -lc

Node URL - Here i hard coded my node URL

http://localhost:1978/node/pattern

P.S i am not expert in c, please correct me if i am code something wrong.

Program Explanation
———————————–
Please always refer Hyper Estraier Node API reference here

1) Insert or Update Node by using est_node_put_doc()
If URI is same , it will update/overwrite existing node details

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
static void
putNode(ESTDOC *doc ,ESTNODE *node, char *cBufferUri ,char *cBufferUrl)
{
	/* add attributes to the document object */
	est_doc_add_attr(doc, "@uri", cBufferUri);
	est_doc_add_attr(doc, "@title", cBufferUri);
	est_doc_add_attr(doc, "url", cBufferUrl);//for include function
 
	/* add the body text to the document object */
	est_doc_add_text(doc, cBufferUrl);
 
	/* register the document object to the node */
	if(!est_node_put_doc(node, doc)){
	  fprintf(stderr, "error: %d\n", est_node_status(node));
	}
        printf("\n URL ID : %s Added/Updated \n", cBufferUri);
}

2) Delete Node by using est_node_out_doc_by_uri()

1
2
3
4
5
6
7
8
static void
outNode(ESTDOC *doc ,ESTNODE *node, char *cBufferUri)
{       
        if(!est_node_out_doc_by_uri(node, cBufferUri)){
	  fprintf(stderr, "error: %d\n", est_node_status(node));
	}
        printf("\n URL ID : %s Deleted\n", cBufferUri);
}

3) View Node by using est_node_get_doc_attr_by_uri()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
static void
listNode(ESTDOC *doc ,ESTNODE *node, char *cBufferUri)
{       
	char *pUrl;
 
        if(!(pUrl = est_node_get_doc_attr_by_uri(node, cBufferUri,"url"))){
	  fprintf(stderr, "error: %d\n", est_node_status(node));
	}
 
        printf("\n URL ID : %s\n", cBufferUri);
        printf(" URL Value : %s\n", pUrl);
 
	pUrl=NULL;
}

Here is the full source code

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
 * HyperIndex.c
 *
 *      Simple Interface For Hyper Estraier
 *
 *  	gcc -o HyperIndex HyperIndex.c -L/usr/local/lib -lestraier -lresolv -lnsl -lpthread -lqdbm -lz -liconv -lm -lc
 *    
 */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
 
#include <estraier.h>
#include <estnode.h>
#include <cabin.h>
#include <string.h>
 
static void
putNode(ESTDOC *doc ,ESTNODE *node, char *cBufferUri ,char *cBufferUrl)
{
	/* add attributes to the document object */
	est_doc_add_attr(doc, "@uri", cBufferUri);
	est_doc_add_attr(doc, "@title", cBufferUri);
	est_doc_add_attr(doc, "url", cBufferUrl);//for include function
 
	/* add the body text to the document object */
	est_doc_add_text(doc, cBufferUrl);
 
	/* register the document object to the node */
	if(!est_node_put_doc(node, doc)){
	  fprintf(stderr, "error: %d\n", est_node_status(node));
	}
 
        printf("\n URL ID : %s Added/Updated \n", cBufferUri);
 
}
 
static void
listNode(ESTDOC *doc ,ESTNODE *node, char *cBufferUri)
{       
	char *pUrl;
 
        if(!(pUrl = est_node_get_doc_attr_by_uri(node, cBufferUri,"url"))){
	  fprintf(stderr, "error: %d\n", est_node_status(node));
	}
 
        printf("\n URL ID : %s\n", cBufferUri);
        printf(" URL Value : %s\n", pUrl);
 
	pUrl=NULL;
}
 
 
static void
outNode(ESTDOC *doc ,ESTNODE *node, char *cBufferUri)
{       
 
        if(!est_node_out_doc_by_uri(node, cBufferUri)){
	  fprintf(stderr, "error: %d\n", est_node_status(node));
	}
 
        printf("\n URL ID : %s Deleted\n", cBufferUri);
 
}
 
int
main(int argc, char **argv)
{
    //calculate program time elapsed
    time_t start, stop;
    clock_t ticks; long count;
 
    //Get user input
    char cBufferFlag[1];
    char cBufferUri[256];
    char cBufferUrl[256];
 
    //start time
    time(&start);
 
    //ESTDOC *est_node_get_doc_by_uri(ESTNODE *node, const char *uri);
 
    ESTNODE *node;
    ESTDOC *doc;
    /* initialize the network environment */
    if(!est_init_net_env()){
      fprintf(stderr, "\nerror: network is unavailable\n");
      return 1;
    }
 
    /* create and configure the node connection object */
    node = est_node_new("http://localhost:1978/node/pattern");
    est_node_set_auth(node, "admin", "admin");
 
    /* create a document object */
    doc = est_doc_new();
 
    printf("\n 1=Insert 2=Update 3=Delete 4=List");
    printf("\n Please Enter Opereation : ");
    scanf("%s",cBufferFlag);
 
 
    if(!strcmp(cBufferFlag, "1") || !strcmp(cBufferFlag, "2"))
    {
    	printf(" Please Enter URL ID : ");
    	scanf("%s",cBufferUri);
 
    	printf(" Please Enter URL : ");
    	scanf("%s",cBufferUrl);
 
        //insert / update
    	putNode(doc,node,cBufferUri,cBufferUrl);
 
    }
    else if(!strcmp(cBufferFlag, "3"))
    {
    	printf(" Please Enter URL ID : ");
    	scanf("%s",cBufferUri);
        //delete url info
    	outNode(doc,node,cBufferUri);
 
    }
    else if(!strcmp(cBufferFlag, "4"))
    {
    	printf(" Please Enter URL ID : ");
    	scanf("%s",cBufferUri);
        //list url info
    	listNode(doc,node,cBufferUri);
 
    }
    else
    {
	exit(1);
    }
 
 
    /* destroy the document object */
    est_doc_delete(doc);
 
 
    /* destroy the node object */
    est_node_delete(node);
    /* free the networking environment */
    est_free_net_env();
 
    //stop time
    time(&stop);
 
    printf("\nFinished in about %.0f seconds. \n\n", difftime(stop, start));
 
    return 0;
}

How to check directory file size on linux (Solution)

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (1 votes, average: 2 out of 10)
Loading ... Loading ...

hmm… linux whatever also in command line, it really make me uncomfortable, i even need to issue a command to check a directory size.

du -lh

P.S
always issue -h to display file size in human readable format

check-directory-size-on-linux

We can check summary of a directory by issuing

du -sh <directory>

How to remove Whitespace between String - Java

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (3 votes, average: 6 out of 10)
Loading ... Loading ...

Today i play around with some funny and simple thing in Java, frankly i really do not know about it. I created following code like below

if(StringUtils.hasLength(sText)
 {
     sText= sText.replaceAll(" ", " AND ");			   
}

What i trying to do is remove all whitespace between a string. for example, user key in “Hello Google”, it will replace as “Hello AND Google”, ya this is correct if user only enter one space between word.

"Hello Google"  ---> "Hello AND Google"

But how about user key in many space in between? Haha.. For example

"Hello           Google"  ---> "Hello AND AND AND AND AND Google"

Above is not what i want, should i replace it as below?

if(StringUtils.hasLength(sText)
 {
     sText= sText.replaceAll(" ", " AND ");
     sText= sText.replaceAll("  ", " AND ");	
     sText= sText.replaceAll("   ", " AND ");	
     sText= sText.replaceAll("    ", " AND ");	
     sText= sText.replaceAll("     ", " AND ");				   
}

ya we can replace as many as we like, but this is not so effective and dynamic enough. Finally Regular Expression come to place and solve it.

if(StringUtils.hasLength(sText)
 {
     sText= sText.replaceAll("\\s+", " AND ");		   
}

Great , exactly what i want, Regular Expression ROCK!!!