From 9c3b4a8e274d82536619eff31cfa6e490a7482ee Mon Sep 17 00:00:00 2001
From: Mark Craig <mark.craig@forgerock.com>
Date: Fri, 07 Feb 2014 10:18:55 +0000
Subject: [PATCH] Fix for OPENDJ-1335: Doc build breaks on duplicate xml:id values in generated log reference

---
 opendj3-server-dev/src/build-tools/org/opends/build/tools/GenerateMessageFile.java |   20 ++++++++++++++++++--
 1 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/opendj3-server-dev/src/build-tools/org/opends/build/tools/GenerateMessageFile.java b/opendj3-server-dev/src/build-tools/org/opends/build/tools/GenerateMessageFile.java
index 3607b29..49f21c9 100644
--- a/opendj3-server-dev/src/build-tools/org/opends/build/tools/GenerateMessageFile.java
+++ b/opendj3-server-dev/src/build-tools/org/opends/build/tools/GenerateMessageFile.java
@@ -537,22 +537,26 @@
 
     private Severity severity;
     private Integer id;
+    private String xmlId;
     private String formatString;
 
     /**
      * Build log reference entry for an log message.
      *
+     * @param msgPropKey
      * @param category
      * @param severity
      * @param ordinal
      * @param formatString
      */
-    public MessageRefEntry(final Category category, final Severity severity,
+    public MessageRefEntry(final String msgPropKey,
+        final Category category, final Severity severity,
         final Integer ordinal, final String formatString)
     {
       this.severity = severity;
       this.formatString = formatString;
       id = calculateId(category, severity, ordinal);
+      xmlId = getXmlId(msgPropKey);
     }
 
     private Integer calculateId(final Category category,
@@ -562,6 +566,17 @@
       return new Integer(ordinal);
     }
 
+    private String getXmlId(final String messagePropertyKey)
+    {
+        // XML IDs must be unique, and must begin with a letter ([A-Za-z])
+        // and may be followed by any number of letters, digits ([0-9]),
+        // hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
+
+        final String invalidChars = "[^A-Za-z0-9\\-_:\\.]";
+        String xmlId = messagePropertyKey.replaceAll(invalidChars, "-");
+        return xmlId;
+    }
+
     /**
      * Return a DocBook XML &lt;varlistentry&gt; of this log reference entry.
      * This implementation copies the message string verbatim, and does not
@@ -572,7 +587,7 @@
     public String toString()
     {
       return
-          "  <varlistentry xml:id=\"log-ref-" + id.intValue() + "\">" + EOL
+          "  <varlistentry xml:id=\"log-ref-" + xmlId + "\">" + EOL
           + "   <term>ID: " + id.intValue() + "</term>" + EOL
           + "   <listitem>" + EOL
           + "    <para>Severity: " + severity.name() + "</para>" + EOL
@@ -973,6 +988,7 @@
                   || s.name().equalsIgnoreCase("SEVERE_ERROR")) {
                 MessageRefEntry entry =
                         new MessageRefEntry(
+                                key.toString(),
                                 c,
                                 s,
                                 globalOrdinal != null ?

--
Gitblit v1.10.0