# HG changeset patch
# User František Kučera <franta-hg@frantovo.cz>
# Date 1318545906 -7200
# Node ID b5690fc25af6dc29e847e307697ad84788dfa08f
# Parent  41d6c0cac8b34dcb79b5f6158127b1876d94fb0d
Drupal: XSL šablona pro formátování XHTML části zprávy.

diff -r 41d6c0cac8b3 -r b5690fc25af6 .hgignore
--- a/.hgignore	Thu Oct 13 03:09:22 2011 +0200
+++ b/.hgignore	Fri Oct 14 00:45:06 2011 +0200
@@ -1,2 +1,4 @@
 syntax: glob
 build
+lib
+var
diff -r 41d6c0cac8b3 -r b5690fc25af6 bin/sonews.sh
--- a/bin/sonews.sh	Thu Oct 13 03:09:22 2011 +0200
+++ b/bin/sonews.sh	Fri Oct 14 00:45:06 2011 +0200
@@ -1,16 +1,22 @@
 #!/bin/bash
+
+JAVA_HOME="/usr/lib/jvm/java-6-openjdk";
+NEWSROOT="/home/fiki/src/sonews-nntp/sonews-11-dev";
+
 cd `dirname $0`/..
 NEWSROOT=`pwd`
-CLASSPATH=$NEWSROOT/lib/sonews.jar:\
-$NEWSROOT/lib/sonews-helpers.jar:\
+CLASSPATH=$NEWSROOT/build/sonews.jar:\
+$NEWSROOT/lib/commons-codec-1.5.jar:\
 $NEWSROOT/lib/mysql-connector-java.jar:\
-$NEWSROOT/lib/glassfish-mail.jar:\
-$NEWSROOT/lib/postgresql.jar
+$NEWSROOT/lib/javax.mail.jar:\
+$NEWSROOT/lib/postgresql-8.3-604.jdbc4.jar:\
+$NEWSROOT/lib/mysql-connector-java-5.1.7-bin.jar
 
-LOGFILE=/var/log/sonews.log
-PIDFILE=/var/pid/sonews.pid
+LOGFILE=var/log/sonews.log
+PIDFILE=var/pid/sonews.pid
 ARGS=$@
 
+
 MAINCLASS=org.sonews.Main
 JAVA=$JAVA_HOME/bin/java
 
diff -r 41d6c0cac8b3 -r b5690fc25af6 build.xml
--- a/build.xml	Thu Oct 13 03:09:22 2011 +0200
+++ b/build.xml	Fri Oct 14 00:45:06 2011 +0200
@@ -29,6 +29,10 @@
         <pathelement location="lib/glassfish-mail.jar"/>
         <pathelement location="lib/mysql-connector-java.jar"/>
         <pathelement location="lib/junit-4.8.2.jar"/>
+
+        <pathelement location="lib/javax.mail.jar"/>
+        <pathelement location="lib/commons-codec-1.5.jar"/>
+
     </path>
 
 
diff -r 41d6c0cac8b3 -r b5690fc25af6 helpers/mimeXhtmlPart.xsl
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/helpers/mimeXhtmlPart.xsl	Fri Oct 14 00:45:06 2011 +0200
@@ -0,0 +1,199 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet version="1.0"
+	xmlns="http://www.w3.org/1999/xhtml"
+	xmlns:h="http://www.w3.org/1999/xhtml"
+	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+	xmlns:fn="http://www.w3.org/2005/xpath-functions"
+	xmlns:svg="http://www.w3.org/2000/svg"
+	xmlns:xs="http://www.w3.org/2001/XMLSchema"
+	exclude-result-prefixes="fn h xs">
+	<xsl:output 
+		method="xml" 
+		indent="yes" 
+		encoding="UTF-8"		
+		doctype-public="-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" 
+		doctype-system="http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd"/>
+	
+		
+	<xsl:param name="title"/>
+	<xsl:param name="isRoot"/>
+	<xsl:param name="urlBase"/>
+	<xsl:param name="wwwRead"/>
+	<xsl:param name="wwwPost"/>
+	
+	
+	<!-- Celý dokument -->
+	<xsl:template match="/">
+		<html>
+			<head>
+				<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
+				<xsl:if test="$urlBase">
+					<base href="{$urlBase}"/>
+				</xsl:if>
+				<xsl:if test="$title">
+					<title><xsl:value-of select="$title"/></title>
+				</xsl:if>
+				<style type="text/css">
+					body {
+						font-family: sans-serif;
+						font-size: 16px;
+					}
+					
+					.wwwLinks {
+						border-top: 2px solid grey;
+						margin-top: 16px;
+						font-size: 66%;
+					}
+					
+					blockquote {
+						background-color: #eee;
+						font-style: italic;
+						padding: 2px 20px;
+						margin: 10px 32px;
+						border-left: 3px solid silver;
+					}
+					
+					pre {
+						background-color: #eee;
+						padding: 2px 20px;
+						margin: 10px 32px;
+						border-left: 3px solid #a00;
+					}
+					
+					img {
+						margin: 8px;
+					}
+					
+					a img {
+						border: none;
+					}
+				</style>
+			</head>
+			<body>
+				<xsl:if test="$title and $isRoot">
+					<h1><xsl:value-of select="$title"/></h1>			
+				</xsl:if>
+				<xsl:apply-templates select="h:html/h:body/node()"/>
+				
+				<xsl:if test="$wwwRead or $wwwPost">
+					<div class="wwwLinks">
+						<p>Přístup přes síť www:</p>
+						<ul>
+							<xsl:if test="$wwwRead"><li><a href="{$wwwRead}">číst tento příspěvek</a></li></xsl:if>
+							<xsl:if test="$wwwPost"><li><a href="{$wwwPost}">odpovědět na tento příspěvek</a></li></xsl:if>
+						</ul>
+					</div>
+				</xsl:if>
+			</body>
+		</html>
+	</xsl:template>
+	
+	
+	<!-- Odkazy -->
+	<xsl:template match="h:a">
+		<a href="{@href}" title="{@title}"><xsl:apply-templates/></a>
+	</xsl:template>
+	
+	
+	<!-- Obrázky -->
+	<xsl:template match="h:img">
+		<img src="{@src}" alt="{@alt}" title="{@title}"><xsl:apply-templates/></img>
+	</xsl:template>
+	
+	<!-- Zkratky -->
+	<xsl:template match="h:abbr">
+		<abbr title="{@title}"><xsl:apply-templates/></abbr>
+	</xsl:template>
+	
+	
+	<!-- Další povolené značky – ostatní odfiltrujeme (zbude z nich jen text) -->
+	<xsl:template match="*">
+		<xsl:choose>		
+			<xsl:when test="
+				name() = 'h1' or
+				name() = 'h2' or
+				name() = 'h3' or
+				name() = 'h4' or
+				name() = 'h5' or
+				name() = 'h6' or
+				name() = 'p' or
+				name() = 'div' or
+				name() = 'br' or
+				name() = 'strong' or
+				name() = 'em' or
+				name() = 'sub' or
+				name() = 'sup' or
+				name() = 'del' or
+				name() = 'ul' or
+				name() = 'ol' or
+				name() = 'li' or
+				name() = 'pre' or
+				name() = 'code' or
+				name() = 'blockquote'">
+				<xsl:element name="{name()}">
+					<xsl:apply-templates/>
+				</xsl:element>
+			</xsl:when>
+			<xsl:otherwise>
+				<xsl:value-of select="."/>
+			</xsl:otherwise>
+		</xsl:choose>		
+    </xsl:template>
+    
+    
+    <!-- 
+    	Z neuzavřeného (nevalidně se vyskytujícího v body) textu uděláme odstavce.
+    	Bohužel nefunguje, když neuzavřený text obsahuje jiné značky (odkazy atd.),
+    	pak se totiž jedná o dva textové uzly (před značkou a za ní) a vzniknou dva odstavce.
+    -->
+	<xsl:template match="h:body/text()">
+		<xsl:call-template name="makeParagraphs">
+			<xsl:with-param name="string" select="."/>
+		</xsl:call-template>
+	</xsl:template>
+    <xsl:variable name="newLinePlaceholder" select="'ߜ'"/>
+    <xsl:template name="makeParagraphs">
+    	<xsl:param name="string" />
+    	<xsl:call-template name="makeParagraphsInternal">
+    		<!--
+    			Konec řádku převedeme na obskurní znak, 
+    			normalizací pročistíme bílé znaky → 
+    			dva obskurní znaky oddělené mezerou pak značí předěl mezi odstavci
+    		-->
+    		<xsl:with-param name="string" select="normalize-space(translate(., '&#10;', $newLinePlaceholder))"/>
+    	</xsl:call-template>
+    </xsl:template>
+	<xsl:template name="makeParagraphsInternal">
+		<xsl:param name="string" />
+		<xsl:if test="ends-with($string, $newLinePlaceholder)"><xsl:comment>končí na $newLinePlaceholder</xsl:comment> </xsl:if>
+		<!-- V XSLT 2.0 můžeme použít fn:tokenize -->
+		<xsl:param name="delimiter" select="concat($newLinePlaceholder, ' ', $newLinePlaceholder)"/>
+		<xsl:choose>
+			<xsl:when test="$delimiter and contains($string, $delimiter)">
+				<xsl:call-template name="makeParagraph">
+					<xsl:with-param name="string" select="substring-before($string, $delimiter)"></xsl:with-param>
+				</xsl:call-template>
+				<xsl:call-template name="makeParagraphsInternal">
+					<xsl:with-param name="string" select="substring-after($string, $delimiter)" />
+					<xsl:with-param name="delimiter" select="$delimiter" />
+				</xsl:call-template>
+			</xsl:when>
+			<xsl:otherwise>
+				<!--
+					Poslední odstavec → zkontrolovat, zda je za ním  
+				-->
+				<xsl:call-template name="makeParagraph">
+					<xsl:with-param name="string" select="$string"></xsl:with-param>
+				</xsl:call-template>
+			</xsl:otherwise>
+		</xsl:choose>
+	</xsl:template>
+	<xsl:template name="makeParagraph">
+		<xsl:param name="string" />
+			<!-- prázdné textové uzly nás nezajímají – nechceme prázdné odstavce -->
+			<xsl:if test="normalize-space($string)">
+				<p class="mešuge"><xsl:value-of select="translate($string, $newLinePlaceholder, '&#10;')" /></p>				
+			</xsl:if>
+	</xsl:template>
+
+</xsl:stylesheet>