Tuesday, December 7, 2010

Validate textbox in Graphical User Interface containing only numbers


Often it is necessary to validate the input data in the Graphical User Interface when received at the server side. According to the received parameters the server may be not called if the parameters are not in the desired format. This will lead to a saving in the used resources server side. This can be easily done by performing a basic validation on the properties of the object received. The validation proposed here below could be smaller by using regular expressions.
The programming code below just loop on a received string and determines if every character of the string is a digit isDigit(). The loop stops if a character is not a digit and returns false.




/**
*
* @author Jose Ferreiro
*/
public class Main {

/**
* This method checks if a String contains only numbers
*/
public boolean containsOnlyNumbers(String str) {

//It can't contain only numbers if it's null or empty...
if (str == null || str.length() == 0)
return false;

for (int i = 0; i < str.length(); i++) {

//If we find a non-digit character we return false.
if (!Character.isDigit(str.charAt(i)))
return false;
}

return true;
}


/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Main main = new Main();
System.out.println(main.containsOnlyNumbers("123456"));
System.out.println(main.containsOnlyNumbers("123abc456"));
}
}


OUTPUT of the main method:
True
False

HAPPY CODING

Saturday, December 4, 2010

Custom 404 Page Using JBOSS (for audit purposes)




Having a custom “page not found”, or 404 page, is an important modification for any website. It’s used to enhance the user experience by presenting an easy to understand message. Sometimes it is also useful to hide information contained in those pages as it reveals information about the server it self, release etc, etc


Setting up a user friendly error page is simple enough using Apache web server. Just modify the line in httpd.conf and point it to a static HTML document:

ErrorDocument 404 /the404_page.html

With JBOSS (or Tomcat-like Java container) application server, it’s slightly trickier. It has to be handled per web application basis. The change is done on the web.xml file, with these entries:

<error-page>

<error-code>404</ error-code>
<location>/404.html < / location >
< /error-page >

For the root directory, modify the web.xml in the ./deploy/jboss-web.deployer/ROOT.war/WEB-INF directory.

Thursday, October 28, 2010

Java lang String Calculate MD5

The java.lang.String class does not provide a faster way to code the MD5 algorithm, surely for security reasons.

Here a quick way to do implement is a a static class

1.import java.security.MessageDigest;
2.import java.security.NoSuchAlgorithmException;
3.
4.public class LMD5Gen {
5.
6. public static String md5(String input){
7. String res = "";
8. try {
9. MessageDigest algorithm = MessageDigest.getInstance("MD5");
10. algorithm.reset();
11. algorithm.update(input.getBytes());
12. byte[] md5 = algorithm.digest();
13. String tmp = "";
14. for (int i = 0; i < md5.length; i++) {
15. tmp = (Integer.toHexString(0xFF & md5[i]));
16. if (tmp.length() == 1) {
17. res += "0" + tmp;
18. } else {
19. res += tmp;
20. }
21. }
22. } catch (NoSuchAlgorithmException ex) {}
23. return res;
24. }
25.
26.}

Sunday, October 17, 2010

Middleware : Service-Oriented Architectures (SOA) using BPEL components

Future is the next generation of Business Integration through Service-Oriented Architecture (SOA). Legacy integration technologies are too complex and require proprietary skills to develop, support, and maintain. Standards have cleared the path to develop truly composite applications that leverage existing technology investments, promote mainstream developer adoption, and adapt to future technological advances.



Tuesday, September 28, 2010

Sistine Chapel on-line || Vatican City state

Check it out the online version of the Sistine Chapel (Italian: Cappella Sistina) at the Vatican City state (Italian: Stato della Città del Vaticano) by Michelangelo, the Italian Renaissance painter that paint it on the XV century.
Last week I had the privilege to be able to visit it.

http://www.vatican.va/various/cappelle/sistina_vr/index.html



Tuesday, August 24, 2010

The ultimate Wedding Query... (SQL Style)

I am running the following SQL query among the databases instances I managed in different MS SQL servers for fun....

At that point, I should say that the desired "tuple" has not yet been found :-( . . . .




Details of the SQL query follow:

--
-- Funny query
-- Date: 25 August 2010
--
-- The ultimate Wedding Query................ (SQL Style)

-- HUSBANDS QUERY

CREATE PROCEDURE MyMarriage(BrideGroom Male (25),Bride Female(20) )
AS BEGIN
SELECT Bride FROM Beautiful_ Brides
WHERE FatherInLaw = 'Millionaire'
AND Count(Car) > 20 AND HouseStatus ='ThreeStoreyed'
AND BrideEduStatus IN (B.TECH ,BE ,Degree ,MCA ,MiBA, PHD) AND Having Brothers= Null
AND Sisters =Null


SELECT Gold, Shares, Cash, Car, BankBalance
FROM FatherInLaw
UPDATE MyBankAccout
SETMyBal = MyBal + FatherInLawBal
UPDATE MyLocker
SET MyLockerContents = MyLockerContents + FatherInLawGold
INSERT INTOMyCarShed VALUES('Porsche')
END
GO

-- Then the wife writes the below query:
DROP HUSBAND;
Commit;

-- (-:

Tuesday, August 17, 2010

My Super Server - version 2010

The server that is presented is as worth as the car below (second hand)! Next, see some snapshots I took from the Operating System (Windows Server 2008 RC2 64 bits).





The monster: HP Proliant ML570R G4 server



RAM: 16 x 4 GB = 64 GIGABYTES !!!!! I may tell you with this you will not have problems with multi threading.




STORAGE of 12 x 1000 Gigabytes (1.0 TB) = 12 Terrabytes !!!! = > 12.0 TB
Additional storage of 1.0 TB for C and D drives. See snapshot below.



Happy surfing!