Wang Ning wrote:
Now the plugin can work. However it's a little complicate. If you want to convert a office document 1. you first upload the document 2. copy the attachment name(because the name of document change after upload) 3. edit the page and add the velocity code to use the importer plugin 4. save and view. I think it should be more simple.
So do I :-)
There is 2 ways we can go about doing this : the page action way and the application way.
1. Page action : we add an "import" action in the menu at the top of the page (and maybe in the WYSIWYG editor as well). When clicking on the button, the user is prompted to choose a compatible file on his machine, then he clicks on "import" (with an interface similar to the one used for uploading attachments). The .../bin/import/Main/... is called, and the content from the file appended at the bottom of the existing page, with a #info('') macro at the top saying something like "The following content has been imported to the page :"
This action way is easy to implement as I can get whatever I want to use by using java. But as you said, change the xwiki-core is not a good idea. However, I can get the byte[] data of the source office doument without using attachment.
It is true that now it is hard to add new actions in the code, but in the future plugins would be able to provide their own actions, without changing the code. Still, the only changes needed are: - assigning a rights level, but the default one is "edit", which I think is a good level for the import action, so there's no need to change this - registering the action in struts-config.xml, but that is not something hard to do; it is on the same level as registering the plugin in xwiki.cfg
2. Application : we create an OfficeImport application with the following components : a homepage where the user is prompted to import one or multiple documents. The documents are then imported, each creting its own wiki page. Once the importation is complete, the user is prompted to move the documents to their new locations (using the Rename or the copy feature to implement this)
The application way is good and decouple. However there are some problem too. I want to get the name of the attachment after upload the office document as the name of the document changed by the xwiki.clearName(). But the util.clearName() don't provide the same result. Do I need to add another clearName model in api util? Alternately, I just provide a select type input in the importer page which contain all the attachments in the page for use to select the source attachments.
You could simply get the name of the last attachment. Personally, I'd go the action way. It is not as modular and easily-integrable as it should, but in the (1.7-1.8?) future this will change. -- Sergiu Dumitriu http://purl.org/net/sergiu/