The conception, birth, and first steps of an application named Charlie

Subscribe: Atom or RSS

Getting Entities onto the Page

by Alister Jones (SomeNewKid)

In my last weblog entry, I said that every item of content on a Charlie webpage is based on the Entity System. But how do these business objects get onto the page? For example, how does an Article business object get the chance to display its Title, Summary, and Content properties on the webpage for the visitor to read? The solution to this challenge involved two stages. I will talk about the second stage in the next weblog entry.

The first stage of getting a business object onto the page involved copying the approach taken by Cuyahoga. (If Charlie ever helps me to earn an income, Martijn Boland is going to get a few bucks.)

The very first version of Cuyahoga includes a Node business object. If you picture a sitemap, each page in the sitemap will be represented by a Node business object. Why do we need a Node business object to represent a webpage, when typically we already have an .aspx page? Well, like most website frameworks, Cuyahoga does not include an .aspx file for each and every webpage in a website. Rather, Cuyahoga includes a PageEngine class that dynamically creates the webpages that will be seen by a visitor. Given that there is no actual .aspx page, we need an object that represents that page. That object is the Node object.

Each Node business object will include a collection of Section business objects. As its name suggests, a Section represents one section of the webpage that is represented by the Node.

Each Section object comprises a Module business object. Concrete examples would be an ArticleModule and a BlogModule. The Module class includes a property that “points to” the .ascx User Control needed to display the Article or BlogEntry or other object.

When a visitor requests a page, Cuyahoga’s PageEngine object does the following. First, it gets the appropriate Node object. Then, it loops though each Section object in that Node. For each Section, the PageEngine will get the Module object that belongs to the Section. The Module will be inspected to determine which .ascx User Control it needs added to the page. The PageEngine will load up an instance of the User Control, and will add it to whatever PlaceHolder server control is defined by the Section. The PageEngine will then “give” the User Control its parent Section. This allows the User Control to inspect the Section object and its Module object, in order to know which Article or BlogEntry or other object it is to display.

This is how it worked in version 0.1 of Cuyahoga. A cursory glance at later versions of Cuyahoga suggests that this process has been polished. Whether it has or not is unimportant to dear old Charlie, since the simplicity of this process was just fine for Charlie in the beginning. (I’ll explain my own polishing steps in the next weblog entry.)

I did make some superficial changes to this process, by way of renaming a few of these business objects. If you look back at the UML diagram I originally created, you can follow my thought process.

The second-top object in the hierarchy is a Domain object, which represents an internet domain. The Domain object will include the true domain, such as “example.com”, and may include a collection of aliases, such as “localhost/example”. The Domain object may include other relevant details such as its WHOIS information.

The top object is the Owner, which is of course the owner of that internet domain. The Owner may be a person or an association or a company.

The Resource object represents an internet resource, as per the definition of a URI (Uniform Resource Identifier). The Resource will include little more than an address such as “/toys/elmo”.

A resource, or web address, points to a Document object. Cuyahoga uses a Node object, but Charlie and I prefer to call this a Document object. After all, each file returned from a domain includes a description of its document-type (such as “text/html” or “image/jpeg”). So that was a superficial change I made from the business objects used in Cuyahoga.

Each Document will use a Template that provides the structure of the document. If I were making best use of ASP.NET version 2.0, this would be implemented by way of a MasterPage. However, I have elected to follow Cuyahoga’s example and use a simple .ascx User Control.

A Template will be divided into Sections, such as “header”, “content”, and “footer”. This is not the same meaning as Section in Cuyahoga, so this too represents a variation. To my mind, a section of a webpage document is a visible “area” of that webpage, and into that section can go many different things (into the “header” section can go the logo, the search box, and the navigation bar). In Cuyahoga, each Section includes only one Module, so I found this term caused me a little confusion. So in Charlie, a Section means one area of the Template that structures a Document, into which any number of things can be placed.

Into each Section a collection of Container objects will be added. A Container contains one, and only one, item of Content. (So Charlie’s Container object has the same purpose as the Section object in Cuyahoga.)

A Content object displays an item of content, such as an Article or a BlogEntry.

An Asset is the item of content that is displayed by a Content object, such as the Article or the BlogEntry. If you find the distinction between a Content object and an Asset object a little unclear, you’re not alone. As I was developing Charlie, I found no use for the Content object, so I removed it from Charlie’s code. The fact that I had included a useless class in my UML diagram shows that the diagram is faulty. Still, this weblog entry is an honest account of Charlie’s development, errors and all.

So there you have a long description of how Charlie gets a business entity, such as an Article or a BlogEntry, onto the webpage that is returned to the visitor. Aren’t you glad you asked? Oh, you didn’t ask? Hell, then I’m sorry to have provided such a boring description. If I provide a sexy picture, will you forgive me? I thought so.

You don’t find saucy photos like that everyday on the internet, do you?

by Alister Jones | Next up: The Presenter Object

0 comments

----