config.java
来自「cwbbs 云网论坛源码」· Java 代码 · 共 125 行
JAVA
125 行
package cn.js.fan.sso;import org.jdom.*;import org.jdom.output.*;import org.jdom.input.*;import java.io.*;import java.util.Iterator;import java.net.URL;import java.sql.ResultSet;import javax.servlet.ServletContext;import cn.js.fan.util.*;import java.net.URLDecoder;public class Config { boolean debug = true; final String configxml = "ssoconfig.xml"; String xmlpath = ""; Document doc = null; Element root = null; String deskey = "bluewind"; public Config() { URL confURL = getClass().getClassLoader().getResource(configxml); xmlpath = confURL.getFile(); xmlpath = URLDecoder.decode(xmlpath); SAXBuilder sb = new SAXBuilder(); try { FileInputStream fin = new FileInputStream(xmlpath); doc = sb.build(fin); root = doc.getRootElement(); fin.close(); } catch (org.jdom.JDOMException e) {} catch (java.io.IOException e) { } } public Element getRootElement() { return root; } public String getLoginURL(String kind) { Element webapp = root.getChild("webapp"); java.util.List webapplist = webapp.getChildren(); Iterator ir = webapplist.iterator(); String attr = ""; while (ir.hasNext()) { Element a = (Element) ir.next(); attr = a.getAttribute("kind").getValue(); if (attr != null && attr.equals(kind)) { Element loginurl = a.getChild("loginurl"); if (loginurl != null) return loginurl.getText(); break; } } return null; } public String getDefaultURL(String kind) { Element webapp = root.getChild("webapp"); java.util.List webapplist = webapp.getChildren(); Iterator ir = webapplist.iterator(); String attr = ""; while (ir.hasNext()) { Element a = (Element) ir.next(); attr = a.getAttribute("kind").getValue(); if (attr != null && attr.equals(kind)) { Element loginurl = a.getChild("defaulturl"); if (loginurl != null) return loginurl.getText(); break; } } return null; } public String getKey() { Element which = root.getChild("key"); if (which == null) return null; String s = StrUtil.getNullStr(which.getText()); return s; } public String getDoorUrl() { Element which = root.getChild("doorurl"); if (which == null) return null; String url = StrUtil.getNullStr(which.getText()); return url; } public boolean setKey(String pwd) { Element which = root.getChild("site").getChild("key"); if (which == null) return false; which.setText(pwd); writemodify(); return true; } public void writemodify() { String indent = " "; boolean newLines = true; Format format = Format.getPrettyFormat(); format.setIndent(indent); format.setEncoding("gb2312"); XMLOutputter outp = new XMLOutputter(format); try { FileOutputStream fout = new FileOutputStream(xmlpath); outp.output(doc, fout); fout.close(); } catch (java.io.IOException e) {} }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?