Created
July 14, 2013 07:48
-
-
Save akhikhl/5993538 to your computer and use it in GitHub Desktop.
A happier, groovier way to parse RTF: apache_tika + XmlSlurper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.akhikhl.test | |
import org.apache.tika.metadata.Metadata | |
import org.apache.tika.parser.rtf.RTFParser | |
class ParseRtf { | |
def parse(String rtfText) { | |
// not validating, not ns-aware | |
XmlSlurper slurper = new XmlSlurper(false, false) | |
InputStream rtfStream = new ByteArrayInputStream(value.getBytes()) | |
new RTFParser().parse(rtfStream, slurper, new Metadata()) | |
slurper.document.'body'.p.each { p -> | |
println "Got paragraph: ${p.text()}" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment