Tech ValidationSpecificationClass
package aaaia.xwiki;
import com.xpn.xwiki.validation.*;
import com.xpn.xwiki.*;
import com.xpn.xwiki.doc.*;
import com.xpn.xwiki.objects.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.commons.lang.StringEscapeUtils;
public class SpecificationValidation implements XWikiValidationInterface {
private static final Logger log = LoggerFactory.getLogger(SpecificationValidation.class);
private static String CLAZZ_NAME = "Species.SpecificationClass";
private static String HTML_TITLE_DISPLAY_CLASS_NAME = "Species.HtmlTitleDisplayClass"
private static String HTML_TITLE_FIELD_NAME = "pHtmlTitle"
private Object aiautil = null;
public boolean validateDocument(XWikiDocument doc, XWikiContext context) {
def res = true;
try {
aiautil = context.getWiki().parseGroovyFromPage("Species.Tech IkonotekaScripts",context);
def obj = doc.getObject(CLAZZ_NAME);
title interception
def pSpecType = obj.getStringValue("pSpecType")
def pSpecValue = obj.getStringValue("pSpecValue")
def pAutorOpisu = obj.getStringValue("pAutorOpisu")
def pRokOpisu = obj.getIntValue("pRokOpisu")
def properTitle
properTitle = "$pSpecType $pSpecValue $pAutorOpisu, $pRokOpisu"
if (doc.getTitle() != properTitle && doc.getTitle()){
doc.setTitle(properTitle)
}
html title interception
def htmlTitleObj = doc.getObject(HTML_TITLE_DISPLAY_CLASS_NAME,true, context)
def pHtmlTitle = htmlTitleObj.getStringValue(HTML_TITLE_FIELD_NAME)
def properHtmlTitle
properHtmlTitle = "$pSpecType $pSpecValue $pAutorOpisu, $pRokOpisu"
if (aiautil.taksonyPisaneKursywa.contains(pSpecType)) {
properHtmlTitle = "$pSpecType <i>$pSpecValue</i> $pAutorOpisu, $pRokOpisu"
}
if (properHtmlTitle != pHtmlTitle) {
properHtmlTitle = StringEscapeUtils.escapeHtml(properHtmlTitle)
htmlTitleObj.setStringValue(HTML_TITLE_FIELD_NAME, properHtmlTitle)
}
parent interception
def interceptParentName = context.getRequest().getParameter("myinput")
if (doc.getParent() != interceptParentName){
log.debug("Setting parent[$interceptParentName] for page[${doc.title}]")
doc.setParent(interceptParentName)
}
aiautil.storeParentFullNameToCache(doc, CLAZZ_NAME, context.getRequest())
aiautil.setLastToCache(context.getRequest(), CLAZZ_NAME, "pSpecType", pSpecType)
} catch (e) {
log.error(e.message,e)
e.printStackTrace()
res = false;
}
return res;
}
public boolean validateObject(BaseObject object, XWikiContext context) {
return true;
}
}