gpt4 book ai didi

org.codehaus.cargo.util.XmlReplacement类的使用及代码示例

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

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

XmlReplacement介绍

[英]XML replacement for the FileHandler.
[中]用XML替换FileHandler。

代码示例

代码示例来源: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

/**
 * {@inheritDoc}
 */
@Override
public void addXmlReplacement(XmlReplacement xmlReplacement)
{
  Map<XmlReplacementDetails, String> fileReplacements =
    this.xmlReplacements.get(xmlReplacement.getFile());
  if (fileReplacements == null)
  {
    fileReplacements = new HashMap<XmlReplacementDetails, String>();
    this.xmlReplacements.put(xmlReplacement.getFile(), fileReplacements);
  }
  fileReplacements.put(new XmlReplacementDetails(xmlReplacement.getXpathExpression(),
    xmlReplacement.getAttributeName(), xmlReplacement.getReplacementBehavior()),
      xmlReplacement.getValue());
}

代码示例来源:origin: com.atlassian.cargo-test-runner/cargo-test-runner

private static List<XmlReplacement> createTomcatRelaxedCharsXmlReplacements(String relaxedPathCharsString, String relaxedQueryCharsString) {
    final String file = "conf/server.xml";
    final String xpath = "//Connector";
    final String relaxedQueryCharsAttribute = "relaxedQueryChars";
    final String relaxedPathCharsAttribute = "relaxedPathChars";
    final boolean ignoreIfNonExisting = false;
    final List<XmlReplacement> relaxedCharsXmlReplacements = new ArrayList<XmlReplacement>();

    if (relaxedPathCharsString != null) {
      relaxedCharsXmlReplacements.add(new XmlReplacement(file, xpath, relaxedPathCharsAttribute, ignoreIfNonExisting, relaxedPathCharsString));
    }
    if (relaxedQueryCharsString != null) {
      relaxedCharsXmlReplacements.add(new XmlReplacement(file, xpath, relaxedQueryCharsAttribute, ignoreIfNonExisting, relaxedQueryCharsString));
    }

    return relaxedCharsXmlReplacements;
  }
}

代码示例来源: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));
}

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

XmlReplacement xmlReplacement = new XmlReplacement(destinationFile,
  key.getXpathExpression(), key.getAttributeName(), key.getReplacementBehavior(),
    value);
  xmlReplacement.setReplacementBehavior(
      XmlReplacement.ReplacementBehavior.IGNORE_IF_NON_EXISTING);

代码示例来源:origin: org.codehaus.cargo/cargo-core-api-util

/**
 * {@inheritDoc}
 */
@Override
public void replaceInXmlFile(XmlReplacement... xmlReplacements)
  throws CargoException
{
  Map<String, Map<XmlReplacementDetails, String>> replacements =
    new HashMap<String, Map<XmlReplacementDetails, String>>();
  for (XmlReplacement xmlReplacement : xmlReplacements)
  {
    Map<XmlReplacementDetails, String> replacementDetails =
      replacements.get(xmlReplacement.getFile());
    if (replacementDetails == null)
    {
      replacementDetails = new HashMap<XmlReplacementDetails, String>();
      replacements.put(xmlReplacement.getFile(), replacementDetails);
    }
    XmlReplacementDetails xmlReplacementDetails = new XmlReplacementDetails(
      xmlReplacement.getXpathExpression(), xmlReplacement.getAttributeName(),
        xmlReplacement.getReplacementBehavior());
    replacementDetails.put(xmlReplacementDetails, xmlReplacement.getValue());
  }
  for (Map.Entry<String, Map<XmlReplacementDetails, String>> replacement
    : replacements.entrySet())
  {
    replaceInXmlFile(replacement.getKey(), replacement.getValue());
  }
}

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

/**
 * {@inheritDoc}
 */
@Override
public List<XmlReplacement> getXmlReplacements()
{
  List<XmlReplacement> xmlReplacements = new ArrayList<XmlReplacement>();
  for (Map.Entry<String, Map<XmlReplacementDetails, String>> xmlReplacementEntry
    : this.xmlReplacements.entrySet())
  {
    for (Map.Entry<XmlReplacementDetails, String> xmlReplacementDetail
      : xmlReplacementEntry.getValue().entrySet())
    {
      XmlReplacementDetails key = xmlReplacementDetail.getKey();
      XmlReplacement xmlReplacement = new XmlReplacement(xmlReplacementEntry.getKey(),
        key.getXpathExpression(), key.getAttributeName(), key.getReplacementBehavior(),
          xmlReplacementDetail.getValue());
      xmlReplacements.add(xmlReplacement);
    }
  }
  return xmlReplacements;
}

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

/**
 * {@inheritDoc}
 */
