1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package Torello.HTML.Tools.Images;

import Torello.HTML.Links;

import Torello.Java.Additional.Ret2;

import Torello.Java.StrCmpr;
import Torello.Java.StrPrint;

import java.net.MalformedURLException;
import java.net.URL;

import java.util.Vector;

class FromStringIterator 
{
    static Request build(final Iterable<String> source)
    {
        final Vector<URL> temp = new Vector<>();
        int count = 0;

        for (final String urlStr : source)
        {
            count++;

            if (urlStr == null) throw new NullPointerException(
                "The " + count + StrPrint.ordinalIndicator(count) + "th element of " +
                "Iterable-Parameter 'source' is null"
            );

            if (StrCmpr.startsWithNAND(urlStr, "http://", "https://"))

                throw new IllegalArgumentException(
                    "The " + count + StrPrint.ordinalIndicator(count) + "th element of " +
                    "Iterable-Parameter 'source' did neither begin with 'http://' nor " +
                    "'https://'.  If there are any partial URL's in you Iterable, you must " +
                    "re-build using an 'originalPageURL' parameter in order to resolve any and " +
                    "all partial URL's."
                );

            try
                { temp.add(new URL(urlStr)); }

            catch (MalformedURLException e)
            {
                throw new IllegalArgumentException(
                    "When attempting to build the " + count + StrPrint.ordinalIndicator(count) +
                    " element of Iterable-Parameter 'source', a MalformedURLException threw.  " +
                    "Please see e.getCause() for details.",
                    e
                );
            }
        }

        return new Request(temp, count, null);
    }

    static Request build(
            final Iterable<String>  source,
            final URL               originalPageURL,
            final boolean           skipDontThrowIfBadStr
        )
    {
        if (originalPageURL == null)
            throw new NullPointerException("'originalPageURL' is null.");

        final Vector<URL>       temp            = new Vector<>();
        final Vector<Exception> strExceptions   = new Vector<>();
        final Vector<String[]>  b64Dummy        = new Vector<>();

        int count = 0;

        for (final String urlStr : source)
        {
            count++;

            // This isn't used here, but the (private) Request-Constructor needs an empty Vector if
            // there aren't any b64-Images.

            b64Dummy.add(null);

            if (urlStr == null) throw new NullPointerException(
                "The " + count + StrPrint.ordinalIndicator(count) + " element of " +
                "Iterable-Parameter 'source' is null"
            );

            final Ret2<URL, MalformedURLException> r2 =
                Links.resolve_KE(urlStr, originalPageURL);

            if (r2.b == null) temp.add(r2.a);
            
            else
            {
                if (skipDontThrowIfBadStr)
                {
                    temp.add(null);
                    strExceptions.add(r2.b);
                }

                else throw new IllegalArgumentException(
                    "When attempting to resolve the " + count +
                    StrPrint.ordinalIndicator(count) + " TagNode of Iterable-Parameter " +
                    "'source' an Exception was thrown.  See 'getCause' for details.",
                    r2.b
                );
            }

        }

        return new Request(temp, count, originalPageURL, b64Dummy, strExceptions);
    }

}