Example usage for org.dom4j Document getRootElement

List of usage examples for org.dom4j Document getRootElement

Introduction

In this page you can find the example usage for org.dom4j Document getRootElement.

Prototype

Element getRootElement();

Source Link

Document

Returns the root Element for this document.

Usage

From source file:com.easyjf.web.config.BeanConfigReader.java

License:Apache License

public static List parseBeansFromDocument(Document doc) {
    List ret = new ArrayList();
    Element beans = XmlElementUtil.findElement("beans", doc.getRootElement());
    if (beans == null)
        return ret;
    List list = beans.elements();
    try {//from   w  w  w . j  a  v  a 2  s  .c  o  m
        if (list != null) {
            for (int i = 0; i < list.size(); i++) {
                Element e = (Element) list.get(i);
                BeanDefinitionImpl definition = new BeanDefinitionImpl();
                // ?
                definition.setBeanName(e.attributeValue("name"));
                Class clz = ClassUtils.forName(e.attributeValue("class"));
                definition.setBeanClass(clz);
                if (e.attributeValue("scope") != null)
                    definition.setScope(e.attributeValue("scope"));
                if (e.attributeValue("factory-method") != null)
                    definition.setFactoryMethod(e.attributeValue("factory-method"));
                // ???

                List ps = XmlElementUtil.findElements("property", e);
                MutablePropertyValues mpv = parsePropertyValues(ps);
                definition.setPropertyValues(mpv);
                // ????
                String autoInject = e.attributeValue("auto");// auto?
                if (autoInject == null)
                    autoInject = e.attributeValue("inject");
                handleAutoInject(definition, autoInject);// ?
                ps = XmlElementUtil.findElements("constructor-arg", e);
                ps = e.selectNodes("constructor-arg");
                definition.setConstructorArguments(parseConstructorArguments(ps));
                ret.add(definition);
            }
        }
    } catch (Exception e) {
        logger.error(I18n.getLocaleMessage("core.web.loading.Bean.configuration.information.error") + e);
        throw new com.easyjf.web.exception.FrameworkException(
                I18n.getLocaleMessage("core.web.loading.Bean.configuration.information.error"), e);
    }
    return ret;
}

From source file:com.edo.dolphin.service.impl.DolphinServiceImpl.java

@Override
public DolphinResult queryZrrKxHonest(Integer operatorID, String name, String idNumber, String mobile) {
    DolphinResult result = new DolphinResult();

    try {/*from  w  w w . jav a2s . co m*/
        String data = DolphinAPIUtil.execute(name, idNumber, mobile);

        Document document = DocumentHelper.parseText(data);
        Element root = document.getRootElement();
        result.setName(root.attributeValue("name"));
        result.setIdNumber(root.attributeValue("zjhm"));
        result.setSearchNo(root.attributeValue("cxbh"));

        Element resultElement = root.element("RESULT");
        result.setResult(resultElement.getText());

        if (!result.getResult().equals("1005")) {
            return result;
        }

        @SuppressWarnings("unchecked")
        List<Element> resourceList = root.elements("RESOURCE");
        for (Element element : resourceList) {
            String resources = element.attributeValue("RESOURCES");
            Resource resource = null;
            switch (resources) {
            case "GRZX130000005":
                // ??:GRZX130000005
                resource = new SocialResource();

                SocialResource socialResource = (SocialResource) resource;

                // ??:SHBXDJM
                socialResource.setRegisterCode(element.elementText("SHBXDJM"));
                // ????:DWMC
                socialResource.setCompanyName(element.elementText("DWMC"));
                // ??:JNSHBXJZTHZ
                socialResource.setSocialPayStatus(element.elementText("JNSHBXJZTHZ"));
                // ???:LQYLJZTHZ
                socialResource.setSocialGetStatus(element.elementText("LQYLJZTHZ"));
                // :JDWRQ
                socialResource.setSocialStartTime(element.elementText("JDWRQ"));
                // :ZXGXSJ
                socialResource.setSocialUpdateTime(element.elementText("ZXGXSJ"));

                processStaffData(socialResource, idNumber, operatorID);
                processStaffExpData(socialResource, idNumber, operatorID);
                break;
            case "XY0700050207030001":
                // ?:XY0700050207030001
                resource = new HouseFundResource();
                HouseFundResource houseFundResource = (HouseFundResource) resource;

                // ??:A3
                houseFundResource.setAccountStatus(element.elementText("A3"));
                // ????:A4
                houseFundResource.setAccountCompanyName(element.elementText("A4"));
                // :A5
                houseFundResource.setAccountCreateTime(element.elementText("A5"));

                break;
            case "GRZX100000007":
            case "GRZX100000008":
                // ?:GRZX100000007
                // ?:GRZX100000008
                resource = new MarryResource();
                resource.setResourceCode(resources);
                MarryResource marryResource = (MarryResource) resource;

                // :DJJG
                marryResource.setRegisterOrg(element.elementText("DJJG"));
                // :DJRQ
                marryResource.setRegisterDate(element.elementText("DJRQ"));
                // ??:ZSBH
                marryResource.setRegisterNumber(element.elementText("ZSBH"));
                // ????:POXM
                marryResource.setMateName(element.elementText("POXM"));

                processRegisterData(marryResource, idNumber, operatorID);
                break;
            case "GRZX080000032":
                // ??:GRZX080000032
                resource = new IllegalResource();
                IllegalResource illegalResource = (IllegalResource) resource;
                // ??
                illegalResource.setHasSwindling(element.elementText("SFYZPLAJWFJL"));
                // ??
                illegalResource.setHasTheft(element.elementText("SFYDQLAJWFJL"));
                // ??
                illegalResource.setHasTrick(element.elementText("SFYZYZPLAJWFJL"));
                // ?????
                illegalResource.setHasCounterfeit(element.elementText("SFYWZBZMMGWZJLAJWFJL"));
                break;
            case "GRZX080000040":
                // ?:GRZX080000040
                resource = new VehicleResource();
                VehicleResource vehicleResource = (VehicleResource) resource;

                // ??:HPZL
                vehicleResource.setLicenseType(element.elementText("HPZL"));
                // ???:HPHM
                vehicleResource.setLicenseNumber(element.elementText("HPHM"));
                // ?:CCDJRQ
                vehicleResource.setRegisterTime(element.elementText("CCDJRQ"));
                // :YXQZ
                vehicleResource.setInspectionValidityDate(element.elementText("YXQZ"));
                // :DJRQ
                vehicleResource.setInspectionDate(element.elementText("DJRQ"));
                // :QZBFQZ
                vehicleResource.setRetirementDate(element.elementText("QZBFQZ"));
                // ?:BXZZRQ
                vehicleResource.setRepairDate(element.elementText("BXZZRQ"));
                // ?:XZQH
                vehicleResource.setRegisterArea(element.elementText("XZQH"));
                // ?:ZTHZ
                vehicleResource.setStatus(element.elementText("ZTHZ"));
                // ?:DYBJHZ
                vehicleResource.setIsMortgage(element.elementText("DYBJHZ"));

                processVehicleData(vehicleResource, idNumber, operatorID);
                break;
            case "GRZX080000039":
            case "GRZX080000038":
                // ?:GRZX080000039
                // ?:GRZX080000038
                resource = new DriverResource();

                DriverResource driverResource = (DriverResource) resource;
                // ??WFMS
                driverResource.setIllegalType(element.elementText("WFMS"));
                // ?:JDSBH
                driverResource.setIllegalNumber(element.elementText("JDSBH"));
                // ?:WFSJ
                driverResource.setIllegalTime(element.elementText("WFSJ"));
                // ??:WFDZ
                driverResource.setIllegalAddress(element.elementText("WFDZ"));
                // ?:CLSJ
                driverResource.setIllegalProcessTime(element.elementText("CLSJ"));
                break;
            }

            if (resource != null) {

                // RESOURCES:??
                resource.setResourceCode(resources);

                // RESOURCENAME:???
                resource.setResourceName(element.attributeValue("RESOURCENAME"));
                // XXSSDWDM:????
                resource.setUnitCode(element.attributeValue("XXSSDWDM"));
                // XXSSDW:???
                resource.setUnitName(element.attributeValue("XXSSDW"));
                // XXLB:?
                resource.setCategory(element.attributeValue("XXLB"));

                result.getResources().add(resource);
            }
        }

    } catch (Exception e) {
        logger.fatal(e);
    }

    return result;
}

From source file:com.erpak.jtrackplanner3d.xml.LibraryReader.java

License:Open Source License

/**
 * create a new LibraryReader object with the library file name
 * @param fileName Name of the library file
 *//*from   ww  w.  j av  a2s .  c o  m*/
public LibraryReader(File libraryFile) {

    TrackSystem trackSystem = null;
    TracksTreeCellRenderer renderer = new TracksTreeCellRenderer();
    try {
        renderer.setStraigthTrackIcon(new ImageIcon(ResourcesManager.getResource("StraigthTrackIcon")));
        renderer.setCurvedTrackIcon(new ImageIcon(ResourcesManager.getResource("CurvedTrackIcon")));
        renderer.setStraightTurnoutTrackIcon(
                new ImageIcon(ResourcesManager.getResource("StraigthTurnoutTrackIcon")));
        renderer.setCrossingTrackIcon(new ImageIcon(ResourcesManager.getResource("CrossingTrackIcon")));
    } catch (Exception ex) {
        logger.error("Unable to load tree node icons");
        logger.error(ex.toString());
    }

    try {
        Element trackSystemInfoNode;
        Element element;
        Element subElement;
        Attribute attribute;
        Iterator iter;
        DefaultMutableTreeNode treeTop;
        DefaultMutableTreeNode treeCategory;
        DefaultMutableTreeNode treeElement;

        // Load the xml library file
        InputStream in = new FileInputStream(libraryFile);
        EntityResolver resolver = new EntityResolver() {
            public InputSource resolveEntity(String publicId, String systemId) {
                logger.debug("Public id : " + publicId);
                logger.debug("System Id : " + systemId);
                if (publicId.equals("-//TrackPlanner//DTD track_system V 1.0//EN")) {
                    InputStream in = getClass().getResourceAsStream("ressources/track_system.dtd");
                    return new InputSource(in);
                }
                return null;
            }
        };
        SAXReader reader = new SAXReader();
        reader.setEntityResolver(resolver);
        // Read the xml library file
        Document document = reader.read(in);
        Element root = document.getRootElement();
        logger.debug("Root name : " + root.getName());

        // Get "track_system_info" node
        trackSystemInfoNode = root.element("track_system_infos");
        // Get track_system_info_node attributes 
        trackSystem = new TrackSystem(trackSystemInfoNode.attribute("name").getValue(),
                trackSystemInfoNode.attribute("version").getValue());
        trackSystem.setScale(trackSystemInfoNode.attribute("scale").getValue());
        trackSystem.setManufacturer(trackSystemInfoNode.attribute("manufacturer").getValue());
        // Get the "track_system_caracteristics" node
        element = trackSystemInfoNode.element("track_system_caracteristics");
        trackSystem.setBallastWidth(Float.parseFloat(element.attribute("ballast_width").getValue()));
        trackSystem.setTrackWidth(Float.parseFloat(element.attribute("railway_width").getValue()));
        // Get the "track_system_colors" node
        element = trackSystemInfoNode.element("track_system_colors");
        for (iter = element.elementIterator(); iter.hasNext();) {
            subElement = (Element) iter.next();
            trackSystem.addColor(subElement.attribute("name").getValue(), subElement.attribute("r").getValue(),
                    subElement.attribute("g").getValue(), subElement.attribute("b").getValue());
        }

        // Set the top node of tree with tracksystem
        treeTop = new DefaultMutableTreeNode(trackSystem.getName());

        // iterate "straight_tracks" node
        element = root.element("straight_tracks");
        treeCategory = new DefaultMutableTreeNode(element.getName());
        treeTop.add(treeCategory);
        logger.debug("Node : " + element.getName());
        for (iter = element.elementIterator("straight_track"); iter.hasNext();) {
            subElement = (Element) iter.next();
            logger.debug("Adding reference : " + subElement.attribute("reference").getValue());
            treeElement = new DefaultMutableTreeNode(new StraightTrackSymbol(trackSystem,
                    subElement.attribute("reference").getValue(), subElement.attribute("reference").getValue(),
                    subElement.attribute("reference").getValue(),
                    Float.parseFloat(subElement.attribute("length").getValue()),
                    subElement.attribute("color").getValue()));
            treeCategory.add(treeElement);
        }

        // iterate "curved_tracks" node
        element = root.element("curved_tracks");
        treeCategory = new DefaultMutableTreeNode(element.getName());
        treeTop.add(treeCategory);
        logger.debug("Node : " + element.getName());
        for (iter = element.elementIterator("curved_track"); iter.hasNext();) {
            subElement = (Element) iter.next();
            logger.debug("Adding reference : " + subElement.attribute("reference").getValue());
            treeElement = new DefaultMutableTreeNode(new CurvedTrackSymbol(trackSystem,
                    subElement.attribute("reference").getValue(), subElement.attribute("reference").getValue(),
                    subElement.attribute("reference").getValue(),
                    Float.parseFloat(subElement.attribute("radius").getValue()),
                    Float.parseFloat(subElement.attribute("angle").getValue()),
                    subElement.attribute("color").getValue()));
            treeCategory.add(treeElement);
        }

        // iterate "straight_turnouts" node
        element = root.element("straight_turnouts");
        treeCategory = new DefaultMutableTreeNode(element.getName());
        treeTop.add(treeCategory);
        logger.debug("Node : " + element.getName());
        for (iter = element.elementIterator("straight_turnout"); iter.hasNext();) {
            subElement = (Element) iter.next();
            logger.debug("Adding reference : " + subElement.attribute("reference").getValue());
            treeElement = new DefaultMutableTreeNode(new StraightTurnoutSymbol(trackSystem,
                    subElement.attribute("reference").getValue(), subElement.attribute("reference").getValue(),
                    subElement.attribute("reference").getValue(),
                    Float.parseFloat(subElement.attribute("length").getValue()),
                    Float.parseFloat(subElement.attribute("radius").getValue()),
                    Float.parseFloat(subElement.attribute("angle").getValue()),
                    subElement.attribute("direction").getValue(), subElement.attribute("color").getValue()));
            treeCategory.add(treeElement);
        }

        // iterate through "curved_turnouts" node
        element = root.element("curved_turnouts");
        treeCategory = new DefaultMutableTreeNode(element.getName());
        treeTop.add(treeCategory);
        logger.debug("Node : " + element.getName());
        for (Iterator i = root.elementIterator("curved_turnouts"); i.hasNext();) {
            element = (Element) i.next();
            logger.debug("Node : " + element.getName());
        }

        // iterate through "three_way_turnouts" node
        element = root.element("three_way_turnouts");
        treeCategory = new DefaultMutableTreeNode(element.getName());
        treeTop.add(treeCategory);
        logger.debug("Node : " + element.getName());
        for (iter = element.elementIterator("symetric_three_way_turnout"); iter.hasNext();) {
            subElement = (Element) iter.next();
            logger.debug("Adding reference : " + subElement.attribute("reference").getValue());
            treeElement = new DefaultMutableTreeNode(new SymetricThreeWayTurnoutSymbol(trackSystem,
                    subElement.attribute("reference").getValue(), subElement.attribute("reference").getValue(),
                    subElement.attribute("reference").getValue(),
                    Float.parseFloat(subElement.attribute("length").getValue()),
                    Float.parseFloat(subElement.attribute("radius").getValue()),
                    Float.parseFloat(subElement.attribute("angle").getValue()),
                    subElement.attribute("color").getValue()));
            treeCategory.add(treeElement);
        }

        // iterate through "crossings" node
        element = root.element("crossings");
        treeCategory = new DefaultMutableTreeNode(element.getName());
        treeTop.add(treeCategory);
        logger.debug("Node : " + element.getName());
        for (Iterator i = root.elementIterator("crossings"); i.hasNext();) {
            element = (Element) i.next();
            logger.debug("Node : " + element.getName());
        }

        // iterate through "double_slip_switchs" node
        element = root.element("double_slip_switchs");
        treeCategory = new DefaultMutableTreeNode(element.getName());
        treeTop.add(treeCategory);
        logger.debug("Node : " + element.getName());
        for (Iterator i = root.elementIterator("double_slip_switchs"); i.hasNext();) {
            element = (Element) i.next();
            logger.debug("Node : " + element.getName());
        }

        // iterate through "special_tracks" node
        element = root.element("special_tracks");
        treeCategory = new DefaultMutableTreeNode(element.getName());
        treeTop.add(treeCategory);
        logger.debug("Node : " + element.getName());
        for (Iterator i = root.elementIterator("special_tracks"); i.hasNext();) {
            element = (Element) i.next();
            logger.debug("Node : " + element.getName());
        }

        // fill the tree
        tree = new JTree(treeTop);
    } catch (Exception ex) {
        logger.error("Unable to load track trackSystem library", ex);
        // Todo : Throws an exception and display an error box instaed of displaying atree with scrap data
        tree = new JTree();
    }

    logger.debug("Parsing done for trackSystem : " + trackSystem);
    tree.setName("Track systems");
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setCellRenderer(renderer);
}

