📄 template.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package include;import java.io.BufferedReader;import java.io.File;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.IOException;import java.util.ArrayList;import include.MyConfig;/** * * @author James Bond 007 */public class Template { public class Value{ String key = ""; String Value = ""; public Value(String key, String Value){ this.key = key; this.Value = Value; } } public boolean safeHTML = true; public String themePath = ""; public ArrayList<Value> valueList = new ArrayList<Value>(); public String themedata = ""; private boolean isthemeloaded = false; public Template(String themepath){ MyConfig myconfig = new MyConfig(); this.themePath = themepath; valueList.add(new Value("{CONTENTS}", "")); valueList.add(new Value("{HEADER}", "")); valueList.add(new Value("{TITLE}", "")); valueList.add(new Value("{SEARCH_FORM}", "")); valueList.add(new Value("{SCRIPT}", "")); valueList.add(new Value("{SUB_HEADER}", "")); valueList.add(new Value("{RIGHT_MENU}", "")); valueList.add(new Value("{MENU}", "")); valueList.add(new Value("{DESCRIPTION}", "")); valueList.add(new Value("{HEAD}", "")); valueList.add(new Value("{TOP_MENU}", "")); valueList.add(new Value("{SIDE_BAR}", "")); String cpath = themepath.replace("\\", "/"); int pos = cpath.indexOf("themes"); if(pos!=-1) valueList.add(new Value("{THEME_PATH}", cpath.substring(pos))); else valueList.add(new Value("{THEME_PATH}", "themes/default")); } public int getValueListSize(){ return valueList.size(); } public boolean hasValue(String Value){ for(int i = 0; i<this.valueList.size();i++){ if(this.valueList.get(i).Value.equals(Value)) return true; } return false; } public boolean hasKey(String key){ for(int i = 0; i<this.valueList.size();i++){ if(this.valueList.get(i).key.equals(key)) return true; } return false; } public void removeKey(String key){ for(int i = 0;i < this.valueList.size();i++){ if(this.valueList.get(i).key.equals(key)){ this.valueList.remove(i); return; } } } public void replaceValue(String key, String Value){ for(int i = 0;i < this.valueList.size();i++){ if(this.valueList.get(i).key.equals(key)){ Value v = this.valueList.get(i); v.Value = Value; this.valueList.set(i, v); } } } public void addValueFromFile(String key, String file, String value) throws FileNotFoundException, IOException{ File f = new File(this.themePath + "" + File.separator + file); //System.out.println("load: " + this.themePath + "" + File.separator + file); if(!f.exists() || !f.canRead()) return; BufferedReader bf = new BufferedReader(new FileReader(f)); String line = ""; String data = ""; while((line = bf.readLine())!= null){ data += line + "\n"; } bf.close(); data = data.replace(key, value); this.addValue(key, data); } public void addValueFromFile(String key, String file) throws FileNotFoundException, IOException{ addValueFromFile(key, file,""); } public void appendValueFromFile(String key, String file) throws FileNotFoundException, IOException{ appendValueFromFile(key, file,""); } public void appendValueFromFile(String key, String file, String value) throws FileNotFoundException, IOException{ File f = new File(this.themePath + "" + File.separator + file); if(!f.exists() || !f.canRead()) return; BufferedReader bf = new BufferedReader(new FileReader(f)); String line = ""; String data = ""; while((line = bf.readLine())!= null){ data += line + "\n"; } bf.close(); data = data.replace(key, value); this.appendValue(key, value); } public void addValue(String key, String Value){ if(key.equals("{Script}")) Value = "//Begin Javascript\n" + Value; Value v = new Value(key,Value); if(!hasKey(key)){ this.valueList.add(v); }else{ replaceValue(key, Value); } } public void appendValue(String key, String Value){ Value v = new Value(key,Value); if(!hasKey(key)){ this.valueList.add(v); }else{ for(int i = 0;i < this.valueList.size();i++){ if(this.valueList.get(i).key.equals(key)){ v = this.valueList.get(i); v.Value = v.Value + Value; this.valueList.set(i, v); } } } } public String getThemePath(){ return this.themePath; } public void setThemePath(String newtp){ this.themePath = newtp; } public void setSafeHTML(boolean newHTML){ this.safeHTML = newHTML; } public boolean getSafeHTML(){ return this.safeHTML; } public boolean loadTheme(String TName) throws FileNotFoundException, IOException{ File f = new File(this.themePath + "" + File.separator + TName); if(!f.exists() || !f.canRead()) { System.out.println("Themes cannot load '" + this.themePath + "" + File.separator + TName + "'"); return false; } this.isthemeloaded =false; BufferedReader bf = new BufferedReader(new FileReader(f)); String line = ""; this.themedata=""; while((line = bf.readLine())!= null){ this.themedata += line + "\n"; } bf.close(); this.isthemeloaded = true; return true; } public String compileTheme(){ if(this.isthemeloaded){ for(int i = 0; i< this.valueList.size();i++){ Value v = this.valueList.get(i); this.themedata = this.themedata.replace(v.key, v.Value); } return this.themedata; } return "Theme has not been loaded"; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -