com.yahoo.text.XML类的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(203)

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

XML介绍

[英]Static XML utility methods
[中]静态XML实用工具方法

代码示例

代码示例来源:origin: com.yahoo.vespa/config-model

private Optional<Element> findChildById(Element parent, String id) {
  for (Element child : XML.getChildren(parent))
    if (id.equals(child.getAttribute("id"))) return Optional.of(child);
  return Optional.empty();
}

代码示例来源:origin: com.yahoo.vespa/config-model

private List<Node> readNodes(Element providerElement) {
  Element nodesSpec = XML.getChild(providerElement, "nodes");
  if (nodesSpec == null) {
    return null;
  }
  List<Node> nodes = new ArrayList<>();
  for (Element nodeSpec : XML.getChildren(nodesSpec, "node")) {
    nodes.add(readNode(nodeSpec));
  }
  return nodes;
}

代码示例来源:origin: com.yahoo.vespa/vespajlib

/**
 * Returns the Document of the string XML payload
 */
public static Document getDocument(String xmlString) {
  return getDocument(new StringReader(xmlString));
}

代码示例来源:origin: com.yahoo.vespa/config-model

private String getPath(Element servletElement) {
  Element pathElement = XML.getChild(servletElement, "path");
  return XML.getValue(pathElement);
}

代码示例来源:origin: com.yahoo.vespa/config-model

private Map<String, String> getServletConfig(Element servletElement) {
    Map<String, String> servletConfig = new HashMap<>();

    Element servletConfigElement = XML.getChild(servletElement, "servlet-config");
    XML.getChildren(servletConfigElement).forEach( parameter ->
        servletConfig.put(parameter.getTagName(), XML.getValue(parameter))
    );

    return servletConfig;
  }
}

代码示例来源:origin: com.yahoo.vespa/config-model

public static Collection<String> valuesFromElements(Element parent, String elementName) {
  List<String> symbols = new ArrayList<>();
  for (Element symbol : XML.getChildren(parent, elementName)) {
    symbols.add(XML.getValue(symbol).trim());
  }
  return symbols;
}

代码示例来源:origin: com.yahoo.vespa/config-model

private boolean readSourceSet(Element searcherSpec) {
  return XML.getChild(searcherSpec, "source-set") != null;
}

代码示例来源:origin: com.yahoo.vespa/config-model-api

/**
 * Returns a ValidationOverrides instance with the content of the given XML string.
 * An empty ValidationOverrides is returned if the argument is empty.
 *
 * @param xmlForm the string which optionally contains a validation-overrides XML structure
 * @return a ValidationOverrides from the argument
 * @throws IllegalArgumentException if the validation-allows.xml file exists but is invalid
 */
public static ValidationOverrides fromXml(String xmlForm) {
  if ( xmlForm.isEmpty()) return ValidationOverrides.empty;
  try {
    // Assume valid structure is ensured by schema validation
    Element root = XML.getDocument(xmlForm).getDocumentElement();
    List<ValidationOverrides.Allow> overrides = new ArrayList<>();
    for (Element allow : XML.getChildren(root, "allow")) {
      Instant until = LocalDate.parse(allow.getAttribute("until"), DateTimeFormatter.ISO_DATE)
          .atStartOfDay().atZone(ZoneOffset.UTC).toInstant()
          .plus(Duration.ofDays(1)); // Make the override valid *on* the "until" date
      Optional<ValidationId> validationId = ValidationId.from(XML.getValue(allow));
      if (validationId.isPresent()) // skip unknown ids as they may be valid for other model versions
        overrides.add(new ValidationOverrides.Allow(validationId.get(), until));
    }
    return new ValidationOverrides(overrides, xmlForm);
  }
  catch (IllegalArgumentException e) {
    throw new IllegalArgumentException("validation-overrides is invalid", e);
  }
}

代码示例来源:origin: com.yahoo.vespa/container-search

public List<Element> createQueryProfiles(List<NamedReader> queryProfileReaders, QueryProfileRegistry registry) {
  List<Element> queryProfileElements = new ArrayList<>(queryProfileReaders.size());
  for (NamedReader reader : queryProfileReaders) {
    Element root = XML.getDocument(reader).getDocumentElement();
    if ( ! root.getNodeName().equals("query-profile")) {
      throw new IllegalArgumentException("Root tag in '" + reader.getName() +
    Element dimensions = XML.getChild(root,"dimensions");
    if (dimensions != null)
      queryProfile.setDimensions(toArray(XML.getValue(dimensions)));

代码示例来源:origin: com.yahoo.vespa/vespajlib

/**
 * Replaces the following:
 * <ul>
 * <li>all ascii codes less than 32 except 9 (tab), 10 (nl) and 13 (cr) if
 * escapeLowAscii is <code>true</code>
 * <li>ampersand (&amp;)
 * <li>less than (&lt;)
 * <li>larger than (&gt;)
 * <li>double quotes (&quot;) if isAttribute is <code>true</code>
 * </ul>
 * with character entities.
 *
 */
public static String xmlEscape(String string, boolean isAttribute, boolean escapeLowAscii, StringBuilder buffer) {
  return xmlEscape(string, isAttribute, escapeLowAscii, buffer, -1);
}

代码示例来源:origin: com.yahoo.vespa/config-model-api

List<Step> steps = new ArrayList<>();
Optional<String> globalServiceId = Optional.empty();
Element root = XML.getDocument(xmlForm).getDocumentElement();
if (validate)
  validateTagOrder(root);
for (Element environmentTag : XML.getChildren(root)) {
  if ( ! isEnvironmentName(environmentTag.getTagName())) continue;
    for (Element stepTag : XML.getChildren(environmentTag)) {
      Optional<AthenzService> athenzService = stringAttribute("athenz-service", environmentTag).map(AthenzService::from);
      if (stepTag.getTagName().equals("delay")) {
      } else if (stepTag.getTagName().equals("parallel")) {
        List<DeclaredZone> zones = new ArrayList<>();
        for (Element regionTag : XML.getChildren(stepTag)) {
          zones.add(readDeclaredZone(environment, athenzService, regionTag));

代码示例来源:origin: com.yahoo.vespa/container-search

public List<Element> createQueryProfileTypes(List<NamedReader> queryProfileTypeReaders, QueryProfileTypeRegistry registry) {
  List<Element> queryProfileTypeElements = new ArrayList<>(queryProfileTypeReaders.size());
  for (NamedReader reader : queryProfileTypeReaders) {
    Element root = XML.getDocument(reader).getDocumentElement();
    if ( ! root.getNodeName().equals("query-profile-type")) {
      throw new IllegalArgumentException("Root tag in '" + reader.getName() +
                        "' must be 'query-profile-type', not '" + root.getNodeName() + "'");
    }
    String idString=root.getAttribute("id");
    if (idString == null || idString.equals(""))
      throw new IllegalArgumentException("'" + reader.getName() + "' has no 'id' attribute in the root element");
    ComponentId id = new ComponentId(idString);
    validateFileNameToId(reader.getName(),id,"query profile type");
    QueryProfileType type = new QueryProfileType(id);
    type.setMatchAsPath(XML.getChild(root,"match") != null);
    type.setStrict(XML.getChild(root,"strict") != null);
    registry.register(type);
    queryProfileTypeElements.add(root);
  }
  return queryProfileTypeElements;
}

代码示例来源:origin: com.yahoo.vespa/config-model

private static String getBinding(Element e) {
  String binding = XML.getValue(e);
  if (! binding.endsWith("/")) {
    log.warning("Adding a trailing '/' to the document-api binding: " + binding + " -> " + binding + "/");
    binding = binding + "/";
  }
  return binding;
}

代码示例来源:origin: com.yahoo.vespa/vespajlib

/**
 * Creates a new XML DocumentBuilder
 *
 * @return a DocumentBuilder
 * @throws RuntimeException if we fail to create one
 */
public static DocumentBuilder getDocumentBuilder() {
  return getDocumentBuilder("com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl", null);
}

代码示例来源:origin: com.yahoo.vespa/container-search

private Map<String,String> readParameters(Element containingElement) {
  List<Element> parameterElements=XML.getChildren(containingElement,"parameter");
  if (parameterElements.size()==0) return Collections.emptyMap(); // Shortcut
  Map<String,String> parameters=new LinkedHashMap<>();
  for (Element parameter : parameterElements) {
    String key=parameter.getAttribute("name");
    String value=XML.getValue(parameter);
    parameters.put(key,value);
  }
  return parameters;
}

代码示例来源:origin: com.yahoo.vespa/config-model

private static String getCleanValue(Element spec, String name) {
  Element elem = XML.getChild(spec, name);
  if (elem == null) {
    return null;
  }
  String value = elem.getFirstChild().getNodeValue();
  if (value == null) {
    return null;
  }
  value = value.trim();
  return value.isEmpty() ? null : value;
}

代码示例来源:origin: com.yahoo.vespa/config-model

private void addRoutingAliases(ContainerCluster cluster, Element spec, Environment environment) {
  if (environment != Environment.prod) return;
  Element aliases = XML.getChild(spec, "aliases");
  for (Element alias : XML.getChildren(aliases, "service-alias")) {
    cluster.serviceAliases().add(XML.getValue(alias));
  }
  for (Element alias : XML.getChildren(aliases, "endpoint-alias")) {
    cluster.endpointAliases().add(XML.getValue(alias));
  }
}

代码示例来源:origin: com.yahoo.vespa/vespajlib

/**
 * Replaces the following:
 * <ul>
 * <li>all ascii codes less than 32 except 9 (tab), 10 (nl) and 13 (cr)
 * <li>ampersand (&amp;)
 * <li>less than (&lt;)
 * <li>larger than (&gt;)
 * <li>double quotes (&quot;) if isAttribute is <code>true</code>
 * </ul>
 * with character entities.
 *
 */
public static String xmlEscape(String string, boolean isAttribute, StringBuilder buffer) {
  return xmlEscape(string, isAttribute, true, buffer, -1);
}

代码示例来源:origin: com.yahoo.vespa/container-search

private Object readFieldValue(Element field, String name, String targetDescription, QueryProfileRegistry registry) {
  Element ref = XML.getChild(field,"ref");
  if (ref != null) {
    String referencedName = XML.getValue(ref);
    QueryProfile referenced = registry.getComponent(referencedName);
    if (referenced == null)
      throw new IllegalArgumentException("Could not find query profile '" + referencedName + "' referenced as '" +
                        name + "' in " + targetDescription);
    return referenced;
  }
  else {
    return XML.getValue(field);
  }
}

代码示例来源:origin: com.yahoo.vespa/config-model-api

private DeclaredZone readDeclaredZone(Environment environment, Optional<AthenzService> athenzService, Element regionTag) {
  return new DeclaredZone(environment, Optional.of(RegionName.from(XML.getValue(regionTag).trim())),
              readActive(regionTag), athenzService);
}

相关文章