<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4376900328906540649</id><updated>2012-02-15T23:08:05.436-08:00</updated><title type='text'>Java Blogs</title><subtitle type='html'>Java / J2EE blogs
.... a cool site to share my Java learning experiences</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://cooljavablogs.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4376900328906540649/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://cooljavablogs.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Deepa S</name><uri>http://www.blogger.com/profile/17454651506422642481</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://2.bp.blogspot.com/_py_WCXXpxm0/SLy196xkG8I/AAAAAAAAABc/-X_G4BA8808/S220/P1010025.JPG'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4376900328906540649.post-3785259311191988191</id><published>2008-08-26T03:49:00.000-07:00</published><updated>2010-06-06T10:56:00.028-07:00</updated><title type='text'>How to instruct JAXB to ignore Namespaces</title><content type='html'>&lt;span style="font-family:arial;"&gt;&lt;strong&gt;The problem&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;I am developing an application that accepts Java EE deployment descriptors (XML files) and parses it using JAXB. The application should handle any valid versions of descriptors. The problem here is that the JAXB bean classes are generated in accordance with the latest XSD and the namespace of this XSD may differ from that of the previous versions, resulting in XML parse exception while unmarshalling the xml files. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;The Solution&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: Create a new XML SAX filter class by extending the &lt;b&gt;org.xml.sax.helpers.XMLFilterImpl&lt;/b&gt; class. The purpose of this class is to set the correct namespace before passing the xml file information to the JAXB unmarshaller.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: &lt;span style="font-family:Arial;"&gt;Override the &lt;b&gt;startElement&lt;/b&gt; method of XMLFilterImpl class to set the correct namespace. The code snippet of the filter class is shown below:&lt;/span&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public class XMLNamespaceFilter extends XMLFilterImpl {&lt;br /&gt;    public XMLNamespaceFilter(XMLReader arg0) {&lt;br /&gt;       super(arg0);&lt;br /&gt;    }&lt;br /&gt;    @Override&lt;br /&gt;    public void startElement(String uri, String localName,&lt;br /&gt;                             String qName, Attributes attributes)&lt;br /&gt;                             throws SAXException {&lt;br /&gt;       super.startElement(&lt;b&gt;&amp;lt;required namespace&amp;gt;&lt;/b&gt;, localName, qName, &lt;br /&gt;                          attributes);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br&gt;&lt;br&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt;: Unmarshall the xml document using the following code snippet&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;  JAXBContext jc = JAXBContext.newInstance("ctxpath");&lt;br /&gt;  Unmarshaller unmarshaller = jc.createUnmarshaller();&lt;br /&gt;&lt;br /&gt;  // Create the XMLReader&lt;br /&gt;  SAXParserFactory factory = SAXParserFactory.newInstance();&lt;br /&gt;  XMLReader reader = factory.newSAXParser().getXMLReader();&lt;br /&gt;&lt;br /&gt;  // The filter class to set the correct namespace&lt;br /&gt;  XMLFilterImpl xmlFilter = new XMLNamespaceFilter(reader);&lt;br /&gt;  reader.setContentHandler(unmarshaller.getUnmarshallerHandler());&lt;br /&gt;  InputStream inStream = new FileInputStream(new File("some file path"));&lt;br /&gt;  SAXSource source = new SAXSource(xmlFilter, new InputSource(inStream));&lt;br /&gt;&lt;br /&gt;  // Get the root element&lt;br /&gt;  JAXBElement rootElement = unmarshaller.unmarshal(source,Some.class);&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Arial;"&gt;&lt;br /&gt;&lt;br&gt;&lt;b&gt;Summary&lt;/b&gt;&lt;br&gt;&lt;br /&gt;The SAX namespace filter did the trick in this case. If you find any better workaround for similar problem, please share it here.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;br /&gt;var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");&lt;br /&gt;document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;br /&gt;try {&lt;br /&gt;var pageTracker = _gat._getTracker("UA-5780206-3");&lt;br /&gt;pageTracker._trackPageview();&lt;br /&gt;} catch(err) {}&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;&lt;!-- Beginning of Freelancer.com Affiliates Widget --&gt;&lt;br /&gt;&lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;!--&lt;br /&gt;GAF_text_color = "black";&lt;br /&gt;GAF_link_color = "green";&lt;br /&gt;GAF_title_color = "blue";&lt;br /&gt;//--&gt;&lt;/script&gt;&lt;br /&gt;&lt;script src="http://www.freelancer.com/widgets/projects/horizontal.js"&gt;&lt;/script&gt;&lt;br /&gt;&lt;div id="GAF_projects_horizontal_box" style="padding: 0px; font-family:sans-serif; font-size: 12px;"&gt;&lt;br /&gt;&lt;div style="padding: 3px; overflow: hidden"&gt;&lt;br /&gt;&lt;div style="padding-bottom: 0px; border-bottom: 0px solid #5D5E91"&gt;&lt;br /&gt;&lt;a href="http://www.freelancer.com/" target="_blank"&gt;&lt;font color="blue"&gt;Freelance jobs&lt;/font&gt;&lt;/a&gt; on &lt;a href="http://www.freelancer.com/" target="_blank"&gt;&lt;font color="blue"&gt;&lt;b&gt;Freelancer.com&lt;/b&gt;&lt;/font&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div id="GAF_projects_horizontal"&gt;&lt;/div&gt;&lt;br /&gt;&lt;div align="right"&gt;Find more &lt;a href="http://www.freelancer.com/sellers/" target="_blank"&gt;freelance jobs&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;script src="http://api.freelancer.com/Project/Search.json?aff=1608600&amp;callback=GAF_update_projects_horizontal_callback&amp;order=rand&amp;count=4&amp;iads=true&amp;nonpublic=0&amp;charset=UTF-8"&gt;&lt;/script&gt;&lt;br /&gt;&lt;!-- End of Freelancer.com Affiliates Widget --&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4376900328906540649-3785259311191988191?l=cooljavablogs.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cooljavablogs.blogspot.com/feeds/3785259311191988191/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4376900328906540649&amp;postID=3785259311191988191' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4376900328906540649/posts/default/3785259311191988191'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4376900328906540649/posts/default/3785259311191988191'/><link rel='alternate' type='text/html' href='http://cooljavablogs.blogspot.com/2008/08/how-to-instruct-jaxb-to-ignore.html' title='How to instruct JAXB to ignore Namespaces'/><author><name>Deepa S</name><uri>http://www.blogger.com/profile/17454651506422642481</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://2.bp.blogspot.com/_py_WCXXpxm0/SLy196xkG8I/AAAAAAAAABc/-X_G4BA8808/S220/P1010025.JPG'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4376900328906540649.post-5026452034471275891</id><published>2008-03-28T01:32:00.000-07:00</published><updated>2008-12-09T08:27:45.180-08:00</updated><title type='text'>Personalizing web pages using JSF</title><content type='html'>&lt;p&gt;&lt;strong&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;Personalization &lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;Personalization is an unavoidable part of any web sites. Personalization allows users to tailor a standard web site as per their needs. User can perform page customizations like adjust the position of various sections of a page, add new sections, remove existing sections etc. In this article we will see how to customize a &lt;strong&gt;&lt;em&gt;Dashboard&lt;/em&gt;&lt;/strong&gt; application using Java, Java Server Faces (JSF) and JavaScript.&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;&lt;strong&gt;Dashboards &amp;amp; Dashlets&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-family:arial;"&gt;&lt;span style="font-size:85%;"&gt;Dashboards are becoming widely accepted user interface for representing independent units of related information in a common web page. A dashboard can be developed by assembling a set of components called &lt;strong&gt;&lt;em&gt;Dashlets&lt;/em&gt;&lt;/strong&gt;, wherein each dashlet represents a useful unit of information. If you take &lt;a href="http://www.google.com/ig?hl=en"&gt;Google Home page &lt;/a&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;for example, there are different dashlets like 'Google Mail', 'Google News', 'Sports News' etc. Upto certain extent, user has been given the option to decide the content to be appeared in this page. The sample application explained here shows how user can personalize a simple dashboard application.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;strong&gt;Features Supported&lt;/strong&gt;&lt;/span&gt; &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Displays a set of standard dashlets using default look n feel.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;User can adjust the position of dashlets using drag n drop feature.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;User can easily configure the details of dashlets using a properties file.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;User can remove existing dashlets displayed in a page.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;User can add previously removed dashlets.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;How it works?&lt;/span&gt;&lt;br /&gt;&lt;/strong&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;This application is purely a java based component. The user can mention the name of the dashlets as well as the name of include files storing the content of these dashlets as a comma delimited list in a properties file called &lt;em&gt;dashlet.properties&lt;/em&gt;. The content of the property file used in the sample application is shown below&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://3.bp.blogspot.com/_py_WCXXpxm0/R_X_uZy-K1I/AAAAAAAAAAY/kFCrYQWLS1U/s1600-h/prop.gif"&gt;&lt;img id="BLOGGER_PHOTO_ID_5185331718650735442" style="CURSOR: hand" alt="" src="http://3.bp.blogspot.com/_py_WCXXpxm0/R_X_uZy-K1I/AAAAAAAAAAY/kFCrYQWLS1U/s320/prop.gif" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;p align="justify"&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;By default, the dashlets are displayed as two columns, the left column and right column. The &lt;em&gt;'leftDashlets'&lt;/em&gt; property set the dashlets to be displayed on the left column. Similarly the &lt;em&gt;rightDashlets&lt;/em&gt; property set the dashlets to be displayed on the right column. &lt;/span&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;For the first time site visitors, the application picks the details of dashlets from the dashlet.properties file and displays it using a default look n feel. The look n feel of the site is controlled through a CSS file called &lt;em&gt;dashlet.css&lt;/em&gt;. The screen shot of the dashlet page is shown below:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://1.bp.blogspot.com/_py_WCXXpxm0/R_XL_5y-K0I/AAAAAAAAAAM/OuFlx1Rge-Y/s1600-h/dashlet.gif"&gt;&lt;img id="BLOGGER_PHOTO_ID_5185274844693801794" style="CURSOR: hand" alt="" src="http://1.bp.blogspot.com/_py_WCXXpxm0/R_XL_5y-K0I/AAAAAAAAAAM/OuFlx1Rge-Y/s320/dashlet.gif" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;The application uses JSF as the UI framework. The JSF backing bean called DashletBean maintains the state of all UI components displayed in the dashboard. The DashletBean also manages the list of dashlets displayed on the dashboard, the names of the dashlets displayed in the 'Add Dashlet' section etc. Once the user personalizes the content of the site, the DashletBean persists the personalization details to a "Cookie". The personalization details for subsequent visits will be picked from this cookie. Hence it is important that Cookie must be enabled on your browser to get this application properly work.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;User can remove any dashlet from the dashboard by clicking the 'Close' button (x) provided at the top right corner of each dashlet window. Whenever user removes a dashlet, the name of this dashlet appears in the 'Add Dashlet' section so that user can add this dashlet back to the dashboard. This page also provides a section called 'Personalize Dashlets' wherein user can adjust the position of each dashlet by dragging and dropping the dashlet to the desired position. The drag-n-drop feature is implemented using Javascript. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;strong&gt;How to run this application?&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;To run this application, you need the following jar files in the classpath&lt;/span&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;jsf-impl.jar&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;jsf-api.jar&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;jstl.jar&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;standard.jar&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;commons-beanutils.jar&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;commons-collections.jar&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;commons-digester.jar&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:arial;font-size:85%;"&gt;commons-logging.jar&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Also keep the dashlet.properties file in your classpath. Create a war file out of the &lt;a href="http://www.filejumbo.com/Download/7F3D507B63AACA73"&gt;code &lt;/a&gt;base and deploy it on any web container. The URL of the dashboard page is http://&amp;lt;hostname&amp;gt;://&amp;lt;port&amp;gt;/&amp;lt;context-root&amp;gt;/dashlet.html .&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;So far we have discussed how to customize a web page using Java technologies. However you can try adding more features to this application such as enabling AJAX based approach, minimizing/maximizing dashlet windows etc. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial;font-size:85%;"&gt;Click &lt;a href="http://www.filejumbo.com/Download/7F3D507B63AACA73"&gt;here&lt;/a&gt; to download the code base of the sample application.&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4376900328906540649-5026452034471275891?l=cooljavablogs.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cooljavablogs.blogspot.com/feeds/5026452034471275891/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4376900328906540649&amp;postID=5026452034471275891' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4376900328906540649/posts/default/5026452034471275891'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4376900328906540649/posts/default/5026452034471275891'/><link rel='alternate' type='text/html' href='http://cooljavablogs.blogspot.com/2008/03/personalizing-web-pages-using-jsf.html' title='Personalizing web pages using JSF'/><author><name>Deepa S</name><uri>http://www.blogger.com/profile/17454651506422642481</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://2.bp.blogspot.com/_py_WCXXpxm0/SLy196xkG8I/AAAAAAAAABc/-X_G4BA8808/S220/P1010025.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_py_WCXXpxm0/R_X_uZy-K1I/AAAAAAAAAAY/kFCrYQWLS1U/s72-c/prop.gif' height='72' width='72'/><thr:total>1</thr:total></entry></feed>
