Wednesday, November 4, 2009

Phoebus Play List

Tuesday, October 27, 2009

Include another bash script of functions

Add the following line to your bash script:
source functions.bash

Friday, June 5, 2009

Axis2 AxisFault Connection Refused in an Applet

Problem:
When running an applet from Eclipse to call an Axis2 web service, I got the following error:


org.apache.axis2.AxisFault: Connection refused: connect
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:193)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:371)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:209)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:448)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:401)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)

Solution:
In the applet, add the following code in the init() method where 8080 is my Tomcat port number:

public void init(){
System.setProperty("http.proxyPort", "8080");
}

When running an Applet, the port number is set to default 80.
According to the documentation from apache.org, when getting a Connection refused error, it is because "The host exists, nothing is listening for connections on that port. Alternatively, a firewall is blocking that port. Site Finder: the URL is using a port other than 80, and the .com or .net address is invalid"

Reference to http://ws.apache.org/axis/java/client-side-axis.html

Monday, June 1, 2009

Axis2 Service Archiver java.lang.NoClassDefFoundError

Problem:
When running the Axis2 Service Archiver, I got the following error: java.lang.NoClassDefFoundError



Solution:
1. Close Eclipse.
2. Open an explore window and navigate to your workspace. Under your workspace folder, open .metadata folder and then open .plugins folder, and then open the Axis2_Service_Archiver folder. Now you should see a file called "dialog_settings.xml", delete that file.
3. Restart Eclipse.

Looks like Eclipse cashed plugin related information in that xml file. If something is wrong in that xml file, you'll get this error.

Friday, May 22, 2009

Create/Deploy/Test a Signed Applet

1. Package the applet into a JAR file:
The applet must be in a JAR file before a certificate can be attached to it. Use the jar JDK utility. If the applet was previously referenced with the help of a codebase attribute in <applet> tag, replace the codebase attribute with the archive attribute. The value of the archive attribute is a URL of a JAR file.

   $ jar -cvf SignedApplet.jar *.class
2. Create a public/private key pair. The command for this is

$ keytool -genkey -alias signFiles
-keystore compstore
-keypass kpi135 -dname "cn=jones"
-storepass ab987c

Verify your keystore:

$ keytool -list -keystore compstore
-storepass ab987c

Keystore type: jks
Keystore provider: SUN

Your keystore contains 1 entry

signfiles, May 21, 2009, keyEntry,
Certificate fingerprint (MD5): 20:3D:6D:A0:20:71:2D:85:7D:72:6C:23:B5:2F:16:D7
$
keytool is another SDK utility. It will prompt you for a password to your keystore and for the remaining parameters, one of which is alias, whose value is the name of the key. The keystore is a file that contains your public/private key-pairs, and the public-keys of others with whom you exchange information. See the documentation in the above link.

3. Create a certificate for the key you created in the previous step.
$ jarsigner -keystore compstore
-storepass ab987c
-keypass kpi135
-signedjar SSignedApplet.jar SignedApplet.jar signFiles
Again, keytool will prompt you for a keystore password and remaining parameters. This certificate is now self-signed by you, meaning that it has not been validated by any third party. This is suitable for demo purposes, and may be acceptable to yourself and those who know you because if there is any doubt that the certificate is really yours they can always call you up and ask you for the digest to verify that it is really you and not some impostor that created the certificate. However, if this applet were to be widely distributed, and you wanted it to be accepted by those who do not know you personally, you would certainly want to pay a modest fee to obtain a certificate that is validated by a trusted certificate authority. The procedure for this is straightforward, but beyond the scope of this simple tutorial.

4. Run jarsigner associate this certificate with the JAR file that contains your applet.
You will need to give the name of the public key of the certificate you just created. This creates a digest for each file in your JAR and signs them with your private key. These digests or hashes, the public key, and the certificate will all be included in the "WEB-INF" directory of the JAR.

Verify your signed applet jar file:

$ jar -tvf SignedApplet.jar
25 Thu May 21 14:56:42 MST 2009 META-INF/MANIFEST.MF
141 Thu Sep 25 02:11:08 MST 2008 java.policy.applet
776 Thu May 21 14:09:50 MST 2009 appletexample/Welcome.class
2005 Thu May 21 14:49:22 MST 2009 appletexample/SignedAppletDemo.class

