Java URI to toRepositoryItemUri(String uriString)

Here you can find the source of toRepositoryItemUri(String uriString)

Description

Converts the given string to a URI.

License

Apache License

Parameter

Parameter Description
uriString the URI string to analyze

Exception

Parameter Description
URISyntaxException thrown if the given string does not conform to the format of a valid OTMrepository URI

Return

URI

Declaration

public static URI toRepositoryItemUri(String uriString) throws URISyntaxException 

Method Source Code

//package com.java2s;
/**/*w  w w.  j  a  v  a2s . com*/
 * Copyright (C) 2014 OpenTravel Alliance (info@opentravel.org)
 *
 * 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;

public class Main {
    /**
     * Converts the given string to a URI. Prior to returning, this method verifies that the
     * conforms to the OTM repository scheme, and that all required URI components are present.
     * 
     * @param uriString
     *            the URI string to analyze
     * @return URI
     * @throws URISyntaxException
     *             thrown if the given string does not conform to the format of a valid OTM
     *             repository URI
     */
    public static URI toRepositoryItemUri(String uriString) throws URISyntaxException {
        URI uri = new URI(uriString);

        if ((uri.getScheme() == null) || !uri.getScheme().equals("otm")) {
            throw new URISyntaxException(uriString, "The OTM repository URI provided is not valid.", 0);
        }
        if (uri.getAuthority() == null) {
            throw new URISyntaxException(uriString,
                    "All OTM repository URI's must specify a repository ID as the authority.", 6);
        }
        if (uri.getPath() == null) {
            throw new URISyntaxException(uriString,
                    "All OTM repository URI's must specify the filename of a managed resource..",
                    (uriString.length() - 1));
        }
        return uri;
    }
}

Related

  1. tokenizeBase(URI uri)
  2. toName(URI uri)
  3. toNdnUri(String channelName)
  4. toPackageTokens(String uri)
  5. toRelativeURI(URI uri)
  6. toString(URI pathUri)
  7. toString(URI uri)
  8. toStringList(List list)
  9. toStringSet(Collection uris)