Danh mục

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

Số trang: 19      Loại file: pdf      Dung lượng: 34.43 KB      Lượt xem: 1      Lượt tải: 0    
Hoai.2512

Hỗ trợ phí lưu trữ khi tải xuống: 7,000 VND Tải xuống file đầy đủ (19 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-p4, 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-P4 Chapter 10. RDF, RDF Tools, and the Content Model-P4When you create RDF statements with assertions or work with in-memorydatasources, it is often difficult to remember the shape of the graph, whichstatements exist about which resources, or which objects are attached towhich subjects. These getter methods can help you verify the shape ofyour graph.10.3.6. nsIRDFRemoteDataSourceThe Section 10.3.3 section (earlier in this chapter) showed how to load adatasource from a remote server simply. If you want control over thatdatasource, you can manage it by using the nsIRDFRemoteDatasource to setup a remote datasource:xml = @mozilla.org/rdf/datasource;1?name=xml-datasource;datasource = Components.classes[xml].createInstance(Components.interfaces.nsIRDFRemoteDataSource);datasource.Init(http://books.mozdev.org/file.rdf);datasource.Refresh(false);In this example, the Init and Refresh methods control the datasource onthe server. In addition to these methods, you can call the Flush method toflush the data thats been changed and reload, or you can check whether thedatasource is loaded by using the loaded property:if (datasource.loaded) { // Do something}Built-in datasources that implement nsIRDFRemoteDataSource (and othernecessary interfaces) and do their own data handling include:@mozilla.org/rdf/datasource;1?name=history@mozilla.org/browser/bookmarks-service;1@mozilla.org/autocompleteSession;1?type=history@mozilla.org/browser/global-history;1@mozilla.org/rdf/datasource;1?name=bookmarks10.3.7. nsIRDFPurgeableDataSourceUsing the nsIRDFPurgeableDatasource interface allows you to delete awhole section of an existing in-memory datasource in one fell swoop. Thismeans that all relatives -- all statements derived from that node -- areremoved. When you work with large in-memory datasources (such as emailsystems), the using interface can manipulate the data efficiently. TheSweep( ) method can delete a section that is marked in the datasource.datasource.QueryInterface(Components.interfaces.nsIRDFPurgeableDataSource);rootSubject = RDF.GetResource(urn:root);predicate =RDF.GetResource(http://books.mozdev.org/rdf#chapters);object = RDF.GetResource(Chapter1);datasource.Mark(rootSubject,predicate,object,true);datasource.Sweep( );In this instance, a statement about a chapter in a book is marked and thenremoved from the datasource. You can also mark more than one node beforesweeping.10.3.8. nsIRDFNode, nsIRDFResource, and nsIRDFLiteralThese types of objects come from only a few different places. Here are allthe functions that can return the resource of a literal:nsIRDFService.GetResourcensIRDFService.GetAnonymousResourcensIRDFService.GetLiteralnsIRDFDataSource.GetSourcensIRDFDataSource.GetTargetnsIRDFNode is the parent of nsIRDFResource and nsIRDFLiteral. It is notused often because its sole function is to test equality:isEqual = resource1.EqualsNode(resource2);The other two interfaces inherit this function automatically. EqualsNodetests the equivalency of two resources, which can be useful when you try toput together different statements (e.g., Eric wrote a book and [This] bookis about XML) and want to verify that a resource like book is the same inboth cases.10.3.8.1. nsIRDFResourceLike nsIRDFNode, nsIRDFResource is a minimalist interface. Here are thefunctions and the property available in a resource from the nsIRDFResourceinterface:resource = RDF.GetAnonymousResource( );// get the resource value, something likerdf:#$44RG7resourceIdentifierString = resource.Value;// compare the resource to an identifierisTrue =resourceEqualsString(resourceIdentifierString);// Give the resource a real name.resource.Init(Eric);10.3.8.2. nsIRDFLiteralA literals value can be read but not written. To change the value of a literal,make a new literal and set it properly:aValue = literal.Value;Note that aValue could be a string or an integer in this case. The base typeconversion, based on the datas format, is done automatically.10.3.9. nsIRDFContainerUtilsThis interface facilitates the creation of containers and provides othercontainer-related functions. It provides functions that make and work with asequence, bag, and alternative. (The functions work the same wayfor all types of containers, so only sequence is covered here.) To create aninstance of nsIRDFContainerUtils, use the following:containerUtils =Components.classes[@mozilla.org/rdf/container-utils;1].getService(Components.interfaces.nsIRDFContainerUtils);Once you create an anonymous resource, you can create a sequence from it.Then you can test the type of the container and see whether its empty:// create an anonymous resourceanonResource = RDF.GetAnonymousResource( );// create a sequence from that resourceaSequence =containerUtils.MakeSeq(datasource,anonResource);// test the resource// (all of these are true)isContainer =containerUtils.isContainer(datasource,anonResource);isSequence =containerUtils.isSequence(datasource,anonResource);isEmpty =containerUtils.isEmpty(datasource,anonResource);Note that the sequence object is not passed into the functions performing thetest in the previous example; the resource containing the sequence is passedin. Although aSequence and anonResource are basically the sameresource, their data types are different. isContainer, isSequence, andisEmpty can be used more easily with other RDF functions when aresource is used as a parameter:object =datasource.GetTarget(subject,predicate,true);if(RDF.isAnonymousResource(object)){ isSeq = containerUtils.IsSeq(datasource,object);}The RDF container utilities also provide an indexing function. indexOf isuseful for checking if an element exists in a container reso ...

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