$ jar -tvf SSignedApplet.jar
265 Thu May 21 15:00:56 MST 2009 META-INF/MANIFEST.MF
432 Thu May 21 15:00:56 MST 2009 META-INF/SIGNFILE.SF
762 Thu May 21 15:00:56 MST 2009 META-INF/SIGNFILE.DSA
141 Thu Sep 25 02:11:08 MST 2008 java.policy.applet
776 Thu May 21 14:09:50 MST 2009 appletexample/Welcome.class
2005 Thu May 21 14:49:22 MST 2009 appletexample/SignedAppletDemo.class

5. Update your html files to use the signed applet jar file:
Welcome.html: within your applet tag
code="appletexample/Welcome.class"
archive="SSignedApplet.jar"
width="500" height="400"
SignedApplet.html: within your applet tag
code="appletexample/SignedAppletDemo.class"
archive="SSignedApplet.jar"
param="" name="file" value="/"
width="400" height="400"
6. Deploy the html and jar files to Apache HTTP server:
Copy Welcome.html, SignedApplet.html, and SSignedApplet.jar (not the SignedApplet.jar) to Apache's htdocs/applet directory (I create a folder called "applet" under htdocs folder).

C:\Apache\Apache2.2\htdocs\applet>dir
Volume in drive C has no label.
Volume Serial Number is 588C-3312

Directory of C:\Apache\Apache2.2\htdocs\applet

05/22/2009 10:24 AM <DIR> .
05/22/2009 10:24 AM <DIR> ..
05/22/2009 10:21 AM 247 SignedApplet.html
05/21/2009 03:00 PM 3,794 SSignedApplet.jar
05/22/2009 10:24 AM 173 Welcome.html
3 File(s) 4,214 bytes
2 Dir(s) 25,086,658,560 bytes free

C:\Apache\Apache2.2\htdocs\applet>

7. Test your Signed Applet from localhost:
Your applet is now signed. The next time you or someone else downloads it in it's page the browser will present a dialog box displaying the credentials you just created for it and asking the user permission to run it. If he/she chooses not to, the applet will throw the same AccessControlException that we saw in the Java Console window the first time we tried to run it in our browser. The difference is that now the user gets to make an informed decision as to whether or not they trust your applet to not harm his/her system.



References/Links:
1. <a href="http://www-personal.umich.edu/~lsiden/tutorials/signed-applet/signed-applet.html">Signed Applet Tutorial by Larry Siden</a>
2. <a href="http://java.sun.com/developer/onlineTraining/Programming/JDCBook/signed.html">Tutorials: Chapter 10: Signed Applets from Sun Developer Network</a>

Wednesday, May 20, 2009

Tomcat 6 CGI HTTP status 404 error?

Problem:
HTTP status 404 error?

Solution:
Need to keep the *.cgi files in Tomcat6.0\webapps\ROOT\WEB-INF\cgi folder.

Tomcat 6 CGI java.lang.SecurityException?

Problem:
Servlet of class org.apache.catalina.servlets.CGIServlet is privileged and cannot be
loaded by this web application

Solution:
In Tomcat 6, I noticed that the servlet-cgi.jar is now part of catalina.jar
Change the $CATALINA_BASE/conf/context.xml
From: <Context>
To : <Context privileged="true">

Tomcat 6 CGI: java.io.IOException: CreateProcess: perl

Problem:
java.io.IOException: CreateProcess: perl "C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ROOT\WEB-INF\cgi\test.txt" error=2

Solution:
Update the conf/web.xml to add the follings:
FROM:


<servlet>
<servlet-name>cgi</servlet-name>
<servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>cgiPathPrefix</param-name>
<param-value>WEB-INF/cgi</param-value>
</init-param>

<load-on-startup>5</load-on-startup>
</servlet>

TO:

<servlet>
<servlet-name>cgi</servlet-name>
<servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>cgiPathPrefix</param-name>
<param-value>WEB-INF/cgi</param-value>
</init-param>

<init-param>
<param-name>executable</param-name>
<param-value>cmd /c</param-value>
</init-param>

<load-on-startup>5</load-on-startup>
</servlet>

Restart Tomcat.

Just an FYI.... I still can't enable CGI in Tomcat 6 after fixing this issue. What the $%@#$%

Tomcat auto-configure Issue: cannot find the path specified

