⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 weblanguages.java

📁 一个免费的CA,基于EJB平台的,老师叫我们测试,现把之共享出来让大家参考
💻 JAVA
字号:
/************************************************************************* *                                                                       * *  EJBCA: The OpenSource Certificate Authority                          * *                                                                       * *  This software is free software; you can redistribute it and/or       * *  modify it under the terms of the GNU Lesser General Public           * *  License as published by the Free Software Foundation; either         * *  version 2.1 of the License, or any later version.                    * *                                                                       * *  See terms of license at gnu.org.                                     * *                                                                       * *************************************************************************/ package org.ejbca.ui.web.admin.configuration;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import javax.servlet.ServletContext;import org.ejbca.core.model.InternalResources;import org.ejbca.core.model.ra.raadmin.GlobalConfiguration;/** * An class interpreting the langage properties files. I contains one method getText that returns * the presented text in the users prefered language. * * @author  Philip Vendil * @version $Id: WebLanguages.java,v 1.4.2.1 2007/01/24 08:47:41 anatom Exp $ */public class WebLanguages implements java.io.Serializable {	    /** Internal localization of logs and errors */    private static final InternalResources intres = InternalResources.getInstance();    /** Construtor used to load static content. An instance must be declared with this constructor before     *  any WebLanguage object can be used. */    /** Special constructor used by Ejbca web bean */    private void init(ServletContext servletContext, GlobalConfiguration globalconfiguration) throws IOException {        if(languages == null){            // Get available languages.            availablelanguages=null;                        String availablelanguagesstring = globalconfiguration.getAvailableLanguagesAsString();            availablelanguages =  availablelanguagesstring.split(",");            for(int i=0; i < availablelanguages.length;i++){                availablelanguages[i] =  availablelanguages[i].trim().toUpperCase();            }            // Load availabe languages            languages = new LanguageProperties[availablelanguages.length];            for(int i = 0; i < availablelanguages.length; i++){                languages[i] = new LanguageProperties();                String propsfile = "/" + globalconfiguration.getLanguagePath() + "/"                + globalconfiguration.getLanguageFilename() + "."                + availablelanguages[i].toLowerCase() +".properties";                                InputStream is = null;                if (servletContext != null) {                	is = servletContext.getResourceAsStream(propsfile);                } else {                    is = this.getClass().getResourceAsStream(propsfile);                	                }                if(is==null) {                    //if not available as stream, try it as a file                    is = new FileInputStream("/tmp"+propsfile);                }                languages[i].load(is);            }        }    }    public WebLanguages(ServletContext servletContext, GlobalConfiguration globalconfiguration, int preferedlang, int secondarylang) throws IOException {        init(servletContext, globalconfiguration);        this.userspreferedlanguage=preferedlang;        this.userssecondarylanguage=secondarylang;    }    /** The main method that looks up the template text in the users prefered language. */    public  String getText(String template){      String returnvalue = null;      try{        returnvalue= languages[userspreferedlanguage].getProperty(template);        if(returnvalue == null){          returnvalue= languages[userssecondarylanguage].getProperty(template);        }        if(returnvalue == null){            returnvalue= intres.getLocalizedMessage(template);        }              }catch(java.lang.NullPointerException e){}      if(returnvalue == null)        returnvalue= "No text available";      return returnvalue;    }    /* Returns a textstring containing the available languages */    public String[] getAvailableLanguages(){      return availablelanguages;    }    // Protected fields    private int userspreferedlanguage;    private int userssecondarylanguage;    private String[] availablelanguages;    private LanguageProperties[] languages = null;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -