Clover coverage report -
Coverage timestamp: Do Okt 21 2004 12:21:23 CEST
file stats: LOC: 117   Methods: 5
NCLOC: 81   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ConfigProtocolHandler.java 0% 0% 0% 0%
coverage
 1    /*
 2    * ConfigProtocolHandler.java
 3    *
 4    * Created on 25. Januar 2004, 18:16
 5    */
 6   
 7    package org.jconfig.server;
 8   
 9    import java.io.File;
 10    import java.io.InputStream;
 11    import java.io.OutputStream;
 12    import java.net.Socket;
 13    /**
 14    *
 15    * @author Administrator
 16    */
 17    public class ConfigProtocolHandler implements ProtocolHandler {
 18   
 19  0 public ConfigProtocolHandler() {
 20    }
 21   
 22  0 public void execute(Socket socket) {
 23  0 try {
 24  0 InputStream input = null;
 25  0 OutputStream output = null;
 26  0 input = socket.getInputStream();
 27  0 output = socket.getOutputStream();
 28   
 29    // create Request object and parse
 30  0 Request request = new Request(input);
 31  0 request.parse(socket);
 32    // create Response object
 33  0 Response response = new Response(output);
 34  0 response.setRequest(request);
 35  0 response.sendStaticResource();
 36   
 37    // Close the socket
 38  0 socket.close();
 39    }
 40    catch (Exception e) {
 41  0 e.printStackTrace();
 42    }
 43    }
 44   
 45    /**
 46    * This method will try to find a configuration based on the name
 47    * and on the ip-address of the client. The strategy is that it
 48    * will first try to find {ip_adr}_{configname}.xml. If the file
 49    * is not found then it will delete the last part of the ip-address
 50    * and try again. If no file is found the it will at last search
 51    * for the {configname}.xml. If no success then return an empty
 52    * configuration.
 53    */
 54  0 private String getFileName(Request request,ServerContext serverContext) {
 55  0 String uri = request.getUri();
 56  0 String ip_adr = request.getHostAddress();
 57  0 if ( uri.startsWith("/") ) {
 58  0 uri = uri.substring(1);
 59    }
 60  0 uri += ".xml";
 61  0 String tmp = serverContext.getDocumentRoot()+ip_adr+"_"+uri;
 62  0 if ( checkFile(tmp)) {
 63  0 return tmp;
 64    }
 65  0 ip_adr = ip_adr.substring(0,ip_adr.lastIndexOf("."));
 66  0 tmp = serverContext.getDocumentRoot()+ip_adr+"_"+uri;
 67  0 if ( checkFile(tmp)) {
 68  0 return tmp;
 69    }
 70  0 ip_adr = ip_adr.substring(0,ip_adr.lastIndexOf("."));
 71  0 tmp = serverContext.getDocumentRoot()+ip_adr+"_"+uri;
 72  0 if ( checkFile(tmp)) {
 73  0 return tmp;
 74    }
 75  0 ip_adr = ip_adr.substring(0,ip_adr.lastIndexOf("."));
 76  0 tmp = serverContext.getDocumentRoot()+ip_adr+"_"+uri;
 77  0 if ( checkFile(tmp)) {
 78  0 return tmp;
 79    }
 80  0 tmp = serverContext.getDocumentRoot()+uri;
 81  0 if ( checkFile(tmp)) {
 82  0 return tmp;
 83    }
 84  0 uri = serverContext.getDocumentRoot()+uri;
 85  0 return uri;
 86    }
 87   
 88  0 private boolean checkFile(String name) {
 89  0 File file = new File(name);
 90  0 return file.exists();
 91    }
 92   
 93  0 public void execute(Socket socket, ServerContext serverContext) {
 94  0 try {
 95  0 InputStream input = null;
 96  0 OutputStream output = null;
 97  0 input = socket.getInputStream();
 98  0 output = socket.getOutputStream();
 99   
 100    // create Request object and parse
 101  0 Request request = new Request(input);
 102  0 request.parse(socket);
 103    // create Response object
 104  0 Response response = new Response(output);
 105  0 response.setRequest(request);
 106  0 String filename = getFileName(request,serverContext);
 107  0 response.sendStaticResource(filename);
 108   
 109    // Close the socket
 110  0 socket.close();
 111    }
 112    catch (Exception e) {
 113  0 e.printStackTrace();
 114    }
 115    }
 116   
 117    }