Sebastian Schafer wrote:
> I think right now I'm mostly battling the linked images in the original html 
> files. Xwiki uses relative paths and those are not valid anymore after 
> converting to a wiki page. I think I need to handle this when I create the 
> html files and embed the images as text - ugly but the only option I see 
> right now.
Here would be a continuation, before the document.save of course.
The imports should be put first.

paul

import java.util.regexp.*;
import org.apache.commons.io.FileUtils;
import java.io.File;
import com.xpn.xwiki.api.*;

    java.util.regexp.Pattern pattern = Pattern.compile("<img
src=\\\"(/download/attachments/[^\\\"]*)");
    Matcher m = pattern.matcher(html);
    println("<ul>")
    while(m.find()) {
        URL u = new URL(pageURL, m.group(1));
        String imageName = u.getPath().replaceAll(".*/","");
        println("<li><a href='${u}'>${imageName }</a>");
        File tmp = new File("/tmp/xxx.png");
        FileUtils.copyURLToFile(u, tmp);

        // now fetch and store
        byte[] content = FileUtils.readFileToByteArray(tmp);
        //println("Attachment is of size ${content.length} and is named
${name}");
        Attachment attachment = doc.addAttachment(imageName , content);
        println(" has become <a href='${doc.getAttachmentURL(imageName
)}'>${imageName }</a> (rev ${attachment.getVersion()}).</li>");
    }
    println("</ul>");

_______________________________________________
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users

Reply via email to