Here you can find the source of convertToURI(String uriString, Map
Parameter | Description |
---|---|
uriString | A string with the initial uri to check for aliases. |
aliasMap | The map of known aliases to the associated URIs |
public static URI convertToURI(String uriString, Map<String, URI> aliasMap)
//package com.java2s; /*//from w ww . ja va 2 s .co m * Copyright 2008 Fedora Commons, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.net.URI; import java.net.URISyntaxException; import java.util.Map; public class Main { /** * Replace an alias in a URI, if one is recognized. * @param uriString A string with the initial uri to check for aliases. * @param aliasMap The map of known aliases to the associated URIs * @return A new URI with the alias replaced, or the original if no alias is found. */ public static URI convertToURI(String uriString, Map<String, URI> aliasMap) { try { URI uri = new URI(uriString); if (uri.isOpaque()) { // Attempt qname-to-URI substitution for aliased namespace prefixes URI mapping = aliasMap.get(uri.getScheme()); if (mapping != null) { uri = new URI(mapping.toString() + uri.getSchemeSpecificPart() + (uri.getFragment() != null ? "#" + uri.getFragment() : "")); } } return uri; } catch (URISyntaxException e) { throw new RuntimeException("Bad URI syntax in resource", e); } } }