Java URI Parse parseURIs(String uri)

Here you can find the source of parseURIs(String uri)

Description

parse UR Is

License

Open Source License

Declaration

private static ArrayList<String> parseURIs(String uri) 

Method Source Code


//package com.java2s;
/*/*ww  w.  jav  a 2 s.c o m*/
 * Be Careful this version is not the original version.
 * I modified some sources.          Philippe Le Hegaret
 *
 * @(#)Util.java                    0.2-2 23/03/1997
 *
 *  This file is part of the HTTPClient package
 *  Copyright (C) 1996,1997  Ronald Tschalaer
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public
 *  License along with this library; if not, write to the Free
 *  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 *  MA 02111-1307, USA
 *
 *  For questions, suggestions, bug-reports, enhancement-requests etc.
 *  I may be contacted at:
 *
 *  ronald@innovation.ch
 *  Ronald.Tschalaer@psi.ch
 *
 */

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    private static Pattern uri_param = Pattern.compile("[&?][^&?=]+=([^&?]+)");

    private static ArrayList<String> parseURIs(String uri) {
        ArrayList<String> uris = new ArrayList<String>();
        int pos = 0;
        uris.add(uri);
        // we avoid recursion by putting stuff on our plate at the right place for processing
        while (pos < uris.size()) {
            String u = uris.get(pos++);
            Matcher m = uri_param.matcher(u);
            while (m.find()) {
                try {
                    String compound = URLDecoder.decode(m.group(1), "UTF-8");
                    if (compound.contains("://")) {
                        uris.add(compound);
                    }
                } catch (UnsupportedEncodingException e) {
                    // it is supported
                }
            }
        }
        return uris;
    }
}

Related

  1. parseUri(String s)
  2. parseURI(String target)
  3. parseURI(String uriStr)
  4. parseUriParameters(URI uri)
  5. parseUriQueryParams(URI uri)