1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.velocity;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  
20  import java.io.InputStream;
21  
22  import org.apache.velocity.exception.ResourceNotFoundException;
23  
24  /**
25   * <a href="ClassLoaderVelocityResourceListener.java.html"><b><i>View Source</i>
26   * </b></a>
27   *
28   * @author Brian Wing Shun Chan
29   */
30  public class ClassLoaderVelocityResourceListener
31      extends VelocityResourceListener {
32  
33      public InputStream getResourceStream(String source)
34          throws ResourceNotFoundException {
35  
36          InputStream is = null;
37  
38          int pos = source.indexOf(JOURNAL_SEPARATOR);
39  
40          if (pos == -1) {
41              pos = source.indexOf(SERVLET_SEPARATOR);
42          }
43  
44          if (pos == -1) {
45              pos = source.indexOf(THEME_LOADER_SEPARATOR);
46          }
47  
48          if (pos == -1) {
49              ClassLoader classLoader = getClass().getClassLoader();
50  
51              if (_log.isDebugEnabled()) {
52                  _log.debug("Loading " + source);
53              }
54  
55              is = classLoader.getResourceAsStream(source);
56          }
57  
58          return is;
59      }
60  
61      private static Log _log = LogFactoryUtil.getLog(
62          ClassLoaderVelocityResourceListener.class);
63  
64  }