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;
018
019import org.apache.commons.vfs2.FileName;
020import org.apache.commons.vfs2.FileSystemException;
021import org.apache.commons.vfs2.FileType;
022
023/**
024 * Implementation for any url based file system.
025 * <p>
026 * Parses the url into user/password/host/port/path/queryString.
027 * </p>
028 * @deprecated Use {@link GenericURLFileNameParser} as it doesn't depend on HTTP Client v3 API directly.
029 */
030@Deprecated
031public class URLFileNameParser extends HostFileNameParser {
032
033    /**
034     * Constructs a new instance.
035     *
036     * @param defaultPort The default port.
037     */
038    public URLFileNameParser(final int defaultPort) {
039        super(defaultPort);
040    }
041
042    @Override
043    public boolean encodeCharacter(final char ch) {
044        return super.encodeCharacter(ch) || ch == '?';
045    }
046
047    @Override
048    public FileName parseUri(final VfsComponentContext context, final FileName base, final String fileName)
049            throws FileSystemException {
050        // FTP URI are generic URI (as per RFC 2396)
051        final StringBuilder name = new StringBuilder();
052
053        // Extract the scheme and authority parts
054        final Authority auth = extractToPath(context, fileName, name);
055
056        // Extract the queryString
057        final String queryString = UriParser.extractQueryString(name);
058
059        // Decode and normalise the file name
060        UriParser.canonicalizePath(name, 0, name.length(), this);
061        UriParser.fixSeparators(name);
062        final FileType fileType = UriParser.normalisePath(name);
063        final String path = name.toString();
064
065        return new URLFileName(auth.getScheme(), auth.getHostName(), auth.getPort(), getDefaultPort(),
066                auth.getUserName(), auth.getPassword(), path, fileType, queryString);
067    }
068}