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  import org.apache.myfaces.tobago.config.Configurable;
23  import org.apache.myfaces.tobago.layout.Measure;
24  
25  import javax.faces.context.FacesContext;
26  import java.util.ArrayList;
27  import java.util.List;
28  
29  /**
30   * @deprecated please use {@link ResourceManagerUtils}
31   */
32  @Deprecated
33  public class ResourceManagerUtil {
34  
35    private ResourceManagerUtil() {
36      // no instance
37    }
38  
39    /**
40     * @deprecated please use {@link ResourceManagerUtils}
41     */
42    @Deprecated
43    public static String getProperty(final FacesContext facesContext, final String bundle, final String key) {
44      return ResourceManagerFactory.getResourceManager(facesContext).getProperty(facesContext, bundle, key);
45    }
46  
47    /**
48     * @deprecated please use {@link ResourceManagerUtils}
49     */
50    @Deprecated
51    public static String getPropertyNotNull(final FacesContext facesContext, final String bundle, final String key) {
52      final String result
53          = ResourceManagerFactory.getResourceManager(facesContext).getProperty(facesContext, bundle, key);
54      if (result == null) {
55        return "???" + key + "???";
56      } else {
57        return result;
58      }
59    }
60  
61    /**
62     * Searches for an image and return it with the context path
63     * @deprecated please use {@link ResourceManagerUtils}
64     */
65    public static String getImageWithPath(final FacesContext facesContext, final String name) {
66      return facesContext.getExternalContext().getRequestContextPath()
67          + ResourceManagerFactory.getResourceManager(facesContext).getImage(facesContext, name);
68    }
69  
70    /**
71     * Searches for an image and return it with the context path
72     * @deprecated please use {@link ResourceManagerUtils}
73     */
74    public static String getImageWithPath(
75        final FacesContext facesContext, final String name, final boolean ignoreMissing) {
76      final String image
77          = ResourceManagerFactory.getResourceManager(facesContext).getImage(facesContext, name, ignoreMissing);
78      if (image == null) {
79        return null;
80      } else {
81        return facesContext.getExternalContext().getRequestContextPath() + image;
82      }
83    }
84  
85    /**
86     * @deprecated please use {@link ResourceManagerUtils}
87     */
88    @Deprecated
89    public static List<String> getStyles(final FacesContext facesContext, final String name) {
90      final String contextPath = facesContext.getExternalContext().getRequestContextPath();
91      final String[] styles = ResourceManagerFactory.getResourceManager(facesContext).getStyles(facesContext, name);
92      return addContextPath(styles, contextPath);
93    }
94  
95    /**
96     * @deprecated please use {@link ResourceManagerUtils}
97     */
98    @Deprecated
99    private static List<String> addContextPath(final String[] strings, final String contextPath) {
100     final List<String> withContext = new ArrayList<String>(strings.length);
101     for (final String string : strings) {
102       withContext.add(contextPath + string);
103     }
104     return withContext;
105   }
106 
107   /**
108    * @deprecated please use {@link ResourceManagerUtils}
109    */
110   @Deprecated
111   public static List<String> getScripts(final FacesContext facesContext, final String name) {
112     final String contextPath = facesContext.getExternalContext().getRequestContextPath();
113     final String[] scripts = ResourceManagerFactory.getResourceManager(facesContext).getScripts(facesContext, name);
114     return addContextPath(scripts, contextPath);
115   }
116 
117   /**
118    * @deprecated please use {@link ResourceManagerUtils}
119    */
120   @Deprecated
121   public static String getScriptsAsJSArray(final FacesContext facesContext, final String[] names) {
122     final List<String> fileNames = new ArrayList<String>();
123     for (final String name : names) {
124       fileNames.addAll(getScripts(facesContext, name));
125     }
126     return toJSArray(fileNames);
127   }
128 
129   /**
130    * @deprecated please use {@link ResourceManagerUtils}
131    */
132   @Deprecated
133   public static String getStylesAsJSArray(final FacesContext facesContext, final String[] names) {
134     final List<String> fileNames = new ArrayList<String>();
135     for (final String name : names) {
136       fileNames.addAll(getStyles(facesContext, name));
137     }
138     return toJSArray(fileNames);
139   }
140 
141   /**
142    * @deprecated please use {@link ResourceManagerUtils}
143    */
144   @Deprecated
145   public static String toJSArray(final List<String> list) {
146     final StringBuilder sb = new StringBuilder();
147     for (final String name : list) {
148       if (sb.length() > 0) {
149         sb.append(", ");
150       }
151       sb.append('\'');
152       sb.append(name);
153       sb.append('\'');
154     }
155     return "[" + sb.toString() + "]";
156   }
157 
158   /**
159    * @deprecated please use {@link ResourceManagerUtils}
160    */
161   @Deprecated
162   public static String getDisabledImageWithPath(final FacesContext facesContext, final String image) {
163     final String filename = ResourceUtils.addPostfixToFilename(image, "Disabled");
164     return getImageWithPath(facesContext, filename, true);
165   }
166 
167   /**
168    * @deprecated please use {@link ResourceManagerUtils}
169    */
170   @Deprecated
171   public static String getBlankPage(final FacesContext facesContext) {
172     return ResourceManagerUtils.getBlankPage(facesContext);
173   }
174 
175   /**
176    * @deprecated please use {@link ResourceManagerUtils}
177    */
178   @Deprecated
179   public static String getPageWithoutContextPath(final FacesContext facesContext, final String name) {
180     return ResourceManagerFactory.getResourceManager(facesContext).getImage(facesContext, name);
181   }
182 
183   /**
184    * @deprecated please use {@link ResourceManagerUtils}
185    */
186   @Deprecated
187   public static Measure getThemeMeasure(
188       final FacesContext facesContext, final Configurable configurable, final String name) {
189     return ResourceManagerUtils.getThemeMeasure(facesContext, configurable, name);
190   }
191 
192   /**
193    * @deprecated please use {@link ResourceManagerUtils}
194    */
195   @Deprecated
196   public static boolean isAbsoluteResource(final String value) {
197     return ResourceManagerUtils.isAbsoluteResource(value);
198   }
199   
200 }