From source file:com.eurelis.opencms.ant.task.ManifestBuilderTask.java

License:Open Source License

private void insertExplorerTypes(Element module) {
    if (null != explorertypes) {
        File xml = new File(explorertypes);
        SAXReader reader = new SAXReader();
        Document doc;
        try {/*from  w w w.ja va2 s. co  m*/
            doc = reader.read(xml);
            Element root = doc.getRootElement();
            module.add(root);
        } catch (DocumentException e) {
            module.addElement("explorertypes");
        }

    }
}

From source file:com.eurelis.opencms.ant.task.ManifestBuilderTask.java

License:Open Source License

private void insertResourceTypes(Element module) {
    if (null != resourcetypes) {
        File xml = new File(resourcetypes);
        SAXReader reader = new SAXReader();
        Document doc;
        try {/*from ww w.j a  va2  s  .  c  o  m*/
            doc = reader.read(xml);
            Element root = doc.getRootElement();
            module.add(root);
        } catch (DocumentException e) {
            module.addElement("resourcetypes");
        }
    }

}

From source file:com.eurelis.opencms.ant.task.ManifestBuilderTask.java

License:Open Source License

private void addAccessesToTree(Element root, String propFilePath) {
    if (null != propFilePath) {
        File xml = new File(propFilePath);
        SAXReader reader = new SAXReader();
        Document doc;
        try {//  w w w.j av  a2 s.  c  o m
            doc = reader.read(xml);
            Element elem = doc.getRootElement();
            if (null != elem)
                root.add(elem);
            else
                root.addElement("accesscontrol");
        } catch (DocumentException e) {
            root.addElement("accesscontrol");
        }
    }
}

