View Javadoc

1   /*
2    * Copyright 2004-2006 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.tuigwaa.plugin;
17  
18  import java.util.Locale;
19  import java.util.MissingResourceException;
20  import java.util.ResourceBundle;
21  
22  import org.apache.commons.logging.Log;
23  import org.apache.commons.logging.LogFactory;
24  import org.seasar.tuigwaa.cms.core.CmsConstants;
25  import org.seasar.tuigwaa.cms.core.Resource;
26  
27  import com.isenshi.util.CharUtil;
28  
29  public class PluginUtils {
30  
31  	private static final String PATH_PLUGINRESOURCE = "org.seasar.tuigwaa.plugin.plugin";
32  
33  	private static ResourceBundle resource;
34  
35  	private static Log log = LogFactory.getLog(AbstractPlugin.class);
36  
37  	static {
38  		try {
39  			Locale locale = Locale.getDefault();
40  			resource = ResourceBundle.getBundle(PATH_PLUGINRESOURCE, locale);
41  		} catch (MissingResourceException mre) {
42  			log.error("resource not found.");
43  		}
44  	}
45  
46  	public static final String getMessage(String key) {
47  		if (resource == null) {
48  			return null;
49  		}
50  
51  		String msg = null;
52  
53  		try {
54  			msg = resource.getString(key);
55  		} catch (Exception e) {
56  			log.error("error occured during reading " + key);
57  		}
58  		
59  		return msg;
60  	}
61  	
62  	public static final boolean isAttachment(Resource res){
63  		String pagePath = res.getPath();			
64  		pagePath = CharUtil.chartrim(pagePath, '/');
65  		return res.isFolder() && pagePath.endsWith(CmsConstants.ATTACHEMENT_SUFFIX);
66  	}
67  	
68  	
69  	
70  }