Example #1
0
 private static Result<List<Element>> readDocument(String rootElementName, String stringDoc) {
   final SAXBuilder builder = new SAXBuilder();
   try {
     final Document document = builder.build(new StringReader(stringDoc));
     final Element rootElement = document.getRootElement();
     return Result.success(List.fromCollection(rootElement.getChildren(rootElementName)));
   } catch (IOException | JDOMException io) {
     return Result.failure(
         String.format(
             "Invalid root element name '%s' or XML data %s", rootElementName, stringDoc),
         io);
   } catch (Exception e) {
     return Result.failure(
         String.format("Unexpected error while reading XML data %s", stringDoc), e);
   }
 }
Example #2
0
 private static String processElement(Element element, Tuple<String, List<String>> format) {
   String formatString = format._1;
   List<String> parameters = format._2.map(element::getChildText);
   return String.format(formatString, parameters.toJavaList().toArray());
 }
Example #3
0
 private static List<String> toStringList(List<Element> list, Tuple<String, List<String>> format) {
   return list.map(e -> processElement(e, format));
 }