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.FileType;
021
022/**
023 * A file name for layered files.
024 */
025public class LayeredFileName extends AbstractFileName {
026
027    /**
028     * The layer separator character '{@value #LAYER_SEPARATOR}'.
029     *
030     * @since 2.10.0
031     */
032    public static final char LAYER_SEPARATOR = '!';
033
034    static final char SCHEME_SEPARATOR = ':';
035
036    private final FileName outerUri;
037
038    /**
039     * Constructs a new instance.
040     *
041     * @param scheme The scheme.
042     * @param outerUri outer file name.
043     * @param path the absolute path, maybe empty or null.
044     * @param type the file type.
045     */
046    public LayeredFileName(final String scheme, final FileName outerUri, final String path, final FileType type) {
047        super(scheme, path, type);
048        this.outerUri = outerUri;
049    }
050
051    @Override
052    protected void appendRootUri(final StringBuilder buffer, final boolean addPassword) {
053        buffer.append(getScheme());
054        buffer.append(SCHEME_SEPARATOR);
055        buffer.append(getOuterName().getURI());
056        buffer.append(LAYER_SEPARATOR);
057    }
058
059    /**
060     * Creates a FileName.
061     *
062     * @param path The file URI.
063     * @param type The FileType.
064     * @return The FileName.
065     */
066    @Override
067    public FileName createName(final String path, final FileType type) {
068        return new LayeredFileName(getScheme(), getOuterName(), path, type);
069    }
070
071    /**
072     * Returns the URI of the outer file.
073     *
074     * @return The FileName.
075     */
076    public FileName getOuterName() {
077        return outerUri;
078    }
079}