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