}
}
else if (contextFunction.equals("area")) {
WGArea area = db.getArea(contextExpression);
if (area == null) {
context.setLastError("No area of name '" + contextExpression + "'");
return errorReturnContext;
}
WGContent content = navigator.getRootContent(area);
if (content != null) {
return context.getTMLContextForDocument(content);
}
else {
context.setLastError("No root content in area '" + contextExpression + "'");
return errorReturnContext;
}
}
else if (contextFunction.equals("query")) {
if (context.getDesignContext().getTag() == null) {
context.setLastError("Cannot retrieve tag because this script does not run on a WebTML page");
return errorReturnContext;
}
BaseTagStatus tag = context.getDesignContext().getTag().getTagStatusById(contextExpression);
if (tag != null && tag instanceof Query.Status) {
Query.Status queryTag = (Query.Status) tag;
WGContent content = queryTag.getFirstContent();
if (content != null) {
return context.getTMLContextForDocument(queryTag.getFirstContent());
}
else {
context.setLastError(
"Could not retrieve context by query tag \"" + contextExpression + "\". Query had no result.");
return errorReturnContext;
}
}
else {
context.setLastError("No query tag with id: " + contextExpression);
return errorReturnContext;
}
}
else if (contextFunction.equals("role")) {
setRole(contextExpression);
return context;
}
else if (contextFunction.equals("relation")) {
WGContent relationContent = context.content().getRelation(contextExpression);
if (relationContent != null) {
return context.getTMLContextForDocument(relationContent);
}
else {
context.setLastError("Content " + context.meta("KEY") + " has no relation named '" + contextExpression + "'");
return errorReturnContext;
}
}
else if (contextFunction.equals("level")) {
int level;
try {
level = Integer.parseInt(contextExpression);
}
catch (NumberFormatException e) {
context.setLastError("Cannot be parsed as level number: " + contextExpression);
return errorReturnContext;
}
WGContent con = context.content();
if (!con.hasCompleteRelationships()) {
context.setLastError("Current content does not belong to a page hierarchy");
return errorReturnContext;
}
WGStructEntry struct = con.getStructEntry();
while (struct != null && struct.getLevel() > level) {
struct = struct.getParentEntry();
}
if (struct != null) {
WGContent targetCon = _languageChooser.selectContentForPage(struct, isBI);
if (targetCon != null) {
return context.getTMLContextForDocument(targetCon);
}
else {
context.setLastError("Page on level " + level + " has no appropriate content document");
return errorReturnContext;
}
}
else {
context.setLastError("Failed to go to page level " + level);
return errorReturnContext;
}
}
else if (contextFunction.equals("np")) {
String namePart = UniqueNamePartFormatter.INSTANCE.format(contextExpression);
String uname = context.content().getUniqueName();
if (WGUtils.isEmpty(uname)) {
uname = context.content().getStructEntry().getUniqueName();
}
String fullname;
if (!WGUtils.isEmpty(uname)) {
fullname = uname + "." + namePart;
}
else {
fullname = namePart;
}
WGContent content = _languageChooser.selectContentForName(context.content().getDatabase(), fullname, context.isbrowserinterface());
if (content != null) {
return context.getTMLContextForDocument(navigator.chooseRelevantContent(content, mainContent));
}
context.setLastError("Could not retrieve content for hdb unique name " + fullname);
return errorReturnContext;
}
// From here special functions for BI
else if (contextFunction.equals("$struct")) {
WGStructEntry entry = db.getStructEntryByKey(contextExpression);
if (entry != null) {
return context.getTMLContextForDocument(entry);
}
else {
context.setLastError("Could not retrieve struct entry with key '" + contextExpression + "'");
return errorReturnContext;
}
}
else if (contextFunction.equals("$area")) {
WGArea area = db.getArea(contextExpression);
if (area != null) {
return context.getTMLContextForDocument(area);
}
else {
context.setLastError("Could not retrieve area with name '" + contextExpression + "'");