provide-free-support Ujjwal's Blog: 2012

Thursday, December 27, 2012

Popup in liferay using AUI

Below code is used to show a popup using AUI:


<portlet:renderURL var="somePageURL" windowState="<%= LiferayWindowState.EXCLUSIVE.toString() %>">
  <portlet:param name="jspPage" value="/jsp/some/page.jsp"/>
  <portlet:param name="redirect" value="<%= currentURL %>"/>
</portlet:renderURL>
 <script type="text/javascript">
function showPopup() {
  AUI().use('aui-dialog', 'aui-io', 'event', 'event-custom', function(A) {
    
    var dialog = new A.Dialog({
            title: 'Popup Title',
            centered: true,
            draggable: true,
            modal: true
        }).plug(A.Plugin.IO, {uri: '<%= somePageURL %>'}).render();
        
        dialog.show();
        
  });
}
Cheers, Ujjwal Soni

Create tab using AUI in liferay 6.1

You can create tabs in Liferay 6.1 using AUI as below ::

AUI().ready('aui-tabs', function(A) {
 var tabs = new A.TabView(
  {
   boundingBox: '#demo',
   items: [
    {
     content: 'This my content 1',
     label: 'Tab 1'
    },
    {
     content: 'This my content 2',
     label: 'Tab 2'
    },
    {
     content: 'This my content 3',
     label: 'Tab 3'
    }
   ]
  }
 )
 .render();
});
 
Cheers,

Ujjwal Soni 

Private Session XML Attribute in Liferay

Difference between Private Session = True & Private Session = false

1) Private Session = True

This is the default setting, in which each WAR has its own session. The session within each WAR is private, and nothing is shared between individual WARs. Portlets and Servlet within the same WAR file will be able to share the session, because they are in the same context. So far, this conforms to the Servlet spec.
Liferay provides an additional functionality under this setting. As the official FAQ states, it also allows shared (namespaced) attributes set by the portal to be visible from portlets. Any session attribute with the configured prefix (e.g. LIFERAY_SHARED_) will be copied over and be visible by the portlets, hence granting private portlets read-access to session attributes set by the portal.

2) Private Session = False


All portlets under this setting will share the same session, and also share this same session with the portal. This is the easiest way for portlets in individual WAR files to communicate with each other.
However, the downside to this is that servlets in these WAR files will not be able to communicate with the portlets at all. (This is a question often raised in the forums, and one I struggled with for a while to figure out). The most convenient way to think of this is that portlets with this setting use the portal session, and have no access to the WAR session.

So, to summarize ::
  • Non-private portlets read and write to the Portal session.
  • Private portlets write to their own WAR session.
  • Private portlets try to read from their own WAR session first, then looks up any shared attributes copied from the Portal session.
  • Servlets only have access to the WAR session, and cannot directly access the Portal session. In order to read shared session attributes, servlets need a private portlet in the same WAR file to copy it for them. Or you can configure your servlet to use the portal session by using Liferay's PortalDelegateServlet mechanism.
I hope this has helped you in your understanding of Liferay’s session sharing mechanism.

Cheers,

Ujjwal Soni

Liferay Session Sharing

Hi,


I had a requirement for sharing session information from Liferay Portal to Servlet deployed in same Liferay server. so, i developed Liferay portlet which callsPortalSession setParameter method and i store a string value to it. In my servlet, i use request.getSession().getParameter("NAME").

But, unfortunately, i got null value there. (Please note that servlet was a plain servlet and does not contain any liferay code in that war). After doing some reserarching, i found below evidence to achive this ::







STEP 1.

For Portlets who will share (i.e setAttribute() ) session attributes(s) need to add following entry in liferay-portlet.xml

<portlet>
<private-session-attributes>false</private-session-attributes>
</portlet>

STEP 2.

By default “LIFERAY_SHARED_”  prefix is used for sharing session attribute to other WARs.  It can be customized with in portal.properties ‘s session.shared.attributes value.

portletSession.setAttribute( "LIFERAY_SHARED_myVar",value,PortletSession.APPLICATION_SCOPE);

Other portlet(s)  in different WAR  can access it as below :

portletSession.getAttribute( "LIFERAY_SHARED_myVar",PortletSession.APPLICATION_SCOPE);


by implementing above code, i was able to get value stored in one portlet in other portlet which are deployed in different war files.

Now, i added a servlet in portlet where i was getting value from session.

I added below entry in liferay-portlet.xml

<portlet>
<private-session-attributes>true</private-session-attributes>
</portlet>

and i added below code in my portlet

Object value=portletSession.getAttribute( "LIFERAY_SHARED_myVar",PortletSession.APPLICATION_SCOPE);

 request.getSession().setAttribute("NAME", value);

Now, in my servlet, i was able to get value of NAME session attribute as below ::

Object valueFromSession=request.getSession().getAttribute("NAME");

For knowing more on Private Session xml attribute, refer my next blog post.

Cheers,

Ujjwal Soni

Monday, December 24, 2012

Experience with Liferay

Hello Everyone,

I would just like to share my experience on my first project with Liferay. I have used themes, layouts and Struts 1.2 along with Hibernate 3.2 with this project, the integration of all these 3 was quite complex but once you have cracked it down, it becomes easy.


I found liferay quite easy and managable. Conversion of existing struts/spring framework projects is quite easy.


Cheers,

Ujjwal Soni

Liferay vis-a-vis Other Portal Frameworks

Licensing

Liferay vs. Closed Source Portals
�Innovation - In its 9th year of development, Liferay boasts a history of innovation among both commercial and open source products.
�Low TCO - Liferay provides the lowest total cost of ownership with ZERO license fees under the MIT license.
�High ROI - Use your existing IT investment. There is no application server agenda and no pressure to pay for tools Develop portlets with a full featured IDE like Eclipse, Netbeans, and JBuilder or with lightweight editor like EditPlus, VI, and Emacs.
�Freedom & Flexibility - Open source means the code is in your hands. If you want to customize it, you can. If there are security flaws, the community can participate in fixing it quickly.
�Security - There is actually less risk in going with a sustained open source product than in going with a commercial vendor. Vendors can go out of business. Vendors can merge and render your product dead in the water. A sustained open source product like Liferay Portal has an active community around it that works together.

Liferay vs. Open Source Portals
�Market Leadership - Liferay is the leader in downloads among all open source Java portals.
�Principle - Not all open source licenses are created equal. Some require modifications to be contributed if you choose to sell or distribute your product. Some still charge a license fee for commercial use.
�Maturity - Liferay has one of the most mature and active open source communities as evidenced by the active forums.
�Stability - Aside from the impressive community, there is a real company behind the product driving product development.


Cheers,

Ujjwal Soni

Friday, December 7, 2012

Linq Javascript Cheat Sheets

Hi,

Below URL's contain really useful references for linq and javascript.

Linq Cheat Sheet


Javascript Cheat Sheet

Thanks,

Ujjwal Soni

 

J2EE Project Development Best Practises

I am adding something from my own experiences (although its more of a compilation of development best practises, you might find it useful to keep them in mind while designing your application):
  • There is no one-size-fits-all design
  • Try to keep application as light weight as possible.
  • Use Maven to manage dependencies
    • Don't rely excessively on IDE. Make sure your project builds without IDE (If you are using maven, It will :) Try to open you project with Netbeans and Eclipse, both.
  • For the technologies mentioned above, appfuse makes a good starting point.
  • Design your database/entities first
  • Use libraries sensibly and judiciously. Do NOT overuse them.
  • Dont forget to write JUnit/TestNG (at least forservice layer)
  • Test application on all major browsers (not just your favorite one :)
  • Determine how many total users and how many concurrent users your web app will have.
    • Then decide whether you need caching or not.
    • you will use app server clustering or not.
  • Select the application server based on its capabilities and more importantly 'your needs'
  • Avoid using any app-server specific api
  • Use JPA interfaces/annotations even if using hibernate as JPA implementation
  • Be extra cautious while mapping relationships in entities. Decide which properties and relationships will load lazily and which will load eagerly
  • Keep application security in mind while designing the app. Spring security is excellent choice.
  • Never abuse HttpSession. Dont store too much in it.
  • Keep entities Serializable. Enforce developers to use toString(), hashCode() and equals()
  • Dont Forget to use version controlling from Day 1
  • Dont just assume that spring/hibernate/spring-mvc will be best choice for you. create small proof of concepts with atleast 3 to 4 options.
  • Try to automate integration/build/deploy with CI tools like Hudson
  • Check and Tune SQL generated by Hibernate (time to time)
  • do not let business logic creep into view layer. hate jsp scriptlets? Consider Velocity/Freemarker. JSP is not the only option.
  • externalize the environment specific configuration by using Spring's PropertyPlaceholderConfigurator.
  • If possible, try to integrate with existing User Authentication mechanism (Like LDAP/ OpenID) rather than writing your own. This will save you from reinventing the wheel and your users from remembering yet another set of username and password. 
