|
19 | 19 | import java.net.URI;
|
20 | 20 | import java.util.ArrayDeque;
|
21 | 21 | import java.util.Arrays;
|
| 22 | +import java.util.Collections; |
22 | 23 | import java.util.HashMap;
|
23 | 24 | import java.util.List;
|
24 | 25 | import java.util.Locale;
|
@@ -172,28 +173,29 @@ public List<String> getSubmodelNames() {
|
172 | 173 | .collect( Collectors.toList() );
|
173 | 174 | }
|
174 | 175 |
|
175 |
| - protected String escapeUrnNamespacePart( final String namespacePart ) { |
176 |
| - if ( namespacePart.matches( AspectModelUrn.NAMESPACE_REGEX_PART ) ) { |
177 |
| - return namespacePart; |
| 176 | + private String iriToReversedHostNameNotation( final IRI iri ) { |
| 177 | + final URI uri; |
| 178 | + try { |
| 179 | + uri = URI.create( iri.toString().contains( "://" ) ? iri.toString() : "https://" + iri ); |
| 180 | + } catch ( IllegalArgumentException e ) { |
| 181 | + throw new IllegalArgumentException( "Incorrect IRI: " + iri, e ); |
178 | 182 | }
|
179 |
| - throw new AspectModelGenerationException( "Encountered URI with invalid namespace part: " + namespacePart ); |
180 |
| - } |
181 | 183 |
|
182 |
| - private <T> Collector<T, ArrayDeque<T>, ArrayDeque<T>> reverseOrder() { |
183 |
| - return Collector.of( ArrayDeque::new, ArrayDeque::addFirst, ( deque1, deque2 ) -> { |
184 |
| - deque2.addAll( deque1 ); |
185 |
| - return deque2; |
186 |
| - } ); |
187 |
| - } |
| 184 | + if ( uri.getHost() == null ) { |
| 185 | + throw new IllegalArgumentException( "URI doesn't contain host: " + uri ); |
| 186 | + } |
188 | 187 |
|
189 |
| - private String iriToReversedHostNameNotation( final IRI iri ) { |
190 |
| - final URI uri = URI.create( iri.toString().contains( "://" ) ? iri.toString() : "https://" + iri ); |
191 |
| - return Stream.concat( |
192 |
| - Arrays.stream( uri.getHost().split( "\\." ) ).collect( reverseOrder() ).stream(), |
193 |
| - Arrays.stream( uri.getPath().split( "/" ) ) ) |
| 188 | + final String[] hostParts = uri.getHost().split( "\\." ); |
| 189 | + final List<String> hostPartsList = Arrays.asList( hostParts ); |
| 190 | + Collections.reverse( hostPartsList ); |
| 191 | + final String reversedHost = String.join( ".", hostPartsList ); |
| 192 | + |
| 193 | + final String[] pathParts = uri.getPath().split( "/" ); |
| 194 | + final String path = Arrays.stream( pathParts ) |
194 | 195 | .filter( StringUtils::isNotBlank )
|
195 |
| - .map( this::escapeUrnNamespacePart ) |
196 | 196 | .collect( Collectors.joining( "." ) );
|
| 197 | + |
| 198 | + return reversedHost + ( path.isEmpty() ? "" : "." + path ); |
197 | 199 | }
|
198 | 200 |
|
199 | 201 | private Optional<IRI> iri( final String lexicalRepresentation ) {
|
|
0 commit comments