# HG changeset patch # User František Kučera # Date 1318868074 -7200 # Node ID c60625d581582e672c66e654d07195da256b94b9 # Parent cbf1a1153313a4297187ae2ff58bba6af02449d8 Drupal: textová část zpráv (text/plain), základní funkční verze (XSLT+Java). diff -r cbf1a1153313 -r c60625d58158 helpers/mimeTextPart.xsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/helpers/mimeTextPart.xsl Mon Oct 17 18:14:34 2011 +0200 @@ -0,0 +1,199 @@ + + + + + + + + + + + + + + + + + + + # + + + + + + + + - + + + + + + # + + + + + + + + + # + + + + + + + + + # + + + + + + + + # + + + + + + + + + + + + + + + " + + " < + + + + + + + + + + + + + + + + + + + > + + ( + + ) + + + + + + Obrázek: + + + + + + ** + + ** + + + + * + + * + + + + + ( + + ) + + + + -------------------------------- + + + + -------------------------------- + + + + + + ` + + ` + + + + ---------------------------------------------------------------- + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- + + + + + + diff -r cbf1a1153313 -r c60625d58158 src/org/sonews/storage/DrupalMessage.java --- a/src/org/sonews/storage/DrupalMessage.java Mon Oct 17 13:55:28 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();