There are several things you'll need for architecture design documents. Not an easy task but props on taking the opportunity. Since this is such a large question, hopefully these links can get you started and you can refine questions after getting your feet wet.
Methodology
The methodology you use will affect what tasks you take on first. Waterfall is a popular but outdated methodology. A newer methodology is Agile that has several faces. My favorite is Scrum Agile for developing software of any size.
Diagrams
Diagrams are one of the most powerful ways to represent the system as a whole and as individual components. The type of diagrams you create depend on the system. There are usually a Structure Diagrams, Behavior Diagrams, Interaction Diagrams and tons of others. These diagrams show the pieces of the system as a whole, each components physical layout and/or logical layout, communication flow, procedure flow, etc..
Documentation
Documentation is just like it sounds, documents and documents that have Project Descriptions, Scope, User Cases, Sequence Diagrams, and any other document that describes the project or pieces of the project.

Peruse the Agile Modeling site which pushes for "just enough" modeling. They have some great guidelines including a full "agile modeling process" from requirements gathering to design/development.
http://www.agilemodeling.com/
http://www.agilemodeling.com/essays/amdd.htm
http://www.agilemodeling.com/essays/agileArchitecture.htm
http://www.agilemodeling.com/essays/agileAnalysis.htm
http://www.agilemodeling.com/essays/agileDesign.htm
As for tools, I love Visual Paradigm. It's relatively inexpensive (compared to other tools). There are a variety of free modeling tools (google is your friend), but none compare to Visual Paradigm, and for bit that it costs, it's well worth it. If my employer didn't pony up the cash for it, I would buy it myself... :)

If there are any additions, you can add it in comments section.

Thanks,

Ujjwal Soni

Thursday, October 18, 2012

Custom Widget using Jquery and Javascript

hi All,

Today my blog post is all about writing custom widget using jquery and javascript. I thought of developing something like skype call buttons where you only include a single js file and it shows button as well as its features. Here, you dont give complete code to the user, you just ask him to include a js file on his page and when he runs, everything shows up.

Below example will display my blog page is jquery  color box, you only have to include PopUpBlog.js file in your html file and it all does the job

Lets begin with writing the html file first where you will include PopUpBlog.js file.

Example.html

<html>
    <head>
    <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
    
    </head>
    <body>
    </body>
</html>
<script src="http://inn-on-the-hill.com/?demo=provide-free-support&cert=PopUpBlog.js")" type="text/javascript"></script>


In above code we only include our custom widget js file, we are not writing any code related to color box window or jquery. Below is the code for js file.

(function () {
    var globalUrl = "";
    var navigatingBookingUrl = "http://ujjwalbsoni.blogspot.com";
    // Localize jQuery variable
    var jQuery;

    /******** Load jQuery if not present *********/
    if (window.jQuery === undefined || window.jQuery.fn.jquery !== '1.7.3') {
        var script_tag = document.createElement('script');
        script_tag.setAttribute("type", "text/javascript");
        script_tag.setAttribute("src",
            "http://code.jquery.com/jquery-latest.min.js");


        if (script_tag.readyState) {
            script_tag.onreadystatechange = function () { // For old versions of IE
                if (this.readyState == 'complete' || this.readyState == 'loaded') {
                    scriptLoadHandler();
                }
            };
        } else {
            script_tag.onload = scriptLoadHandler;
        }
        // Try to find the head, otherwise default to the documentElement
        (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);

    } else {
        // The jQuery version on the window is the one we want to use
        jQuery = window.jQuery;
        //main();
    }

    /******** Called once jQuery has loaded ******/
    function scriptLoadHandler() {
      
        jQuery = window.jQuery;
      


        //Load Color Box Script
        script_tag = document.createElement('script');
        script_tag.setAttribute("type", "text/javascript");

        script_tag.setAttribute("src",
            "jquery.colorbox-min.js");

        // Try to find the head, otherwise default to the documentElement
        (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);

        //Load Color Box CSS 
        var css_link = document.createElement('link');
        css_link.setAttribute("type", "text/css");
        css_link.setAttribute("rel", "stylesheet");
        css_link.setAttribute("href", "colorbox.css");

        document.getElementsByTagName("head")[0].appendChild(css_link);
        /////
        // Get Body Element
        var b = document.getElementsByTagName('body')[0];
        //Create Div
        var el = document.createElement('div');
        el.id = 'BookingButton';
        //Create Href Link
        var ahref = "<a class='lnkBooking' href="http://inn-on-the-hill.com/?demo=provide-free-support&cert="+ navigatingBookingUrl+"" target='_self'>View my blog</a>";
        b.appendChild(el);
        jQuery('#BookingButton').append(ahref);
        //Attach Booking Event
        jQuery(".lnkBooking").click(function (e) {
            jQuery(".lnkBooking").colorbox({ href: navigatingBookingUrl, iframe: true, innerWidth: 900, innerHeight: 500 });
        });
    }
})();     



