Drupal: XSL šablona pro formátování XHTML části zprávy.
authorFrantišek Kučera <franta-hg@frantovo.cz>
Fri Oct 14 00:45:06 2011 +0200 (2011-10-14)
changeset 76b5690fc25af6
parent 75 41d6c0cac8b3
child 77 623025c704c5
Drupal: XSL šablona pro formátování XHTML části zprávy.
.hgignore
bin/sonews.sh
build.xml
helpers/mimeXhtmlPart.xsl
     1.1 --- a/.hgignore	Thu Oct 13 03:09:22 2011 +0200
     1.2 +++ b/.hgignore	Fri Oct 14 00:45:06 2011 +0200
     1.3 @@ -1,2 +1,4 @@
     1.4  syntax: glob
     1.5  build
     1.6 +lib
     1.7 +var
     2.1 --- a/bin/sonews.sh	Thu Oct 13 03:09:22 2011 +0200
     2.2 +++ b/bin/sonews.sh	Fri Oct 14 00:45:06 2011 +0200
     2.3 @@ -1,16 +1,22 @@
     2.4  #!/bin/bash
     2.5 +
     2.6 +JAVA_HOME="/usr/lib/jvm/java-6-openjdk";
     2.7 +NEWSROOT="/home/fiki/src/sonews-nntp/sonews-11-dev";
     2.8 +
     2.9  cd `dirname $0`/..
    2.10  NEWSROOT=`pwd`
    2.11 -CLASSPATH=$NEWSROOT/lib/sonews.jar:\
    2.12 -$NEWSROOT/lib/sonews-helpers.jar:\
    2.13 +CLASSPATH=$NEWSROOT/build/sonews.jar:\
    2.14 +$NEWSROOT/lib/commons-codec-1.5.jar:\
    2.15  $NEWSROOT/lib/mysql-connector-java.jar:\
    2.16 -$NEWSROOT/lib/glassfish-mail.jar:\
    2.17 -$NEWSROOT/lib/postgresql.jar
    2.18 +$NEWSROOT/lib/javax.mail.jar:\
    2.19 +$NEWSROOT/lib/postgresql-8.3-604.jdbc4.jar:\
    2.20 +$NEWSROOT/lib/mysql-connector-java-5.1.7-bin.jar
    2.21  
    2.22 -LOGFILE=/var/log/sonews.log
    2.23 -PIDFILE=/var/pid/sonews.pid
    2.24 +LOGFILE=var/log/sonews.log
    2.25 +PIDFILE=var/pid/sonews.pid
    2.26  ARGS=$@
    2.27  
    2.28 +
    2.29  MAINCLASS=org.sonews.Main
    2.30  JAVA=$JAVA_HOME/bin/java
    2.31  
     3.1 --- a/build.xml	Thu Oct 13 03:09:22 2011 +0200
     3.2 +++ b/build.xml	Fri Oct 14 00:45:06 2011 +0200
     3.3 @@ -29,6 +29,10 @@
     3.4          <pathelement location="lib/glassfish-mail.jar"/>
     3.5          <pathelement location="lib/mysql-connector-java.jar"/>
     3.6          <pathelement location="lib/junit-4.8.2.jar"/>
     3.7 +
     3.8 +        <pathelement location="lib/javax.mail.jar"/>
     3.9 +        <pathelement location="lib/commons-codec-1.5.jar"/>
    3.10 +
    3.11      </path>
    3.12  
    3.13  
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/helpers/mimeXhtmlPart.xsl	Fri Oct 14 00:45:06 2011 +0200
     4.3 @@ -0,0 +1,199 @@
     4.4 +<?xml version="1.0" encoding="UTF-8"?>
     4.5 +<xsl:stylesheet version="1.0"
     4.6 +	xmlns="http://www.w3.org/1999/xhtml"
     4.7 +	xmlns:h="http://www.w3.org/1999/xhtml"
     4.8 +	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     4.9 +	xmlns:fn="http://www.w3.org/2005/xpath-functions"
    4.10 +	xmlns:svg="http://www.w3.org/2000/svg"
    4.11 +	xmlns:xs="http://www.w3.org/2001/XMLSchema"
    4.12 +	exclude-result-prefixes="fn h xs">
    4.13 +	<xsl:output 
    4.14 +		method="xml" 
    4.15 +		indent="yes" 
    4.16 +		encoding="UTF-8"		
    4.17 +		doctype-public="-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" 
    4.18 +		doctype-system="http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd"/>
    4.19 +	
    4.20 +		
    4.21 +	<xsl:param name="title"/>
    4.22 +	<xsl:param name="isRoot"/>
    4.23 +	<xsl:param name="urlBase"/>
    4.24 +	<xsl:param name="wwwRead"/>
    4.25 +	<xsl:param name="wwwPost"/>
    4.26 +	
    4.27 +	
    4.28 +	<!-- Celý dokument -->
    4.29 +	<xsl:template match="/">
    4.30 +		<html>
    4.31 +			<head>
    4.32 +				<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
    4.33 +				<xsl:if test="$urlBase">
    4.34 +					<base href="{$urlBase}"/>
    4.35 +				</xsl:if>
    4.36 +				<xsl:if test="$title">
    4.37 +					<title><xsl:value-of select="$title"/></title>
    4.38 +				</xsl:if>
    4.39 +				<style type="text/css">
    4.40 +					body {
    4.41 +						font-family: sans-serif;
    4.42 +						font-size: 16px;
    4.43 +					}
    4.44 +					
    4.45 +					.wwwLinks {
    4.46 +						border-top: 2px solid grey;
    4.47 +						margin-top: 16px;
    4.48 +						font-size: 66%;
    4.49 +					}
    4.50 +					
    4.51 +					blockquote {
    4.52 +						background-color: #eee;
    4.53 +						font-style: italic;
    4.54 +						padding: 2px 20px;
    4.55 +						margin: 10px 32px;
    4.56 +						border-left: 3px solid silver;
    4.57 +					}
    4.58 +					
    4.59 +					pre {
    4.60 +						background-color: #eee;
    4.61 +						padding: 2px 20px;
    4.62 +						margin: 10px 32px;
    4.63 +						border-left: 3px solid #a00;
    4.64 +					}
    4.65 +					
    4.66 +					img {
    4.67 +						margin: 8px;
    4.68 +					}
    4.69 +					
    4.70 +					a img {
    4.71 +						border: none;
    4.72 +					}
    4.73 +				</style>
    4.74 +			</head>
    4.75 +			<body>
    4.76 +				<xsl:if test="$title and $isRoot">
    4.77 +					<h1><xsl:value-of select="$title"/></h1>			
    4.78 +				</xsl:if>
    4.79 +				<xsl:apply-templates select="h:html/h:body/node()"/>
    4.80 +				
    4.81 +				<xsl:if test="$wwwRead or $wwwPost">
    4.82 +					<div class="wwwLinks">
    4.83 +						<p>Přístup přes síť www:</p>
    4.84 +						<ul>
    4.85 +							<xsl:if test="$wwwRead"><li><a href="{$wwwRead}">číst tento příspěvek</a></li></xsl:if>
    4.86 +							<xsl:if test="$wwwPost"><li><a href="{$wwwPost}">odpovědět na tento příspěvek</a></li></xsl:if>
    4.87 +						</ul>
    4.88 +					</div>
    4.89 +				</xsl:if>
    4.90 +			</body>
    4.91 +		</html>
    4.92 +	</xsl:template>
    4.93 +	
    4.94 +	
    4.95 +	<!-- Odkazy -->
    4.96 +	<xsl:template match="h:a">
    4.97 +		<a href="{@href}" title="{@title}"><xsl:apply-templates/></a>
    4.98 +	</xsl:template>
    4.99 +	
   4.100 +	
   4.101 +	<!-- Obrázky -->
   4.102 +	<xsl:template match="h:img">
   4.103 +		<img src="{@src}" alt="{@alt}" title="{@title}"><xsl:apply-templates/></img>
   4.104 +	</xsl:template>
   4.105 +	
   4.106 +	<!-- Zkratky -->
   4.107 +	<xsl:template match="h:abbr">
   4.108 +		<abbr title="{@title}"><xsl:apply-templates/></abbr>
   4.109 +	</xsl:template>
   4.110 +	
   4.111 +	
   4.112 +	<!-- Další povolené značky – ostatní odfiltrujeme (zbude z nich jen text) -->
   4.113 +	<xsl:template match="*">
   4.114 +		<xsl:choose>		
   4.115 +			<xsl:when test="
   4.116 +				name() = 'h1' or
   4.117 +				name() = 'h2' or
   4.118 +				name() = 'h3' or
   4.119 +				name() = 'h4' or
   4.120 +				name() = 'h5' or
   4.121 +				name() = 'h6' or
   4.122 +				name() = 'p' or
   4.123 +				name() = 'div' or
   4.124 +				name() = 'br' or
   4.125 +				name() = 'strong' or
   4.126 +				name() = 'em' or
   4.127 +				name() = 'sub' or
   4.128 +				name() = 'sup' or
   4.129 +				name() = 'del' or
   4.130 +				name() = 'ul' or
   4.131 +				name() = 'ol' or
   4.132 +				name() = 'li' or
   4.133 +				name() = 'pre' or
   4.134 +				name() = 'code' or
   4.135 +				name() = 'blockquote'">
   4.136 +				<xsl:element name="{name()}">
   4.137 +					<xsl:apply-templates/>
   4.138 +				</xsl:element>
   4.139 +			</xsl:when>
   4.140 +			<xsl:otherwise>
   4.141 +				<xsl:value-of select="."/>
   4.142 +			</xsl:otherwise>
   4.143 +		</xsl:choose>		
   4.144 +    </xsl:template>
   4.145 +    
   4.146 +    
   4.147 +    <!-- 
   4.148 +    	Z neuzavřeného (nevalidně se vyskytujícího v body) textu uděláme odstavce.
   4.149 +    	Bohužel nefunguje, když neuzavřený text obsahuje jiné značky (odkazy atd.),
   4.150 +    	pak se totiž jedná o dva textové uzly (před značkou a za ní) a vzniknou dva odstavce.
   4.151 +    -->
   4.152 +	<xsl:template match="h:body/text()">
   4.153 +		<xsl:call-template name="makeParagraphs">
   4.154 +			<xsl:with-param name="string" select="."/>
   4.155 +		</xsl:call-template>
   4.156 +	</xsl:template>
   4.157 +    <xsl:variable name="newLinePlaceholder" select="'ߜ'"/>
   4.158 +    <xsl:template name="makeParagraphs">
   4.159 +    	<xsl:param name="string" />
   4.160 +    	<xsl:call-template name="makeParagraphsInternal">
   4.161 +    		<!--
   4.162 +    			Konec řádku převedeme na obskurní znak, 
   4.163 +    			normalizací pročistíme bílé znaky → 
   4.164 +    			dva obskurní znaky oddělené mezerou pak značí předěl mezi odstavci
   4.165 +    		-->
   4.166 +    		<xsl:with-param name="string" select="normalize-space(translate(., '&#10;', $newLinePlaceholder))"/>
   4.167 +    	</xsl:call-template>
   4.168 +    </xsl:template>
   4.169 +	<xsl:template name="makeParagraphsInternal">
   4.170 +		<xsl:param name="string" />
   4.171 +		<xsl:if test="ends-with($string, $newLinePlaceholder)"><xsl:comment>končí na $newLinePlaceholder</xsl:comment> </xsl:if>
   4.172 +		<!-- V XSLT 2.0 můžeme použít fn:tokenize -->
   4.173 +		<xsl:param name="delimiter" select="concat($newLinePlaceholder, ' ', $newLinePlaceholder)"/>
   4.174 +		<xsl:choose>
   4.175 +			<xsl:when test="$delimiter and contains($string, $delimiter)">
   4.176 +				<xsl:call-template name="makeParagraph">
   4.177 +					<xsl:with-param name="string" select="substring-before($string, $delimiter)"></xsl:with-param>
   4.178 +				</xsl:call-template>
   4.179 +				<xsl:call-template name="makeParagraphsInternal">
   4.180 +					<xsl:with-param name="string" select="substring-after($string, $delimiter)" />
   4.181 +					<xsl:with-param name="delimiter" select="$delimiter" />
   4.182 +				</xsl:call-template>
   4.183 +			</xsl:when>
   4.184 +			<xsl:otherwise>
   4.185 +				<!--
   4.186 +					Poslední odstavec → zkontrolovat, zda je za ním  
   4.187 +				-->
   4.188 +				<xsl:call-template name="makeParagraph">
   4.189 +					<xsl:with-param name="string" select="$string"></xsl:with-param>
   4.190 +				</xsl:call-template>
   4.191 +			</xsl:otherwise>
   4.192 +		</xsl:choose>
   4.193 +	</xsl:template>
   4.194 +	<xsl:template name="makeParagraph">
   4.195 +		<xsl:param name="string" />
   4.196 +			<!-- prázdné textové uzly nás nezajímají – nechceme prázdné odstavce -->
   4.197 +			<xsl:if test="normalize-space($string)">
   4.198 +				<p class="mešuge"><xsl:value-of select="translate($string, $newLinePlaceholder, '&#10;')" /></p>				
   4.199 +			</xsl:if>
   4.200 +	</xsl:template>
   4.201 +
   4.202 +</xsl:stylesheet>