Problem:
httpd.exe: Syntax error on line 484 of C:/Program Files/Apache Software Foundation/Apache2.2/conf/httpd.conf:
Could not open configuration file C:/Program/ Files/Apache/ Software/ Foundation/Tomcat/ 6.0/conf/jk/mod_jk.conf-auto:
The system cannot find the path specified.

Solution:
Looks like Apache doesn't like spaces in the path (i.e. "C:\Program Files\...". Reinstall Apache HTTP server and Tomcat server without spaces in the install paths.
Don't use the default install path for both Apache 2.2 and Tomcat 6.

Click the link for more information about how to install Apache 2.2 and Tomcat 6....

Tomcat auto-configure Issue: The specified module could not be found

Problem:
httpd.exe: Syntax error on line 484 of C:/Apache/Apache2.2/conf/httpd.conf:
Syntax error on line 4 of C:/Apache/Tomcat6.0/conf/jk/mod_jk.conf-auto: Cannot load
C:/Apache/Apache2.2/modules/mod_jk-apache-2.2.3.so into server:
The specified module could not be found.

Solution:
The module file I copied was mod_jk-1.2.28-httpd-2.2.3.so, I forgot to rename it.
What the #$%@...
Rename it to mod_jk-apache-2.2.3.so and it fixed the issue.

Click the link for more information about how to install Apache 2.2 and Tomcat 6....

Apache 2.2 + Tomcat 6 Installation and Configuration on Windows XP SP2

This summary is not available. Please click here to view the post.

Monday, May 18, 2009

Tomcat 6 ServiceStart returned 3 Error

Problem:
After downloading TomCat 6.0 and installing the .exe, everything was smooth and i left most of the settings as default. I'm having problems starting my tomcat 6.0 service in "Configure" on my windows XP sp2. It was unable to start the service after install. And, it gave me the following errors in the jakarta_service_20090518.log.


[2009-05-18 16:25:00] [443 javajni.c] [error]
FindClass org/apache/catalina/startup/Bootstrap failed
[2009-05-18 16:25:00] [1005 prunsrv.c] [error]
Failed loading main
org/apache/catalina/startup/Bootstrap class
C:\Program Files\Apache Software Foundation\Tomcat 6.0\bin\bootstrap.jar
[2009-05-18 16:25:00] [1269 prunsrv.c] [error]
ServiceStart returned 3


Solution:
I found that there are more than one java jre installed on my windows XP, one is located on
C:\java\jre1.5.0_16
and the other is located on
C:\Program Files\Java\jdk1.5.0_16\jre
. When re-installing Tomcat 6, I changed the default
C:\java\jre1.5.0_16
to
C:\Program Files\Java\jdk1.5.0_16\jre
, and it fixed those errrors.

Monday, April 20, 2009

date Function

add 5 years/months/days/hours/minutes/seconds to current date/time

$ date +%Y%m%d%H%M%S; date --date "now +5 years" +%Y%m%d%H%M%S
20090420161628
20140420161628
$ date +%Y%m%d%H%M%S; date --date "now +5 months" +%Y%m%d%H%M%S
20090420161639
20090920161639
$ date +%Y%m%d%H%M%S; date --date "now +5 days" +%Y%m%d%H%M%S
20090420161646
20090425161646
$ date +%Y%m%d%H%M%S; date --date "now +5 hours" +%Y%m%d%H%M%S
20090420161654
20090420211654
$ date +%Y%m%d%H%M%S; date --date "now +5 minutes" +%Y%m%d%H%M%S
20090420161659
20090420162159
$ date +%Y%m%d%H%M%S; date --date "now +5 seconds" +%Y%m%d%H%M%S


subtract xxx to current date/time

$ date +%Y%m%d%H%M%S; date --date "now -5 years" +%Y%m%d%H%M%S
20090420161922
20240420161922

$ date +%Y%m%d%H%M%S; 
date --date "now -5 years -1 months" +"%Y/%m/%d %H:%M:%S"
20090420162122
2004/03/20 16:21:22

Friday, February 13, 2009

Java.SQL.Exception The Network Adapter could not establish the connection

1. The port number can be 1526 or 1521. Confirm with tnsnames.ora on the Oracle Server.
2. If that is all right, then use the IP address of the Oracle host, rather than the name.

Tuesday, January 27, 2009

Empty Values Assigned to Variables in webMethods

Only when your are testing a Flow Service from webMethods Developer, you can pass an empty string ( or zero-length string ) to a service.



If you want to pass empty variables (variables that have no value), enable the "Include empty values for String Types" check box. When you enable this option, empty String variables are passed with a zero-length value. If you do not enable this option, the variables will be removed from pipelines.

Thursday, January 22, 2009

Map the first name from a document list

1. Add a MAP to your process flow
2. In Properties window, enter "Get the first name" to property Comments.
3. Drag a link line between records.name in Pipeline In to firstName in Pipeline Out.
4. Notice that when you click on the link, it displays the link's Properties.
5. Click on the "Edit..." button of the Indices property.
6. Enter 0 to the records text box, and then click on OK button
7. Notice that the color of the link changed to blue like below:

Insert SYSDATE via JDBC Adapter Service

This is how you can insert a Date + Time to Oracle DATE field in webMethods:

1. Open a new Adapter Serivce
-> Select "JDBC Adapter" type, click Next
-> Select your database "Adapter Connection Alias", click Next
-> Select "InsertSQL" Template, click Next
-> Enter the name of your new Adapter Service, click Finish

2. Select your table under Table tab

3. Add the system date column under INSERT tab.

4. Highlight your date column
-> Double click on the Expression field
-> Enter TO_DATE(TO_CHAR(sysdate, 'DD-MON-YYYY hh:mi:ss'),
'DD-MON-YYYY hh:mi:ss')

Oracle Triggers

CREATE OR REPLACE TRIGGER EBP.INSERT_EBP_TRADING_PARTNERS
BEFORE INSERT
ON EBP.EBP_TRADING_PARTNERS
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
tmpVar NUMBER;
v_fax_subject_line VARCHAR2(60);
BEGIN
tmpVar := 0;

SELECT SUBJECT_LINE INTO v_fax_subject_line FROM EBP_BILLERS WHERE BILLER_ID = :NEW.BILLER_ID;

IF :NEW.FAX_SUBJECT IS NULL THEN
:NEW.FAX_SUBJECT := v_fax_subject_line;
END IF;

EXCEPTION
WHEN NO_DATA_FOUND THEN
dbms_output.put_line('Warning: The Biller_Id does not exist in EBP_BILLERS table.');

END ;
/

Select between dates in Oracle SQL

SQL> with t as 
(select to_date('01/01/2007',
'dd/mm/yyyy') as update_date from dual union all
2    select to_date('01/01/2007',
'dd/mm/yyyy') from dual union all
3    select to_date('03/01/2007',
'dd/mm/yyyy') from dual union all
4    select to_date('03/01/2007',
'dd/mm/yyyy') from dual union all
5    select to_date('03/01/2007', 
'dd/mm/yyyy') from dual union all
6    select to_date('04/01/2007', 
'dd/mm/yyyy') from dual union all
7    select to_date('05/01/2007', 
'dd/mm/yyyy') from dual union all
8    select to_date('07/01/2007', 
'dd/mm/yyyy') from dual union all
9    select to_date('07/01/2007', 
'dd/mm/yyyy') from dual)
10  -- end of test data
11  select to_char(x.UPDATE_DATE,  
'YYYY-MM-DD') as update_date, 
DECODE(t.update_date, NULL, 0, count (*)) 
as count
12  from (select to_date('2007-01-01 00:00:00', 
'YYYY-MM-DD HH24:MI:SS')+
(rownum-1) as update_date
13        from   dual
14        connect by rownum <= 
(to_date('2007-02-01 00:00:00', 
'YYYY-MM-DD HH24:MI:SS')-
15             to_date('2007-01-01 00:00:00', 
'YYYY-MM-DD HH24:MI:SS'))) x
16        LEFT OUTER JOIN t 
ON (x.update_date = t.update_date)
17  where x.UPDATE_DATE >= 
to_date('2007-01-01 00:00:00', 
'YYYY-MM-DD HH24:MI:SS')
18  and x.UPDATE_DATE < 
color="navy">'2007-02-01 00:00:00', 
'YYYY-MM-DD HH24:MI:SS')
19  group by to_char(x.UPDATE_DATE, 'YYYY-MM-DD'), 
t.update_date
20  order by 1
21  /

UPDATE_DAT      COUNT
---------- ----------
2007-01-01          2
2007-01-02          0
2007-01-03          3
2007-01-04          1
2007-01-05          1

Regular Expression Tips

JavaScript Tester: http://codespec.blogspot.com/2007/10/regular-expression-tips.html

foob.*r
: matchs strings like 'foobar', 'foobalkjdflkj9r' and 'foobr'
foob.+r : matchs strings like 'foobar', 'foobalkjdflkj9r' but not 'foobr'
foob.?r : matchs strings like 'foobar', 'foobbr' and 'foobr' but not 'foobalkj9r'
fooba{2}r : matchs the string 'foobaar'
fooba{2,}r : matchs strings like 'foobaar', 'foobaaar', 'foobaaaar' etc.
fooba{2,3}r : matchs strings like 'foobaar', or 'foobaaar' but not 'foobaaaar'

Metacharacters \1 through \9 are interpreted as backreferences. \ matches previously matched subexpression #.

Examples:

(.)\1+ matchs 'aaaa' and 'cc'.
(.+)\1+ also match 'abab' and '123123'
(['"]?)(\d+)\1 matchs '"13" (in double quotes), or '4' (in single quotes) or 77 (without quotes) etc

Metacharacters - line separators

^ start of line
$ end of line
\A start of text
\Z end of text
. any character in line

Examples:

^foobar matchs string 'foobar' only if it's at the beginning of line
foobar$ matchs string 'foobar' only if it's at the end of line
\^foobar$ matchs string 'foobar' only if it's the only string in line
\foob.r matchs strings like 'foobar', 'foobbr', 'foob1r' and so on


Metacharacters - predefined classes

\w an alphanumeric character (including "_")
\W a nonalphanumeric
\d a numeric character
\D a non-numeric
\s any space (same as [ \t\n\r\f])
\S a non space

You may use \w, \d and \s within custom character classes .

Examples:

\foob\dr matchs strings like 'foob1r', ''foob6r' and so on but not 'foobar', 'foobbr' and so on
\foob[\w\s]r matchs strings like 'foobar', 'foob r', 'foobbr' and so on but not 'foob1r', 'foob=r' and so on

CONCAT Strings in Oracle v.s. MySQL

Oracle uses the CONCAT(string1, string2) function or the || operator. The Oracle CONCAT function can only take two strings so the above example would not be possible as there are three strings to be joined (FirstName, ' ' and LastName). To achieve this in Oracle we would need to use the || operator which is equivalent to the + string concatenation operator in SQL Server / Access.

-- Oracle
SELECT FirstName || ' ' || LastName As FullName FROM Customers

MySQL uses the CONCAT(string1, string2, string3...) function. The above example would appear as follows in MySQL

-- MySQL
SELECT CONCAT(FirstName, ' ', LastName) As FullName FROM Customers

Backup MySQL Database

Full backup:
echo "============================================================"
echo "Backup $dbName database to $dbFile"

# The following commands will be put to the beginning of the database dump file.
echo " 1. Creating header.tmp temporary file"
echo "SET AUTOCOMMIT = 0;SET FOREIGN_KEY_CHECKS=0;" > $dbDir/header.tmp

# Dumping the database.
echo " 2. Creating $dbName.tmp temporary file"
mysqldump --opt --user=$dbUSER --password=$dbPASSWORD $dbName > $dbDir/$dbName.tmp

# The following commands will be put to the end of the database dump file.
echo " 3. Creating tailer.tmp temporary file"
echo "SET FOREIGN_KEY_CHECKS = 1;COMMIT;SET AUTOCOMMIT = 1;" > $dbDir/tailer.tmp

echo " 4. Create today's backup file : $dbFile"
cat $dbDir/header.tmp $dbDir/$dbName.tmp $dbDir/tailer.tmp > $dbDir/$dbFile

Backup Schema Only:
$ mysqldump --no-data --user=$dbUSER --password=$dbPASSWORD $dbName > Schema20081003.sql

Search by Attribute and print RANum and position()

XML:

<InvoiceAdj>
<RAInfo RANumType="79">
<RANum>RANumType_79</RANum>
</RAInfo>
<RAInfo RANumType="82">
<RANum>RANumType_82</RANum>
</RAInfo>
<RAInfo RANumType="85">
<RANum>RANumType_85</RANum>
</RAInfo>
<RAInfo RANumType="88">
<RANum>RANumType_88</RANum>
</RAInfo>
<RAInfo RANumType="79">
<RANum>RANumType_79_1</RANum>
</RAInfo>
<RAInfo RANumType="82">
<RANum>RANumType_82_1</RANum>
</RAInfo>
<RAInfo RANumType="85">
<RANum>RANumType_85_1</RANum>
</RAInfo>
<RAInfo RANumType="88">
<RANum>RANumType_88_1</RANum>
</RAInfo>
</InvoiceAdj>

XSLT: Search by attribute RANumType = 79 or 88
<xsl:for-each select="InvoiceAdj/RAInfo">
<xsl:choose>
<xsl:when test="@RANumType = 79 or @RANumType = 88">
<tr>
<td><xsl:value-of select="RANum"/></td>
<td><xsl:value-of select="position()"/></td>
<td></td>
</tr>
</xsl:when>
</xsl:choose>
</xsl:for-each>

HTML:
<tr>
<td>RANumType_79</td>
<td>1</td>
<td></td>
</tr>
<tr>
<td>RANumType_88</td>
<td>4</td>
<td></td>
</tr>
<tr>
<td>RANumType_79_1</td>
<td>5</td>
<td></td>
</tr>
<tr>
<td>RANumType_88_1</td>
<td>8</td>
<td></td>
</tr>

xsl:for-each sample:

xml:

<InvoiceAdj AdjType="CS" AdjNumType="BP">

1. <xsl:for-each select="InvoiceAdj">

2. <xsl:for-each select="InvoiceAdj[@AdjType='CS']">

3. <xsl:for-each select="InvoiceAdj[@AdjType='CS' and @AdjNumType = 'BP']">

Legal filter operators are:

1. = (equal)
2. != (not equal)
3. &lt; less than
4. &gt; greater than

Search by Element and print RANum and position()

XML:

<InvoiceAdj>
<RAInfo RANumType="79">
<RANum>RANumType_79</RANum>
</RAInfo>
<RAInfo RANumType="82">
<RANum>RANumType_82</RANum>
</RAInfo>
<RAInfo RANumType="85">
<RANum>RANumType_85</RANum>
</RAInfo>
<RAInfo RANumType="88">
<RANum>RANumType_88</RANum>
</RAInfo>
<RAInfo RANumType="79">
<RANum>RANumType_79_1</RANum>
</RAInfo>
<RAInfo RANumType="82">
<RANum>RANumType_82_1</RANum>
</RAInfo>
<RAInfo RANumType="85">
<RANum>RANumType_85_1</RANum>
</RAInfo>
<RAInfo RANumType="88">
<RANum>RANumType_88_1</RANum>
</RAInfo>
</InvoiceAdj>


XSLT: Search by attribute RANum = 'RANumType_88'
<xsl:for-each select="InvoiceAdj/RAInfo">
<xsl:choose>
<xsl:when test="RANum = 'RANumType_88'">
<tr>
<td><xsl:value-of select="RANum"/></td>
<td><xsl:value-of select="position()"/></td>
<td></td>
</tr>
</xsl:when>
</xsl:choose>
</xsl:for-each>

HTML:
<tr>
<td>RANumType_88</td>
<td>4</td>

Increment a variable in for-each loop

Sorry, no can do.

XSLT is a declarative programming language. You can bind a value to a variable only once, you cannot change it later. <link>

string replacement

Sometimes you want to replace one string with another. This is done with the ex command "s". The form of the replacement is :

: line_range s/old/new/g
ex ( replace foo with bar from line 10 to 20 ) :
:10,20s/foo/bar/g
You can use visual mode to select the lines, when you type the colon to start the command it will use symbols for the visual line range.

vi commands

Switch to command mode

ESC start command mode ( it starts in command mode )
i change to insert mode
:q quit
:wq write and quit
:w write the file
:# goto line #
/str search down for "str"
?str search up for "str"
dd delete line
x delete character
dw delete word ( cut )
yy yank line ( copy )
yw yank word
p paste
u undo ( only limit is the last write )
. repeat last change
cw change word

Go to line number ## :##

Undo previous command: u

Undo all changes to line: U

Search backward for string: ?string

Search forward for string: /string

% (entire file) s (search and replace) /old text with new/ c (confirm) g (global - all): %s/oldstring/newstring/cg

Delete 5 lines (to buffer): 5dd

Delete lines 5-10:5,10d

Rounding Numbers

Need to be able to round numbers in bash to the nearest whole number? You can use a single line of code in AWK to do the job. For example, the following code will make the number 29.498398 round up to 29.50:

$ echo 29.498398 | awk '{ rounded = sprintf("%.2f", $1); print rounded }'
29.50

Remove first 3 lines in a file

$cat bearish.htm | awk 'NR>3'

while statement

C-style while loop:

#!/bin/bash
# wh-loopc.sh: Count to 10 in a "while" loop.
LIMIT=10
a=1
while [ "$a" -le $LIMIT ]
do
echo -n "$a "
let "a+=1"
done           # No surprises, so far.
echo; echo
# +=================================================================+

# Now, repeat with C-like syntax.

# Double parentheses permit space when setting a variable, as in C.
((a = 1))      # a=1

# Double parentheses, and no "$" preceding variables.
while (( a <= LIMIT ))
do 
echo -n "$a "  
((a += 1))
# Double parentheses permit incrementing a variable with C-like syntax.
done
exit 0

# +=================================================================+
# reading a file line by line

while read line 
do 
echo "${line}"
done < ./straddle.prop



case statement

case $1 in
-s) sec=1; shift;;
-m) sec=60; shift;;
-h) sec=3600; shift;;
-d) sec=86400; shift;;
*) sec=86400;;
esac