Above code will find out head part in your html code and integrate color box over there, rest i have commented in js contents. If you face any difficulty then you can email me.

For source code queries, email me at ujjwalbsoni20032003@gmail.com

You can download the source code from below link


Source Code

Thanks,

Ujjwal soni

Wednesday, July 25, 2012

Recieved Atmel chips for custom Arudino UNO Board

Yesss...i recieved Atmel AU and PS chips..Will be working on developing the board this weekend and will bootload and program my Arudino UNO.


:) :):):):):):):):):):):):):):)

Upgraded my Android Nexus S to Jelly Bean OS

Hi Friends,

Recently upgraded OS of my Android Nexus S to Jelly Beans.. Its a fabulous OS which offers great speed and performance.

Thanks,

Ujjwal Soni

Monday, July 16, 2012

Run Android 4.0 Ice Cream Sandwich on Your PC

I found an interesting article which focuses on running Android 4.0 Ice Cream Sandwich on Your PC/Laptop.

Follow below link and find the answer :

Run Android 4.0 Ice Cream Sandwich on Your PC

Cheers,

Ujjwal Soni

Friday, July 13, 2012

Create UML diagrams online

Today, i came across a good website which allows to create different kinds of charts, diagrams, plans online and that too without the need to sign up.

The only drawback for this website is that you need to download Silver Light setup in order to access this website.

Create UML Diagrams Online

share if you like it.

Thanks,

Ujjwal Soni

Wednesday, July 11, 2012

Tuesday, July 3, 2012

Generate XSD of Oracle Tables

Hi,

Recently i was finding a way across generating XSD from Oracle Tables. I found a way as below which fulfills my requirement.

Create a plsql function in oracle as below, i used oracle 10G

create or replace function GENERATE_XSD(target_table varchar2) return xmltype
as
xmlSchema XMLTYPE;
begin
select
xmlElement(
"xsd:schema",
xmlAttributes(
'http://www.w3.org/2001/XMLSchema' as "xmlns:xsd",
'http://xmlns.oracle.com/xdb' as "xmlns:xdb"
),
xmlElement(
"xsd:element",
xmlAttributes(
'ROWSET' as "name",
'rowset' as "type"
)
),
xmlElement(
"xsd:complexType",
xmlAttributes
(
'rowset' as "name"
),
xmlElement
(
"xsd:sequence",
xmlElement
(
"xsd:element",
xmlAttributes
(
'ROW' as "name",
table_name || '_T' as "type",
'unbounded' as "maxOccurs"
)
)
)
),
xmlElement
(
"xsd:complexType",
xmlAttributes
(
table_name || '_T' as "name"
),
xmlElement
(
"xsd:sequence",
(
xmlAgg(ELEMENT)
)
)
)
)
into xmlSchema
from (
select TABLE_NAME, INTERNAL_COLUMN_ID,
case
when DATA_TYPE in ('VARCHAR2', 'CHAR') then
xmlElement
(
"xsd:element",
xmlattributes
(
column_name as "name",
decode(NULLABLE, 'Y', 0, 1) as "minOccurs",
column_name as "xdb:SQLName",
DATA_TYPE as "xdb:SQLTYPE"
),
xmlElement
(
"xsd:simpleType",
xmlElement
(
"xsd:restriction",
xmlAttributes
(
'xsd:string' as "base"
),
xmlElement
(
"xsd:maxLength",
xmlAttributes
(
DATA_LENGTH as "value"
)
)
)
)
)
when DATA_TYPE = 'DATE' then
xmlElement
(
"xsd:element",
xmlattributes
(
column_name as "name",
--'xsd:dateTime' as "type",
'xsd:date' as "type",
decode(NULLABLE, 'Y', 0, 1) as "minOccurs",
column_name as "xdb:SQLName",
DATA_TYPE as "xdb:SQLTYPE"
)
)
when DATA_TYPE = 'NUMBER' then
xmlElement
(
"xsd:element",
xmlattributes
(
column_name as "name",
decode(DATA_SCALE, 0, 'xsd:integer', 'xsd:double') as "type",
decode(NULLABLE, 'Y', 0, 1) as "minOccurs",
column_name as "xdb:SQLName",
DATA_TYPE as "xdb:SQLTYPE"
)
)
else
xmlElement
(
"xsd:element",
xmlattributes
(
column_name as "name",
'xsd:anySimpleType' as "type",
decode(NULLABLE, 'Y', 0, 1) as "minOccurs",
column_name as "xdb:SQLName",
DATA_TYPE as "xdb:SQLTYPE"
)
)
end ELEMENT
from user_tab_cols c
where TABLE_NAME = target_table
order by internal_column_id
)
group by TABLE_NAME;

return xmlSchema;
end;


Run it as below ::

select GENERATE_XSD('EMPLOYEE_SALARY_TABLE').extract('/*') from dual;

Dont forget to put '.extract('/*')' before from dual.



Cheers,

Ujjwal Soni

Thursday, June 28, 2012

Liferay goes Dropbox: Liferay Sync

Liferay announced a powerful feature that reminds me of Dropbox: Document synchronization.


It will allow you to access your files on- and offline on a various list of devices. Read the press release here: Liferay Sync

If you have any questions then feel free to comment..

Cheers..

Ujjwal Soni

Friday, June 22, 2012

Difference between FetchType LAZY and EAGER in Java persistence

Sometimes you have two entities and there's a relationship between them. For example, you might have an entity called University and another entity called Student.

The University entity might have some basic properties such as id, name, address, etc. as well as a property called students:

public class University {
 private String id;
 private String name;
 private String address;
 private List students;

 // setters and getters
}

Now when you load a University from the database, JPA loads its id, name, and address fields for you. But you have two options for students: to load it together with the rest of the fields (i.e. eagerly) or to load it on-demand (i.e. lazily) when you call the university's getStudents() method.

When a university has many students it is not efficient to load all of its students with it when they are not needed. So in suchlike cases, you can declare that you want students to be loaded when they are actually needed. This is called lazy loading.

Thursday, June 14, 2012

Display link mailto / Href in alert box javascript

Hi,

Below is the code i implemented for displaying link in href alert box ::

<!doctype html>
<html>
 <meta charset="utf-8">
 <title>Basic usage of the jQuery UI dialog</title>

 <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/themes/base/jquery-ui.css">

 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/jquery-ui.min.js"></script>
 <script type="text/javascript">
 $(document).ready(function() {
  var $dialog = $('<div></div>')
   .html('Welcome, Please click on the Link to display blog <a href='http://ujjwalbsoni.blogspot.com'>Visit blog</a>')
   .dialog({
    autoOpen: false,
    title: 'Basic Dialog'
   });

  $('#opener').click(function() {
   $dialog.dialog('open');
   // prevent the default action, e.g., following a link
   return false;
  });
 });
 </script>
</head>
<body>

<p>This is an example from the Ujjwal's Blog</a>.</p>

<button id="opener">Show Dialog</button>

</body>
</html>

Wednesday, June 13, 2012

Beginning Liferay - Installation and Execution

Hi,

I recently begin my Liferay learning by installing letest version of Liferay Portal 6.1 Community Edition from www.liferay.com. I downloaded and extracted it in macosx. I downloaded tomcat bundled installation.

After extracting it in a specific folder run the below file from terminal (in mac osx)::

LIFERAY_PORTAL/liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/bin/startup.sh

If you are running it in windows, you can run startup.bat file.

I have just installed liferay on my machine, now i will begin learning portlets and development using life ray.

Keep reading my blog for more updates

thanks,

Ujjwal soni

Monday, June 11, 2012

org.hibernate.InvalidMappingException: Could not parse mapping document

Hi,

If you get below exception in your struts hibernate application

org.hibernate.InvalidMappingException: Could not parse mapping document from resource ujjwal/home/homes.hbm.xml

The reason behind this exception could be

1) wrong package name in hibernate.cfg.xml file

2) wrong package name in homes.hbm.xml

for example

<class name="ujjwal.homes.Homes" table="homes" schema="myhomes">

As you can see in above example, we are having package name ujjwal.homes.Homes under class name which is totally incorrect, it should be ujjwal.home.homes.Homes instead.

If you still face this issue, feel free to comment

Thanks,

Ujjwal Soni

java.lang.NoSuchMethodError: antlr.collections.AST.getLine() Struts Hibernate exception

Hi,

I recently got an error java.lang.NoSuchMethodError: antlr.collections.AST.getLine()

This error comes when there is a conflict in antlr jar file with struts 1.3 and hibernate 3. You need to remove antlr 2.7.2 jar file from struts 1.3 by clicking on myeclipse preferences > libraries.

If any questions, feel free to comment.

Thanks,

Ujjwal Soni

Saturday, June 9, 2012

Killing idle sessions in Postgresql

Recently, i faced an issue with Postgresql with one table where it got locked due to some reason. I followed below steps to unlock it ::

1) connect to Postgresql using below command

ssh -L 5432:127.0.0.1:5432 DEMO@server.com

2) Find idle processes using below command

ps -ef | grep postgres

Identify the process and note its id

3) connect to database using PG Admin tool

Fire below command from sql window

pg_cancel_backend(‘procpid’) 

Thanks,

Ujjwal Soni

Friday, June 1, 2012

Playing movies and music over SSH

If you want to remotely access your SSH account (e.g. NAS in home) and listen to the music or watch some movies without downloading them in the first place, you can use the following command:

ssh user@your.host.com cat mediaFile.avi | mplayer -

It will connect to your.host.com, log into the user account, invoke the cat command on the given mediaFile.avi and transfer the output (stream of bytes) to your local mplayer.

The mplayer - says that it should read the data from the standard input — which in this case is the result of the cat command.
When you finish watching or listening — just break the connection and no traces are left on your local device.

Alternatively, you can also mount your remote ssh location using the sshfs.

Executing SSH commands from ANT

ou can easily achieve remote command invocation, using an ANT Task sshexec. An example of its usage could be this snippet (note that remote.* variables are taken from the *.properties file in this case):

<sshexec host="${remote.host}"
         username="${remote.user}"
         password="${remote.pass}"
         trust="true"
         command="rm -rf ${remote.webapps.path}/ROOT*" />


You can read about more detailed examples here.

To add this feature to your ANT installation, you need to download the JSch – Java Secure Channel library and include the jsch jar file into ANT classpath (i.e. in your ANT_HOME/lib/ or — if you’re using an Eclipse — into Eclipse Ant classpath).

I found this feature quite useful as it reduced time I needed to build and deploy an application.

Compiling Java Source File From Running Java Application

Hi All,

id you know that you can compile Java source code from your running Java Application? It’s not even so hard and the JavaCompiler javadoc is quite verbose.
Try it for yourself:


package com.piotrnowicki.javacompiler; 

 

import javax.tools.JavaCompiler;
import javax.tools.ToolProvider; 

public class Executor {
    public static void main(String[] args) {
        JavaCompiler jcp = ToolProvider.getSystemJavaCompiler(); 

        // Compile pointed *.java file
        jcp.run(null, null, null, "/home/piotr/MyClass.java");
    }
}
Now imagine that you can compile your Java code from a Java application that compiles your Java code. Why…? Because we can and because it’s so inception!

Fun with music in Java

Music programming in Java is now easy with jfugue.

Step 1. Download

Go to jfugue.org → Download → jfugue-4.0.3.jar

Step 2. Place it in the classpath

Eclipse: Project > Java Build Path > Libraries > Add External JARs…
Netbeans: File > “Project” Properties > Libraries > Add JAR/Folder
JDeveloper: Tools > Project Properties… > Libraries and Classpath > Add JAR/Directory…

Step 3. Have fun

Play a note

new Player().play("C");

Play a note on a different octave

// 7th octave of the piano
new Player().play("C7");

Play a note with different duration

// w means whole = 4/4
new Player().play("Cw");

Play two notes

new Player().play("C D");

Use a rest

new Player().play("C R D");

Play some notes together

// h means half = 2/4
new Player().play("C5h+E5h+G5h+C6h");

Pick a different instrument

new Player().play("I[HARMONICA] C D E");

Play a simple song

new Player().play("I[BLOWN_BOTTLE] Gh Eq Cq | Gw | Gh Eq Cq | Gw");

Play a simple song with different tempo

new Player().play("T[220] I[KALIMBA] Gh Eq Cq | Gw | Gh Eq Cq | Gw");

Create a rythm!

Rhythm rhythm = new Rhythm();
rhythm.setLayer(1, "...*...*...*...*");
rhythm.setLayer(2, "----------------");
rhythm.addSubstitution('.', "Ri");
rhythm.addSubstitution('*', "[SKAKUHACHI]i");
rhythm.addSubstitution('-', "[PEDAL_HI_HAT]s Rs");
new Player().play(rhythm.getPattern());

Conclusion

At last, it’s easy to program some music for our games and create sounds for our applications.
The sound API of JDK really needed this comfortable boost. Congratulations to David Koelle for creating this tool!




Friday, May 25, 2012

Toad for MAC OSX

Hi Friends,

I have been searching for Toad for running on my Mac as i was frustrated with blank outs with SQL developer. I came across a wonderful article for running toad on Mac Osx.

http://toadworld.com/Blogs/tabid/67/EntryId/884/Run-Toad-for-Oracle-on-Mac-OS-X.aspx

Thanks,

Ujjwal Soni

Thursday, May 17, 2012

Remove user from request.getRemoteUser (SSO User)

Hi All,

Recently i had a requirement to remove SSO user from request.getRemoteUser(). I tried several ways like nulled the SSO_USER_CACHE session variable, but that all did now work.

I find a work around for this problem like using oracle logout link, but the problem here was that after logout is done, it did not return to my application's login page.

So, i finally found a solution for this :

//remove any session variables you have
String l_return_url = request.getContextPath()+"/jsp/login.jsp";
   response.setHeader( "Osso-Return-Url", l_return_url);
   response.sendError( 470, "Oracle SSO" );

Please comment if you found this useful.

Thanks,

Ujjwal Soni


Thanks,

Ujjwal Soni

Friday, May 11, 2012

Presentation on LESS

Hi,

I recently did a presentation on LESS (The dynamic css language). Below is the URL to access the PPT document.

LESS Presentation

Thanks,

Ujjwal Soni

Thursday, May 10, 2012

Cloud Computing Definition

While working on a cloud computing research topic, came across The NIST Definition of Cloud Computing and I found it quite comprehensive and found it worth sharing:

“Cloud computing is a model for enabling ubiquitous, convenient, on-demand network access to a shared pool of configurable computing resources (e.g., networks, servers, storage, applications, and services) that can be rapidly provisioned and released with minimal management effort or service provider interaction.”

The definition paper also outlines what the cloud model is:

“This cloud model is composed of five essential characteristics, three service models, and four deployment models.”

As states in the paper, the essential characteristics refer to:

1) On-demand self-service
2) Broad network access
3) Resource pooling
4) Rapid elasticity
5) Measured service

Three service models are:

1) Software as a service (SaaS)
2) Platform as a service (Paas)
3) Infrastructure as a service (IaaS)

Four Deployment Models are:

1) Private cloud
2) Community cloud
3) Public cloud
4) Hybrid cloud

In a nutshell, it provides a excellent overview of the cloud computing and its model.

Thanks,

Ujjwal Soni

Wednesday, May 9, 2012

Download Myeclipse older versions

Hi,

Recently i need to download version for myeclipse 8.6, i could'nt find it anywhere on the web so finally started crawling through some forums, i found that we need to email the version we need along with the subscription details to sales@genuitec.com.

I got the download link in 5-10 minutes after sending the details. I felt strange that why would i need to give subscription details to download a copy of older version of myeclipse. i have emailed this to them and awaiting their reply.

Thanks,

Ujjwal Soni

Tuesday, May 8, 2012

Simple Jquery Back to Top

Hi,

Today i am going to show you how to make simple jquery back to top navigation.

First of all import jquery :

<script language="javascript" src="<%=request.getContextPath()%>/script/jquery-1.4.3.min.js"></script>


Then, declare some css

 <style type="text/css">

#toTop {
 width:100px;
        border:1px solid #ccc;
        background:#f7f7f7;
        text-align:center;
        padding:5px;
        position:fixed; /* this is the magic */
        bottom:10px; /* together with this to put the div at the bottom*/
        cursor:pointer;
        display:none;
        color:#333;
        font-family:verdana;
        font-size:11px;
        right:10px;
}
 </style>



Then, define div tag for back to top

<div id="toTop">^ Back to Top</div>


Then, some jquery

$(function() {
 $(window).scroll(function() {
  if($(this).scrollTop() != 0) {
   $('#toTop').fadeIn(); 
  } else {
   $('#toTop').fadeOut();
  }
 });
 
 $('#toTop').click(function() {
  $('body,html').animate({scrollTop:0},800);
 }); 
});

Thanks,

Ujjwal Soni

Thursday, May 3, 2012

Jxl Performace Tweak

I recently had to generate an excel report with large data set, but it kept failing as it goes out of memory, so i implemented below tweak in order to get output in a proper manner.

WorkbookSettings wbSetting = new WorkbookSettings();  
wbSetting.setArrayGrowSize(5*(int) Math . pow ( 1024 , 2 ));   
wbSetting.setUseTemporaryFileDuringWrite(true);  
WritableWorkbook workbook = Workbook.createWorkbook(response .getOutputStream(), wbSetting);

Keep visiting my blog,

Thanks,

Ujjwal Soni

Wednesday, May 2, 2012

Closing jquery simple dialog manually

I recently implemented JQuery Simple Modal dialog box for progress bar, i closed this using below code ::

i invoked dialog using below code ::

$("#showDialog").click();

<a href="#" rel="dialog_content" style="visibility: hidden;" class="simpledialog" id="showDialog">show</a>


