Wednesday, December 17, 2008

In Content Server Explorer, you can create a JSP that is addressable through a Site Entry. For example, create a Content Server Element named my/site/FormResponse and a Site Entry whose RootElement is my/site/FormResponse.jsp - and you can reach that element with a URL such as: http://SERVER/servlet/ContentServer?pagename=my/site/FormResponse. Content Server is the controller (/servlet/ContentServer) that invokes other elements based on the GET arguments sent to it :?pagename=my/site/FormResponse for example.

That's good, but you cannot use that URL directly in a form's action attribute, such as below.

That's because in a form's action attribute, any GET style arguments at the end of the URL are ignored. So the URL invoked from the FORM above would be http://SERVER/servlet/ContentServer. The fix is simple enough. Put the pagename argument in a hidden field, such as below.

Saturday, December 13, 2008

I frequently use this Bash script in Cgywin to easily search for a file by name (using regex), see a list of results and choose which of those results I want to open up in my favourite text editor, like UltraEdit. The script in this post my own wrapper for grep and find that allows me to search through the contents of files, show the results of the search and call the previous script to show me a list of matching files, asking me which ones I want to open.

Purpose. Search through files, show user results and allow user to open any of the files that contained a match.

Friday, December 12, 2008

When I am programming, I often swap between using Eclipse or a Cywin + UltraEdit combination.

In Eclipse, Control+Shift+T is a wild card enabled search for Java files by file name and Control+Shift+R is a wild card enabled search for everything else (plus Java files) by file name - where you can double click on a result to open the file. You also have a file search (with regex) with Control+H.

In Cygwin, I use my own script to regex search for files by name, opening whichever file I need in UltraEdit. I also have a couple of scripts that grep through file contents and pass the result to the above script, which offers me a menu of the results and allows me to choose which of the results to open. I find this incredibly handy for many situations when I want to drop to a command line and search with a regular expression, or when I want a refreshing burst of geeky joy from using a command line.

I find it is easier to use my script on the command line to search through files and open the match I need than it is to use Eclipse's file search.

Recently, I have started to use Vim more and more - a particularly useful skill for times when I need to SSH to a remote *nix box and I don't have an UltraEdit to help me. Like any program, there is a learning curve, but text editors like Vim and Emacs have a steeper curve because there are no GUI menus to explore. However, the reward is arguably higher because as you learn how to use the app, you find so many ways to make your life easier.

I decided to try and match the functionality above using Vim. Here is the way I have found to allow searching for files by name and contents, seeing a list of results and easily opening one of the results.

With these two, I can now very easily run a shell command from within Vim and have the results appear in a new buffer - either a horizontal split or a new tab. For example here are three ways to run the shell command "ls -la" from within Vim:

:Split ls -la
:Tab ls -la
:! ls -la

:Split puts the results in a new horizontal split. :Tab puts the results in a new tab. The third technique is the built in way to run a shell command from within Vim. It hides Vim i.e. shows the command line, runs the command and shows the results in the command line and displays a prompt to go back to Vim: Press ENTER or type command to continue.

Now for the kicker. If I use :Split or :Tab, I can move the cursor to rest within whichever file I am interested in and press gf to open the file.

To find a file within a project's directory tree, ls -la isn't enough: I need the find command. The two examples below are equivalent.

:Find ".*\.css"
:Tab find . -iregex ".*\.css"

The first - much shorter - example uses the last short cut now in my .vimrc file. They both do a recursive regex search for a file through the entire directory tree, beginning from the directory I opened Vim from. Again, I put my cursor within whichever result I am interested in and press gf to open the file - which replaces the search results.

Always looking for shorter shortcuts for common searches, I put this small command in my bin dir: ~/bin/fjg ("fjg" for "find Java then grep").

#!/bin/bash
find . -name "*.java" | grep -i $@

It makes it much easier to search for Java source files quickly. Now I search with a shorter string:

:Tab fjg SomeClass

If I want to search through the contents of the files and select which result file to open, this is easy too:

This page showed me something else very helpful. After I finish editing a file in Vim, I can easily commit the change to Subversion or CVS with a command such as::Split svn commit -m "Comment for my commit." % The % expands to the current filename. Use svn or cvs accordingly: the rest of the command is the same for both.

One of my favourite Firefox plugins is It's All Text! which allows you to use an external editor to edit text areas in a browser page.

One of my favourite text editor (up there with UltraEdit) is vim and gvim. I wanted to use "It's All Text!" with gvim. It is easy enough to point the plugin at the gvim executable, but this meant each time I used the plugin, it would open a new gvim instance.

For Windows, this is the workaround I found to make sure "It's All Text!" would always open in the same gvim instance - opening a new tab each time. Create a cmd file:

Tuesday, December 09, 2008

If it worked, you should see a response like this: CacheServer flushing all pages.

Trouble shooting tips.

If flushing gives you this error: CacheServer : No access allowed for requested action.(Force page flush), check the following.

Are you sure your username and password are correct?

Does that user name have SiteGod ACL?

Are you logged in?

I made some changes and can't see them on refresh! Check your URL. If it is a satellite URL (http://DOMAIN/servlet/Satellite), change Satellite to ContentServer, i.e. http://DOMAIN/servlet/ContentServer and refresh again.

CSElements called by SiteEntry - to cache or not to cache.

If it is static (like some non changing content or maybe a Javascript file), cache it. In the SiteEntry, set "Pagelet Cache Criteria" to "true,*".

If the element is dynamic, i.e. it performs some processing and the output should be different each time, don't cache it. In the SiteEntry, set "Pagelet Cache Criteria" to "false".

See CacheInfo String Syntax section of the developer pdf for a detailed description of how to use this setting.

I said don't cache, but it is! I found (CS 5.5) that when I set my SiteEntry initially to "true,*" and changed it afterwards to "false", it was still being cached. To fix it, I deleted and re-created the SiteEntry.

A few tips and things to watch for with Asset Descriptor Files (ADFs) under Content Server in the FatWire 5.5 Content Manaqement System (CMS). An ADF is the XML file used to define and create a basic asset using the AssetMaker utility. I am not sure how many of these issues are still relevant in newer versions.

General Tips

Keep PROPERTY NAME values all in lower case.

Keep INPUTFORM TYPE values all in upper case.

Date Fields

Here is a sample date field. Note that it allows searching for the date field.

Trouble Shooting

First steps.

Open the XML ADF in a browser like Firefox, which will parse the XML and give you a bit more information about malformed XML.

If a browser like Firefox opens the ADF ok, it should be properly formed XML, which still means it might be breaking a FatWire specific parsing rule i.e. it is valid XML, but not not valid ADF XML. Look at the FatWire documentation on the error numbers for some further clues.

If you are getting a problem with your ADF and you are unable to nail down which property it relates to, start removing properties from your ADF and re-loading it until you find a point at which the error no longer occurs. This means: delete the asset and table from Content Server, modify the ADF to remove one property, re-make the asset, register asset elements and create the table.

The error was: This attempt to delete the asset failed with error -105. The most likely cause is a system configuration error. Please exit the browser, login, and then try the operation again. If the problem persists, please contact your System Administrator.

The issue was a STORAGE TYPE that had to be changed from CHAR to VARCHAR. Here is the changed property.