All Downloads are FREE. Search and download functionalities are using the official Maven repository.

live.document.mavenplugin.freemind.FreeMindExporter Maven / Gradle / Ivy

package live.document.mavenplugin.freemind;

import java.util.Arrays;
import java.util.List;

public class FreeMindExporter {
    public String toFreeMind(String plantUmlMindMap) {
        StringBuilder stringBuilder = new StringBuilder("\n" +
                "");

        List list = Arrays.asList(plantUmlMindMap.split(System.lineSeparator()));
        int previousLevel = 0;
        for (int i = 0; i < list.size(); i++) {
            if (! list.get(i).startsWith("*")) {
                continue;
            }

            int level = getLevel(list.get(i));
            if (previousLevel > 0) {
                for (int j = level; j <= previousLevel; j++) {
                    stringBuilder.append("").append(System.lineSeparator());
                }
            }

            String nodeText = getNodeText(list.get(i));
            String note = getNote(list.get(i));
            stringBuilder.append("").append(System.lineSeparator());
            if (note != null && note.trim().length() > 0) {
                stringBuilder.append(note);
            }


            previousLevel = level;
        }

        for (int j = 1; j <= previousLevel; j++) {
            stringBuilder.append("").append(System.lineSeparator());
        }

        return stringBuilder.toString() + "";
    }

    private String getNote(String line) {
        int i = line.indexOf("");
        int j = line.indexOf("");

        if (i >= 0 && j >= 0) {
            String template = "%s";
            String note = line.substring(i + "".length(), j);
            return String.format(template, escape(note));
        }

        return "";
    }

    private String escape(String nodeText) {
        return nodeText.replace("\\n", "
")
                .replace("<", "<")
                .replace(">", ">");
    }

    int getLevel(String line) {
        int i = line.indexOf(" ");

        return i;
    }

    String getNodeText(String line) {
        String result = removeNote(line);
        int i = line.indexOf(" ");
        int j = line.indexOf("]]");
        int kk = line.indexOf("* [[");
        if (kk >= 0 && j > 0) {
            result = result.substring(j + 2);
        } else if (i > 0) {
            result = result.substring(i + 1);
        }

        if (result.trim().endsWith(">>")) {
            int k = result.lastIndexOf("<<");
            result = result.substring(0, k);
        }

        return result.trim() + (line.indexOf("Link(") >= 0 ? " [Link]" : "");
    }

    private String removeNote(String s) {
        int i = s.indexOf("");
        int j = s.indexOf("");

        if (i >= 0 && j >= 0) {
            s = s.substring(0, i) + s.substring(j + "".length());
        }
        return s;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy