You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by rm...@apache.org on 2012/10/17 15:06:08 UTC

svn commit: r1399217 - in /incubator/isis/trunk/framework/core/commons/src/main/java/org/apache/isis/core/commons/debug: DebugHtmlStringAbstract.java DebugList.java DebugString.java

Author: rmatthews
Date: Wed Oct 17 13:06:08 2012
New Revision: 1399217

URL: http://svn.apache.org/viewvc?rev=1399217&view=rev
Log:
Minor improvements to debug helpers.

Modified:
    incubator/isis/trunk/framework/core/commons/src/main/java/org/apache/isis/core/commons/debug/DebugHtmlStringAbstract.java
    incubator/isis/trunk/framework/core/commons/src/main/java/org/apache/isis/core/commons/debug/DebugList.java
    incubator/isis/trunk/framework/core/commons/src/main/java/org/apache/isis/core/commons/debug/DebugString.java

Modified: incubator/isis/trunk/framework/core/commons/src/main/java/org/apache/isis/core/commons/debug/DebugHtmlStringAbstract.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/core/commons/src/main/java/org/apache/isis/core/commons/debug/DebugHtmlStringAbstract.java?rev=1399217&r1=1399216&r2=1399217&view=diff
==============================================================================
--- incubator/isis/trunk/framework/core/commons/src/main/java/org/apache/isis/core/commons/debug/DebugHtmlStringAbstract.java (original)
+++ incubator/isis/trunk/framework/core/commons/src/main/java/org/apache/isis/core/commons/debug/DebugHtmlStringAbstract.java Wed Oct 17 13:06:08 2012
@@ -1,247 +1,262 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- */
-package org.apache.isis.core.commons.debug;
-
-import java.io.PrintWriter;
-import java.io.StringWriter;
-
-public abstract class DebugHtmlStringAbstract implements DebugBuilder {
-
-    private final boolean createPage;
-    private int tableLevel;
-    private boolean isOdd;
-
-    public DebugHtmlStringAbstract(final boolean createPage) {
-        this.createPage = createPage;
-    }
-
-    @Override
-    public void concat(final DebugBuilder debug) {
-        appendHtml(debug.toString());
-    }
-
-    @Override
-    public void append(final int number, final int width) {
-    }
-
-    @Override
-    public void append(final Object object) {
-    }
-
-    @Override
-    public void append(final Object object, final int width) {
-    }
-
-    @Override
-    public void appendln() {
-        if (tableLevel > 0) {
-            appendHtml(row() + "<td class=\"error\" colspan=\"2\" >end line</td></tr>");
-        } else {
-            appendHtml("<p>end line</p>");
-        }
-    }
-
-    @Override
-    public void blankLine() {
-        if (tableLevel > 0) {
-            appendHtml(row() + "<td class=\"error\" colspan=\"2\" >blank line</td></tr>");
-        } else {
-            appendHtml("<p>blank line</p>");
-        }
-    }
-
-    @Override
-    public void appendln(final String label, final boolean value) {
-        appendln(label, String.valueOf(value));
-    }
-
-    @Override
-    public void appendln(final String label, final double value) {
-        appendln(label, String.valueOf(value));
-    }
-
-    @Override
-    public void appendln(final String label, final long value) {
-        appendln(label, String.valueOf(value));
-    }
-
-    @Override
-    public void appendAsHexln(final String label, final long value) {
-        appendln(label, Long.toHexString(value));
-    }
-
-    @Override
-    public void appendPreformatted(final String label, final String object) {
-        final String value = object == null ? "null" : object.toString();
-        appendln(label, "<pre>" + value + "</pre>");
-    };
-
-    @Override
-    public void appendln(final String label, final Object object) {
-        final String value = object == null ? "null" : object.toString();
-        appendln(label, value);
-    }
-
-    @Override
-    public void appendln(final String label, final Object[] object) {
-        if (object.length == 0) {
-            appendln(label, "empty array");
-        } else {
-            appendln(label, object[0]);
-            for (int i = 1; i < object.length; i++) {
-                appendHtml(row() + "<td></td><td>" + object[i] + "</td></tr>");
-            }
-        }
-    }
-
-    @Override
-    public void startSection(final String title) {
-        startTableIfNeeded(true);
-        appendTitle(title);
-    }
-
-    @Override
-    public void endSection() {
-        endTableIfStarted();
-    }
-
-    @Override
-    public void indent() {
-        if (tableLevel > 0) {
-            appendHtml(row() + "<td>indented</td><td>");
-            startTableIfNeeded(true);
-        }
-    }
-
-    @Override
-    public void unindent() {
-        if (tableLevel > 0) {
-            endTableIfStarted();
-            appendHtml("</td>");
-        }
-    }
-
-    protected void header() {
-        if (createPage) {
-            appendHtml("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">");
-            appendHtml("<html>");
-            appendHtml("<head>");
-            appendHtml("<title>Debug Details</title>");
-            appendHtml("<style type=\"text/css\">");
-            appendHtml("body { margin: 15px; }\n" + ".links { background: #ddd; font-size: 80%; padding-bottom:5px; }\n" + ".links > p { display: inline-block; }\n" + "td {vertical-align: top; margin-left: 15px;}\n" + "td.error {color: red; font-style: italic; }\n" + "td.code {white-space: pre; font-family: monospace;}\n"
-                    + "th.title {text-align: left; padding: 0.3em 1em; font-style: italic; background: #AED1FF; }\n" + "td.label {width: 16em; text-align: right; padding-right: 1.5em; padding-top: 0.2em; font-size: 80%; font-weight: bold; }\n"
-                    + "span.facet-type { font-weight: bold; padding-right: 10px; }\n");
-            appendHtml("</style>");
-            appendHtml("</head>");
-            appendHtml("<body>");
-        }
-    }
-
-    protected abstract void appendHtml(String html);
-
-    protected void footer() {
-        endTableIfStarted();
-        if (createPage) {
-            appendHtml("</body>");
-            appendHtml("</html>");
-        }
-    }
-
-    @Override
-    public void appendException(final Throwable e) {
-        appendTitle("Exception");
-        final String message = e.getMessage();
-        if (message != null) {
-            appendHtml(row() + "<td class=\"error\" colspan=\"2\" >" + message + "</td></tr>");
-        }
-        causingException(e);
-        appendHtml(row() + "<td class=\"code\" colspan=\"2\" ><pre>");
-        final StringWriter stringWriter = new StringWriter();
-        final PrintWriter printWriter = new PrintWriter(stringWriter);
-        e.printStackTrace(printWriter);
-        appendHtml(stringWriter.toString());
-        appendHtml("</pre></td></tr>");
-
-    }
-
-    private void causingException(final Throwable throwable) {
-        final Throwable cause = throwable.getCause();
-        if (cause != null && cause != throwable) {
-            appendHtml(row() + "<td colspan=\"2\" >" + cause.getMessage() + "</td></tr>");
-            causingException(cause);
-        }
-    }
-
-    @Override
-    public void appendTitle(final String title) {
-        if (tableLevel > 0) {
-            appendHtml(row() + "<th class=\"title\" colspan=\"2\" >" + title + "</th></tr>");
-        } else {
-            appendHtml("<h2>" + title + "</h2>");
-        }
-    }
-
-    private void appendln(final String name, final String value) {
-        startTableIfNeeded(false);
-        appendHtml(row() + "<td class=\"label\">" + name + "</td><td>" + value + "</td></tr>");
-    }
-
-    private String row() {
-        final String line = isOdd ? "odd" : "even";
-        isOdd = !isOdd;
-        return "<tr class=\"" + line + "\">";
-    }
-
-    private void startTableIfNeeded(final boolean b) {
-        if (tableLevel == 0 || b) {
-            appendHtml("<table class=\"debug\" width=\"100%\" summary=\"Debug details\" >");
-            tableLevel++;
-        }
-    }
-
-    private void endTableIfStarted() {
-        if (tableLevel > 0) {
-            appendHtml("</table>");
-            tableLevel--;
-        }
-    }
-
-    @Override
-    public void appendPreformatted(final String text) {
-        appendln("<pre>" + text + "</pre>");
-    }
-
-    @Override
-    public void appendln(final String text) {
-        if (tableLevel > 0) {
-            appendHtml(row() + "<td colspan=\"2\">" + text + "</td></tr>");
-        } else {
-            appendHtml("<p>" + text + "</p>");
-        }
-    }
-
-    @Override
-    public void close() {
-        endTableIfStarted();
-        doClose();
-    }
-
-    protected abstract void doClose();
-
-}
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.isis.core.commons.debug;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+public abstract class DebugHtmlStringAbstract implements DebugBuilder {
+
+    private final boolean createPage;
+    private int tableLevel;
+    private boolean isOdd;
+    private boolean titleShown;
+    private boolean endLine;
+
+    public DebugHtmlStringAbstract(final boolean createPage) {
+        this.createPage = createPage;
+    }
+
+    @Override
+    public void concat(final DebugBuilder debug) {
+        appendHtml(debug.toString());
+    }
+
+    @Override
+    public void append(final int number, final int width) {
+        appendHtml(number + "");
+    }
+
+    @Override
+    public void append(final Object object) {
+        if (object instanceof DebuggableWithTitle) {
+            DebuggableWithTitle d = (DebuggableWithTitle) object;
+            appendTitle(d.debugTitle());
+            d.debugData(this);
+        } else {
+            appendHtml(object.toString());
+        }
+    }
+
+    @Override
+    public void append(final Object object, final int width) {
+        appendHtml(object.toString());
+    }
+
+    @Override
+    public void appendln() {
+        if (tableLevel > 0) {
+            endLine = true;
+        } else {
+            appendHtml("<p></p>");
+        }
+    }
+
+    @Override
+    public void blankLine() {
+        if (tableLevel > 0) {
+            appendHtml(row() + "<td class=\"error\" colspan=\"2\" >blank line</td></tr>");
+        } else {
+            appendHtml("<p>blank line</p>");
+        }
+    }
+
+    @Override
+    public void appendln(final String label, final boolean value) {
+        appendln(label, String.valueOf(value));
+    }
+
+    @Override
+    public void appendln(final String label, final double value) {
+        appendln(label, String.valueOf(value));
+    }
+
+    @Override
+    public void appendln(final String label, final long value) {
+        appendln(label, String.valueOf(value));
+    }
+
+    @Override
+    public void appendAsHexln(final String label, final long value) {
+        appendln(label, Long.toHexString(value));
+    }
+
+    @Override
+    public void appendPreformatted(final String label, final String object) {
+        final String value = object == null ? "null" : object.toString();
+        appendln(label, "<pre>" + value + "</pre>");
+    };
+
+    @Override
+    public void appendln(final String label, final Object object) {
+        final String value = object == null ? "null" : object.toString();
+        appendln(label, value);
+    }
+
+    @Override
+    public void appendln(final String label, final Object[] object) {
+        if (object.length == 0) {
+            appendln(label, "empty array");
+        } else {
+            appendln(label, object[0]);
+            for (int i = 1; i < object.length; i++) {
+                appendHtml(row() + "<td></td><td>" + object[i] + "</td></tr>");
+            }
+        }
+    }
+
+    @Override
+    public void startSection(final String title) {
+        startTableIfNeeded(true);
+        appendTitle(title);
+    }
+
+    @Override
+    public void endSection() {
+        endTableIfStarted();
+    }
+
+    @Override
+    public void indent() {
+        if (tableLevel > 0) {
+            appendHtml(row() + "<td>indented</td><td>");
+            startTableIfNeeded(true);
+        }
+    }
+
+    @Override
+    public void unindent() {
+        if (tableLevel > 0) {
+            endTableIfStarted();
+            appendHtml("</td>");
+        }
+    }
+
+    protected void header() {
+        if (createPage) {
+            appendHtml("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">");
+            appendHtml("<html>");
+            appendHtml("<head>");
+            appendHtml("<title>Debug Details</title>");
+            appendHtml("<style type=\"text/css\">");
+            appendHtml("body { margin: 15px; }\n" + ".links { background: #ddd; font-size: 80%; padding-bottom:5px; }\n" + ".links > p { display: inline-block; }\n" + "td {vertical-align: top; margin-left: 15px;}\n" + "td.error {color: red; font-style: italic; }\n" + "td.code {white-space: pre; font-family: monospace;}\n"
+                    + "th.title {text-align: left; padding: 0.3em 1em; font-style: italic; background: #AED1FF; }\n" + "td.label {width: 16em; text-align: right; padding-right: 1.5em; padding-top: 0.2em; font-size: 80%; font-weight: bold; }\n"
+                    + "span.facet-type { font-weight: bold; padding-right: 10px; }\n");
+            appendHtml("</style>");
+            appendHtml("</head>");
+            appendHtml("<body>");
+        }
+    }
+
+    protected abstract void appendHtml(String html);
+
+    protected void footer() {
+        endTableIfStarted();
+        if (createPage) {
+            appendHtml("</body>");
+            appendHtml("</html>");
+        }
+    }
+
+    @Override
+    public void appendException(final Throwable e) {
+        appendTitle("Exception");
+        final String message = e.getMessage();
+        if (message != null) {
+            appendHtml(row() + "<td class=\"error\" colspan=\"2\" >" + message + "</td></tr>");
+        }
+        causingException(e);
+        appendHtml(row() + "<td class=\"code\" colspan=\"2\" ><pre>");
+        final StringWriter stringWriter = new StringWriter();
+        final PrintWriter printWriter = new PrintWriter(stringWriter);
+        e.printStackTrace(printWriter);
+        appendHtml(stringWriter.toString());
+        appendHtml("</pre></td></tr>");
+
+    }
+
+    private void causingException(final Throwable throwable) {
+        final Throwable cause = throwable.getCause();
+        if (cause != null && cause != throwable) {
+            appendHtml(row() + "<td colspan=\"2\" >" + cause.getMessage() + "</td></tr>");
+            causingException(cause);
+        }
+    }
+
+    @Override
+    public void appendTitle(final String title) {
+        if (tableLevel > 0) {
+            String className = titleShown ? "subtitle" : "title";
+            appendHtml(row() + "<th class=\""+ className + "\" colspan=\"2\" >" + title + "</th></tr>");
+            titleShown = true;
+        } else {
+            appendHtml("<h2>" + title + "</h2>");
+        }
+    }
+
+    private void appendln(final String name, final String value) {
+        startTableIfNeeded(false);
+        appendHtml(row() + "<td class=\"label\">" + name + "</td><td>" + value + "</td></tr>");
+    }
+
+    private String row() {
+        final String line = (isOdd ? "odd" : "even") + (endLine ? " end-line" : ""); 
+        isOdd = !isOdd;
+        endLine = false;
+        return "<tr class=\"" + line + "\">";
+    }
+
+    private void startTableIfNeeded(final boolean b) {
+        if (tableLevel == 0 || b) {
+            appendHtml("<table class=\"debug\" summary=\"Debug details\" >");
+            tableLevel++;
+            titleShown = false;
+        }
+    }
+
+    private void endTableIfStarted() {
+        if (tableLevel > 0) {
+            appendHtml("</table>");
+            tableLevel--;
+        }
+    }
+
+    @Override
+    public void appendPreformatted(final String text) {
+        appendln("<pre>" + text + "</pre>");
+    }
+
+    @Override
+    public void appendln(final String text) {
+        if (tableLevel > 0) {
+            appendHtml(row() + "<td colspan=\"2\">" + text + "</td></tr>");
+        } else {
+            appendHtml("<p>" + text + "</p>");
+        }
+    }
+
+    @Override
+    public void close() {
+        endTableIfStarted();
+        doClose();
+    }
+
+    protected abstract void doClose();
+
+}

Modified: incubator/isis/trunk/framework/core/commons/src/main/java/org/apache/isis/core/commons/debug/DebugList.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/core/commons/src/main/java/org/apache/isis/core/commons/debug/DebugList.java?rev=1399217&r1=1399216&r2=1399217&view=diff
==============================================================================
--- incubator/isis/trunk/framework/core/commons/src/main/java/org/apache/isis/core/commons/debug/DebugList.java (original)
+++ incubator/isis/trunk/framework/core/commons/src/main/java/org/apache/isis/core/commons/debug/DebugList.java Wed Oct 17 13:06:08 2012
@@ -1,57 +1,62 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- */
-
-package org.apache.isis.core.commons.debug;
-
-import java.util.List;
-
-import com.google.common.collect.Lists;
-
-public class DebugList {
-    private final List<DebuggableWithTitle> debuggableList = Lists.newArrayList();
-    private final DebugBuilder summary = new DebugString();
-
-    public DebugList(final String name) {
-        debuggableList.add(new DebuggableWithTitle() {
-            @Override
-            public void debugData(final DebugBuilder debug) {
-                debug.append(summary.toString());
-            }
-
-            @Override
-            public String debugTitle() {
-                return name;
-            }
-        });
-    }
-
-    public void add(final String name, final Object object) {
-        final boolean b = object instanceof DebuggableWithTitle;
-        if (b) {
-            debuggableList.add((DebuggableWithTitle) object);
-        }
-        if (object != null) {
-            summary.appendln(name + (b ? "*" : ""), object.toString());
-        }
-    }
-
-    public DebuggableWithTitle[] debug() {
-        return debuggableList.toArray(new DebuggableWithTitle[debuggableList.size()]);
-    }
-}
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.core.commons.debug;
+
+import java.util.List;
+
+import com.google.common.collect.Lists;
+
+public class DebugList {
+    private final List<String[]> names = Lists.newArrayList();
+    private final List<DebuggableWithTitle> debuggableList = Lists.newArrayList();
+
+    public DebugList(final String name) {
+        debuggableList.add(new DebuggableWithTitle() {
+            @Override
+            public void debugData(final DebugBuilder debug) {
+                for (String[] name : names) {
+                    debug.appendln(name[0], name[1]);
+                }
+            }
+
+            @Override
+            public String debugTitle() {
+                return name;
+            }
+        });
+    }
+
+    public void add(final String name, final Object object) {
+        final boolean b = object instanceof DebuggableWithTitle;
+        if (b) {
+            debuggableList.add((DebuggableWithTitle) object);
+        }
+        if (object != null) {
+            String[] n = new String[2];
+            n[0] = name + (b ? "*" : "");
+            n[1] = object.toString();
+            names.add(n);
+        }
+    }
+
+    public DebuggableWithTitle[] debug() {
+        return debuggableList.toArray(new DebuggableWithTitle[debuggableList.size()]);
+    }
+}

Modified: incubator/isis/trunk/framework/core/commons/src/main/java/org/apache/isis/core/commons/debug/DebugString.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/core/commons/src/main/java/org/apache/isis/core/commons/debug/DebugString.java?rev=1399217&r1=1399216&r2=1399217&view=diff
==============================================================================
--- incubator/isis/trunk/framework/core/commons/src/main/java/org/apache/isis/core/commons/debug/DebugString.java (original)
+++ incubator/isis/trunk/framework/core/commons/src/main/java/org/apache/isis/core/commons/debug/DebugString.java Wed Oct 17 13:06:08 2012
@@ -1,313 +1,323 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- */
-
-package org.apache.isis.core.commons.debug;
-
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
-
-public class DebugString implements DebugBuilder {
-
-    private static final int COLUMN_SPACING = 25;
-    private static final int INDENT_WIDTH = 3;
-    private static final String LINE;
-    private static final int MAX_LINE_LENGTH;
-    private static final int MAX_SPACES_LENGTH;
-    private static final String SPACES = "                                                                            ";
-
-    static {
-        LINE = "-------------------------------------------------------------------------------";
-        MAX_LINE_LENGTH = LINE.length();
-        MAX_SPACES_LENGTH = SPACES.length();
-    }
-
-    private int indent = 0;
-    private int section = 1;
-    private final StringBuffer string = new StringBuffer();
-    private boolean newLine = true;
-
-    @Override
-    public void concat(final DebugBuilder debug) {
-        string.append(debug.toString());
-    }
-
-    /**
-     * Append the specified number within a space (number of spaces) specified
-     * by the width. E.g. "15 " where number is 15 and width is 4.
-     */
-    @Override
-    public void append(final int number, final int width) {
-        appendIndent();
-        final int len = string.length();
-        string.append(number);
-        regularizeWidth(width, len);
-    }
-
-    /**
-     * Append the specified object by calling it <code>toString()</code> method.
-     */
-    @Override
-    public void append(final Object object) {
-        if (object instanceof DebuggableWithTitle) {
-            indent();
-            appendTitle(((DebuggableWithTitle) object).debugTitle());
-            ((DebuggableWithTitle) object).debugData(this);
-            unindent();
-        } else {
-            appendIndent();
-            string.append(object);
-        }
-    }
-
-    /**
-     * Append the specified object by calling its <code>toString()</code>
-     * method, placing it within specified space.
-     */
-    @Override
-    public void append(final Object object, final int width) {
-        appendIndent();
-        final int len = string.length();
-        string.append(object);
-        regularizeWidth(width, len);
-    }
-
-    /**
-     * Append the specified number, displayed in hexadecimal notation, with the
-     * specified label, then start a new line.
-     */
-    @Override
-    public void appendAsHexln(final String label, final long value) {
-        appendln(label, "#" + Long.toHexString(value));
-    }
-
-    /**
-     * Append the message and trace of the specified exception.
-     */
-    @Override
-    public void appendException(final Throwable e) {
-        ByteArrayOutputStream baos;
-        final PrintStream s = new PrintStream(baos = new ByteArrayOutputStream());
-        e.printStackTrace(s);
-        appendln(e.getMessage());
-        appendln(new String(baos.toByteArray()));
-        s.close();
-    }
-
-    /**
-     * Start a new line.
-     * 
-     * @see #blankLine()
-     */
-    @Override
-    public void appendln() {
-        string.append('\n');
-        newLine = true;
-    }
-
-    @Override
-    public void appendPreformatted(final String text) {
-        appendln(text);
-    }
-
-    /**
-     * Append the specified text, then start a new line.
-     */
-    @Override
-    public void appendln(final String text) {
-        appendIndent();
-        append(text);
-        appendln();
-        newLine = true;
-    }
-
-    /**
-     * Append the specified value, displayed as true or false, with the
-     * specified label, then start a new line.
-     */
-    @Override
-    public void appendln(final String label, final boolean value) {
-        appendln(label, String.valueOf(value));
-    }
-
-    /**
-     * Append the specified number with the specified label, then start a new
-     * line.
-     */
-    @Override
-    public void appendln(final String label, final double value) {
-        appendln(label, String.valueOf(value));
-    }
-
-    /**
-     * Append the specified number, displayed in hexadecimal notation, with the
-     * specified label, then start a new line.
-     */
-    @Override
-    public void appendln(final String label, final long value) {
-        appendln(label, String.valueOf(value));
-    }
-
-    @Override
-    public void appendPreformatted(final String label, final String text) {
-        appendln(label, text);
-    };
-
-    /**
-     * Append the specified object with the specified label, then start a new
-     * line.
-     */
-    @Override
-    public void appendln(final String label, final Object object) {
-        appendIndent();
-        string.append(label);
-        final int spaces = COLUMN_SPACING - label.length();
-        string.append(": " + spaces(spaces > 0 ? spaces : 0));
-        string.append(object);
-        string.append('\n');
-        newLine = true;
-    }
-
-    /**
-     * Append the elements of the specified array with the specified label. Each
-     * element is appended on its own line, and a new line is added after the
-     * last element.
-     */
-    @Override
-    public void appendln(final String label, final Object[] object) {
-        if (object.length == 0) {
-            appendln(label, "empty array");
-        } else {
-            appendln(label, object[0]);
-            for (int i = 1; i < object.length; i++) {
-                string.append(spaces(COLUMN_SPACING + 2));
-                string.append(object[i]);
-                string.append('\n');
-            }
-            newLine = true;
-        }
-    }
-
-    /**
-     * Append the specified title, then start a new line. A title is shown on
-     * two lines with the text on the first line and dashes on the second.
-     */
-    @Override
-    public void appendTitle(final String title) {
-        appendTitleString(title);
-    }
-
-    private void appendTitleString(final String titleString) {
-        appendln();
-        appendln(titleString);
-        final String underline = LINE.substring(0, Math.min(MAX_LINE_LENGTH, titleString.length()));
-        appendln(underline);
-    }
-
-    @Override
-    public void startSection(final String title) {
-        appendTitleString(section++ + ". " + title);
-        indent();
-    }
-
-    @Override
-    public void endSection() {
-        appendln();
-        unindent();
-    }
-
-    /**
-     * Append a blank line only if there are existing lines and the previous
-     * line is not blank.
-     */
-    @Override
-    public void blankLine() {
-        final int length = string.length();
-        if (length == 0) {
-            return;
-        }
-        final boolean hasLineEnding = string.charAt(length - 1) == '\n';
-        if (!hasLineEnding) {
-            string.append('\n');
-            string.append('\n');
-            newLine = true;
-        } else {
-            final boolean hasDoubleLineEnding = length >= 2 && string.charAt(length - 2) != '\n';
-            if (hasDoubleLineEnding) {
-                string.append('\n');
-                newLine = true;
-            }
-        }
-    }
-
-    /**
-     * Increase indent used when appending.
-     */
-    @Override
-    public void indent() {
-        indent++;
-    }
-
-    private void appendIndent() {
-        if (newLine) {
-            final String spaces = spaces(Math.min(MAX_SPACES_LENGTH, indent * INDENT_WIDTH));
-            string.append(spaces);
-            newLine = false;
-        }
-    }
-
-    private void regularizeWidth(final int width, final int len) {
-        if (width > 0) {
-            final int textWidth = string.length() - len;
-            if (textWidth > width) {
-                string.setLength(len + width - 3);
-                string.append("...");
-            } else {
-                int spaces = width - textWidth;
-                spaces = Math.max(0, spaces);
-                string.append(SPACES.substring(0, spaces));
-            }
-        }
-    }
-
-    private String spaces(final int spaces) {
-        return SPACES.substring(0, spaces);
-    }
-
-    /**
-     * Decrease indent used when appending.
-     */
-    @Override
-    public void unindent() {
-        if (indent > 0) {
-            indent--;
-        }
-    }
-
-    @Override
-    public void close() {
-    }
-
-    /**
-     * Return the <code>String</code> representation of this debug string.
-     */
-    @Override
-    public String toString() {
-        return string.toString();
-    }
-}
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.core.commons.debug;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.StringTokenizer;
+
+public class DebugString implements DebugBuilder {
+
+    private static final int COLUMN_SPACING = 25;
+    private static final int INDENT_WIDTH = 3;
+    private static final String LINE;
+    private static final int MAX_LINE_LENGTH;
+    private static final int MAX_SPACES_LENGTH;
+    private static final String SPACES = "                                                                            ";
+
+    static {
+        LINE = "-------------------------------------------------------------------------------";
+        MAX_LINE_LENGTH = LINE.length();
+        MAX_SPACES_LENGTH = SPACES.length();
+    }
+
+    private int indent = 0;
+    private int section = 1;
+    private final StringBuffer string = new StringBuffer();
+    private boolean newLine = true;
+
+    @Override
+    public void concat(final DebugBuilder debug) {
+        string.append(debug.toString());
+    }
+
+    /**
+     * Append the specified number within a space (number of spaces) specified
+     * by the width. E.g. "15 " where number is 15 and width is 4.
+     */
+    @Override
+    public void append(final int number, final int width) {
+        appendIndent();
+        final int len = string.length();
+        string.append(number);
+        regularizeWidth(width, len);
+    }
+
+    /**
+     * Append the specified object by calling it <code>toString()</code> method.
+     */
+    @Override
+    public void append(final Object object) {
+        if (object instanceof DebuggableWithTitle) {
+            indent();
+            appendTitle(((DebuggableWithTitle) object).debugTitle());
+            ((DebuggableWithTitle) object).debugData(this);
+            unindent();
+        } else {
+            appendIndent();
+            string.append(object);
+        }
+    }
+
+    /**
+     * Append the specified object by calling its <code>toString()</code>
+     * method, placing it within specified space.
+     */
+    @Override
+    public void append(final Object object, final int width) {
+        appendIndent();
+        final int len = string.length();
+        string.append(object);
+        regularizeWidth(width, len);
+    }
+
+    /**
+     * Append the specified number, displayed in hexadecimal notation, with the
+     * specified label, then start a new line.
+     */
+    @Override
+    public void appendAsHexln(final String label, final long value) {
+        appendln(label, "#" + Long.toHexString(value));
+    }
+
+    /**
+     * Append the message and trace of the specified exception.
+     */
+    @Override
+    public void appendException(final Throwable e) {
+        ByteArrayOutputStream baos;
+        final PrintStream s = new PrintStream(baos = new ByteArrayOutputStream());
+        e.printStackTrace(s);
+        appendln(e.getMessage());
+        appendln(new String(baos.toByteArray()));
+        s.close();
+    }
+
+    /**
+     * Start a new line.
+     * 
+     * @see #blankLine()
+     */
+    @Override
+    public void appendln() {
+        string.append('\n');
+        newLine = true;
+    }
+
+    @Override
+    public void appendPreformatted(final String text) {
+        appendln(text);
+    }
+
+    /**
+     * Append the specified text, then start a new line.
+     */
+    @Override
+    public void appendln(final String text) {
+        appendIndent();
+        append(text);
+        appendln();
+        newLine = true;
+    }
+
+    /**
+     * Append the specified value, displayed as true or false, with the
+     * specified label, then start a new line.
+     */
+    @Override
+    public void appendln(final String label, final boolean value) {
+        appendln(label, String.valueOf(value));
+    }
+
+    /**
+     * Append the specified number with the specified label, then start a new
+     * line.
+     */
+    @Override
+    public void appendln(final String label, final double value) {
+        appendln(label, String.valueOf(value));
+    }
+
+    /**
+     * Append the specified number, displayed in hexadecimal notation, with the
+     * specified label, then start a new line.
+     */
+    @Override
+    public void appendln(final String label, final long value) {
+        appendln(label, String.valueOf(value));
+    }
+
+    @Override
+    public void appendPreformatted(final String label, final String text) {
+        StringTokenizer tokenizer = new StringTokenizer(text, "\n\r\f", false);
+        if (tokenizer.hasMoreTokens()) {
+            appendln(label, tokenizer.nextToken());
+        }
+        while (tokenizer.hasMoreTokens()) {
+            string.append(spaces(indent * INDENT_WIDTH + COLUMN_SPACING + 2));
+            string.append(tokenizer.nextToken());
+            string.append('\n');
+        }
+        newLine = true;
+    }
+
+    /**
+     * Append the specified object with the specified label, then start a new
+     * line.
+     */
+    @Override
+    public void appendln(final String label, final Object object) {
+        appendIndent();
+        string.append(label);
+        final int spaces = COLUMN_SPACING - label.length();
+        string.append(": " + spaces(spaces > 0 ? spaces : 0));
+        string.append(object);
+        string.append('\n');
+        newLine = true;
+    }
+
+    /**
+     * Append the elements of the specified array with the specified label. Each
+     * element is appended on its own line, and a new line is added after the
+     * last element.
+     */
+    @Override
+    public void appendln(final String label, final Object[] object) {
+        if (object.length == 0) {
+            appendln(label, "empty array");
+        } else {
+            appendln(label, object[0]);
+            for (int i = 1; i < object.length; i++) {
+                string.append(spaces(COLUMN_SPACING + 2));
+                string.append(object[i]);
+                string.append('\n');
+            }
+            newLine = true;
+        }
+    }
+
+    /**
+     * Append the specified title, then start a new line. A title is shown on
+     * two lines with the text on the first line and dashes on the second.
+     */
+    @Override
+    public void appendTitle(final String title) {
+        appendTitleString(title);
+    }
+
+    private void appendTitleString(final String titleString) {
+        appendln();
+        appendln(titleString);
+        final String underline = LINE.substring(0, Math.min(MAX_LINE_LENGTH, titleString.length()));
+        appendln(underline);
+    }
+
+    @Override
+    public void startSection(final String title) {
+        appendTitleString(section++ + ". " + title);
+        indent();
+    }
+
+    @Override
+    public void endSection() {
+        appendln();
+        unindent();
+    }
+
+    /**
+     * Append a blank line only if there are existing lines and the previous
+     * line is not blank.
+     */
+    @Override
+    public void blankLine() {
+        final int length = string.length();
+        if (length == 0) {
+            return;
+        }
+        final boolean hasLineEnding = string.charAt(length - 1) == '\n';
+        if (!hasLineEnding) {
+            string.append('\n');
+            string.append('\n');
+            newLine = true;
+        } else {
+            final boolean hasDoubleLineEnding = length >= 2 && string.charAt(length - 2) != '\n';
+            if (hasDoubleLineEnding) {
+                string.append('\n');
+                newLine = true;
+            }
+        }
+    }
+
+    /**
+     * Increase indent used when appending.
+     */
+    @Override
+    public void indent() {
+        indent++;
+    }
+
+    private void appendIndent() {
+        if (newLine) {
+            final String spaces = spaces(Math.min(MAX_SPACES_LENGTH, indent * INDENT_WIDTH));
+            string.append(spaces);
+            newLine = false;
+        }
+    }
+
+    private void regularizeWidth(final int width, final int len) {
+        if (width > 0) {
+            final int textWidth = string.length() - len;
+            if (textWidth > width) {
+                string.setLength(len + width - 3);
+                string.append("...");
+            } else {
+                int spaces = width - textWidth;
+                spaces = Math.max(0, spaces);
+                string.append(SPACES.substring(0, spaces));
+            }
+        }
+    }
+
+    private String spaces(final int spaces) {
+        return SPACES.substring(0, spaces);
+    }
+
+    /**
+     * Decrease indent used when appending.
+     */
+    @Override
+    public void unindent() {
+        if (indent > 0) {
+            indent--;
+        }
+    }
+
+    @Override
+    public void close() {
+    }
+
+    /**
+     * Return the <code>String</code> representation of this debug string.
+     */
+    @Override
+    public String toString() {
+        return string.toString();
+    }
+}