convert method

  1. @override
Iterable<WebDavStdResource> convert(
  1. XmlElement input
)
override

Converts input and returns the result of the conversion.

Implementation

@override
Iterable<WebDavStdResource> convert(XmlElement input) {
  final pathNode = input.getElement(WebDavElementNames.href,
      namespace: input.namespaceUri);
  if (pathNode == null) {
    throw WebDavParserDataError(
        "response node must contain ${WebDavElementNames.href}");
  }
  final statusNode = input.getElement(WebDavElementNames.status,
      namespace: input.namespaceUri);
  final errorNode = input.getElement(WebDavElementNames.error,
      namespace: input.namespaceUri);
  final locationNode = input.getElement(WebDavElementNames.location,
      namespace: input.namespaceUri);
  final descNode = input.getElement(WebDavElementNames.responsedescription,
      namespace: input.namespaceUri);

  final status = statusNode != null
      ? statusParser.convert(statusNode)
      : HttpStatus.multiStatus;
  final error = errorNode != null ? errorParser?.convert(errorNode) : null;
  final redirect =
      locationNode != null ? locationParser?.convert(locationNode) : null;
  final desc = descNode?.innerText.trim();

  switch (status) {
    case null:
      return const [];
    case HttpStatus.multiStatus:
      final path = hrefParser.convert(pathNode);
      if (path == null) return const [];
      final resourceTemplate =
          WebDavStdResource(path: path, status: status, redirect: redirect);
      return [
        WebDavStdResource.fromProps(
          path: path,
          status: status,
          error: error,
          redirect: redirect,
          desc: desc,
          props: input
              .findElements(WebDavElementNames.propstat,
                  namespace: input.namespaceUri)
              .map((e) => propstatParser
                  .convert((node: e, resource: resourceTemplate)))
              .expand((e) => e),
        )
      ];
    default:
      return input
          .findElements(WebDavElementNames.href,
              namespace: input.namespaceUri)
          .map((e) => hrefParser.convert(e))
          .whereNotNull()
          .map((e) => WebDavStdResource(
              path: e,
              status: status,
              error: error,
              redirect: redirect,
              desc: desc));
  }
}