Example usage for org.dom4j.io SAXReader read

List of usage examples for org.dom4j.io SAXReader read

Introduction

In this page you can find the example usage for org.dom4j.io SAXReader read.

Prototype

public Document read(InputSource in) throws DocumentException 

Source Link

Document

Reads a Document from the given InputSource using SAX

Usage

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   w ww . j  a va2  s  .c  om*/
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;/*from w w  w  .  j  a  v a2  s. com*/
        try {
            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;// w ww  .j a  v  a2  s  .c  o m
        try {
            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;//from   ww  w .j a  v a2 s  .c o  m
        try {
            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.eurelis.opencms.workflows.workflows.A_OSWorkflowManager.java

License:Open Source License

/**
 * Get the OpenCMS RFS OSWorkflow configuration file and update it with the given filepath.
 * /*from ww  w  .java2  s.c o m*/
 * @param listOfWorkflowsFilepath
 *            the path of the file containing the list of available workflow descriptions
 * @return the path in RFS of the updated file
 * @throws DocumentException
 *             this exception is thrown if an error occurs during the parsing of the document
 * @throws IOException
 *             this exception is thrown if a problem occurs during overwriting of the config file
 */
private String updateOSWorkflowConfigFile(String listOfWorkflowsFilepath)
        throws CmsException, DocumentException, IOException {

    // get file path
    String configFilePath = this.getWebINFPath() + ModuleSharedVariables.SYSTEM_FILE_SEPARATOR
            + OSWORKFLOWCONFIGFILE_RFSFILEPATH;

    File listOfWorkflowsFile = new File(listOfWorkflowsFilepath);
    // Load Jdom parser
    SAXReader reader = new SAXReader();
    Document document = reader.read(configFilePath);
    Node propertyNode = document.selectSingleNode(OSWORKFLOWCONFIGFILE_PROPERTYTOUPDATE_XPATH);
    if (propertyNode != null) {
        if (propertyNode.getNodeType() == Node.ELEMENT_NODE) {
            // convert Node into element
            Element propertyElement = (Element) propertyNode;

            // update the Attribute
            Attribute valueAttribute = propertyElement
                    .attribute(OSWORKFLOWCONFIGFILE_PROPERTYTOUPDATE_ATTRIBUTNAME);

            valueAttribute.setValue(listOfWorkflowsFile.toURI().toString());

        } else {
            LOGGER.debug("the node with Xpath " + OSWORKFLOWCONFIGFILE_PROPERTYTOUPDATE_XPATH + " in the file "
                    + configFilePath + " doesn't correspond to an element");
        }

    } else {
        Node parentNode = document.selectSingleNode(OSWORKFLOWCONFIGFILE_PROPERTYTOUPDATE_PARENT_XPATH);
        if (parentNode != null) {

            if (parentNode.getNodeType() == Node.ELEMENT_NODE) {
                // convert Node into element
                Element parentElement = (Element) parentNode;

                // add new property
                Element propertyElement = parentElement.addElement("property");

                // add attributs
                propertyElement.addAttribute("key", "resource");
                propertyElement.addAttribute("value", listOfWorkflowsFile.toURI().toString());

            } else {
                LOGGER.debug("the node with Xpath " + OSWORKFLOWCONFIGFILE_PROPERTYTOUPDATE_XPATH
                        + " in the file " + configFilePath + " doesn't correspond to an element");
            }

        } else {
            LOGGER.debug("the node with Xpath " + OSWORKFLOWCONFIGFILE_PROPERTYTOUPDATE_PARENT_XPATH
                    + " in the file " + configFilePath + " has not been found.");
        }
    }

    /*
     * Get a string of the resulting file
     */

    // creating of a buffer that will collect result
    ByteArrayOutputStream xmlContent = new ByteArrayOutputStream();

    // Pretty print the document to xmlContent
    OutputFormat format = OutputFormat.createPrettyPrint();
    XMLWriter writer = new XMLWriter(xmlContent, format);
    writer.write(document);
    writer.flush();
    writer.close();

    // get the config file content as a String
    String documentContent = new String(xmlContent.toByteArray());

    /*
     * Overwrite the config file
     */
    FileWriter.writeFile(configFilePath, documentContent);

    return configFilePath;
}

From source file:com.eurelis.tools.xml.transformation.local.LocalDocumentSource.java

License:Open Source License

/**
 * Read a dom4j document from a File object.
 *
 * @param file the File object indicating the document position
 * @return the read document//from w  w w .  jav  a 2 s.c  om
 * @throws Exception any exception that might occurs while trying to convert the file to a dom4j document
 */
public static Document readDocument(File file) throws Exception {
    Document document = null;
    SAXReader saxReader = new SAXReader();

    InputStream ist = new FileInputStream(file);
    Charset charset = Charset.forName("UTF-8");
    Reader reader = new BufferedReader(new InputStreamReader(ist, charset));
    InputSource source = new InputSource(reader);

    document = saxReader.read(source);

    return document;
}

From source file:com.eurelis.tools.xml.transformation.opencms.OpenCmsDocumentSource.java

License:Open Source License

public OpenCmsDocumentSource(String documentPath, CmsObject cmsObject, boolean ignoreInitialValidation)
        throws CmsException, DocumentException, IOException {
    this.cmsObject = cmsObject;
    cmsFile = this.cmsObject.readFile(documentPath);
    cmsObject.lockResource(cmsFile);//from w ww.j  a v a 2s . c o  m

    this.documentPath = documentPath;

    byte[] documentBytes = cmsFile.getContents();

    SAXReader saxReader = new SAXReader();
    InputStream is = new ByteArrayInputStream(documentBytes);
    this.initialDocument = saxReader.read(is);
    this.ignoreInitialValidation = ignoreInitialValidation;

    is.close();

    cmsObject.unlockResource(cmsFile);

}

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 {//  w  ww.  ja  v a2 s  .  c o 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?????");
    }//ww w  .  j  a  v  a  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   ww w . jav  a2  s.  com
 *
 * @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;
}