View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.context;
21  
22  public class ResourceUtils {
23  
24    public static final char FOLDER_SEPARATOR = '/';
25    public static final char SEPARATOR = '-';
26    public static final char DOT = '.';
27  
28    public static final String GIF = "gif";
29  
30    public static String createString(String folder, String component, String name, String postfix, String extension) {
31      return new StringBuilder()
32          .append(folder)
33          .append(FOLDER_SEPARATOR)
34          .append(component)
35          .append(SEPARATOR)
36          .append(name)
37          .append(SEPARATOR)
38          .append(postfix)
39          .append(DOT)
40          .append(extension)
41          .toString();
42    }
43  
44    public static String createString(String folder, String component, String name, String extension) {
45      return new StringBuilder()
46          .append(folder)
47          .append(FOLDER_SEPARATOR)
48          .append(component)
49          .append(SEPARATOR)
50          .append(name)
51          .append(DOT)
52          .append(extension)
53          .toString();
54    }
55  
56    public static String addPostfixToFilename(String filename, String postfix) {
57      int dotIndex = filename.lastIndexOf('.');
58      String name = filename.substring(0, dotIndex);
59      String extension = filename.substring(dotIndex);
60      return new StringBuilder()
61          .append(name)
62          .append(postfix)
63          .append(extension)
64          .toString();
65    }
66  
67    private ResourceUtils() {
68    }
69  
70  }