Acoustic Alchemy - The Beautiful Game - Instrumental JAZZ
Isn't it awesome ?
<a href="download">Download String </a>
Controller Method :
@RequestMapping(value = "/download", method = RequestMethod.GET)
public @ResponseBody
void downloadFile(HttpServletResponse resp) {
String downloadFileName= "download.txt";
String downloadStringContent= getStringToWrite(); // implement this
try {
OutputStream out = resp.getOutputStream();
resp.setContentType("text/plain; charset=utf-8");
resp.addHeader("Content-Disposition","attachment; filename=\"" + downloadFileName + "\"");
out.write(downloadStringContent.getBytes(Charset.forName("UTF-8")));
out.flush();
out.close();
} catch (IOException e) {
}
}
<a href="downloadFile?fileName=log.txt">Download String </a>
Controller Method :
@RequestMapping(value = "/downLoadFile", method = RequestMethod.GET)
public void downLoadFile( HttpServletRequest request, HttpServletResponse response ) {
try {
String fileName = request.getParameter( "fileName" );
File file = getFileToDownload(fileName) // implement this to return a valid file object
InputStream in = new BufferedInputStream( new FileInputStream( file ) );
response.setContentType( "text/plain" ); // define your type
response.setHeader( "Content-Disposition", "attachment; filename=" + fileName );
ServletOutputStream out = response.getOutputStream( );
IOUtils.copy( in, out ); //import org.apache.commons.io.IOUtils;
response.flushBuffer( );
} catch ( Exception e ) {
e.printStackTrace( );
}
}
package g.t.test; import org.xhtmlrenderer.pdf.ITextRenderer; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; public class HtmlToPDFConverter { public static void convert(String htmlContent, File pdfFile) throws Exception { ByteArrayOutputStream os = new ByteArrayOutputStream(); //step1: render html to memory
ITextRenderer renderer = new ITextRenderer();
renderer.setDocumentFromString(htmlContent);
renderer.layout();
renderer.createPDF(os);
//step2: conver to byte array stream
byte[] pdfAsBytes = os.toByteArray();
os.close();
//step3: write byte array stream to file
FileOutputStream fos = new FileOutputStream(pdfFile);
fos.write(pdfAsBytes);
fos.flush();
fos.close();
}
// let's test !!
public static void main(String[] args) throws Exception{
convert("<html> <body> " +
"<h1>Hello Crazy World !!</h1> <br/> " +
"<h2> I hope you are doing great.</h2> " +
"</body> </html>", new File("test.pdf"));
}
}
<dependency> <groupId>com.lowagie</groupId> <artifactId>itext</artifactId> <version>2.1.7</version> </dependency> <dependency> <groupId>org.xhtmlrenderer</groupId> <artifactId>flying-saucer-pdf</artifactId> <version>9.0.9</version> </dependency>
[selector].show( speed, [callback] );Here is the description of all the parameters:
[selector].hide( speed, [callback] ); |
<html> <head> <title>the title</title> <script type="text/javascript" src="/jquery/jquery-1.3.2.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#show").click(function () { $(".mydiv").show( 1000 ); }); $("#hide").click(function () { $(".mydiv").hide( 1000 ); }); }); </script> <style> .mydiv{ margin:10px;padding:12px; border:2px solid #666; width:100px; height:100px; } </style> </head> <body> <div class="mydiv"> This is SQUAR </div> <input id="hide" type="button" value="Hide" /> <input id="show" type="button" value="Show" /> </body> </html>
[selector]..toggle([speed][, callback]); |
<html> <head> <title>the title</title> <script type="text/javascript" src="/jquery/jquery-1.3.2.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $(".clickme").click(function(event){ $(".target").toggle('slow', function(){ $(".log").text('Transition Complete'); }); }); }); </script> <style> .clickme{ margin:10px;padding:12px; border:2px solid #666; width:100px; height:50px; } </style> </head> <body> <div class="content"> <div class="clickme">Click Me</div> <div class="target"> <img src="/images/jquery.jpg" alt="jQuery" /> </div> <div class="log"></div> </body> </html>
Methods and Description |
---|
animate( params, [duration, easing, callback] ) A function for making custom animations. |
fadeIn( speed, [callback] ) Fade in all matched elements by adjusting their opacity and firing an optional callback after completion. |
fadeOut( speed, [callback] ) Fade out all matched elements by adjusting their opacity to 0, then setting display to "none" and firing an optional callback after completion. |
fadeTo( speed, opacity, callback ) Fade the opacity of all matched elements to a specified opacity and firing an optional callback after completion. |
hide( ) Hides each of the set of matched elements if they are shown. |
hide( speed, [callback] ) Hide all matched elements using a graceful animation and firing an optional callback after completion. |
show( ) Displays each of the set of matched elements if they are hidden. |
show( speed, [callback] ) Show all matched elements using a graceful animation and firing an optional callback after completion. |
slideDown( speed, [callback] ) Reveal all matched elements by adjusting their height and firing an optional callback after completion. |
slideToggle( speed, [callback] ) Toggle the visibility of all matched elements by adjusting their height and firing an optional callback after completion. |
slideUp( speed, [callback] ) Hide all matched elements by adjusting their height and firing an optional callback after completion. |
stop( [clearQueue, gotoEnd ]) Stops all the currently running animations on all the specified elements. |
toggle( ) Toggle displaying each of the set of matched elements. |
toggle( speed, [callback] ) Toggle displaying each of the set of matched elements using a graceful animation and firing an optional callback after completion. |
toggle( switch ) Toggle displaying each of the set of matched elements based upon the switch (true shows all elements, false hides all elements). |
jQuery.fx.off Globally disable all animations. |
[selector].load( URL, [data], [callback] );Here is the description of all the parameters:
<html> <head> <title>the title</title> <script type="text/javascript" src="/jquery/jquery-1.3.2.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#driver").click(function(event){ $('#stage').load('/jquery/result.html'); }); }); </script> </head> <body> <p>Click on the button to load result.html file:</p> <div id="stage" style="background-color:blue;"> STAGE </div> <input type="button" id="driver" value="Load Data" /> </body> </html>Here load() initiates an Ajax request to the specified URL /jquery/result.html file. After loading this file, all the content would be populated inside <div> tagged with ID stage. Assuming, our /jquery/result.html file has just one HTML line:
<h1>THIS IS RESULT...</h1> |
<html> <head> <title>the title</title> <script type="text/javascript" src="/jquery/jquery-1.3.2.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#driver").click(function(event){ $.getJSON('/jquery/result.json', function(jd) { $('#stage').html('<p> Name: ' + jd.name + '</p>'); $('#stage').append('<p>Age : ' + jd.age+ '</p>'); $('#stage').append('<p> Sex: ' + jd.sex+ '</p>'); }); }); }); </script> </head> <body> <p>Click on the button to load result.html file:</p> <div id="stage" style="background-color:blue;"> STAGE </div> <input type="button" id="driver" value="Load Data" /> </body> </html>Here JQuery utility method getJSON() initiates an Ajax request to the specified URL /jquery/result.json file. After loading this file, all the content would be passed to the callback function which finally would be populated inside <div> tagged with ID stage. Assuming, our /jquery/result.json file has following json formatted content:
{ "name": "Zara Ali", "age" : "67", "sex": "female" } |
<html> <head> <title>the title</title> <script type="text/javascript" src="/jquery/jquery-1.3.2.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#driver").click(function(event){ var name = $("#name").val(); $("#stage").load('/jquery/result.php', {"name":name} ); }); }); </script> </head> <body> <p>Enter your name and click on the button:</p> <input type="input" id="name" size="40" /><br /> <div id="stage" style="background-color:blue;"> STAGE </div> <input type="button" id="driver" value="Show Result" /> </body> </html>Here is the code written in result.php script:
<?php if( $_REQUEST["name"] ) { $name = $_REQUEST['name']; echo "Welcome ". $name; } ?>
$('div').bind('click', function( event ){ alert('Hi there!'); }); selector.bind( eventType[, eventData], handler)Following is the description of the parameters:
selector.unbind(eventType, handler) or selector.unbind(eventType)Following is the description of the parameters:
Event Type | Description |
---|---|
blur | Occurs when the element loses focus |
change | Occurs when the element changes |
click | Occurs when a mouse click |
dblclick | Occurs when a mouse double-click |
error | Occurs when there is an error in loading or unloading etc. |
focus | Occurs when the element gets focus |
keydown | Occurs when key is pressed |
keypress | Occurs when key is pressed and released |
keyup | Occurs when key is released |
load | Occurs when document is loaded |
mousedown | Occurs when mouse button is pressed |
mouseenter | Occurs when mouse enters in an element region |
mouseleave | Occurs when mouse leaves an element region |
mousemove | Occurs when mouse pointer moves |
mouseout | Occurs when mouse pointer moves out of an element |
mouseover | Occurs when mouse pointer moves over an element |
mouseup | Occurs when mouse button is released |
resize | Occurs when window is resized |
scroll | Occurs when window is scrolled |
select | Occurs when a text is selected |
submit | Occurs when form is submitted |
unload | Occurs when documents is unloaded |
Property | Description |
---|---|
altKey | Set to true if the Alt key was pressed when the event was triggered, false if not. The Alt key is labeled Option on most Mac keyboards. |
ctrlKey | Set to true if the Ctrl key was pressed when the event was triggered, false if not. |
data | The value, if any, passed as the second parameter to the bind() command when the handler was established. |
keyCode | For keyup and keydown events, this returns the key that was pressed. |
metaKey | Set to true if the Meta key was pressed when the event was triggered, false if not. The Meta key is the Ctrl key on PCs and the Command key on Macs. |
pageX | For mouse events, specifies the horizontal coordinate of the event relative from the page origin. |
pageY | For mouse events, specifies the vertical coordinate of the event relative from the page origin. |
relatedTarget | For some mouse events, identifies the element that the cursor left or entered when the event was triggered. |
screenX | For mouse events, specifies the horizontal coordinate of the event relative from the screen origin. |
screenY | For mouse events, specifies the vertical coordinate of the event relative from the screen origin. |
shiftKey | Set to true if the Shift key was pressed when the event was triggered, false if not. |
target | Identifies the element for which the event was triggered. |
timeStamp | The timestamp (in milliseconds) when the event was created. |
type | For all events, specifies the type of event that was triggered (for example, click). |
which | For keyboard events, specifies the numeric code for the key that caused the event, and for mouse events, specifies which button was pressed (1 for left, 2 for middle, 3 for right) |
Method | Description |
---|---|
preventDefault() | Prevents the browser from executing the default action. |
isDefaultPrevented() | Returns whether event.preventDefault() was ever called on this event object. |
stopPropagation() | Stops the bubbling of an event to parent elements, preventing any parent handlers from being notified of the event. |
isPropagationStopped() | Returns whether event.stopPropagation() was ever called on this event object. |
stopImmediatePropagation() | Stops the rest of the handlers from being executed. |
isImmediatePropagationStopped() | Returns whether event.stopImmediatePropagation() was ever called on this event object. |
selector.html( )
<html> <head> <title>the title</title> <script type="text/javascript" src="/jquery/jquery-1.3.2.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("div").click(function () { var content = $(this).html(); $("#result").text( content ); }); }); </script> <style> #division{ margin:10px;padding:12px; border:2px solid #666; width:60px; } </style> </head> <body> <p>Click on the square below:</p> <span id="result"> </span> <div id="division" style="background-color:blue;"> This is Blue Square!! </div> </body> </html>
selector.replaceWith( content ) |
<html> <head> <title>the title</title> <script type="text/javascript" src="/jquery/jquery-1.3.2.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("div").click(function () { $(this).replaceWith("<h1>JQuery is Great</h1>"); }); }); </script> <style> #division{ margin:10px;padding:12px; border:2px solid #666; width:60px; } </style> </head> <body> <p>Click on the square below:</p> <span id="result"> </span> <div id="division" style="background-color:blue;"> This is Blue Square!! </div> </body> </html>
selector.remove( [ expr ]) or selector.empty( ) |
<html> <head> <title>the title</title> <script type="text/javascript" src="/jquery/jquery-1.3.2.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("div").click(function () { $(this).remove( ); }); }); </script> <style> .div{ margin:10px;padding:12px; border:2px solid #666; width:60px; } </style> </head> <body> <p>Click on any square below:</p> <span id="result"> </span> <div class="div" style="background-color:blue;"></div> <div class="div" style="background-color:green;"></div> <div class="div" style="background-color:red;"></div> </body> </html>
selector.after( content ) or selector.before( content ) |
<html> <head> <title>the title</title> <script type="text/javascript" src="/jquery/jquery-1.3.2.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("div").click(function () { $(this).before('<div class="div"></div>' ); }); }); </script> <style> .div{ margin:10px;padding:12px; border:2px solid #666; width:60px; } </style> </head> <body> <p>Click on any square below:</p> <span id="result"> </span> <div class="div" style="background-color:blue;"></div> <div class="div" style="background-color:green;"></div> <div class="div" style="background-color:red;"></div> </body> </html>
Method | Description |
---|---|
after( content ) | Insert content after each of the matched elements. |
append( content ) | Append content to the inside of every matched element. |
appendTo( selector ) | Append all of the matched elements to another, specified, set of elements. |
before( content ) | Insert content before each of the matched elements. |
clone( bool ) | Clone matched DOM Elements, and all their event handlers, and select the clones. |
clone( ) | Clone matched DOM Elements and select the clones. |
empty( ) | Remove all child nodes from the set of matched elements. |
html( val ) | Set the html contents of every matched element. |
html( ) | Get the html contents (innerHTML) of the first matched element. |
insertAfter( selector ) | Insert all of the matched elements after another, specified, set of elements. |
insertBefore( selector ) | Insert all of the matched elements before another, specified, set of elements. |
prepend( content ) | Prepend content to the inside of every matched element. |
prependTo( selector ) | Prepend all of the matched elements to another, specified, set of elements. |
remove( expr ) | Removes all matched elements from the DOM. |
replaceAll( selector ) | Replaces the elements matched by the specified selector with the matched elements. |
replaceWith( content ) | Replaces all matched elements with the specified HTML or DOM elements. |
text( val ) | Set the text contents of all matched elements. |
text( ) | Get the combined text contents of all matched elements. |
wrap( elem ) | Wrap each matched element with the specified element. |
wrap( html ) | Wrap each matched element with the specified HTML content. |
wrapAll( elem ) | Wrap all the elements in the matched set into a single wrapper element. |
wrapAll( html ) | Wrap all the elements in the matched set into a single wrapper element. |
wrapInner( elem ) | Wrap the inner child contents of each matched element (including text nodes) with a DOM element. |
wrapInner( html | Wrap the inner child contents of each matched element (including text nodes) with an HTML structure. |
selector.css( PropertyName, PropertyValue );Here you can pass PropertyName as a javascript string and based on its value, PropertyValue could be string or integer.
<html> <head> <title>the title</title> <script type="text/javascript" src="/jquery/jquery-1.3.2.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("li").eq(2).css("color", "red"); }); </script> </head> <body> <div> <ul> <li>list item 1</li> <li>list item 2</li> <li>list item 3</li> <li>list item 4</li> <li>list item 5</li> <li>list item 6</li> </ul> </div> </body> </html>
selector.css( {key1:val1, key2:val2....keyN:valN}) |
<html> <head> <title>the title</title> <script type="text/javascript" src="/jquery/jquery-1.3.2.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("li").eq(2).css({"color":"red", "background-color":"green"}); }); </script> </head> <body> <div> <ul> <li>list item 1</li> <li>list item 2</li> <li>list item 3</li> <li>list item 4</li> <li>list item 5</li> <li>list item 6</li> </ul> </div> </body> </html>
<html> <head> <title>the title</title> <script type="text/javascript" src="/jquery/jquery-1.3.2.min.js"></script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("div:first").width(100); $("div:first").css("background-color", "blue"); }); </script> <style> div{ width:70px; height:50px; float:left; margin:5px; background:red; cursor:pointer; } </style> </head> <body> <div></div> <div>d</div> <div>d</div> <div>d</div> <div>d</div> </body> </html>
Method | Description |
---|---|
css( name ) | Return a style property on the first matched element. |
css( name, value ) | Set a single style property to a value on all matched elements. |
css( properties ) | Set a key/value object as style properties to all matched elements. |
height( val ) | Set the CSS height of every matched element. |
height( ) | Get the current computed, pixel, height of the first matched element. |
innerHeight( ) | Gets the inner height (excludes the border and includes the padding) for the first matched element. |
innerWidth( ) | Gets the inner width (excludes the border and includes the padding) for the first matched element. |
offset( ) | Get the current offset of the first matched element, in pixels, relative to the document |
offsetParent( ) | Returns a jQuery collection with the positioned parent of the first matched element. |
outerHeight( [margin] ) | Gets the outer height (includes the border and padding by default) for the first matched element. |
outerWidth( [margin] ) | Get the outer width (includes the border and padding by default) for the first matched element. |
position( ) | Gets the top and left position of an element relative to its offset parent. |
scrollLeft( val ) | When a value is passed in, the scroll left offset is set to that value on all matched elements. |
scrollLeft( ) | Gets the scroll left offset of the first matched element. |
scrollTop( val ) | When a value is passed in, the scroll top offset is set to that value on all matched elements. |
scrollTop( ) | Gets the scroll top offset of the first matched element. |
width( val ) | Set the CSS width of every matched element. |
width( ) | Get the current computed, pixel, width of the first matched element. |