Example usage for org.apache.commons.lang StringUtils trim

List of usage examples for org.apache.commons.lang StringUtils trim

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils trim.

Prototype

public static String trim(String str) 

Source Link

Document

Removes control characters (char <= 32) from both ends of this String, handling null by returning null.

Usage

From source file:com.huateng.startup.init.MenuInfoUtil.java

/**
 * ???/* ww  w. jav  a  2s .  c  o m*/
 * @param degree
 */
@SuppressWarnings("unchecked")
public static LinkedHashMap<String, Object> setOperatorMenuWithDegree(String degree, String contextPath,
        Document document) {
    String sql = "select * FROM TBL_ROLE_FUNC_MAP WHERE KEY_ID in ( " + degree + ")";
    ICommQueryDAO commQueryDAO = (ICommQueryDAO) ContextUtil.getBean("CommQueryDAO");
    List<Object[]> funcMapList = commQueryDAO.findBySQLQuery(sql);
    valueIdRole(funcMapList);
    List<Object> menuLvl1List = allMenuBean.getDataList();
    LinkedHashMap<String, Object> menuIndexMap = new LinkedHashMap<String, Object>();
    String panelStr = "";
    //?????
    for (int i = 0, n = menuLvl1List.size(); i < n; i++) {
        Map<String, Object> menuLvl1Map = (Map<String, Object>) menuLvl1List.get(i);
        LinkedList<Object> menuLvl2List = (LinkedList<Object>) menuLvl1Map.get(Constants.MENU_CHILDREN);
        List<String> menuList = new ArrayList<String>();
        for (int j = 0, m = menuLvl2List.size(); j < m; j++) {
            Map<String, Object> menuLvl2Map = (Map<String, Object>) menuLvl2List.get(j);
            LinkedList<Object> menuLvl3List = (LinkedList<Object>) menuLvl2Map.get(Constants.MENU_CHILDREN);
            for (int k = 0, l = menuLvl3List.size(); k < l; k++) {
                Map<String, Object> menuLvl3Map = (Map<String, Object>) menuLvl3List.get(k);
                for (int a = 0, b = funcMapList.size(); a < b; a++) {
                    if (StringUtils.trim(funcMapList.get(a)[1].toString())
                            .equals(StringUtils.trim(menuLvl3Map.get(Constants.MENU_ID).toString()))) {
                        if (!menuIndexMap.containsKey(menuLvl1Map.get(Constants.MENU_ID).toString())) {
                            Map<String, Object> menuLvl1HashMap = new LinkedHashMap<String, Object>();
                            String menuId = menuLvl1Map.get(Constants.MENU_ID).toString();
                            menuLvl1HashMap.put(Constants.MENU_ID, menuLvl1Map.get(Constants.MENU_ID));
                            menuLvl1HashMap.put(Constants.MENU_TEXT, menuLvl1Map.get(Constants.MENU_TEXT));
                            menuLvl1HashMap.put(Constants.MENU_CLS, menuLvl1Map.get(Constants.MENU_CLS));
                            menuLvl1HashMap.put(Constants.MENU_HANDLER, Constants.MENU_LVL1_FUNC);
                            menuLvl1HashMap.put(Constants.TOOL_BAR_TYPE, Constants.TOOL_BAR_BUTTON);
                            menuLvl1HashMap.put(Constants.TOOLBAR_ICON, Constants.TOOLBAR_ICON_MENU);
                            menuLvl1HashMap.put(Constants.IS_EXPAND, true);

                            if ("1".equals(menuId) && panelStr.indexOf("baseTree") == -1) {
                                panelStr = panelStr + "baseTree,";
                            }
                            if ("2".equals(menuId) && panelStr.indexOf("mchtTree") == -1) {
                                panelStr = panelStr + "mchtTree,";
                            }
                            if ("3".equals(menuId) && panelStr.indexOf("termTree") == -1) {
                                panelStr = panelStr + "termTree,";
                            }
                            if ("5".equals(menuId) && panelStr.indexOf("queryTree") == -1) {
                                panelStr = panelStr + "queryTree,";
                            }
                            if ("9".equals(menuId) && panelStr.indexOf("onLinePayTree") == -1) {
                                panelStr = panelStr + "onLinePayTree,";
                            }
                            if ("10".equals(menuId) && panelStr.indexOf("taskTree") == -1) {
                                panelStr = panelStr + "taskTree,";
                            }
                            if ("8".equals(menuId) && panelStr.indexOf("clearTree") == -1) {
                                panelStr = panelStr + "clearTree,";
                            }
                            if ("4".equals(menuId) && panelStr.indexOf("riskTree") == -1) {
                                panelStr = panelStr + "riskTree,";
                            }
                            if ("11".equals(menuId) && panelStr.indexOf("provisionsTree") == -1) {
                                panelStr = panelStr + "provisionsTree,";
                            }
                            if ("12".equals(menuId) && panelStr.indexOf("errorTree") == -1) {
                                panelStr = panelStr + "errorTree,";
                            }
                            Map<String, Object> menuLvl2HashMap = new LinkedHashMap<String, Object>();
                            menuLvl2HashMap.put(Constants.MENU_ID, menuLvl2Map.get(Constants.MENU_ID));
                            menuLvl2HashMap.put(Constants.MENU_TEXT, menuLvl2Map.get(Constants.MENU_TEXT));
                            menuLvl2HashMap.put(Constants.MENU_PARENT_ID,
                                    menuLvl2Map.get(Constants.MENU_PARENT_ID));
                            menuLvl2HashMap.put(Constants.MENU_CLS, menuLvl2Map.get(Constants.MENU_CLS));
                            menuLvl2HashMap.put(Constants.TOOLBAR_ICON, Constants.TOOLBAR_ICON_MENUITEM);
                            menuLvl2HashMap.put(Constants.IS_EXPAND, true);

                            Map<String, Object> menuLvl3HashMap = new LinkedHashMap<String, Object>();
                            int index = menuList.lastIndexOf((String) menuLvl3Map.get(Constants.MENU_ID));
                            LinkedList<Object> menuLvl3Child = new LinkedList<Object>();
                            //System.out.println((String)menuLvl3Map.get(Constants.MENU_ID) + ">>>>>>>>>" + index + ">>>>>" + menuList.size());
                            if (-1 == index) {
                                String tbar = MenuUtil.initMenu((String) menuLvl3Map.get(Constants.MENU_ID),
                                        (String) funcMapList.get(a)[5]);
                                menuLvl3HashMap.put(Constants.MENU_ID, menuLvl3Map.get(Constants.MENU_ID));
                                menuLvl3HashMap.put(Constants.MENU_TEXT, menuLvl3Map.get(Constants.MENU_TEXT));
                                menuLvl3HashMap.put(Constants.MENU_PARENT_ID,
                                        menuLvl3Map.get(Constants.MENU_PARENT_ID));
                                menuLvl3HashMap.put(Constants.MENU_LEAF, true);
                                menuLvl3HashMap.put(Constants.MENU_URL, menuLvl3Map.get(Constants.MENU_URL));
                                menuLvl3HashMap.put(Constants.ROLE_FLAG, tbar);
                                menuLvl3HashMap.put(Constants.MENU_CLS, menuLvl3Map.get(Constants.MENU_CLS));
                                menuLvl3HashMap.put(Constants.MENU_HANDLER, Constants.MENU_LVL3_FUNC);
                                menuLvl3HashMap.put(Constants.TOOLBAR_ICON,
                                        menuLvl3Map.get(Constants.TOOLBAR_ICON));
                                menuLvl3HashMap.put(Constants.IS_EXPAND, true);

                                menuList.add((String) menuLvl3Map.get(Constants.MENU_ID));

                                menuLvl3Child.add(menuLvl3HashMap);
                            } else {
                                Map<String, Object> menu = (Map<String, Object>) menuLvl3Child.get(index);
                                menu.put(Constants.ROLE_FLAG,
                                        (String) menu.get(Constants.ROLE_FLAG) + funcMapList.get(a)[5]);
                            }

                            menuLvl2HashMap.put(Constants.MENU_CHILDREN, menuLvl3Child);
                            menuLvl2HashMap.put(Constants.TOOL_BAR_CHILDREN, menuLvl3Child);
                            LinkedList<Object> menuLvl2Child = new LinkedList<Object>();
                            menuLvl2Child.add(menuLvl2HashMap);
                            menuLvl1HashMap.put(Constants.MENU_CHILDREN, menuLvl2Child);
                            menuLvl1HashMap.put(Constants.TOOL_BAR_CHILDREN, menuLvl2Child);

                            menuIndexMap.put(menuLvl1Map.get(Constants.MENU_ID).toString(), menuLvl1HashMap);
                        } else {
                            Map<String, Object> menuLvl1HashMap = (Map<String, Object>) menuIndexMap
                                    .get(menuLvl1Map.get(Constants.MENU_ID).toString());
                            LinkedList<Object> menuLvl2Child = (LinkedList<Object>) menuLvl1HashMap
                                    .get(Constants.MENU_CHILDREN);
                            boolean hasMenu = false;
                            for (int c = 0, d = menuLvl2Child.size(); c < d; c++) {
                                Map<String, Object> menuLvl2HashMap = (Map<String, Object>) menuLvl2Child
                                        .get(c);
                                if (StringUtils.trim(menuLvl2HashMap.get(Constants.MENU_ID).toString()).equals(
                                        StringUtils.trim(menuLvl2Map.get(Constants.MENU_ID).toString()))) {
                                    LinkedList<Object> menuLvl3Child = (LinkedList<Object>) menuLvl2HashMap
                                            .get(Constants.MENU_CHILDREN);
                                    Map<String, Object> menuLvl3HashMap = new LinkedHashMap<String, Object>();
                                    int index = menuList
                                            .lastIndexOf((String) menuLvl3Map.get(Constants.MENU_ID));
                                    if (-1 == index) {
                                        String tbar = MenuUtil.initMenu(
                                                (String) menuLvl3Map.get(Constants.MENU_ID),
                                                (String) funcMapList.get(a)[5]);
                                        menuLvl3HashMap.put(Constants.MENU_ID,
                                                menuLvl3Map.get(Constants.MENU_ID));
                                        menuLvl3HashMap.put(Constants.MENU_TEXT,
                                                menuLvl3Map.get(Constants.MENU_TEXT));
                                        menuLvl3HashMap.put(Constants.MENU_PARENT_ID,
                                                menuLvl3Map.get(Constants.MENU_PARENT_ID));
                                        menuLvl3HashMap.put(Constants.MENU_LEAF, true);
                                        menuLvl3HashMap.put(Constants.MENU_URL,
                                                menuLvl3Map.get(Constants.MENU_URL));
                                        menuLvl3HashMap.put(Constants.ROLE_FLAG, tbar);
                                        menuLvl3HashMap.put(Constants.MENU_CLS,
                                                menuLvl3Map.get(Constants.MENU_CLS));
                                        menuLvl3HashMap.put(Constants.MENU_HANDLER, Constants.MENU_LVL3_FUNC);
                                        menuLvl3HashMap.put(Constants.TOOLBAR_ICON,
                                                menuLvl3Map.get(Constants.TOOLBAR_ICON));
                                        menuLvl3HashMap.put(Constants.IS_EXPAND, true);

                                        menuList.add((String) menuLvl3Map.get(Constants.MENU_ID));
                                        menuLvl3Child.add(menuLvl3HashMap);
                                    }
                                    //                              else{
                                    //                                 Map<String, Object> menu = (Map<String, Object>)menuLvl3Child.get(index);
                                    //                                 menu.put(Constants.ROLE_FLAG,(String)menu.get(Constants.ROLE_FLAG) + funcMapList.get(a)[5]);
                                    //                              }
                                    menuLvl2HashMap.put(Constants.MENU_CHILDREN, menuLvl3Child);
                                    menuLvl2HashMap.put(Constants.TOOL_BAR_CHILDREN, menuLvl3Child);
                                    menuLvl2HashMap.put(Constants.IS_EXPAND, true);
                                    menuLvl2Child.set(c, menuLvl2HashMap);
                                    hasMenu = true;
                                    break;
                                }
                            }
                            if (!hasMenu) {
                                String tbar = MenuUtil.initMenu((String) menuLvl3Map.get(Constants.MENU_ID),
                                        (String) funcMapList.get(a)[5]);
                                Map<String, Object> menuLvl2HashMap = new HashMap<String, Object>();
                                menuLvl2HashMap.put(Constants.MENU_ID, menuLvl2Map.get(Constants.MENU_ID));
                                menuLvl2HashMap.put(Constants.MENU_TEXT, menuLvl2Map.get(Constants.MENU_TEXT));
                                menuLvl2HashMap.put(Constants.MENU_PARENT_ID,
                                        menuLvl2Map.get(Constants.MENU_PARENT_ID));
                                menuLvl2HashMap.put(Constants.MENU_CLS, menuLvl2Map.get(Constants.MENU_CLS));
                                menuLvl2HashMap.put(Constants.TOOLBAR_ICON, Constants.TOOLBAR_ICON_MENUITEM);
                                menuLvl2HashMap.put(Constants.IS_EXPAND, true);
                                LinkedList<Object> menuLvl3Child = new LinkedList<Object>();
                                Map<String, Object> menuLvl3HashMap = new LinkedHashMap<String, Object>();
                                menuLvl3HashMap.put(Constants.MENU_ID, menuLvl3Map.get(Constants.MENU_ID));
                                menuLvl3HashMap.put(Constants.MENU_TEXT, menuLvl3Map.get(Constants.MENU_TEXT));
                                menuLvl3HashMap.put(Constants.MENU_PARENT_ID,
                                        menuLvl3Map.get(Constants.MENU_PARENT_ID));
                                menuLvl3HashMap.put(Constants.MENU_LEAF, true);
                                menuLvl3HashMap.put(Constants.MENU_URL, menuLvl3Map.get(Constants.MENU_URL));
                                menuLvl3HashMap.put(Constants.MENU_CLS, menuLvl3Map.get(Constants.MENU_CLS));
                                menuLvl3HashMap.put(Constants.ROLE_FLAG, tbar);
                                menuLvl3HashMap.put(Constants.MENU_HANDLER, Constants.MENU_LVL3_FUNC);
                                //menuLvl3HashMap.put(Constants.TOOLBAR_ICON, Constants.TOOLBAR_ICON_MENUITEM);
                                menuLvl3HashMap.put(Constants.TOOLBAR_ICON,
                                        menuLvl3Map.get(Constants.TOOLBAR_ICON));
                                menuLvl3HashMap.put(Constants.IS_EXPAND, true);

                                menuLvl3Child.add(menuLvl3HashMap);
                                menuLvl2HashMap.put(Constants.MENU_CHILDREN, menuLvl3Child);
                                menuLvl2HashMap.put(Constants.TOOL_BAR_CHILDREN, menuLvl3Child);
                                menuLvl2Child.add(menuLvl2HashMap);
                            }
                            menuLvl1HashMap.put(Constants.MENU_CHILDREN, menuLvl2Child);
                            menuLvl1HashMap.put(Constants.TOOL_BAR_CHILDREN, menuLvl2Child);
                            menuLvl1HashMap.put(Constants.IS_EXPAND, true);
                            menuIndexMap.put(menuLvl1Map.get(Constants.MENU_ID).toString(), menuLvl1HashMap);
                        }
                    }
                }
            }
        }
    }
    menuIndexMap.remove(Constants.TREE_MENU_PANEL);
    if (panelStr.length() != 0) {
        menuIndexMap.put(Constants.TREE_MENU_PANEL, panelStr.substring(0, panelStr.length() - 1));
    } else {
        menuIndexMap.put(Constants.TREE_MENU_PANEL, "");
    }
    return menuIndexMap;
}

From source file:com.allinfinance.startup.init.MenuInfoUtil.java

/**
 * ???//from   ww w . j av a 2  s .  c  o m
 * @param degree
 */
@SuppressWarnings("unchecked")
public static LinkedHashMap<String, Object> setOperatorMenuWithDegree(String degree, String contextPath) {
    String sql = "select VALUE_ID FROM TBL_ROLE_FUNC_MAP ,TBL_ROLE_INF WHERE ROLE_ID = KEY_ID and KEY_ID = "
            + degree;
    ICommQueryDAO commQueryDAO = (ICommQueryDAO) ContextUtil.getBean("CommQueryDAO");
    List<Object> funcMapList = commQueryDAO.findBySQLQuery(sql);
    List<Object> menuLvl1List = allMenuBean.getDataList();
    LinkedHashMap<String, Object> menuIndexMap = new LinkedHashMap<String, Object>();
    //?????
    for (int i = 0, n = menuLvl1List.size(); i < n; i++) {
        Map<String, Object> menuLvl1Map = (Map<String, Object>) menuLvl1List.get(i);
        LinkedList<Object> menuLvl2List = (LinkedList<Object>) menuLvl1Map.get(Constants.MENU_CHILDREN);
        for (int j = 0, m = menuLvl2List.size(); j < m; j++) {
            Map<String, Object> menuLvl2Map = (Map<String, Object>) menuLvl2List.get(j);
            LinkedList<Object> menuLvl3List = (LinkedList<Object>) menuLvl2Map.get(Constants.MENU_CHILDREN);
            for (int k = 0, l = menuLvl3List.size(); k < l; k++) {
                Map<String, Object> menuLvl3Map = (Map<String, Object>) menuLvl3List.get(k);
                for (int a = 0, b = funcMapList.size(); a < b; a++) {
                    if (StringUtils.trim(funcMapList.get(a).toString())
                            .equals(StringUtils.trim(menuLvl3Map.get(Constants.MENU_ID).toString()))) {
                        if (!menuIndexMap.containsKey(menuLvl1Map.get(Constants.MENU_ID).toString())) {
                            Map<String, Object> menuLvl1HashMap = new LinkedHashMap<String, Object>();
                            menuLvl1HashMap.put(Constants.MENU_ID, menuLvl1Map.get(Constants.MENU_ID));
                            menuLvl1HashMap.put(Constants.MENU_TEXT, menuLvl1Map.get(Constants.MENU_TEXT));
                            menuLvl1HashMap.put(Constants.MENU_CLS, menuLvl1Map.get(Constants.MENU_CLS));
                            menuLvl1HashMap.put(Constants.MENU_HANDLER, Constants.MENU_LVL1_FUNC);
                            menuLvl1HashMap.put(Constants.TOOL_BAR_TYPE, Constants.TOOL_BAR_BUTTON);
                            menuLvl1HashMap.put(Constants.TOOLBAR_ICON, Constants.TOOLBAR_ICON_MENU);

                            Map<String, Object> menuLvl2HashMap = new LinkedHashMap<String, Object>();
                            menuLvl2HashMap.put(Constants.MENU_ID, menuLvl2Map.get(Constants.MENU_ID));
                            menuLvl2HashMap.put(Constants.MENU_TEXT, menuLvl2Map.get(Constants.MENU_TEXT));
                            menuLvl2HashMap.put(Constants.MENU_PARENT_ID,
                                    menuLvl2Map.get(Constants.MENU_PARENT_ID));
                            menuLvl2HashMap.put(Constants.MENU_CLS, menuLvl2Map.get(Constants.MENU_CLS));
                            //                        menuLvl2HashMap.put(Constants.TOOLBAR_ICON, Constants.TOOLBAR_ICON_MENUITEM);

                            //
                            menuLvl2HashMap.put(Constants.TOOLBAR_ICON,
                                    menuLvl2Map.get(Constants.TOOLBAR_ICON));

                            Map<String, Object> menuLvl3HashMap = new LinkedHashMap<String, Object>();
                            menuLvl3HashMap.put(Constants.MENU_ID, menuLvl3Map.get(Constants.MENU_ID));
                            menuLvl3HashMap.put(Constants.MENU_TEXT, menuLvl3Map.get(Constants.MENU_TEXT));
                            menuLvl3HashMap.put(Constants.MENU_PARENT_ID,
                                    menuLvl3Map.get(Constants.MENU_PARENT_ID));
                            menuLvl3HashMap.put(Constants.MENU_LEAF, true);
                            menuLvl3HashMap.put(Constants.MENU_URL,
                                    contextPath + menuLvl3Map.get(Constants.MENU_URL));
                            menuLvl3HashMap.put(Constants.MENU_CLS, menuLvl3Map.get(Constants.MENU_CLS));
                            menuLvl3HashMap.put(Constants.MENU_HANDLER, Constants.MENU_LVL3_FUNC);
                            //menuLvl3HashMap.put(Constants.TOOLBAR_ICON, Constants.TOOLBAR_ICON_MENUITEM);
                            menuLvl3HashMap.put(Constants.TOOLBAR_ICON,
                                    menuLvl3Map.get(Constants.TOOLBAR_ICON));

                            LinkedList<Object> menuLvl3Child = new LinkedList<Object>();
                            menuLvl3Child.add(menuLvl3HashMap);
                            menuLvl2HashMap.put(Constants.MENU_CHILDREN, menuLvl3Child);
                            menuLvl2HashMap.put(Constants.TOOL_BAR_CHILDREN, menuLvl3Child);
                            LinkedList<Object> menuLvl2Child = new LinkedList<Object>();
                            menuLvl2Child.add(menuLvl2HashMap);
                            menuLvl1HashMap.put(Constants.MENU_CHILDREN, menuLvl2Child);
                            menuLvl1HashMap.put(Constants.TOOL_BAR_CHILDREN, menuLvl2Child);

                            menuIndexMap.put(menuLvl1Map.get(Constants.MENU_ID).toString(), menuLvl1HashMap);
                        } else {
                            Map<String, Object> menuLvl1HashMap = (Map<String, Object>) menuIndexMap
                                    .get(menuLvl1Map.get(Constants.MENU_ID).toString());
                            LinkedList<Object> menuLvl2Child = (LinkedList<Object>) menuLvl1HashMap
                                    .get(Constants.MENU_CHILDREN);
                            boolean hasMenu = false;
                            for (int c = 0, d = menuLvl2Child.size(); c < d; c++) {
                                Map<String, Object> menuLvl2HashMap = (Map<String, Object>) menuLvl2Child
                                        .get(c);
                                if (StringUtils.trim(menuLvl2HashMap.get(Constants.MENU_ID).toString()).equals(
                                        StringUtils.trim(menuLvl2Map.get(Constants.MENU_ID).toString()))) {
                                    LinkedList<Object> menuLvl3Child = (LinkedList<Object>) menuLvl2HashMap
                                            .get(Constants.MENU_CHILDREN);
                                    Map<String, Object> menuLvl3HashMap = new LinkedHashMap<String, Object>();
                                    menuLvl3HashMap.put(Constants.MENU_ID, menuLvl3Map.get(Constants.MENU_ID));
                                    menuLvl3HashMap.put(Constants.MENU_TEXT,
                                            menuLvl3Map.get(Constants.MENU_TEXT));
                                    menuLvl3HashMap.put(Constants.MENU_PARENT_ID,
                                            menuLvl3Map.get(Constants.MENU_PARENT_ID));
                                    menuLvl3HashMap.put(Constants.MENU_LEAF, true);
                                    menuLvl3HashMap.put(Constants.MENU_URL,
                                            contextPath + menuLvl3Map.get(Constants.MENU_URL));
                                    menuLvl3HashMap.put(Constants.MENU_CLS,
                                            menuLvl3Map.get(Constants.MENU_CLS));
                                    menuLvl3HashMap.put(Constants.MENU_HANDLER, Constants.MENU_LVL3_FUNC);
                                    //menuLvl3HashMap.put(Constants.TOOLBAR_ICON, Constants.TOOLBAR_ICON_MENUITEM);
                                    menuLvl3HashMap.put(Constants.TOOLBAR_ICON,
                                            menuLvl3Map.get(Constants.TOOLBAR_ICON));

                                    menuLvl3Child.add(menuLvl3HashMap);
                                    menuLvl2HashMap.put(Constants.MENU_CHILDREN, menuLvl3Child);
                                    menuLvl2HashMap.put(Constants.TOOL_BAR_CHILDREN, menuLvl3Child);
                                    menuLvl2Child.set(c, menuLvl2HashMap);
                                    hasMenu = true;
                                    break;
                                }
                            }
                            if (!hasMenu) {
                                Map<String, Object> menuLvl2HashMap = new HashMap<String, Object>();
                                menuLvl2HashMap.put(Constants.MENU_ID, menuLvl2Map.get(Constants.MENU_ID));
                                menuLvl2HashMap.put(Constants.MENU_TEXT, menuLvl2Map.get(Constants.MENU_TEXT));
                                menuLvl2HashMap.put(Constants.MENU_PARENT_ID,
                                        menuLvl2Map.get(Constants.MENU_PARENT_ID));
                                menuLvl2HashMap.put(Constants.MENU_CLS, menuLvl2Map.get(Constants.MENU_CLS));
                                //                           menuLvl2HashMap.put(Constants.TOOLBAR_ICON, Constants.TOOLBAR_ICON_MENUITEM);                           

                                //
                                menuLvl2HashMap.put(Constants.TOOLBAR_ICON,
                                        menuLvl2Map.get(Constants.TOOLBAR_ICON));

                                LinkedList<Object> menuLvl3Child = new LinkedList<Object>();
                                Map<String, Object> menuLvl3HashMap = new LinkedHashMap<String, Object>();
                                menuLvl3HashMap.put(Constants.MENU_ID, menuLvl3Map.get(Constants.MENU_ID));
                                menuLvl3HashMap.put(Constants.MENU_TEXT, menuLvl3Map.get(Constants.MENU_TEXT));
                                menuLvl3HashMap.put(Constants.MENU_PARENT_ID,
                                        menuLvl3Map.get(Constants.MENU_PARENT_ID));
                                menuLvl3HashMap.put(Constants.MENU_LEAF, true);
                                menuLvl3HashMap.put(Constants.MENU_URL,
                                        contextPath + menuLvl3Map.get(Constants.MENU_URL));
                                menuLvl3HashMap.put(Constants.MENU_CLS, menuLvl3Map.get(Constants.MENU_CLS));
                                menuLvl3HashMap.put(Constants.MENU_HANDLER, Constants.MENU_LVL3_FUNC);
                                //menuLvl3HashMap.put(Constants.TOOLBAR_ICON, Constants.TOOLBAR_ICON_MENUITEM);
                                menuLvl3HashMap.put(Constants.TOOLBAR_ICON,
                                        menuLvl3Map.get(Constants.TOOLBAR_ICON));

                                menuLvl3Child.add(menuLvl3HashMap);
                                menuLvl2HashMap.put(Constants.MENU_CHILDREN, menuLvl3Child);
                                menuLvl2HashMap.put(Constants.TOOL_BAR_CHILDREN, menuLvl3Child);
                                menuLvl2Child.add(menuLvl2HashMap);
                            }
                            menuLvl1HashMap.put(Constants.MENU_CHILDREN, menuLvl2Child);
                            menuLvl1HashMap.put(Constants.TOOL_BAR_CHILDREN, menuLvl2Child);
                            menuIndexMap.put(menuLvl1Map.get(Constants.MENU_ID).toString(), menuLvl1HashMap);
                        }
                    }
                }
            }
        }
    }
    return menuIndexMap;
}

From source file:com.snp.site.init.SystemInit.java

/**
 * ??? ?????, ? siteStrMap =/*w w w .j av  a 2 s . c  o m*/
 * FileProcessor.getMapFromePropFile(getConfigRoot() + "lang",
 * "properties"); snpStrMap =
 * FileProcessor.getMapFromePropFile(getConfigRoot() + "lang", "txt");
 * ?MAP
 */
public static HashMap getMapFromePropFile(String filepath, String file_dx) throws Exception {
    try {
        HashMap MapData = new HashMap();
        String[] extensions = { file_dx };
        Collection files = FileUtils.listFiles(new File(filepath), extensions, false);
        for (Iterator iter = files.iterator(); iter.hasNext();) {
            File element = (File) iter.next();
            String filename = StringUtils.substringBefore(element.getName(), ".").toLowerCase();
            BufferedReader br = new BufferedReader(
                    new InputStreamReader(new FileInputStream(element), "utf-8"));
            String strvalue = "";
            while (strvalue != null) {
                strvalue = br.readLine();
                String[] mapValue = StringUtils.split(strvalue, "=");
                if (mapValue != null && mapValue.length > 1) {
                    MapData.put(filename + "_" + mapValue[0].trim(), StringUtils.trim(mapValue[1]));
                }
            }

        }
        return MapData;
    } catch (Exception e) {
        throw e;
    }

}

