Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/delibero.git

Added menu system.

Author Dave Jarvis <email>
Date 2015-01-17 14:04:41 GMT-0800
Commit c60434983478035b1c01816c10ef17857307445d
Parent 57d39eb
build.gradle
sourceSets {
main {
- output.resourcesDir = 'build/resources'
- output.classesDir = 'build/classes'
+ output.resourcesDir = "$buildDir/resources"
+ output.classesDir = "$buildDir/classes"
java {
task configured {
copy {
- from 'source/xsl'
- into 'build/resources/xsl'
- include '**/*'
+ from "source/xsl"
+ into "$buildDir/resources/xsl"
+ exclude "menu"
+ include "**/*"
}
copy {
- from 'source/css'
- into 'build/resources/static/css'
- include '**/*'
+ from "source/xsl/menu"
+ into "$buildDir/resources/xsl/menu"
+ exclude "menu.xml"
+ include "*.xml"
}
copy {
- from 'source/js'
- into 'build/resources/static/js'
- include '**/*'
+ from "source/css"
+ into "$buildDir/resources/static/css"
+ include "**/*"
}
copy {
- from 'source/fonts'
- into 'build/resources/static/fonts'
- include '**/*'
+ from "source/js"
+ into "$buildDir/resources/static/js"
+ include "**/*"
+ }
+
+ copy {
+ from "source/fonts"
+ into "$buildDir/resources/static/fonts"
+ include "**/*"
}
+}
+
+task copyLibraries(type: Copy) {
+ from configurations.runtime
+ into "$buildDir/libs"
}
+
+build.dependsOn( copyLibraries )
dependencies {
// Authentication and authorization
compile "org.apache.shiro:shiro-core:1.2.3"
// XSLT 2.0 with EXSLT (http://exslt.org/)
compile "net.sourceforge.saxon:saxon:9.1.0.8"
+
+ // Xerces XML parser
+ compile "xerces:xercesImpl:2.11.0"
// XSLT 2.0 without EXLST
resources/log4j.properties
+#
+# Jetty logging configuration file
+#
#log4j.rootLogger=DEBUG, CONSOLE
log4j.rootLogger=INFO, CONSOLE
resources/static.properties
-# Configures the default servlet handler for static files.
+#
+# Servlet handler configuration file.
#
# http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/servlet/DefaultServlet.html
resources/system.properties
+#
+# Calls System.setProperty for each of the name/value pairs.
+#
+javax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl
+
source/css/home.css
@charset "utf-8";
+@import url( "xref.css" );
+
.policy {
display: flex;
source/css/rationale.css
-@charset "utf-8";
-
-@import url( "xref.css" );
-@import url( "list.css" );
-
-.policy {
- padding-bottom: 0.5em;
- border-bottom: 1px solid black;
-}
-
-.policy, .title {
- border-bottom: 1px solid black;
-}
-
-.paragraph {
- margin-bottom: 0.5em;
-}
-
-.hypotheses > .general::before {
- content: "General Hypothesis";
-}
-
-.hypotheses > .directional::before {
- content: "Directional Hypothesis";
-}
-
-.hypotheses > .measurable::before {
- content: "Measurable Hypothesis";
-}
-
-.hypotheses > *::before {
- font-family: 'Montserrat', Helvetica, sans-serif;
- font-size: 1.2em;
- font-weight: bold;
-}
-
-.hypotheses > * > .paragraph {
- padding-top: 0.5em;
- padding-bottom: 0.5em;
-}
source/css/success.css
+@charset "utf-8";
+
+@import url( "xref.css" );
+@import url( "list.css" );
+
+.policy {
+ padding-bottom: 0.5em;
+ border-bottom: 1px solid black;
+}
+
+.policy, .title {
+ border-bottom: 1px solid black;
+}
+
+.paragraph {
+ margin-bottom: 0.5em;
+}
+
+.hypotheses > .general::before {
+ content: "General Hypothesis";
+}
+
+.hypotheses > .directional::before {
+ content: "Directional Hypothesis";
+}
+
+.hypotheses > .measurable::before {
+ content: "Measurable Hypothesis";
+}
+
+.hypotheses > *::before {
+ font-family: 'Montserrat', Helvetica, sans-serif;
+ font-size: 1.2em;
+ font-weight: bold;
+}
+
+.hypotheses > * > .paragraph {
+ padding-top: 0.5em;
+ padding-bottom: 0.5em;
+}
source/java/to/discuss/App.java
private void sendContent() throws Exception {
- getTransformer().transform( getDocument(), getResultStream() );
+ Transformer transformer = getTransformer();
+ transformer.setParameter( "APP_ID", getAppId() );
+ transformer.transform( getDocument(), getResultStream() );
}
// slash that might follow the application name.
return path.substring( 0, index > 0 ? index : path.length() );
+ }
+
+ /**
+ * Returns the numeric identifier at application URL end.
+ *
+ * @return 0 if the identifier could not be found.
+ */
+ public long getAppId() {
+ long result;
+
+ try {
+ String path = getRequestPathInfo();
+ // Everything after the last slash is a potential identifier.
+ result = Long.parseLong( path.substring( path.lastIndexOf( '/' ) + 1 ) );
+ }
+ catch( Exception e ) {
+ result = 0;
+ }
+
+ return result;
}
source/java/to/discuss/Main.java
ServletContextHandler context = new ServletContextHandler();
+ configureSystemProperties();
configureServletMap( context );
configureServletDefault( context );
server.setHandler( context );
server.start();
server.join();
+ }
+
+ protected void configureSystemProperties() throws Exception {
+ Map<String, String> map = getSystemPropertyMap();
+
+ for( String name : map.keySet() ) {
+ System.setProperty( name, map.get( name ) );
+ }
}
DefaultServlet staticServlet = new DefaultServlet();
context.addServlet( new ServletHolder( staticServlet ), "/*" );
+ }
+
+ private Map<String, String> getSystemPropertyMap() throws Exception {
+ return getPropertyMap( "system.properties" );
}
source/xsl/account.xsl
<artefacts>
<css>account</css>
- <menu>
- <item>home</item>
- </menu>
+ <xsl:copy-of select="document( 'menu/account.xml' )"/>
</artefacts>
</xsl:variable>
source/xsl/common.xsl
<xsl:include href="template://discuss.to/app"/>
-<!-- Action parser that responds to HTTP requests. -->
+<!-- Application context that responds to HTTP requests. -->
<xsl:param name="CONTEXT" select="'app'"/>
+
+<!-- Identifier on the URL. -->
+<xsl:param name="APP_ID" select="0"/>
<xsl:template match="/">
<xsl:template match="item" mode="menu">
- <li class="item"><a href="/{$CONTEXT}/{.}/"><xsl:apply-templates/></a></li>
+ <li class="item">
+ <a href="/{$CONTEXT}/{.}/{$APP_ID}"><xsl:apply-templates/></a>
+ </li>
</xsl:template>
source/xsl/discuss.xsl
+<?xml version='1.0' encoding='utf-8'?>
+<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
+
+<xsl:variable name="artefacts">
+<artefacts>
+ <css>discuss</css>
+ <xsl:copy-of select="document( 'menu/discuss.xml' )"/>
+</artefacts>
+</xsl:variable>
+
+</xsl:stylesheet>
source/xsl/home.xsl
<artefacts>
<css>home</css>
+ <xsl:copy-of select="document( 'menu/home.xml' )"/>
</artefacts>
</xsl:variable>
source/xsl/menu/account.xml
-
+<?xml version="1.0" encoding="utf-8"?>
+<menu>
+ <item>home</item>
+</menu>
source/xsl/menu/build.sh
+#!/bin/bash
+
+java -cp "../../../build/libs/*" net.sf.saxon.Transform \
+ -s:menu.xml -xsl:menu.xsl
+
source/xsl/menu/discuss.xml
-
+<?xml version="1.0" encoding="utf-8"?>
+<menu>
+ <item>home</item>
+ <item>synopsis</item>
+ <item>proposal</item>
+ <item>resources</item>
+ <item>success</item>
+ <item>account</item>
+ <item>edit</item>
+ <item>flag</item>
+</menu>
source/xsl/menu/home.xml
-
+<?xml version="1.0" encoding="utf-8"?>
+<menu>
+ <item>account</item>
+ <item>tags</item>
+</menu>
source/xsl/menu/menu.xml
+<?xml version="1.0" encoding="utf-8"?>
+<menus>
+ <items>
+ <item id="1">home</item>
+ <item id="2">synopsis</item>
+ <item id="3">proposal</item>
+ <item id="4">resources</item>
+ <item id="5">discuss</item>
+ <item id="6">success</item>
+ <item id="7">account</item>
+ <item id="8">tags</item>
+ <item id="9">edit</item>
+ <item id="10">flag</item>
+ <item id="11">support</item>
+ </items>
+ <menu id="1">
+ <item id="7"/> <item id="8"/>
+ </menu>
+ <menu id="2">
+ <item id="1"/> <item id="3"/> <item id="4"/> <item id="5"/> <item id="6"/>
+ <item id="7"/>
+ </menu>
+ <menu id="3">
+ <item id="1"/> <item id="2"/> <item id="4"/> <item id="5"/> <item id="6"/>
+ <item id="7"/> <item id="9"/> <item id="10"/>
+ </menu>
+ <menu id="4">
+ <item id="1"/> <item id="2"/> <item id="3"/> <item id="5"/> <item id="6"/>
+ <item id="7"/> <item id="9"/> <item id="10"/>
+ </menu>
+ <menu id="5">
+ <item id="1"/> <item id="2"/> <item id="3"/> <item id="4"/> <item id="6"/>
+ <item id="7"/> <item id="9"/> <item id="10"/>
+ </menu>
+ <menu id="6">
+ <item id="1"/> <item id="2"/> <item id="3"/> <item id="4"/> <item id="5"/>
+ <item id="7"/> <item id="9"/> <item id="10"/>
+ </menu>
+ <menu id="7">
+ <item id="1"/>
+ </menu>
+ <menu id="8">
+ <item id="1"/>
+ </menu>
+ <menu id="11">
+ <item id="1"/> <item id="3"/> <item id="4"/> <item id="4"/> <item id="5"/>
+ <item id="6"/> <item id="7"/> <item id="9"/> <item id="10"/>
+ </menu>
+</menus>
+
source/xsl/menu/menu.xsl
+<?xml version='1.0' encoding='utf-8'?>
+<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
+
+<xsl:output indent="yes" method="xml" encoding="utf-8"/>
+
+<xsl:strip-space elements="*"/>
+
+<xsl:key name="items" match="/menus/items/item" use="@id"/>
+
+<xsl:template match="/">
+ <xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template match="menus">
+ <xsl:apply-templates select="menu"/>
+</xsl:template>
+
+<xsl:template match="menu">
+ <xsl:variable name="menu" select="key( 'items', @id )"/>
+ <xsl:result-document href="{$menu}.xml" method="xml">
+ <menu>
+ <xsl:apply-templates />
+ </menu>
+ </xsl:result-document>
+</xsl:template>
+
+<xsl:template match="item">
+ <item><xsl:value-of select="key( 'items', @id )"/></item>
+</xsl:template>
+
+<!-- Ignore /menus/items -->
+<xsl:template match="*"/>
+
+</xsl:stylesheet>
source/xsl/menu/proposal.xml
-
+<?xml version="1.0" encoding="utf-8"?>
+<menu>
+ <item>home</item>
+ <item>synopsis</item>
+ <item>resources</item>
+ <item>discuss</item>
+ <item>success</item>
+ <item>account</item>
+ <item>edit</item>
+ <item>flag</item>
+</menu>
source/xsl/menu/resources.xml
-
+<?xml version="1.0" encoding="utf-8"?>
+<menu>
+ <item>home</item>
+ <item>synopsis</item>
+ <item>proposal</item>
+ <item>discuss</item>
+ <item>success</item>
+ <item>account</item>
+ <item>edit</item>
+ <item>flag</item>
+</menu>
source/xsl/menu/success.xml
-
+<?xml version="1.0" encoding="utf-8"?>
+<menu>
+ <item>home</item>
+ <item>synopsis</item>
+ <item>proposal</item>
+ <item>resources</item>
+ <item>discuss</item>
+ <item>account</item>
+ <item>edit</item>
+ <item>flag</item>
+</menu>
source/xsl/menu/support.xml
-
+<?xml version="1.0" encoding="utf-8"?>
+<menu>
+ <item>home</item>
+ <item>proposal</item>
+ <item>resources</item>
+ <item>resources</item>
+ <item>discuss</item>
+ <item>success</item>
+ <item>account</item>
+ <item>edit</item>
+ <item>flag</item>
+</menu>
source/xsl/menu/synopsis.xml
-
+<?xml version="1.0" encoding="utf-8"?>
+<menu>
+ <item>home</item>
+ <item>proposal</item>
+ <item>resources</item>
+ <item>discuss</item>
+ <item>success</item>
+ <item>account</item>
+</menu>
source/xsl/menu/tags.xml
-
+<?xml version="1.0" encoding="utf-8"?>
+<menu>
+ <item>home</item>
+</menu>
source/xsl/proposal.xsl
<artefacts>
<css>proposal</css>
- <menu>
- <item>home</item>
- <item>edit</item>
- <item>resources</item>
- <item>discuss</item>
- <item>success</item>
- </menu>
+ <xsl:copy-of select="document( 'menu/proposal.xml' )"/>
</artefacts>
</xsl:variable>
source/xsl/resources.xsl
<artefacts>
<css>resources</css>
- <menu>
- <item>home</item>
- <item>proposal</item>
- <item>discuss</item>
- <item>success</item>
- <item>flag</item>
- </menu>
+ <xsl:copy-of select="document( 'menu/resources.xml' )"/>
</artefacts>
</xsl:variable>
source/xsl/success.xsl
<xsl:variable name="artefacts">
<artefacts>
- <css>rationale</css>
- <menu>
- <item>home</item>
- <item>proposal</item>
- <item>discuss</item>
- <item>success</item>
- </menu>
+ <css>success</css>
+ <xsl:copy-of select="document( 'menu/success.xml' )"/>
</artefacts>
</xsl:variable>
source/xsl/support.xsl
<js>editor.min</js>
<js>support</js>
- <menu>
- <item>home</item>
- <item>proposal</item>
- <item>discuss</item>
- <item>success</item>
- <item>flag</item>
- </menu>
+ <xsl:copy-of select="document( 'menu/support.xml' )"/>
</artefacts>
</xsl:variable>
source/xsl/synopsis.xsl
<artefacts>
<css>synopsis</css>
- <menu>
- <item>home</item>
- <item>proposal</item>
- <item>resources</item>
- <item>discuss</item>
- <item>success</item>
- </menu>
+ <xsl:copy-of select="document( 'menu/synopsis.xml' )"/>
</artefacts>
</xsl:variable>
source/xsl/tags.xsl
<js>jquery.min</js>
<js>tags</js>
+ <xsl:copy-of select="document( 'menu/tags.xml' )"/>
</artefacts>
</xsl:variable>
Delta 314 lines added, 105 lines removed, 209-line increase