AnsweredAssumed Answered

replace text within the ODT file content keeping the format

Question asked by mguarinoni on Jul 14, 2011
Hi,
Is there any way to replace text within the ODT file content keeping the format?
This is the code that I tried, but i'm loosing the content format, it seems plain text:

          ContentWriter writer = this.contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
          writer.setMimetype("application/vnd.oasis.opendocument.text");
          writer.setEncoding("UTF-8");
          writer.setLocale(reader.getLocale());         
          AutoDetectParser parser = new AutoDetectParser();         
          ParseContext parseContext = new ParseContext();
          ContentHandler conentHandler = new BodyContentHandler();   
          Metadata metadata = new Metadata();                          
          parser.parse(reader.getContentInputStream(), conentHandler, metadata, parseContext);
          String content = conentHandler.toString().replace(label, value);
          writer.putContent(content);

This code is part of a Custom Java Action receiving parameters: label, value.

thanks

Outcomes