using System;
using System.Collections.Generic;
using System.Text;
using ScrewTurn.Wiki.SearchEngine;
using ScrewTurn.Wiki.PluginFramework;
namespace ScrewTurn.Wiki {
///
/// Represents a page attachment document.
///
public class PageAttachmentDocument : IDocument {
///
/// The type tag for a .
///
public const string StandardTypeTag = "A";
private uint id;
private string name;
private string title;
private string typeTag = StandardTypeTag;
private DateTime dateTime;
private PageInfo page;
private string provider;
///
/// Initializes a new instance of the class.
///
/// The page.
/// The attachment name.
/// The file provider.
/// The modification date/time.
public PageAttachmentDocument(PageInfo page, string name, string provider, DateTime dateTime) {
if(page == null) throw new ArgumentNullException("page");
if(name == null) throw new ArgumentNullException("name");
if(name.Length == 0) throw new ArgumentException("Name cannot be empty", "name");
if(provider == null) throw new ArgumentNullException("provider");
if(provider.Length == 0) throw new ArgumentException("Provider cannot be empty", "provider");
this.name = page.FullName + "|" + provider + "|" + name;
id = Tools.HashDocumentNameForTemporaryIndex(this.name);
title = name;
this.dateTime = dateTime;
this.page = page;
this.provider = provider;
}
///
/// Initializes a new instance of the class.
///
/// The dumped document.
public PageAttachmentDocument(DumpedDocument doc) {
string[] fields = doc.Name.Split('|');
id = doc.ID;
name = doc.Name;
title = doc.Title;
dateTime = doc.DateTime;
provider = fields[0];
page = Pages.FindPage(fields[1]);
}
///
/// Gets or sets the globally unique ID of the document.
///
public uint ID {
get { return id; }
set { id = value; }
}
///
/// Gets the globally-unique name of the document.
///
public string Name {
get { return name; }
}
///
/// Gets the title of the document, if any.
///
public string Title {
get { return title; }
}
///
/// Gets the tag for the document type.
///
public string TypeTag {
get { return typeTag; }
}
///
/// Gets the document date/time.
///
public DateTime DateTime {
get { return dateTime; }
}
///
/// Performs the tokenization of the document content.
///
/// The content to tokenize.
/// The extracted words and their positions (always an empty array).
public WordInfo[] Tokenize(string content) {
return ScrewTurn.Wiki.SearchEngine.Tools.Tokenize(content);
}
///
/// Gets the page.
///
public PageInfo Page {
get { return page; }
}
///
/// Gets the provider.
///
public string Provider {
get { return provider; }
}
}
}