This is kind of a fun component…nothing too special, but I think a nice example of something you can do with UCM filter events, specifically the validateCheckinData event. What is does is automatically assign a friendly web file name to site studio content using the title of the item. The funtionality I was trying to emulate is pretty similar to what this blog does. Whenever I post something, WordPress take the title and turns it in to a friendly file name by sort of removing any spaces or funny characters and then adding .htm on the end. Shouldn’t be too hard to do in UCM/Site Studio right?
A little background
In Site Studio there are two types of pages; Primary pages, which are essentially the landing pages for a folder(think home, search and listing pages). They are almost always named index.htm and what’s unique about them is that when they are called they only refence specific content items. Secondary pages, which could be viewed as everything else in a folder differ as they are used in more of traditional templated, delivery fashion, where the content is delivered through a reuseable template. I butchering those descriptions a little for simplicities sack, but for the most part that’s how they work.
Out of the box, Site Studio lets you reference a content item using it’s content id in the url. So if you had a content item called 000525, it would be referenced in a folder with it’s content id at the end(http://SiteStudio.com/site/folder/000525 for example). Since all templates are mapped to thier folder, everything you need to render a page can be found in the URL…it’s all pretty simple. The thing is, what if you aren’t too crazy about the 000525 name though? It’s not really all that intuative of a name; you could make the content id friendly or you could use also take advantage of the SSUrlFieldName property in Site Studio. The SSUrlFieldName property allows you to map a custom metadata field(perhaps one longer than the 30 characters you get for a content id?) as the file name idenifiier used when reference in a URL.
So content item 000525 can also have a metadata field tagged as “autofillthatfriendlyname.htm” and so when refereced as a url, it could look like this: http://SiteStudio.com/site/folder/autofillthatfriendlyname.htm. That’s pretty cool, right? There is a bit of a catch though, like the content id the value used in the friendly name field should be unique. The only problem though is that there’s no automatic validation for the values, so there’s nothing to tell the contributor if they’ve duplicated a value.
What the component does
The code for this component is pretty simple, we’re hooking in to the validateCheckinData event and then basically updating whatever field is identified in the SSUrlFieldName property with a friendly name. I like the validateCheckinData filter quite bit for situations like this where I need to update or add some metadata at check in or update time. If I have to kick a process off or do something to a piece of content that has just been checked in, so after it’s in the system, I usually prefer the afterLoadRecordWebChange, but that’s probably for another post.
Getting back on track, once a piece of content is checked in which has a xWebsiteSection value(meaning it’s been assigned a default URL in a web site), it pulls the dDocTitle value out of the binder and makes it friendly(removes any spaces or special characters I could think of). It then appends a file extension(set in the environmental config) and checks the value against the database. If the friendly name has been used before on another content item it goes back and adds a 1 to the end of the title part of the file name(I know…not very imaginative). Each time the component assembles a name it checks it against a max character count also found in the component’s enviornmental config.
Installing this puppy
The install on this component is not really unlike any other. You of course do need to make sure Site Studio is installed on your content server and that the SSUrlFieldName property has been set in the config.cfg file. I should note that when you set the SSUrlFieldName property, you need to leave the little x prefixing all custom metadata fields off. So no xFieldName formats…just FieldName. You probably will need to tell the component what the size of your friendly name field is. It’s defaulted to 80 characters, so if you plan on using less or more, you might want to update it in the component’s environmental config file.
You can download the component here: Auto Fill Friendly Name