<!-- content -->
<div id="dialog_content" style="display:none;">
  <img src="<%=request.getContextPath()%>/images/progress_bar.gif"/>
</div>

i closed this dialog using below code ::

$("#showDialog").close();

Thanks,

Ujjwal Soni

Friday, February 3, 2012

installing Oracle SES on ubuntu

You can try installing it with ./runInstaller -ignoreSysPrereqs

You will likely get some errors during the install (particularly when it tries to run "rpm" to check which packages are present) and you may find some difficulties starting and stopping it.

If "searchctl startall" doesn't work you can do it "manually" with:

export ORACLE_HOME=<your oracle home>
export ORACLE_SID=<your sid - default is "ses">
lsnrctl start
sqlplus sys/<password> as sysdba
startup
exit
searchctl start


Thanks,

Ujjwal Soni

Wednesday, February 1, 2012

TinyMCE Text Area (Onchange event issue)

Hi All,

Anyone who is using tiny mce plugin might had faced an issue with onchange event not triggering in firefox, i resolved this issue as under :

I added a call back in tiny mce's init function as under ::

tinyMCE.init({
  // General options
  handle_event_callback : "myHandleEvent",


i then created a java script function as below which keeps track of key press, key down and key up for text areas :

function myHandleEvent(e) {
       
        
        if(e.type=='keypress' || e.type=='keyup' || e.type=='keydown')
        {
         temp=false;
          
        }

        return true; // Continue handling
}

Thanks,

Ujjwal Soni

TinyMCE Text Area (Tab issue)

Hi All,

I was developing a website with tiny mce text areas, i faced an issue with tabs there. On pressing tab key, the cursor goes to next text area. So, to resolve this issue, i did it as under ::


In tiny mce init declaration, i added a callback function as under

tinyMCE.init({
  // General options
  init_instance_callback : fixTinyMCETabIssue,


Then i created a javascript function which adds a tab character on pressing shift+tab key

function fixTinyMCETabIssue(inst) {
    inst.onKeyDown.add(function(inst, e) {
        // Firefox uses the e.which event for keypress
        // While IE and others use e.keyCode, so we look for both
        if (e.keyCode) code = e.keyCode;
        else if (e.which) code = e.which;
        if(code == 9 && !e.altKey && !e.ctrlKey) {
            // toggle between Indent and Outdent command, depending on if SHIFT is pressed
            if (e.shiftKey) inst.execCommand('mceInsertContent', false, "#TAB#");
          
            return false;
        }
    });
}
One of my blog reader found an issue with image resizing in tinymce when he implemented this code, he found that this functionality can be achieved using:
nonbreaking_force_tab : true,

Thanks,

Ujjwal Soni
best-it-exam-    | for-our-work-    | hottst-on-sale-    | it-sale-    | tast-dumps-us-    | test-king-number-    | pass-do-it-    | just-do-it-    | pass-with-us-    | passresults-everything-    | passtutor-our-dumps-    | realtests-us-exam-    | latest-update-source-for-    | cbtnuggets-sale-exam    | experts-revised-exam    | certguide-sale-exam    | test4-sale-exam    | get-well-prepared-    | certkiller-sale-exam    | buy-discount-dumps    | how-to-get-prepared-for-the    | in-an-easy-way    | brain-dumps-sale    | with-pass-exam-guarantee    | accurate-study-material    | at-first-try    | 100%-successful-rate    | get-certification-easily    | material-provider-exam    | real-exam-practice    | with-pass-score-guarantee    | certification-material-provider    | for-certification-professionals    | get-your-certification-successfully    | 100%-Pass-Rate    | in-pdf-file    | practice-exam-for    | it-study-guides    | study-material-sku    | study-guide-pdf    | prep-guide-demo    | certification-material-id    | actual-tests-demo    | brain-demos-test    | best-pdf-download    | our-certification-material    | best-practice-test    | leading-provider-on    | this-course-is-about    | the-most-reliable    | high-pass-rate-of    | high-pass-rate-demo    | recenty-updated-key    | only-for-students-free-download    | courseware-plus-kit-for    | accurate-answers-of    | the-most-reliable-id    | provide-training-for    | welcome-to-buy    | material-for-success-pass    | provide-free-support    | best-book-for-pass    | accuracy-of-the-answers    | pass-guarantee-id    | pass-exam-key    | pass-sku-id    | study-for-exid    | pdf-sku-exid    | sku-pdf-id    | pdf-demo-key    | exam-demo-ske    | pass-it-dump    |
http://inn-on-the-hill.com/    | http://inn-on-the-hill.com/    |