Example usage for org.dom4j Element elementIterator

List of usage examples for org.dom4j Element elementIterator

Introduction

In this page you can find the example usage for org.dom4j Element elementIterator.

Prototype

Iterator<Element> elementIterator();

Source Link

Document

Returns an iterator over all this elements child elements.

Usage

From source file:com.christophermrossi.jpt.PageTemplateImpl.java

License:Open Source License

/**
 * With all of our namespace woes, getting an XPath expression
 * to work has proven futile, so we'll recurse through the tree
 * ourselves to find what we need.//from   w w w. j  a  v a2 s.c  om
 */
private void findSlots(Element element, Map slots) {
    //System.err.println( "element: " + element.getName() );
    for (Iterator i = element.attributes().iterator(); i.hasNext();) {
        Attribute attribute = (Attribute) i.next();
        //System.err.println( "\t" + attribute.getName() + "\t" + attribute.getQualifiedName() );
    }

    // Look for our attribute
    //String qualifiedAttributeName = this.metalNamespacePrefix + ":fill-slot";
    //String name = element.attributeValue( qualifiedAttributeName );
    String name = element.attributeValue("fill-slot");
    if (name != null) {
        slots.put(name, new SlotImpl(element));
    }

    // Recurse into child elements
    for (Iterator i = element.elementIterator(); i.hasNext();) {
        findSlots((Element) i.next(), slots);
    }
}

From source file:com.christophermrossi.jpt.PageTemplateImpl.java

License:Open Source License

/**
 * With all of our namespace woes, getting an XPath expression
 * to work has proven futile, so we'll recurse through the tree
 * ourselves to find what we need./*w  w  w  . jav a  2 s .c o m*/
 */
private void findMacros(Element element, Map macros) {
    // Process any declared namespaces
    for (Iterator i = element.declaredNamespaces().iterator(); i.hasNext();) {
        Namespace namespace = (Namespace) i.next();
        namespaces.put(namespace.getPrefix(), namespace.getURI());
        //if ( namespace.getURI().equals( TAL_NAMESPACE_URI ) ) {
        //    this.talNamespacePrefix = namespace.getPrefix();
        //}
        //else if ( namespace.getURI().equals( METAL_NAMESPACE_URI ) ) {
        //    this.metalNamespacePrefix = namespace.getPrefix();
        //}
    }

    // Look for our attribute
    //String qualifiedAttributeName = this.metalNamespacePrefix + ":define-macro";
    //String name = element.attributeValue( qualifiedAttributeName );
    String name = element.attributeValue("define-macro");
    //if ( name == null ) {
    //    name = element.attributeValue
    //        ( new QName( "define-macro", new Namespace( metalNamespacePrefix, METAL_NAMESPACE_URI ) ) );
    //}
    if (name != null) {
        macros.put(name, new MacroImpl(element));
    }

    // Recurse into child elements
    for (Iterator i = element.elementIterator(); i.hasNext();) {
        findMacros((Element) i.next(), macros);
    }
}

From source file:com.cloopen.rest.sdk.CCPRestSDK.java

License:Open Source License

/**
 * @description xml??map//from  w  ww .j ava 2s. c o  m
 * @param xml
 * @return Map
 */
private HashMap<String, Object> xmlToMap(String xml) {
    HashMap<String, Object> map = new HashMap<String, Object>();
    Document doc = null;
    try {
        doc = DocumentHelper.parseText(xml); // XML
        Element rootElt = doc.getRootElement(); // ?
        HashMap<String, Object> hashMap2 = new HashMap<String, Object>();
        ArrayList<HashMap<String, Object>> arrayList = new ArrayList<HashMap<String, Object>>();
        for (Iterator i = rootElt.elementIterator(); i.hasNext();) {
            Element e = (Element) i.next();
            if ("statusCode".equals(e.getName()) || "statusMsg".equals(e.getName()))
                map.put(e.getName(), e.getText());
            else {
                if ("SubAccount".equals(e.getName()) || "TemplateSMS".equals(e.getName())
                        || "totalCount".equals(e.getName()) || "token".equals(e.getName())
                        || "callSid".equals(e.getName()) || "state".equals(e.getName())
                        || "downUrl".equals(e.getName())) {
                    if (!"SubAccount".equals(e.getName()) && !"TemplateSMS".equals(e.getName())) {
                        hashMap2.put(e.getName(), e.getText());
                    } else if ("SubAccount".equals(e.getName())) {

                        HashMap<String, Object> hashMap3 = new HashMap<String, Object>();
                        for (Iterator i2 = e.elementIterator(); i2.hasNext();) {
                            Element e2 = (Element) i2.next();
                            hashMap3.put(e2.getName(), e2.getText());
                        }
                        arrayList.add(hashMap3);
                        hashMap2.put("SubAccount", arrayList);
                    } else if ("TemplateSMS".equals(e.getName())) {

                        HashMap<String, Object> hashMap3 = new HashMap<String, Object>();
                        for (Iterator i2 = e.elementIterator(); i2.hasNext();) {
                            Element e2 = (Element) i2.next();
                            hashMap3.put(e2.getName(), e2.getText());
                        }
                        arrayList.add(hashMap3);
                        hashMap2.put("TemplateSMS", arrayList);
                    }
                    map.put("data", hashMap2);
                } else {

                    HashMap<String, Object> hashMap3 = new HashMap<String, Object>();
                    for (Iterator i2 = e.elementIterator(); i2.hasNext();) {
                        Element e2 = (Element) i2.next();
                        // hashMap2.put(e2.getName(),e2.getText());
                        hashMap3.put(e2.getName(), e2.getText());
                    }
                    if (hashMap3.size() != 0) {
                        hashMap2.put(e.getName(), hashMap3);
                    } else {
                        hashMap2.put(e.getName(), e.getText());
                    }
                    map.put("data", hashMap2);
                }
            }
        }
    } catch (DocumentException e) {
        e.printStackTrace();
        LoggerUtil.error(e.getMessage());
    } catch (Exception e) {
        LoggerUtil.error(e.getMessage());
        e.printStackTrace();
    }
    return map;
}

