Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.73 KB | None | 0 0
  1.    @Override
  2.    public List<String> proces(String content)
  3.    {
  4.       List<String> versions = new ArrayList<String>();
  5.       try
  6.       {
  7.          Pattern pattern = Pattern.compile("<a\\b[^>]*href=\"[^>]*>(.*?)/</a>");
  8.          Matcher matcher = pattern.matcher(content);
  9.          int mIdx = 0;
  10.          while (matcher.find())
  11.          {
  12.             mIdx++;
  13.             if(mIdx == 1)
  14.             {
  15.                continue;
  16.             }
  17.             String rawVersion = matcher.group(1);
  18.             if(include(rawVersion))
  19.             {
  20.                versions.add(rawVersion);              
  21.             }
  22.          }
  23.       }
  24.       catch (Exception e)
  25.       {
  26.          throw new RuntimeException("Could not extract version numbers", e);
  27.       }
  28.  
  29.       return versions;
  30.    }
  31.  
  32.    private boolean include(String rawVersion)
  33.    {
  34.       return !rawVersion.matches(".*(SP1|SP2|SP3|OSGi).*");
  35.    }
  36.  
  37.       HttpGet get = new HttpGet(url.toExternalForm());
  38.       try
  39.       {
  40.          return client.execute(get, new ResponseHandler<T>()
  41.          {
  42.             @Override
  43.             public T handleResponse(HttpResponse response) throws ClientProtocolException, IOException
  44.             {
  45.                 StringBuilder content = new StringBuilder();
  46.                 BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
  47.                 String line;
  48.                 while( (line = in.readLine()) != null)
  49.                 {
  50.                     content.append(line);
  51.                 }
  52.                 in.close();
  53.                 return handler.proces(content.toString());
  54.             }
  55.          });
  56.       }
  57.       catch (Exception e)
  58.       {
  59.          throw new RuntimeException(e);
  60.       }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement