From version < 3.1 >
edited by Manuel Smeria
on 2018/04/02 09:44
To version < 4.1 >
edited by Paul Panțiru
on 2019/03/20 12:01
< >
Change comment: There is no comment for this version

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -xwiki:XWiki.ManuelSmeria
1 +xwiki:XWiki.ppantiru
ExtensionCode.ExtensionClass[0]
Is allowed namespaces empty
... ... @@ -1,0 +1,1 @@
1 +No
Authors
... ... @@ -1,1 +1,1 @@
1 -xwiki:XWiki.lucaa
1 +xwiki:XWiki.lucaa xwiki:XWiki.ppantiru
Description
... ... @@ -34,3 +34,43 @@
34 34  {{info}}
35 35  Also keep in mind that the script only works for terminal pages.
36 36  {{/info}}
37 +
38 +{{info}}
39 +Ana updated script that also works for nested documents can be found below.
40 +{{/info}}
41 +
42 +{{code}}
43 +{{velocity}}
44 +#if ("$!request.documentsToFix" != "")
45 + #set($documentsList = $request.getParameterValues('documentsToFix'))
46 + #foreach($page in $documentsList)
47 + #calculateNewPages()
48 + * renaming $page : $xwiki.getDocument($pageReference).rename($newPageReference)
49 + #end
50 +#else
51 + #set($pagesWithSlash = $services.query.xwql("from XWikiSpace as space where doc.space = space.reference and (((doc.name <> 'WebHome' and lower(doc.name) like '%/%') or(doc.name <> 'WebHome' and lower(doc.name) like '%\\%')) or ((doc.name = 'WebHome' and lower(space.name) like '%/%') or (doc.name = 'WebHome' and lower(space.name) like '%\\%')))").execute())
52 +
53 + {{html}}
54 + <form action="" method="post">
55 + <ul>
56 + #foreach($page in $pagesWithSlash)
57 + #calculateNewPages()
58 + <li> <input type="checkbox" name="documentsToFix" value="$escapetool.xml($services.model.serialize($pageReference, 'default'))">$page -> $services.model.serialize($newPageReference, 'default')</input></li>
59 + #end
60 + </ul>
61 + <input type="submit" class="button" value="Rename" />
62 + </form>
63 + {{/html}}
64 +#end
65 +
66 +#macro(calculateNewPages)
67 + #set($pageReference = $services.model.resolveDocument($page))
68 + #set($spaceArray = [])
69 + #foreach($sp in $pageReference.getSpaceReferences())
70 + #set($auxSpace = $sp.name.replaceAll('/', ' ').replaceAll('\\', ' '))
71 + #set($discard = $spaceArray.add($auxSpace))
72 + #end
73 + #set($newPageReference = $services.model.createDocumentReference($pageReference.wikiReference.name, $spaceArray, $pageReference.name.replaceAll('/', ' ').replaceAll('\\', ' ')))
74 +#end
75 +{{/velocity}}
76 +{{/code}}
Recommended
... ... @@ -1,0 +1,1 @@
1 +No
Show installed count
... ... @@ -1,0 +1,1 @@
1 +Yes
cogCleanup slashes and backslashes from document names.
Developed by

Anca Luca

Anca Luca, Paul Panțiru

Rating
Rate!
3 Votes
LicenseGNU Lesser General Public License 2.1

Description

This script is useful if for any reason issue XE-688 is hit and it cannot be fixed at the level of Tomcat or other application server in front (for example, Apache httpd proxy-ing will have the same behaviour and Tomcat changes cannot fix anything).

The following script looks up all documents containing '/' or '\' in the document name and allows replacing the character with a space. To use it, copy the following code in a page with syntax 2.1:

{{velocity}}
#if ("$!request.documentsToFix" != "")
 #set($documentsList = $request.getParameterValues('documentsToFix'))
 #foreach($documentName in $documentsList)
   #set($pageReference = $services.model.resolveDocument($documentName))
   #set($newPageReference = $services.model.createDocumentReference($pageReference.wikiReference.name, $pageReference.lastSpaceReference.name, $pageReference.name.replaceAll('/', ' ').replaceAll('\\', ' ')))    
    * renaming $documentName : $xwiki.getDocument($pageReference).rename($newPageReference)
 #end
#else
 #set($pagesWithSlash = $xwiki.searchDocuments("where doc.name like '%/%' or doc.name like '%\\%'"))
 {{html}}
  

  

     #foreach($page in $pagesWithSlash)
       #set($pageReference = $services.model.resolveDocument($page))
       #set($newPageReference = $services.model.createDocumentReference($pageReference.wikiReference.name, $pageReference.lastSpaceReference.name, $pageReference.name.replaceAll('/', ' ').replaceAll('\\', ' ')))
        
  • escapetool.xml($services.model.serialize($pageReference, 'default'))">$page -> $services.model.serialize($newPageReference, 'default')

  •  #end
      

  
  

 {{/html}}
#end
{{/velocity}}

Keep in mind that this script does not prevent the issue to reappear (i.e. a document with the said characters in the name to be re-created) so, if you find yourself in the situation of not being able to fix XE-688, you need to make custom verifications and make sure that the code that created those documents does not do it again.

Also keep in mind that the script only works for terminal pages.

Ana updated script that also works for nested documents can be found below.

{{velocity}}
#if ("$!request.documentsToFix" != "")
  #set($documentsList = $request.getParameterValues('documentsToFix'))
  #foreach($page in $documentsList)
    #calculateNewPages()
   * renaming $page : $xwiki.getDocument($pageReference).rename($newPageReference)
  #end
#else
  #set($pagesWithSlash = $services.query.xwql("from XWikiSpace as space where doc.space = space.reference and (((doc.name <> 'WebHome' and lower(doc.name) like '%/%') or(doc.name <> 'WebHome' and lower(doc.name) like '%\\%')) or ((doc.name = 'WebHome' and lower(space.name) like '%/%') or (doc.name = 'WebHome' and lower(space.name) like '%\\%')))").execute())

  {{html}}
 <form action="" method="post">
 <ul>
  #foreach($page in $pagesWithSlash)
    #calculateNewPages()
   <li> <input type="checkbox" name="documentsToFix" value="$escapetool.xml($services.model.serialize($pageReference, 'default'))">$page -> $services.model.serialize($newPageReference, 'default')input>li>
  #end
 ul>
 <input type="submit" class="button" value="Rename" />
 form>
  {{/html}}
#end

#macro(calculateNewPages)
  #set($pageReference = $services.model.resolveDocument($page))
  #set($spaceArray = [])
  #foreach($sp in $pageReference.getSpaceReferences())
    #set($auxSpace = $sp.name.replaceAll('/', ' ').replaceAll('\\', ' '))
    #set($discard = $spaceArray.add($auxSpace))
  #end
  #set($newPageReference = $services.model.createDocumentReference($pageReference.wikiReference.name, $spaceArray, $pageReference.name.replaceAll('/', ' ').replaceAll('\\', ' ')))
#end
{{/velocity}}

Prerequisites & Installation Instructions

Copy the code snippet to a page and save it.

Get Connected