From source file:com.ewcms.content.particular.util.XmlConvert.java

License:Open Source License

@SuppressWarnings("unchecked")
public static List<Map<String, Object>> importXML(File xmlFile, String fileType) {
    if (xmlFile != null) {
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        try {//from w  w w.jav  a 2 s  .co m
            List<InputStream> inputStreams = new ArrayList<InputStream>();
            //FileType fileType = FileTypeJudge.getType(xmlFile);
            if (fileType.toLowerCase().equals("application/zip")) {
                inputStreams = parseXmlZIPFile(xmlFile);
            } else if (fileType.toLowerCase().equals("text/xml")) {
                InputStream in = new FileInputStream(xmlFile);
                inputStreams.add(in);
            } else {
                return null;
            }
            if (!inputStreams.isEmpty()) {
                SAXReader reader = new SAXReader();
                Document doc = null;
                for (InputStream inputStream : inputStreams) {
                    try {
                        doc = reader.read(inputStream);
                        if (doc != null) {
                            Element root = doc.getRootElement();
                            Element metaViewData;
                            Element projecties;
                            for (Iterator<?> metaViewDataIterator = root
                                    .elementIterator("MetaViewData"); metaViewDataIterator.hasNext();) {
                                metaViewData = (Element) metaViewDataIterator.next();
                                for (Iterator<?> projectiesIterator = metaViewData
                                        .elementIterator("PROPERTIES"); projectiesIterator.hasNext();) {
                                    projecties = (Element) projectiesIterator.next();
                                    List<Element> elements = projecties.elements();
                                    if (!elements.isEmpty()) {
                                        Map<String, Object> map = new HashMap<String, Object>();
                                        for (Element element : elements) {
                                            map.put(element.getName(), element.getData());
                                        }
                                        list.add(map);
                                    }
                                }
                            }
                        }
                    } catch (DocumentException e) {
                    } finally {
                        if (doc != null) {
                            doc.clearContent();
                            doc = null;
                        }
                    }
                }
            }
        } catch (IOException e) {
            return null;
        }
        return list;
    }
    return null;
}

