Chris Pollett > Students >
Rao

    ( Print View )

    [Bio]

    [Project Blog]

    [CS297 Proposal]

    [Del1]

    [Firefox Plugin-PPT]

    [Del2]

    [DOMTest-ZIP]

    [Del3]

    [Del4]

    [Firefox Plugin to match h1 tags-ZIP]

    [CS297-PDF]

    [CS298Proposal-PDF]

    [CS298 Report-PDF]

    [CS298Presentation-PPT]

                          

























Deliverable 4 -- Saving web page contents on desktop

Description:

The fourth deliverable was to save some component of the web page on the users desktop.
A lot of inbuilt Firefox services already exist as components which can be utilized. I found a utility at [6] which had the interfaces for writing the contents to a specified location. Here is a piece of code that writes the passed content to a file. This was embedded in the sample plugin to save the contents of the <body> tag.

function save(mydata) {
	//mydata = 'hELLO VIJAY';
	alert("in save " + mydata);
	try {
		netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
	} catch (e) {
		alert("Permission to save file was denied.");
	}
	var file = Components.classes["@mozilla.org/file/local;1"]
		.createInstance(Components.interfaces.nsILocalFile);
	file.initWithPath( savefile );
	if ( file.exists() == false ) {
		alert( "Creating file... " );
		file.create( Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 420 );
	}
	var outputStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
		.createInstance( Components.interfaces.nsIFileOutputStream );
	/* Open flags 
	#define PR_RDONLY       0x01
	#define PR_WRONLY       0x02
	#define PR_RDWR         0x04
	#define PR_CREATE_FILE  0x08
	#define PR_APPEND      0x10
	#define PR_TRUNCATE     0x20
	#define PR_SYNC         0x40
	#define PR_EXCL         0x80
	*/
	/*
	** File modes ....
	**
	** CAVEAT: 'mode' is currently only applicable on UNIX platforms.
	** The 'mode' argument may be ignored by PR_Open on other platforms.
	**
	**   00400   Read by owner.
	**   00200   Write by owner.
	**   00100   Execute (search if a directory) by owner.
	**   00040   Read by group.
	**   00020   Write by group.
	**   00010   Execute by group.
	**   00004   Read by others.
	**   00002   Write by others
	**   00001   Execute by others.
	**
	*/
	outputStream.init( file, 0x04 | 0x08 | 0x20, 420, 0 );
	//var output = document.getElementById('blog').value;
	alert( "B4 write... " );	
	var result = outputStream.write( mydata, mydata.length );
	alert( "result ... " +  result );		
	outputStream.close();

}