Toggle navigation
Entrar
Registrar
BNMP2
Índice de Documentos
Diretório de Usuários
Application Index
Global
Diretório de Divisões
You need to login to start the chat system
FileManager Página Incial
Xambox Sync
Código fonte Wiki de
Xambox Sync
Última modificação por
Administrator
em 25/07/2020, 16:19
Esconder números de linha
1: {{groovy}} 2: import org.xwiki.velocity.tools.EscapeTool; 3: 4: def xc = services.xambox.xamboxConnector 5: xc.login() 6: 7: def text = (request.text) ? request.text : "type:document" 8: def escapetool = new EscapeTool() 9: def stext = escapetool.xml(text) 10: def aurl = doc.getURL("view") 11: 12: println """ 13: {{html clean="false"}} 14: <form action="${aurl}" method="post"> 15: Search term <input type="text" name="text" value="${stext}" /> 16: <input type="submit" value="Search" /> 17: </form> 18: {{/html}} 19: """ 20: 21: if (request.pid) { 22: def pids = request.getParameterValues("pid") 23: for (pid in pids) { 24: def xamboxDoc = xc.getDocument(pid); 25: def linkpage = request.get("page_" + pid) 26: def linkpagedoc = null; 27: 28: if (linkpage!=null && linkpage.trim()!="") { 29: linkpagedoc = xwiki.getDocument(linkpage) 30: } 31: xamboxDoc.setTitle(request.get("title_" + pid)); 32: xdoc = xc.createFileManagerDocumentFromXambox("FileManager", xamboxDoc); 33: 34: def linkmsg = ""; 35: if (linkpagedoc!=null && !linkpagedoc.isNew()) { 36: // adding reference to linkpagedoc 37: xdoc.setParent(linkpage); 38: xdoc.save(); 39: 40: linkpagedoc.setContent(linkpagedoc.content + "\n{{filemanagerdoc page=\"${xdoc.fullName}\" /}}"); 41: linkpagedoc.save(); 42: linkmsg = " and linked to [[${linkpage}]]"; 43: } 44: println "* Imported document [[${xdoc.fullName}]] ${linkmsg}" 45: 46: 47: } 48: } else if (request.text) { 49: println """{{html clean="false" wiki="true"}} 50: <form action="" method="post"> 51: <input type="hidden" name="text" value="${stext}" /> 52: """ 53: 54: def list = xc.getDocuments(request.text, 0, 20) 55: 56: for (item in list) { 57: def pid = item.pid; 58: 59: // def xdoc = xc.findXamboxDocument(pid); 60: def xdoc = null; 61: def wiki = ""; 62: 63: // find the proper search engine 64: def searchConfigDoc = xwiki.getDocument("XWiki.SearchConfig") 65: def searchEngine = searchConfigDoc.getValue("engine") 66: if (searchEngine==null || searchEngine=="") 67: searchEngine = "solr"; 68: 69: if (searchEngine=="lucene") { 70: def result = xwiki.lucene.getSearchResults("FileManager.XamboxDocumentClass.pid:${pid}", "") 71: if (result!=null && result.getHitcount()>0) { 72: def ldoc = result.getResults(1,1).get(0); 73: def fdocname = ldoc.getWiki() + ":" + ldoc.getFullName() 74: xdoc = xwiki.getDocument(fdocname) 75: wiki = ldoc.getWiki(); 76: } 77: } else { 78: def queryStatement = "property.FileManager.XamboxDocumentClass.pid:${pid}" 79: def query = services.query.createQuery(queryStatement, 'solr') 80: def searchResponse = query.execute()[0].results 81: if (searchResponse.size()>0) { 82: wiki = searchResponse[0].wiki 83: def fdocname = "" + searchResponse[0].wiki + ":" + searchResponse[0].fullname 84: xdoc = xwiki.getDocument(fdocname) 85: } 86: } 87: 88: if (xdoc==null) { 89: def stitle = escapetool.xml(item.title) 90: println """Document not synced (${item.processingStatus}): <input type="checkbox" name="pid" value="${item.pid}" /> Title: <input type="text" name="title_${item.pid}" value="${stitle}" size="60" /> Link to page: <input type="text" name="page_${item.pid}" value="" class="suggestDocuments" size="60" /><br />""" 91: } else { 92: println """Document already synced: [[${xdoc.title}>>${wiki}:${xdoc.fullName}]]<br />""" 93: } 94: } 95: println """ 96: <br /> 97: <input type="submit" value="Import" /> 98: </form> 99: {{/html}} 100: """ 101: } 102: {{/groovy}}