Styles styles = pageContext.getStylingEngine().getStyles();
processMenuItemStyles(attributes, styles);
MenuModelBuilder builder = pageContext.getMenuBuilder();
try {
// Start a new menu item
builder.startMenuItem();
// Start a new menu label
builder.startLabel();
// Start a new menu text
builder.startText();
// Set the text by constructing an artificial output buffer from
// the text attribute
// NB: The allocation mechanism must be compatible with the
// de-allocation mechanism used in
// {@link MenuElement#releaseLabelOutputBuffers}
OutputBuffer text = pageContext.getProtocol().
getOutputBufferFactory().createOutputBuffer();
text.writeText(attributes.getText());
builder.setText(text);
// End the menu text
builder.endText();
// OK, get the attributes from PAPI
String onImage = attributes.getOnImage();
String offImage = attributes.getOffImage();
String rolloverImage = attributes.getRolloverImage();
String image = attributes.getImage();
// Set the normal (on) and over (off) images
setNormalAndOverImages(pageContext, onImage, offImage,
rolloverImage, image);
// Create the menu icon on the builder
if (normal != null) {
// Start a new menu icon
builder.startIcon();
// Set the values
builder.setNormalImageURL(normal);
if (over != null) {
builder.setOverImageURL(over);
}
// End the menu icon
builder.endIcon();
}
// End the menu label;
builder.endLabel();
// Set the stylistic information in the model for this element.
MenuInternals.setElementDetails(builder, attributes,
styles);
// Set the segment
builder.setSegment(attributes.getSegment());
// Set the target
builder.setTarget(attributes.getTarget());
// Set the event handling
MenuInternals.setEvents(builder, attributes, pageContext);
// Set the pane attribute
MenuInternals.setPane(builder, attributes.getPane(), pageContext);
// Initialise the attributes specific to this field.
String accessKey = attributes.getAccessKey();
String shortcut = attributes.getShortcut();
if (shortcut != null) {
if (accessKey != null) {
throw new PAPIException(exceptionLocalizer.
format(
"menu-building-shortcut-and-accesskey-error"));
}
} else {
shortcut = accessKey;
}
PolicyReferenceResolver resolver =
pageContext.getPolicyReferenceResolver();
// Process the shortcut
TextAssetReference shortcutObj =
resolver.resolveQuotedTextExpression(shortcut);
builder.setShortcut(shortcutObj);
//Process the href as a mariner expression
LinkAssetReference href = resolver.resolveQuotedLinkExpression(
attributes.getHref(), PageURLType.MENU_ITEM);
builder.setHref(href);
// Process the prompt as a mariner expression
TextAssetReference prompt = resolver.resolveQuotedTextExpression(
attributes.getPrompt());
builder.setPrompt(prompt);
// Set the title.
builder.setTitle(attributes.getTitle());
} catch (BuilderException be) {
logger.error("menu-building-error", be);
throw new PAPIException(
exceptionLocalizer.format("menu-building-error"), be);