From source file:at.gv.egovernment.moa.id.configuration.filter.AuthenticationFilter.java

public void init(FilterConfig filterConfig) throws ServletException {
    log.debug("Starting init of " + this.getClass().getName() + ".");

    try {//from  w  ww.j  a  v  a 2  s.co m
        config = ConfigurationProvider.getInstance();

    } catch (ConfigurationException e) {
        throw new ServletException(e.getMessage(), e);

    }

    // login page
    loginPage = StringUtils.trim(filterConfig.getInitParameter(WEB_XML_INIT_PARAM_LOGIN_PAGE));
    if (MiscUtil.isEmpty(loginPage)) {
        throw new ServletException(
                "ServletInitParameter \"" + WEB_XML_INIT_PARAM_LOGIN_PAGE + "\" must not be empty.");
    }
    loginPageForward = false; //!WebAppUtil.isFullQualifiedURL(loginPage);

    // error page
    errorPage = StringUtils.trim(filterConfig.getInitParameter(WEB_XML_INIT_PARAM_ERROR_PAGE));
    if (MiscUtil.isEmpty(errorPage)) {
        throw new ServletException(
                "ServletInitParameter \"" + WEB_XML_INIT_PARAM_ERROR_PAGE + "\" must not be empty.");
    }

    // session lost page
    sessionLostPage = StringUtils.trim(filterConfig.getInitParameter(WEB_XML_INIT_PARAM_SESSION_LOST_PAGE));
    if (MiscUtil.isEmpty(sessionLostPage)) {
        log.warn("ServletInitParameter \"" + WEB_XML_INIT_PARAM_SESSION_LOST_PAGE
                + "\" is empty. This parameter defines a failsafe url the browser is redirected to if the original url has been lost due to session timeout.");
    }

    // authenticated page
    authenticatedPage = StringUtils.trim(filterConfig.getInitParameter(WEB_XML_INIT_PARAM_AUTHENTICATED_PAGE));
    if (MiscUtil.isEmpty(authenticatedPage)) {
        log.debug("ServletInitParameter \"" + WEB_XML_INIT_PARAM_AUTHENTICATED_PAGE
                + "\" is empty. This parameter defines the url the user is redirected to (instead of the original url) on successful authentication.");
    }
    String excluded = filterConfig.getInitParameter(WEB_XML_INIT_PARAM_ALLOWED_LIST);
    ArrayList<String> excludedList = new ArrayList<String>();
    if (MiscUtil.isNotEmpty(excluded)) {
        StringTokenizer tokenizer = new StringTokenizer(excluded, WEB_XML_INIT_PARAM_EXCLUDED_PAGES_DELIMITER);
        while (tokenizer.hasMoreTokens()) {
            String ex = StringUtils.trim(tokenizer.nextToken());
            if (MiscUtil.isNotEmpty(ex)) {
                excludedList.add(ex);
            }
        }
    }
    excludedList.add(loginPage);
    excludedList.add(errorPage);
    excludedPages = new String[excludedList.size()];
    excludedPages = excludedList.toArray(excludedPages);

    String excludedRegExString = StringUtils
            .trim(filterConfig.getInitParameter(WEB_XML_INIT_PARAM_ALLOWED_REGEX));
    if (MiscUtil.isNotEmpty(excludedRegExString)) {
        excludedRegEx = Pattern.compile(excludedRegExString);
    }

    log.debug(WEB_XML_INIT_PARAM_LOGIN_PAGE + " [" + (loginPageForward ? "forward" : "redirect") + "] = \""
            + loginPage + "\"");
    log.debug(WEB_XML_INIT_PARAM_AUTHENTICATED_PAGE + " = \""
            + (MiscUtil.isNotEmpty(authenticatedPage) ? authenticatedPage : "<n/a>") + "\"");
    log.debug(WEB_XML_INIT_PARAM_ERROR_PAGE + " = \"" + errorPage + "\"");
    log.debug(WEB_XML_INIT_PARAM_SESSION_LOST_PAGE + " = \""
            + (MiscUtil.isNotEmpty(sessionLostPage) ? sessionLostPage : "<n/a>") + "\"");
    log.debug(WEB_XML_INIT_PARAM_ALLOWED_LIST + " = " + ToStringUtil.toString(excludedPages, ", ", "\""));
    log.debug(WEB_XML_INIT_PARAM_ALLOWED_REGEX + " = \""
            + (excludedRegEx != null ? excludedRegEx.pattern() : "<n/a>") + "\"");
}

From source file:com.redhat.satellite.search.config.Configuration.java

/**
 * get the config entry for string s// w ww .  j  ava  2 s. com
 *
 * @param value string to get the value of
 * @return the value
 */
public String getString(String value) {
    if (logger.isDebugEnabled()) {
        logger.debug("getString() -     getString() called with: " + value);
    }
    if (value == null) {
        return null;
    }

    int lastDot = value.lastIndexOf(".");
    String ns = "";
    String property = value;
    if (lastDot > 0) {
        property = value.substring(lastDot + 1);
        ns = value.substring(0, lastDot);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("getString() -     getString() -> Getting property: " + property);
    }
    String result = configValues.getProperty(property);
    if (logger.isDebugEnabled()) {
        logger.debug("getString() -     getString() -> result: " + result);
    }
    if (result == null) {
        if (!"".equals(ns)) {
            result = configValues.getProperty(ns + "." + property);
        } else {
            for (int i = 0; i < prefixOrder.length; i++) {
                result = configValues.getProperty(prefixOrder[i] + "." + property);
                if (result != null) {
                    break;
                }
            }
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("getString() -     getString() -> returning: " + result);
    }

    if (result == null || result.equals("")) {
        return null;
    }

    return StringUtils.trim(result);
}

From source file:com.hangum.tadpole.rdb.core.dialog.restfulapi.MainSQLEditorAPIServiceDialog.java

private void executeQuery(String strSQL, String strArgument) {
    try {/*www  .ja  v a  2s .co m*/
        String strReturnResult = ""; //$NON-NLS-1$

        // velocity  if else   . 
        String strSQLs = RESTfulAPIUtils.makeTemplateTOSQL("APIServiceDialog", strSQL, strArgument); //$NON-NLS-1$
        // ? ? .
        for (String strTmpSQL : strSQLs.split(PublicTadpoleDefine.SQL_DELIMITER)) {
            if (StringUtils.trim(strTmpSQL).equals(""))
                continue;

            NamedParameterDAO dao = NamedParameterUtil.parseParameterUtils(userDB, strTmpSQL, strArgument);
            if (QueryUtils.RESULT_TYPE.JSON.name().equalsIgnoreCase(comboResultType.getText())) {
                strReturnResult += getSelect(userDB, dao.getStrSQL(), dao.getListParam()) + ","; //$NON-NLS-1$
            } else {
                strReturnResult += getSelect(userDB, dao.getStrSQL(), dao.getListParam());
            }
        }

        if (QueryUtils.RESULT_TYPE.JSON.name().equalsIgnoreCase(comboResultType.getText())) {
            strReturnResult = "[" + StringUtils.removeEnd(strReturnResult, ",") + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        }

        textResult.setText(strReturnResult);

    } catch (Exception e) {
        logger.error("api exception", e); //$NON-NLS-1$

        MessageDialog.openError(getShell(), CommonMessages.get().Error, e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
    }
}

From source file:com.edgenius.wiki.installation.DBLoader.java

/**
 * If url is empty, try to use prototype, by host and dbname. Otherwise, compare prototype(combile host/dbname) with URL, if diff
 *//*ww w . j av a 2 s  .  c  o m*/
public ConnectionProxy getConnection(String dbType, String url, String dbSchema, String username,
        String password) throws Exception {

    String driver = getDriver(dbType, getDriverType(url));
    log.info("Loading database driver {} on type {}.", driver, dbType);
    if (StringUtils.isBlank(driver) || StringUtils.isBlank(url) || StringUtils.isBlank(username)) {
        throw new DBLoaderException(
                "driver or url or username is blank:" + dbType + "|" + url + "|" + username + "|");
    }
    try {
        Class.forName(driver);
    } catch (Exception e) {
        throw new DriverNotFoundException(e);
    }
    return new ConnectionProxy(dbType,
            DriverManager.getConnection(url.trim(), username.trim(), StringUtils.trim(password)),
            StringUtils.trim(dbSchema));

}

From source file:eu.annocultor.converter.ConverterHandler.java

@Override
public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
    try {/*  w  w w .j av  a  2s  .c  o m*/
        if (endRawFilter(qName)) {
            return;
        }

        // closing a triple
        if (tagPath.size() > 0) {
            // process this tag value
            Path closingTag = tagPath.pop();
            DataObject dataObject = peekNotYetCompletedDataObject();
            if (dataObject != null) {
                XmlValue value = new XmlValue(StringUtils.trim(closingTag.getValue()), closingTag.getLang());
                if (value != null) {
                    try {
                        dataObject.addValue(closingTag, value);
                    } catch (Exception e) {
                        throw new SAXException("error on " + closingTag, e);
                    }

                    if (dataObject.size() > 10000) {
                        throw new SAXException(
                                "Data object is longer than 10000 elements. This suggests that the record separating XML path is incorrect");
                    }
                }
            }

            // closing a record
            List<ObjectRule> rules;
            try {
                rules = task.getRuleForSourcePath(closingTag);
            } catch (Exception e) {
                throw new SAXException(e);
            }

            if (rules.size() > 1)
                throw new SAXException("Multiple rules found on path: " + tagPath.peek());

            if (rules.size() == 1) {
                /*
                 * This is the end of a data object
                 */
                // check consistency
                if (closingTag == null)
                    throw new SAXException("Data object separator tag is not closed");

                if (!partsNotYetCompleted.peek().getSeparatingPath().equals(closingTag))
                    throw new SAXException(
                            "Open-close tags mismatch on tag " + localName + " value " + closingTag.getValue());

                // complete this part
                partsCompleted.add(partsNotYetCompleted.pop());

                // if we completed all parts - process them
                if (partsNotYetCompleted.isEmpty()) {
                    passedARecord = true;
                    currentPassedRecord++;

                    while (!partsCompleted.isEmpty()) {
                        try {
                            processDataObject();
                        } catch (Exception e) {
                            try {
                                reportException(e);
                            } catch (Exception ex) {
                                throw new SAXException(ex);
                            }
                            throw new SAXException(e);
                        }
                        partsCompleted.pop();
                    }
                }
            }

            // append this tag value to the parent
            if (htmlMode)
                if (tagPath.size() > 0) {
                    // TODO: should be local tag ipv full ns tagPath
                    tagPath.peek().appendValue('<' + tagPath.peek().getPath() + '>' + closingTag.getValue()
                            + "</" + tagPath.peek().getPath() + ">");
                }

        } else
            throw new SAXException("Error in XML structure");
    } catch (Exception e) {
        throw new SAXException("Exception on ending tag " + namespaceURI + localName, e);
    }

}

From source file:ch.entwine.weblounge.contentrepository.impl.endpoint.FilesEndpoint.java

/**
 * Returns a collection of files which match the given criteria.
 * //ww  w  .  j av a2  s  .  c o  m
 * @param request
 *          the request
 * @param path
 *          the file path (e.g. <code>/my/simple/path</code>)
 * @param subjectstring
 *          one ore more subjects, divided by a comma
 * @param searchterms
 *          fulltext search terms
 * @param filter
 *          further search result filtering
 * @param type
 *          the file type, e. g.
 *          {@link ch.entwine.weblounge.common.content.image.ImageResource#TYPE}
 * @param sort
 *          sort order, possible values are
 *          <code>created-asc, created-desc, published-asc, published-desc, modified-asc & modified-desc</code>
 * @param limit
 *          search result limit
 * @param offset
 *          search result offset (for paging in combination with limit)
 * @return a collection of matching files
 */
@GET
@Path("/")
public Response getAllFiles(@Context HttpServletRequest request, @QueryParam("path") String path,
        @QueryParam("subjects") String subjectstring, @QueryParam("searchterms") String searchterms,
        @QueryParam("filter") String filter, @QueryParam("type") String type,
        @QueryParam("sort") @DefaultValue("modified-desc") String sort,
        @QueryParam("limit") @DefaultValue("10") int limit,
        @QueryParam("offset") @DefaultValue("0") int offset) {

    // Create search query
    Site site = getSite(request);
    SearchQuery q = new SearchQueryImpl(site);
    q.withVersion(Resource.LIVE);

    // Type
    q.withoutTypes(Page.TYPE);
    if (StringUtils.isNotBlank(type))
        q.withTypes(type);

    // Path
    if (StringUtils.isNotBlank(path))
        q.withPath(path);

    // Subjects
    if (StringUtils.isNotBlank(subjectstring)) {
        StringTokenizer subjects = new StringTokenizer(subjectstring, ",");
        while (subjects.hasMoreTokens())
            q.withSubject(subjects.nextToken());
    }

    // Search terms
    if (StringUtils.isNotBlank(searchterms))
        q.withText(true, searchterms);

    Calendar today = Calendar.getInstance();
    today.set(Calendar.HOUR_OF_DAY, 0);
    today.set(Calendar.MINUTE, 0);
    today.set(Calendar.SECOND, 0);
    today.set(Calendar.MILLISECOND, 0);
    Calendar yesterday = Calendar.getInstance();
    yesterday.add(Calendar.DATE, -1);
    yesterday.set(Calendar.HOUR_OF_DAY, 0);
    yesterday.set(Calendar.MINUTE, 0);
    yesterday.set(Calendar.SECOND, 0);
    yesterday.set(Calendar.MILLISECOND, 0);
    Calendar tomorrow = Calendar.getInstance();
    tomorrow.add(Calendar.DATE, 1);
    tomorrow.set(Calendar.HOUR_OF_DAY, 0);
    tomorrow.set(Calendar.MINUTE, 0);
    tomorrow.set(Calendar.SECOND, 0);
    tomorrow.set(Calendar.MILLISECOND, 0);

    // Filter query
    if (StringUtils.isNotBlank(filter)) {
        if ("/".equals(filter)) {
            q.withPath("/");
        }

        // by user
        else if (filter.startsWith("creator:") && filter.length() > "creator:".length()) {
            String creator = StringUtils.trim(filter.substring("creator:".length()));
            if ("me".equals(creator))
                q.withCreator(securityService.getUser());
            else
                q.withCreator(new UserImpl(creator));
        } else if (filter.startsWith("modifier:") && filter.length() > "modifier:".length()) {
            String modifier = StringUtils.trim(filter.substring("modifier:".length()));
            if ("me".equals(modifier))
                q.withModifier(securityService.getUser());
            else
                q.withModifier(new UserImpl(modifier));
        } else if (filter.startsWith("publisher:") && filter.length() > "publisher:".length()) {
            String publisher = StringUtils.trim(filter.substring("publisher:".length()));
            if ("me".equals(publisher))
                q.withPublisher(securityService.getUser());
            else
                q.withPublisher(new UserImpl(publisher));
        }

        // by date

        else if (filter.startsWith("created:") && filter.length() > "created:".length()) {
            String created = StringUtils.trim(filter.substring("created:".length()));
            if ("today".equals(created))
                q.withCreationDateBetween(today.getTime()).and(tomorrow.getTime());
            else if ("yesterday".equals(created))
                q.withCreationDateBetween(yesterday.getTime()).and(today.getTime());
            else
                q.withCreationDate(tomorrow.getTime());
        } else if (filter.startsWith("modified:") && filter.length() > "modified:".length()) {
            String modified = StringUtils.trim(filter.substring("modified:".length()));
            if ("today".equals(modified))
                q.withModificationDateBetween(today.getTime()).and(tomorrow.getTime());
            else if ("yesterday".equals(modified))
                q.withModificationDateBetween(yesterday.getTime()).and(today.getTime());
            else
                q.withCreationDate(tomorrow.getTime());
        } else if (filter.startsWith("publisher:") && filter.length() > "publisher:".length()) {
            String published = StringUtils.trim(filter.substring("published:".length()));
            if ("today".equals(published))
                q.withPublishingDateBetween(today.getTime()).and(tomorrow.getTime());
            else if ("yesterday".equals(published))
                q.withPublishingDateBetween(yesterday.getTime()).and(today.getTime());
            else
                q.withCreationDate(tomorrow.getTime());
        }

        // by id
        else if (filter.contains("id:")) {
            String[] searchTerms = StringUtils.split(filter);
            for (String searchTerm : searchTerms) {
                if (searchTerm.startsWith("id:") && filter.length() > "id:".length()) {
                    q.withIdentifier(StringUtils.trim(searchTerm.substring("id:".length())));
                }
            }
        }

        // simple filter
        else {
            q.withFulltext(true, filter);
        }
    }

    // Limit and Offset
    q.withLimit(limit);
    q.withOffset(offset);

    // Sort order
    if (StringUtils.equalsIgnoreCase("modified-asc", sort)) {
        q.sortByModificationDate(Order.Ascending);
    } else if (StringUtils.equalsIgnoreCase("modified-desc", sort)) {
        q.sortByModificationDate(Order.Descending);
    } else if (StringUtils.equalsIgnoreCase("created-asc", sort)) {
        q.sortByCreationDate(Order.Ascending);
    } else if (StringUtils.equalsIgnoreCase("created-desc", sort)) {
        q.sortByCreationDate(Order.Descending);
    } else if (StringUtils.equalsIgnoreCase("published-asc", sort)) {
        q.sortByPublishingDate(Order.Ascending);
    } else if (StringUtils.equalsIgnoreCase("published-desc", sort)) {
        q.sortByPublishingDate(Order.Descending);
    }

    // Load the result
    String result = loadResultSet(q);

    // Return the response
    return Response.ok(result).build();
}

From source file:de.iteratec.iteraplan.businesslogic.exchange.timeseriesExcel.importer.TimeseriesExcelImporter.java

private BuildingBlock getBuildingBlock(Row row, BuildingBlockService<BuildingBlock, Integer> bbService) {
    Cell cell = row.getCell(BB_COL_NO);/*from   ww w  .  j  a v a2 s. c o m*/

    if (ExcelUtils.isEmptyCell(cell)) {
        logError(ExcelUtils.getFullCellReference(row.getSheet(), new CellReference(row.getRowNum(), BB_COL_NO)),
                "No Building Block found.");
        return null;
    }

    String bbName = StringUtils.trim(ExcelUtils.getStringCellValue(cell));
    List<BuildingBlock> bbList = bbService.findByNames(Collections.singleton(bbName));

    if (bbList == null || bbList.isEmpty()) {
        logError(ExcelUtils.getFullCellReference(cell), "No Building Block named \"{0}\" found.", bbName);
        return null;
    }

    if (bbList.size() > 1) {
        LOGGER.error("More than one Building Block named \"{0}\" found.", bbName);
        throw new IteraplanTechnicalException(IteraplanErrorMessages.GENERAL_TECHNICAL_ERROR);
    }

    return bbList.get(0);
}