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

📄 weblanguages.java

📁 JAVA做的J2EE下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 se.anatom.ejbca.webdist.webconfiguration;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import se.anatom.ejbca.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.16 2005/05/13 09:29:53 anatom Exp $ */public class WebLanguages implements java.io.Serializable {    /** 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(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 = 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(GlobalConfiguration globalconfiguration, int preferedlang, int secondarylang) throws IOException {        init(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);      }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 + -