001 package com.khubla.pragmatach.contrib.clientproxygenerator;
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 String nl = nextLine[i];
029 if ((null != nl) && (nl.length() > 0)) {
030 parts.add(nl);
031 }
032 }
033 ret.add(new RouteUrl(parts, method, context));
034 }
035 }
036 reader.close();
037 return ret;
038 } catch (final Exception e) {
039 throw new Exception("Exception in readRoutes", e);
040 }
041 }
042
043 /**
044 * url parts
045 */
046 private final List<String> parts;
047 /**
048 * method
049 */
050 private final String method;
051 /**
052 * context
053 */
054 private final String context;
055
056 /**
057 * ctor
058 */
059 public RouteUrl(List<String> parts, String method, String context) {
060 this.parts = parts;
061 this.method = method;
062 this.context = context;
063 }
064
065 public String getContext() {
066 return context;
067 }
068
069 public String getMethod() {
070 return method;
071 }
072
073 public List<String> getParts() {
074 return parts;
075 }
076 }