001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.vfs2.provider.url;
018
019import org.apache.commons.vfs2.FileType;
020import org.apache.commons.vfs2.provider.URLFileName;
021
022/**
023 * A URL FileName.
024 */
025public class UrlFileName extends URLFileName {
026    /**
027     * The constructor.
028     *
029     * @param scheme The scheme to use.
030     * @param hostName The host name.
031     * @param port The port.
032     * @param defaultPort The default port.
033     * @param userName The user's login id.
034     * @param password The user's credentials.
035     * @param path The file path.
036     * @param type The file type.
037     * @param queryString Parameters to use when locating or creating the file name.
038     */
039    public UrlFileName(final String scheme, final String hostName, final int port, final int defaultPort,
040            final String userName, final String password, final String path, final FileType type,
041            final String queryString) {
042        super(scheme, hostName, port, defaultPort, userName, password, path, type, queryString);
043    }
044
045    @Override
046    protected void appendRootUri(final StringBuilder buffer, final boolean addPassword) {
047        if (getHostName() != null && !"".equals(getHostName())) {
048            super.appendRootUri(buffer, addPassword);
049            return;
050        }
051
052        buffer.append(getScheme());
053        buffer.append(":");
054    }
055}