📄 mapcontext.java
字号:
package mapcenter.weihu;
import java.io.*;
import java.util.*;
import org.jdom.*;
import org.jdom.input.SAXBuilder;
import mapcenter.service.*;
public class MapContext {
private static final Log log = LogFactory.getLog("WebGIS");
private static HashMap sectionMap = new HashMap();
private static String saxDriverClass = "org.apache.xerces.parsers.SAXParser";
private static SAXBuilder builder;
static{
try{
builder = new SAXBuilder(saxDriverClass);
Document doc = builder.build(new File("config.xml"));
Element root = doc.getRootElement();
List sectionList = root.getChildren();
Iterator sectionListIter = sectionList.iterator();
while (sectionListIter.hasNext()) {
//========== 向集合增加一条协议 ============
Element section = (Element)sectionListIter.next();
String sectionName = section.getName();
sectionMap.put(sectionName,new HashMap());
List paramtList = section.getChildren();
Iterator paramtListIter = paramtList.iterator();
for(int i=0; i<paramtList.size(); i++){
//======== 增加一个字段 ============
String paramtName = ((Element)paramtListIter.next()).getName();
String paramtValue = section.getChild(paramtName).getTextTrim();;
((HashMap)sectionMap.get(sectionName)).put(paramtName,paramtValue);
}
}
}catch(Exception e){log.error(e);}
}
public static String getInitParameter(String paramtName){
Object value = ((HashMap)sectionMap.get("init")).get(paramtName);
return (String)value;
}
public static String[] getLayerParameter(){
Object layerStr = ((HashMap)sectionMap.get("implayers")).get("layer");
String[] layerArray = ((String)layerStr).split("[,]",0);
return layerArray;
}
public static void main(String[] args){
String[] layers = MapContext.getLayerParameter();
System.out.println(layers.length);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -