001    package com.khubla.pragmatach.contrib.controllertester;
002    
003    import java.io.InputStream;
004    import java.io.InputStreamReader;
005    import java.util.ArrayList;
006    import java.util.List;
007    
008    import au.com.bytecode.opencsv.CSVReader;
009    
010    /**
011     * @author tome
012     */
013    public class RouteUrl {
014       /**
015        * read
016        */
017       public static List<RouteUrl> readRoutes(InputStream inputStream) throws Exception {
018          try {
019             final List<RouteUrl> ret = new ArrayList<RouteUrl>();
020             final CSVReader reader = new CSVReader(new InputStreamReader(inputStream));
021             String[] nextLine;
022             while ((nextLine = reader.readNext()) != null) {
023                if (nextLine[0].charAt(0) != '#') {
024                   final String method = nextLine[0];
025                   final String context = nextLine[1];
026                   final List<String> parts = new ArrayList<String>();
027                   for (int i = 2; i < nextLine.length; i++) {
028                      parts.add(nextLine[i]);
029                   }
030                   ret.add(new RouteUrl(parts, method, context));
031                }
032             }
033             reader.close();
034             return ret;
035          } catch (final Exception e) {
036             throw new Exception("Exception in readRoutes", e);
037          }
038       }
039    
040       /**
041        * url parts
042        */
043       private final List<String> parts;
044       /**
045        * method
046        */
047       private final String method;
048       /**
049        * context
050        */
051       private final String context;
052    
053       /**
054        * ctor
055        */
056       public RouteUrl(List<String> parts, String method, String context) {
057          this.parts = parts;
058          this.method = method;
059          this.context = context;
060       }
061    
062       public String getContext() {
063          return context;
064       }
065    
066       public String getMethod() {
067          return method;
068       }
069    
070       public List<String> getParts() {
071          return parts;
072       }
073    }