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.lang3.StringUtils; 020import org.apache.commons.vfs2.FileType; 021import org.apache.commons.vfs2.provider.URLFileName; 022 023/** 024 * A URL FileName. 025 */ 026public class UrlFileName extends URLFileName { 027 028 /** 029 * The constructor. 030 * 031 * @param scheme The scheme to use. 032 * @param hostName The host name. 033 * @param port The port. 034 * @param defaultPort The default port. 035 * @param userName The user's login id. 036 * @param password The user's credentials. 037 * @param path The file path. 038 * @param type The file type. 039 * @param queryString Parameters to use when locating or creating the file name. 040 */ 041 public UrlFileName(final String scheme, final String hostName, final int port, final int defaultPort, 042 final String userName, final String password, final String path, final FileType type, 043 final String queryString) { 044 super(scheme, hostName, port, defaultPort, userName, password, path, type, queryString); 045 } 046 047 @Override 048 protected void appendRootUri(final StringBuilder buffer, final boolean addPassword) { 049 if (!StringUtils.isEmpty(getHostName())) { 050 super.appendRootUri(buffer, addPassword); 051 return; 052 } 053 054 buffer.append(getScheme()); 055 buffer.append(":"); 056 } 057}