# HG changeset patch # User František Kučera <franta-hg@frantovo.cz> # Date 1301841282 -7200 # Node ID 801a8935caf766c2ddabe5b0a39adc385026aa00 # Parent 0a7c6c9357d33886b415f09e3a8d462cc060afe7 Java funkce pro zjištění poslední úpravy souboru, Atom agregace, konfigurační soubor webu. diff -r 0a7c6c9357d3 -r 801a8935caf7 analýza/princip.dot --- a/analýza/princip.dot Sun Apr 03 02:39:06 2011 +0200 +++ b/analýza/princip.dot Sun Apr 03 16:34:42 2011 +0200 @@ -1,11 +1,20 @@ digraph princip { rankdir=LR - gen [label="Generátor" shape="box" labelURL="xxxxxxxx"] + gen [label="Generátor\n(Ant: build.xml)" shape="box"] xml [label="Texty v XML"] xhtml [label="XHTML web"] - xslt [label="XSLT šablona"] + xslt [label="XSLT šablony"] + + atom [label="Atom"] + rss [label="RSS"] + sitemap [label="sitemap.xml"] - xml -> gen -> xhtml; + xml -> gen; xslt -> gen; + + gen -> xhtml; + gen -> atom; + gen -> rss; + gen -> sitemap; } diff -r 0a7c6c9357d3 -r 801a8935caf7 build.xml --- a/build.xml Sun Apr 03 02:39:06 2011 +0200 +++ b/build.xml Sun Apr 03 16:34:42 2011 +0200 @@ -7,19 +7,37 @@ <property name="temp" value="temp"/> <property name="funkce" value="${šablona}/funkce/build/classes"/> - <target name="generuj" description="Vygeneruje XHTML webové stránky."> + <target name="generuj" description="Vygeneruje kompletní web." depends="kompiluj-funkce,stránky,agregace"> + </target> + + <target name="stránky" description="Vygeneruje XHTML webové stránky."> <xslt basedir="${vstup}" destdir="${výstup}" includes="*.xml" extension=".xhtml" style="${šablona}/stránka.xsl"> <classpath location="/usr/share/java/saxonb-9.0.jar"/> - <classpath location="${funkce}"/> - - <factory name="net.sf.saxon.TransformerFactoryImpl"> + <classpath location="${funkce}"/> + <factory name="net.sf.saxon.TransformerFactoryImpl"> <attribute name="http://saxon.sf.net/feature/allow-external-functions" value="true"/> </factory> - - <sysproperty key="javax.xml.parsers.DocumentBuilderFactory" value="org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"/> - <sysproperty key="javax.xml.parsers.SAXParserFactory" value="org.apache.xerces.jaxp.SAXParserFactoryImpl"/> - <sysproperty key="org.apache.xerces.xni.parser.XMLParserConfiguration" value="org.apache.xerces.parsers.XIncludeParserConfiguration"/> </xslt> </target> + <target name="agregace" description="Vytvoří agregované výstupy: RSS, Atom, Sitemap.xml"> + <xslt in="${vstup}/web.conf" out="${výstup}/atom.xml" style="${šablona}/atom.xsl"> + <param name="konfigurák" expression="../vstup/web.conf"/> + <classpath location="/usr/share/java/saxonb-9.0.jar"/> + <classpath location="${funkce}"/> + <factory name="net.sf.saxon.TransformerFactoryImpl"> + <attribute name="http://saxon.sf.net/feature/allow-external-functions" value="true"/> + </factory> + </xslt> + </target> + + <target name="kompiluj-funkce" description=""> + <mkdir dir="${funkce}"/> + <javac + srcdir="${šablona}/funkce/src" + destdir="${funkce}" + includeAntRuntime="no"> + </javac> + </target> + </project> diff -r 0a7c6c9357d3 -r 801a8935caf7 vstup/web.conf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vstup/web.conf Sun Apr 03 16:34:42 2011 +0200 @@ -0,0 +1,12 @@ +<web xmlns="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/prostor"> + <název>Chovatelská stanice tučňáků</název> + <podtitul>vše pro tučňáky</podtitul> + <autor> + <jméno>František Kučera</jméno> + <email>nereknu_nechci_spam@example.com</email> + </autor> + <url>https://trac.frantovo.cz/xml-web-generator/</url> + <uuid>399a714c-956e-444c-a8f4-afe8f0df802a</uuid> + <kod>PokusnyWeb123</kod> + +</web> diff -r 0a7c6c9357d3 -r 801a8935caf7 šablona/atom.xsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/šablona/atom.xsl Sun Apr 03 16:34:42 2011 +0200 @@ -0,0 +1,44 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xsl:stylesheet version="2.0" + xmlns="http://www.w3.org/2005/Atom" + xmlns:g="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/prostor" + xmlns:j="java:cz.frantovo.xmlWebGenerator.Funkce" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:fn="http://www.w3.org/2005/xpath-functions" + exclude-result-prefixes="fn g j"> + <xsl:output method="xml" indent="yes" encoding="UTF-8"/> + + <xsl:param name="konfigurák"></xsl:param> + + <xsl:template match="/"> + <!-- TODO: proměnná: --> + <xsl:variable name="konfigurace" select="document($konfigurák)"/> + + <feed> + <title><xsl:value-of select="$konfigurace/g:web/g:název"/></title> + <subtitle><xsl:value-of select="$konfigurace/g:web/g:podtitul"/></subtitle> + <link rel="self" href="{concat($konfigurace/g:web/g:url, 'atom.xml')}"/> + <link href="{$konfigurace/g:web/g:url}"/> + <updated><xsl:value-of select="current-dateTime()"/></updated> + <author> + <name><xsl:value-of select="$konfigurace/g:web/g:autor/g:jméno"/></name> + <email><xsl:value-of select="$konfigurace/g:web/g:autor/g:email"/></email> + </author> + <id><xsl:value-of select="concat('urn:uuid:', $konfigurace/g:web/g:uuid)"/></id> + + <xsl:for-each select="collection('../vstup/?select=*.xml')[empty(g:stránka/g:skrytá) or not(g:stránka/g:skrytá)]"> + <entry> + <title><xsl:value-of select="g:stránka/g:nadpis"/></title> + <xsl:variable name="soubor" select="replace(tokenize(document-uri(.), '/')[last()], '.xml', '')"/> + <link href="{concat($konfigurace/g:web/g:url, encode-for-uri($soubor), '.xhtml')}" /> + <id><xsl:value-of select="concat('urn:', $konfigurace/g:web/g:kod ,':strana:', encode-for-uri($soubor))"/></id> + <!--2010-10-09T20:51:04Z--> + <updated><xsl:value-of select="j:posledníZměna(document-uri(.))"/></updated> + <summary><xsl:value-of select="g:stránka/g:perex"/></summary> + </entry> + </xsl:for-each> + + </feed> + </xsl:template> + +</xsl:stylesheet> diff -r 0a7c6c9357d3 -r 801a8935caf7 šablona/funkce/src/cz/frantovo/xmlWebGenerator/Funkce.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/šablona/funkce/src/cz/frantovo/xmlWebGenerator/Funkce.java Sun Apr 03 16:34:42 2011 +0200 @@ -0,0 +1,13 @@ +package cz.frantovo.xmlWebGenerator; + +import java.io.File; +import java.util.Date; +import java.net.URI; +import java.net.URISyntaxException; + +public class Funkce { + public static Date posledníZměna(String soubor) throws URISyntaxException { + return new Date(new File(new URI(soubor)).lastModified()); + } +} + diff -r 0a7c6c9357d3 -r 801a8935caf7 šablona/stránka.xsl --- a/šablona/stránka.xsl Sun Apr 03 02:39:06 2011 +0200 +++ b/šablona/stránka.xsl Sun Apr 03 16:34:42 2011 +0200 @@ -18,7 +18,9 @@ <xsl:template match="/"> <html> <head> - <title><xsl:value-of select="g:stránka/g:nadpis"/></title> + <title><xsl:value-of select="g:stránka/g:nadpis"/></title> + <link title="Novinky (Atom)" href="atom.xml" type="application/atom+xml" rel="alternate" /> + <link title="Novinky (RSS)" href="rss.xml" type="application/atom+xml" rel="alternate" /> </head> <body> <xsl:apply-templates select="document(fn:encode-for-uri('../vstup/záhlaví.inc'))/g:stránka/h:text/node()"/>