Example usage for org.dom4j Element addText

List of usage examples for org.dom4j Element addText

Introduction

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

Prototype

Element addText(String text);

Source Link

Document

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

Usage

From source file:org.hibernate.eclipse.launch.CodeGenXMLFactory.java

License:Open Source License

@SuppressWarnings("unchecked")
protected Element createRoot() {
    ExporterAttributes attributes = null;
    try {/*from  w  ww  .  ja v a  2s.c om*/
        attributes = new ExporterAttributes(lc);
    } catch (CoreException e) {
        // ignore
    }
    if (attributes == null) {
        return null;
    }
    Properties props = new Properties();
    if (attributes.isReverseEngineer()) {
        props.setProperty(ConfigurationXMLStrings.ISREVENG, Boolean.toString(attributes.isReverseEngineer()));
        props.setProperty(ConfigurationXMLStrings.PACKAGENAME, attributes.getPackageName());
        props.setProperty(ConfigurationXMLStrings.PREFERBASICCOMPOSITEIDS,
                Boolean.toString(attributes.isPreferBasicCompositeIds()));
        props.setProperty(ConfigurationXMLStrings.DETECTMANYTOMANY,
                Boolean.toString(attributes.detectManyToMany()));
        props.setProperty(ConfigurationXMLStrings.DETECTONTTOONE,
                Boolean.toString(attributes.detectOneToOne()));
        props.setProperty(ConfigurationXMLStrings.DETECTOPTIMISTICLOCK,
                Boolean.toString(attributes.detectOptimisticLock()));
        props.setProperty(ConfigurationXMLStrings.REVERSESTRATEGY, attributes.getRevengStrategy());
        String revEngFile = getResLocation(attributes.getRevengSettings());
        props.setProperty(ConfigurationXMLStrings.REVENGFILE, revEngFile);
    }
    //
    final IPath pathPlace2Generate = isEmpty(place2Generate) ? null : new Path(getResLocation(place2Generate));
    final IPath pathWorkspacePath = isEmpty(workspacePath) ? null : new Path(getResLocation(workspacePath));
    //
    String consoleConfigName = attributes.getConsoleConfigurationName();
    ConsoleConfigurationPreferences consoleConfigPrefs = getConsoleConfigPreferences(consoleConfigName);
    final ConfigurationXMLFactory configurationXMLFactory = new ConfigurationXMLFactory(consoleConfigPrefs,
            props);
    configurationXMLFactory.setPlace2Generate(pathPlace2Generate);
    configurationXMLFactory.setWorkspacePath(pathWorkspacePath);
    Element rootConsoleConfig = configurationXMLFactory.createRoot();
    //
    String defaultTargetName = "hibernateAntCodeGeneration"; //$NON-NLS-1$
    Element el, root = DocumentFactory.getInstance().createElement(CodeGenerationStrings.PROJECT);
    root.addAttribute(CodeGenerationStrings.NAME, "CodeGen"); //$NON-NLS-1$
    root.addAttribute(CodeGenerationStrings.DEFAULT, defaultTargetName);
    //
    if (!isEmpty(place2Generate)) {
        el = root.addElement(CodeGenerationStrings.PROPERTY);
        el.addAttribute(CodeGenerationStrings.NAME, varCurrentDir);
        el.addAttribute(CodeGenerationStrings.LOCATION, getPlace2GenerateUID());
    }
    if (!isEmpty(workspacePath)) {
        el = root.addElement(CodeGenerationStrings.PROPERTY);
        el.addAttribute(CodeGenerationStrings.NAME, varWorkspaceDir);
        el.addAttribute(CodeGenerationStrings.LOCATION, getWorkspacePathUID());
    }
    //
    String location = getResLocation(attributes.getOutputPath());
    location = ConfigurationXMLFactory.makePathRelative(location, pathPlace2Generate, pathWorkspacePath);
    el = root.addElement(CodeGenerationStrings.PROPERTY);
    el.addAttribute(CodeGenerationStrings.NAME, varBuildDir);
    el.addAttribute(CodeGenerationStrings.LOCATION, location);
    //
    String hibernatePropFile = null;
    String generateHibernatePropeties = null;
    String connProfileName = consoleConfigPrefs == null ? null : consoleConfigPrefs.getConnectionProfileName();
    IConnectionProfile profile = getConnectionProfile(connProfileName);
    boolean bPropFile = profile != null;
    // update property with fake tm
    Properties propsTmp = null;
    String hibernateVersion = consoleConfigPrefs == null ? "3.5" : consoleConfigPrefs.getHibernateVersion();
    IService service = ServiceLookup.findService(hibernateVersion);
    IEnvironment environment = service.getEnvironment();
    if (consoleConfigPrefs != null && consoleConfigPrefs.getPropertyFile() != null) {
        propsTmp = consoleConfigPrefs.getProperties();
        String tmStrategy = propsTmp.getProperty(environment.getTransactionManagerStrategy());
        if (tmStrategy != null && StringHelper.isEmpty(tmStrategy)) {
            propsTmp.setProperty(environment.getTransactionManagerStrategy(),
                    ConfigurationFactory.FAKE_TM_LOOKUP);
            bPropFile = true;
        }
    }
    if (bPropFile) {
        Set<String> specialProps = new TreeSet<String>();
        specialProps.add(environment.getDriver());
        specialProps.add(environment.getURL());
        specialProps.add(environment.getUser());
        specialProps.add(environment.getPass());
        specialProps.add(environment.getDialect());
        //
        if (propsTmp == null) {
            propsTmp = new Properties();
        }
        StringBuilder propFileContent = new StringBuilder();
        String driverClass = getDriverClass(connProfileName);
        if (profile != null) {
            final Properties cpProperties = profile.getProperties(profile.getProviderId());
            //
            String url = cpProperties.getProperty(IJDBCDriverDefinitionConstants.URL_PROP_ID);
            //
            String user = cpProperties.getProperty(IJDBCDriverDefinitionConstants.USERNAME_PROP_ID);
            //
            String pass = cpProperties.getProperty(IJDBCDriverDefinitionConstants.PASSWORD_PROP_ID);
            //
            String dialectName = consoleConfigPrefs.getDialectName();
            //
            propsTmp.setProperty(environment.getDriver(), driverClass);
            propsTmp.setProperty(environment.getURL(), url);
            propsTmp.setProperty(environment.getUser(), user);
            propsTmp.setProperty(environment.getPass(), pass);
            if (StringHelper.isNotEmpty(dialectName)) {
                propsTmp.setProperty(environment.getDialect(), dialectName);
            }
        }
        // output keys in sort order
        Object[] keys = propsTmp.keySet().toArray();
        Arrays.sort(keys);
        //
        if (externalPropFile) {
            for (Object obj : keys) {
                addIntoPropFileContent(propFileContent, obj.toString(), propsTmp.getProperty(obj.toString()));
            }
        } else {
            for (Object obj : keys) {
                if (specialProps.contains(obj)) {
                    el = root.addElement(CodeGenerationStrings.PROPERTY);
                    el.addAttribute(CodeGenerationStrings.NAME, obj.toString());
                    el.addAttribute(CodeGenerationStrings.VALUE, propsTmp.getProperty(obj.toString()));
                    addIntoPropFileContent(propFileContent, obj.toString());
                } else {
                    addIntoPropFileContent(propFileContent, obj.toString(),
                            propsTmp.getProperty(obj.toString()));
                }
            }
        }
        if (externalPropFile) {
            hibernatePropFile = externalPropFileName;
        } else {
            hibernatePropFile = "hibernatePropFile"; //$NON-NLS-1$
            el = root.addElement(CodeGenerationStrings.PROPERTY);
            el.addAttribute(CodeGenerationStrings.NAME, hibernatePropFile);
            el.addAttribute(CodeGenerationStrings.VALUE,
                    "${java.io.tmpdir}${ant.project.name}-hibernate.properties"); //$NON-NLS-1$
            //
            generateHibernatePropeties = "generateHibernatePropeties"; //$NON-NLS-1$
            Element target = root.addElement(CodeGenerationStrings.TARGET);
            target.addAttribute(CodeGenerationStrings.NAME, generateHibernatePropeties);
            //
            hibernatePropFile = getVar(hibernatePropFile);
            Element echo = target.addElement(CodeGenerationStrings.ECHO);
            echo.addAttribute(CodeGenerationStrings.FILE, hibernatePropFile);
            echo.addText(getPropFileContentStubUID());
        }
        propFileContentPreSave = propFileContent.toString().trim();
    }
    // all jars from libraries should be here
    String toolslibID = "toolslib"; //$NON-NLS-1$
    Element toolslib = root.addElement(CodeGenerationStrings.PATH);
    toolslib.addAttribute(CodeGenerationStrings.ID, toolslibID);
    final URL[] customClassPathURLs = PreferencesClassPathUtils.getCustomClassPathURLs(consoleConfigPrefs);
    for (int i = 0; i < customClassPathURLs.length; i++) {
        if (customClassPathURLs[i] == null) {
            continue;
        }
        // what is right here: CodeGenerationStrings.PATH or CodeGenerationStrings.PATHELEMENT?
        // http://www.redhat.com/docs/en-US/JBoss_Developer_Studio/en/hibernatetools/html/ant.html
        // use CodeGenerationStrings.PATH - so may be error in documentation?
        Element pathItem = toolslib.addElement(CodeGenerationStrings.PATH);
        //Element pathItem = toolslib.addElement(CodeGenerationStrings.PATHELEMENT);
        String strPathItem = customClassPathURLs[i].getPath();
        try {
            strPathItem = (new java.io.File(customClassPathURLs[i].toURI())).getPath();
        } catch (URISyntaxException e) {
            // ignore
        }
        strPathItem = new Path(strPathItem).toString();
        strPathItem = ConfigurationXMLFactory.makePathRelative(strPathItem, pathPlace2Generate,
                pathWorkspacePath);
        pathItem.addAttribute(CodeGenerationStrings.LOCATION, strPathItem);
    }
    //
    Element target = root.addElement(CodeGenerationStrings.TARGET);
    target.addAttribute(CodeGenerationStrings.NAME, defaultTargetName);
    if (!isEmpty(generateHibernatePropeties)) {
        target.addAttribute(CodeGenerationStrings.DEPENDS, generateHibernatePropeties);
    }
    //
    Element taskdef = target.addElement(CodeGenerationStrings.TASKDEF);
    taskdef.addAttribute(CodeGenerationStrings.NAME, CodeGenerationStrings.HIBERNATETOOL);
    taskdef.addAttribute(CodeGenerationStrings.CLASSNAME, "org.hibernate.tool.ant.HibernateToolTask"); //$NON-NLS-1$
    taskdef.addAttribute(CodeGenerationStrings.CLASSPATHREF, toolslibID);
    //
    Element hibernatetool = target.addElement(CodeGenerationStrings.HIBERNATETOOL);
    hibernatetool.addAttribute(CodeGenerationStrings.DESTDIR, getVar(varBuildDir));
    if (attributes.isUseOwnTemplates()) {
        String templatePath = getResLocation(attributes.getTemplatePath());
        hibernatetool.addAttribute(CodeGenerationStrings.TEMPLATEPATH, templatePath);
    }
    if (rootConsoleConfig != null) {
        if (StringHelper.isNotEmpty(hibernatePropFile)) {
            rootConsoleConfig.addAttribute(ConfigurationXMLStrings.PROPERTYFILE, hibernatePropFile);
        }
        // add hibernate console configuration
        hibernatetool.content().add(rootConsoleConfig);
    }
    //
    // the path there are user classes
    Element classpath = hibernatetool.addElement(CodeGenerationStrings.CLASSPATH);
    Element path = classpath.addElement(CodeGenerationStrings.PATH);
    path.addAttribute(CodeGenerationStrings.LOCATION, getVar(varBuildDir));
    //
    Map<String, Map<String, AttributeDescription>> exportersDescr = ExportersXMLAttributeDescription
            .getExportersDescription();
    Map<String, Set<String>> exportersSetSubTags = ExportersXMLAttributeDescription.getExportersSetSubTags();
    //
    Properties globalProps = new Properties();
    // obligatory global properties
    globalProps.put(CodeGenerationStrings.EJB3, "" + attributes.isEJB3Enabled()); //$NON-NLS-1$
    globalProps.put(CodeGenerationStrings.JDK5, "" + attributes.isJDK5Enabled()); //$NON-NLS-1$
    List<ExporterFactory> exporterFactories = attributes.getExporterFactories();
    for (Iterator<ExporterFactory> iter = exporterFactories.iterator(); iter.hasNext();) {
        ExporterFactory ef = iter.next();
        if (!ef.isEnabled(lc)) {
            continue;
        }
        //Map<String, ExporterProperty> defExpProps = ef.getDefaultExporterProperties();
        //String expId = ef.getId();
        String expDefId = ef.getExporterDefinitionId();
        String expName = ef.getExporterTag();
        // mapping: guiName -> AttributeDescription
        Map<String, AttributeDescription> attributesDescrGui = exportersDescr.get(expName);
        if (attributesDescrGui == null) {
            attributesDescrGui = new TreeMap<String, AttributeDescription>();
        }
        // mapping: guiName -> set of sub tags
        Set<String> setSubTags = exportersSetSubTags.get(expName);
        if (setSubTags == null) {
            setSubTags = new TreeSet<String>();
        }
        // construct new mapping: name -> AttributeDescription
        Map<String, AttributeDescription> attributesDescrAnt = new TreeMap<String, AttributeDescription>();
        for (AttributeDescription ad : attributesDescrGui.values()) {
            attributesDescrAnt.put(ad.name, ad);
        }
        //
        Element exporter = hibernatetool.addElement(expName);
        Properties expProps = new Properties();
        expProps.putAll(globalProps);
        expProps.putAll(ef.getProperties());
        //
        Properties extractGUISpecial = new Properties();
        try {
            ExporterFactory.extractExporterProperties(expDefId, expProps, extractGUISpecial);
        } catch (CoreException e) {
            // ignore
        }
        // convert gui special properties names into Ant names
        for (Map.Entry<Object, Object> propEntry : extractGUISpecial.entrySet()) {
            Object key = propEntry.getKey();
            Object val = propEntry.getValue();
            AttributeDescription ad = attributesDescrGui.get(key);
            if (ad == null) {
                expProps.put(key, val);
                continue;
            }
            expProps.put(ad.name, val);
        }
        // to add attributes and properties in alphabetic order
        Map<String, Object> expPropsSorted = new TreeMap<String, Object>();
        for (Map.Entry<Object, Object> propEntry : expProps.entrySet()) {
            Object key = propEntry.getKey();
            Object val = propEntry.getValue();
            expPropsSorted.put(key.toString(), val);
        }
        // list2Remove - list to collect properties which put into attributes,
        // all other properties be ordinal property definition
        List<Object> list2Remove = new ArrayList<Object>();
        for (Map.Entry<String, Object> propEntry : expPropsSorted.entrySet()) {
            Object key = propEntry.getKey();
            Object val = propEntry.getValue();
            AttributeDescription ad = attributesDescrAnt.get(key);
            if (ad == null) {
                continue;
            }
            list2Remove.add(key);
            if (val == null || 0 == val.toString().compareTo(ad.defaultValue)) {
                continue;
            }
            String processedVal = processPropertyValue(val);
            if (setSubTags.contains(ad.guiName)) {
                Element subTag = exporter.addElement(ad.name);
                subTag.addText(processedVal);
            } else {
                exporter.addAttribute(ad.name, processedVal);
            }
        }
        for (Object obj : list2Remove) {
            expProps.remove(obj);
            expPropsSorted.remove(obj);
        }
        for (Map.Entry<String, Object> propEntry : expPropsSorted.entrySet()) {
            Object key = propEntry.getKey();
            Object val = propEntry.getValue();
            String processedVal = processPropertyValue(val);
            Element property = exporter.addElement(CodeGenerationStrings.PROPERTY);
            property.addAttribute(CodeGenerationStrings.KEY, key.toString());
            property.addAttribute(CodeGenerationStrings.VALUE, processedVal);
        }
    }
    return root;
}

From source file:org.hightides.annotations.processor.SpringConfigProcessor.java

License:Apache License

/**
 * Adds controller bean and url mapping to spring config
 * @param params/*from   ww w.jav a2  s.com*/
 */
private void addControllerConfiguration(Map<String, Object> params) {
    // Add controller bean
    //      <!-- Template Controller -->
    //      <bean id="templateController" class="com.ideyatech.veeui.controller.TemplateController" autowire="byName">
    //         <property name="service" ref="templateService"></property>
    //         <property name="commandName" value="template" />
    //         <property name="commandClass" value="com.ideyatech.veeui.bean.Template" />
    //         <property name="formView" value="template/template-form" />
    //         <property name="searchView" value="template/template-list" />
    //         <property name="refreshView" value="template/template-refresh" />
    //         <property name="pageSize" value="${search.page.size}" />
    //         <property name="numLinks" value="${search.links.displayed}" />
    //      </bean>
    String xmlFilename = (new File(".")).getAbsolutePath() + contextPath + controllerContextFile;
    Element bean = DocumentHelper.createElement("bean");
    bean.addAttribute("id", params.get("modelName") + "Controller");
    bean.addAttribute("class", params.get("package") + "." + params.get("className") + "Controller");
    bean.addAttribute("autowire", "byName");
    addPropertyByRef(bean, "service", params.get("modelName") + "Service");
    if (BaseParamReader.isValidation()) {
        addPropertyByRef(bean, "validator", params.get("modelName") + "Validator");
    }
    addPropertyByValue(bean, "commandName", params.get("modelName") + "");
    addPropertyByValue(bean, "commandClass", params.get("modelPackage") + "." + params.get("className"));
    addPropertyByValue(bean, "formView", params.get("jspFolder") + "/" + params.get("modelName") + "-form");
    addPropertyByValue(bean, "searchView", params.get("jspFolder") + "/" + params.get("modelName") + "-list");
    if (params.get("pageType") == PageType.PARENT) {
        addPropertyByValue(bean, "refreshView", "redirect:" + params.get("modelName") + ".jspx");
    } else {
        addPropertyByValue(bean, "refreshView",
                params.get("jspFolder") + "/" + params.get("modelName") + "-refresh");
    }
    addPropertyByValue(bean, "pageSize", "${search.page.size}");
    addPropertyByValue(bean, "numLinks", "${search.links.displayed}");
    Element ret = SpringXMLUtil.addBean(xmlFilename, bean, params.get("syncMode").toString());
    if (ret != null && params.get("pageType") != PageType.CHILD) {
        // if URL mapping is not yet present and page is not a CHILD
        // Then add URL mapping
        // <prop key="/template.jspx">templateController</prop>
        Element urlMap = DocumentHelper.createElement("prop");
        urlMap.addAttribute("key", params.get("pageName") + "");
        urlMap.addText(params.get("modelName") + "Controller");
        // no need to backup because backup is already done by addBean earlier
        SpringXMLUtil.addURLMapProperty(xmlFilename, urlMap, false);
    }
}

From source file:org.hightides.annotations.util.SpringXMLUtil.java

License:Apache License

/**
 * Copies the node to target. This is necessary because
 * DOM4J appends xmlns when bean is inserted as addElement().
 * @param target/* ww w.ja  v  a 2  s. c  om*/
 * @param node
 */
@SuppressWarnings("unchecked")
private static void cloneChildElement(Element target, Element node) {
    // create new element
    Element newBean = target.addElement(node.getName());
    // copy all attributes
    newBean.setAttributes(node.attributes());
    // copy text elements
    if (!StringUtil.isEmpty(node.getText()))
        newBean.addText(node.getText());
    List<Element> elements = node.elements();
    // copy all elements
    for (Element elem : elements) {
        cloneChildElement(newBean, elem);
    }
}

From source file:org.infoglue.cms.util.dom.DOMBuilder.java

License:Open Source License

/**
 * This method adds a text-element with a given name to a given parent element.
 *//*from  w  w w . j a va 2 s. co  m*/

public Element addTextElement(Element element, String text) {
    Element newElement = element.addText(text);
    return newElement;
}

From source file:org.jage.platform.config.xml.loaders.AbstractDocumentLoader.java

License:Open Source License

protected static final Element newValueElement(final String type, final String value) {
    final Element element = createElement(createQName(ConfigTags.VALUE.toString(), NAMESPACE));
    element.addAttribute(ConfigAttributes.TYPE.toString(), type);
    element.addText(value);
    return element;
}

From source file:org.jboss.tools.jbpm.convert.bpmnto.util.DomXmlWriter.java

License:Open Source License

public static Document createDomTree(boolean useNamespace, String url, String rootElementName) {
    Document document = DocumentHelper.createDocument();
    Element root = null;

    if (useNamespace) {
        Namespace jbpmNamespace = new Namespace(null, url);
        root = document.addElement(rootElementName, jbpmNamespace.getURI());
    } else {//  w w w .j  a va 2s.  c  om
        root = document.addElement(rootElementName);
    }
    root.addText(System.getProperty("line.separator"));

    return document;
}

From source file:org.jbpm.jpdl.internal.convert.node.MailNode.java

License:Open Source License

public void read(Jpdl3Converter reader) {
    String template = nodeElement.attributeValue("template");
    String actors = nodeElement.attributeValue("actors");
    String to = nodeElement.attributeValue("to");
    String subject = reader.getProperty("subject", nodeElement);
    String text = reader.getProperty("text", nodeElement);
    if (template != null) {
        convertedElement.addAttribute("template", template);
    }//www  . j a  v  a 2 s.c om

    if (actors != null) {
        Element toElement = convertedElement.addElement("to");
        toElement.addAttribute("users", actors);
    }
    if (to != null) {
        Element toElement = convertedElement.addElement("to");
        toElement.addAttribute("addresses", to);
    }
    if (subject != null) {
        Element subjectElement = convertedElement.addElement("subject");
        subjectElement.addText(subject);
    }
    if (text != null) {
        Element textElement = convertedElement.addElement("text");
        textElement.addText(text);
    }
}

From source file:org.jbpm.jpdl.xml.JpdlXmlWriter.java

License:Open Source License

private Document createDomTree(ProcessDefinition processDefinition) {
    Document document = DocumentHelper.createDocument();
    Element root = null;

    if (useNamespace)
        root = document.addElement("process-definition", jbpmNamespace.getURI());
    else//from ww w.j  av a  2 s .  c  om
        root = document.addElement("process-definition");
    addAttribute(root, "name", processDefinition.getName());

    // write the start-state
    if (processDefinition.getStartState() != null) {
        writeComment(root, "START-STATE");
        writeStartNode(root, (StartState) processDefinition.getStartState());
    }
    // write the nodeMap
    if ((processDefinition.getNodes() != null) && (processDefinition.getNodes().size() > 0)) {
        writeComment(root, "NODES");
        writeNodes(root, processDefinition.getNodes());
    }
    // write the process level actions
    if (processDefinition.hasEvents()) {
        writeComment(root, "PROCESS-EVENTS");
        writeEvents(root, processDefinition);
    }
    if (processDefinition.hasActions()) {
        writeComment(root, "ACTIONS");
        List namedProcessActions = getNamedProcessActions(processDefinition.getActions());
        writeActions(root, namedProcessActions);
    }

    root.addText(System.getProperty("line.separator"));

    return document;
}

From source file:org.jbpm.jpdl.xml.JpdlXmlWriter.java

License:Open Source License

private void writeComment(Element element, String comment) {
    element.addText(System.getProperty("line.separator"));
    element.addComment(" " + comment + " ");
}

From source file:org.jenkins.tools.test.model.MavenPom.java

License:Open Source License

public void addDependencies(Map<String, VersionNumber> toAdd, Map<String, VersionNumber> toReplace,
        VersionNumber coreDep, Map<String, String> pluginGroupIds) throws IOException {
    File pom = new File(rootDir.getAbsolutePath() + "/" + pomFileName);
    Document doc;/* ww  w  . j ava 2  s.  com*/
    try {
        doc = new SAXReader().read(pom);
    } catch (DocumentException x) {
        throw new IOException(x);
    }
    Element dependencies = doc.getRootElement().element("dependencies");
    if (dependencies == null) {
        dependencies = doc.getRootElement().addElement("dependencies");
    }
    for (Element mavenDependency : (List<Element>) dependencies.elements("dependency")) {
        Element artifactId = mavenDependency.element("artifactId");
        if (artifactId == null || !"maven-plugin".equals(artifactId.getTextTrim())) {
            continue;
        }
        Element version = mavenDependency.element("version");
        if (version == null || version.getTextTrim().startsWith("${")) {
            // Prior to 1.532, plugins sometimes assumed they could pick up the Maven plugin version from their parent POM.
            if (version != null) {
                mavenDependency.remove(version);
            }
            version = mavenDependency.addElement("version");
            version.addText(coreDep.toString());
        }
    }
    for (Element mavenDependency : (List<Element>) dependencies.elements("dependency")) {
        Element artifactId = mavenDependency.element("artifactId");
        if (artifactId == null) {
            continue;
        }
        excludeSecurity144Compat(mavenDependency);
        VersionNumber replacement = toReplace.get(artifactId.getTextTrim());
        if (replacement == null) {
            continue;
        }
        Element version = mavenDependency.element("version");
        if (version != null) {
            mavenDependency.remove(version);
        }
        version = mavenDependency.addElement("version");
        version.addText(replacement.toString());
    }
    dependencies.addComment("SYNTHETIC");
    for (Map.Entry<String, VersionNumber> dep : toAdd.entrySet()) {
        Element dependency = dependencies.addElement("dependency");
        String group = pluginGroupIds.get(dep.getKey());

        // Handle cases where plugin isn't under default groupId
        if (group != null && !group.isEmpty()) {
            dependency.addElement("groupId").addText(group);
        } else {
            dependency.addElement("groupId").addText("org.jenkins-ci.plugins");
        }
        dependency.addElement("artifactId").addText(dep.getKey());
        dependency.addElement("version").addText(dep.getValue().toString());
        excludeSecurity144Compat(dependency);
    }
    FileWriter w = new FileWriter(pom);
    try {
        doc.write(w);
    } finally {
        w.close();
    }
}