Example usage for org.dom4j Element addComment

List of usage examples for org.dom4j Element addComment

Introduction

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

Prototype

Element addComment(String comment);

Source Link

Document

Adds a new Comment node with the given text to this element.

Usage

From source file:com.orange.atk.phone.android.wizard.AndroidWizard.java

License:Apache License

public void printReport() {
    String configXmlFileName = configFileName + ".xml";

    Document configxml = DocumentHelper.createDocument();

    configxml.addComment("  " + phone.getName() + " configuration file   ");
    configxml.addComment("   Screen resolution " + screenWidth + "x" + screenHeight + "   ");

    Element root = configxml.addElement("Android-config");

    Element canalPattern = root.addElement("CanalPattern");

    //keyboards//from   w w  w  .  j a v a  2  s . c o  m
    if (!keyboard.equals(""))
        printKeyMapping("keyboard", keyboard, canalPattern, root);
    if (!keyboard2.equals(""))
        printKeyMapping("keyboard2", keyboard2, canalPattern, root);
    if (!keyboard3.equals(""))
        printKeyMapping("keyboard3", keyboard3, canalPattern, root);

    Set<String> softKeySet = softKeyMap.keySet();

    Element keyMapping = root.addElement("SoftKeyMapping");
    for (String key : softKeySet) {
        keyMapping.addElement("Key").addAttribute("name", key)
                .addAttribute("avgX", "" + softKeyMap.get(key).getX())
                .addAttribute("avgY", "" + softKeyMap.get(key).getY());
    }

    //touchscreen
    if (!touchscreen.equals("")) {
        canalPattern.addElement("Pattern").addAttribute("canal", "touchscreen").addAttribute("value",
                touchscreen.replace("\"", ""));
        Element Touchscreen = root.addElement("Touchscreen");

        Touchscreen.addComment("!!! THIS IS JUST TOUCHSCREEN Elements TEMPLATE !!!");
        Touchscreen
                .addComment("!!! SEE ATK User Guide - Configuration section - and UPDATE following values !!!");
        if (codeX != -1 && codeY != -1) {
            Touchscreen.addComment("!!! Please check following X Y ratioX and ratioY patterns");
            Touchscreen.addElement("Pattern").addAttribute("name", "X").addAttribute("value",
                    "3 " + codeX + " ");
            Touchscreen.addElement("Pattern").addAttribute("name", "Y").addAttribute("value",
                    "3 " + codeY + " ");
            long ratio = maxX * 100 / screenWidth;
            Touchscreen.addElement("Pattern").addAttribute("name", "ratioX").addAttribute("value",
                    String.valueOf((double) ratio / 100.0));
            ratio = maxY * 100 / screenHeight;
            Touchscreen.addElement("Pattern").addAttribute("name", "ratioY").addAttribute("value",
                    String.valueOf((double) ratio / 100.0));
            Touchscreen.addComment("!!! Please update following patterns");
        } else {
            Touchscreen.addElement("Pattern").addAttribute("name", "X").addAttribute("value", "0 0 ");
            Touchscreen.addElement("Pattern").addAttribute("name", "Y").addAttribute("value", "0 0 ");
            Touchscreen.addElement("Pattern").addAttribute("name", "ratioX").addAttribute("value", "1.0");
            Touchscreen.addElement("Pattern").addAttribute("name", "ratioY").addAttribute("value", "1.0");
        }
        Touchscreen.addElement("Pattern").addAttribute("name", "down").addAttribute("value", "0 0 0");
        Touchscreen.addElement("Pattern").addAttribute("name", "downmax").addAttribute("value", "0 0 0");
        Touchscreen.addElement("Pattern").addAttribute("name", "up").addAttribute("value", "0 0 0");
        Touchscreen.addElement("Pattern").addAttribute("name", "flush").addAttribute("value", "0 0 0");
        Touchscreen.addElement("Pattern").addAttribute("name", "flush2").addAttribute("value", "0 2 0");
        Touchscreen.addElement("Threshold").addAttribute("name", "move").addAttribute("value", "15");
        Touchscreen.addElement("Option").addAttribute("name", "sendMouseDownForMove").addAttribute("value",
                "true");
        Touchscreen.addElement("Option").addAttribute("name", "sendMouseEventFirst").addAttribute("value",
                "true");
        Touchscreen.addElement("Option").addAttribute("name", "useMonkeyForPress").addAttribute("value",
                "true");
    }

    //Write the file.
    OutputFormat format = OutputFormat.createPrettyPrint();
    XMLWriter writer = null;
    try {
        writer = new XMLWriter(new FileWriter(configXmlFileName), format);
        writer.write(configxml);
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    //Show a confirm dialog and exit the wizard
    JOptionPane.showConfirmDialog(this,
            "A template of the config file has been created under \n" + configXmlFileName + "\n"
                    + "See ATK User guide to configure the Touchscreen section of this template\n",
            "Success", JOptionPane.CLOSED_OPTION);
    exit(true);

}

From source file:com.sap.data.db.dao.StructureUtil.java

public void addStructure(String entity, String structure)
        throws DocumentException, FileNotFoundException, SAXException, IOException, NotFoundException {
    synchronized (lockhu) {
        if (entity != null && !entity.trim().isEmpty()) {
            Document document = this.getDocument(PropertyUtil.getHbDtoXml());
            Element rootElement = document.getRootElement();
            rootElement.addAttribute("package", PropertyUtil.getHbPjPkgn());
            String comment = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
            rootElement.addComment(comment + " " + entity);
            this.addStructure(rootElement.addElement("class"), entity, structure);
            String classpath = StructureUtil.class.getResource("/").getPath() + PropertyUtil.getHbPjResource();
            this.save(document, classpath + entity + ".dto.xml");
        }//from  w w  w  .j a v a  2s  .c o  m
    }
}

From source file:com.stratumsoft.xmlgen.SchemaTypeXmlGenerator.java

License:Open Source License

/**
 * Handle the choice particle - Depending on the option {@link XmlGenOptions#getChoiceOptions()} set,
 * either the first child particle or a random particle within choice will be processed.
 * Other elements may be generated as comments if the option
 * {@link XmlGenOptions#isGenChoiceOptionsAsComments()} is set to do so
 *
 * @param choice//  ww  w .  j a  v  a  2s.com
 * @param dom4jEl
 */
private void handleParticleChoice(XmlSchemaChoice choice, Element dom4jEl) {
    if (choice != null) {

        List<XmlSchemaObject> choiceItems = choice.getItems();
        int count = choiceItems.size();
        if (count > 0) {
            XmlSchemaParticle childParticle;
            switch (options.getChoiceOptions()) {
            case FIRST:
                childParticle = (XmlSchemaParticle) choiceItems.get(0);
                break;
            case RANDOM:
                int i = new Random().nextInt(count);
                childParticle = (XmlSchemaParticle) choiceItems.get(i);
                break;
            default:
                childParticle = (XmlSchemaParticle) choiceItems.get(0);
                break;
            }

            long minOccurs = choice.getMinOccurs();
            long maxOccurs = choice.getMaxOccurs();
            logger.debug("Choice minOccurs = {} maxOccurs = {}", minOccurs, maxOccurs);

            long maxCount = getMaxElementsToGenerate(minOccurs, maxOccurs);
            logger.debug("Adding choice particle contents: {}  times", maxCount);

            for (int x = 0; x < maxCount; x++) {

                handleParticle(childParticle, dom4jEl);

                //generate other elements as comments?
                if (options.isGenChoiceOptionsAsComments()) {
                    logger.trace("Adding other elements in choice as comments");
                    for (XmlSchemaObject obj : choiceItems) {
                        if (obj != childParticle) { //already handled
                            //generating only if the other choice is an element!
                            if (obj instanceof XmlSchemaElement) {
                                Element optEl = handleElement((XmlSchemaElement) obj);
                                if (optEl != null) {
                                    logger.trace("Adding element: {} as comment to choice compositor",
                                            optEl.getName());

                                    String comment = optEl.asXML();
                                    comment = comment.replace("--", "- -"); // -- is invalid within a comment, so escape it
                                    dom4jEl.addComment(comment);
                                }
                            }
                        }
                    }

                }
            }

        }

    }
}

From source file:com.stratumsoft.xmlgen.SchemaTypeXmlGenerator.java

License:Open Source License

/**
 * Handle the 'any' particle - since any element can be present, this just adds a commented
 * element if the gen comments option is set
 *
 * @param any/*  w  ww .  java2  s .com*/
 * @param dom4jEl
 */
private void handleParticleAny(XmlSchemaAny any, Element dom4jEl) {
    if (any != null) {
        if (options.isGenCommentsForParticles()) {
            dom4jEl.addComment("Any element can be present here");

            Element el = factory.createElement("SomeElement");
            dom4jEl.addComment(el.asXML());
        }
    }
}

From source file:com.stratumsoft.xmlgen.SchemaTypeXmlGenerator.java

License:Open Source License

/**
 * Handle the 'sequence' particle - sequence can inturn contain XmlSchemaElement, XmlSchemaGroupRef, XmlSchemaChoice,
 * XmlSchemaSequence, or XmlSchemaAny./*ww  w  .  ja v a 2s. c o m*/
 *
 * @param seq
 * @param dom4jEl
 */
private void handleParticleSequence(XmlSchemaSequence seq, Element dom4jEl) {
    if (seq != null) {
        List<XmlSchemaSequenceMember> seqItems = seq.getItems();

        if (seqItems.size() > 0) {

            if (options.isGenCommentsForParticles()) {
                dom4jEl.addComment("sequence");
            }

            for (XmlSchemaSequenceMember seqMember : seqItems) {
                logger.trace("Processing sequence collection particle");

                if (seqMember instanceof XmlSchemaParticle) {

                    long min = seq.getMinOccurs();
                    long max = seq.getMaxOccurs();
                    logger.debug("sequence particle minOccurs = {}; maxOccurs = {}", min, max);

                    long maxCnt = getMaxElementsToGenerate(min, max);
                    logger.debug("handling sequence particles {} times", maxCnt);

                    for (int i = 0; i < maxCnt; i++) {
                        handleParticle((XmlSchemaParticle) seqMember, dom4jEl);
                    }

                } else {
                    logger.error("sequence collection particle is not an instanceof XmlSchemaParticle!");
                }
            }
        } else {
            logger.warn("sequence compositor is empty!");
        }
    }
}

From source file:com.stratumsoft.xmlgen.SchemaTypeXmlGenerator.java

License:Open Source License

/**
 * Handle the 'all' particle/* w  w w  .jav a 2s.c om*/
 *
 * @param all
 * @param dom4jEl
 */
private void handleParticleAll(XmlSchemaAll all, Element dom4jEl) {
    if (all != null) {
        List<XmlSchemaElement> allItems = all.getItems();

        if (options.isGenCommentsForParticles()) {
            //add a comment to indicate that this is an 'all' particle
            dom4jEl.addComment("following elements can appear in any order (all)");
        }

        logger.debug("Handling [{}] elements in 'all' particle", allItems.size());
        for (XmlSchemaElement schEl : allItems) {
            logger.trace("Processing element {}", schEl.getName());

            Element elem = handleElement(schEl);
            if (elem != null) {
                addElement(dom4jEl, elem, schEl);
            }
        }

    }
}

From source file:com.synesoft.fisp.app.common.utils.XmlFileUtil.java

License:Open Source License

/**
 * add comment for sub ele/*from  ww  w .j  a  v  a2s.  c  om*/
 * 
 * @param explain
 * @param element
 */
public static void addCommend(String explain, Element element) {
    element.addComment(explain);
}

From source file:com.taobao.datax.engine.tools.JobConfGenDriver.java

License:Open Source License

private static int genXmlFile(String filename, ClassNode reader, ClassNode writer) throws IOException {

    Document document = DocumentHelper.createDocument();
    Element jobsElement = document.addElement("jobs");
    Element jobElement = jobsElement.addElement("job");
    String id = reader.getName() + "_to_" + writer.getName() + "_job";
    jobElement.addAttribute("id", id);

    /**//from  w  w w  .j  a  v  a2s  .  c  om
     * ?readerxml
     */
    Element readerElement = jobElement.addElement("reader");
    Element plugin_Element = readerElement.addElement("plugin");
    plugin_Element.setText(reader.getName());

    ClassNode readerNode = reader;
    Element tempElement = null;

    List<ClassMember> members = readerNode.getAllMembers();
    for (ClassMember member : members) {
        StringBuilder command = new StringBuilder("\n");

        Set<String> set = member.getAllKeys();
        String value = "";
        for (String key : set) {
            value = member.getAttr("default");
            command.append(key).append(":").append(member.getAttr(key)).append("\n");
        }
        readerElement.addComment(command.toString());

        String keyName = member.getName();
        keyName = keyName.substring(1, keyName.length() - 1);
        tempElement = readerElement.addElement("param");
        tempElement.addAttribute("key", keyName);

        if (value == null || "".equals(value)) {
            value = "?";
        }
        tempElement.addAttribute("value", value);
    }

    /**
     * ?writerxml
     */
    Element writerElement = jobElement.addElement("writer");
    plugin_Element = writerElement.addElement("plugin");
    plugin_Element.setText(writer.getName());

    members = writer.getAllMembers();
    for (ClassMember member : members) {
        StringBuilder command = new StringBuilder("\n");
        Set<String> set = member.getAllKeys();

        String value = "";
        for (String key : set) {
            value = member.getAttr("default");
            command.append(key).append(":").append(member.getAttr(key)).append("\n");
        }
        writerElement.addComment(command.toString());

        String keyName = member.getName();
        keyName = keyName.substring(1, keyName.length() - 1);
        tempElement = writerElement.addElement("param");
        tempElement.addAttribute("key", keyName);

        if (value == null || "".equals(value)) {
            value = "?";
        }
        tempElement.addAttribute("value", value);
    }

    try {
        OutputFormat format = OutputFormat.createPrettyPrint();
        format.setEncoding("UTF-8");
        XMLWriter writerOfXML = new XMLWriter(new FileWriter(new File(filename)), format);
        writerOfXML.write(document);
        writerOfXML.close();
    } catch (Exception ex) {
        throw new IOException(ex.getCause());
    }

    return 0;
}

From source file:eu.planets_project.pp.plato.xml.ProjectExporter.java

License:Open Source License

public String exportTreeToFreemind(TreeNode treeRoot) {
    Document doc = DocumentHelper.createDocument();
    Element root = doc.addElement("map");
    Namespace xsi = new Namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");

    root.add(xsi);/*from w w  w.  j a v  a 2  s  .c  om*/
    root.addAttribute("version", "0.8.1");

    root.addComment(
            "To view this file, download free mind mapping software FreeMind from http://freemind.sourceforge.net");
    addSubTreeFreemind(root, treeRoot);

    String xml = doc.asXML();
    //PlatoLogger.getLogger(ProjectExporter.class).debug(arg0)
    return xml;
}

From source file:eu.scape_project.planning.criteria.bean.CriteriaHierarchyHelperBean.java

License:Apache License

/**
 * A function which exports all current criteria into a freemind xml string.
 * Used to ease creation of criteria-hierarchies (manual this is a hard
 * job)./*from   ww  w. j  a  v a 2  s  . c om*/
 * 
 * @return the criteria as XML string
 */
private String exportAllCriteriaToFreeMindXml() {
    Document doc = DocumentHelper.createDocument();
    doc.setXMLEncoding("UTF-8");

    Element root = doc.addElement("map");
    Namespace xsi = new Namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");

    root.add(xsi);
    root.addAttribute("version", "0.8.1");

    root.addComment(
            "To view this file, download free mind mapping software FreeMind from http://freemind.sourceforge.net");

    Element baseNode = root.addElement("node");
    baseNode.addAttribute("TEXT", "allCriteria");

    Collection<Measure> allCriteria = criteriaManager.getAllMeasures();
    ArrayList<Measure> allCriteriaSortable = new ArrayList<Measure>(allCriteria);
    Collections.sort(allCriteriaSortable);
    allCriteria = allCriteriaSortable;

    // each criterion should be added as simple node
    for (Measure measure : allCriteria) {
        // construct node text
        String nodeText = measure.getAttribute().getName() + "#" + measure.getName() + "|" + measure.getUri();

        // add node
        Element node = baseNode.addElement("node");
        node.addAttribute("TEXT", nodeText);
    }

    String xml = doc.asXML();
    return xml;
}