From source file:com.faithbj.shop.action.admin.InstallAction.java

public String save() throws URISyntaxException, IOException, DocumentException {
    if (isInstalled()) {
        return ajaxJsonErrorMessage("CAIJINGLING?????");
    }//from  w  w  w .j ava 2 s . c  o  m
    if (StringUtils.isEmpty(databaseHost)) {
        return ajaxJsonErrorMessage("?!");
    }
    if (StringUtils.isEmpty(databasePort)) {
        return ajaxJsonErrorMessage("??!");
    }
    if (StringUtils.isEmpty(databaseUsername)) {
        return ajaxJsonErrorMessage("???!");
    }
    if (StringUtils.isEmpty(databasePassword)) {
        return ajaxJsonErrorMessage("??!");
    }
    if (StringUtils.isEmpty(databaseName)) {
        return ajaxJsonErrorMessage("???!");
    }
    if (StringUtils.isEmpty(adminUsername)) {
        return ajaxJsonErrorMessage("???!");
    }
    if (StringUtils.isEmpty(adminPassword)) {
        return ajaxJsonErrorMessage("??!");
    }
    if (StringUtils.isEmpty(installStatus)) {
        Map<String, String> jsonMap = new HashMap<String, String>();
        jsonMap.put(STATUS, "requiredCheckFinish");
        return ajaxJson(jsonMap);
    }

    String jdbcUrl = "jdbc:mysql://" + databaseHost + ":" + databasePort + "/" + databaseName
            + "?useUnicode=true&characterEncoding=UTF-8";
    Connection connection = null;
    PreparedStatement preparedStatement = null;
    ResultSet resultSet = null;
    try {
        // ?
        connection = DriverManager.getConnection(jdbcUrl, databaseUsername, databasePassword);
        DatabaseMetaData databaseMetaData = connection.getMetaData();
        String[] types = { "TABLE" };
        resultSet = databaseMetaData.getTables(null, databaseName, "%", types);
        if (StringUtils.equalsIgnoreCase(installStatus, "databaseCheck")) {
            Map<String, String> jsonMap = new HashMap<String, String>();
            jsonMap.put(STATUS, "databaseCheckFinish");
            return ajaxJson(jsonMap);
        }

        // ?
        if (StringUtils.equalsIgnoreCase(installStatus, "databaseCreate")) {
            StringBuffer stringBuffer = new StringBuffer();
            BufferedReader bufferedReader = null;
            String sqlFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI()
                    .getPath() + SQL_INSTALL_FILE_NAME;
            bufferedReader = new BufferedReader(
                    new InputStreamReader(new FileInputStream(sqlFilePath), "UTF-8"));
            String line = "";
            while (null != line) {
                line = bufferedReader.readLine();
                stringBuffer.append(line);
                if (null != line && line.endsWith(";")) {
                    System.out.println("[CAIJINGLING?]SQL: " + line);
                    preparedStatement = connection.prepareStatement(stringBuffer.toString());
                    preparedStatement.executeUpdate();
                    stringBuffer = new StringBuffer();
                }
            }
            String insertAdminSql = "INSERT INTO `admin` VALUES ('402881862bec2a21012bec2bd8de0003','2010-10-10 0:0:0','2010-10-10 0:0:0','','admin@shopxx.net',b'1',b'0',b'0',b'0',NULL,NULL,0,NULL,'?','"
                    + DigestUtils.md5Hex(adminPassword) + "','" + adminUsername + "');";
            String insertAdminRoleSql = "INSERT INTO `admin_role` VALUES ('402881862bec2a21012bec2bd8de0003','402881862bec2a21012bec2b70510002');";
            preparedStatement = connection.prepareStatement(insertAdminSql);
            preparedStatement.executeUpdate();
            preparedStatement = connection.prepareStatement(insertAdminRoleSql);
            preparedStatement.executeUpdate();
        }
    } catch (SQLException e) {
        e.printStackTrace();
        return ajaxJsonErrorMessage("???!");
    } finally {
        try {
            if (resultSet != null) {
                resultSet.close();
                resultSet = null;
            }
            if (preparedStatement != null) {
                preparedStatement.close();
                preparedStatement = null;
            }
            if (connection != null) {
                connection.close();
                connection = null;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    // ???
    String configFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI().getPath()
            + JDBC_CONFIG_FILE_NAME;
    Properties properties = new Properties();
    properties.put("jdbc.driver", "com.mysql.jdbc.Driver");
    properties.put("jdbc.url", jdbcUrl);
    properties.put("jdbc.username", databaseUsername);
    properties.put("jdbc.password", databasePassword);
    properties.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
    properties.put("hibernate.show_sql", "false");
    properties.put("hibernate.format_sql", "false");
    OutputStream outputStream = new FileOutputStream(configFilePath);
    properties.store(outputStream, JDBC_CONFIG_FILE_DESCRIPTION);
    outputStream.close();

    // ??
    String backupWebConfigFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI()
            .getPath() + BACKUP_WEB_CONFIG_FILE_NAME;
    String backupApplicationContextConfigFilePath = Thread.currentThread().getContextClassLoader()
            .getResource("").toURI().getPath() + BACKUP_APPLICATION_CONTEXT_CONFIG_FILE_NAME;
    String backupCompassApplicationContextConfigFilePath = Thread.currentThread().getContextClassLoader()
            .getResource("").toURI().getPath() + BACKUP_COMPASS_APPLICATION_CONTEXT_CONFIG_FILE_NAME;
    String backupSecurityApplicationContextConfigFilePath = Thread.currentThread().getContextClassLoader()
            .getResource("").toURI().getPath() + BACKUP_SECURITY_APPLICATION_CONTEXT_CONFIG_FILE_NAME;

    String webConfigFilePath = new File(
            Thread.currentThread().getContextClassLoader().getResource("").toURI().getPath()).getParent() + "/"
            + WEB_CONFIG_FILE_NAME;
    String applicationContextConfigFilePath = Thread.currentThread().getContextClassLoader().getResource("")
            .toURI().getPath() + APPLICATION_CONTEXT_CONFIG_FILE_NAME;
    String compassApplicationContextConfigFilePath = Thread.currentThread().getContextClassLoader()
            .getResource("").toURI().getPath() + COMPASS_APPLICATION_CONTEXT_CONFIG_FILE_NAME;
    String securityApplicationContextConfigFilePath = Thread.currentThread().getContextClassLoader()
            .getResource("").toURI().getPath() + SECURITY_APPLICATION_CONTEXT_CONFIG_FILE_NAME;

    FileUtils.copyFile(new File(backupWebConfigFilePath), new File(webConfigFilePath));
    FileUtils.copyFile(new File(backupApplicationContextConfigFilePath),
            new File(applicationContextConfigFilePath));
    FileUtils.copyFile(new File(backupCompassApplicationContextConfigFilePath),
            new File(compassApplicationContextConfigFilePath));
    FileUtils.copyFile(new File(backupSecurityApplicationContextConfigFilePath),
            new File(securityApplicationContextConfigFilePath));

    // ??
    String systemConfigFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI()
            .getPath() + SystemConfigUtil.CONFIG_FILE_NAME;
    File systemConfigFile = new File(systemConfigFilePath);
    SAXReader saxReader = new SAXReader();
    Document document = saxReader.read(systemConfigFile);
    Element rootElement = document.getRootElement();
    Element systemConfigElement = rootElement.element("systemConfig");
    Node isInstalledNode = document.selectSingleNode("/shopxx/systemConfig/isInstalled");
    if (isInstalledNode == null) {
        isInstalledNode = systemConfigElement.addElement("isInstalled");
    }
    isInstalledNode.setText("true");
    try {
        OutputFormat outputFormat = OutputFormat.createPrettyPrint();// XML?
        outputFormat.setEncoding("UTF-8");// XML?
        outputFormat.setIndent(true);// ?
        outputFormat.setIndent("   ");// TAB?
        outputFormat.setNewlines(true);// ??
        XMLWriter xmlWriter = new XMLWriter(new FileOutputStream(systemConfigFile), outputFormat);
        xmlWriter.write(document);
        xmlWriter.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return ajaxJsonSuccessMessage("CAIJINGLING?????");
}

From source file:com.feilong.framework.netpay.advance.adaptor.alipay.AlipayAdvanceAdaptor.java

License:Apache License

/**
 * ??xml?.//from  w  w  w  .  jav  a2  s .c om
 *
 * @author xialong
 * @param alipayResult
 *            the alipay result
 * @return the map
 * @throws DocumentException
 *             the document exception
 */
private static Map<String, String> convertResultToMap(String alipayResult) throws DocumentException {
    log.info("alipayResult :\n {}", alipayResult);

    Map<String, String> map = new HashMap<String, String>();
    SAXReader reader = new SAXReader();
    Document document = reader.read(new InputSource(new StringReader(alipayResult)));
    Element root = document.getRootElement();

    String is_success = root.elementText("is_success");
    String error = root.elementText("error");
    log.info("is_success : {}", is_success);
    log.info("error : {}", error);

    map.put("is_success", is_success);
    map.put("error", error);

    return map;
}

From source file:com.feilong.framework.netpay.payment.adaptor.alipay.wap.AlipayWapAdaptor.java

License:Apache License

/**
 * ?keyxml.//from ww w.ja  v  a  2 s .  co m
 * 
 * @param xmlData
 *            the xml data
 * @param name
 *            the name
 * @return String
 * @throws DocumentException
 *             the document exception
 * @author 
 * @time 2013-9-16?10:16:39
 */
private String getValueByKeyForXML(String xmlData, String name) throws DocumentException {
    SAXReader reader = new SAXReader();
    Document document = reader.read(new InputSource(new StringReader(xmlData)));
    Element root = document.getRootElement();
    String value = root.elementText(name);
    return value;
}