Search in sources :

Example 1 with Comment

use of org.dom4j.Comment in project atlas by alibaba.

the class ManifestFileUtils method removeComments.

/**
     * 移除xml中的注释
     *
     * @param document
     * @throws IOException
     * @throws DocumentException
     */
private static void removeComments(Document document) throws IOException, DocumentException {
    Visitor visitor = new VisitorSupport() {

        public void visit(Comment comment) {
            comment.setText(" ");
        }
    };
    document.accept(visitor);
}
Also used : Comment(org.dom4j.Comment) Visitor(org.dom4j.Visitor) VisitorSupport(org.dom4j.VisitorSupport)

Example 2 with Comment

use of org.dom4j.Comment in project cpsolver by UniTime.

the class GetInfo method getInfo.

public static void getInfo(File folder, List<Info> infos, String prefix) {
    File infoFile = new File(folder, "info.xml");
    if (infoFile.exists()) {
        System.out.println("Reading " + infoFile + " ...");
        try {
            Document document = (new SAXReader()).read(infoFile);
            HashMap<String, String> info = getInfo(document.getRootElement());
            if (info != null && !info.isEmpty()) {
                infos.add(new Info(prefix, info));
                return;
            }
        } catch (Exception e) {
            System.err.println("Error reading file " + infoFile + ", message: " + e.getMessage());
        }
    }
    File outputFile = new File(folder, "output.csv");
    if (outputFile.exists()) {
        System.out.println("Reading " + outputFile + " ...");
        try {
            HashMap<String, String> info = getInfo(outputFile);
            if (info != null && !info.isEmpty()) {
                infos.add(new Info(prefix, info));
                return;
            }
        } catch (Exception e) {
            System.err.println("Error reading file " + infoFile + ", message: " + e.getMessage());
        }
    }
    File solutionFile = new File(folder, "solution.xml");
    if (!solutionFile.exists())
        return;
    try {
        System.out.println("Reading " + solutionFile + " ...");
        Document document = (new SAXReader()).read(solutionFile);
        for (Iterator<?> i = document.nodeIterator(); i.hasNext(); ) {
            Node node = (Node) i.next();
            if (node instanceof Comment) {
                Comment comment = (Comment) node;
                if (comment.getText().indexOf("Solution Info:") >= 0) {
                    HashMap<String, String> info = getInfo(comment.getText());
                    if (info != null)
                        infos.add(new Info(prefix, info));
                }
            }
        }
    } catch (Exception e) {
        System.err.println("Error reading file " + solutionFile + ", message: " + e.getMessage());
    }
}
Also used : Comment(org.dom4j.Comment) SAXReader(org.dom4j.io.SAXReader) Node(org.dom4j.Node) Document(org.dom4j.Document) File(java.io.File) CSVFile(org.cpsolver.ifs.util.CSVFile)

Aggregations

Comment (org.dom4j.Comment)2 File (java.io.File)1 CSVFile (org.cpsolver.ifs.util.CSVFile)1 Document (org.dom4j.Document)1 Node (org.dom4j.Node)1 Visitor (org.dom4j.Visitor)1 VisitorSupport (org.dom4j.VisitorSupport)1 SAXReader (org.dom4j.io.SAXReader)1