From source file:com.cn.controller.CommonController.java

/**
 * ?????json//from   w w w. j a  v a 2 s  .co m
 *
 * @param element
 * @param roleRightList
 * @return
 */
public String hasRight(Element element, ArrayList<String> roleRightList) {
    String menuJson = "";
    String roleCode = element.attributeValue("id");
    if (roleRightList.contains(roleCode)) {
        if (element.elementIterator().hasNext()) {
            menuJson += "\"" + element.attributeValue("text") + "\":{";
            Iterator<Element> iterator = element.elementIterator();
            while (iterator.hasNext()) {
                menuJson += hasRight(iterator.next(), roleRightList);
            }
            menuJson = menuJson.substring(0, menuJson.length() - 1);
            menuJson += "},";
        } else {
            menuJson += "\"" + element.attributeValue("text") + "\":";
            menuJson += "\"" + element.attributeValue("hypelnk") + "," + element.attributeValue("url") + ","
                    + element.attributeValue("id") + "," + element.attributeValue("icon") + "\",";
        }
    }
    return menuJson;
}

From source file:com.cn.controller.CommonController.java

public String hasAppRight(Element element, ArrayList<String> roleRightList) {
    String menuJson = "";
    String roleCode = element.attributeValue("id");
    if (roleRightList.contains(roleCode) && roleCode.startsWith("80")) {
        if (element.elementIterator().hasNext()) {
            menuJson += "\"" + element.attributeValue("text") + "\":{";
            Iterator<Element> iterator = element.elementIterator();
            while (iterator.hasNext()) {
                menuJson += hasAppRight(iterator.next(), roleRightList);
            }/*from   w w  w.  j a va2s.co m*/
            menuJson = menuJson.substring(0, menuJson.length() - 1);
            menuJson += "},";
        } else {
            menuJson += "\"" + element.attributeValue("text") + "\":";
            menuJson += "\"" + element.attributeValue("hypelnk") + "," + element.attributeValue("url") + ","
                    + element.attributeValue("id") + "," + element.attributeValue("icon") + "\",";
        }
    }
    return menuJson;
}

From source file:com.cn.servlet.DataInterface.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.// w w w .  ja  v  a 2 s.c om
 *
 * @param request servlet request
 * @param response servlet response
 * @param params
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response, String params)
        throws ServletException, IOException {
    String uri = request.getRequestURI();
    String subUri = uri.substring(uri.lastIndexOf("/") + 1, uri.lastIndexOf("."));
    String json = null;
    CommonController commonController = new CommonController();
    InterfaceController interfaceController = new InterfaceController();
    DatabaseOpt opt = new DatabaseOpt();
    //logger.info(Units.getIpAddress(request) + "accept:" + subUri + ",time:" + (new Date().getTime()));

    try {
        logger.info(subUri + ",params:" + params);
        JSONObject paramsJson = JSONObject.parseObject(params);
        //logger.info("send:" + subUri + ",time:" + paramsJson.getString("timestamp"));
        String module = paramsJson.getString("module");
        String operation = paramsJson.getString("operation");
        String rely = (paramsJson.getString("rely") == null) ? ("{}") : (paramsJson.getString("rely"));
        String target = paramsJson.getString("target");
        String datas = (paramsJson.getString("datas") == null) ? ("") : paramsJson.getString("datas");
        String update = paramsJson.getString("update");
        String add = paramsJson.getString("add");
        String delete = paramsJson.getString("del");
        String item = paramsJson.getString("item");
        String details = paramsJson.getString("details");
        String detail = paramsJson.getString("detail");
        String fileName = paramsJson.getString("fileName");
        String operateType = paramsJson.getString("type");
        String start = paramsJson.getString("start");
        String end = paramsJson.getString("end");
        int isHistory = paramsJson.getIntValue("isHistory");
        int pageIndex = paramsJson.getIntValue("pageIndex");
        int pageSize = paramsJson.getIntValue("pageSize");

        HttpSession session = request.getSession();
        String path = this.getClass().getClassLoader().getResource("/").getPath().replaceAll("%20", " ");
        String importPath = getServletContext().getRealPath("/").replace("\\", "/") + "excelFile/";

        /*??*/
        if (!"userLogin".equals(module) && (session.getAttribute("user") == null
                || session.getAttribute("loginType") == null || session.getAttribute("employee") == null)) {
            session.invalidate();
            json = Units.objectToJson(-99, "", null);
            PrintWriter out = response.getWriter();
            try {
                response.setContentType("text/html;charset=UTF-8");
                response.setHeader("Cache-Control", "no-store");
                response.setHeader("Pragma", "no-cache");
                response.setDateHeader("Expires", 0);
                out.print(json);
            } finally {
                out.close();
            }
            return;
        }

        Employee curEmployee = null;
        Customer curCustomer = null;
        if (session.getAttribute("employee") != null
                && session.getAttribute("loginType").toString().compareTo("employeeLogin") == 0) {
            curEmployee = (Employee) session.getAttribute("employee");
        }
        if (session.getAttribute("employee") != null
                && session.getAttribute("loginType").toString().compareTo("customerLogin") == 0) {
            curCustomer = (Customer) session.getAttribute("employee");
        }

        switch (module) {
        //<editor-fold desc="?">
        case "userLogin": {
            switch (operation) {
            //<editor-fold desc="">
            case "employeeLogin": {
                String whereSql = "EmployeeName = '" + paramsJson.getString("username") + "'";
                List<Object> res = commonController.dataBaseQuery("table", "com.cn.bean.", "Employee", "*",
                        whereSql, 1, 1, "EmployeeName", 1, DatabaseOpt.DATA);
                String type = paramsJson.getString("type");
                if (res != null && res.size() > 0) {
                    Employee employee = (Employee) res.get(0);
                    if (employee.getEmployeePassword().compareTo(paramsJson.getString("password")) == 0) {
                        session.setAttribute("user", paramsJson.getString("username"));
                        session.setAttribute("loginType", "employeeLogin");
                        session.setAttribute("employee", employee);
                        //session.setAttribute("customer", null);
                        String whereCase = "RoleCode in ('" + employee.getEmployeeTypeCode() + "')";
                        List<Object> roleRight = commonController.dataBaseQuery("table", "com.cn.bean.",
                                "PlatformRoleRight", "*", whereCase, Integer.MAX_VALUE, 1, "RoleCode", 0,
                                DatabaseOpt.BASE);
                        if (roleRight != null && roleRight.size() > 0) {
                            ArrayList<String> roleRightList = new ArrayList<>();
                            roleRight.stream().map((obj) -> (PlatformRoleRight) obj).forEach((right) -> {
                                roleRightList.add(right.getRightCode());
                            });

                            if (type.compareTo("pc") == 0) {
                                /*???????*/
                                String menuJson = "{";
                                SAXReader reader = new SAXReader();
                                Document document = reader.read(new File(path + "menu.xml"));
                                Element root = document.getRootElement();
                                Iterator<Element> iterator = root.elementIterator();
                                while (iterator.hasNext()) {
                                    menuJson += commonController.hasRight(iterator.next(), roleRightList);
                                }
                                if (menuJson.length() <= 1) {
                                    menuJson = null;
                                    json = Units.objectToJson(-1, "???!", menuJson);
                                } else {
                                    menuJson = menuJson.substring(0, menuJson.length() - 1) + "}";
                                    json = Units.objectToJson(0, "?!", menuJson);
                                }
                            }
                            if (type.compareTo("app") == 0) {
                                /*???????*/
                                String menuJson = "{";
                                SAXReader reader = new SAXReader();
                                Document document = reader.read(new File(path + "menu.xml"));
                                Element root = document.getRootElement();
                                Iterator<Element> iterator = root.elementIterator();
                                while (iterator.hasNext()) {
                                    menuJson += commonController.hasAppRight(iterator.next(), roleRightList);
                                }
                                if (menuJson.length() <= 1) {
                                    menuJson = null;
                                    json = Units.objectToJson(-1, "???!", menuJson);
                                } else {
                                    menuJson = menuJson.substring(0, menuJson.length() - 1) + "}";
                                    JSONObject object = new JSONObject();
                                    object.put("menuJson", menuJson);
                                    object.put("employee", employee);
                                    json = Units.objectToJson(0, "?!", object);
                                }
                            }
                        } else {
                            json = Units.objectToJson(-1, "???!", null);
                        }
                    } else {
                        json = Units.objectToJson(-1, "????!", null);
                    }
                } else {
                    json = Units.objectToJson(-1, "???!", null);
                }

                break;
            }
            //</editor-fold>

            //<editor-fold desc="?">
            case "login": {
                String type = paramsJson.getString("type");
                PlatformUserInfoController controller = new PlatformUserInfoController();
                int result = controller.userLogin(paramsJson.getString("username"),
                        paramsJson.getString("password"));
                switch (result) {
                case 0:
                    session.setAttribute("user", paramsJson.getString("username"));
                    session.setAttribute("loginType", "login");
                    //session.setAttribute("customer", null);
                    session.setAttribute("employee", null);
                    /*??*/
                    String whereCase = "UserLoginAccount = '" + paramsJson.getString("username") + "'";
                    List<Object> userRole = commonController.dataBaseQuery("table", "com.cn.bean.",
                            "PlatformUserRole", "*", whereCase, Integer.MAX_VALUE, 1, "UserLoginAccount", 0,
                            DatabaseOpt.BASE);
                    if (userRole != null) {
                        /*?????*/
                        whereCase = "RoleCode in (";
                        for (Object obj : userRole) {
                            PlatformUserRole role = (PlatformUserRole) obj;
                            whereCase += "'" + role.getRoleCode() + "',";
                        }
                        whereCase = whereCase.substring(0, whereCase.length() - 1);
                        whereCase += ")";
                        List<Object> roleRight = commonController.dataBaseQuery("table", "com.cn.bean.",
                                "PlatformRoleRight", "*", whereCase, Integer.MAX_VALUE, 1, "RoleCode", 0,
                                DatabaseOpt.BASE);
                        ArrayList<String> roleRightList = new ArrayList<>();
                        roleRight.stream().map((obj) -> (PlatformRoleRight) obj).forEach((right) -> {
                            roleRightList.add(right.getRightCode());
                        });
                        /*???????*/
                        String menuJson = "{";
                        SAXReader reader = new SAXReader();
                        Document document = reader.read(new File(path + "menu.xml"));
                        Element root = document.getRootElement();
                        Iterator<Element> iterator = root.elementIterator();
                        while (iterator.hasNext()) {
                            menuJson += commonController.hasRight(iterator.next(), roleRightList);
                        }
                        menuJson = menuJson.substring(0, menuJson.length() - 1) + "}";

                        if (type.compareTo("pc") == 0) {
                            json = Units.objectToJson(result, "?!", menuJson);
                        }
                        if (type.compareTo("app") == 0) {
                            json = Units.objectToJson(result, "?!", roleRightList);
                        }
                    } else {
                        json = Units.objectToJson(-1, "?!", null);
                    }
                    break;
                case 1:
                    json = Units.objectToJson(result, "???!", null);
                    break;
                case 2:
                    json = Units.objectToJson(result, "???!", null);
                    break;
                case -1:
                    json = Units.objectToJson(result, "!", null);
                    break;
                default:
                    json = Units.objectToJson(result, "?!", null);
                    break;
                }
                break;
            }
            //</editor-fold>

            //<editor-fold desc="">
            case "customerLogin": {
                String whereSql = "CustomerID = '" + paramsJson.getString("username") + "'";
                List<Object> res = commonController.dataBaseQuery("view", "com.cn.bean.", "Customer", "*",
                        whereSql, 1, 1, "CustomerID", 1, DatabaseOpt.DATA);
                String type = paramsJson.getString("type");
                if (res != null && res.size() > 0) {
                    Customer customer = (Customer) res.get(0);
                    if (customer.getCustomerPassword().compareTo(paramsJson.getString("password")) == 0) {
                        session.setAttribute("user", paramsJson.getString("username"));
                        session.setAttribute("loginType", "customerLogin");
                        //session.setAttribute("customer", customer);
                        session.setAttribute("employee", customer);
                        String whereCase = "RoleCode in ('" + customer.getCustomerRoleCode() + "')";
                        List<Object> roleRight = commonController.dataBaseQuery("table", "com.cn.bean.",
                                "PlatformRoleRight", "*", whereCase, Integer.MAX_VALUE, 1, "RoleCode", 0,
                                DatabaseOpt.BASE);
                        if (roleRight != null && roleRight.size() > 0) {
                            ArrayList<String> roleRightList = new ArrayList<>();
                            roleRight.stream().map((obj) -> (PlatformRoleRight) obj).forEach((right) -> {
                                roleRightList.add(right.getRightCode());
                            });

                            if (type.compareTo("pc") == 0) {
                                /*???????*/
                                String menuJson = "{";
                                SAXReader reader = new SAXReader();
                                Document document = reader.read(new File(path + "menu.xml"));
                                Element root = document.getRootElement();
                                Iterator<Element> iterator = root.elementIterator();
                                while (iterator.hasNext()) {
                                    menuJson += commonController.hasRight(iterator.next(), roleRightList);
                                }
                                if (menuJson.length() <= 1) {
                                    menuJson = null;
                                    json = Units.objectToJson(-1, "???!", menuJson);
                                } else {
                                    menuJson = menuJson.substring(0, menuJson.length() - 1) + "}";
                                    json = Units.objectToJson(0, "?!", menuJson);
                                }
                            }
                            if (type.compareTo("app") == 0) {
                                /*???????*/
                                String menuJson = "{";
                                SAXReader reader = new SAXReader();
                                Document document = reader.read(new File(path + "menu.xml"));
                                Element root = document.getRootElement();
                                Iterator<Element> iterator = root.elementIterator();
                                while (iterator.hasNext()) {
                                    menuJson += commonController.hasAppRight(iterator.next(), roleRightList);
                                }

                                if (menuJson.length() <= 1) {
                                    menuJson = null;
                                    json = Units.objectToJson(-1, "???!", menuJson);
                                } else {
                                    menuJson = menuJson.substring(0, menuJson.length() - 1) + "}";
                                    JSONObject object = new JSONObject();
                                    object.put("menuJson", menuJson);
                                    object.put("employee", customer);
                                    json = Units.objectToJson(0, "?!", object);
                                }
                            }
                        } else {
                            json = Units.objectToJson(-1, "???!", null);
                        }
                    } else {
                        json = Units.objectToJson(-1, "????!", null);
                    }
                } else {
                    json = Units.objectToJson(-1, "???!", null);
                }
                break;
            }
            //</editor-fold>
            }
            break;
        }
        //</editor-fold>

        //<editor-fold desc="?">
        case "?": {
            String oldPassword = paramsJson.getString("oldPassword");
            String newPassword = paramsJson.getString("newPassword");
            switch (session.getAttribute("loginType").toString()) {
            case "employeeLogin": {
                if (curEmployee != null && curEmployee.getEmployeePassword().compareTo(oldPassword) == 0) {
                    JSONArray updateParams = new JSONArray();
                    JSONObject setObj = new JSONObject();
                    setObj.put("employeePassword", newPassword);
                    updateParams.add(setObj);
                    JSONObject whereObj = new JSONObject();
                    whereObj.put("employeeName", curEmployee.getEmployeeName());
                    updateParams.add(whereObj);

                    ArrayList<Integer> updateResult = commonController.dataBaseOperate(
                            updateParams.toJSONString(), "com.cn.bean.", "Employee", "update",
                            DatabaseOpt.DATA);
                    if (updateResult.get(0) == 0) {
                        json = Units.objectToJson(0, "??!", null);
                    } else {
                        json = Units.objectToJson(-1, "?!", null);
                    }
                } else {
                    json = Units.objectToJson(-1, "??!", null);
                }
                break;
            }
            case "customerLogin": {
                if (curCustomer != null && curCustomer.getCustomerPassword().compareTo(oldPassword) == 0) {
                    JSONArray updateParams = new JSONArray();
                    JSONObject setObj = new JSONObject();
                    setObj.put("customerPassword", newPassword);
                    updateParams.add(setObj);
                    JSONObject whereObj = new JSONObject();
                    whereObj.put("customerID", curCustomer.getCustomerID());
                    updateParams.add(whereObj);

                    ArrayList<Integer> updateResult = commonController.dataBaseOperate(
                            updateParams.toJSONString(), "com.cn.bean.", "Customer", "update",
                            DatabaseOpt.DATA);
                    if (updateResult.get(0) == 0) {
                        json = Units.objectToJson(0, "??!", null);
                    } else {
                        json = Units.objectToJson(-1, "?!", null);
                    }
                } else {
                    json = Units.objectToJson(-1, "??!", null);
                }
                break;
            }
            case "login": {

                break;
            }
            }
            break;
        }
        //</editor-fold>

        //<editor-fold desc="?">
        case "?": {
            if (curEmployee != null && curEmployee.getEmployeeName().compareTo("?") == 0) {
                CommonOperate operate = new CommonOperate();
                json = operate.dataMoveToHistory(curEmployee.getEmployeeName());
            } else {
                json = Units.objectToJson(-1, "???", null);
            }
            break;
        }
        //</editor-fold>

        //<editor-fold desc="">
        case "": {
            List<Object> res = commonController.dataBaseQuery("table", "com.cn.bean.", "DataJZ", "*", "",
                    Integer.MAX_VALUE, 1, "JZYMonth", 1, DatabaseOpt.DATA);
            if (res != null && res.size() > 0) {
                json = Units.objectToJson(0, "", res);
            } else {
                json = Units.objectToJson(-1, "?!", null);
            }
            break;
        }
        //</editor-fold>
        /**
         * ***************************************?**************************************
         */
        //<editor-fold desc="?">
        //<editor-fold desc="">
        case "": {
            switch (operation) {
            case "create": {
                json = interfaceController.createOperate(20, "table", "com/cn/json/plan/", "com.cn.bean.plan.",
                        "DHPlan", "DHPlanID", DatabaseOpt.DATA);
                json = Units.insertStr(json, "\\\"??\\",
                        ",@DHJH_" + Units.getNowTimeNoSeparator());
                break;
            }
            case "request_table": {
                if (target.compareToIgnoreCase("supplierID") == 0) {
                    String[] keys = { "supplierID", "supplierName" };
                    String[] keysName = { "?", "??" };
                    int[] keysWidth = { 50, 50 };
                    String[] fieldsName = { "customerID", "customerName" };
                    json = interfaceController.queryOperate(target, "com.cn.bean.", "table", "Customer",
                            "CustomerID", datas, rely, true, DatabaseOpt.DATA, pageSize, pageIndex, keys,
                            keysName, keysWidth, fieldsName);
                }
                if (target.compareToIgnoreCase("partCode") == 0) {
                    String[] keys = { "partCode", "partID", "partName", "partUnit", "cfAddress" };
                    String[] keysName = { "??", "??", "???", "???",
                            "?" };
                    int[] keysWidth = { 20, 20, 20, 20, 20 };
                    String[] fieldsName = { "partCode", "partID", "partName", "partUnit", "psAddress1" };
                    json = interfaceController.queryOperate(target, "com.cn.bean.", "table", "PartBaseInfo",
                            "PartCode", datas, rely, true, DatabaseOpt.DATA, pageSize, pageIndex, keys,
                            keysName, keysWidth, fieldsName);
                }
                break;
            }
            case "request_detail": {
                json = interfaceController.queryOperate("com.cn.bean.plan.", "table", "DHPlanList", "DHPlanID",
                        datas, rely, true, DatabaseOpt.DATA, pageSize, pageIndex);
                break;
            }
            case "request_page": {
                json = interfaceController.queryOperate("com.cn.bean.plan.", "table", "DHPlan", "DHPlanID",
                        datas, rely, true, DatabaseOpt.DATA, pageSize, pageIndex);
                break;
            }
            case "submit": {
                int result = commonController.dataBaseOperate("[" + item + "]", "com.cn.bean.plan.", "DHPlan",
                        "add", DatabaseOpt.DATA).get(0);
                if (result == 0) {
                    result = commonController.dataBaseOperate(details, "com.cn.bean.plan.", "DHPlanList", "add",
                            DatabaseOpt.DATA).get(0);
                    if (result == 0) {
                        json = Units.objectToJson(0, "??!", null);
                    } else {
                        json = Units.objectToJson(-1, "!", null);
                        commonController.dataBaseOperate("[" + item + "]", "com.cn.bean.plan.", "DHPlan",
                                "delete", DatabaseOpt.DATA);
                    }
                } else {
                    json = Units.objectToJson(-1, "?!", null);
                }
                break;
            }
            }
            break;
        }
        //</editor-fold>

        //<editor-fold desc="?">
        case "?": {
            switch (operation) {
            case "create": {
                json = interfaceController.createOperate(20, "table", "com/cn/json/plan/", "com.cn.bean.plan.",
                        "SHPlan", "SHPlanID", DatabaseOpt.DATA);
                json = Units.insertStr(json, "\\\"???\\",
                        ",@SHJH_" + Units.getNowTimeNoSeparator());
                break;
            }
            case "request_table": {
                if (target.compareToIgnoreCase("dhPlanID") == 0) {
                    String[] keys = { "dhPlanID" };
                    String[] keysName = { "??" };
                    int[] keysWidth = { 100, 50 };
                    String[] fieldsName = { "dhPlanID" };
                    json = interfaceController.queryOperate(target, "com.cn.bean.plan.", "table", "DHPlan",
                            "DHPlanID", datas, rely, true, DatabaseOpt.DATA, pageSize, pageIndex, keys,
                            keysName, keysWidth, fieldsName);
                }
                if (target.compareToIgnoreCase("supplierID") == 0) {
                    String[] keys = { "supplierID", "supplierName" };
                    String[] keysName = { "?", "??" };
                    int[] keysWidth = { 50, 50 };
                    String[] fieldsName = { "customerID", "customerName" };
                    json = interfaceController.queryOperate(target, "com.cn.bean.", "table", "Customer",
                            "CustomerID", datas, rely, true, DatabaseOpt.DATA, pageSize, pageIndex, keys,
                            keysName, keysWidth, fieldsName);
                }
                if (target.compareToIgnoreCase("partCode") == 0) {
                    String[] keys = { "partCode", "partID", "partName", "partUnit", "cfAddress" };
                    String[] keysName = { "??", "??", "???", "???",
                            "?" };
                    int[] keysWidth = { 20, 20, 20, 20, 20 };
                    String[] fieldsName = { "partCode", "partID", "partName", "partUnit", "psAddress1" };
                    json = interfaceController.queryOperate(target, "com.cn.bean.", "table", "PartBaseInfo",
                            "PartCode", datas, rely, true, DatabaseOpt.DATA, pageSize, pageIndex, keys,
                            keysName, keysWidth, fieldsName);
                }
                break;
            }
            case "request_detail": {
                json = interfaceController.queryOperate("com.cn.bean.plan.", "table", "SHPlanList", "SHPlanID",
                        datas, rely, true, DatabaseOpt.DATA, pageSize, pageIndex);
                break;
            }
            case "request_page": {
                json = interfaceController.queryOperate("com.cn.bean.plan.", "table", "SHPlan", "SHPlanID",
                        datas, rely, true, DatabaseOpt.DATA, pageSize, pageIndex);
                break;
            }
            case "submit": {
                int result = commonController.dataBaseOperate("[" + item + "]", "com.cn.bean.plan.", "SHPlan",
                        "add", DatabaseOpt.DATA).get(0);
                if (result == 0) {
                    result = commonController.dataBaseOperate(details, "com.cn.bean.plan.", "SHPlanList", "add",
                            DatabaseOpt.DATA).get(0);
                    if (result == 0) {
                        json = Units.objectToJson(0, "??!", null);
                    } else {
                        json = Units.objectToJson(-1, "!", null);
                    }
                } else {
                    json = Units.objectToJson(-1, "?!", null);
                }
                break;
            }
            }
            break;
        }
        //</editor-fold>
        //</editor-fold>
        }

    } catch (Exception e) {
        logger.info(subUri);
        logger.error("?:" + e.getMessage(), e);
        json = Units.objectToJson(-1, "?!", e.toString());
    }
    //logger.info(Units.getIpAddress(request) + "response:" + subUri + ",time:" + (new Date().getTime()));

    PrintWriter out = response.getWriter();

    try {
        response.setContentType("text/html;charset=UTF-8");
        response.setHeader("Cache-Control", "no-store");
        response.setHeader("Pragma", "no-cache");
        response.setDateHeader("Expires", 0);
        out.print(json);
    } finally {
        if (out != null) {
            out.close();
        }
    }
}

From source file:com.core.util.wx.XmlUtils.java

License:Apache License

/**
 * xmlmap/*from ww w.ja  v a2s.  c  om*/
 * 
 * @param xml
 * @return
 */
@SuppressWarnings("rawtypes")
public static Map<String, String> xmlToMap(String xml) {
    Map<String, String> map = new HashMap<String, String>();
    Document doc = null;
    try {
        doc = DocumentHelper.parseText(xml);
    } catch (DocumentException e) {
        LOG.error(e.getMessage(), e);
    }
    if (null == doc)
        return map;
    Element root = doc.getRootElement();
    for (Iterator iterator = root.elementIterator(); iterator.hasNext();) {
        Element e = (Element) iterator.next();
        map.put(e.getName(), e.getText());
    }
    return map;
}

From source file:com.core.util.wx.XmlUtils.java

License:Apache License

/**
 * @param  ??xml/* ww w  .  java 2s.  c  om*/
 * @return
 * @throws UnsupportedEncodingException
 * @throws DocumentException
 * ???xml???
 */
public static Map<String, String> sfxmlToMap(String xml)
        throws UnsupportedEncodingException, DocumentException {
    LOG.info("xml:" + xml);
    Map<String, String> map = new HashMap<String, String>();
    Document doc = null;
    try {
        doc = DocumentHelper.parseText(xml);
    } catch (DocumentException e) {
        LOG.error(e.getMessage(), e);
    }
    if (null == doc)
        return map;
    Element root = doc.getRootElement();
    for (Iterator iterator = root.elementIterator(); iterator.hasNext();) {
        Element e = (Element) iterator.next();
        if (e.getName().equals("Head")) {
            if (e.getText().equals("ERR")) {
                return null;
            }
        }
        if (e.getName().equals("Body")) {
            Element e1 = e.element("OrderResponse");
            if (e1 != null) {
                if (e1.attribute("mailno") != null) {
                    map.put("mailno", e1.attribute("mailno").getText());
                }
                if (e1.attribute("destcode") != null) {
                    map.put("destcode", e1.attribute("destcode").getText());
                }
                if (e1.attribute("filter_result") != null) {
                    map.put("filter_result", e1.attribute("filter_result").getText());
                }
            }
            Element e2 = e.element("OrderZDResponse");
            if (e2 != null) {
                Element s = e2.element("OrderZDResponse");
                if (s.attribute("mailno_zd") != null) {
                    map.put("mailno_zd", s.attribute("mailno_zd").getText());
                }
            }
            break;
        }
    }
    return map;
}

