com.yahoo.text.XML.getDocument()方法的使用及代码示例

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

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

XML.getDocument介绍

[英]Returns the parsed Document from an XML file
[中]从XML文件返回已解析的文档

代码示例

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

/**
 * Utility method to get an XML element from a reader
 *
 * @param reader the {@link Reader} to get an xml element from
 */
public static Element getElement(Reader reader) {
  return XML.getDocument(reader).getDocumentElement();
}

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

private static Document parseIncludeFile(File file, String parentTagName, boolean required) throws IOException {
  StringWriter w = new StringWriter();
  final String startTag = "<" + parentTagName + " " + XmlPreProcessor.deployNamespace + "='" + XmlPreProcessor.deployNamespaceUri + "' " + XmlPreProcessor.preprocessNamespace + "='" + XmlPreProcessor.preprocessNamespaceUri + "'>";
  w.append(startTag);
  if (file.exists() || required) {
    w.append(IOUtils.readFile(file));
  }
  final String endTag = "</" + parentTagName + ">";
  w.append(endTag);
  return XML.getDocument(new StringReader(w.toString()));
}

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

/** Returns the major version this application is valid for, or empty if it is valid for all versions */
default Optional<Integer> getMajorVersion() {
  if ( ! getDeployment().isPresent()) return Optional.empty();
  Element deployElement = XML.getDocument(getDeployment().get()).getDocumentElement();
  if (deployElement == null) return Optional.empty();
  String majorVersionString = deployElement.getAttribute("major-version");
  if (majorVersionString == null || majorVersionString.isEmpty())
    return Optional.empty();
  try {
    return Optional.of(Integer.parseInt(majorVersionString));
  }
  catch (NumberFormatException e) {
    throw new IllegalArgumentException("major-version must be an integer number, not '" + majorVersionString + "'");
  }
}

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

private Map<ComponentId,Element> createPages(List<NamedReader> pageReaders,boolean validateReaderNames) {
  Map<ComponentId,Element> pageElementsByPageId=new LinkedHashMap<>();
  for (NamedReader reader : pageReaders) {
    Element pageElement= XML.getDocument(reader).getDocumentElement();
    if ( ! pageElement.getNodeName().equals("page")) {
      logger.info("Ignoring '" + reader.getName() +
           "': Expected XML root element 'page' but was '" + pageElement.getNodeName() + "'");
      continue;
    }
    String idString=pageElement.getAttribute("id");
    if (idString==null || idString.isEmpty())
      throw new IllegalArgumentException("Page template '" + reader.getName() + "' has no 'id' attribute in the root element");
    ComponentId id=new ComponentId(idString);
    if (validateReaderNames)
      validateFileName(reader.getName(),id,"page template");
    registry.register(new PageTemplate(id));
    pageElementsByPageId.put(id,pageElement);
  }
  return pageElementsByPageId;
}

代码示例来源: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> 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/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() +

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

相关文章