home | products | community | about aQtive | download | help
community > developers > developers pack > XML Qbits > intranets

Recipes to extend onCue

have an aQtive Intranet!

Think what onCue can do for your Intranet or Extranet. onCue can take you from a customer reference directly to the customer details on your Intranet site. On your customer's desks, onCue can take them from a product name to the ordering details for that product, or from a product category straight to the relevant page in your online catalogue.

Much of this can be achieved using the mechanisms described in go to specific web pages on given keywords, add links to Internet searches and services and aQtivate your own web site with onCue, for example, going to specific company pages on different keywords and rapidly accessing Intranet search facilities.

However, as an Intranet or Extranet developer, you are also likely to be dealing with specific codes and reference numbers. Let's see how you can make onCue work with these.

Note that to distribute Qbits on an Intranet, other than for demonstration purposes, you will usually need to obtain a commercial licence. See your licence agreement in the onCue help for details or contact developers@aqtive.com.

about regular expressions

As well as being able to recognise keywords and built-in types, such as names and email addresses, the XML Qbits can be used to recognise regular expressions. If you have programmed CGI scripts in Perl, worked with UNIX or used certain powerful program editors, you may have come across regular expressions before. Regular expressions allow you to describe text patterns.

For example, a customer code may always start with a C, followed by a single lowercase or uppercase letter, followed by four to six digits, e.g. CX5682 or Ca15729. The regular expression for this is:

    C[A-Za-z][0-9]{4,6}

The regular expression is matched against a target word from left to right. A plain letter or digit on its own in the regular expression means an exact match. So the first letter must be a 'C' as required. Letter ranges in square brackets [] mean one of the letter range. So [A-Za-z] means a single upper or lower case letter. The next part is [0-9], which means a digit, but it is immediately followed by {4,6}. This is a modifier, so instead of meaning exactly one digit, [0-9]{4,6} means between four and six digits.

The default action for regular expression matches is to look for a match anywhere in the target (unlike keyword matching). However, this would mean that xCz123456789 would match because it contains Cz123456, which is a valid customer code. To prevent this, you can prefix the regular expression with a carat ^, which means 'must start at the beginning', and end it with a dollar $, which means 'must finish at the end'.

    ^C[A-Za-z][0-9]{4,6}$

This is usually a bit too strong, as you have to avoid selecting spaces around the target word. To allow trailing and leading spaces \s* is often added to the beginning and end of a regular expression. This means ignore any number (the asterisk * means 'any number') of spaces (the \s means a space).

    ^\s*C[A-Za-z][0-9]{4,6}\s*$

Here are some other examples of regular expressions:

    ^\s*GR/[0-9]{5}x?\s*$

This is another reference number example. It starts with "GR/" then has exactly five digits [0-9]{5}, possibly followed by a single letter x - the question mark says the preceding thing is optional (like * and {}, it follows the thing it applies to). Like the previous regular expression, this one has optional space surrounding it. Examples include GR/56789, GR/12245x.

Here's another one:

    ^\s*([0-3]?[0-9])[-/]([0-3]?[0-9])[-/]([0-9]{2}|[0-9]{4})\s*$

This recognises dates in a number of forms, e.g. 12/12/99, 3-7-1997, 01/01/2000
Notice the bit that says [-/]. This means: either a hyphen or slash. The [] construct can have any list of characters in it, but of course hyphen has a special meaning as in [0-9], so if you want to have a hyphen it needs to go at the front to tell the regular expression it is not a letter range! Also new are round brackets, which simply group things together, and the vertical bar. This means 'either/or'. So the end part of the regular expression
([0-9]{2}|[0-9]{4}) means either exactly two digits or exactly four digits.

Regular expressions are quite difficult to get right, even when you understand them well. The best thing is to start with simple examples and then work up to what you really want.

See UNIX or Perl books for more detailed explanations of regular expressions, but beware, there are variants, so don't expect them all to work identically. You may find the regular expressions section of the Perl Frequently Asked Questions document useful.

adding your own types

OK, now you are in a position to make a Qbit with a custom type - let's say the customer order code we had earlier:

    ^\s*(C[A-Za-z][0-9]{4,6})\s*$

Note that an extra set of brackets has been added around the whole reference code. Put these around the bit you want included into your search URL. We'll see why in a moment.

Open a regular-expression-template page. If you have been through the simpler examples, you will be used to these templates by now. The only thing that is new is **regexp** where you put the regular expression. Note, however, the **webpage**, which must be the search URL, with $0 where you want the customer code and any special characters translated, just as in add links to Internet searches and services.

The only other line worth mentioning at this point is:

    <Field Name="code" Expand="Yes">$1</Field>

You don't need to understand this to produce the Qbit, so skip the rest of this paragraph if you like. The $1 means take the contents of the first bracketed expression. In the example above, this would be the straight customer number. You can in fact have several named 'Field's corresponding to different bracketed parts of the expression by using several <Field ...> lines with different names and $2, $3, etc, for different parts of your regular expression, for example to split a date into day, month and year. You can see an example of this in the date example file.

Having filled in the blanks (or rather **blanks**) in the template, save it as customer.xml which should look something like this. Then proceed with adding your XML Qbit to onCue as in other recipes.

having several menu items for the same type

Take another look at the date example file. Towards the end of it you will see two <URL ...> lines.

In fact, you can have any number of these lines between <For ...> and </For>. Each one corresponds to a different suggested service and will appear as a separate menu entry for your Qbit. In this example, the regular expression can't tell whether the date is in US or UK format, so offers to use it in either way.

Think now of customer codes. There will be various Intranet-connected databases keyed on customer codes. You can either write several different Qbits, one for each database, or instead write one or more Qbits with several menu options.

turbocharging your Intranet

With Qbits written in Java it is possible to 'screen scrape' web pages to deliver information directly from onCue menus, or access databases directly. Watch our developers pages for ongoing information on the Java Qbit API, or contact aQtive corporate services for details on commercial licences and consultancy.

deploying your onCue XML Qbits

Read giving your Qbits to others for details on how to distribute XML Qbits.

If you want to deploy onCue in your own Intranet/Extranet or use it to develop web-based services for others, contact aQtive corporate services for details on licencing and partnering.


More recipes to extend onCue


home | products | community | about aQtive | download | help