Coverage report

  %line %branch
be.dvw.administration.mvc.navigation.LeftMenuXSLTImpl
100% 
100% 

 1  
 package be.dvw.administration.mvc.navigation;
 2  
 
 3  
 import be.dvw.administration.util.FileUtils;
 4  
 import be.dvw.administration.util.PropertyManager;
 5  
 import org.apache.commons.logging.Log;
 6  
 import org.apache.commons.logging.LogFactory;
 7  
 import org.dom4j.Document;
 8  
 import org.dom4j.DocumentException;
 9  
 import org.dom4j.io.DocumentResult;
 10  
 import org.dom4j.io.DocumentSource;
 11  
 import org.dom4j.io.SAXReader;
 12  
 
 13  
 import javax.xml.transform.Transformer;
 14  
 import javax.xml.transform.TransformerException;
 15  
 import javax.xml.transform.TransformerFactory;
 16  
 import javax.xml.transform.stream.StreamSource;
 17  
 import java.io.IOException;
 18  
 import java.net.MalformedURLException;
 19  
 
 20  
 /**
 21  
  * Created by IntelliJ IDEA.
 22  
  * User: Toon.Timbermont
 23  
  * Date: Mar 25, 2005
 24  
  * Time: 6:19:27 PM
 25  
  * To change this template use File | Settings | File Templates.
 26  
  */
 27  
 public class LeftMenuXSLTImpl implements LeftMenu {
 28  
 
 29  
     private String currentItem;
 30  
     private Document currentMenu;
 31  
 
 32  24
     private String stylesheet = PropertyManager.getProperty("menu.xsl.path");
 33  24
     private String menuXML = PropertyManager.getProperty("menu.xml.path");
 34  
 
 35  12
     private static Log LOG = LogFactory.getLog(LeftMenuXSLTImpl.class);
 36  
 
 37  
 
 38  
     /**
 39  
      * Constructor based on the currently selected item, defining the currentMenu
 40  
      * @param currentItem
 41  
      * @throws IOException
 42  
      * @throws DocumentException
 43  
      * @throws TransformerException
 44  
      */
 45  24
     public LeftMenuXSLTImpl(String currentItem) throws IOException, DocumentException, TransformerException {
 46  24
         LOG.debug("Building LeftMenuXSLTImpl with currentItem = " + currentItem);
 47  24
         this.currentItem = currentItem;
 48  24
         LOG.debug("Building currentMenu");
 49  24
         currentMenu = getCurrentMenu(getXmlMenu(), currentItem);
 50  24
 		LOG.debug("currentMenu built");
 51  24
     }
 52  
 
 53  
     /**
 54  
      * Method returning the unformatted HTML menu
 55  
      * based on the XSL transformation
 56  
      * @return currrentMenu
 57  
      */
 58  
     public Document getCurrentMenu()
 59  
     {
 60  24
         return currentMenu;
 61  
     }
 62  
 
 63  
     /**
 64  
      * Helper method that reads the XML menu file
 65  
      * @return
 66  
      * @throws java.net.MalformedURLException
 67  
      * @throws org.dom4j.DocumentException
 68  
      */
 69  
     protected Document getXmlMenu() throws MalformedURLException, DocumentException {
 70  24
 		LOG.debug("Loading input XML file for menu from " + menuXML);
 71  24
         SAXReader reader = new SAXReader();
 72  24
         Document document = reader.read( FileUtils.getFile(menuXML) );
 73  24
 		LOG.debug("Menu loaded");
 74  24
         return document;
 75  
     }
 76  
 
 77  
 
 78  
     /**
 79  
      * Helper method that transforms the menu XML to the output HTML
 80  
      * @param document
 81  
      * @param currentItem
 82  
      * @return
 83  
      * @throws TransformerException
 84  
      */
 85  
     protected Document getCurrentMenu(Document document, String currentItem) throws TransformerException {
 86  
 
 87  
 		// load the transformer using JAXP
 88  24
 		LOG.debug("starting transformation");
 89  24
 		TransformerFactory factory = TransformerFactory.newInstance();
 90  24
         LOG.debug("loading stylesheet " + stylesheet);
 91  24
 		Transformer transformer = factory.newTransformer( new StreamSource( FileUtils.getFile(stylesheet) ) );
 92  
 
 93  24
 		LOG.debug("configuring stylesheet with currentItem = " + currentItem);
 94  24
 		transformer.setParameter("selected", currentItem);
 95  
 
 96  
         // now lets style the given document
 97  24
         DocumentSource source = new DocumentSource( document );
 98  24
         DocumentResult result = new DocumentResult();
 99  24
         transformer.transform( source, result );
 100  
 
 101  
         // return the transformed document
 102  24
         Document transformedDoc = result.getDocument();
 103  24
         return transformedDoc;
 104  
     }
 105  
 
 106  
 
 107  
 
 108  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.