← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1506: More XSLT fun. Work in progress on help center

 

------------------------------------------------------------
revno: 1506
committer: Lars Helge Oeverland <larshelge@xxxxxxxxx>
branch nick: trunk
timestamp: Thu 2010-02-25 16:43:36 +0100
message:
  More XSLT fun. Work in progress on help center
added:
  dhis-2/dhis-options/src/main/resources/helpitems_stylesheet.xsl
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/help/action/GetHelpItemsAction.java
modified:
  dhis-2/dhis-options/src/main/java/org/hisp/dhis/options/help/DefaultHelpManager.java
  dhis-2/dhis-options/src/main/java/org/hisp/dhis/options/help/HelpManager.java
  dhis-2/dhis-options/src/test/java/org/hisp/dhis/options/help/HelpManagerTest.java
  dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription.
=== modified file 'dhis-2/dhis-options/src/main/java/org/hisp/dhis/options/help/DefaultHelpManager.java'
--- dhis-2/dhis-options/src/main/java/org/hisp/dhis/options/help/DefaultHelpManager.java	2010-02-23 19:44:51 +0000
+++ dhis-2/dhis-options/src/main/java/org/hisp/dhis/options/help/DefaultHelpManager.java	2010-02-25 15:43:36 +0000
@@ -44,20 +44,22 @@
 public class DefaultHelpManager
     implements HelpManager
 {
+    // -------------------------------------------------------------------------
+    // HelpManager implementation
+    // -------------------------------------------------------------------------
+
     public void getHelpContent( OutputStream out, String id )
     {
         try
         {
-            Source stylesheet = new StreamSource( new ClassPathResource( "help_stylesheet.xsl" ).getInputStream() );
-            
-            Transformer transformer = TransformerFactory.newInstance().newTransformer( stylesheet );
+            Source source = new StreamSource( new ClassPathResource( "help_content.xml" ).getInputStream() );
+            
+            Result result = new StreamResult( out );
+            
+            Transformer transformer = getTransformer( "help_stylesheet.xsl" );
             
             transformer.setParameter( "sectionId", id );
             
-            Source source = new StreamSource( new ClassPathResource( "help_content.xml" ).getInputStream() );
-            
-            Result result = new StreamResult( out );
-            
             transformer.transform( source, result );
         }
         catch ( Exception ex )
@@ -65,4 +67,32 @@
             throw new RuntimeException( "Failed to get help content", ex );
         }
     }
+    
+    public void getHelpItems( OutputStream out )
+    {
+        try
+        {
+            Source source = new StreamSource( new ClassPathResource( "help_content.xml" ).getInputStream() );
+            
+            Result result = new StreamResult( out );
+            
+            getTransformer( "helpitems_stylesheet.xsl" ).transform( source, result );
+        }
+        catch ( Exception ex )
+        {
+            throw new RuntimeException( "Failed to get help content", ex );
+        }
+    }
+
+    // -------------------------------------------------------------------------
+    // Supportive methods
+    // -------------------------------------------------------------------------
+
+    private Transformer getTransformer( String stylesheetName )
+        throws Exception
+    {
+        Source stylesheet = new StreamSource( new ClassPathResource( stylesheetName ).getInputStream() );
+        
+        return TransformerFactory.newInstance().newTransformer( stylesheet );
+    }
 }

=== modified file 'dhis-2/dhis-options/src/main/java/org/hisp/dhis/options/help/HelpManager.java'
--- dhis-2/dhis-options/src/main/java/org/hisp/dhis/options/help/HelpManager.java	2010-02-23 17:10:02 +0000
+++ dhis-2/dhis-options/src/main/java/org/hisp/dhis/options/help/HelpManager.java	2010-02-25 15:43:36 +0000
@@ -37,4 +37,6 @@
     final String ID = HelpManager.class.getName();
     
     void getHelpContent( OutputStream out, String id );
+    
+    void getHelpItems( OutputStream out );
 }

=== added file 'dhis-2/dhis-options/src/main/resources/helpitems_stylesheet.xsl'
--- dhis-2/dhis-options/src/main/resources/helpitems_stylesheet.xsl	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-options/src/main/resources/helpitems_stylesheet.xsl	2010-02-25 15:43:36 +0000
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
+
+<xsl:template match="section">
+  <li><a href="javascript:getHelpContent('{@id}')"><xsl:value-of select="title"/></a></li>
+</xsl:template>
+
+<xsl:template match="/">
+<ul>
+  <xsl:apply-templates select="book/chapter//section[@id]"/>
+</ul>
+</xsl:template>
+
+</xsl:stylesheet>

=== modified file 'dhis-2/dhis-options/src/test/java/org/hisp/dhis/options/help/HelpManagerTest.java'
--- dhis-2/dhis-options/src/test/java/org/hisp/dhis/options/help/HelpManagerTest.java	2010-02-23 17:10:02 +0000
+++ dhis-2/dhis-options/src/test/java/org/hisp/dhis/options/help/HelpManagerTest.java	2010-02-25 15:43:36 +0000
@@ -51,7 +51,7 @@
     }
 
     @Test
-    public void testGetHelpContent()
+    public void testGetEmbeddedHelpContent()
     {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
                 
@@ -59,4 +59,14 @@
         
         log.debug( out.toString() );        
     }
+    
+    @Test
+    public void testGetHelpCenterContent()
+    {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        
+        helpManager.getHelpItems( out );
+        
+        log.debug( out.toString() );        
+    }
 }

=== added file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/help/action/GetHelpItemsAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/help/action/GetHelpItemsAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/help/action/GetHelpItemsAction.java	2010-02-25 15:43:36 +0000
@@ -0,0 +1,70 @@
+package org.hisp.dhis.help.action;
+
+/*
+ * Copyright (c) 2004-2007, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.io.OutputStream;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.hisp.dhis.options.help.HelpManager;
+import org.hisp.dhis.util.StreamActionSupport;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class GetHelpItemsAction
+    extends StreamActionSupport
+{
+    private HelpManager helpManager;
+    
+    public void setHelpManager( HelpManager helpManager )
+    {
+        this.helpManager = helpManager;
+    }
+
+    @Override
+    protected String execute( HttpServletResponse response, OutputStream out )
+        throws Exception
+    {
+        helpManager.getHelpItems( out );
+        
+        return SUCCESS;
+    }
+
+    @Override
+    protected String getContentType()
+    {
+        return CONTENT_TYPE_HTML;
+    }
+
+    @Override
+    protected String getFilename()
+    {
+        return "help.html";
+    }
+}

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml	2010-02-25 13:53:26 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml	2010-02-25 15:43:36 +0000
@@ -536,6 +536,11 @@
 		<property name="helpManager" ref="org.hisp.dhis.options.help.HelpManager"/>
     </bean>
     
+    <bean id="org.hisp.dhis.help.action.GetHelpItemsAction" class="org.hisp.dhis.help.action.GetHelpItemsAction"
+        scope="prototype">
+        <property name="helpManager" ref="org.hisp.dhis.options.help.HelpManager"/>
+    </bean>
+    
 	<!-- Common actions -->
 
     <bean id="org.hisp.dhis.commons.action.GetDataElementAction"

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml	2010-02-25 13:53:26 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml	2010-02-25 15:43:36 +0000
@@ -232,6 +232,10 @@
 			<result name="success" type="outputStreamResult"></result>
 		</action>
 
+        <action name="getHelpItems" class="org.hisp.dhis.help.action.GetHelpItemsAction">
+            <result name="success" type="outputStreamResult"></result>
+        </action>
+
 	</package>
 
 	<!-- Security -->