General Actions:
Log-in
Register
Wiki:
Main wiki
▼
:
Document Index
»
Space:
Panels
▼
:
Document Index
»
Page:
DocumentInformation
Search
default
Page Actions:
Export
▼
:
Export as PDF
Export as RTF
Export as HTML
More actions
▼
:
Print preview
View Source
Main wiki
»
Panels
»
Document Information
Wiki source code of
Document Information
Last modified by
Administrator
on 2012/03/21 17:40
Content
·
Comments
(0)
·
Annotations
(0)
·
Attachments
(0)
·
History
·
Information
Hide line numbers
1: {{velocity output="false"}} 2: #macro(convertDocument $targetDoc $error $oldSyntaxId $newSyntaxId) 3: #if ($targetDoc.realLanguage == $xwiki.languagePreference) 4: #if ($request.content) 5: ## Use the content received from the client if the target document is the edited one (could be also a translation of the edited document). 6: #set ($void = $targetDoc.setContent($request.content)) 7: #end 8: #end 9: ## Use the syntax received from the client as the user might have made some changes that are not saved yet. 10: #set ($void = $targetDoc.setSyntaxId($oldSyntaxId)) 11: #if (!$services.csrf.isTokenValid($request.form_token) || !$targetDoc.convertSyntax($newSyntaxId)) 12: #set ($error = true) 13: #else 14: #set ($void = $targetDoc.save("Document converted from syntax $oldSyntaxId to syntax $newSyntaxId")) 15: #end 16: #end 17: {{/velocity}} 18: 19: {{velocity wiki="false"}} 20: #if ("$!request.action" == 'convertSyntax') 21: #set ($oldSyntaxId = $request.oldSyntaxId) 22: #set ($newSyntaxId = $request.newSyntaxId) 23: #set ($targetDoc = $xwiki.getDocument($request.documentName)) 24: #set ($error = false) 25: ## 26: ## Convert the specified document 27: ## 28: #convertDocument($targetDoc $error $oldSyntaxId $newSyntaxId) 29: ## 30: ## Convert all the translations of the specified document 31: ## 32: #set($languages = $targetDoc.translationList) 33: #if (!$error) 34: #foreach ($language in $languages) 35: #if (!$error) 36: #set ($translatedDoc = $targetDoc.getTranslatedDocument($language)) 37: #if ($translatedDoc.language != $targetDoc.language) 38: #convertDocument($translatedDoc $error $oldSyntaxId $newSyntaxId) 39: #end 40: #end 41: #end 42: #end 43: ## 44: ## Error management 45: ## 46: #if (!$error) 47: ## Conversion successful. The "ok:" prefix is needed, since otherwise an empty content will result in a "This template does not exist" exception. 48: ok:${targetDoc.content}## 49: #else 50: $response.setStatus(501) 51: ## TODO: Find a way to put the exception in the context and send it to the client. 52: failed 53: #end 54: #end 55: {{/velocity}} 56: 57: {{velocity}} 58: #if ("$!request.action" != 'convertSyntax') 59: {{include document="Panels.PanelSheet"/}} 60: #end 61: {{/velocity}}