From f1892029930456478d6e1fdf846fd47731163b90 Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Wed, 7 Aug 2024 12:51:23 +0530 Subject: [PATCH] reader moved to private Signed-off-by: Arun Venmany --- .../langserver/lemminx/util/XmlReader.java | 50 +++++++++---------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java index f64e26cc..8cca69b2 100644 --- a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java +++ b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java @@ -58,27 +58,7 @@ private static boolean hasServerRoot(File xmlFile) { try { XMLInputFactory factory = getXmlInputFactory(); - - XMLEventReader reader = null; - - try { - reader = getReader(factory, xmlFile); - while (reader.hasNext()) { - XMLEvent nextEvent = reader.nextEvent(); - if (nextEvent.isStartElement()) { - return isServerElement(nextEvent); - } - } - } catch (XMLStreamException | FileNotFoundException e) { - LOGGER.severe("Error received trying to read XML file: " + xmlFile.getAbsolutePath()); - } finally { - if (reader != null) { - try { - reader.close(); - } catch (Exception ignored) { - } - } - } + return hasSeverRootValues(factory,xmlFile); } catch (Exception e) { LOGGER.severe("Unable to access XML file "+ xmlFile.getAbsolutePath()); } @@ -86,10 +66,29 @@ private static boolean hasServerRoot(File xmlFile) { return false; } - private static XMLEventReader getReader(XMLInputFactory factory, File xmlFile) - throws FileNotFoundException, XMLStreamException { - FileInputStream fis = new FileInputStream(xmlFile); - return factory.createXMLEventReader(fis); + private static boolean hasSeverRootValues(XMLInputFactory factory, File xmlFile) { + XMLEventReader reader=null; + try { + FileInputStream fis = new FileInputStream(xmlFile); + + reader = factory.createXMLEventReader(fis); + while (reader.hasNext()) { + XMLEvent nextEvent = reader.nextEvent(); + if (nextEvent.isStartElement()) { + return isServerElement(nextEvent); + } + } + } catch (XMLStreamException | FileNotFoundException e) { + LOGGER.severe("Error received trying to read XML file: " + xmlFile.getAbsolutePath()); + } finally { + if (reader != null) { + try { + reader.close(); + } catch (Exception ignored) { + } + } + } + return false; } private static XMLInputFactory getXmlInputFactory() { @@ -125,7 +124,6 @@ public static Map getElementValues(Path file, Set elemen XMLInputFactory factory = getXmlInputFactory(); readElementValues(file, elementNames, factory, returnValues); - return returnValues; }