Float/Real Number Comparison

if [ $( echo "5.5 > 10.5" | bc ) -eq 1 ]; then
echo 5.5 is greater than 10.5.
else
echo 5.5 is NOT greater than 10.5.
fi
=> 5.5 is NOT greater than 10.5.

Regular Expression in if in bash script

if echo "4567" | grep -q "^4"; then
echo "4567 is started with a 4."
elif echo "4567" | grep -q "^A"; then
echo "4567 is started with a A."
else
echo "4567 is NOT started with a 4 or A."
fi

Get Create Table statement from MySQL

$ sql "show create table my_table\G" | sed -e '1,2d;s/Create Table: //'
Note: sed -e '1,2d' removes the first 2 lines.

Change Prompt

$
$ PS1="myPrompt> "
myPrompt>
myPrompt>

Calulation in bash

bash$
bash$ echo "1.5 * 2" | bc -l
3.0
bash$ echo "1/3" | bc -l
.33333333333333333333
bash$
bash$ echo "scale=3; 10/3" | bc
3.333

Finding Files with keywords

% grep "yourString" * | awk '{ if($1!=filename){ filename=$1; print $filename}}'
10000CSCO.txt: <xsl:with-param name="vars" select="yourString"/>
10000ELMR.txt: <xsl:with-param name="vars" select="yourString"/>
10000GLSW.txt: <xsl:with-param name="vars" select="yourString"/>
10000IN04.txt: <xsl:with-param name="vars" select="yourString"/>
10000ISAG.txt: <xsl:with-param name="vars" select="yourString"/>
10000KNG1.txt: <xsl:with-param name="vars" select="yourString"/>
10000KNGT.txt: <xsl:with-param name="vars" select="yourString"/>
10000NETF.txt: <xsl:with-param name="vars" select="yourString"/>
10000NGMK.txt: <xsl:with-param name="vars" select="yourString"/>
10000REPI.txt: <xsl:with-param name="vars" select="yourString"/>
10000SATL.txt: <xsl:with-param name="vars" select="yourString"/>
10000SMRT.txt: <xsl:with-param name="vars" select="yourString"/>
10000VINM.txt: <xsl:with-param name="vars" select="yourString"/>
% 

Wednesday, January 21, 2009

Force XDoclet to rebuild web.xml and jboss-web.xml

Add the following code to eclipse_project_root/xdoclet-build.xml, after XDoclet setup in Eclipse:

<target name="_xdoclet_generation_" depends="ForceRebuild,N65540,N67036"/>
<target name="ForceRebuild" description="Force XDoclet to rebuild web.xml and jboss-web.xml">
<delete file="WEB-INF/web.xml"/>
<delete file="WEB-INF/jboss-web.xml"/>
</target>

"Run XDoclet" in Eclipse does not overwrite WEB-INF/web.xml and WEB-INF/jboss-web.xml. Therefore, you'll have to remove them before running XDoclet.

Change home directory in Cygwin

Put the new home directory in /etc/passwd file.

i.e. Change the following line from:
$ more /etc/passwd
userID:unused_by_nt/2000/xp:57827:10513:LastName, FirstName,DomanName\userID,S-1-5-21-1123561945-1708537768-1801674531-47827: /OldHome/userID:/bin/bash

to:
$ more /etc/passwd
userID:unused_by_nt/2000/xp:57827:10513:LastName, FirstName,DomanName\userID,S-1-5-21-1123561945-1708537768-1801674531-47827: /NewHome/userID:/bin/bash

found in jboss-web.xml but not in web.xml

Solution:
This is the reason why you have to remove web.xml and jboss-web.xml before you run XDoclet in Eclipse.

The web.xml and jboss-web.xml are stored under WEB-INF directory.

========================================================
2009-01-21 12:50:49,855 WARN [org.jboss.web.tomcat.tc5.Tomcat5] Failed to parse descriptors for war(file:/C:/cygwin/usr/local/jboss/server/default/tmp/deploy/tmp64661smsj.ear-contents/smsjWeb.war/)
org.jboss.deployment.DeploymentException: Failed to parse WEB-INF/jboss-web.xml; - nested throwable: (org.jboss.deployment.DeploymentException: ejb-ref ejb/DailyKDSession found in jboss-web.xml but not in web.xml)
at org.jboss.web.AbstractWebContainer.parseMetaData(AbstractWebContainer.java:651)
at org.jboss.web.AbstractWebContainer.init(AbstractWebContainer.java:289)
at org.jboss.deployment.MainDeployer.init(MainDeployer.java:696)
at org.jboss.deployment.MainDeployer.init(MainDeployer.java:713)
at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:631)

Caught Remote Exception - javax.naming.NameNotFoundException: ejb not bound

Solution: Make sure the following XDoclet settings in Eclipse :
1. ejbdoclet.entitypk.pattern={0}PK
2. ejbdoclet.localhomeinterface.pattern={0}LocalHome
3. ejbdoclet.localinterface.pattern={0}Local
4. ejbdoclet.utilobject.pattern={0}Util
5. ejbdoclet.valueobject.pattern={0}Value

Before you re-run XDoclet in Eclipse, remove web.xml and jboss-web.xml under WFB-INF directory.

============================================
2009-01-21 10:16:16,459 ERROR [smsj.server.SMSActionProperty] Caught Remote Exception from WatchListSessionHome or WatchListSession objectejb not bound
2009-01-21 10:16:16,459 INFO [STDOUT] javax.naming.NameNotFoundException: ejb not bound
2009-01-21 10:16:16,459 INFO [STDOUT] at org.jnp.server.NamingServer.getBinding(NamingServer.java:490)
2009-01-21 10:16:16,459 INFO [STDOUT] at org.jnp.server.NamingServer.getBinding(NamingServer.java:498)
2009-01-21 10:16:16,459 INFO [STDOUT] at org.jnp.server.NamingServer.getObject(NamingServer.java:504)
2009-01-21 10:16:16,459 INFO [STDOUT] at org.jnp.server.NamingServer.lookup(NamingServer.java:248)
2009-01-21 10:16:16,459 INFO [STDOUT] at org.jnp.server.NamingServer.lookup(NamingServer.java:251)
2009-01-21 10:16:16,459 INFO [STDOUT] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:530)
2009-01-21 10:16:16,459 INFO [STDOUT] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:644)
2009-01-21 10:16:16,459 INFO [STDOUT] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:509)
2009-01-21 10:16:16,459 INFO [STDOUT] at javax.naming.InitialContext.lookup(InitialContext.java:347)
2009-01-21 10:16:16,459 INFO [STDOUT] at smsj.ejb.interfaces.WatchListSessionUtil.lookupHome(WatchListSessionUtil.java:17)
2009-01-21 10:16:16,459 INFO [STDOUT] at smsj.ejb.interfaces.WatchListSessionUtil.getHome(WatchListSessionUtil.java:36)
2009-01-21 10:16:16,459 INFO [STDOUT] at smsj.server.SMSActionProperty.reloadQuoteFiles(SMSActionProperty.java:170)
2009-01-21 10:16:16,459 INFO [STDOUT] at smsj.server.SMSServerConsole.setQuoteFiles(SMSServerConsole.java:219)
2009-01-21 10:16:16,459 INFO [STDOUT] at smsj.server.SMSServerConsole.run(SMSServerConsole.java:95)