@Override
public void replaceInXmlFile(XmlReplacement... xmlReplacements)
  throws CargoException
{
  Map<String, Map<XmlReplacementDetails, String>> replacements =
    new HashMap<String, Map<XmlReplacementDetails, String>>();
  for (XmlReplacement xmlReplacement : xmlReplacements)
  {
    Map<XmlReplacementDetails, String> replacementDetails =
      replacements.get(xmlReplacement.getFile());
    if (replacementDetails == null)
    {
      replacementDetails = new HashMap<XmlReplacementDetails, String>();
      replacements.put(xmlReplacement.getFile(), replacementDetails);
    }
    XmlReplacementDetails xmlReplacementDetails = new XmlReplacementDetails(
      xmlReplacement.getXpathExpression(), xmlReplacement.getAttributeName(),
        xmlReplacement.getReplacementBehavior());
    replacementDetails.put(xmlReplacementDetails, xmlReplacement.getValue());
  }
  for (Map.Entry<String, Map<XmlReplacementDetails, String>> replacement
    : replacements.entrySet())
  {
    replaceInXmlFile(replacement.getKey(), replacement.getValue());
  }
}

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

/**
 * Test non-existing XML attribute replacement
 */
public void testNonExistingXmlAttributeReplacement()
{
  final String file = "target/jboss-standalone-nonexisting-xml-attribute.xml";
  final String nonExistingAttribute = "nonexisting";
  final String test = "nonexisting=\"test\"";
  this.fileHandler.copyFile("src/test/resources/jboss-standalone.xml", file, true);
  XmlReplacement xmlReplacement = new XmlReplacement(file,
    "//server/socket-binding-group/socket-binding[@name='http']", nonExistingAttribute,
      XmlReplacement.ReplacementBehavior.THROW_EXCEPTION, "test");
  this.fileHandler.replaceInXmlFile(xmlReplacement);
  String read = this.fileHandler.readTextFile(file, "UTF-8");
  assertTrue("File " + file + " does not contain: " + test, read.contains(test));
}

代码示例来源:origin: org.codehaus.cargo/cargo-daemon-client

+ escapeJson(xmlReplacement.getAttributeName()) + "\","
+ "\"file\":\"" + escapeJson(xmlReplacement.getFile()) + "\","
+  "\"value\":\"" + escapeJson(xmlReplacement.getValue()) + "\","
+ "\"xpathExpression\":\""
  + escapeJson(xmlReplacement.getXpathExpression()) + "\","
+ "\"replacementBehavior\":\""
  + xmlReplacement.getReplacementBehavior() + "\"}");

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

/**
 * Test valid XML replacement for replacing a neighbor
 */
public void testXmlNeighborReplacement()
{
  final String file = "target/bindings-jboss-beans.xml";
  final String old = "<property name=\"port\">@cargo.rmi.port@</property>";
  final String permanent = "<property name=\"port\">@cargo.jboss.naming.port@</property>";
  final String new1 = "<property name=\"port\">test1</property>";
  this.fileHandler.copyFile("src/test/resources/bindings-jboss-beans.xml", file, true);
  String read = this.fileHandler.readTextFile(file, "UTF-8");
  assertTrue("File " + file + " does not contain: " + old, read.contains(old));
  assertTrue("File " + file + " does not contain: " + permanent, read.contains(permanent));
  XmlReplacement xmlReplacement = new XmlReplacement(file,
    "//deployment/bean[@name='StandardBindings']/constructor/parameter/set/bean"
      + "/property[@name='serviceName' and text()='jboss:service=Naming']/.."
      + "/property[@name='bindingName' and text()='Port']/.."
      + "/property[@name='port']", null,
      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));
  assertTrue("File " + file + " does not contain anymore: " + permanent,
    read.contains(permanent));
}

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

+ escapeJson(xmlReplacement.getAttributeName()) + "\","
+ "\"file\":\"" + escapeJson(xmlReplacement.getFile()) + "\","
+  "\"value\":\"" + escapeJson(xmlReplacement.getValue()) + "\","
+ "\"xpathExpression\":\""
  + escapeJson(xmlReplacement.getXpathExpression()) + "\","
+ "\"replacementBehavior\":\""
  + xmlReplacement.getReplacementBehavior() + "\"}");

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

/**
 * Test invalid XML XPath replacement
 */
public void testInvalidXmlXpathReplacement()
{
  final String file = "target/jboss-standalone-invalid-xpath.xml";
  final String nonExistingXpath =
    "//server/socket-binding-group/socket-binding[@name='nonexisting']";
  this.fileHandler.copyFile("src/test/resources/jboss-standalone.xml", file, true);
  XmlReplacement xmlReplacement =
    new XmlReplacement(file, nonExistingXpath, null,
        XmlReplacement.ReplacementBehavior.THROW_EXCEPTION, "test");
  try
  {
    this.fileHandler.replaceInXmlFile(xmlReplacement);
    fail();
  }
  catch (CargoException e)
  {
    assertNotNull(e.getCause());
    assertNotNull(e.getCause().getMessage());
    assertTrue(e.getCause().getMessage().contains(
      "Node " + nonExistingXpath + " not found"));
  }
}

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