gpt4 book ai didi

org.codehaus.cargo.util.XmlReplacement.setAttributeName()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-19 22:10:40 27 4
gpt4 key购买 nike

本文整理了Java中org.codehaus.cargo.util.XmlReplacement.setAttributeName()方法的一些代码示例,展示了XmlReplacement.setAttributeName()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XmlReplacement.setAttributeName()方法的具体详情如下:
包路径:org.codehaus.cargo.util.XmlReplacement
类名称:XmlReplacement
方法名:setAttributeName

XmlReplacement.setAttributeName介绍

暂无

代码示例

代码示例来源:origin: apache/geode

/**
 * Edits the container's configuration so that the file's XML element specified by the XPath
 * parameter contains the given XML attributes
 *
 * Uses {@link XmlReplacement} instances to add XML attributes to the specified XML node without
 * actively updating the original XML file.
 *
 * This function is used to edit the system properties that need to be placed in the server.xml
 * file. Adding these replacement XML pieces to the container's configuration allows the
 * configuration to modify the server.xml file only when creating the standalone container
 * configuration. This means that the server.xml file located in the installation's 'conf' folder
 * remains static, which resolves possible concurrency issues that might arise if more than one
 * container is modifying the server.xml file.
 *
 * @param file The path to the XML file that will be edited
 * @param XPath The path within XML file that leads to the node that should be changed
 * @param attributes The attributes to add to the node
 */
private void writePropertiesToConfig(StandaloneLocalConfiguration config, String file,
  String XPath, HashMap<String, String> attributes) {
 for (String key : attributes.keySet()) {
  XmlReplacement property = new XmlReplacement();
  property.setFile(file);
  property.setXpathExpression(XPath);
  property.setAttributeName(key);
  property.setValue(attributes.get(key));
  config.addXmlReplacement(property);
 }
}

代码示例来源:origin: codehaus-cargo/cargo

/**
 * Test valid XML replacement
 */
public void testValidXmlReplacement()
{
  final String file = "target/jboss-standalone-valid.xml";
  final String old = "<socket-binding name=\"http\" port=\"@cargo.servlet.port@\"/>";
  final String new1 = "<socket-binding name=\"http\" port=\"test1\"/>";
  final String new2 = "<socket-binding name=\"http\" port=\"test1\">test2</socket-binding>";
  this.fileHandler.copyFile("src/test/resources/jboss-standalone.xml", file, true);
  String read = this.fileHandler.readTextFile(file, "UTF-8");
  assertTrue("File " + file + " does not contain: " + old, read.contains(old));
  XmlReplacement xmlReplacement = new XmlReplacement(file,
    "//server/socket-binding-group/socket-binding[@name='http']", "port",
      XmlReplacement.ReplacementBehavior.THROW_EXCEPTION, "test1");
  this.fileHandler.replaceInXmlFile(xmlReplacement);
  read = this.fileHandler.readTextFile(file, "UTF-8");
  assertFalse("File " + file + " still contains: " + old, read.contains(old));
  assertTrue("File " + file + " does not contain: " + new1, read.contains(new1));
  xmlReplacement.setAttributeName(null);
  xmlReplacement.setValue("test2");
  this.fileHandler.replaceInXmlFile(xmlReplacement);
  read = this.fileHandler.readTextFile(file, "UTF-8");
  assertFalse("File " + file + " still contains: " + old, read.contains(old));
  assertFalse("File " + file + " still contains: " + new1, read.contains(new1));
  assertTrue("File " + file + " does not contain: " + new2, read.contains(new2));
}

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com