From source file:com.creativity.controller.CepWebService.java

@SuppressWarnings("rawtypes")
public CepWebService(String cep) {

    try {/*from  w  w w.j  a  va  2 s .c  o m*/
        URL url = new URL("http://cep.republicavirtual.com.br/web_cep.php?cep=" + cep + "&formato=xml");

        Document document = getDocumento(url);

        Element root = document.getRootElement();

        for (Iterator i = root.elementIterator(); i.hasNext();) {
            Element element = (Element) i.next();

            if (element.getQualifiedName().equals("uf")) {
                setEstado(element.getText());
            }

            if (element.getQualifiedName().equals("cidade")) {
                setCidade(element.getText());
            }

            if (element.getQualifiedName().equals("bairro")) {
                setBairro(element.getText());
            }

            if (element.getQualifiedName().equals("tipo_logradouro")) {
                setTipoLogradouro(element.getText());
            }

            if (element.getQualifiedName().equals("logradouro")) {
                setLogradouro(element.getText());
            }

            if (element.getQualifiedName().equals("resultado")) {
                setResultado(Integer.parseInt(element.getText()));
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:com.ctvit.vdp.services.sysconfiguration.user.UserService.java

/**
 * ?????XML/*from w w w .ja  v a2  s.  com*/
 **/
public Map<String, String> getXML(Map xmlRightIds, Map thirdRightIds) throws DocumentException {
    String baseXML = systemConfigDao.selectByPrimaryKey("Rights").getValue();//??XML
    Document doc = DocumentHelper.parseText(baseXML);
    Document topDoc = DocumentHelper.createDocument();

    Element baseElement = doc.getRootElement();
    Element topEl = topDoc.addElement("Rights");//?XML
    List<Element> secMenuList = new ArrayList<Element>();
    String topIdFlag = "";

    Iterator elementIter = baseElement.elementIterator();
    while (elementIter.hasNext()) {//??
        Element element01 = (Element) elementIter.next();
        Iterator elementIter01 = element01.elementIterator();
        while (elementIter01.hasNext()) {//??
            Element element02 = (Element) elementIter01.next();
            Iterator elementIter02 = element02.elementIterator();
            String idFlag = "";
            if (xmlRightIds.get(element02.attributeValue("id")) != null) {//??ID?ID
                Element tempEl = element02.getParent();//?
                if (topEl.nodeCount() > 0 && !topIdFlag.equals(tempEl.attributeValue("id"))) {
                    topEl.addElement(tempEl.getName()).addAttribute("id", element01.attributeValue("id"))
                            .addAttribute("name", element01.attributeValue("name"));
                }
                if (topEl.nodeCount() == 0) {
                    topEl.addElement(tempEl.getName()).addAttribute("id", element01.attributeValue("id"))
                            .addAttribute("name", element01.attributeValue("name"));
                }
                topIdFlag = tempEl.attributeValue("id");
                secMenuList.add(element02);
            }
        }
    }

    StringBuffer secXML = new StringBuffer();
    secXML.append("<Rights>");
    Element tempTopEl = topEl.createCopy();
    //      System.out.println("tempTopEl: "+tempTopEl.asXML());
    Iterator secIt = tempTopEl.elementIterator();//????
    String flag = "";
    while (secIt.hasNext()) {
        Element op = (Element) secIt.next();
        for (Element eo : secMenuList) {//eo?? 
            if (eo.attributeValue("id").substring(0, 2).equals(op.attributeValue("id"))
                    && !flag.equals(eo.attributeValue("id"))) {
                flag = eo.attributeValue("id");
                Document secDoc = DocumentHelper.createDocument();
                Element secEle = secDoc.addElement("SecMenu");
                secEle.addAttribute("id", eo.attributeValue("id"));
                secEle.addAttribute("name", eo.attributeValue("name"));
                secEle.addAttribute("source", eo.attributeValue("source"));

                Iterator eoIter = eo.elementIterator();
                while (eoIter.hasNext()) {//??
                    Element thirdEl = (Element) eoIter.next();
                    if (thirdRightIds.get(thirdEl.attributeValue("id")) != null) {
                        Document document = DocumentHelper.createDocument();
                        Element tempEle = document.addElement("ThirdMenu");
                        tempEle.addAttribute("id", thirdEl.attributeValue("id"));
                        tempEle.addAttribute("name", thirdEl.attributeValue("name"));
                        tempEle.addAttribute("source", thirdEl.attributeValue("source"));
                        secEle.add(tempEle);//
                    }
                }
                op.add(secEle);//
            }
            //System.out.println("************ op: "+op.asXML());
        }
        secXML.append(op.asXML());
    }
    secXML.append("</Rights>");
    Map<String, String> xmlMap = new HashMap<String, String>();

    xmlMap.put("topMenu", topEl.asXML());
    xmlMap.put("treeMenu", secXML.toString());
    xmlMap.put("baseXML", baseElement.asXML());
    //      this.getElementList(baseElement,xmlRightIds);
    return xmlMap;
}