001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements.  See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership.  The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the
007     * "License"); you may not use this file except in compliance
008     * with the License.  You may obtain a copy of the License at
009     *
010     *   http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing,
013     * software distributed under the License is distributed on an
014     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     * KIND, either express or implied.  See the License for the
016     * specific language governing permissions and limitations
017     * under the License.
018     */
019    
020    package org.apache.myfaces.tobago.context;
021    
022    public class ResourceUtils {
023    
024      public static final char FOLDER_SEPARATOR = '/';
025      public static final char SEPARATOR = '-';
026      public static final char DOT = '.';
027    
028      public static final String GIF = "gif";
029    
030      public static String createString(String folder, String component, String name, String postfix, String extension) {
031        return new StringBuilder()
032            .append(folder)
033            .append(FOLDER_SEPARATOR)
034            .append(component)
035            .append(SEPARATOR)
036            .append(name)
037            .append(SEPARATOR)
038            .append(postfix)
039            .append(DOT)
040            .append(extension)
041            .toString();
042      }
043    
044      public static String createString(String folder, String component, String name, String extension) {
045        return new StringBuilder()
046            .append(folder)
047            .append(FOLDER_SEPARATOR)
048            .append(component)
049            .append(SEPARATOR)
050            .append(name)
051            .append(DOT)
052            .append(extension)
053            .toString();
054      }
055    
056      public static String addPostfixToFilename(String filename, String postfix) {
057        int dotIndex = filename.lastIndexOf('.');
058        String name = filename.substring(0, dotIndex);
059        String extension = filename.substring(dotIndex);
060        return new StringBuilder()
061            .append(name)
062            .append(postfix)
063            .append(extension)
064            .toString();
065      }
066    
067      private ResourceUtils() {
068      }
069    
070    }