By: Paul S. Cilwa Viewed: 12/17/2018
Posted: 8/3/2018
Topics/Keywords: #Computers #Programming #Organica #VB.NET Page Views: 188
The base class for all Organica documents.

The Document class provides the basic functionality for all documents, including being able to create objects of the appropriate document type. It is the base class for all the document types. It also does double duty as the default class for unrecognized document types.

Documents.vb (append)

Public Class Document Public Visible As Boolean = True Public IconPath As String Private i_Pathname As String Private i_FileInfo As FileInfo
Public Shared Function CreateObject(a_Pathname As String) As Document

This function is called to create the appropriate type of document being accessed. It determines this by calling the DocumentType function, defined below.

Dim Test As New Document(a_Pathname) Select Case Test.DocumentType Case DocumentTypes.organica_Folder Return New FolderDocument(a_Pathname) Case DocumentTypes.organica_Profile Return New ProfileDocument(a_Pathname) Case DocumentTypes.organica_Link Return New LinkDocument(a_Pathname) Case Else Return New Document(a_Pathname) End Select Return Test End Function
Public ReadOnly Property IsFolder As Boolean

This property examines flags to determine if the document being examined is, in fact, a Windows folder. If so, then it should be treated as a Folder object.

Get Return (File.GetAttributes(Pathname) And _ FileAttributes.Directory) = FileAttributes.Directory End Get End Property
Private ReadOnly Property DocumentType As DocumentTypes

This property returns the type of document being examined. Currently, the only two possibilities are a Folder, or a Profile (also known as an ".INI" file). But, obviously, we'll be adding many more document types later.

Get If IsFolder Then Return DocumentTypes.organica_Folder End If Select Case i_FileInfo.Extension.ToLower Case ".ini" Return DocumentTypes.organica_Profile End Select Return DocumentTypes.organica_Unknown End Get End Property
Public Sub New(ByVal a_Pathname As String)

Creating a new object of a Document class requires a pathname. If the pathname is, in fact, the name of a Windows Library, the name is parsed accordingly.

i_FileInfo = New FileInfo(a_Pathname) i_Pathname = i_FileInfo.FullName End Sub
Public ReadOnly Property Pathname As String Get Return i_Pathname End Get End Property
Public Overridable Overloads ReadOnly Property Filename As String Get Return i_FileInfo.Name End Get End Property
Public ReadOnly Property Extension As String Get Return i_FileInfo.Extension End Get End Property
Public ReadOnly Property IsTemporary As Boolean Get Return (File.GetAttributes(Pathname) And FileAttributes.Temporary) = FileAttributes.Temporary End Get End Property
Public ReadOnly Property IsSystem As Boolean Get Return (File.GetAttributes(Pathname) And FileAttributes.System) = FileAttributes.System End Get End Property
Public ReadOnly Property IsHidden As Boolean Get Return (File.GetAttributes(Pathname) And FileAttributes.Hidden) = FileAttributes.Hidden End Get End Property
Public ReadOnly Property IsReadOnly As Boolean Get Return (File.GetAttributes(Pathname) And FileAttributes.ReadOnly) = FileAttributes.ReadOnly End Get End Property
Public ReadOnly Property Exists As Boolean Get Return File.Exists(Pathname) End Get End Property
Public ReadOnly Property DateCreated As Date Get Return File.GetCreationTime(Pathname) End Get End Property
Public Overridable Overloads Sub Populate()

This dummy stub exists to allow derived classes to implement this procedure to load the data of a Document.

End Sub
Public Overridable Overloads Function Find(ByVal Key As String) As Document

This dummy stub exists to allow derived classes to implement this procedure to locate any specific piece of data in a Document.

Return Nothing End Function
Public Overridable Overloads ReadOnly Property RenderHeader As String

This procedure, which will be overridden in derived Document types, simply provides the HTML required to display essential properties of this Document. (Remember, the generic Document class is, essentially, an "undefined" document type.

Get Dim Buffer As String Buffer = "<div class=organica_Document>" ConCat(Buffer, "<img src=TypeUnknown.png><div>") ConCat(Buffer, "<h1>" & Filename & "</h1>") ConCat(Buffer, "<p>" & Pathname & "</p>") ConCat(Buffer, "</div>") Return Buffer End Get End Property
Public Overridable Overloads ReadOnly Property RenderContent As String Get Return "" End Get End Property
Public Overridable Overloads ReadOnly Property RenderProperties As String Get Return "" End Get End Property
End Class