Danh mục

Creating Applications with Mozilla-Chapter 10. RDF, RDF Tools, and the Content Model-P5

Số trang: 16      Loại file: pdf      Dung lượng: 31.11 KB      Lượt xem: 1      Lượt tải: 0    
10.10.2023

Hỗ trợ phí lưu trữ khi tải xuống: 15,000 VND Tải xuống file đầy đủ (16 trang) 0

Báo xấu

Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Tham khảo tài liệu creating applications with mozilla-chapter 10. rdf, rdf tools, and the content model-p5, công nghệ thông tin, quản trị web phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả
Nội dung trích xuất từ tài liệu:
Creating Applications with Mozilla-Chapter 10. RDF, RDF Tools, and the Content Model-P5 Chapter 10. RDF, RDF Tools, and the Content Model-P510.1.3.2. Root resourceIn Example 10-11, everything you need to display a datasourcedynamically is present. The only difference between this dynamicallygenerated version and a static RDF-based template is thedatasources=rdf:null, which specifies that the template doesnot refer to an actual datasource. Data that is edited, rearranged, orchanged in a different way is often displayed dynamically in the UIwith templates in this manner.10.5. JSLib RDF FilesWorking with actual RDF files is not easy. However, JSLib(http://jslib.mozdev.org) provides an RDF file library that can help youdevelop an RDF-based application. The library provides many types of errorchecking, as well as a friendly abstraction away from the RDF/XMLinterfaces of Mozilla (see Section 10.3.11, later in this chapter). Example 10-12 shows some common uses of the RDFFile class in JSLib. Thisfunctionality can be used in situations in which you have data in RDF thatyou want to pull out manually and use piece by piece (rather than as awhole datasource in a template).Example 10-12. Creating and modifying an RDF file using JSLibvar rdfFileURL = chrome://jarfly/content/jar.rdf;var gTreeBody = null;var gListbox = null;var gRDF = null;function onload( ){ fileUtils = new FileUtils( ); path = fileUtils.chrome_to_path(rdfFileURL); if(navigator.platform == Win32) { path = path.replace(/\//g,\\); // Only needed on Windows, until JSLib is fixed } gRDF = newRDFFile(path,jar:flies,http://mozdev.org/fly-rdf#); gTreeBody = document.getElementById(tb); gTreeBody.database.AddDataSource(gRDF.dsource); gListbox = document.getElementById(list); gListbox.database.AddDataSource(gRDF.dsource); rebuildLists( );}function rebuildLists( ){ gTreeBody.builder.rebuild( ); gListbox.builder.rebuild( );}function update( ){ name =document.getElementById(nameField).value; color =document.getElementById(colorField).value; quantity =document.getElementById(quantityField).value; seqNumber = -1; del = false; replace = false; if(document.getElementById(delete).checked) del = true; if(document.getElementById(replace).checked) replace = true; var seqLength = 0; if(gRDF.doesSeqExist(types)) { seqLength =gRDF.getSeqSubNodes(types).length; //if(del)gRDF.removeSeq(types,false); } else gRDF.addSeq(types); for(i=0;i gRDF.setAttribute(item,color,color); if(quantity!=) { gRDF.setAttribute(item,quantity,quantity);gRDF.setAttribute(item,dead,calcDead(quantity,replace)); } if(!del) gRDF.addNode(item); else gRDF.removeNode(item); gRDF.flush( ); onload( );}function calcDead(quantity,replace){ if(!replace) { v = parseInt( (quantity * Math.random( )) *0.13 ); return (v.toString( )); } else return 0;}function changeC(color){document.getElementById(colorField).value=color;}function changeQ(quantity){document.getElementById(quantityField).value=quantity;}This example contains a datasource that represents a collection of flies.These flies are built up dynamically with JavaScript objects from the RDFlibrary, which represent the datasource itself (gRDF = new RDFFile),methods that view and update the data(if(gRDF.getAttribute(tempItem,name)==name), andutilities that make work with RDF files easier (path =fileUtils.chrome_to_path(rdfFileURL)).Example 10-13 initializes and updates a file after it changes.Example 10-13. Initializationvar rdfFileURL = chrome://jarfly/content/jar.rdf;var gTreeBody = null;var gListbox = null;var gRDF = null;function onload( ){ fileUtils = new FileUtils( ); path = fileUtils.chrome_to_path(rdfFileURL); if(navigator.platform == Win32) { path = path.replace(/\//g,\\); // Only needed on Windows, until JSLib is fixed } gRDF = newRDFFile(path,jar:flies,http://mozdev.org/fly-rdf#);In Example 10-13, the file URL is set to an RDF file in the chrome area.Note that both a and a , which display the same datain different ways, will be updated with the same datasource. The onloadfunction is called after the main XUL document is loaded. A class calledFileUtils is initialized, which will create a path to the RDF file. If thefile doesnt already exist, JSLib automatically creates it.Finally, the RDFFile is created by using the path and a root resourceidentifier, and the xFly namespace is used for the data references. Example10-14 shows that the RDF file is ready to have its data added and deleted.Example 10-14. Data updatingfunction update( ){ ... var seqLength = 0; if(gRDF.doesSeqExist(types)) { seqLength =gRDF.getSeqSubNodes(types).length; } else gRDF.addSeq(types); for(i=0;i if(seqNumber == -1) { item = types:_ + (seqLength+1); gRDF.setAttribute(item,name,name); gRDF.setAttribute(item,number,seqLength+1); } else { item = types:_ + seqNumber; gRDF.setAttribute(item,number,seqNumber); } if(color!=) gRDF.setAttribute(item,color,color); if(quantity!=) { gRDF.setAttribute(item,quantity,quantity);gRDF.setAttribute(item,dead,calcDead(quantity,replace)); } if(!del) gRDF.addNode(item); else gRDF.removeNode(item); gRDF.flush( ); onload( );Example 10-14 contains a modified version of the update function. First,the function checks to see if a sequence called types is in the RDF file. I ...

Tài liệu được xem nhiều: