日期:2014-05-19 浏览次数:20689 次
public static void langEditorInit(HttpServletRequest request, HttpServletResponse response) throws Exception { StringBuilder tabs = new StringBuilder(); StringBuilder tree = new StringBuilder(); ConcurrentHashMap lans = Str.getLangMap(); List ls = StringUtil.sortMapKey(lans); boolean isFirst = true; for (Map.Entry e : ls) { String key = (String)e.getKey(); ConcurrentHashMap v = (ConcurrentHashMap)lans.get(key); if (v.size() != 0) { if (isFirst) { isFirst = false; } else { tabs.append(','); tree.append(','); } tabs.append("{title:"); tabs.append(StringUtil.quote(key)); tabs .append( StringUtil.concat( ",id:\"tab_", new String[] { key, "\",layout:\"fit\",items:[{xtype:\"textarea\",id:\"area_", key, "\"}]" })); tabs.append('}'); tree.append("{text:"); tree.append(StringUtil.quote(key)); tree.append(",iconCls:\"item_icon\",leaf:true"); tree.append('}'); } } request.setAttribute("langTabs", tabs.toString()); request.setAttribute("treeContent", tree.toString()); } public static List<Entry<String, ?>> sortMapKey(Map<String, ?> map) { return sortMapKey(map, false); } public static List<Entry<String, ?>> sortMapKey(Map<String, ?> map, boolean keyAsNumber) { List<Entry<String, ?>> list = new ArrayList<Entry<String, ?>>(map .entrySet()); final boolean keyAsNum = keyAsNumber; Collections.sort(list, new Comparator<Entry<String, ?>>() { Collator collator = Collator.getInstance(); public int compare(Entry<String, ?> e1, Entry<String, ?> e2) { if (keyAsNum) return Integer.parseInt(e1.getKey()) - Integer.parseInt(e2.getKey()); else { CollationKey key1 = collator.getCollationKey(e1.getKey() .toLowerCase()); CollationKey key2 = collator.getCollationKey(e2.getKey() .toLowerCase()); return key1.compareTo(key2); } } }); return list; }