Dave Jarvis' Repositories

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

Platform independence for file paths. Clarified intent of dynamic template import.

Author Dave Jarvis <email>
Date 2015-01-15 17:34:24 GMT-0800
Commit c6e80d70584deaefe538b85ba7cc43b105365820
Parent b14e87f
source/java/to/discuss/Base.java
*/
public interface Base {
+ public final static String FILE_SEP = System.getProperty( "file.separator" );
+
/**
* Subclasses can use this to open a file in the resources directory.
source/java/to/discuss/util/AppURIResolver.java
public Source resolve( String href, String base )
throws TransformerException {
- Source result = null;
- URI uri = null;
-
try {
- uri = new URI( href );
+ return isTemplate( new URI( href ) ) ? openTemplate() : openFile( href );
}
catch( Exception e ) {
throw new TransformerException( e );
- }
-
- // The XSLT file has a URI path that allows for a file to be included
- // dynamically.
- if( "import".equalsIgnoreCase( uri.getScheme() ) &&
- "discuss.to".equalsIgnoreCase( uri.getAuthority() ) ) {
- result = openAppTemplate();
- }
- else {
- result = getDelegate().resolve( href, base );
}
+ }
- return result;
+ /**
+ * Answers with the URI points to a dynamic template to include into the
+ * stylesheet.
+ */
+ protected boolean isTemplate( URI uri ) {
+ return "template".equalsIgnoreCase( uri.getScheme() ) &&
+ "discuss.to".equalsIgnoreCase( uri.getAuthority() );
}
/**
* Guaranteed to open an XSL template that corresponds to the app name.
* If no template is found, or the default template file is missing, this
* will return a hard-coded string as a StreamSource.
*
* @return A valid StreamSource containing a stylesheet DOM.
*/
- private Source openAppTemplate() {
+ private Source openTemplate() {
Source result = null;
try {
result = new StreamSource( open( getStylesheetFilename() ) );
}
catch( IOException ioe ) {
try {
- result = new StreamSource( open( "xsl/template.xsl" ) );
+ result = new StreamSource( open( "xsl" + FILE_SEP + "template.xsl" ) );
}
catch( Exception e ) {
result = new StreamSource( getDefaultTemplate() );
}
}
return result;
+ }
+
+ /**
+ * Opens a stylesheet relative to the XSL directory.
+ */
+ private Source openFile( String href ) throws IOException {
+ return new StreamSource( open( "xsl" + FILE_SEP + href ) );
}
private String getStylesheetFilename() {
- return String.format( "xsl/%s.xsl", getApp().getAppName() );
+ return String.format( "xsl%s%s.xsl", FILE_SEP, getApp().getAppName() );
}
source/xsl/common.xsl
<!-- Custom URI resolver to import an XSL file corresponding to the app. -->
-<xsl:include href="import://discuss.to/app"/>
+<xsl:include href="template://discuss.to/app"/>
<!-- Action parser that responds to HTTP requests. -->
source/xsl/resources.xsl
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ | MIT License
+ |
+ | Copyright 2014 White Magic Software, Inc.
+ +-->
+<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+<xsl:include href="chart.xsl"/>
+
+<xsl:variable name="artefacts">
+<artefacts>
+ <css>resources</css>
+</artefacts>
+</xsl:variable>
+
+</xsl:stylesheet>
Delta 39 lines added, 19 lines removed, 20-line increase