Archive for the ‘ Java ’ Category

Close img bracket …

Close img bracket to convers from html to xml in Eclipse editor (Regular expression)

     Find :          <img(([\d]|[\s]|[\w]|\=|\"|\.)*)>
     Replace with :  <img$1/>

Modifies img source to quick change data source in Eclipse editor (Regular expression)

     Find :          <img(.*)src="([\w]*[\\.][\w]*)
     Replace with :  <img$1src="/img/newsletter/$2

Sort a bean

Sort a bean

java.util.Comparator
java.util.TreeSet
org.apache.cocoon.i18n.XMLResourceBundle
org.apache.cocoon.i18n.XMLResourceBundleFactory
 
ListTravelerType = hs.createQuery("FROM Utypes WHERE isdefault = 1 ORDER BY type ASC").list();
 
try {
	XMLResourceBundle translationBundle = null;
	XMLResourceBundleFactory bf = (XMLResourceBundleFactory)manager.lookup(XMLResourceBundleFactory.ROLE);
	translationBundle = (XMLResourceBundle)bf.select("/opt/tomcat/webapps/project/translations", "travelertypes", );
 
	for(Iterator i = ListTravelerType.iterator(); i.hasNext();) {
		Utypes elt = (Utypes)i.next();
		hs.evict(elt);
		elt.setType(translationBundle.getString(elt.getType()));
	}
} catch (Exception cme) {
	logger.error("Could not look up the PersistenceManager", cme);
}
 
Set sortedTravelerType = new TreeSet(new Comparator() {
	public int compare(Object o1, Object o2) {
		if(o1 instanceof Utypes &amp;&amp; o2 instanceof Utypes) {
			Utypes utype1 = (Utypes)o1;
			Utypes utype2 = (Utypes)o2;
			return utype1.getType().compareTo(utype2.getType());
		}
		return 1;
	}
});
 
sortedTravelerType.addAll(ListTravelerType);

Cocoon translations in XSP

Cocoon translations in XSP – java

 
XMLResourceBundle translationBundle = null; 
XMLResourceBundleFactory bf = (XMLResourceBundleFactory)manager.lookup(XMLResourceBundleFactory.ROLE);
 
translationBundle = (XMLResourceBundle)bf.select("/opt/tomcat/webapps/project/translations", "translations", <util:get-sitemap-parameter name="locale"/>);
String translated = translationBundle.getString("Go get the String");