1 /* Copyright 2002-2025 CS GROUP
2 * Licensed to CS GROUP (CS) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * CS licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.orekit.data;
18
19 import java.io.File;
20 import java.io.IOException;
21 import java.io.InputStream;
22 import java.net.URISyntaxException;
23 import java.net.URL;
24 import java.net.URLConnection;
25
26 import org.hipparchus.exception.DummyLocalizable;
27 import org.orekit.errors.OrekitException;
28
29
30 /** Provider for data files directly fetched from network.
31 * <p>
32 * This class handles a list of URLs pointing to data files or zip/jar on
33 * the net. Since the net is not a tree structure the list elements
34 * cannot be top elements recursively browsed as in {@link
35 * DirectoryCrawler}, they must be data files or zip/jar archives.
36 * </p>
37 * <p>
38 * The files fetched from network can be locally cached on disk. This prevents
39 * too frequent network access if the URLs are remote ones (for example
40 * original internet URLs).
41 * </p>
42 * <p>
43 * If the URL points to a remote server (typically on the web) on the other side
44 * of a proxy server, you need to configure the networking layer of your
45 * application to use the proxy. For a typical authenticating proxy as used in
46 * many corporate environments, this can be done as follows using for example
47 * the AuthenticatorDialog graphical authenticator class that can be found
48 * in the tests directories:
49 * <pre>
50 * System.setProperty("http.proxyHost", "proxy.your.domain.com");
51 * System.setProperty("http.proxyPort", "8080");
52 * System.setProperty("http.nonProxyHosts", "localhost|*.your.domain.com");
53 * Authenticator.setDefault(new AuthenticatorDialog());
54 * </pre>
55 *
56 * <p>
57 * All {@link FiltersManager#addFilter(DataFilter) registered}
58 * {@link DataFilter filters} are applied.
59 * </p>
60 * <p>
61 * Zip archives entries are supported recursively.
62 * </p>
63 * <p>
64 * This is a simple application of the <code>visitor</code> design pattern for
65 * list browsing.
66 * </p>
67 * @see DataProvidersManager
68 * @author Luc Maisonobe
69 */
70 public class NetworkCrawler extends AbstractListCrawler<URL> {
71
72 /** Connection timeout (milliseconds). */
73 private int timeout;
74
75 /** Build a data classpath crawler.
76 * <p>The default timeout is set to 10 seconds.</p>
77 * @param inputs list of input file URLs
78 */
79 public NetworkCrawler(final URL... inputs) {
80 super(inputs);
81 timeout = 10000;
82 }
83
84 /** Set the timeout for connection.
85 * @param timeout connection timeout in milliseconds
86 */
87 public void setTimeout(final int timeout) {
88 this.timeout = timeout;
89 }
90
91 /** {@inheritDoc} */
92 @Override
93 protected String getCompleteName(final URL input) {
94 try {
95 return input.toURI().toString();
96 } catch (URISyntaxException ue) {
97 throw new OrekitException(ue, new DummyLocalizable(ue.getMessage()));
98 }
99 }
100
101 /** {@inheritDoc} */
102 @Override
103 protected String getBaseName(final URL input) {
104 return new File(input.getPath()).getName();
105 }
106
107 /** {@inheritDoc} */
108 @Override
109 protected ZipJarCrawler getZipJarCrawler(final URL input) {
110 return new ZipJarCrawler(input);
111 }
112
113 /** {@inheritDoc} */
114 @Override
115 protected InputStream getStream(final URL input) throws IOException {
116 final URLConnection connection = input.openConnection();
117 connection.setConnectTimeout(timeout);
118 return connection.getInputStream();
119 }
120
121 }