diff -r d4435ac082dc -r c60625d58158 src/org/sonews/storage/DrupalMessage.java --- a/src/org/sonews/storage/DrupalMessage.java Mon Oct 17 11:16:18 2011 +0200 +++ b/src/org/sonews/storage/DrupalMessage.java Mon Oct 17 18:14:34 2011 +0200 @@ -98,7 +98,9 @@ /** Plain text part */ MimeBodyPart textPart = new MimeBodyPart(); - textPart.setText(readPlainText(rs, xhtmlText)); + String plainText = readPlainText(rs, xhtmlText); + textPart.setText(plainText); + //addHeader("Lines", String.valueOf(plainText.split("\n").length)); /** * Thunderbirdu záleží, v jakém pořadí části jsou @@ -114,10 +116,22 @@ } private String readPlainText(ResultSet rs, String xhtmlText) { - /** - * TODO: převést na prostý text - */ - return "TODO: obyčejný text\n(zatím čtěte XHTML verzi)"; + try { + TransformerFactory tf = TransformerFactory.newInstance(); + Transformer textTransformer = tf.newTransformer(new StreamSource(Resource.getAsStream("helpers/mimeTextPart.xsl"))); + + StringReader input = new StringReader(xhtmlText); + StringWriter output = new StringWriter(xhtmlText.length()); + textTransformer.transform(new StreamSource(input), new StreamResult(output)); + + return output.toString(); + } catch (Exception e) { + /** + * TODO: lepší ošetření chyby + */ + log.log(Level.WARNING, "Error while transforming article to plain text", e); + return makeSimpleXHTML("Při transformaci příspěvku bohužel došlo k chybě."); + } } private String readXhtmlText(ResultSet rs) { @@ -177,7 +191,13 @@ * TODO: refaktorovat, přesunout */ private static String tidyXhtml(String inputText) throws IOException { - // https://sourceforge.net/tracker/index.php?func=detail&aid=3424437&group_id=27659&atid=390966 + /* + * Viz https://sourceforge.net/tracker/index.php?func=detail&aid=3424437&group_id=27659&atid=390966 + * + * TODO: + * - použít delší zástupný řetězec, ne jen jeden znak + * - umísťovat ho jen tam, kde už nějaký text je (ne mezi >\s*<) + */ inputText = inputText.replaceAll("\\n", "◆\n"); Runtime r = Runtime.getRuntime();