| | 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() ); |
| | } |
| | |