Clover coverage report - JTidy Servlet - r8-SNAPSHOT
Coverage timestamp: Tue Jan 4 2005 09:40:47 PST
file stats: LOC: 176   Methods: 7
NCLOC: 72   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DefaultRepositoryFactory.java 66.7% 90.5% 100% 85%
coverage coverage
 1    /*
 2    * Java HTML Tidy - JTidy
 3    * HTML parser and pretty printer
 4    *
 5    * Copyright (c) 1998-2000 World Wide Web Consortium (Massachusetts
 6    * Institute of Technology, Institut National de Recherche en
 7    * Informatique et en Automatique, Keio University). All Rights
 8    * Reserved.
 9    *
 10    * Contributing Author(s):
 11    *
 12    * Dave Raggett <dsr@w3.org>
 13    * Andy Quick <ac.quick@sympatico.ca> (translation to Java)
 14    * Gary L Peskin <garyp@firstech.com> (Java development)
 15    * Sami Lempinen <sami@lempinen.net> (release management)
 16    * Fabrizio Giustina <fgiust at users.sourceforge.net>
 17    * Vlad Skarzhevskyy <vlads at users.sourceforge.net> (JTidy servlet development)
 18    *
 19    * The contributing author(s) would like to thank all those who
 20    * helped with testing, bug fixes, and patience. This wouldn't
 21    * have been possible without all of you.
 22    *
 23    * COPYRIGHT NOTICE:
 24    *
 25    * This software and documentation is provided "as is," and
 26    * the copyright holders and contributing author(s) make no
 27    * representations or warranties, express or implied, including
 28    * but not limited to, warranties of merchantability or fitness
 29    * for any particular purpose or that the use of the software or
 30    * documentation will not infringe any third party patents,
 31    * copyrights, trademarks or other rights.
 32    *
 33    * The copyright holders and contributing author(s) will not be
 34    * liable for any direct, indirect, special or consequential damages
 35    * arising out of any use of the software or documentation, even if
 36    * advised of the possibility of such damage.
 37    *
 38    * Permission is hereby granted to use, copy, modify, and distribute
 39    * this source code, or portions hereof, documentation and executables,
 40    * for any purpose, without fee, subject to the following restrictions:
 41    *
 42    * 1. The origin of this source code must not be misrepresented.
 43    * 2. Altered versions must be plainly marked as such and must
 44    * not be misrepresented as being the original source.
 45    * 3. This Copyright notice may not be removed or altered from any
 46    * source or altered source distribution.
 47    *
 48    * The copyright holders and contributing author(s) specifically
 49    * permit, without fee, and encourage the use of this source code
 50    * as a component for supporting the Hypertext Markup Language in
 51    * commercial products. If you use this source code in a product,
 52    * acknowledgment is not required but would be appreciated.
 53    *
 54    */
 55    package org.w3c.tidy.servlet.data;
 56   
 57    import javax.servlet.http.HttpServletRequest;
 58    import javax.servlet.http.HttpServletResponse;
 59    import javax.servlet.http.HttpSession;
 60   
 61    import org.w3c.tidy.servlet.Consts;
 62    import org.w3c.tidy.servlet.RepositoryFactory;
 63    import org.w3c.tidy.servlet.ResponseRecord;
 64    import org.w3c.tidy.servlet.ResponseRecordRepository;
 65   
 66   
 67    /**
 68    * Default Factory implementation, Singleton.
 69    * @author Vlad Skarzhevskyy <a href="mailto:skarzhevskyy@gmail.com">skarzhevskyy@gmail.com </a>
 70    * @version $Revision: 1.4 $ ($Author: fgiust $)
 71    */
 72    public class DefaultRepositoryFactory implements RepositoryFactory
 73    {
 74   
 75    /**
 76    * singleton.
 77    */
 78    private static ResponseRecordRepository repositoryInstance;
 79   
 80    /**
 81    * Global Request key sequence.
 82    */
 83    private static long staticRequestID;
 84   
 85  20 private static synchronized ResponseRecordRepository getStaticRepositoryInstance()
 86    {
 87  20 if (repositoryInstance == null)
 88    {
 89  1 repositoryInstance = new DefaultResponseRecordRepository();
 90    }
 91  20 return repositoryInstance;
 92    }
 93   
 94    /**
 95    * {@inheritDoc}
 96    */
 97  20 public ResponseRecordRepository getRepositoryInstance(HttpSession httpSession)
 98    {
 99  20 return getStaticRepositoryInstance();
 100    }
 101   
 102    /**
 103    * Globabl sequence generator
 104    * @return Returns the requst new ID when asked.
 105    */
 106  11 private static synchronized long getNewRequestID()
 107    {
 108  11 staticRequestID++;
 109  11 return staticRequestID;
 110    }
 111   
 112    /**
 113    * Implementation of sequence generator. Could be overdriven in descendant calss
 114    * @return Returns the requst new ID when asked.
 115    */
 116  11 public long generateNewRequestID(HttpSession httpSession)
 117    {
 118  11 return getNewRequestID();
 119    }
 120   
 121    /**
 122    * Disable some pages validation or, save numbers for not important pages. Could be overdriven in descendant calss
 123    * @return Returns boolean
 124    */
 125  42 public boolean allowURI(String uri)
 126    {
 127  42 if (uri.endsWith("empty.html"))
 128    {
 129  0 return false;
 130    }
 131    else
 132    {
 133  42 return true;
 134    }
 135    }
 136   
 137    /**
 138    * {@inheritDoc}
 139    */
 140  42 public Object getResponseID(HttpSession httpSession, HttpServletRequest request, HttpServletResponse response,
 141    boolean newResponse)
 142    {
 143    // Save the numbers
 144  42 if ((request != null) && (!allowURI(request.getRequestURI())))
 145    {
 146  0 return null;
 147    }
 148   
 149  42 Long atribRequestID = null;
 150  42 if ((!newResponse) && (request != null))
 151    {
 152  42 atribRequestID = (Long) request.getAttribute(Consts.ATTRIBUTE_REQUEST_ID);
 153    }
 154   
 155  42 if (atribRequestID == null)
 156    {
 157  17 atribRequestID = new Long(generateNewRequestID(httpSession));
 158  17 if (request != null)
 159    {
 160  17 request.setAttribute(Consts.ATTRIBUTE_REQUEST_ID, atribRequestID);
 161   
 162    }
 163    }
 164  42 return atribRequestID;
 165    }
 166   
 167    /**
 168    * {@inheritDoc}
 169    */
 170  16 public ResponseRecord createRecord(Object key, HttpSession httpSession, HttpServletRequest request,
 171    HttpServletResponse response)
 172    {
 173  16 return new DefaultResponseRecord();
 174    }
 175   
 176    }