File:  [mozdev] / bookmarktools / www / documentation.html
Revision 1.17: download - view: text, annotated - select for diffs - revision graph
Fri Feb 6 15:53:16 2009 UTC (10 years, 1 month ago) by maik
Branches: MAIN
CVS tags: HEAD
- page layout changed

<html>
	<head>
		<link rel="stylesheet" href="./project.css" type="text/css" />
		
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<meta content="text/css" http-equiv="Content-Style-Type" />
		
		<script type="text/javascript" src="js/prototype.js"></script>
		<script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script>
		<script type="text/javascript" src="js/lightbox.js"></script>
		
		<script type="text/javascript" src="scripts/shCore.js"></script>
		<script type="text/javascript" src="scripts/shBrushBash.js"></script>
		<script type="text/javascript" src="scripts/shBrushCpp.js"></script>

		<script type="text/javascript" src="scripts/shBrushCSharp.js"></script>
		<script type="text/javascript" src="scripts/shBrushCss.js"></script>
		<script type="text/javascript" src="scripts/shBrushDelphi.js"></script>
		<script type="text/javascript" src="scripts/shBrushDiff.js"></script>
		<script type="text/javascript" src="scripts/shBrushGroovy.js"></script>
		<script type="text/javascript" src="scripts/shBrushJava.js"></script>

		<script type="text/javascript" src="scripts/shBrushJScript.js"></script>
		<script type="text/javascript" src="scripts/shBrushPhp.js"></script>
		<script type="text/javascript" src="scripts/shBrushPlain.js"></script>
		<script type="text/javascript" src="scripts/shBrushPython.js"></script>
		<script type="text/javascript" src="scripts/shBrushRuby.js"></script>
		<script type="text/javascript" src="scripts/shBrushScala.js"></script>

		<script type="text/javascript" src="scripts/shBrushSql.js"></script>
		<script type="text/javascript" src="scripts/shBrushVb.js"></script>
		<script type="text/javascript" src="scripts/shBrushXml.js"></script>
		
		<link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" />
		<link type="text/css" rel="stylesheet" href="styles/shCore.css"/>
		<link type="text/css" rel="stylesheet" href="styles/shThemeDefault.css"/>
		
		<script type="text/javascript">
			SyntaxHighlighter.config.clipboardSwf = 'scripts/clipboard.swf';
			SyntaxHighlighter.all();
		</script>
	</head>
	<body>
	
		<div id="main">
		
			<div id="menu-container">
				<ul id="simple-menu">
					<li><a id="home" href="./index.html" title="Home">Home</a></li>
					<li><a id="download" href="./installation.html" title="Home">Download</a></li>
					<li><a id="docu" href="./documentation.html" title="Home" class="current">Documentation</a></li>
					<li><a id="src" href="./source.html" title="Home">Source Code</a></li>
					<li><a id="bugs" href="./bugs.html" title="Home">Bugs</a></li>
					<li><a id="screenshots" href="./screenshots.html" title="Home">Screenshots</a></li>
				</ul>
			</div>
			
			<div id="content">
			
				<div>
					<h3><a name="Content">Content:</a></h3>
					<ul>
						<li><strong>USER GUIDE</strong></li>
						<li><strong>XPCOM</strong>
							<ul>
								<li><a href="#HowToIndex">HowTo use the index component</a></li>
								<li><a href="#HowToTidy">HowTo use the tidy component</a></li>
							</ul>
						</li>
						<li><strong>OTHER</strong></li>
					</ul>
					<br />
				</div>

				<div class="separator"></div>
				
				<br />

				<h3><a href="#Content"><img src="./images/back.png" alt="back" title="back" /></a><a name="HowToIndex">HowTo use the index component (uses clucene-core-0.9.20)</a></h3>
				<h4>Writing::</h4>
				<pre class="brush: js font-size: 80%">

					//initialize file object (location: profile directory)
					var file = Components.classes["@mozilla.org/file/directory_service;1"]
								.getService(Components.interfaces.nsIProperties)
								.get("ProfD", Components.interfaces.nsIFile);

					file.append("index"); //folder named 'index'
					
					if(!file.exists() || !file.isDirectory()) 
						file.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0777);

					//initialize xpcom
					var writer = Components.classes["@bookmarktools.mozdev.org/search/indexWriter;1"].createInstance();
					writer = writer.QueryInterface(Components.interfaces.ICLWriter);
					
					//set path
					writer.setPath(file.path);
					
					//create index document
					var cl_document = new Object();
					cl_document.primaryKey = "key0";						//this shoud be a unique key
					cl_document.name = "CLucene Indexer";					//document name
					cl_document.lastModifiedDate = new Date().getTime();	//date in millis
					cl_document.content = "Hello World!";					//some content
					
					//append document
					writer.appendDocument(
						cl_document.primaryKey,
						cl_document.name,
						cl_document.lastModifiedDate,
						cl_document.content
					);
					
					//optimize data
					writer.optimize();
					
				</pre>

				<h4>Searching::</h4>
				<pre class="brush: js font-size: 80%">

					//initialize xpcom
					var reader = Components.classes["@bookmarktools.mozdev.org/search/indexReader;1"].createInstance();
					reader = reader.QueryInterface(Components.interfaces.ICLReader);
					
					//set path
					reader.setPath(file.path); //see section 'Writing'
					
					if(reader.exists()){ //check for index data
						
						var query = "Hell*";
						var results = Components.classes["@mozilla.org/array;1"]
										.createInstance(Components.interfaces.nsIMutableArray);
						reader.search(query, results);
						
						var e = results.enumerate();
						while (e.hasMoreElements()) {
							var resultNode = e.getNext().QueryInterface(Components.interfaces.IResultNode);
							
							//Object: resultNode
							//-> resultNode.primaryKey
							//-> resultNode.score
							alert(resultNode.primaryKey + "\n" + resultNode.score);
						}
						
					}else {
						//display message or do nothing
					}
					
				</pre>

				<h4>Lookup::</h4>
				<pre class="brush: js font-size: 80%">

					//initialize xpcom
					var reader = Components.classes["@bookmarktools.mozdev.org/search/indexReader;1"].createInstance();
					reader = reader.QueryInterface(Components.interfaces.ICLReader);
					
					//set path
					reader.setPath(file.path); //see section 'Writing'
					
					var results = Components.classes["@mozilla.org/array;1"]
									.createInstance(Components.interfaces.nsIMutableArray);
					reader.lookup(results);
					
					var e = results.enumerate();
					while (e.hasMoreElements()) {
						var lookupNode = e.getNext().QueryInterface(Components.interfaces.ILookupNode);
						
						//Object: lookupNode
						//-> lookupNode.primaryKey
						//-> lookupNode.name
						alert(lookupNode.primaryKey + "\n" + lookupNode.name);
					}

				</pre>

				<h4>Delete documents::</h4>
				<pre class="brush: js font-size: 80%">

					//initialize xpcom
					var writer = Components.classes["@bookmarktools.mozdev.org/search/indexWriter;1"].createInstance();
					writer = writer.QueryInterface(Components.interfaces.ICLWriter);
					
					//set path
					writer.setPath(file.path); //see section 'Writing'
					
					//delete documents with index 0, 5 and 2
					var docs = [0, 5, 2];
					writer.deleteDocument(docs, docs.length);

				</pre>

				<br />

				<div class="separator"></div>
				
				<h3><a href="#Content"><img src="./images/back.png" alt="back" title="back" /></a><a name="HowToTidy">HowTo use the tidy component (uses ctidy version 060405)</a></h3>
				<h4>Cleanup::</h4>
				<pre class="brush: js font-size: 80%">

					//initialize xpcom
					var tidy = Components.classes["@bookmarktools.mozdev.org/repair/tidy;1"].createInstance();
					tidy = tidy.QueryInterface(Components.interfaces.ITidy);
					
					var src = "
					&lt;html&gt;
						&lt;head&gt;&lt;/head&gt;
						&lt;body
							broken body tag & no entity
						&lt;/body&gt;
					&lt;/html>";
					
					//result contains the repaired html/xhtml/xml source
					//otherwise a error message returned
					var result = tidy.cleanup(src);
					
					if(result == "Tidy: no output"){
						alert("error returned");
					}else {
						alert(src);
					}
					
				</pre>
			</div>
			
		</div>
			
		<div id="footer">
				<div style="text-align: center;">
                    Project hosted on <a href="http://www.mozdev.org/">mozdev.org</a>.<br/> <a href="http://www.mozdev.org/copyright.html">Copyright</a> &copy; 2004. All rights reserved. <a href="http://www.mozdev.org/community/terms.html">Terms of Use</a>.
                </div>
		</div>
	</body>
</html>

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>