<?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:blogger='http://schemas.google.com/blogger/2008' 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-2679601544275098679</id><updated>2024-09-01T11:26:13.570+05:30</updated><category term="Technical"/><category term="Java"/><category term="XML"/><category term="HTML"/><category term="Liferay"/><category term="Web"/><category term="Apache Tomcat"/><category term="Liferay-Portal"/><category term="Servlet"/><category term="Transformation"/><category term="Web Security"/><category term="AUI"/><category term="AUI-FORM"/><category term="Alerts"/><category term="Apache"/><category term="Apache Tika"/><category term="CSRF"/><category term="Caching"/><category term="Compressing"/><category term="Computer Information"/><category term="Cross-Site Request Forgery"/><category term="Database"/><category term="Email Alerts"/><category term="Event Listeners"/><category term="Filters"/><category term="Garbage Collection"/><category term="Google"/><category term="Google Alerts"/><category term="HTTPS"/><category term="Hardware Information"/><category term="Indent XML"/><category term="Java Syntax Highlighter"/><category term="Javascript"/><category term="Listeners"/><category term="MIME Type"/><category term="News"/><category term="OS Licensing Information"/><category term="Oracle"/><category term="Organize XML"/><category term="PhantomReference"/><category term="Properties"/><category term="Reference"/><category term="ReferenceQueue"/><category term="SMS Alerts"/><category term="SSL"/><category term="Self Signed Certificate"/><category term="Sequence"/><category term="Server Banner"/><category term="Server Header"/><category term="Server Signature"/><category term="Servlet Context Listener"/><category term="SoftReference"/><category term="Software Information"/><category term="Source Highlight"/><category term="Syntax"/><category term="Syntax Highlighter"/><category term="System Properties"/><category term="Tomcat"/><category term="Trigger"/><category term="WMIC"/><category term="WeakReference"/><category term="Web Service"/><category term="Web Service Client"/><category term="Web.xml"/><category term="Well-form"/><category term="Well-form XML"/><category term="XALAN"/><category term="XALAN-JAVA"/><category term="XSLT"/><category term="auth-constraint"/><category term="autocomplete"/><category term="cookie-config"/><category term="error-code"/><category term="error-page"/><category term="exception-type"/><category term="http-only"/><category term="owasp"/><category term="security-constraint"/><category term="session-config"/><category term="session-timeout"/><category term="tracking-mode"/><category term="transport-guarantee"/><title type='text'>TECHNICAL ANNEX</title><subtitle type='html'>An information technology extension.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://tech-annex.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://tech-annex.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Tejas Purohit</name><uri>http://www.blogger.com/profile/12572963277655039205</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj61LMQasMba7t1nDNHcF4TA4oB53ydZQB2Zx9lwPBGzjTlaggkPx165DSyYg0Nvvo6Mqqk6o6oopUoGfgVbHXNbX1DuPhAG4IdXARNW-6O5dfec4YXDD5fay8u7mLdtNnC15WhkWCFuEaKypXRBXtrTfsSskw6ODSrVScbALtLa7aEhA/s220/IMG_4680.jpeg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>20</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2679601544275098679.post-2241194509660496558</id><published>2015-03-16T21:16:00.003+05:30</published><updated>2015-03-17T21:41:25.787+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java Syntax Highlighter"/><category scheme="http://www.blogger.com/atom/ns#" term="Source Highlight"/><category scheme="http://www.blogger.com/atom/ns#" term="Syntax"/><category scheme="http://www.blogger.com/atom/ns#" term="Syntax Highlighter"/><title type='text'>Code/Syntax Highlight in Blog</title><content type='html'>Its always a good practice to write a well formed and well managed source code but after putting much effort to write a nice and clean piece of code we often come into a situation that when we post it on Blogs or on Web pages it doesn&#39;t look as nice as it should look.&lt;br /&gt;
&lt;br /&gt;
Have a look at below java code:&lt;br /&gt;
&lt;br /&gt;
public class HelloWorld {&lt;br /&gt;
public static void main(String[] args) {&lt;br /&gt;
System.out.println(&quot;Hello World!&quot;);  // Display the string.&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
I really don&#39;t like that my code looks like this and I am sure you also don&#39;t like it. but what if the same code looks like below:&lt;br /&gt;
&lt;pre class=&quot;brush:java;&quot;&gt;public class HelloWorld {

    public static void main(String[] args) {

        System.out.println(&quot;Hello World!&quot;);  // Display the string.

    }

}
&lt;/pre&gt;&lt;br /&gt;
This looks very neat and clean, right?&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://alexgorbatchev.com/SyntaxHighlighter/&quot; target=&quot;_blank&quot;&gt;SyntaxHighlighter by Alex Gorbatchev&lt;/a&gt; is the most popular and easy to use Java script API to highlight you source code. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Just to steps to add SyntaxHighlighter to your Blog on &lt;i&gt;Blogger.com&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step 1: Adding SyntaxHighlighter resource files to blog&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
1. Go to Blogger Dashboard &amp;gt; Design &amp;gt; Edit HTML.&lt;br /&gt;
2. Press CTRL+F to find the code &lt;br /&gt;
3. Copy the below code &lt;br /&gt;
&lt;pre class=&quot;brush:html; highlight: [3,5,8]&quot;&gt;&amp;lt;!--SYNTAX HIGHLIGHTER BEGINS--&amp;gt;
&amp;lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&amp;gt;
&amp;lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&amp;gt;
&amp;lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&#39; type=&#39;text/javascript&#39;/&amp;gt;
&amp;lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js&#39; type=&#39;text/javascript&#39;/&amp;gt;
&amp;lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js&#39; type=&#39;text/javascript&#39;/&amp;gt;
&amp;lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js&#39; type=&#39;text/javascript&#39;/&amp;gt;
&amp;lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js&#39; type=&#39;text/javascript&#39;/&amp;gt;
&amp;lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js&#39; type=&#39;text/javascript&#39;/&amp;gt;
&amp;lt;script language=&#39;javascript&#39;&amp;gt;
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = &amp;amp;#39;http://alexgorbatchev.com/pub/sh/current/scripts/clipboard.swf&amp;amp;#39;;
SyntaxHighlighter.all();
&amp;lt;/script&amp;gt;
&amp;lt;!--SYNTAX HIGHLIGHTER ENDS--&amp;gt;
&lt;/pre&gt;4. Paste it on top of &lt;code&gt;&amp;lt;/head&amp;gt;&lt;/code&gt;. (We are adding all resource files to &lt;code&gt;HEAD&lt;/code&gt; section of the template)&lt;br /&gt;
5. Preview your template and save it if everything works ok.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step 2: Posting code to Blog&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Before posting your code to the blog its advisable to convert raw HTML characters to escape characters. There are some online utilities available for performing this like:&lt;br /&gt;
1. &lt;a href=&quot;http://centricle.com/tools/html-entities/&quot; target=&quot;_blank&quot;&gt;Encode / Decode HTML Entities&lt;/a&gt;&lt;br /&gt;
2. &lt;a href=&quot;http://www.elliotswan.com/postable/&quot; target=&quot;_blank&quot;&gt;Postable&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
When writing a new post, you need to use &lt;code&gt;&amp;lt;pre&amp;gt;&lt;/code&gt; tag in the post. The code of your post needs to go in between &lt;code&gt;&amp;lt;pre class=&#39;brush:java&#39;&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;/pre&amp;gt;&lt;/code&gt; tags, in order to highlight your code properly. &lt;br /&gt;
Just like below:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:html;&quot;&gt;&amp;lt;pre class=&#39;brush:java;&#39;&amp;gt;

    public class HelloWorld {

        public static void main(String[] args) {

            System.out.println(&quot;Hello World!&quot;);  // Display the string.

        }

    }
&amp;lt;/pre&amp;gt;
&lt;/pre&gt;Which will look like this at end&lt;br /&gt;
&lt;pre class=&quot;brush:java;&quot;&gt;public class HelloWorld {

    public static void main(String[] args) {

        System.out.println(&quot;Hello World!&quot;);  // Display the string.

    }

}
&lt;/pre&gt;&lt;br /&gt;
This is it. You are done with basic setup. In addition you can also customize SyntaxHighlighter with different themes or brushes.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Themes for SyntaxHighlighter&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
SyntaxHighlighter is available with some well known color themes. You can select a theme which match with your Template. You can apply a theme by selecting CSS file for it. Click name of the theme to get preview of the theme. &lt;br /&gt;
&lt;br /&gt;
&lt;table style=&quot;border-color: gray; border-spacing: 5px; border-style: solid; border-width: 1px;&quot;&gt;&lt;thead&gt;
&lt;tr&gt;&lt;th style=&quot;text-align: left;&quot;&gt;Name&lt;/th&gt;&lt;th style=&quot;text-align: left;&quot;&gt;File&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;  &lt;tbody style=&quot;vertical-align: text-top;&quot;&gt;
&lt;tr&gt;    &lt;td style=&quot;text-align: left; white-space: nowrap;&quot;&gt;&lt;a href=&quot;https://www.blogger.com/SyntaxHighlighter/manual/themes/default.html&quot;&gt;Default&lt;/a&gt;&lt;/td&gt;    &lt;td style=&quot;text-align: left;&quot;&gt;&lt;code&gt;&amp;lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&amp;gt;&lt;/code&gt;&lt;/td&gt;   &lt;/tr&gt;
&lt;tr&gt;    &lt;td style=&quot;text-align: left; white-space: nowrap;&quot;&gt;&lt;a href=&quot;https://www.blogger.com/SyntaxHighlighter/manual/themes/django.html&quot;&gt;Django&lt;/a&gt;&lt;/td&gt;    &lt;td style=&quot;text-align: left;&quot;&gt;&lt;code&gt;&amp;lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDjango.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&amp;gt;&lt;/code&gt;&lt;/td&gt;   &lt;/tr&gt;
&lt;tr&gt;    &lt;td style=&quot;text-align: left; white-space: nowrap;&quot;&gt;&lt;a href=&quot;https://www.blogger.com/SyntaxHighlighter/manual/themes/eclipse.html&quot;&gt;Eclipse&lt;/a&gt;&lt;/td&gt;    &lt;td style=&quot;text-align: left;&quot;&gt;&lt;code&gt;&amp;lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeEclipse.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&amp;gt;&lt;/code&gt;&lt;/td&gt;   &lt;/tr&gt;
&lt;tr&gt;    &lt;td style=&quot;text-align: left; white-space: nowrap;&quot;&gt;&lt;a href=&quot;https://www.blogger.com/SyntaxHighlighter/manual/themes/emacs.html&quot;&gt;Emacs&lt;/a&gt;&lt;/td&gt;    &lt;td style=&quot;text-align: left;&quot;&gt;&lt;code&gt;&amp;lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeEmacs.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&amp;gt;&lt;/code&gt;&lt;/td&gt;   &lt;/tr&gt;
&lt;tr&gt;    &lt;td style=&quot;text-align: left; white-space: nowrap;&quot;&gt;&lt;a href=&quot;https://www.blogger.com/SyntaxHighlighter/manual/themes/fadetogrey.html&quot;&gt;Fade To Grey&lt;/a&gt;&lt;/td&gt;    &lt;td style=&quot;text-align: left;&quot;&gt;&lt;code&gt;&amp;lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeFadeToGrey.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&amp;gt;&lt;/code&gt;&lt;/td&gt;   &lt;/tr&gt;
&lt;tr&gt;    &lt;td style=&quot;text-align: left; white-space: nowrap;&quot;&gt;&lt;a href=&quot;https://www.blogger.com/SyntaxHighlighter/manual/themes/midnight.html&quot;&gt;Midnight&lt;/a&gt;&lt;/td&gt;    &lt;td style=&quot;text-align: left;&quot;&gt;&lt;code&gt;&amp;lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeMidnight.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&amp;gt;&lt;/code&gt;&lt;/td&gt;   &lt;/tr&gt;
&lt;tr&gt;    &lt;td style=&quot;text-align: left; white-space: nowrap;&quot;&gt;&lt;a href=&quot;https://www.blogger.com/SyntaxHighlighter/manual/themes/rdark.html&quot;&gt;RDark&lt;/a&gt;&lt;/td&gt;    &lt;td style=&quot;text-align: left;&quot;&gt;&lt;code&gt;&amp;lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeRDark.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&amp;gt;&lt;/code&gt;&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt; &lt;/table&gt;&lt;br /&gt;
You can apply new theme by replacing default theme CSS with the CSS file of your choice from above list. Replace the selected line no 3 in above SyntaxHighlighter resource code which we entered in Template by new CSS file.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Brushes for SyntaxHighlighter&lt;/b&gt;&lt;br /&gt;
You can also select support of different languages by selecting or removing various brushes. This gives you flexibility to select necessary brushes only thus you can also save loading time of your page. Selected line no 5 and 8 shows brushes for CSS and SQL respectively. &lt;br /&gt;
&lt;br /&gt;
A list of all available brushes is available &lt;a href=&quot;http://alexgorbatchev.com/SyntaxHighlighter/manual/brushes/&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Issues with SyntaxHighlighter&lt;/b&gt;&lt;br /&gt;
If you find any issues with SyntaxHighlighter you can post them &lt;a href=&quot;https://github.com/alexgorbatchev/SyntaxHighlighter/issues&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Happy Blogging. :)&lt;br /&gt;
&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all();
SyntaxHighlighter.highlight();
&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://tech-annex.blogspot.com/feeds/2241194509660496558/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://tech-annex.blogspot.com/2015/03/codesyntax-highlight-in-blog.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/2241194509660496558'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/2241194509660496558'/><link rel='alternate' type='text/html' href='http://tech-annex.blogspot.com/2015/03/codesyntax-highlight-in-blog.html' title='Code/Syntax Highlight in Blog'/><author><name>Tejas Purohit</name><uri>http://www.blogger.com/profile/12572963277655039205</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj61LMQasMba7t1nDNHcF4TA4oB53ydZQB2Zx9lwPBGzjTlaggkPx165DSyYg0Nvvo6Mqqk6o6oopUoGfgVbHXNbX1DuPhAG4IdXARNW-6O5dfec4YXDD5fay8u7mLdtNnC15WhkWCFuEaKypXRBXtrTfsSskw6ODSrVScbALtLa7aEhA/s220/IMG_4680.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2679601544275098679.post-1272851279667447785</id><published>2013-06-03T23:54:00.000+05:30</published><updated>2015-03-17T21:54:35.836+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Cross-Site Request Forgery"/><category scheme="http://www.blogger.com/atom/ns#" term="CSRF"/><category scheme="http://www.blogger.com/atom/ns#" term="Liferay"/><category scheme="http://www.blogger.com/atom/ns#" term="Liferay-Portal"/><category scheme="http://www.blogger.com/atom/ns#" term="owasp"/><category scheme="http://www.blogger.com/atom/ns#" term="Web"/><title type='text'>Cross-Site Request Forgery (CSRF) Prevention in Liferay</title><content type='html'>&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;What is CSRF?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Cross-Site Request Forgery (CSRF)is a hidden attack that contains a malicious request. This is in top web vulnerabilities list because, the malicious request carries the identity, privileges, information and permissions of the victim to perform an proxy request on the victim&#39;s behalf. This can attack can be performed for any kind of operations like updating sensitive\confidential  information, purchase something, transfer money etc.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://www.owasp.org/index.php/Cross-Site_Request_Forgery_%28CSRF%29&quot;&gt;More about CSRF&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Prevention Measures&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
To prevent CSRF attack a general recommendation to use &lt;em&gt;Synchronizer Token Pattern&lt;/em&gt;, which suggest to include a random token with all form actions and links associated to confidential server action/operations. &lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
One random token should be generated for each session and must be stored in the session itself. On each incoming request, server must verify the existence and validity against the token stored in current session. &lt;br /&gt;
&lt;br /&gt;
In case of token is not exist in the request or invalid, request must be aborted, token must be reset and incidence must be logged as a CSRF attack. &lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: 18px;&quot;&gt;&lt;b&gt;CSRF Prevention Mechanism in Liferay&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Portal Authentication token mechanism is created to prevent CSRF attacks. This mechanism will include a parameter called &lt;em&gt;p_auth&lt;/em&gt; containing random token in every action request.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: 15px;&quot;&gt;&lt;b&gt;Enable/Disable authentication token checking in portal&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
As this is a portal level setting, authentication token checking can be enabled or disabled by adding below property in portal properties.&lt;br /&gt;
&lt;pre class=&quot;brush: plain; &quot;&gt;auth.token.check.enabled=true
&lt;/pre&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 15px;&quot;&gt;&lt;b&gt;Setting Authentication Token Class&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Custom authentication token class can be implemented to handle and avoid CSRF attacks. Custom authentication class must implement &lt;em&gt;com.liferay.portal.security.auth.AuthToken&lt;/em&gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;com.liferay.portal.security.auth.SessionAuthToken&lt;/em&gt; is the default impelementation available in Liferay.&lt;br /&gt;
&lt;br /&gt;
The class can be registered to portal context by adding below property in portal properties. &lt;br /&gt;
&lt;pre class=&quot;brush: plain; &quot;&gt;auth.token.impl=com.liferay.portal.security.auth.SessionAuthToken
&lt;/pre&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 15px;&quot;&gt;&lt;b&gt;Ignoring actions/portlets from token authentication check&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
A list of comma delimited struts actions or portlet ids can set to ignore authentication token check on them.&lt;br /&gt;
&lt;br /&gt;
List of struts actions can be set by adding below property in portal properties. &lt;br /&gt;
&lt;pre class=&quot;brush: plain; &quot;&gt;auth.token.ignore.actions=\
    /blogs/edit_entry,\
    /blogs/edit_entry_discussion,\
    /blogs/rss
&lt;/pre&gt;&lt;br /&gt;
List of portlet ids can be set by adding below property in portal properties. &lt;br /&gt;
&lt;pre class=&quot;brush: plain; &quot;&gt;auth.token.ignore.portlets=82,87
&lt;/pre&gt;&lt;br /&gt;
Individual portlets can be ignored by adding below init parameter in portlet.xml&lt;br /&gt;
&lt;pre class=&quot;brush: xml; &quot;&gt;&lt;init-param&gt;
 &lt;name&gt;check-auth-token&lt;/name&gt;
 &lt;value&gt;false&lt;/value&gt;
&lt;/init-param&gt;
&lt;/pre&gt;&lt;br /&gt;
Enjoy and Stay Protected.&lt;br /&gt;
&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all();
SyntaxHighlighter.highlight();
&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://tech-annex.blogspot.com/feeds/1272851279667447785/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://tech-annex.blogspot.com/2013/06/cross-site-request-forgery-csrf.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/1272851279667447785'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/1272851279667447785'/><link rel='alternate' type='text/html' href='http://tech-annex.blogspot.com/2013/06/cross-site-request-forgery-csrf.html' title='Cross-Site Request Forgery (CSRF) Prevention in Liferay'/><author><name>Tejas Purohit</name><uri>http://www.blogger.com/profile/12572963277655039205</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj61LMQasMba7t1nDNHcF4TA4oB53ydZQB2Zx9lwPBGzjTlaggkPx165DSyYg0Nvvo6Mqqk6o6oopUoGfgVbHXNbX1DuPhAG4IdXARNW-6O5dfec4YXDD5fay8u7mLdtNnC15WhkWCFuEaKypXRBXtrTfsSskw6ODSrVScbALtLa7aEhA/s220/IMG_4680.jpeg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2679601544275098679.post-3705341495887206890</id><published>2013-01-31T22:44:00.000+05:30</published><updated>2015-03-17T21:54:19.769+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="AUI"/><category scheme="http://www.blogger.com/atom/ns#" term="AUI-FORM"/><category scheme="http://www.blogger.com/atom/ns#" term="autocomplete"/><category scheme="http://www.blogger.com/atom/ns#" term="HTML"/><category scheme="http://www.blogger.com/atom/ns#" term="Liferay"/><title type='text'>Setting Auto Compelete off to Liferay AUI Forms</title><content type='html'>Hi Liferay developers,&lt;br /&gt;
&lt;br /&gt;
We all use AUI components extensively during our Liferay portal development, Right? While using AUI forms we may need to set &lt;a href=&quot;http://www.w3.org/wiki/HTML/Elements/form#HTML_Attributes&quot;&gt;autocomplete&lt;/a&gt; settings on our forms based on the sensitivity of the data our forms carries, like login form, credit card information forms etc. &lt;br /&gt;
&lt;br /&gt;
Now AUI form don&#39;t provide scope to set &lt;em&gt;autocompelete&lt;/em&gt;, have a look &lt;a href=&quot;http://www.liferay.com/community/wiki/-/wiki/Main/Alloy+UI+Forms+%28aui%29#section-Alloy+UI+Forms+(aui)-Attributes&quot;&gt;here&lt;/a&gt; to all AUI form attributes.&lt;br /&gt;
&lt;br /&gt;
This also logged as &lt;a href=&quot;http://issues.liferay.com/browse/LPS-15686&quot;&gt;known bug in AUI form&lt;/a&gt; and still in open state by the time this blog is written.&lt;br /&gt;
&lt;br /&gt;
Don&#39;t get disappointed, although &lt;em&gt;autocompelete&lt;/em&gt; attribute is not available in AUI form we can still get it by just adding &lt;em&gt;autocompelete&lt;/em&gt; attribute to AUI form as below, and it&#39;s done.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:html; highlight: [3]&quot;&gt;&amp;lt;aui:form 
     action=&amp;quot;SOME_FORM_ACTION&amp;quot; method=&amp;quot;POST&amp;quot; 
     autocomplete=&amp;quot;off&amp;quot;&amp;gt;

// Form fields will go here

&amp;lt;/aui:form&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
Cheers!!!&lt;br /&gt;
&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all();
SyntaxHighlighter.highlight();
&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://tech-annex.blogspot.com/feeds/3705341495887206890/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://tech-annex.blogspot.com/2013/01/setting-auto-compelete-off-to-liferay.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/3705341495887206890'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/3705341495887206890'/><link rel='alternate' type='text/html' href='http://tech-annex.blogspot.com/2013/01/setting-auto-compelete-off-to-liferay.html' title='Setting Auto Compelete off to Liferay AUI Forms'/><author><name>Tejas Purohit</name><uri>http://www.blogger.com/profile/12572963277655039205</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj61LMQasMba7t1nDNHcF4TA4oB53ydZQB2Zx9lwPBGzjTlaggkPx165DSyYg0Nvvo6Mqqk6o6oopUoGfgVbHXNbX1DuPhAG4IdXARNW-6O5dfec4YXDD5fay8u7mLdtNnC15WhkWCFuEaKypXRBXtrTfsSskw6ODSrVScbALtLa7aEhA/s220/IMG_4680.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2679601544275098679.post-8000534325076657693</id><published>2013-01-30T16:17:00.001+05:30</published><updated>2015-03-17T21:54:04.358+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Apache"/><category scheme="http://www.blogger.com/atom/ns#" term="Apache Tomcat"/><category scheme="http://www.blogger.com/atom/ns#" term="Liferay"/><category scheme="http://www.blogger.com/atom/ns#" term="Liferay-Portal"/><category scheme="http://www.blogger.com/atom/ns#" term="Server Banner"/><category scheme="http://www.blogger.com/atom/ns#" term="Server Header"/><category scheme="http://www.blogger.com/atom/ns#" term="Server Signature"/><category scheme="http://www.blogger.com/atom/ns#" term="Web Security"/><title type='text'>Hidding Server Signature/Banner Information of Liferay Server</title><content type='html'>Liferay Servers include server banner information with every response it send back. These information can be venerable in respect to security of your website/portal. A sample response header is shown below, look highlighted lines:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:java; highlight: [3,5]&quot;&gt;Date: Tue, 29 Jan 2013 11:02:43 GMT
Content-Encoding: gzip
Server: Apache/2.2.3 (Red Hat)
ETag: &quot;1a467a7a&quot;
Liferay-Portal: Liferay Portal Enterprise Edition 6.1.20 EE (Paton / Build 6120 / July 31, 2012)
Vary: Accept-Encoding
Content-Type: text/html;charset=UTF-8
Connection: Keep-Alive
Content-Length: 9105
&lt;/pre&gt;These information can be hidden on changed with very basic configurations in servers and portal.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Hiding Liferay-Portal Signature/Header/Banner&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Liferay provides a portal property to set the level of verbosity of Liferay portal header. &lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:java; highlight: [2,7]&quot;&gt;//Full, provide full information including version information (Liferay Portal Enterprise Edition 6.1.20 EE) 
http.header.version.verbosity=full

OR

//Partial, provide only name of the server (Liferay Portal Enterprise Edition) 
http.header.version.verbosity=partial
&lt;/pre&gt;&lt;br /&gt;
Still we are not able to completely hide this information. Although there is a strange solution available without any coding. Add below property in portal-ext.properties to hide &lt;em&gt;Liferay-Portal&lt;/em&gt; header.&lt;br /&gt;
&lt;pre class=&quot;brush:java; highlight: [2,7]&quot;&gt;// For Community edition
http.header.version.verbosity=Liferay Portal Community Edition

 OR

//For Enterprise Edition
http.header.version.verbosity=Liferay Portal Enterprise Edition
&lt;/pre&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Updating Server Signature/Banner in Tomcat&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
To update server header in tomcat go to server.xml file at &lt;b&gt;CATALINA_HOME/conf/server.xml&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Add/Update &lt;em&gt;Server&lt;/em&gt; attribute in &lt;em&gt;&amp;lt;Connector&amp;gt;&lt;/em&gt; element as below,&lt;br /&gt;
&lt;pre class=&quot;brush:xml; highlight: [7]&quot;&gt;&amp;lt;Connector 
  URIEncoding=&amp;quot;UTF-8&amp;quot; 
  connectionTimeout=&amp;quot;20000&amp;quot; 
  port=&amp;quot;8080&amp;quot; 
  protocol=&amp;quot;HTTP/1.1&amp;quot; 
  redirectPort=&amp;quot;8443&amp;quot; 
  server=&amp;quot;Technical Annex&amp;quot;
 /&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
This change will hide actual server information and update the response headed as below&lt;br /&gt;
&lt;pre class=&quot;brush:java; highlight: [3]&quot;&gt;Date: Tue, 29 Jan 2013 11:02:43 GMT
Content-Encoding: gzip
Server: Technical Annex
ETag: &quot;1a467a7a&quot;
Liferay-Portal: Liferay Portal Enterprise Edition 6.1.20 EE (Paton / Build 6120 / July 31, 2012)
Vary: Accept-Encoding
Content-Type: text/html;charset=UTF-8
Connection: Keep-Alive
Content-Length: 9105
&lt;/pre&gt;&lt;br /&gt;
Refer this article, &lt;a href=&quot;https://www.owasp.org/index.php/Securing_tomcat&quot;&gt;Securing Tomcat&lt;/a&gt; by OWASP if you are seriously interested to make your tomcat server secure.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Hiding Server Signature/Banner in Apache&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
To hide Apache server signature/banner go to Apache configuration file, usually &lt;b&gt;Apache_Server_Home/apache2.conf&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Set &lt;em&gt;ServerSignature&lt;/em&gt; and &lt;em&gt;ServerTokens&lt;/em&gt; properties for disabling server signature/banner as below:&lt;br /&gt;
&lt;pre class=&quot;brush:xml; highlight: [7]&quot;&gt;ServerSignature Off
ServerTokens ProductOnly
&lt;/pre&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all();
SyntaxHighlighter.highlight();
&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://tech-annex.blogspot.com/feeds/8000534325076657693/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://tech-annex.blogspot.com/2013/01/hidding-server-signaturebanner.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/8000534325076657693'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/8000534325076657693'/><link rel='alternate' type='text/html' href='http://tech-annex.blogspot.com/2013/01/hidding-server-signaturebanner.html' title='Hidding Server Signature/Banner Information of Liferay Server'/><author><name>Tejas Purohit</name><uri>http://www.blogger.com/profile/12572963277655039205</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj61LMQasMba7t1nDNHcF4TA4oB53ydZQB2Zx9lwPBGzjTlaggkPx165DSyYg0Nvvo6Mqqk6o6oopUoGfgVbHXNbX1DuPhAG4IdXARNW-6O5dfec4YXDD5fay8u7mLdtNnC15WhkWCFuEaKypXRBXtrTfsSskw6ODSrVScbALtLa7aEhA/s220/IMG_4680.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2679601544275098679.post-5878701780347350607</id><published>2012-05-24T20:10:00.003+05:30</published><updated>2015-03-17T21:53:49.888+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Apache Tomcat"/><category scheme="http://www.blogger.com/atom/ns#" term="HTTPS"/><category scheme="http://www.blogger.com/atom/ns#" term="Self Signed Certificate"/><category scheme="http://www.blogger.com/atom/ns#" term="SSL"/><category scheme="http://www.blogger.com/atom/ns#" term="Tomcat"/><title type='text'>Enable HTTPS in tomcat with self signed SSL Cerficates</title><content type='html'>Article shows to enable and test HTTPS with Liferay Portal in four easy steps. This approach might be proper for development or testing environment.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step 1: Create Self Signed SSL Certificate&lt;/b&gt; &lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Open command window and move to java tools directory. Typically BIN directory of JDK/JRE installation.&lt;/li&gt;
&lt;li&gt;Execute following command and follow on screen instructions. See the image below.&lt;br /&gt;
&lt;pre class=&quot;brush:java&quot;&gt;keytool -genkeypair 
{-alias alias} {-keyalg keyalg} 
{-keystore keystore}  
[-storepass storepass] 
[-keypass keypass]
&lt;/pre&gt;example: &lt;br /&gt;
&lt;pre class=&quot;brush:java&quot;&gt;keytool -genkeypair 
-alias techannex 
-keyalg RSA 
-keystore techannex.keystore 
-storepass changeit 
-keypass changeit
&lt;/pre&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-5k6hjD-U-jbaMQUiJNA_PIpcicJnrrSkspq5b72B7rcBqGUl-uh1B7vs8WCuRXNWtqI2niVtDEF940hBo7RDrA79lanKJdY3n8_mGqgryJxzI1YO0dkXMElM2z3uEvx0pj7xALWHa5dp/s1600/KeyStore.jpg&quot; imageanchor=&quot;1&quot; style=&quot;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;63&quot; width=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-5k6hjD-U-jbaMQUiJNA_PIpcicJnrrSkspq5b72B7rcBqGUl-uh1B7vs8WCuRXNWtqI2niVtDEF940hBo7RDrA79lanKJdY3n8_mGqgryJxzI1YO0dkXMElM2z3uEvx0pj7xALWHa5dp/s1600/KeyStore.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;b&gt;Step 2: Configure Server&lt;/b&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Stop Tomcat if already running.&lt;/li&gt;
&lt;li&gt;move .keystore file to tomcat conf directory. &amp;lt;tomcat_installation_dir&amp;gt;/conf &lt;/li&gt;
&lt;li&gt;Open server.xml file of tomcat and uncomment SSL Connector with &lt;code&gt;port=&quot;8443&quot;&lt;/code&gt; and update it as below.&lt;/li&gt;
&lt;pre class=&quot;brush:xml&quot;&gt;&amp;lt;Connector port=&amp;quot;8443&amp;quot; 
 protocol=&amp;quot;HTTP/1.1&amp;quot; 
 SSLEnabled=&amp;quot;true&amp;quot;
 maxThreads=&amp;quot;150&amp;quot; 
 scheme=&amp;quot;https&amp;quot; 
 secure=&amp;quot;true&amp;quot; 
 clientAuth=&amp;quot;false&amp;quot;
 sslProtocol=&amp;quot;TLS&amp;quot; 
 keystoreFile=&amp;quot;conf\tech-annex.keystore&amp;quot; /&amp;gt;
&lt;/pre&gt;&lt;/ul&gt;&lt;b&gt;Step 3: Configure Web Application&lt;/b&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Open WEB.XML file of your web application and following property to it.&lt;br /&gt;
&lt;pre class=&quot;brush:xml&quot;&gt;&amp;lt;transport-guarantee&amp;gt;CONFIDENTIAL&amp;lt;/transport-guarantee&amp;gt;
&lt;/pre&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;b&gt;Step 4: Test the application&lt;/b&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Start tomcat and deploy the application.&lt;/li&gt;
&lt;li&gt;Hit the URL application url using HTTPS as &lt;code&gt;https://localhost:8443/itannex&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Your browser(firefox in this case) should show a warning message as below image for untrusted connection.&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi22Il_xLjq9iASFXc_Qumt-_lqDKH7lrHph4T67dKM4I-ZnpDXEDrOGO_LGxhptIp4xFCTiyXFKwWuq0Psq-i53_mXfbp2HXDJWR_mDAznxlgYzwClj8TXipjH92APfISb0unQqrNWjmOr/s1600/untusted.jpg&quot; imageanchor=&quot;1&quot; style=&quot;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;170&quot; width=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi22Il_xLjq9iASFXc_Qumt-_lqDKH7lrHph4T67dKM4I-ZnpDXEDrOGO_LGxhptIp4xFCTiyXFKwWuq0Psq-i53_mXfbp2HXDJWR_mDAznxlgYzwClj8TXipjH92APfISb0unQqrNWjmOr/s320/untusted.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;This is because we are using a self signed SSL certificate and your browser have no trust on it. &lt;h1&gt;&amp;#9786;&lt;/h1&gt;Ignore this and say browser that I understand the risk as you trust this connection.&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
Hurrayyy!!! You had just configured and tested HTTPS on your tomcat server. &lt;br /&gt;
&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all();
SyntaxHighlighter.highlight();
&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://tech-annex.blogspot.com/feeds/5878701780347350607/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://tech-annex.blogspot.com/2012/05/enable-https-in-tomcat-with-self-signed.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/5878701780347350607'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/5878701780347350607'/><link rel='alternate' type='text/html' href='http://tech-annex.blogspot.com/2012/05/enable-https-in-tomcat-with-self-signed.html' title='Enable HTTPS in tomcat with self signed SSL Cerficates'/><author><name>Tejas Purohit</name><uri>http://www.blogger.com/profile/12572963277655039205</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj61LMQasMba7t1nDNHcF4TA4oB53ydZQB2Zx9lwPBGzjTlaggkPx165DSyYg0Nvvo6Mqqk6o6oopUoGfgVbHXNbX1DuPhAG4IdXARNW-6O5dfec4YXDD5fay8u7mLdtNnC15WhkWCFuEaKypXRBXtrTfsSskw6ODSrVScbALtLa7aEhA/s220/IMG_4680.jpeg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-5k6hjD-U-jbaMQUiJNA_PIpcicJnrrSkspq5b72B7rcBqGUl-uh1B7vs8WCuRXNWtqI2niVtDEF940hBo7RDrA79lanKJdY3n8_mGqgryJxzI1YO0dkXMElM2z3uEvx0pj7xALWHa5dp/s72-c/KeyStore.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2679601544275098679.post-5721718008480505217</id><published>2011-12-09T16:13:00.000+05:30</published><updated>2015-03-17T21:51:13.185+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="auth-constraint"/><category scheme="http://www.blogger.com/atom/ns#" term="cookie-config"/><category scheme="http://www.blogger.com/atom/ns#" term="error-code"/><category scheme="http://www.blogger.com/atom/ns#" term="error-page"/><category scheme="http://www.blogger.com/atom/ns#" term="exception-type"/><category scheme="http://www.blogger.com/atom/ns#" term="http-only"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="security-constraint"/><category scheme="http://www.blogger.com/atom/ns#" term="session-config"/><category scheme="http://www.blogger.com/atom/ns#" term="session-timeout"/><category scheme="http://www.blogger.com/atom/ns#" term="tracking-mode"/><category scheme="http://www.blogger.com/atom/ns#" term="transport-guarantee"/><category scheme="http://www.blogger.com/atom/ns#" term="Web Security"/><category scheme="http://www.blogger.com/atom/ns#" term="Web.xml"/><title type='text'>Essential Security Configurations in Java web.xml File</title><content type='html'>Developing a safe, secure and stable Web Applications can be a painful task if you are not aware of all the capabilities your development environment provides. At the same point of time it will also make it very easy and manageable if you are aware of them.&lt;br /&gt;
&lt;br /&gt;
In this article we are going to look into some common but essential configurations for Java Web Applications deployment descriptor file &lt;b&gt;WEB.XML&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Authentication &amp; Authorization Bypass&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
Web Applications can have many kind of informations and data hosted to it which can include public, shared and private data for different group of users. It the job of developer to take care that, confidential or private data can only be accessed by owner of the data or by specific group of users.&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;em&gt;&amp;lt;security-constraint&amp;gt;&lt;/em&gt; element can make things easier as it can control web based access of secured directories or information. Following code shows a basic example of security constraints:&lt;br /&gt;
&lt;pre class=&#39;brush:xml; highlight: [4,9]&#39;&gt;&amp;lt;security-constraint&amp;gt;
 &amp;lt;web-resource-collection&amp;gt;
  &amp;lt;web-resource-name&amp;gt;secure&amp;lt;/web-resource-name&amp;gt;
  &amp;lt;url-pattern&amp;gt;/admin/*&amp;lt;/url-pattern&amp;gt;
  &amp;lt;http-method&amp;gt;GET&amp;lt;/http-method&amp;gt;
  &amp;lt;http-method&amp;gt;POST&amp;lt;/http-method&amp;gt;
 &amp;lt;/web-resource-collection&amp;gt;
 &amp;lt;auth-constraint&amp;gt;
  &amp;lt;role-name&amp;gt;admin&amp;lt;/role-name&amp;gt;
 &amp;lt;/auth-constraint&amp;gt;
&amp;lt;/security-constraint&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
Above example indicates that anything under url pattern or directory &lt;em&gt;/admin/*&lt;/em&gt; can be accessed by user with role &lt;em&gt;admin&lt;/em&gt; using HTTP methods &lt;em&gt;GET&lt;/em&gt; and &lt;em&gt;POST&lt;/em&gt;.&lt;br /&gt;
&lt;br /&gt;
Above example indicates that no user without having &lt;em&gt;/admin/*&lt;/em&gt; role can access anything under url pattern or directory &lt;em&gt;/admin/*&lt;/em&gt; using HTTP methods &lt;em&gt;GET&lt;/em&gt; and &lt;em&gt;POST&lt;/em&gt;. Now question here is what about other HTTP methods like PUT, DELETE, TRACK, TRACE etc. The Configuration will allow any HTTP method which are not listed. Attackers can access your secured data using these methods. Attackers can also try sending some arbitrary string like &quot;HEEF&quot; as HTTP method verb. This is called &lt;i&gt;verb-based authentication and access control (VBAAC) bypass vulnerabilities&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
A solution to this vulnerabilities is to remove all &lt;em&gt;&amp;lt;http-method&amp;gt;&lt;/em&gt; restrictions from access control and authorization rules, this will apply rules to all requests with any HTTP method.&lt;br /&gt;
&lt;br /&gt;
Improvement to above sample can be as follows:&lt;br /&gt;
&lt;pre class=&#39;brush:xml; highlight: [4,8]&#39;&gt;&amp;lt;security-constraint&amp;gt;
 &amp;lt;web-resource-collection&amp;gt;
  &amp;lt;web-resource-name&amp;gt;secure&amp;lt;/web-resource-name&amp;gt;
  &amp;lt;url-pattern&amp;gt;/admin/*&amp;lt;/url-pattern&amp;gt;
  &amp;lt;!-- No HTTP Methods should be listed here --&amp;gt;
 &amp;lt;/web-resource-collection&amp;gt;
 &amp;lt;auth-constraint&amp;gt;
  &amp;lt;role-name&amp;gt;admin&amp;lt;/role-name&amp;gt;
 &amp;lt;/auth-constraint&amp;gt;
&amp;lt;/security-constraint&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Configuring SSL&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
SSL must be used to access sensitive or confidential data in all applications. You can define SSL configurations in &lt;em&gt;&amp;lt;security-constraint&amp;gt;&lt;/em&gt; element as below:&lt;br /&gt;
&lt;pre class=&#39;brush:xml; highlight: [3]&#39;&gt;&amp;lt;security-constraint&amp;gt;
 &amp;lt;user-data-constraint&amp;gt;
  &amp;lt;transport-guarantee&amp;gt;CONFIDENTIAL&amp;lt;/transport-guarantee&amp;gt;
 &amp;lt;/user-data-constraint&amp;gt;
&amp;lt;/security-constraint&amp;gt;
&lt;/pre&gt;Prior to enabling SSL at web application level you should configure your server for that. you can follow  &lt;a href=&quot;http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html&quot;&gt;this&lt;/a&gt; document to configure SSL at tomcat.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Using URL Parameters for Session Tracking&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
The &lt;em&gt;&amp;lt;tracking-mode&amp;gt;&lt;/em&gt; element in the Servlet 3.0 specification define that the JSESSIONID(current session id) should be stored in a cookie or in a URL parameter so that client can use it with next request to the server. &lt;br /&gt;
&lt;br /&gt;
If session id is passed as URL parameter it can be saved at various locations including the history of browser, logs at proxy server, referrer logs, web logs, etc. An accidental disclosure of the session id makes the application more vulnerable to session hijacking attacks. Instead, you should make sure the session id is stored in a cookie using the following configuration:&lt;br /&gt;
&lt;pre class=&#39;brush:xml; highlight: [2]&#39;&gt;&amp;lt;session-config&amp;gt;
 &amp;lt;tracking-mode&amp;gt;COOKIE&amp;lt;/tracking-mode&amp;gt;
&amp;lt;/session-config&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Using the Secure Flag&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
All of us normally use SSL for authentication of the user like login action but revert back to non-SSL for rest of the operations in our application as they can be accessed via non-SSL. This makes session id vulnerable to attacks like session hijacking. As a solution to this problem we can configure session such a way that client(browser) should not transmit cookie with session id over non-SSL.&lt;br /&gt;
&lt;br /&gt;
You can configure this as follows:&lt;br /&gt;
&lt;pre class=&#39;brush:xml; highlight: [3]&#39;&gt;&amp;lt;session-config&amp;gt;
 &amp;lt;cookie-config&amp;gt;
  &amp;lt;secure&amp;gt;true&amp;lt;/secure&amp;gt;
 &amp;lt;/cookie-config&amp;gt;
&amp;lt;/session-config&amp;gt;
&lt;/pre&gt;This will ensure that browser will keep session id cookie secure and never expose it over non-SSL requests.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Using the HttpOnly Flag&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
Along with secure flag for cookie storing session id we should also &lt;em&gt;HttpOnly&lt;/em&gt; flag with it. &lt;em&gt;HttpOnly&lt;/em&gt; flag ensures that cookie with session id can be accessed by HTTP actions only. &lt;br /&gt;
&lt;br /&gt;
Thus session cookie is secured from client side access using java scripts and this will minimize risk of attacks like &lt;a href=&quot;http://en.wikipedia.org/wiki/Cross_site_scripting&quot;&gt;XSS&lt;/a&gt;. &lt;br /&gt;
&lt;br /&gt;
You can configure this as follows:&lt;br /&gt;
&lt;pre class=&#39;brush:xml; highlight: [3]&#39;&gt;&amp;lt;session-config&amp;gt;
 &amp;lt;cookie-config&amp;gt;
  &amp;lt;http-only&amp;gt;true&amp;lt;/http-only&amp;gt;
 &amp;lt;/cookie-config&amp;gt;
&amp;lt;/session-config&amp;gt;
&lt;/pre&gt;Your server also takes care for this, in Tomcat 7 server.xml &lt;em&gt;useHttpOnly&lt;/em&gt; attribute inside &lt;em&gt;&amp;lt;Context&amp;gt;&lt;/em&gt; element is enabled by default. So, even if you configure web.xml to be &amp;lt;http-only&amp;gt;false&amp;lt;/http-only&amp;gt; in Tomcat 7, your JSESSIONID will still be HttpOnly unless you change the default behaviour in server.xml as well.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Setting a Session Timeout&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
All of us like long lived sessions because its very convenient, No one from us will really like to enter user name and password to login again and again after some period of inactivity for any web application. But there are other group of users who also like long lived sessions so that they get more time for carrying out attacks like Session Hijacking and Cross Site Request Forgery. Now this is really a crucial choice security vs. comfort of use.&lt;br /&gt;
&lt;br /&gt;
You have to identify a period of time when sessions gets expired because of inactivity of the user. Session timeout period may vary based on the operations the application carry out but as a best practice it has to be configured in Web.XML.&lt;br /&gt;
&lt;pre class=&#39;brush:xml; highlight: [2]&#39;&gt;&amp;lt;session-config&amp;gt;
 &amp;lt;session-timeout&amp;gt;30&amp;lt;/session-timeout&amp;gt; // Timeout in minutes
&amp;lt;/session-config&amp;gt;
&lt;/pre&gt;Above example shows session time out after 30 minutes of inactivity but you can configure this as per your requirement. If session time out is not configured in Web.XML then controller&#39;s default time out settings will be used(e.g. Tomcat has 30 minutes as default). Number less than or equal to 0 will set infinite time for session time out thus the session will never expire(So many websites use this option now a days). &lt;br /&gt;
&lt;br /&gt;
In addition to session time out configuration we should also consider hard time out for highly secured web sites like banking web sites etc. Hard time out will expire session after some period of time even user is actively using application. This leads user to login again after some period of time and assigns a new session. Java don&#39;t provide this behavior through configuration in WEB.XML but this can be achieved by ServletFilter.  &lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Configuring Custom Error Pages&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
Last but the most important configuration for any web application is defining your own custom error pages for handling errors. By default all java web application displays detailed error page with brief information of server, details about your server resources where error has occurred, snippet of the error stack trace and in some cases brief snippet of your server side code also. The purpose of this error page is to give a brief idea to the developer to track the error but for live and hosted applications scenario is totally different. For any attacker such information is like a treat which can be used to prepare attacks on your application. &lt;br /&gt;
&lt;br /&gt;
You can configure your own custom error pages for specific errors as follows:&lt;br /&gt;
&lt;pre class=&#39;brush:xml; highlight: [2]&#39;&gt;&amp;lt;error-page&amp;gt;
 &amp;lt;error-code&amp;gt;500&amp;lt;/error-code&amp;gt;
 &amp;lt;location&amp;gt;/errors/505.jsp&amp;lt;/location&amp;gt;
&amp;lt;/error-page&amp;gt;
&lt;/pre&gt;Above configuration will redirect to 505.jsp when ever server encounter 505 HTTP error.&lt;br /&gt;
&lt;pre class=&#39;brush:xml; highlight: [2]&#39;&gt;&amp;lt;error-page&amp;gt;
 &amp;lt;exception-type&amp;gt;java.lang.Throwable&amp;lt;/exception-type&amp;gt;
 &amp;lt;location&amp;gt;/errors/error.jsp&amp;lt;/location&amp;gt;
&amp;lt;/error-page&amp;gt;
&lt;/pre&gt;Above configuration will redirect to error.jsp when ever server encounter &lt;em&gt;java.lang.Throwable&lt;/em&gt; error.&lt;br /&gt;
&lt;br /&gt;
Below is the list of some 404 error pages from popular sites:&lt;a href=&quot;http://www.google.com/404&quot;&gt;Google&lt;/a&gt;, &lt;a href=&quot;http://www.yahoo.com/404&quot;&gt;Yahoo&lt;/a&gt;, &lt;a href=&quot;https://github.com/404&quot;&gt;GitHub&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
You can find a detailed list of all HTTP error &lt;a href=&quot;http://en.wikipedia.org/wiki/HTTP_Errors&quot;&gt;here&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Reference: &lt;a href=&quot;http://software-security.sans.org/blog/2010/08/11/security-misconfigurations-java-webxml-files&quot;&gt;Seven Security (Mis)Configurations in Java web.xml Files&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all();
SyntaxHighlighter.highlight();
&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://tech-annex.blogspot.com/feeds/5721718008480505217/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://tech-annex.blogspot.com/2011/12/essential-security-configurations-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/5721718008480505217'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/5721718008480505217'/><link rel='alternate' type='text/html' href='http://tech-annex.blogspot.com/2011/12/essential-security-configurations-in.html' title='Essential Security Configurations in Java web.xml File'/><author><name>Tejas Purohit</name><uri>http://www.blogger.com/profile/12572963277655039205</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj61LMQasMba7t1nDNHcF4TA4oB53ydZQB2Zx9lwPBGzjTlaggkPx165DSyYg0Nvvo6Mqqk6o6oopUoGfgVbHXNbX1DuPhAG4IdXARNW-6O5dfec4YXDD5fay8u7mLdtNnC15WhkWCFuEaKypXRBXtrTfsSskw6ODSrVScbALtLa7aEhA/s220/IMG_4680.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2679601544275098679.post-635136873031336770</id><published>2011-09-12T23:14:00.000+05:30</published><updated>2015-03-17T21:48:42.919+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Alerts"/><category scheme="http://www.blogger.com/atom/ns#" term="Email Alerts"/><category scheme="http://www.blogger.com/atom/ns#" term="Google"/><category scheme="http://www.blogger.com/atom/ns#" term="Google Alerts"/><category scheme="http://www.blogger.com/atom/ns#" term="News"/><category scheme="http://www.blogger.com/atom/ns#" term="SMS Alerts"/><title type='text'>Google Alerts: Keep yourself updated</title><content type='html'>&lt;a href=&quot;http://itannex.files.wordpress.com/2011/09/googlealerts11.jpg&quot;&gt;&lt;img src=&quot;http://itannex.files.wordpress.com/2011/09/googlealerts11.jpg&quot; alt=&quot;&quot; title=&quot;GoogleAlerts&quot; width=&quot;153&quot; height=&quot;65&quot; align=&quot;left&quot; style=&quot;margin-right: 5px;&quot;/&gt;&lt;/a&gt;&lt;b&gt;What are Google Alerts?&lt;/b&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.google.com/alerts&quot;&gt;Google Alerts&lt;/a&gt; are emails sent to you when Google finds new results -- such as web pages, newspaper articles, or blogs -- that match your search term. You can use Google Alerts to monitor anything on the Web. For example, people use Google Alerts to:&lt;ul&gt;&lt;li&gt;find out what is being said about their company or product.&lt;/li&gt;
&lt;li&gt;monitor a developing news story.&lt;/li&gt;
&lt;li&gt;keep up to date on a competitor or industry.&lt;/li&gt;
&lt;li&gt;get the latest news on a celebrity or sports team.&lt;/li&gt;
&lt;li&gt;find out what&#39;s being said about themselves.&lt;/li&gt;
&lt;/ul&gt;&lt;b&gt;Here&#39;s how it works:&lt;/b&gt;&lt;ol&gt;&lt;li&gt;You enter a query that you&#39;re interested in.&lt;/li&gt;
&lt;li&gt;Google Alerts checks regularly to see if there are new results for your query.&lt;/li&gt;
&lt;li&gt;If there are new results, Google Alerts sends them to you in an email.&lt;/li&gt;
&lt;/ol&gt;For general queries like [ &lt;span class=&quot;code&quot;&gt;&quot;Information Technology&quot;&lt;/span&gt; ], you can get a summary of the new results every day. For specific topics, like [ &lt;span class=&quot;code&quot;&gt;cardiovascular atherosclerosis&lt;/span&gt; ], you might not get an email every day, but you&#39;ll find out when something new and relevant is published. &lt;a href=&quot;http://www.google.com/support/alerts/bin/alerts/bin/static.py?page=guide.cs&amp;amp;guide=28413&amp;amp;topic=28416&amp;amp;answer=175928&quot;&gt;See more examples of how Google Alerts are used&lt;/a&gt;&lt;br /&gt;
So, Keep your self updated!!!&lt;br /&gt;
&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all();
SyntaxHighlighter.highlight();
&lt;/script&gt;&lt;br /&gt;
</content><link rel='replies' type='application/atom+xml' href='http://tech-annex.blogspot.com/feeds/635136873031336770/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://tech-annex.blogspot.com/2011/09/google-alerts-keep-yourself-updated.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/635136873031336770'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/635136873031336770'/><link rel='alternate' type='text/html' href='http://tech-annex.blogspot.com/2011/09/google-alerts-keep-yourself-updated.html' title='Google Alerts: Keep yourself updated'/><author><name>Tejas Purohit</name><uri>http://www.blogger.com/profile/12572963277655039205</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj61LMQasMba7t1nDNHcF4TA4oB53ydZQB2Zx9lwPBGzjTlaggkPx165DSyYg0Nvvo6Mqqk6o6oopUoGfgVbHXNbX1DuPhAG4IdXARNW-6O5dfec4YXDD5fay8u7mLdtNnC15WhkWCFuEaKypXRBXtrTfsSskw6ODSrVScbALtLa7aEhA/s220/IMG_4680.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2679601544275098679.post-8476432713295654308</id><published>2011-09-07T20:20:00.000+05:30</published><updated>2015-03-17T21:48:19.816+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="PhantomReference"/><category scheme="http://www.blogger.com/atom/ns#" term="Reference"/><category scheme="http://www.blogger.com/atom/ns#" term="ReferenceQueue"/><category scheme="http://www.blogger.com/atom/ns#" term="SoftReference"/><category scheme="http://www.blogger.com/atom/ns#" term="Technical"/><category scheme="http://www.blogger.com/atom/ns#" term="WeakReference"/><title type='text'>A quick Reference to java.lang.ref package</title><content type='html'>The &lt;code&gt;java.lang.ref&lt;/code&gt; package defines classes that allow Java programs to interact with the Java garbage collector. A &lt;code&gt;Reference&lt;/code&gt; represents an indirect reference to an arbitrary object, known as the &lt;i class=&quot;emphasis&quot;&gt;referent&lt;/i&gt;. &lt;code&gt;SoftReference&lt;/code&gt;, &lt;code&gt;WeakReference&lt;/code&gt;, and &lt;code&gt;PhantomReference&lt;/code&gt; are three concrete subclasses of &lt;code&gt;Reference&lt;/code&gt; that interact with the garbage collector in different ways, as explained in the individual class descriptions that follow. &lt;code&gt;ReferenceQueue&lt;/code&gt; represents a linked list of &lt;code&gt;Reference&lt;/code&gt; objects. Any &lt;code&gt;Reference&lt;/code&gt; object may have a &lt;code&gt;ReferenceQueue&lt;/code&gt; associated with it.&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt; A &lt;code&gt;Reference&lt;/code&gt; object is &lt;i class=&quot;emphasis&quot;&gt;enqueued&lt;/i&gt; on its &lt;code&gt;ReferenceQueue&lt;/code&gt; at some point after the garbage collector determines that the referent object has become appropriately unreachable. (The exact level of unreachability depends on the type of &lt;code&gt;Reference&lt;/code&gt; being used.) An application can monitor a &lt;code&gt;ReferenceQueue&lt;/code&gt; to determine when referent objects enter a new reachability status.&lt;br /&gt;
&lt;br /&gt;
Using the mechanisms defined in this package, you can implement a cache that grows and shrinks in size according to the amount of available system memory. Or, you can implement a hashtable that associates auxiliary information with arbitrary objects, but does not prevent those objects from being garbage-collected if they are otherwise unused. The mechanisms provided by this package are low-level ones, however, and typical applications do not use &lt;code&gt;java.lang.ref&lt;/code&gt; directly. Instead, they rely on higher-level utilities built on top of the package. See &lt;code&gt;java.util.WeakHashMap&lt;/code&gt; for one example.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;code&gt;java.lang.ref.PhantomReference&lt;/code&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
This class represents a reference to an object that does not prevent the referent object from being finalized by the garbage collector. When (or at some point after) the garbage collector determines that there are no more hard (direct) references to the referent object, that there are no &lt;code&gt;SoftReference&lt;/code&gt; or &lt;code&gt;WeakReference&lt;/code&gt; objects that refer to the referent, and that the referent has been finalized, it enqueues the &lt;code&gt;PhantomReference&lt;/code&gt; object on the &lt;code&gt;ReferenceQueue&lt;/code&gt; specified when the &lt;code&gt;PhantomReference&lt;/code&gt; was created. This serves as notification that the object has been finalized and provides one last opportunity for any required cleanup code to be run.&lt;br /&gt;
&lt;br /&gt;
To prevent a &lt;code&gt;PhantomReference&lt;/code&gt; object from resurrecting its referent object, its &lt;code&gt;get()&lt;/code&gt; method always returns &lt;code&gt;null&lt;/code&gt;, both before and after the &lt;code&gt;PhantomReference&lt;/code&gt; is enqueued. Nevertheless, a &lt;code&gt;PhantomReference&lt;/code&gt; is not automatically cleared when it is enqueued, so when you remove a &lt;code&gt;PhantomReference&lt;/code&gt; from a &lt;code&gt;ReferenceQueue&lt;/code&gt;, you must call its &lt;code&gt;clear()&lt;/code&gt; method or allow the &lt;code&gt;PhantomReference&lt;/code&gt; object itself to be garbage-collected.&lt;br /&gt;
&lt;br /&gt;
This class provides a more flexible mechanism for object cleanup than the &lt;code&gt;finalize()&lt;/code&gt; method does. Note that in order to take advantage of it, it is necessary to subclass &lt;code&gt;PhantomReference&lt;/code&gt; and define a method to perform the desired cleanup. Furthermore, since the &lt;code&gt;get()&lt;/code&gt; method of a &lt;code&gt;PhantomReference&lt;/code&gt; always returns &lt;code&gt;null&lt;/code&gt;, such a subclass must also store whatever data is required for the cleanup operation.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:java&quot;&gt;public class PhantomReference extends java.lang.ref.Reference {
 
 // Public Constructors
 public PhantomReference (Object referent, ReferenceQueue q);

 // Public Methods Overriding Reference
 public Object get ();

}
&lt;/pre&gt;Hierarchy: &lt;code&gt;Object--&amp;gt;java.lang.ref.Reference--&amp;gt;PhantomReference&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;code&gt;java.lang.ref.Reference&lt;/code&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
This abstract class represents some type of indirect reference to a referent. &lt;code&gt;get()&lt;/code&gt; returns the referent if the reference has not been explicitly cleared by the &lt;code&gt;clear()&lt;/code&gt; method or implicitly cleared by the garbage collector. There are three concrete subclasses of &lt;code&gt;Reference&lt;/code&gt;. The garbage collector handles these subclasses differently and clears their references under different circumstances.&lt;br /&gt;
&lt;br /&gt;
Each of the subclasses of &lt;code&gt;Reference&lt;/code&gt; defines a constructor that allows a &lt;code&gt;ReferenceQueue&lt;/code&gt; to be associated with the &lt;code&gt;Reference&lt;/code&gt; object. The garbage collector places &lt;code&gt;Reference&lt;/code&gt; objects onto their associated &lt;code&gt;ReferenceQueue&lt;/code&gt; objects to provide notification about the state of the referent object. &lt;code&gt;isEnqueued()&lt;/code&gt; tests whether a &lt;code&gt;Reference&lt;/code&gt; has been placed on the associated queue, and &lt;code&gt;enqueue()&lt;/code&gt; explicitly places it on the queue. &lt;code&gt;enqueue()&lt;/code&gt; returns &lt;code&gt;false&lt;/code&gt; if the &lt;code&gt;Reference&lt;/code&gt; object does not have an associated &lt;code&gt;ReferenceQueue&lt;/code&gt;, or if it has already been enqueued.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:java&quot;&gt;public abstract class Reference {

    //No Constructor

    //Public Instance Methods
    public void clear ();

    public boolean enqueue ();

    public Object get ();

    public boolean isEnqueued ();

}&lt;/pre&gt;Subclasses: &lt;code&gt;PhantomReference, SoftReference, WeakReference&lt;/code&gt;&lt;br /&gt;
Returned By: &lt;code&gt;ReferenceQueue.{poll(), remove()}&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;code&gt;java.lang.ref.ReferenceQueue&lt;/code&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
This class represents a queue (or linked list) of &lt;code&gt;Reference&lt;/code&gt; objects that have been enqueued because the garbage collector has determined that the referent objects to which they refer are no longer adequately reachable. It serves as a notification system for object-reachability changes. Use &lt;code&gt;poll()&lt;/code&gt; to return the first &lt;code&gt;Reference&lt;/code&gt; object on the queue; the method returns &lt;code&gt;null&lt;/code&gt; if the queue is empty. Use &lt;code&gt;remove()&lt;/code&gt; to return the first element on the queue, or, if the queue is empty, to wait for a &lt;code&gt;Reference&lt;/code&gt; object to be enqueued. You can create as many &lt;code&gt;ReferenceQueue&lt;/code&gt; objects as needed. Specify a &lt;code&gt;ReferenceQueue&lt;/code&gt; for a &lt;code&gt;Reference&lt;/code&gt; object by passing it to the &lt;code&gt;SoftReference()&lt;/code&gt;, &lt;code&gt;WeakReference()&lt;/code&gt;, or &lt;code&gt;PhantomReference()&lt;/code&gt; constructor.&lt;br /&gt;
&lt;br /&gt;
A &lt;code&gt;ReferenceQueue&lt;/code&gt; is required to use &lt;code&gt;PhantomReference&lt;/code&gt; objects. It is optional with &lt;code&gt;SoftReference&lt;/code&gt; and &lt;code&gt;WeakReference&lt;/code&gt; objects; for these classes, the &lt;code&gt;get()&lt;/code&gt; method returns &lt;code&gt;null&lt;/code&gt; if the referent object is no longer adequately reachable.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:java&quot;&gt;public class ReferenceQueue {

 //Public Constructors
 public ReferenceQueue ();

 //Public Instance Methods
 public java.lang.ref.Reference poll ();

 public java.lang.ref.Reference remove () throws InterruptedException;

 public java.lang.ref.Reference remove (long timeout) throws IllegalArgumentExceptionInterruptedException;
 
}&lt;/pre&gt;Passed To:&lt;code&gt;PhantomReference.PhantomReference(), SoftReference.SoftReference(), WeakReference.WeakReference()&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;code&gt;java.lang.ref.SoftReference&lt;/code&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
This class represents a soft reference to an object. A &lt;code&gt;SoftReference&lt;/code&gt; is not cleared while there are any remaining hard (direct) references to the referent. Once the referent is no longer in use (i.e., there are no remaining hard references to it), the garbage collector may clear the &lt;code&gt;SoftReference&lt;/code&gt; to the referent at any time. However, the garbage collector does not clear a &lt;code&gt;SoftReference&lt;/code&gt; until it determines that system memory is running low. In particular, the Java VM never throws an &lt;code&gt;OutOfMemoryError&lt;/code&gt; without first clearing all soft references and reclaiming the memory of the referents. The VM may (but is not required to) clear soft references according to a least-recently-used ordering.&lt;br /&gt;
&lt;br /&gt;
If a &lt;code&gt;SoftReference&lt;/code&gt; has an associated &lt;code&gt;ReferenceQueue&lt;/code&gt;, the garbage collector enqueues the &lt;code&gt;SoftReference&lt;/code&gt; at some time after it clears the reference.&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;SoftReference&lt;/code&gt; is particularly useful for implementing object-caching systems that do not have a fixed size, but grow and shrink as available memory allows.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:java&quot;&gt;public class SoftReference extends java.lang.ref.Reference {
 //Public Constructors
 public SoftReference (Object referent);

 public SoftReference (Object referent, ReferenceQueue q);

 //Public Methods Overriding Reference
 public Object get ();

}&lt;/pre&gt;Hierarchy: &lt;code&gt;Object--&amp;gt;java.lang.ref.Reference--&amp;gt;SoftReference &lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;code&gt;java.lang.ref.WeakReference&lt;/code&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
This class refers to an object in a way that does not prevent that referent object from being finalized and reclaimed by the garbage collector. When the garbage collector determines that there are no more hard (direct) references to the object, and that there are no &lt;code&gt;SoftReference&lt;/code&gt; objects that refer to the object, it clears the &lt;code&gt;WeakReference&lt;/code&gt; and marks the referent object for finalization. At some point after this, it also enqueues the &lt;code&gt;WeakReference&lt;/code&gt; on its associated &lt;code&gt;ReferenceQueue&lt;/code&gt;, if there is one, in order to provide notification that the referent has been reclaimed.&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;WeakReference&lt;/code&gt; is used by &lt;code&gt;java.util.WeakHashMap&lt;/code&gt; to implement a hashtable that does not prevent the hashtable key object from being garbage-collected. &lt;code&gt;WeakHashMap&lt;/code&gt; is useful when you want to associate auxiliary information with an object but do not want to prevent the object from being reclaimed.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:java&quot;&gt;public class WeakReference extends java.lang.ref.Reference {

 //Public Constructors
 public WeakReference (Object referent);

 public WeakReference (Object referent, ReferenceQueue q);

}&lt;/pre&gt;Hierarchy: &lt;code&gt;Object--&amp;gt;java.lang.ref.Reference--&amp;gt;WeakReference&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Disclaimer:&lt;/b&gt; Content of this blog is property of O&#39;Reilly &amp;amp; Associates. Content displayed here is just for reference purpose only. You can find actual content &lt;a href=&quot;http://docstore.mik.ua/orelly/java-ent/jnut/ch13_01.htm&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all();
SyntaxHighlighter.highlight();
&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://tech-annex.blogspot.com/feeds/8476432713295654308/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://tech-annex.blogspot.com/2011/09/quick-reference-to-javalangref-package.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/8476432713295654308'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/8476432713295654308'/><link rel='alternate' type='text/html' href='http://tech-annex.blogspot.com/2011/09/quick-reference-to-javalangref-package.html' title='A quick Reference to java.lang.ref package'/><author><name>Tejas Purohit</name><uri>http://www.blogger.com/profile/12572963277655039205</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj61LMQasMba7t1nDNHcF4TA4oB53ydZQB2Zx9lwPBGzjTlaggkPx165DSyYg0Nvvo6Mqqk6o6oopUoGfgVbHXNbX1DuPhAG4IdXARNW-6O5dfec4YXDD5fay8u7mLdtNnC15WhkWCFuEaKypXRBXtrTfsSskw6ODSrVScbALtLa7aEhA/s220/IMG_4680.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2679601544275098679.post-5614823130567795027</id><published>2011-08-29T21:34:00.000+05:30</published><updated>2015-03-17T21:48:07.135+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Properties"/><category scheme="http://www.blogger.com/atom/ns#" term="System Properties"/><category scheme="http://www.blogger.com/atom/ns#" term="Technical"/><title type='text'>Java Platform System Properties</title><content type='html'>The Java platform itself uses a &lt;code&gt;Properties&lt;/code&gt; object to maintain its own configuration. The &lt;code&gt;System&lt;/code&gt; class maintains a &lt;code&gt;Properties&lt;/code&gt; object that describes the configuration of the current working environment. System properties include information about the current user, the current version of the Java runtime, and the character used to separate components of a file path name.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Important system properties&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The following table describes some of the most important system properties &lt;br /&gt;
&lt;br /&gt;
&lt;table style=&quot;border-width: 1px;  border-spacing: 5px;  border-style: solid;  border-color: gray;&quot; summary=&quot;Important system properties&quot;&gt;&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Key&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;  &lt;tbody style=&quot;vertical-align:text-top;&quot;&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;&quot;file.separator&quot;&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Character that separates components of a file path. This is&quot;&lt;code&gt;/&lt;/code&gt;&quot; on UNIX and &quot;&lt;code&gt;\&lt;/code&gt;&quot; on Windows.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;&quot;java.class.path&quot;&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Path used to find directories and JAR archives containing class files. Elements of the class path are separated by a platform-specific character specified in the &lt;code&gt;path.separator&lt;/code&gt; property.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;&quot;java.home&quot;&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Installation directory for Java Runtime Environment (JRE)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;&quot;java.vendor&quot;&lt;/code&gt;&lt;/td&gt;&lt;td&gt;JRE vendor name&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;&quot;java.vendor.url&quot;&lt;/code&gt;&lt;/td&gt;&lt;td&gt;JRE vendor URL&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;&quot;java.version&quot;&lt;/code&gt;&lt;/td&gt;&lt;td&gt;JRE version number&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;&quot;line.separator&quot;&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Sequence used by operating system to separate lines in text files&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;&quot;os.arch&quot;&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Operating system architecture&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;&quot;os.name&quot;&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Operating system name&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;&quot;os.version&quot;&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Operating system version&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;&quot;path.separator&quot;&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Path separator character used in &lt;code&gt;java.class.path&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;&quot;user.dir&quot;&lt;/code&gt;&lt;/td&gt;&lt;td&gt;User working directory&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;&quot;user.home&quot;&lt;/code&gt;&lt;/td&gt;&lt;td&gt;User home directory&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;&quot;user.name&quot;&lt;/code&gt;&lt;/td&gt;&lt;td&gt;User account name&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt; &lt;/table&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;b&gt;Reading System Propertie&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The &lt;code&gt;System&lt;/code&gt; class has two methods used to read system properties: &lt;code&gt;getProperty&lt;/code&gt; and &lt;code&gt;getProperties&lt;/code&gt;.&lt;br /&gt;
The &lt;code&gt;System&lt;/code&gt; class has two different versions of &lt;code&gt;getProperty&lt;/code&gt;. Both retrieve the value of the property named in the argument list. The simpler of the two &lt;code&gt;getProperty&lt;/code&gt; methods takes a single argument, a property key For example, to get the value of &lt;code&gt;path.separator&lt;/code&gt;, use the following statement:&lt;br /&gt;
&lt;pre class=&#39;brush:java;&#39;&gt;System.getProperty(&quot;user.dir&quot;);
&lt;/pre&gt;&lt;br /&gt;
The &lt;code&gt;getProperty&lt;/code&gt; method returns a string containing the value of the property. If the property does not exist, this version of &lt;code&gt;getProperty&lt;/code&gt; returns null.&lt;br /&gt;
&lt;br /&gt;
The other version of &lt;code&gt;getProperty&lt;/code&gt; requires two &lt;code&gt;String&lt;/code&gt; arguments: the first argument is the key to look up and the second argument is a default value to return if the key cannot be found or if it has no value. For example, the following invocation of &lt;code&gt;getProperty&lt;/code&gt; looks up the &lt;code&gt;System&lt;/code&gt; property called &lt;code&gt;user.name&lt;/code&gt;. This is not a valid system property, so instead of returning null, this method returns the default value provided as a second argument: &quot;&lt;code&gt;Guest User&lt;/code&gt;&quot;&lt;br /&gt;
&lt;pre class=&#39;brush:java;&#39;&gt;System.getProperty(&quot;user.name&quot;, &quot;Guest User&quot;);

&lt;/pre&gt;&lt;br /&gt;
The last method provided by the &lt;code&gt;System&lt;/code&gt; class to access property values is the &lt;code&gt;getProperties&lt;/code&gt; method, which returns a &lt;a class=&quot;APILink&quot; href=&quot;http://download.oracle.com/javase/7/docs/api/java/util/Properties.html&quot; target=&quot;_blank&quot;&gt;&lt;code&gt; Properties&lt;/code&gt;&lt;/a&gt; object. This object contains a complete set of system property definitions.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://download.oracle.com/javase/tutorial/essential/environment/sysprop.html&quot; target=&quot;_blank&quot; title=&quot;From Java Tutorials: System Properties&quot;&gt;From Java Tutorials: System Properties&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all();
SyntaxHighlighter.highlight();
&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://tech-annex.blogspot.com/feeds/5614823130567795027/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://tech-annex.blogspot.com/2011/08/java-platform-system-properties.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/5614823130567795027'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/5614823130567795027'/><link rel='alternate' type='text/html' href='http://tech-annex.blogspot.com/2011/08/java-platform-system-properties.html' title='Java Platform System Properties'/><author><name>Tejas Purohit</name><uri>http://www.blogger.com/profile/12572963277655039205</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj61LMQasMba7t1nDNHcF4TA4oB53ydZQB2Zx9lwPBGzjTlaggkPx165DSyYg0Nvvo6Mqqk6o6oopUoGfgVbHXNbX1DuPhAG4IdXARNW-6O5dfec4YXDD5fay8u7mLdtNnC15WhkWCFuEaKypXRBXtrTfsSskw6ODSrVScbALtLa7aEhA/s220/IMG_4680.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2679601544275098679.post-7897054035930026304</id><published>2011-08-29T17:43:00.000+05:30</published><updated>2015-03-17T21:47:43.900+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Database"/><category scheme="http://www.blogger.com/atom/ns#" term="Oracle"/><category scheme="http://www.blogger.com/atom/ns#" term="Sequence"/><category scheme="http://www.blogger.com/atom/ns#" term="Technical"/><category scheme="http://www.blogger.com/atom/ns#" term="Trigger"/><title type='text'>Oracle - Using Sequence for Auto Increment</title><content type='html'>I am working with databases from past few years and I had created or came across hundreds of Tables in database. Out of all those tables 99.99% tables had any of Numeric Primary Key column or Serial Number column or anything similar to this where value of those columns follow numeric incremental pattern.&lt;br /&gt;
&lt;br /&gt;
These are very basic cases of database but there can be so many other cases in database when we need numeric incremental values. For this type of activities Sequence can be very handy.&lt;br /&gt;
&lt;br /&gt;
I am giving a very basic example of How you can use sequence in Oracle? We will perform following activities:&lt;br /&gt;
&lt;strong&gt;1.&lt;/strong&gt; Create Table with a Primary Key Field&lt;br /&gt;
&lt;strong&gt;2.&lt;/strong&gt; Using sequence while insert into table&lt;br /&gt;
&lt;strong&gt;3.&lt;/strong&gt; Achieving Auto Increment using Trigger&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Create Table&lt;/b&gt;&lt;br /&gt;
Creating Table &lt;em&gt;EMPLOYEE&lt;/em&gt; with a Primary Key &lt;em&gt;ID&lt;/em&gt;&lt;br /&gt;
&lt;pre class=&quot;brush:sql;&quot;&gt;CREATE TABLE EMPLOYEE (
ID NUMBER NOT NULL,
NAME VARCHAR2(100) NOT NULL,
DESIGNATION VARCHAR2(50) NOT NULL,

CONSTRAINT EMPLOYEE_PK PRIMARY KEY(ID)

);
&lt;/pre&gt;Now insert some rows into this table. See INSERT statements below:&lt;br /&gt;
&lt;pre class=&quot;brush:sql;&quot;&gt;INSERT INTO EMPLOYEE VALUES(1, &#39;Maecenas&#39;,&#39;Programmer&#39;);
INSERT INTO EMPLOYEE VALUES(2, &#39;Dolorem&#39;,&#39;Team Lead&#39;);
INSERT INTO EMPLOYEE VALUES(3, &#39;Consequat&#39;,&#39;Manager&#39;);
&lt;/pre&gt;Inserting data like this have a problem that before inserting data into table you have to take care that what should be the next value of &lt;em&gt;ID&lt;/em&gt; column. So you have to check last value of &lt;em&gt;ID&lt;/em&gt; column and then continue with next possible value. Creating sequence can solve this problem.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Using Sequence while insert into table&lt;/b&gt;&lt;br /&gt;
Creating Sequence &lt;em&gt;SEQ_EMPLOYEE_ID&lt;/em&gt; to get incremental value for Primary Key Column &lt;em&gt;ID&lt;/em&gt;&lt;br /&gt;
&lt;pre class=&quot;brush:sql;&quot;&gt;CREATE SEQUENCE SEQ_EMPLOYEE_ID
INCREMENT BY 1
START WITH 1;
&lt;/pre&gt;Now we insert data using the sequence we just created.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Note:&lt;/strong&gt; Delete all data from table &lt;em&gt;EMPLOYEE&lt;/em&gt; as we are starting our sequence from 1 and we already inserted data with value 1 in &lt;em&gt;ID&lt;/em&gt; column or you can create your sequence accordingly to start from 4 which should be the next value of &lt;em&gt;ID&lt;/em&gt; column. See INSERT statements below:&lt;br /&gt;
&lt;pre class=&quot;brush:sql;&quot;&gt;INSERT INTO EMPLOYEE VALUES(SEQ_EMPLOYEE_ID.nextval, &#39;Convallis&#39;,&#39;Programmer&#39;);
INSERT INTO EMPLOYEE VALUES(SEQ_EMPLOYEE_ID.nextval, &#39;Sollicitudin&#39;,&#39;Programmer&#39;);
INSERT INTO EMPLOYEE VALUES(SEQ_EMPLOYEE_ID.nextval, &#39;Quisque&#39;,&#39;Programmer&#39;);
&lt;/pre&gt;Still we are doing some manual stuff by getting next value form sequence and inserting it to &lt;em&gt;ID&lt;/em&gt; column while inserting data into &lt;em&gt;EMPLOYEE&lt;/em&gt; table. We can make it more effective by writing a Trigger which will insert value to &lt;em&gt;ID&lt;/em&gt; column automatically every time you insert data into &lt;em&gt;EMPLOYEE&lt;/em&gt; table.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Achieving auto increment using Trigger&lt;/b&gt;&lt;br /&gt;
Create a Trigger for inserting value to &lt;em&gt;ID&lt;/em&gt; column before insert into &lt;em&gt;EMPLOYEE&lt;/em&gt; table.&lt;br /&gt;
&lt;pre class=&quot;brush:sql;&quot;&gt;CREATE TRIGGER TRIG_EMPLOYEE_ID
BEFORE INSERT ON EMPLOYEE  for each row  
WHEN (new.id is null)  

begin
select SEQ_EMPLOYEE_ID.nextval into :new.id from dual;
end;
&lt;/pre&gt;&lt;br /&gt;
Now all we need to care about is inserting values of &lt;em&gt;NAME&lt;/em&gt; and &lt;em&gt;DESIGNATION&lt;/em&gt; columns while inserting data into &lt;em&gt;EMPLOYEE&lt;/em&gt; table because value of &lt;em&gt;ID&lt;/em&gt; column will be added by &lt;em&gt;TRIG_EMPLOYEE_ID&lt;/em&gt; trigger. See INSERT statements below:&lt;br /&gt;
&lt;pre class=&quot;brush:sql;&quot;&gt;INSERT INTO EMPLOYEE (NAME, DESIGNATION) VALUES(&#39;Convallis&#39;,&#39;Programmer&#39;);
INSERT INTO EMPLOYEE (NAME, DESIGNATION) VALUES(&#39;Sollicitudin&#39;,&#39;Programmer&#39;);
INSERT INTO EMPLOYEE (NAME, DESIGNATION) VALUES(&#39;Quisque&#39;,&#39;Programmer&#39;);
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;Oracle® database administrator&#39;s guide 11g release 1&lt;/b&gt;&lt;br /&gt;
&lt;a href=&quot;http://download.oracle.com/docs/cd/B28359_01/server.111/b28310/tables.htm&quot; target=&quot;_blank&quot; title=&quot;Managing Tables&quot;&gt;Managing Tables&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://download.oracle.com/docs/cd/B28359_01/server.111/b28310/views002.htm#ADMIN11792&quot; target=&quot;_blank&quot; title=&quot;Managing Sequences&quot;&gt;Managing Sequences&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://download.oracle.com/docs/cd/B28359_01/server.111/b28310/general004.htm#ADMIN11534&quot; target=&quot;_blank&quot; title=&quot;Enabling and Disabling Triggers&quot;&gt;Enabling and Disabling Triggers&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all();
SyntaxHighlighter.highlight();
&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://tech-annex.blogspot.com/feeds/7897054035930026304/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://tech-annex.blogspot.com/2011/08/oracle-using-sequence-for-auto.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/7897054035930026304'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/7897054035930026304'/><link rel='alternate' type='text/html' href='http://tech-annex.blogspot.com/2011/08/oracle-using-sequence-for-auto.html' title='Oracle - Using Sequence for Auto Increment'/><author><name>Tejas Purohit</name><uri>http://www.blogger.com/profile/12572963277655039205</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj61LMQasMba7t1nDNHcF4TA4oB53ydZQB2Zx9lwPBGzjTlaggkPx165DSyYg0Nvvo6Mqqk6o6oopUoGfgVbHXNbX1DuPhAG4IdXARNW-6O5dfec4YXDD5fay8u7mLdtNnC15WhkWCFuEaKypXRBXtrTfsSskw6ODSrVScbALtLa7aEhA/s220/IMG_4680.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2679601544275098679.post-5162741574705612437</id><published>2011-07-20T16:29:00.000+05:30</published><updated>2015-03-17T21:47:29.487+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Apache Tika"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="MIME Type"/><category scheme="http://www.blogger.com/atom/ns#" term="Technical"/><title type='text'>Apache Tika - Detect MIME Type of any file</title><content type='html'>&lt;strong&gt;Apache Tika - a content analysis toolkit&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
The Apache Tika™ toolkit detects and extracts metadata and structured text content from various documents using existing parser libraries. You can find the latest release on the &lt;a href=&quot;http://tika.apache.org/download.html&quot; title=&quot;download page&quot; target=&quot;_blank&quot;&gt;download page&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;b&gt;JAVA class to detect MIME Type of the file MIMETypeDetector.java&lt;/B&gt;&lt;br /&gt;
&lt;pre class=&#39;brush:java;&#39;&gt;import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.tika.Tika;
import org.apache.tika.io.TikaInputStream;
/** 
 * @author tejas.purohit
 * 
 **/
public class MIMETypeDetector {

 /*** Logger instance for logging info*/
 private final static Logger log = Logger.getLogger(MIMETypeDetector.class.getName());

 /*** Detect and return MIME Type of the given file. 
  * @param file java.io.File to detect MIME Type
  * @return MIME Type of the file as String
  */
 public static String getMimeType(File file) {
  String mimeType = null;
  try {
   Tika tika = null;
   TikaInputStream is = null;

   // Creating new Instance of org.apache.tika.Tika
   tika = new Tika();

   // Detecting MIME Type of the File
   mimeType = tika.detect(file);
  } catch (FileNotFoundException e) {
   log.log(Level.WARNING, &amp;quot;Specified File not found&amp;quot;, e);
  } catch (IOException e) {
   log.log(Level.WARNING, &amp;quot;IO Error&amp;quot;, e);
  }
  // returning detected MIME Type
  return mimeType;
 }

 /** 
  * Detect and return MIME Type of the given file. 
  * @param filePath full path of the file to detect MIME Type
  * @return MIME Type of the file as String
  */
 public static String getMimeType(String filePath) {

  // Creating new instance of java.io.File for given file path
  File f = new File(filePath);

  // Getting and returning MIME Type of the file
  return getMimeType(f);
 }

 public static void main(String[] args) {

  // Getting file path as command line argument
  String filePath = args[0];

  // Getting and printing MIME Type of the given file
  System.out.println(&amp;quot;Is ZIP file:&amp;quot; + MIMETypeDetector.getMimeType(filePath));
 }
}
&lt;/pre&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all();
SyntaxHighlighter.highlight();
&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://tech-annex.blogspot.com/feeds/5162741574705612437/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://tech-annex.blogspot.com/2011/07/apache-tika-detect-mime-type-of-any.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/5162741574705612437'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/5162741574705612437'/><link rel='alternate' type='text/html' href='http://tech-annex.blogspot.com/2011/07/apache-tika-detect-mime-type-of-any.html' title='Apache Tika - Detect MIME Type of any file'/><author><name>Tejas Purohit</name><uri>http://www.blogger.com/profile/12572963277655039205</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj61LMQasMba7t1nDNHcF4TA4oB53ydZQB2Zx9lwPBGzjTlaggkPx165DSyYg0Nvvo6Mqqk6o6oopUoGfgVbHXNbX1DuPhAG4IdXARNW-6O5dfec4YXDD5fay8u7mLdtNnC15WhkWCFuEaKypXRBXtrTfsSskw6ODSrVScbALtLa7aEhA/s220/IMG_4680.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2679601544275098679.post-7510657774699430383</id><published>2011-04-26T23:31:00.000+05:30</published><updated>2015-03-17T21:47:12.044+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Caching"/><category scheme="http://www.blogger.com/atom/ns#" term="Compressing"/><category scheme="http://www.blogger.com/atom/ns#" term="Filters"/><category scheme="http://www.blogger.com/atom/ns#" term="Servlet"/><category scheme="http://www.blogger.com/atom/ns#" term="Technical"/><category scheme="http://www.blogger.com/atom/ns#" term="Web"/><title type='text'>Two Servlet Filters Every Web Application Should Have</title><content type='html'>Almost every single web application you will ever make will seriously benefit from using servlet filters to both cache and compress content.&lt;br /&gt;
&lt;br /&gt;
A caching filter optimizes the time it takes to send back a response from your web server, and a compression filter optimizes the size of the content that you send from your web server to a user via the Internet.&lt;br /&gt;
&lt;br /&gt;
Since generating content and sending content over the World Wide Web are the bread and butter of web applications, it should be no surprise that simple components that aid in these processes are incredibly useful.&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
This article details the process of building and using a caching filter and a compression filter that are suitable for use with just about any web application. After reading this article, you will understand caching and compressing, have code to do both, and be able to apply caching and compression to any of your future (or existing!) web applications.&lt;br /&gt;
&lt;br /&gt;
Find more at &lt;a href=&quot;http://onjava.com/pub/a/onjava/2003/11/19/filters.html?page=1&quot; target=&quot;_blank&quot;&gt;Two Servlet Filters Every Web Application Should Have - O&#39;Reilly Media&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all();
SyntaxHighlighter.highlight();
&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://tech-annex.blogspot.com/feeds/7510657774699430383/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://tech-annex.blogspot.com/2011/04/two-servlet-filters-every-web.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/7510657774699430383'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/7510657774699430383'/><link rel='alternate' type='text/html' href='http://tech-annex.blogspot.com/2011/04/two-servlet-filters-every-web.html' title='Two Servlet Filters Every Web Application Should Have'/><author><name>Tejas Purohit</name><uri>http://www.blogger.com/profile/12572963277655039205</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj61LMQasMba7t1nDNHcF4TA4oB53ydZQB2Zx9lwPBGzjTlaggkPx165DSyYg0Nvvo6Mqqk6o6oopUoGfgVbHXNbX1DuPhAG4IdXARNW-6O5dfec4YXDD5fay8u7mLdtNnC15WhkWCFuEaKypXRBXtrTfsSskw6ODSrVScbALtLa7aEhA/s220/IMG_4680.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2679601544275098679.post-1225984690379537630</id><published>2011-04-26T02:29:00.000+05:30</published><updated>2015-03-17T21:46:57.485+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Technical"/><category scheme="http://www.blogger.com/atom/ns#" term="XALAN"/><category scheme="http://www.blogger.com/atom/ns#" term="XALAN-JAVA"/><category scheme="http://www.blogger.com/atom/ns#" term="XML"/><category scheme="http://www.blogger.com/atom/ns#" term="XSLT"/><title type='text'>Xalan-Java Version 2.7.1 Extensions - Redirect</title><content type='html'>&lt;strong&gt;Xalan-Java Version 2.7.1 Extensions:&lt;/strong&gt; Extension elements and functions provide a powerful mechanism for extending and simplifying what you can do with an XLST processor like Xalan. With input and contributions from the XML open-source developer community, we are working on placing the most useful extensions in an extensions library distributed with Xalan-Java.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Redirect Extension:&lt;/strong&gt; A standard XSL transformation involves an XSL stylesheet, an XML source tree, and the transformation result tree. The transformation sends the entire result to a single &lt;a title=&quot; javax.xml.transform.Result&quot; href=&quot;http://xml.apache.org/xalan-j/apidocs/javax/xml/transform/Result.html&quot; target=&quot;_blank&quot;&gt;javax.xml.transform.Result&lt;/a&gt; object.&lt;br /&gt;
&lt;br /&gt;
The namespace for the Redirect extension is: &lt;code&gt;http://xml.apache.org/xalan/redirect&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
It supplies three extension elements that you can use to redirect portions of your transformation output to multiple files: &lt;code&gt;&amp;lt;open&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;write&amp;gt;&lt;/code&gt;, and &lt;code&gt;&amp;lt;close&amp;gt;&lt;/code&gt;. If you use the &lt;code&gt;&amp;lt;write&amp;gt;&lt;/code&gt; element alone, the extension opens a file, writes to it, and closes the file immediately. If you want explicit control over the opening and closing of files, use &lt;code&gt;&amp;lt;write&amp;gt;&lt;/code&gt; in conjunction with the &lt;code&gt;&amp;lt;open&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;close&amp;gt;&lt;/code&gt; elements.&lt;br /&gt;
&lt;br /&gt;
The &lt;code&gt;&amp;lt;open&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;write&amp;gt;&lt;/code&gt; elements include a file attribute and/or a select attribute to designate the output file. The file attribute takes a string, so you can use it to directly specify the output file name. The select attribute takes an XPath expression, so you can use it to dynamically generate the output file name. If you include both attributes, the Redirect extension first evaluates the select attribute, and falls back to the file attribute if the select attribute expression does not return a valid file name.&lt;br /&gt;
&lt;br /&gt;
The &lt;code&gt;&amp;lt;open&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;write&amp;gt;&lt;/code&gt; elements also support an append attribute. If the append attribute is set to true or yes, then the result is appended to the output file.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Simple Example of using Redirect extension with XSLT:&lt;/b&gt;&lt;br /&gt;
I have a XML file which contains some set of XML elements as shown in Source.XML below. My requirement is, I want to move all &lt;code&gt;&amp;lt;REF1&amp;gt;&lt;/code&gt; elements to file &lt;em&gt;REF1.XML&lt;/em&gt;, all &lt;code&gt;&amp;lt;REF2&amp;gt;&lt;/code&gt; elements to &lt;em&gt;REF2.XML&lt;/em&gt; and so on.&lt;br /&gt;
&lt;br /&gt;
A simple XSLT using Redirect extension from Xalan can do the trick as shown in &lt;em&gt;MultiRedirect.XSL&lt;/em&gt;. I am selecting all &lt;code&gt;&amp;lt;REF1&amp;gt;&lt;/code&gt; elements and copying it to &lt;em&gt;REF1.XML&lt;/em&gt; using Redirect extension and Similar for all &lt;code&gt;&amp;lt;REF2&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;REF3&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;REF4&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;REF5&amp;gt;&lt;/code&gt; elements. On XSLT transformation of &lt;em&gt;Source.XML&lt;/em&gt; by &lt;em&gt;MultiRedirect.XSL&lt;/em&gt; will create five new XML files like &lt;em&gt;REF1.XML&lt;/em&gt;, &lt;em&gt;REF2.XML&lt;/em&gt;, &lt;em&gt;REF3.XML&lt;/em&gt;, &lt;em&gt;REF4.XML&lt;/em&gt; and &lt;em&gt;REF5.XML&lt;/em&gt; as shown below.&lt;br /&gt;
&lt;br /&gt;
Before running this example you should have Xalan-J 2.7.1 available to program. I mean you should have Xalan-J 2.7.1 downloaded and set on CLASSPATH. Refer Bibliography for downloads and other references of Xalan-J 2.7.1&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Source.XML&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&#39;brush:xml;&#39;&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;ISO-8859-1&amp;quot;?&amp;gt;
&amp;lt;Invoice&amp;gt;
 &amp;lt;InvoiceHeader&amp;gt;
  
  &amp;lt;!-- Gruop of Ref1 Elements to go in file REF1.XML --&amp;gt;
  &amp;lt;Ref1 code=&amp;quot;1&amp;quot;&amp;gt;
   &amp;lt;text&amp;gt;Reference Text 1&amp;lt;/text&amp;gt;
  &amp;lt;/Ref1&amp;gt;
  &amp;lt;Ref1 code=&amp;quot;1&amp;quot;&amp;gt;
   &amp;lt;text&amp;gt;Reference Text 2&amp;lt;/text&amp;gt;
  &amp;lt;/Ref1&amp;gt;

  &amp;lt;!-- Gruop of Ref2 Elements to go in file REF2.XML --&amp;gt;
  &amp;lt;Ref2 code=&amp;quot;2&amp;quot;&amp;gt;
   &amp;lt;text&amp;gt;Reference Text 1&amp;lt;/text&amp;gt;
  &amp;lt;/Ref2&amp;gt;
  &amp;lt;Ref2 code=&amp;quot;2&amp;quot;&amp;gt;
   &amp;lt;text&amp;gt;Reference Text 2&amp;lt;/text&amp;gt;
  &amp;lt;/Ref2&amp;gt;

 &amp;lt;/InvoiceHeader&amp;gt;
&amp;lt;/Invoice&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;MultiRedirect.XSL&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&#39;brush:xml;&#39;&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;
&amp;lt;xsl:stylesheet version=&amp;quot;1.0&amp;quot;
 xmlns:xsl=&amp;quot;http://www.w3.org/1999/XSL/Transform&amp;quot; xmlns:redirect=&amp;quot;http://xml.apache.org/xalan/redirect&amp;quot;
 extension-element-prefixes=&amp;quot;redirect&amp;quot;&amp;gt;
 &amp;lt;xsl:variable name=&amp;quot;REF1&amp;quot; select=&amp;quot;&#39;REF1.XML&#39;&amp;quot; /&amp;gt;
 &amp;lt;xsl:variable name=&amp;quot;REF2&amp;quot; select=&amp;quot;&#39;REF2.XML&#39;&amp;quot; /&amp;gt;
 &amp;lt;xsl:template match=&amp;quot;/&amp;quot;&amp;gt;
 
  &amp;lt;!-- Redirecting REF1 Elementns to REF1.XML --&amp;gt;
  &amp;lt;redirect:open select=&amp;quot;$REF1&amp;quot; /&amp;gt;
  &amp;lt;redirect:write select=&amp;quot;$REF1&amp;quot;&amp;gt;
   &amp;lt;Invoice&amp;gt;
    &amp;lt;InvoiceHeader&amp;gt;
     &amp;lt;xsl:copy-of select=&amp;quot;Invoice/InvoiceHeader/Ref1&amp;quot; /&amp;gt;
    &amp;lt;/InvoiceHeader&amp;gt;
   &amp;lt;/Invoice&amp;gt;
  &amp;lt;/redirect:write&amp;gt;
  &amp;lt;redirect:close select=&amp;quot;$REF1&amp;quot; /&amp;gt;
  
  &amp;lt;!-- Redirecting REF2 Elementns to REF2.XML --&amp;gt;
  &amp;lt;redirect:open select=&amp;quot;$REF2&amp;quot; /&amp;gt;
  &amp;lt;redirect:write select=&amp;quot;$REF2&amp;quot;&amp;gt;
   &amp;lt;Invoice&amp;gt;
    &amp;lt;InvoiceHeader&amp;gt;
     &amp;lt;xsl:copy-of select=&amp;quot;Invoice/InvoiceHeader/Ref2&amp;quot; /&amp;gt;
    &amp;lt;/InvoiceHeader&amp;gt;
   &amp;lt;/Invoice&amp;gt;
  &amp;lt;/redirect:write&amp;gt;
  &amp;lt;redirect:close select=&amp;quot;$REF2&amp;quot; /&amp;gt;
  
 &amp;lt;/xsl:template&amp;gt;
&amp;lt;/xsl:stylesheet&amp;gt;&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;REF1.XML&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&#39;brush:xml;&#39;&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;
&amp;lt;Invoice&amp;gt;
 &amp;lt;InvoiceHeader&amp;gt;
  &amp;lt;Ref1 code=&amp;quot;1&amp;quot;&amp;gt;
   &amp;lt;text&amp;gt;Reference Text 1&amp;lt;/text&amp;gt;
  &amp;lt;/Ref1&amp;gt;
  &amp;lt;Ref1 code=&amp;quot;1&amp;quot;&amp;gt;
   &amp;lt;text&amp;gt;Reference Text 2&amp;lt;/text&amp;gt;
  &amp;lt;/Ref1&amp;gt;
 &amp;lt;/InvoiceHeader&amp;gt;
&amp;lt;/Invoice&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;REF2.XML&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&#39;brush:xml;&#39;&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;
&amp;lt;Invoice&amp;gt;
 &amp;lt;InvoiceHeader&amp;gt;
  &amp;lt;Ref2 code=&amp;quot;2&amp;quot;&amp;gt;
   &amp;lt;text&amp;gt;Reference Text 1&amp;lt;/text&amp;gt;
  &amp;lt;/Ref2&amp;gt;
  &amp;lt;Ref2 code=&amp;quot;2&amp;quot;&amp;gt;
   &amp;lt;text&amp;gt;Reference Text 2&amp;lt;/text&amp;gt;
  &amp;lt;/Ref2&amp;gt;
 &amp;lt;/InvoiceHeader&amp;gt;
&amp;lt;/Invoice&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;Bibliography:&lt;/b&gt;&lt;br /&gt;
&lt;a title=&quot;Apache Organization&quot; href=&quot;http://xml.apache.org/xalan-j/&quot; target=&quot;_blank&quot;&gt;Apache Organization&lt;/a&gt;, &lt;a title=&quot;Xalan-Java Extensions&quot; href=&quot;http://xml.apache.org/xalan-j/extensions.html&quot; target=&quot;_blank&quot;&gt;Xalan-Java Extensions&lt;/a&gt;, &lt;a title=&quot;Redirect Extension&quot; href=&quot;http://xml.apache.org/xalan-j/extensionslib.html#redirect&quot; target=&quot;_blank&quot;&gt;Redirect Extension&lt;/a&gt;, &lt;a title=&quot;Example with the Redirect extension&quot; href=&quot;http://xml.apache.org/xalan-j/extensionslib.html#ex-redirect&quot; target=&quot;_blank&quot;&gt;Example with the Redirect extension&lt;/a&gt;, &lt;a title=&quot;Download Xalan-J 2.7.1&quot; href=&quot;http://xml.apache.org/xalan-j/downloads.html&quot; target=&quot;_blank&quot;&gt;Download Xalan-J 2.7.1&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all();
SyntaxHighlighter.highlight();
&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://tech-annex.blogspot.com/feeds/1225984690379537630/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://tech-annex.blogspot.com/2011/04/xalan-java-version-271-extensions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/1225984690379537630'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/1225984690379537630'/><link rel='alternate' type='text/html' href='http://tech-annex.blogspot.com/2011/04/xalan-java-version-271-extensions.html' title='Xalan-Java Version 2.7.1 Extensions - Redirect'/><author><name>Tejas Purohit</name><uri>http://www.blogger.com/profile/12572963277655039205</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj61LMQasMba7t1nDNHcF4TA4oB53ydZQB2Zx9lwPBGzjTlaggkPx165DSyYg0Nvvo6Mqqk6o6oopUoGfgVbHXNbX1DuPhAG4IdXARNW-6O5dfec4YXDD5fay8u7mLdtNnC15WhkWCFuEaKypXRBXtrTfsSskw6ODSrVScbALtLa7aEhA/s220/IMG_4680.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2679601544275098679.post-750284368099098133</id><published>2011-04-26T01:42:00.000+05:30</published><updated>2015-03-17T21:46:45.448+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Event Listeners"/><category scheme="http://www.blogger.com/atom/ns#" term="Listeners"/><category scheme="http://www.blogger.com/atom/ns#" term="Servlet"/><category scheme="http://www.blogger.com/atom/ns#" term="Servlet Context Listener"/><category scheme="http://www.blogger.com/atom/ns#" term="Technical"/><category scheme="http://www.blogger.com/atom/ns#" term="Web"/><title type='text'>implementing javax.servlet.ServletContextListener</title><content type='html'>Each web application has a ServletContext associated with it. The ServletContext object is created when the application is started and is destroyed when the application is shut down. A ServletContext has a global scope and is similar to a global variable in an application. ServletContextListener will gets notified when servlet context gets initialization and destroyed.&lt;br /&gt;
&lt;br /&gt;
A Simple example of implementing javax.servlet.ServletContextListener in your web application is shown below. You need to write one class implementing javax.servlet.ServletContextListener and it&#39;s methods. As shown below:&lt;br /&gt;
&lt;b&gt;ContextListenerIMPL.java&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;!-more--&gt;&lt;br /&gt;
&lt;pre class=&#39;brush:java;&#39;&gt;package com.test;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class ContextListenerIMPL implements ServletContextListener {

 /** Creates a new instance of ContextListenerIMPL */
 public ContextListenerIMPL() { }

 public void contextInitialized(ServletContextEvent servletContextEvent) {

  //Code which should be executed just after web application context initialized should go here.
  //This code will be executed before any filter or servlet initialized.
  System.out.println(&amp;quot;Web Application Context Initialized...&amp;quot;);

 }
 public void contextDestroyed(ServletContextEvent servletContextEvent) {

  //Code which should be executed just before web application context gets destroyed should go here.
  //This code will be executed after all filter or servlet in the web application destroyed.
  System.out.println(&amp;quot;Web Application Context destroyed...&amp;quot;);

 }

}
&lt;/pre&gt;&lt;br /&gt;
Once writting ServletContextListener for your application you need to register it in WEB.XML file of your web application. As shown in bold letters below:&lt;br /&gt;
&lt;b&gt;WEB.XML&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&#39;brush:xml;&#39;&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;
&amp;lt;web-app version=&amp;quot;2.5&amp;quot; xmlns=&amp;quot;http://java.sun.com/xml/ns/javaee&amp;quot;
 xmlns:xsi=&amp;quot;http://www.w3.org/2001/XMLSchema-instance&amp;quot;
 xsi:schemaLocation=&amp;quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&amp;quot;&amp;gt;
 . . . . . .
 &amp;lt;!-- Context Listener Config --&amp;gt;
 &amp;lt;listener&amp;gt;
  &amp;lt;listener-class&amp;gt;com.test.ContextListenerManager&amp;lt;/listener-class&amp;gt;
 &amp;lt;/listener&amp;gt;
 . . . . .
&amp;lt;/web-app&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
Other References:&lt;br /&gt;
&lt;a href=&quot;http://download.oracle.com/javaee/1.4/api/javax/servlet/ServletContextListener.html&quot; title=&quot;ServletContextListener API Docs&quot; target=&quot;_blank&quot;&gt;ServletContextListener API Docs&lt;/a&gt;, &lt;a href=&quot;http://download.oracle.com/javaee/5/tutorial/doc/bnaeo.html&quot; title=&quot;Configuring Web Applications&quot; target=&quot;_blank&quot;&gt;Configuring Web Applications&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all();
SyntaxHighlighter.highlight();
&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://tech-annex.blogspot.com/feeds/750284368099098133/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://tech-annex.blogspot.com/2011/04/implementing-javaxservletservletcontext.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/750284368099098133'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/750284368099098133'/><link rel='alternate' type='text/html' href='http://tech-annex.blogspot.com/2011/04/implementing-javaxservletservletcontext.html' title='implementing javax.servlet.ServletContextListener'/><author><name>Tejas Purohit</name><uri>http://www.blogger.com/profile/12572963277655039205</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj61LMQasMba7t1nDNHcF4TA4oB53ydZQB2Zx9lwPBGzjTlaggkPx165DSyYg0Nvvo6Mqqk6o6oopUoGfgVbHXNbX1DuPhAG4IdXARNW-6O5dfec4YXDD5fay8u7mLdtNnC15WhkWCFuEaKypXRBXtrTfsSskw6ODSrVScbALtLa7aEhA/s220/IMG_4680.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2679601544275098679.post-2208420764421318161</id><published>2011-04-26T01:11:00.000+05:30</published><updated>2015-03-17T21:46:31.385+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Computer Information"/><category scheme="http://www.blogger.com/atom/ns#" term="Hardware Information"/><category scheme="http://www.blogger.com/atom/ns#" term="OS Licensing Information"/><category scheme="http://www.blogger.com/atom/ns#" term="Software Information"/><category scheme="http://www.blogger.com/atom/ns#" term="Technical"/><category scheme="http://www.blogger.com/atom/ns#" term="WMIC"/><title type='text'>Computer Software And Hardware Information using JAVA</title><content type='html'>The example provides various information about computer hardware and software. As listed below:&lt;br /&gt;
1. OS Installation date &amp;amp; Time&lt;br /&gt;
2. OS Serial Number&lt;br /&gt;
3. Motherboard Serial Number&lt;br /&gt;
4. Processor ID&lt;br /&gt;
5. Computer Name&lt;br /&gt;
&lt;br /&gt;
The program provides information as stream of data, It is your JOB how you will extract information from stream and utilize them?&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;b&gt;Note:&lt;/b&gt;The program will work only on windows platform and on Windows XP or later OS.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;ComputerInfo.java&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&#39;brush:java;&#39;&gt;import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class ComputerInfo {

 public static void main(String[] args) {

  try {

   String[][] commands = new String[][]{
     {&amp;quot;CMD&amp;quot;, &amp;quot;/C&amp;quot;, &amp;quot;WMIC OS GET Installdate,SerialNumber&amp;quot;}, //OS Installation date &amp;amp; Time, OS Serial Number
     {&amp;quot;CMD&amp;quot;, &amp;quot;/C&amp;quot;, &amp;quot;WMIC BASEBOARD GET SerialNumber&amp;quot;}, // Motherboadrd Serial Number
     {&amp;quot;CMD&amp;quot;, &amp;quot;/C&amp;quot;, &amp;quot;WMIC CPU GET ProcessorId&amp;quot;}, // Processor ID
     {&amp;quot;CMD&amp;quot;, &amp;quot;/C&amp;quot;, &amp;quot;WMIC COMPUTERSYSTEM GET Name&amp;quot;}}; // Computer Name

   for (int i = 0; i &amp;lt; commands.length; i++) {

    String[] com = commands[i];

    Process process = Runtime.getRuntime().exec(com);

    process.getOutputStream().close(); //Closing output stream of the process

    System.out.println();
    String s = null;
    //Reading sucessful output of the command
    BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
    while ((s = reader.readLine()) != null) {
     System.out.print(s);
    }

    // Reading error if any
    reader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
    while ((s = reader.readLine()) != null) {
     System.out.print(s);
    }

   }

  } catch (IOException e) {
   e.printStackTrace(); //TODO: necessary exception handling
  }
 }
}&lt;/pre&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all();
SyntaxHighlighter.highlight();
&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://tech-annex.blogspot.com/feeds/2208420764421318161/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://tech-annex.blogspot.com/2011/04/computer-software-and-hardware.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/2208420764421318161'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/2208420764421318161'/><link rel='alternate' type='text/html' href='http://tech-annex.blogspot.com/2011/04/computer-software-and-hardware.html' title='Computer Software And Hardware Information using JAVA'/><author><name>Tejas Purohit</name><uri>http://www.blogger.com/profile/12572963277655039205</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj61LMQasMba7t1nDNHcF4TA4oB53ydZQB2Zx9lwPBGzjTlaggkPx165DSyYg0Nvvo6Mqqk6o6oopUoGfgVbHXNbX1DuPhAG4IdXARNW-6O5dfec4YXDD5fay8u7mLdtNnC15WhkWCFuEaKypXRBXtrTfsSskw6ODSrVScbALtLa7aEhA/s220/IMG_4680.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2679601544275098679.post-4306214910189460058</id><published>2011-04-26T01:05:00.000+05:30</published><updated>2015-03-17T21:46:18.594+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Technical"/><category scheme="http://www.blogger.com/atom/ns#" term="Web Service"/><category scheme="http://www.blogger.com/atom/ns#" term="Web Service Client"/><title type='text'>Invoke Web Service using basic java.net package</title><content type='html'>Below code shows sample code to invoke Web Service Using basic java.net package.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;InvokeService.java&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&#39;brush:java;&#39;&gt;import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 *
 * @author Tejas Purohit
 */
