}
protected boolean innerTestCondition() {
TMLContext context = this.getTMLContext();
context.setrole(this.getRole());
try {
WGContent content = context.content();
String attValue;
attValue = this.getIstrue();
if (attValue != null) {
if (!context.istrue(attValue)) {
return false;
}
}
attValue = this.getIsfalse();
if (attValue != null) {
if (!context.isfalse(attValue)) {
return false;
}
}
attValue = this.getIsdefined();
if (attValue != null) {
if (!context.isdefined(attValue)) {
return false;
}
}
attValue = this.getCondition();
if (attValue != null) {
ExpressionEngine engine = ExpressionEngineFactory.getEngine(this.getConditionlanguage());
if (engine == null) {
this.addWarning("Unknown expression language: " + this.getConditionlanguage(), true);
return false;
}
Map objects = new HashMap();
objects.put(RhinoExpressionEngine.PARAM_SCRIPTNAME, "Condition on " + getTagDescription());
ExpressionResult result = engine.evaluateExpression(attValue, this.getTMLContext(), ExpressionEngine.TYPE_EXPRESSION, objects);
if (result.isError()) {
addExpressionWarning(attValue,result);
return false;
}
else if (result.isFalse()) {
return false;
}
}
attValue = this.getIsselected();
if (attValue != null) {
boolean isSelected = context.isselected();
if (this.stringToBoolean(attValue) == false) {
isSelected = !isSelected;
}
if (isSelected == false) {
return false;
}
}
attValue = this.getHaschildren();
if (attValue != null) {
boolean hasChildren = context.haschildren();
if (this.stringToBoolean(attValue) == false) {
hasChildren = !hasChildren;
}
if (hasChildren == false) {
return false;
}
}
attValue = this.getHassiblings();
if (attValue != null) {
boolean hasSiblings = context.hassiblings();
if (this.stringToBoolean(attValue) == false) {
hasSiblings = !hasSiblings;
}
if (hasSiblings == false) {
return false;
}
}
attValue = this.getHasoption();
if (attValue != null) {
if(!context.hasoption(attValue))
return false;
}
attValue = this.getIsroot();
if (attValue != null) {
boolean isRoot = context.isroot();
if (this.stringToBoolean(attValue) == false) {
isRoot = !isRoot;
}
if (isRoot == false) {
return false;
}
}
attValue = this.getIscurrentdocument();
if (attValue != null) {
boolean isCurrentDocument = context.ismaindocument();
if (this.stringToBoolean(attValue) == false) {
isCurrentDocument = !isCurrentDocument;
}
if (isCurrentDocument == false) {
return false;
}
}
attValue = this.getHasurlparameter();
if (attValue != null) {
String urlParam = this.pageContext.getRequest().getParameter(attValue);
boolean hasUrlParameter = (urlParam != null ? true : false);
if (hasUrlParameter == false) {
return false;
}
}
attValue = this.getHasnextpage();
if (attValue != null) {
IterationTagStatus iterationTag = (IterationTagStatus) this.getTagStatusById(attValue, IterationTagStatus.class);
if (iterationTag == null) {
this.addWarning("Could not find iteration tag: " + this.getHasnextpage());
return false;
}
if (!iterationTag.hasNextPage()) {
return false;
}
}
attValue = this.getHaspreviouspage();
if (attValue != null) {
IterationTagStatus iterationTag = (IterationTagStatus) this.getTagStatusById(attValue, IterationTagStatus.class);
if (iterationTag == null) {
this.addWarning("Could not find iteration tag: " + attValue);
return false;
}
if (!iterationTag.hasPreviousPage()) {
return false;
}
}
attValue = this.getIscontextvalid();
if (attValue != null) {
boolean iscontextvalid = !this.isChildContextErrornous();
if (this.stringToBoolean(attValue) == false) {
iscontextvalid = !iscontextvalid;
}
if (iscontextvalid == false) {
return false;
}
}
attValue = this.getIstagidvalid();
if (attValue != null) {
boolean istagidvalid = (this.getTagStatusById(attValue) != null ? true : false);
if (istagidvalid == false) {
return false;
}
}
attValue = this.getPlatform();
if (attValue != null) {
if (!attValue.equalsIgnoreCase("wgpublisher")) {
return false;
}
}
attValue = this.getDoctype();
if (attValue != null) {
if (content.getStructEntry() == null || content.getStructEntry().getContentType() == null) {
return false;
}
if (!attValue.equalsIgnoreCase(content.getStructEntry().getContentType().getName())) {
return false;
}
}
attValue = this.getIsbrowserinterface();
if (attValue != null) {
boolean isBI = context.isbrowserinterface();
if (this.stringToBoolean(attValue) == false) {
isBI = !isBI;
}
if (isBI == false) {
return false;
}
}
attValue = this.getIseditmode();
if (attValue != null) {
boolean isEditmode = (context.isbrowserinterface() && content.getStatus().equals(WGContent.STATUS_DRAFT));
if (this.stringToBoolean(attValue) == false) {
isEditmode = !isEditmode;
}
if (isEditmode == false) {
return false;
}
}
attValue = this.getIsnewsession();
if (attValue != null) {
boolean isNewSession = context.isnewsession();
if (this.stringToBoolean(attValue) == false) {
isNewSession = !isNewSession;
}
if (isNewSession == false) {
return false;
}
}
attValue = this.getPortletmode();
if (attValue != null) {
List modesToTest = WGUtils.deserializeCollection(attValue.toLowerCase(), ",", true);
HttpSession session = this.pageContext.getSession();
TMLPortlet portlet = context.getportlet();
if (portlet == null) {
addWarning("Portlet mode was tested although no portlet was registered", false);
return false;
}
String portletMode = portlet.getmode();
if (!modesToTest.contains(portletMode.toLowerCase())) {
return false;
}
}
attValue = this.getHasprofile();
if (attValue != null) {
boolean hasProfile = context.hasprofile();
if (this.stringToBoolean(attValue) == false) {
hasProfile = !hasProfile;
}
if (hasProfile == false) {
return false;
}
}
attValue = this.getLanguage();
if (attValue != null) {
String prefLanguage = getTMLContext().getpreferredlanguage();
if (prefLanguage == null) {
prefLanguage = (String) getTMLContext().meta("language");
}
if (!prefLanguage.equals("attValue")) {
return false;
}
}
attValue = this.getIsempty();
if (attValue != null) {
if (!getTMLContext().isempty(attValue)) {
return false;
}
}
attValue = this.getIsfilled();
if (attValue != null) {
// Bypass this test in edit mode (as it most likely is used to hide fields that are not filled)
boolean isEditmode = (context.isbrowserinterface() && content.getStatus().equals(WGContent.STATUS_DRAFT));
if (!isEditmode) {
if (getTMLContext().isempty(attValue)) {
return false;
}
}
}
attValue = this.getIsfirstloop();
if (attValue != null) {
boolean firstLoop = false;
if (WGUtils.isBooleanValue(attValue)) {
firstLoop = getTMLContext().isfirstloop();
if (this.stringToBoolean(attValue) == false) {
firstLoop = !firstLoop;
}
} else {
firstLoop = getTMLContext().isfirstloop(attValue);
}
if (firstLoop == false) {
return false;
}
}
attValue = this.getIslastloop();
if (attValue != null) {
boolean lastLoop = false;
if (WGUtils.isBooleanValue(attValue)) {
lastLoop = getTMLContext().islastloop();
if (this.stringToBoolean(attValue) == false) {
lastLoop = !lastLoop;
}
} else {
lastLoop = getTMLContext().islastloop(attValue);
}
if (lastLoop == false) {
return false;
}
}
return true;
}
catch (Exception exc) {
log.error("Error evaluating expression", exc);
return false;
}
catch (Error err) {
log.error("Error evaluating expression", err);
return false;
}
finally {
context.setrole(null);
}
}