General Actions:
Log-in
Register
Wiki:
xwiki
▼
:
Document Index
»
Space:
Species
▼
:
Document Index
»
Page:
Tech ValidationSpecificationClass
Search
en
Page Actions:
Export
▼
:
Export as PDF
Export as HTML
More actions
▼
:
Print preview
View Source
Koncepcja
»
Wiki source code of
Tech ValidationSpecificationClass
Hide line numbers
1: package aaaia.xwiki; 2: 3: import com.xpn.xwiki.validation.*; 4: import com.xpn.xwiki.*; 5: import com.xpn.xwiki.doc.*; 6: import com.xpn.xwiki.objects.*; 7: import org.slf4j.Logger; 8: import org.slf4j.LoggerFactory; 9: import org.apache.commons.lang.StringEscapeUtils; 10: 11: public class SpecificationValidation implements XWikiValidationInterface { 12: 13: private static final Logger log = LoggerFactory.getLogger(SpecificationValidation.class); 14: private static String SPACE_NAME = "Species" 15: private static String CLAZZ_NAME = "${SPACE_NAME}.SpecificationClass"; 16: private static String HTML_TITLE_DISPLAY_CLASS_NAME = "Species.HtmlTitleDisplayClass" 17: private static String HTML_TITLE_FIELD_NAME = "pHtmlTitle" 18: private static String DEFAULT_PARENT = "Species.Incertae sedis" 19: private static def PARENT_ALLOWED_CLASSES = [CLAZZ_NAME] 20: private Object aiautil = null; 21: 22: public boolean validateDocument(XWikiDocument doc, XWikiContext context) { 23: def res = true; 24: try { 25: aiautil = context.getWiki().parseGroovyFromPage("Species.Tech IkonotekaScripts",context); 26: def obj = doc.getObject(CLAZZ_NAME); 27: 28: def esc = {input -> 29: return StringEscapeUtils.escapeHtml(""+input) 30: } 31: 32: //get properties from object 33: def pSpecTypeNonEsc = obj.getStringValue("pSpecType") 34: def pSpecValueNonEsc = obj.getStringValue("pSpecValue") 35: def pAutorOpisuNonEsc = obj.getStringValue("pAutorOpisu") 36: def pRokOpisuNonEsc = obj.getIntValue("pRokOpisu") 37: 38: def pSpecType = esc(pSpecTypeNonEsc) 39: def pSpecValue = esc(pSpecValueNonEsc) 40: def pAutorOpisu = esc(pAutorOpisuNonEsc) 41: //no need of escaping as it is int 42: def pRokOpisu = pRokOpisuNonEsc 43: 44: //title interception 45: def properTitle 46: properTitle = "$pSpecTypeNonEsc $pSpecValueNonEsc"// $pAutorOpisuNonEsc, $pRokOpisuNonEsc" 47: if (doc.getTitle() != properTitle && doc.getTitle()){ 48: doc.setTitle(properTitle) 49: } 50: 51: //html title interception 52: // it is mandatory to escape html in html title 53: def htmlTitleObj = doc.getObject(HTML_TITLE_DISPLAY_CLASS_NAME,true, context) 54: def pHtmlTitle = htmlTitleObj.getStringValue(HTML_TITLE_FIELD_NAME) 55: def properHtmlTitle 56: 57: //jeśli brak roku bądź autora to odpowiednia sekcja nie powinna się wyświetlać 58: def tmpPRokOpisu = (pRokOpisu==0 || !pRokOpisu)?null:pRokOpisu; 59: def pAutorPRokOpisuPart = [pAutorOpisu, tmpPRokOpisu].grep{it}.join(", ") 60: if (pAutorPRokOpisuPart) { 61: pAutorPRokOpisuPart = " " + pAutorPRokOpisuPart 62: } 63: if (aiautil.taksonyPisaneKursywa.contains(pSpecType)) { 64: properHtmlTitle = "$pSpecType <i>$pSpecValue</i>$pAutorPRokOpisuPart" 65: } else { 66: properHtmlTitle = "$pSpecType $pSpecValue$pAutorPRokOpisuPart" 67: } 68: if (properHtmlTitle != pHtmlTitle) { 69: htmlTitleObj.setStringValue(HTML_TITLE_FIELD_NAME, properHtmlTitle) 70: } 71: 72: //parent interception 73: def interceptParentName = context.getRequest().getParameter("myinput") 74: interceptParentName = org.apache.commons.lang.StringEscapeUtils.unescapeHtml(interceptParentName ) 75: log.debug("Setting parent/interceptParentName=$interceptParentName;") 76: if (doc.getParent() != interceptParentName && interceptParentName){ 77: def parentDoc = context.getWiki().getDocument(interceptParentName, context); 78: log.debug("Setting parent/parentDoc != null=${parentDoc != null};") 79: if (!aiautil.hasOneOfClasses(parentDoc, context, PARENT_ALLOWED_CLASSES)) { 80: log.debug("!aiautil.hasOneOfClasses(parentDoc, context, PARENT_ALLOWED_CLASSES)=TRUE") 81: com.xpn.xwiki.XWiki xwiki = context.getWiki(); 82: def hasAdmin = xwiki.getRightService().hasAdminRights(context); 83: if (!hasAdmin) { 84: interceptParentName = DEFAULT_PARENT 85: } 86: } 87: log.debug("Setting parent[$interceptParentName] for page[${doc.title}]") 88: doc.setParent(interceptParentName) 89: } 90: 91: aiautil.storeParentFullNameToCache(doc, CLAZZ_NAME, context.getRequest()) 92: aiautil.setLastToCache(context.getRequest(), CLAZZ_NAME, "pSpecType", pSpecType) 93: } catch (e) { 94: log.error(e.message,e) 95: e.printStackTrace() 96: res = false; 97: } 98: return res; 99: } 100: 101: public boolean validateObject(BaseObject object, XWikiContext context) { 102: return true; 103: } 104: 105: }
Kategorie
Koncepcja
Gatunki
Stanowiska
Sponsorzy
Instytut Paleobiologii PAN
Klasyfikacja