Dear reader,

Version: XWiki/XE 2.2.4

I gave the Office importer some treatment to make it work conform expectations. 
Maybe interesting for others?
Whats weird is, that in IE7 it proposes an ugly document name, something like: 
c-fakepath etc. So I modified XWiki.OfficeImporterResults to strip everything 
in front of the actual documentname:

#set($fileName=$fileUpload.getFileName("filePath").replaceAll("^.*[\\]",""))

Then, I added a check for an empty spacename (otherwise you'll end-up with a 
document in the XWiki space, which is probably not what you want), and also 
strip any considered 'dangerous' character from the documentname (such as &^@, 
accents, etc):

###########################
## Validate Target Space ##
###########################
  #if(! $request.targetSpace)
    {{error}}$msg.get("xe.officeimporter.results.missingspace", 
[$goBack]){{/error}}
  #else
    #if( $request.targetSpace == "" )
      {{error}}$msg.get("xe.officeimporter.results.missingspace", 
[$goBack]){{/error}}
    #else
      ## #set($targetSpace=$request.targetSpace.replaceAll("[:/&=+?#]", "-"))
      ## 
#set($targetSpace=$request.targetSpace.replaceAll("[^a-zA-Z0-9-_~]","_").replaceAll("
 \\.\\/", "").replaceAll('"',""))
      #set($targetSpace=$request.targetSpace.replaceAll(" \\.\\/", 
"").replaceAll("[\=\&\@'\\/()]","-").replaceAll('"',"").replaceAll("[^a-zA-Z0-9-_~]","_"))
    #end
  #end
##########################
## Validate Target Page ##
##########################
  #if(! $request.targetPage)
    {{error}}$msg.get("xe.officeimporter.results.missingpage", 
[$goBack]){{/error}}
  #else
    ## #set($targetPage=$request.targetPage)
    ## 
#set($targetPage=$request.targetPage.replaceAll("[^a-zA-Z0-9-_~]","_").replaceAll("/",
 "-").replaceAll('"',""))
    #set($targetPage=$request.targetPage.replaceAll("[\=\&\@'\\/()]", 
"-").replaceAll('"',"").replaceAll("[^a-zA-Z0-9-_~]","_"))
  #end

Finally, I did not want to present the menu option at all for users who have no 
rights to create documents:
In: templates/menuview.vm
  ## #if($canImport) (original)
  #if($canImport && $hasCreatePage)
    #submenuitem($xwiki.getURL('XWiki.OfficeImporter', 'view') 
$msg.get('core.menu.create.pageFromOffice') 'tmActionImport')
  #end
 
More of this to follow, hopefully useful for others!

Regards,
Wouter
_______________________________________________
users mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/users

Reply via email to