public class InvokeService {

 public InvokeService() {

 }

 public static void main(String[] args) {

  // Setting Proxy Settings If Applicable, Consider below commented code
  // if you are working behind the proxy to access any web service.
  /*
  System.setProperty(&amp;quot;proxySet&amp;quot;, &amp;quot;true&amp;quot;);
  System.setProperty(&amp;quot;http.proxyHost&amp;quot;, &amp;quot;192.168.1.100&amp;quot;);
  System.setProperty(&amp;quot;http.proxyPort&amp;quot;, &amp;quot;8080&amp;quot;);
  System.setProperty(&amp;quot;http.proxyUser&amp;quot;, &amp;quot;ProxyUser&amp;quot;);
  System.setProperty(&amp;quot;http.proxyPassword&amp;quot;, &amp;quot;ProxyPassword&amp;quot;);
   */

  // Web Service URL
  String url = &amp;quot;http://www.myapp.com/mywebservice/invoke&amp;quot;;

  // SOAPAction
  String action = &amp;quot;http://www.myapp.com/mywebservice/action&amp;quot;;

  // SOAPMessage
  String reqMessage = &amp;quot;&amp;lt;soap:Envelope xmlns:soap=&#39;http://schemas.xmlsoap.org/soap/envelope/&#39;&amp;gt;&amp;lt;soap:Body&amp;gt;&amp;lt;Request&amp;gt;&amp;lt;Emp&amp;gt;&amp;lt;EmpNo&amp;gt;10&amp;lt;/EmpNo&amp;gt;&amp;lt;EmpName&amp;gt;Tejas Purohit&amp;lt;/EmpName&amp;gt;&amp;lt;EmpDesignation&amp;gt;Developer&amp;lt;/EmpDesignation&amp;gt;&amp;lt;/Emp&amp;gt;&amp;lt;/Request&amp;gt;&amp;lt;/soap:Body&amp;gt;&amp;lt;/soap:Envelope&amp;gt;&amp;quot;;

  InvokeService invokeService = new InvokeService();

  String res = invokeService.invoke(url, reqMessage, action);

  // Displaying Response
  System.out.println(res);

 }

