Class Item

Inheritance Relationships

Derived Type

Class Documentation

class Item

Item represent data to be added to the archive.

This is a abstract class the user need to implement. libzim provides BasicItem, StringItem and FileItem to simplify (or avoid) this reimplementation.

Subclassed by zim::writer::BasicItem

Public Functions

virtual std::string getPath() const = 0

The path of the item.

The path must be absolute. Path must be unique.

Returns:

the path of the item.

virtual std::string getTitle() const = 0

The title of the item.

Item’s title is indexed and is used for the suggestion system. Title don’t have to be unique.

Returns:

the title of the item.

virtual std::string getMimeType() const = 0

The mimetype of the item.

Mimetype is store within the content. It is also used to detect if the content must be compressed or not.

Returns:

the mimetype of the item.

virtual std::unique_ptr<ContentProvider> getContentProvider() const = 0

The content provider of the item.

The content provider is responsible to provide the content to the creator. The returned content provider must stay valid even after creator release its reference to the item.

This method will be called once by libzim, in the main thread (but will be used in a different thread). The default IndexData will also call this method once (more) in the main thread (and use it in another thread).

Returns:

the contentProvider of the item.

virtual std::shared_ptr<IndexData> getIndexData() const

The index data of the item.

The index data is the data to index. (May be different from the content to store). The returned index data must stay valid even after creator release its reference to the item. This method will be called once by libzim if it is compiled with xapian (and is configured to index data).

The returned IndexData will be used as source to index the item. If you don’t want the item to be indexed, you can return a nullptr here or return a valid IndexData pointer which will return false to hasIndexData.

If you don’t implement this method, a default implementation will be used. The default implementation first checks for the mimetype and if the mimetype contains text/html it will use a contentProvider to get the content to index. The contentProvider will be created in the main thread but the data reading and parsing will occur in a different thread.

All methods of IndexData will be called in a different (same) thread.

Returns:

the indexData of the item. May return a nullptr if there is no indexData.

virtual Hints getHints() const

Hints to help the creator takes decision about the item.

For now two hints are supported:

  • COMPRESS: Can be used to force the creator to put the item content in a compressed cluster (if true) or not (if false). If the hint is not provided, the decision is taken based on the mimetype (textual or binary content ?)

  • FRONT_ARTICLE: Can (Should) be used to specify if the item is a front article or not. If the hint is not provided, the decision is taken based on the mimetype (html or not ?)

Returns:

A list of hints.

Hints getAmendedHints() const

Returns the getHints() amended with default values based on mimetypes.

virtual ~Item() = default