Date formatting in java:
public static Calendar parseTimestamp(String timestamp,Locale locale)
throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat
("dd-MMM-yyyy HH:mm:ss", locale);
Date d = sdf.parse(timestamp);
Calendar cal = Calendar.getInstance();
cal.setTime(d);
return cal;
}
public String getStrDate(Date date,String format, Locale locale) {
SimpleDateFormat formatter;
String str = "";
formatter = new SimpleDateFormat(format, locale);
if (this.getDate() != null) {
str = formatter.format(date.getTime());
}
return str;
}
sexta-feira, 23 de outubro de 2009
Java: Date formatting in java using SimpleDateFormat
quarta-feira, 3 de junho de 2009
Java: System.properties
Different Operating Systems usually require a different syntax. A good example is the file separator char, the line separator or the path separator.
In order not to hard code these values on your source code there's the System.getProperty(String str) static method that receives a String and returns the desired property.
Take a look at http://java.sun.com/docs/books/tutorial/essential/environment/sysprop.html for further information.
In order not to hard code these values on your source code there's the System.getProperty(String str) static method that receives a String and returns the desired property.
Take a look at http://java.sun.com/docs/books/tutorial/essential/environment/sysprop.html for further information.
Java: get Locale Date String
After struggling with the GregorianCalendar, Date and DateFormat classes for a while, here's a simple wrapper to replace the now deprecated date.getLocalizedString():
public static String getLocaleDate(Date date, Locale locale) {
return SimpleDateFormat.getDateInstance(
SimpleDateFormat.SHORT,locale).format(date).toUpperCase();
}
public static String getLocaleDate(Date date, Locale locale) {
return SimpleDateFormat.getDateInstance(
SimpleDateFormat.SHORT,locale).format(date).toUpperCase();
}
terça-feira, 12 de maio de 2009
Java: Call method by reflection
Here's a simple and yet handy function that one can easily include in an Utility class that given an object and one of its method's name, invokes it (with no parameters).
public void callIt(String funcName, Object obj)
{
try
{
Class class= obj.getClass();
Method funcToCall = _class.getMethod(funcName, null);
funcToCall.invoke(obj, null);
}
catch ( Exception _e )
{
System.out.println("Failed to invoke function " + _e);
}
}
public void callIt(String funcName, Object obj)
{
try
{
Class class= obj.getClass();
Method funcToCall = _class.getMethod(funcName, null);
funcToCall.invoke(obj, null);
}
catch ( Exception _e )
{
System.out.println("Failed to invoke function " + _e);
}
}
quarta-feira, 7 de janeiro de 2009
.NET LDAP integration COMException (0x80005000): Unknown error (0x80005000)
Be carefull when working with DirectoryServices in .NET
The following exception:
Exception info:
[COMException (0x80005000): Unknown error (0x80005000)]
can be caused by specifying the LDAP Domain in lowercase when creating the DirectoryEntry:
wrong:
DirectoryEntry entry = new DirectoryEntry("ldap://ldap.myserver.com","domain\\user","pass");
correct:
DirectoryEntry entry = new DirectoryEntry("LDAP://ldap.myserver.com","domain\\user","pass");
The following exception:
Exception info:
[COMException (0x80005000): Unknown error (0x80005000)]
can be caused by specifying the LDAP Domain in lowercase when creating the DirectoryEntry:
wrong:
DirectoryEntry entry = new DirectoryEntry("ldap://ldap.myserver.com","domain\\user","pass");
correct:
DirectoryEntry entry = new DirectoryEntry("LDAP://ldap.myserver.com","domain\\user","pass");
Etiquetas:
.NET,
COMException,
DirectoryEntry,
LDAP,
lowercase,
Unknown error
terça-feira, 6 de janeiro de 2009
Tomcat: wrong version of the project
It may happen sometimes when we need to have several branches/versions of one project, that when we deploy one to tomcat another one is actually referenced. In that case even though we deploy one version, in fact we get a reference to another version.
To check if this is the case we can go to $tomcat/conf/Catalina/localhost/.xml and see if the project name references another version. One simple solution to this problem is to rename/remove the mentioned file.
To check if this is the case we can go to $tomcat/conf/Catalina/localhost/
segunda-feira, 5 de janeiro de 2009
Javascript: return from an iframe
Sometimes when we use iframes (I know we all should avoid them and I most certainly do so, but when you can't really avoid them) and we need to from an inner page navigate to another page but in the main window it may not be straightforward. The problem is you never know exactly if window.parent is the root window, since it might be another iframe. In order to overcome this pitfall I implemented a simple javascript function to solve this problem:
function getRootWin(){
var win = window;
while(win.parent != null && win != win.parent){
win = win.parent;
}
return win.parent;
}
This function gets the root window so we can now do something like
win = getRootWin();
win.location.href= url;
and so go to the target page, getting rid of all the iframes the page be inside of.
Subscrever:
Mensagens (Atom)