This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch lines
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/lines by this push:
     new 12348a47985b CAMEL-22605: camel-core - Dump model structure dev console
12348a47985b is described below

commit 12348a47985bd14f4aa12e207359e0e8a4b3ab04
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Oct 27 20:25:27 2025 +0100

    CAMEL-22605: camel-core - Dump model structure dev console
---
 .../java/org/apache/camel/spi/ModelDumpLine.java   |  7 ++-
 .../apache/camel/impl/console/ConsoleHelper.java   |  2 +-
 .../impl/console/RouteStructureDevConsole.java     | 19 +-----
 .../org/apache/camel/xml/LwModelToXMLDumper.java   | 71 ----------------------
 .../java/org/apache/camel/xml/io/XMLWriter.java    |  7 +--
 .../java/org/apache/camel/xml/out/BaseWriter.java  |  6 +-
 6 files changed, 10 insertions(+), 102 deletions(-)

diff --git 
a/core/camel-api/src/main/java/org/apache/camel/spi/ModelDumpLine.java 
b/core/camel-api/src/main/java/org/apache/camel/spi/ModelDumpLine.java
index 06ce1ab0e038..8b880b6500c2 100644
--- a/core/camel-api/src/main/java/org/apache/camel/spi/ModelDumpLine.java
+++ b/core/camel-api/src/main/java/org/apache/camel/spi/ModelDumpLine.java
@@ -17,10 +17,13 @@
 package org.apache.camel.spi;
 
 /**
- * Represents a line in a model dumper
+ * Represents a line in a model dumper of the route structure (not with full 
details like a XML or YAML dump).
  *
  * @param location line source location:line (if present)
- * @param code     dump code such as YAML, XML, or text
+ * @param type     the kind of EIP node
+ * @param id       the id of the EIP node
+ * @param level    indent level of the EIP node
+ * @param code     EIP code such as label or short name that is human-readable 
or pseudocode
  */
 public record ModelDumpLine(String location, String type, String id, int 
level, String code) {
 }
diff --git 
a/core/camel-console/src/main/java/org/apache/camel/impl/console/ConsoleHelper.java
 
b/core/camel-console/src/main/java/org/apache/camel/impl/console/ConsoleHelper.java
index 30dca7af3f7f..1553ee12241b 100644
--- 
a/core/camel-console/src/main/java/org/apache/camel/impl/console/ConsoleHelper.java
+++ 
b/core/camel-console/src/main/java/org/apache/camel/impl/console/ConsoleHelper.java
@@ -113,7 +113,7 @@ public final class ConsoleHelper {
         return null;
     }
 