 public String invoke(String strURL, String soapMessage, String soapAction) {

  String resMessage = null;

  try {

   // Initializing Connection with default properties
   URL url = new URL(strURL);
   HttpURLConnection urlCon = (HttpURLConnection) url.openConnection();
   urlCon.setAllowUserInteraction(true);
   urlCon.setDoOutput(true);
   urlCon.setDoInput(true);
   urlCon.setConnectTimeout(2000); // Setting Connection Timeout
   urlCon.setReadTimeout(2000); // Setting Read Timeout
   urlCon.setRequestProperty(&amp;quot;Action&amp;quot;, soapAction); // Setting SOAP Action
   urlCon.setRequestProperty(&amp;quot;Content-Type&amp;quot;, &amp;quot;text/xml&amp;quot;); // Setting Content Type
   urlCon.connect();

   // Openoutput stream and writting SOAPRequest Message
   OutputStream out = urlCon.getOutputStream();
   out.write(soapMessage.getBytes());
   out.flush();
   out.close();

   // Reading InputStream
   InputStream dataInputStream;
   if (urlCon.getResponseCode() == HttpURLConnection.HTTP_OK) {
    dataInputStream = urlCon.getInputStream();
   } else {
    dataInputStream = urlCon.getErrorStream();
   }
   resMessage = readInputStream(dataInputStream);
   dataInputStream.close();

   // Disconnecting
   urlCon.disconnect();

  } catch (Exception ex) {

   ex.printStackTrace();

  }

  return resMessage;

 }

 private String readInputStream(InputStream in) throws IOException {

  StringBuffer sb = new StringBuffer();

  int avail = in.available();

  while (avail &amp;gt; 0) {
   byte[] availBytes = new byte[avail];
   in.read(availBytes);
   sb.append(new String(availBytes));
   avail = in.available();
  }

  return sb.toString();

 }

}
&lt;/pre&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all();
SyntaxHighlighter.highlight();
&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://tech-annex.blogspot.com/feeds/4306214910189460058/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://tech-annex.blogspot.com/2011/04/invoke-web-service-using-basic-javanet.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/4306214910189460058'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/4306214910189460058'/><link rel='alternate' type='text/html' href='http://tech-annex.blogspot.com/2011/04/invoke-web-service-using-basic-javanet.html' title='Invoke Web Service using basic java.net package'/><author><name>Tejas Purohit</name><uri>http://www.blogger.com/profile/12572963277655039205</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj61LMQasMba7t1nDNHcF4TA4oB53ydZQB2Zx9lwPBGzjTlaggkPx165DSyYg0Nvvo6Mqqk6o6oopUoGfgVbHXNbX1DuPhAG4IdXARNW-6O5dfec4YXDD5fay8u7mLdtNnC15WhkWCFuEaKypXRBXtrTfsSskw6ODSrVScbALtLa7aEhA/s220/IMG_4680.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2679601544275098679.post-5955047339796186792</id><published>2011-04-21T18:09:00.000+05:30</published><updated>2015-03-17T21:44:26.862+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="HTML"/><category scheme="http://www.blogger.com/atom/ns#" term="Technical"/><category scheme="http://www.blogger.com/atom/ns#" term="Transformation"/><category scheme="http://www.blogger.com/atom/ns#" term="XML"/><title type='text'>XML to HTML Transformation</title><content type='html'>Below example will take SourceXML.xml(Source XML Block) and HTMLStyleSheet.xsl(StyleSheet to process XML Block) as input. On transform action StyleSheet will process given XML block and store result at Employees.html file.&lt;br /&gt;
Before running the Example you need to have following files created as described.&lt;br /&gt;
&lt;br /&gt;
1. HTMLStyleSheet.xsl (given below) as input XSLT.&lt;br /&gt;
2. SourceXML.xml (given below) as input XML.&lt;br /&gt;
3. Employees.html (an blank file - to avoid FileNotFoundException while transformation) as output file.&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;SourceXML.xml&lt;/em&gt; given below will be used as input XML. It will be transformed to well formed HTML Document after transforming.&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;b&gt;SourceXML.xml&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&#39;brush:xml;&#39;&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;
&amp;lt;Employees&amp;gt;
 &amp;lt;Employee&amp;gt;
  &amp;lt;EmpId&amp;gt;1&amp;lt;/EmpId&amp;gt;
  &amp;lt;Name&amp;gt;Kapil dev&amp;lt;/Name&amp;gt;
  &amp;lt;Address1&amp;gt;Delhi&amp;lt;/Address1&amp;gt;
  &amp;lt;Address2&amp;gt;India&amp;lt;/Address2&amp;gt;
  &amp;lt;BirthDate&amp;gt;1954-05-13T00:00:00+05:30&amp;lt;/BirthDate&amp;gt;
  &amp;lt;Salary&amp;gt;500&amp;lt;/Salary&amp;gt;
 &amp;lt;/Employee&amp;gt;
 &amp;lt;Employee&amp;gt;
  &amp;lt;EmpId&amp;gt;2&amp;lt;/EmpId&amp;gt;
  &amp;lt;Name&amp;gt;Sunil Gavaskar&amp;lt;/Name&amp;gt;
  &amp;lt;Address1&amp;gt;Mumbai&amp;lt;/Address1&amp;gt;
  &amp;lt;Address2&amp;gt;India&amp;lt;/Address2&amp;gt;
  &amp;lt;BirthDate&amp;gt;1945-07-10T00:00:00+05:30&amp;lt;/BirthDate&amp;gt;
  &amp;lt;Salary&amp;gt;700&amp;lt;/Salary&amp;gt;
 &amp;lt;/Employee&amp;gt;
 &amp;lt;Employee&amp;gt;
  &amp;lt;EmpId&amp;gt;3&amp;lt;/EmpId&amp;gt;
  &amp;lt;Name&amp;gt;Alen Border&amp;lt;/Name&amp;gt;
  &amp;lt;Address1&amp;gt;Sydney&amp;lt;/Address1&amp;gt;
  &amp;lt;Address2&amp;gt;Australia&amp;lt;/Address2&amp;gt;
  &amp;lt;BirthDate&amp;gt;1950-09-25T00:00:00+05:30&amp;lt;/BirthDate&amp;gt;
  &amp;lt;Salary&amp;gt;400&amp;lt;/Salary&amp;gt;
 &amp;lt;/Employee&amp;gt;
 &amp;lt;Employee&amp;gt;
  &amp;lt;EmpId&amp;gt;4&amp;lt;/EmpId&amp;gt;
  &amp;lt;Name&amp;gt;Sachin Tendulkar&amp;lt;/Name&amp;gt;
  &amp;lt;Address1&amp;gt;Mumbai&amp;lt;/Address1&amp;gt;
  &amp;lt;Address2&amp;gt;India&amp;lt;/Address2&amp;gt;
  &amp;lt;BirthDate&amp;gt;1970-02-06T00:00:00+05:30&amp;lt;/BirthDate&amp;gt;
  &amp;lt;Salary&amp;gt;2000&amp;lt;/Salary&amp;gt;
 &amp;lt;/Employee&amp;gt;
 &amp;lt;Employee&amp;gt;
  &amp;lt;EmpId&amp;gt;5&amp;lt;/EmpId&amp;gt;
  &amp;lt;Name&amp;gt;Ricky Ponting&amp;lt;/Name&amp;gt;
  &amp;lt;Address1&amp;gt;Melbourne&amp;lt;/Address1&amp;gt;
  &amp;lt;Address2&amp;gt;Australia&amp;lt;/Address2&amp;gt;
  &amp;lt;BirthDate&amp;gt;1968-02-15T00:00:00+05:30&amp;lt;/BirthDate&amp;gt;
  &amp;lt;Salary&amp;gt;1500&amp;lt;/Salary&amp;gt;
 &amp;lt;/Employee&amp;gt;
&amp;lt;/Employees&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;em&gt;HTMLStyleSheet.xsl&lt;/em&gt; given below will be used as input XSLT. This Style Sheet will transform &lt;em&gt;SourceXML.xml&lt;/em&gt; to well formed HTML Document.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;HTMLStyleSheet.xsl&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&#39;brush:xml;&#39;&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;
&amp;lt;xsl:stylesheet version=&amp;quot;1.0&amp;quot;
 xmlns:xsl=&amp;quot;http://www.w3.org/1999/XSL/Transform&amp;quot;&amp;gt;

 &amp;lt;xsl:template match=&amp;quot;/&amp;quot;&amp;gt;
  &amp;lt;HTML&amp;gt;
   &amp;lt;BODY&amp;gt;
    &amp;lt;h1&amp;gt;
     &amp;lt;U&amp;gt;List of Employees&amp;lt;/U&amp;gt;
    &amp;lt;/h1&amp;gt;
    &amp;lt;TABLE BORDER=&amp;quot;1&amp;quot;&amp;gt;
     &amp;lt;TBODY&amp;gt;
      &amp;lt;TR&amp;gt;
       &amp;lt;TH&amp;gt;EmpId&amp;lt;/TH&amp;gt;
       &amp;lt;TH&amp;gt;Name&amp;lt;/TH&amp;gt;
       &amp;lt;TH&amp;gt;Address1&amp;lt;/TH&amp;gt;
       &amp;lt;TH&amp;gt;Address2&amp;lt;/TH&amp;gt;
       &amp;lt;TH&amp;gt;BirthDate&amp;lt;/TH&amp;gt;
       &amp;lt;TH&amp;gt;Salary&amp;lt;/TH&amp;gt;
      &amp;lt;/TR&amp;gt;
      &amp;lt;xsl:for-each select=&amp;quot;Employees&amp;quot;&amp;gt;
       &amp;lt;xsl:for-each select=&amp;quot;Employee&amp;quot;&amp;gt;
        &amp;lt;TR&amp;gt;
         &amp;lt;TD&amp;gt;
          &amp;lt;xsl:value-of select=&amp;quot;EmpId&amp;quot; /&amp;gt;
         &amp;lt;/TD&amp;gt;
         &amp;lt;TD&amp;gt;
          &amp;lt;xsl:value-of select=&amp;quot;Name&amp;quot; /&amp;gt;
         &amp;lt;/TD&amp;gt;
         &amp;lt;TD&amp;gt;
          &amp;lt;xsl:value-of select=&amp;quot;Address1&amp;quot; /&amp;gt;
         &amp;lt;/TD&amp;gt;
         &amp;lt;TD&amp;gt;
          &amp;lt;xsl:value-of select=&amp;quot;Address2&amp;quot; /&amp;gt;
         &amp;lt;/TD&amp;gt;
         &amp;lt;TD&amp;gt;
          &amp;lt;xsl:value-of select=&amp;quot;BirthDate&amp;quot; /&amp;gt;
         &amp;lt;/TD&amp;gt;
         &amp;lt;TD&amp;gt;
          &amp;lt;xsl:value-of select=&amp;quot;Salary&amp;quot; /&amp;gt;
         &amp;lt;/TD&amp;gt;
        &amp;lt;/TR&amp;gt;
       &amp;lt;/xsl:for-each&amp;gt;
      &amp;lt;/xsl:for-each&amp;gt;
     &amp;lt;/TBODY&amp;gt;
    &amp;lt;/TABLE&amp;gt;
   &amp;lt;/BODY&amp;gt;
  &amp;lt;/HTML&amp;gt;
 &amp;lt;/xsl:template&amp;gt;