-    private static Integer extractSourceLocationLineNumber(String location) {
+    public static Integer extractSourceLocationLineNumber(String location) {
         int cnt = StringHelper.countChar(location, ':');
         if (cnt > 0) {
             int pos = location.lastIndexOf(':');
diff --git 
a/core/camel-console/src/main/java/org/apache/camel/impl/console/RouteStructureDevConsole.java
 
b/core/camel-console/src/main/java/org/apache/camel/impl/console/RouteStructureDevConsole.java
index 95648b29a065..26d4aef9ac14 100644
--- 
a/core/camel-console/src/main/java/org/apache/camel/impl/console/RouteStructureDevConsole.java
+++ 
b/core/camel-console/src/main/java/org/apache/camel/impl/console/RouteStructureDevConsole.java
@@ -37,6 +37,8 @@ import org.apache.camel.util.StringHelper;
 import org.apache.camel.util.json.JsonObject;
 import org.apache.camel.util.json.Jsoner;
 
+import static 
org.apache.camel.impl.console.ConsoleHelper.extractSourceLocationLineNumber;
+
 @DevConsole(name = "route-structure", description = "Dump route structure")
 public class RouteStructureDevConsole extends AbstractDevConsole {
 
@@ -188,21 +190,4 @@ public class RouteStructureDevConsole extends 
AbstractDevConsole {
         return code;
     }
 
-    private static Integer extractSourceLocationLineNumber(String location) {
-        int cnt = StringHelper.countChar(location, ':');
-        if (cnt > 0) {
-            int pos = location.lastIndexOf(':');
-            // in case pos is end of line
-            if (pos < location.length() - 1) {
-                String num = location.substring(pos + 1);
-                try {
-                    return Integer.valueOf(num);
-                } catch (Exception e) {
-                    return null;
-                }
-            }
-        }
-        return null;
-    }
-
 }
diff --git 
a/core/camel-xml-io/src/main/java/org/apache/camel/xml/LwModelToXMLDumper.java 
b/core/camel-xml-io/src/main/java/org/apache/camel/xml/LwModelToXMLDumper.java
index b063234783e4..fcda4f7985e0 100644
--- 
a/core/camel-xml-io/src/main/java/org/apache/camel/xml/LwModelToXMLDumper.java
+++ 
b/core/camel-xml-io/src/main/java/org/apache/camel/xml/LwModelToXMLDumper.java
@@ -26,8 +26,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.function.Consumer;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.CamelContextAware;
@@ -47,7 +45,6 @@ import org.apache.camel.model.SendDefinition;
 import org.apache.camel.model.ToDynamicDefinition;
 import org.apache.camel.model.dataformat.DataFormatsDefinition;
 import org.apache.camel.model.language.ExpressionDefinition;
-import org.apache.camel.spi.ModelDumpLine;
 import org.apache.camel.spi.ModelToXMLDumper;
 import org.apache.camel.spi.NamespaceAware;
 import org.apache.camel.spi.annotations.JdkService;
@@ -63,8 +60,6 @@ import static 
org.apache.camel.model.ProcessorDefinitionHelper.filterTypeInOutpu
 @JdkService(ModelToXMLDumper.FACTORY)
 public class LwModelToXMLDumper implements ModelToXMLDumper {
 
-    private static final Pattern SOURCE_LOCATION_PATTERN = 
Pattern.compile("(\\ssourceLocation=\"(.*?)\")");
-
     @Override
     public String dumpModelAsXml(CamelContext context, NamedNode definition) 
throws Exception {
         return dumpModelAsXml(context, definition, false, true);
@@ -477,70 +472,4 @@ public class LwModelToXMLDumper implements 
ModelToXMLDumper {
         }
     }
 
-    // TODO: Remove me
-    public List<ModelDumpLine> dumpStructureModel(CamelContext context, 
NamedNode definition) throws Exception {
-        List<ModelDumpLine> answer = new ArrayList<>();
-        doDumpStructureModelAsXml(answer, context, definition);
-        return answer;
-    }
-
-    protected void doDumpStructureModelAsXml(List<ModelDumpLine> answer, 
CamelContext context, NamedNode definition)
-            throws Exception {
-        final StringWriter buffer = new StringWriter();
-        ModelWriter writer = new ModelWriter(buffer, 
BaseWriter.DEFAULT_NAMESPACE) {
-            protected void 
doWriteOptionalIdentifiedDefinitionAttributes(OptionalIdentifiedDefinition<?> 
def)
-                    throws IOException {
-                if (Boolean.TRUE.equals(def.getCustomId())) {
-                    // write custom id
-                    doWriteAttribute("id", def.getId());
-                }
-
-                // remember source locations
-                String loc = (def instanceof RouteDefinition ? 
((RouteDefinition) def).getInput() : def).getLocation();
-                int line = (def instanceof RouteDefinition ? 
((RouteDefinition) def).getInput() : def).getLineNumber();
-                if (line != -1) {
-                    doWriteAttribute("sourceLocation", loc + ":" + line);
-                }
-                // we do not want any other attributes
-            }
-
-            protected void doWriteExpressionNodeElements(ExpressionNode def) 
throws IOException {
-                // do not include expressions in brief mode
-            }
-
-            @Override
-            protected void attribute(String name, Object value) throws 
IOException {
-                // limit what we want to see in structure mode
-                if ("sourceLocation".equals(name) || "id".equals(name) || 
"uri".equals(name) || "message".equals(name)) {
-                    String s = value != null ? value.toString() : null;
-                    // clip long text
-                    if (s != null && s.length() > 80) {
-                        s = s.substring(0, 80) + " ... (clipped value)";
-                    }
-                    super.attribute(name, s);
-                }
-            }
-        };
-
-        writer.setEmptyTagNewLine(true);
-        
writer.writeOptionalIdentifiedDefinitionRef((OptionalIdentifiedDefinition<?>) 
definition);
-
-        String data = buffer.toString();
-        for (String line : data.split(System.lineSeparator())) {
-            if (!line.isBlank()) {
-                String loc = null;
-                Matcher m = SOURCE_LOCATION_PATTERN.matcher(line);
-                if (m.find()) {
-                    loc = m.group(2);
-                    line = m.replaceAll("");
-                }
-                // fake no line number
-                if (loc == null) {
-                    loc = ":-1";
-                }
-                answer.add(new ModelDumpLine(loc, null, null, 0, line));
-            }
-        }
-    }
-
 }
diff --git 
a/core/camel-xml-io/src/main/java/org/apache/camel/xml/io/XMLWriter.java 
b/core/camel-xml-io/src/main/java/org/apache/camel/xml/io/XMLWriter.java
index 64ca776b753e..0d87e4d3b181 100644
--- a/core/camel-xml-io/src/main/java/org/apache/camel/xml/io/XMLWriter.java
+++ b/core/camel-xml-io/src/main/java/org/apache/camel/xml/io/XMLWriter.java
@@ -39,7 +39,6 @@ public class XMLWriter {
     private int depth;
     private boolean readyForNewLine;
     private boolean tagIsEmpty;
-    private boolean emptyTagNewLine;
 
     /**
      * @param writer not null
@@ -94,10 +93,6 @@ public class XMLWriter {
         }
     }
 
-    public void setEmptyTagNewLine(boolean emptyTagNewLine) {
-        this.emptyTagNewLine = emptyTagNewLine;
-    }
-
     private static String validateLineSeparator(String lineSeparator) {
         String ls = lineSeparator != null ? lineSeparator : 
System.lineSeparator();
         if (!(ls.equals("\n") || ls.equals("\r") || ls.equals("\r\n"))) {
@@ -196,7 +191,7 @@ public class XMLWriter {
 
         if (tagIsEmpty) {
             write("/");
-            readyForNewLine = emptyTagNewLine ? true : false;
+            readyForNewLine = false;
             finishTag();
             elements.removeLast();
         } else {
diff --git 
a/core/camel-xml-io/src/main/java/org/apache/camel/xml/out/BaseWriter.java 
b/core/camel-xml-io/src/main/java/org/apache/camel/xml/out/BaseWriter.java
index 2cfc68583e95..4f1e559f9da8 100644
--- a/core/camel-xml-io/src/main/java/org/apache/camel/xml/out/BaseWriter.java
+++ b/core/camel-xml-io/src/main/java/org/apache/camel/xml/out/BaseWriter.java
@@ -35,8 +35,8 @@ public class BaseWriter {
 
     public static final String DEFAULT_NAMESPACE = 
"http://camel.apache.org/schema/xml-io";;
 
-    protected final Deque<String> namespacesStack = new LinkedList<>();
     protected final XMLWriter writer;
+    protected final Deque<String> namespacesStack = new LinkedList<>();
     protected boolean namespaceWritten;
     protected boolean skipCustomId = true;
 
@@ -49,10 +49,6 @@ public class BaseWriter {
         }
     }
 
-    public void setEmptyTagNewLine(boolean emptyTagNewLine) {
-        writer.setEmptyTagNewLine(emptyTagNewLine);
-    }
-
     protected void startElement(String name) throws IOException {
         writer.startElement(name);
         if (!namespaceWritten && namespacesStack.peek() != null) {

Reply via email to