&amp;lt;/xsl:stylesheet&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
XmlToHtmlTransformation class contains transform method will accept source xml, source style sheet and output file. It will transform given source xml using style sheet and store result in output file. output file is Employees.html in our case.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;XmlToHtmlTransformation.java&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&#39;brush:java;&#39;&gt;import java.io.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

/**
 *
 * @author Tejas Purohit
 */
public class XmlToHtmlTransformation {

 public boolean transform(String stylesheet, String sourceXML, String result) {

  try {

   // Creating Transformer with XSLT
   Source sourceXSLT = new StreamSource(new FileInputStream(stylesheet));
   TransformerFactory tFactory = TransformerFactory.newInstance();
   Transformer transformer = tFactory.newTransformer(sourceXSLT);

   // Creating StreamSource with sourceXML
   Source streamSource = new StreamSource(new FileInputStream(sourceXML));
   
   // Creating StreamResult with result
   Result streamResult = new StreamResult(new FileOutputStream(result)); 

   transformer.transform(streamSource, streamResult); // Transforming

  } catch (Exception exception) {

   exception.printStackTrace();

   return false;

  }

  return true;
 }

 public static void main(String[] args) {

  XmlToHtmlTransformation xhTransformation = new XmlToHtmlTransformation();

  String stylesheet = &amp;quot;HTMLStyleSheet.xsl&amp;quot;;
  String sourceXML = &amp;quot;SourceXML.xml&amp;quot;;
  String result = &amp;quot;Employees.html&amp;quot;;

  if (xhTransformation.transform(stylesheet, sourceXML, result)) {
   System.out.println(&amp;quot;Successful.&amp;quot;);
  } else {
   System.out.println(&amp;quot;Error.&amp;quot;);
  }
 }
}
&lt;/pre&gt;&lt;br /&gt;
Transformation process will generate result HTML and store in Employees.html. Once Transformation is done Employees.html will look like below:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Employees.html&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&#39;brush:html;&#39;&gt;&amp;lt;HTML&amp;gt;
 &amp;lt;BODY&amp;gt;
  &amp;lt;h1&amp;gt;
   &amp;lt;U&amp;gt;List of Employees&amp;lt;/U&amp;gt;
  &amp;lt;/h1&amp;gt;
  &amp;lt;TABLE BORDER=&amp;quot;1&amp;quot;&amp;gt;
   &amp;lt;TBODY&amp;gt;
    &amp;lt;TR&amp;gt;
     &amp;lt;TH&amp;gt;EmpId&amp;lt;/TH&amp;gt;
     &amp;lt;TH&amp;gt;Name&amp;lt;/TH&amp;gt;
     &amp;lt;TH&amp;gt;Address1&amp;lt;/TH&amp;gt;
     &amp;lt;TH&amp;gt;Address2&amp;lt;/TH&amp;gt;
     &amp;lt;TH&amp;gt;BirthDate&amp;lt;/TH&amp;gt;
     &amp;lt;TH&amp;gt;Salary&amp;lt;/TH&amp;gt;
    &amp;lt;/TR&amp;gt;
    &amp;lt;TR&amp;gt;
     &amp;lt;TD&amp;gt;1&amp;lt;/TD&amp;gt;
     &amp;lt;TD&amp;gt;Kapil dev&amp;lt;/TD&amp;gt;
     &amp;lt;TD&amp;gt;Delhi&amp;lt;/TD&amp;gt;
     &amp;lt;TD&amp;gt;India&amp;lt;/TD&amp;gt;
     &amp;lt;TD&amp;gt;1954-05-13T00:00:00+05:30&amp;lt;/TD&amp;gt;
     &amp;lt;TD&amp;gt;500&amp;lt;/TD&amp;gt;
    &amp;lt;/TR&amp;gt;
    &amp;lt;TR&amp;gt;
     &amp;lt;TD&amp;gt;2&amp;lt;/TD&amp;gt;
     &amp;lt;TD&amp;gt;Sunil Gavaskar&amp;lt;/TD&amp;gt;
     &amp;lt;TD&amp;gt;Mumbai&amp;lt;/TD&amp;gt;
     &amp;lt;TD&amp;gt;India&amp;lt;/TD&amp;gt;
     &amp;lt;TD&amp;gt;1945-07-10T00:00:00+05:30&amp;lt;/TD&amp;gt;
     &amp;lt;TD&amp;gt;700&amp;lt;/TD&amp;gt;
    &amp;lt;/TR&amp;gt;
    &amp;lt;TR&amp;gt;
     &amp;lt;TD&amp;gt;3&amp;lt;/TD&amp;gt;
     &amp;lt;TD&amp;gt;Alen Border&amp;lt;/TD&amp;gt;
     &amp;lt;TD&amp;gt;Sydney&amp;lt;/TD&amp;gt;
     &amp;lt;TD&amp;gt;Australia&amp;lt;/TD&amp;gt;
     &amp;lt;TD&amp;gt;1950-09-25T00:00:00+05:30&amp;lt;/TD&amp;gt;
     &amp;lt;TD&amp;gt;400&amp;lt;/TD&amp;gt;
    &amp;lt;/TR&amp;gt;
    &amp;lt;TR&amp;gt;
     &amp;lt;TD&amp;gt;4&amp;lt;/TD&amp;gt;
     &amp;lt;TD&amp;gt;Sachin Tendulkar&amp;lt;/TD&amp;gt;
     &amp;lt;TD&amp;gt;Mumbai&amp;lt;/TD&amp;gt;
     &amp;lt;TD&amp;gt;India&amp;lt;/TD&amp;gt;
     &amp;lt;TD&amp;gt;1970-02-06T00:00:00+05:30&amp;lt;/TD&amp;gt;
     &amp;lt;TD&amp;gt;2000&amp;lt;/TD&amp;gt;
    &amp;lt;/TR&amp;gt;
    &amp;lt;TR&amp;gt;
     &amp;lt;TD&amp;gt;5&amp;lt;/TD&amp;gt;
     &amp;lt;TD&amp;gt;Ricky Ponting&amp;lt;/TD&amp;gt;
     &amp;lt;TD&amp;gt;Melbourne&amp;lt;/TD&amp;gt;
     &amp;lt;TD&amp;gt;Australia&amp;lt;/TD&amp;gt;
     &amp;lt;TD&amp;gt;1968-02-15T00:00:00+05:30&amp;lt;/TD&amp;gt;
     &amp;lt;TD&amp;gt;1500&amp;lt;/TD&amp;gt;
    &amp;lt;/TR&amp;gt;
   &amp;lt;/TBODY&amp;gt;
  &amp;lt;/TABLE&amp;gt;
 &amp;lt;/BODY&amp;gt;
&amp;lt;/HTML&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
Which generates html output as below:&lt;br /&gt;
&lt;h1&gt;&lt;u&gt;List of Employees&lt;/U&gt;&lt;br /&gt;
&lt;/h1&gt;&lt;table BORDER=&quot;1&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;                     &lt;th&gt;EmpId&lt;/TH&gt;&lt;th&gt;Name&lt;/TH&gt;&lt;th&gt;Address1&lt;/TH&gt;&lt;th&gt;Address2&lt;/TH&gt;&lt;th&gt;BirthDate&lt;/TH&gt;&lt;th&gt;Salary&lt;/TH&gt;                 &lt;/TR&gt;
&lt;tr&gt;                     &lt;td&gt;1&lt;/TD&gt;&lt;td&gt;Kapil dev&lt;/TD&gt;&lt;td&gt;Delhi&lt;/TD&gt;&lt;td&gt;India&lt;/TD&gt;&lt;td&gt;1954-05-13T00:00:00+05:30&lt;/TD&gt;&lt;td&gt;500&lt;/TD&gt;                 &lt;/TR&gt;
&lt;tr&gt;                     &lt;td&gt;2&lt;/TD&gt;&lt;td&gt;Sunil Gavaskar&lt;/TD&gt;&lt;td&gt;Mumbai&lt;/TD&gt;&lt;td&gt;India&lt;/TD&gt;&lt;td&gt;1945-07-10T00:00:00+05:30&lt;/TD&gt;&lt;td&gt;700&lt;/TD&gt;                 &lt;/TR&gt;
&lt;tr&gt;                     &lt;td&gt;3&lt;/TD&gt;&lt;td&gt;Alen Border&lt;/TD&gt;&lt;td&gt;Sydney&lt;/TD&gt;&lt;td&gt;Australia&lt;/TD&gt;&lt;td&gt;1950-09-25T00:00:00+05:30&lt;/TD&gt;&lt;td&gt;400&lt;/TD&gt;                 &lt;/TR&gt;
&lt;tr&gt;                     &lt;td&gt;4&lt;/TD&gt;&lt;td&gt;Sachin Tendulkar&lt;/TD&gt;&lt;td&gt;Mumbai&lt;/TD&gt;&lt;td&gt;India&lt;/TD&gt;&lt;td&gt;1970-02-06T00:00:00+05:30&lt;/TD&gt;&lt;td&gt;2000&lt;/TD&gt;                 &lt;/TR&gt;
&lt;tr&gt;                     &lt;td&gt;5&lt;/TD&gt;&lt;td&gt;Ricky Ponting&lt;/TD&gt;&lt;td&gt;Melbourne&lt;/TD&gt;&lt;td&gt;Australia&lt;/TD&gt;&lt;td&gt;1968-02-15T00:00:00+05:30&lt;/TD&gt;&lt;td&gt;1500&lt;/TD&gt;                 &lt;/TR&gt;
&lt;/TBODY&gt;         &lt;/TABLE&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all();
SyntaxHighlighter.highlight();
&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://tech-annex.blogspot.com/feeds/5955047339796186792/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://tech-annex.blogspot.com/2011/04/xml-to-html-transformation.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/5955047339796186792'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/5955047339796186792'/><link rel='alternate' type='text/html' href='http://tech-annex.blogspot.com/2011/04/xml-to-html-transformation.html' title='XML to HTML Transformation'/><author><name>Tejas Purohit</name><uri>http://www.blogger.com/profile/12572963277655039205</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj61LMQasMba7t1nDNHcF4TA4oB53ydZQB2Zx9lwPBGzjTlaggkPx165DSyYg0Nvvo6Mqqk6o6oopUoGfgVbHXNbX1DuPhAG4IdXARNW-6O5dfec4YXDD5fay8u7mLdtNnC15WhkWCFuEaKypXRBXtrTfsSskw6ODSrVScbALtLa7aEhA/s220/IMG_4680.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2679601544275098679.post-5226767376248581715</id><published>2011-04-21T17:53:00.000+05:30</published><updated>2015-03-17T21:44:05.397+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Indent XML"/><category scheme="http://www.blogger.com/atom/ns#" term="Organize XML"/><category scheme="http://www.blogger.com/atom/ns#" term="Technical"/><category scheme="http://www.blogger.com/atom/ns#" term="Well-form"/><category scheme="http://www.blogger.com/atom/ns#" term="Well-form XML"/><category scheme="http://www.blogger.com/atom/ns#" term="XML"/><title type='text'>Indent,Organize or Well-form XML Using Java</title><content type='html'>Below Code Well form, Organize or Indent plain or unorganized XML String using XML API in JDK 6.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;IndentXML.java&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&#39;brush:java;&#39;&gt;import com.actl.dxchange.utilities.XMLUtil;
import java.io.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.w3c.dom.*;

/**
 * XMLTransformations Utilities.
 * @author Tejas Purohit
 */
public class IndentXML {

 public IndentXML() {

 }

 public static void main(String[] args) throws Exception {

  IndentXML t = new IndentXML();

  String strXML = &amp;quot;&amp;lt;Employees&amp;gt;&amp;lt;Employee Name=&#39;Amitabh Bachapan&#39; Designation=&#39;Director&#39;&amp;gt;&amp;quot;+
    &amp;quot;&amp;lt;Address&amp;gt;&amp;lt;AddressLine&amp;gt;Opp. Taj Square&amp;lt;/AddressLine&amp;gt;&amp;lt;City&amp;gt;Mumbai&amp;lt;/City&amp;gt;&amp;quot;+
    &amp;quot;&amp;lt;Country&amp;gt;India&amp;lt;/Country&amp;gt;&amp;lt;/Address&amp;gt;&amp;lt;/Employee&amp;gt;&amp;lt;Employee Name=&#39;Shah RukRukKhan&#39;&amp;quot;+
    &amp;quot; Designation=&#39;Manager&#39;&amp;gt;&amp;lt;Address&amp;gt;&amp;lt;AddressLine&amp;gt;Behind Chandani Choak&amp;lt;/AddressLine&amp;gt;&amp;quot;+
    &amp;quot;&amp;lt;City&amp;gt;Delhi&amp;lt;/City&amp;gt;&amp;lt;Country&amp;gt;India&amp;lt;/Country&amp;gt;&amp;lt;/Address&amp;gt;&amp;lt;/Employee&amp;gt;&amp;lt;/Employees&amp;gt;&amp;quot;;

  System.out.println(&amp;quot;Plain XML:&amp;quot;);
  System.out.println(strXML); // Print Plain XML

  strXML = t.indentXML(strXML); // Indent XML

  System.out.println(&amp;quot;Organized XML:&amp;quot;); // Print Organized/Indented XML
  System.out.println(strXML);

 }

 /**
  * Indent given XML String and returns organized String.
  * @param strXML Plain XML String
  * @return Organized or indented String
  */
 public String indentXML(String strXML) {

  String result = null;

  try {

   // Creating StreamSource from given plain XML String
   ByteArrayInputStream bin = new ByteArrayInputStream(strXML.getBytes());
   StreamSource streamSource = new StreamSource(bin);
   streamSource.setSystemId(&amp;quot;http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd&amp;quot;);

   // Creating new Transformer
   TransformerFactory transFactory = TransformerFactory.newInstance();
   Transformer transformer = transFactory.newTransformer();

   // Setting output properties
   transformer.setOutputProperty(OutputKeys.METHOD, &amp;quot;xml&amp;quot;);
   transformer.setOutputProperty(OutputKeys.ENCODING, &amp;quot;utf-8&amp;quot;);
   transformer.setOutputProperty(&amp;quot;{http://xml.apache.org/xslt}indent-amount&amp;quot;, &amp;quot;5&amp;quot;);
   transformer.setOutputProperty(OutputKeys.INDENT, &amp;quot;yes&amp;quot;);
   transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, &amp;quot;yes&amp;quot;);
   transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, &amp;quot;http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd&amp;quot;);
   transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, &amp;quot;-//W3C//DTD XHTML 1.1//EN&amp;quot;);


   // Creating StreamResult
   ByteArrayOutputStream bout = new ByteArrayOutputStream();
   StreamResult streamResult = new StreamResult(bout);
   streamResult.setSystemId(&amp;quot;http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd&amp;quot;);

   // Transforming StreamSource and storing result in StreamResult
   transformer.transform(streamSource, streamResult);

   // Getting String from ByteArrayOutputStream
   result = bout.toString();

  } catch (Exception ex) {

   ex.printStackTrace();

  }

  return result;

 }

}&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;Plain XML output will be like:&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&#39;brush:xml;&#39;&gt;&amp;lt;Employees&amp;gt;&amp;lt;Employee Name=&#39;Amitabh Bachapan&#39; Designation=&#39;Director&#39;&amp;gt;&amp;lt;Address&amp;gt;&amp;lt;AddressLine&amp;gt;Opp. Taj Square&amp;lt;/AddressLine&amp;gt;&amp;lt;City&amp;gt;Mumbai&amp;lt;/City&amp;gt;&amp;lt;Country&amp;gt;India&amp;lt;/Country&amp;gt;&amp;lt;/Address&amp;gt;&amp;lt;/Employee&amp;gt;&amp;lt;Employee Name=&#39;Shah RukRukKhan&#39; Designation=&#39;Manager&#39;&amp;gt;&amp;lt;Address&amp;gt;&amp;lt;AddressLine&amp;gt;Behind Chandani Choak&amp;lt;/AddressLine&amp;gt;&amp;lt;City&amp;gt;Delhi&amp;lt;/City&amp;gt;&amp;lt;Country&amp;gt;India&amp;lt;/Country&amp;gt;&amp;lt;/Address&amp;gt;&amp;lt;/Employee&amp;gt;&amp;lt;/Employees&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;Well formed/Organized/Indented XML output will like:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;pre class=&#39;brush:xml;&#39;&gt;&amp;lt;!DOCTYPE Employees PUBLIC &amp;quot;-//W3C//DTD XHTML 1.1//EN&amp;quot; &amp;quot;http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd&amp;quot;&amp;gt;
&amp;lt;Employees&amp;gt;
 &amp;lt;Employee Name=&amp;quot;Amitabh Bachapan&amp;quot; Designation=&amp;quot;Director&amp;quot;&amp;gt;
  &amp;lt;Address&amp;gt;
   &amp;lt;AddressLine&amp;gt;Opp. Taj Square&amp;lt;/AddressLine&amp;gt;
   &amp;lt;City&amp;gt;Mumbai&amp;lt;/City&amp;gt;
   &amp;lt;Country&amp;gt;India&amp;lt;/Country&amp;gt;
  &amp;lt;/Address&amp;gt;
 &amp;lt;/Employee&amp;gt;
 &amp;lt;Employee Name=&amp;quot;Shah RukRukKhan&amp;quot; Designation=&amp;quot;Manager&amp;quot;&amp;gt;
  &amp;lt;Address&amp;gt;
   &amp;lt;AddressLine&amp;gt;Behind Chandani Choak&amp;lt;/AddressLine&amp;gt;
   &amp;lt;City&amp;gt;Delhi&amp;lt;/City&amp;gt;
   &amp;lt;Country&amp;gt;India&amp;lt;/Country&amp;gt;
  &amp;lt;/Address&amp;gt;
 &amp;lt;/Employee&amp;gt;
&amp;lt;/Employees&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all();
SyntaxHighlighter.highlight();
&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://tech-annex.blogspot.com/feeds/5226767376248581715/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://tech-annex.blogspot.com/2011/04/indentorganize-or-well-form-xml-using.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/5226767376248581715'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/5226767376248581715'/><link rel='alternate' type='text/html' href='http://tech-annex.blogspot.com/2011/04/indentorganize-or-well-form-xml-using.html' title='Indent,Organize or Well-form XML Using Java'/><author><name>Tejas Purohit</name><uri>http://www.blogger.com/profile/12572963277655039205</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj61LMQasMba7t1nDNHcF4TA4oB53ydZQB2Zx9lwPBGzjTlaggkPx165DSyYg0Nvvo6Mqqk6o6oopUoGfgVbHXNbX1DuPhAG4IdXARNW-6O5dfec4YXDD5fay8u7mLdtNnC15WhkWCFuEaKypXRBXtrTfsSskw6ODSrVScbALtLa7aEhA/s220/IMG_4680.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2679601544275098679.post-8709798154104953090</id><published>2011-04-21T02:39:00.000+05:30</published><updated>2015-03-17T21:43:51.064+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Garbage Collection"/><category scheme="http://www.blogger.com/atom/ns#" term="HTML"/><category scheme="http://www.blogger.com/atom/ns#" term="Javascript"/><category scheme="http://www.blogger.com/atom/ns#" term="Technical"/><title type='text'>Garbage Collection in JavaScript</title><content type='html'>Rich application development now a days includes wast use of JavaScript and Ajax. Latest web browsers are developed to handle such interactive web applications. All data which Ajax imports from server is stored in web browser memory cache. Larger amount of data stored in web browser cache may slow down performance of web browser. One way to release memory from web browser cache or applying garbage collection is to close the browser. But web application can&#39;t use this practice to close browser or tell user to restart web browser while web application application is running.&lt;br /&gt;
&lt;br /&gt;
You can force/implement garbage collection in JavaScript. Web developers should develop practice to force garbage collection contentiously while web application is running.&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;em&gt;delete &lt;/em&gt;operator is one of the most unknown and unused operators in JavaScript. You can use &lt;em&gt;delete &lt;/em&gt;operator to release memory occupied by any unused or unreferenced objects in JavaScript. While deleting any object be sure you don&#39;t have any reference stored in any other variables for particular object. This will lead performance breakdown when these other variable will try to access the object which was deleted. You can delete any object which has performed it&#39;s job and is not going to be used in future.&lt;br /&gt;
&lt;br /&gt;
For example, You can delete window onload handler function and release any memory associated with the function, like this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&#39;brush:js;&#39;&gt;var winLoadFun = function(){
    
        // code for my function
        delete winLoadFun;
    }

    window.addEventListener(&#39;load&#39;, winLoadFun , false);

&lt;/pre&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all();
SyntaxHighlighter.highlight();
&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://tech-annex.blogspot.com/feeds/8709798154104953090/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://tech-annex.blogspot.com/2011/04/garbage-collection-in-javascript.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/8709798154104953090'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/8709798154104953090'/><link rel='alternate' type='text/html' href='http://tech-annex.blogspot.com/2011/04/garbage-collection-in-javascript.html' title='Garbage Collection in JavaScript'/><author><name>Tejas Purohit</name><uri>http://www.blogger.com/profile/12572963277655039205</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj61LMQasMba7t1nDNHcF4TA4oB53ydZQB2Zx9lwPBGzjTlaggkPx165DSyYg0Nvvo6Mqqk6o6oopUoGfgVbHXNbX1DuPhAG4IdXARNW-6O5dfec4YXDD5fay8u7mLdtNnC15WhkWCFuEaKypXRBXtrTfsSskw6ODSrVScbALtLa7aEhA/s220/IMG_4680.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2679601544275098679.post-8285724006009611193</id><published>2011-04-21T02:32:00.000+05:30</published><updated>2015-03-17T21:43:03.920+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Technical"/><category scheme="http://www.blogger.com/atom/ns#" term="Transformation"/><category scheme="http://www.blogger.com/atom/ns#" term="XML"/><title type='text'>XML Transformations in Java</title><content type='html'>Java provides very robust API for XML Processing. Transforming XML String to org.w3c.dom.Document and vise versa is very simple. XMLTransformations.java given below is written using JDK6. Method getDocumentAsString transforms org.w3c.dom.Document to plain String.Method getStringAsDocument transforms plain String to org.w3c.dom.Document.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;XMLTransformations.java&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&#39;brush:java;&#39;&gt;import java.io.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.*;
import org.xml.sax.InputSource;

/**
 * XMLTransformations Utilities.
 * @author Tejas Purohit
 */
public class XMLTransformations {

 public XMLTransformations() {
 }

 /**
  * Transforms given org.w3c.dom.Document to String.
  * @param node Node to convert to String
  * @return String representation of given org.w3c.dom.Document
  */
 public String getDocumentAsString(Document doc) {

  String result = null;

  try {

   // Getting DOM Source
   DOMSource domSource = new DOMSource(doc);

   // Getting Output Stream to write result
   ByteArrayOutputStream byteOut = new ByteArrayOutputStream();

   // Getting new TransformerFactory
   TransformerFactory transformerfactory = TransformerFactory.newInstance();

   // Getting new Transformer
   Transformer transformer = transformerfactory.newTransformer();

   // Transforms DOMSource to StreamResult
   transformer.transform(domSource, new StreamResult(byteOut));

   result = byteOut.toString(); // Getting String from ByteArrayOutputStream

  } catch (Exception ex) {

   ex.printStackTrace();

  }

  return result;

 }

 /**
  * Builds org.w3c.dom.Document from given String.
  * @param strXML XML as String
  * @return org.w3c.dom.Document builded from String
  */
 public Document getStringAsDocument(String strXML) {

  Document doc = null;

  try {

   // Getting new DocumentBuilderFactory
   DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

   // Setting namespace aware to true
   factory.setNamespaceAware(true);

   // Getting new DocumentBuilder
   DocumentBuilder builder = factory.newDocumentBuilder();

   // Parsing String to Document
   doc = builder.parse(new InputSource(new StringReader(strXML)));

  } catch (Exception ex) {

   ex.printStackTrace();

  }

  return doc;

 }
}
&lt;/pre&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all();
SyntaxHighlighter.highlight();
&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://tech-annex.blogspot.com/feeds/8285724006009611193/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://tech-annex.blogspot.com/2011/04/xml-transformations-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/8285724006009611193'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2679601544275098679/posts/default/8285724006009611193'/><link rel='alternate' type='text/html' href='http://tech-annex.blogspot.com/2011/04/xml-transformations-in-java.html' title='XML Transformations in Java'/><author><name>Tejas Purohit</name><uri>http://www.blogger.com/profile/12572963277655039205</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj61LMQasMba7t1nDNHcF4TA4oB53ydZQB2Zx9lwPBGzjTlaggkPx165DSyYg0Nvvo6Mqqk6o6oopUoGfgVbHXNbX1DuPhAG4IdXARNW-6O5dfec4YXDD5fay8u7mLdtNnC15WhkWCFuEaKypXRBXtrTfsSskw6ODSrVScbALtLa7aEhA/s220/IMG_4680.jpeg'/></author><thr:total>0</thr:total></entry></feed>