From 601f347643bb03e17313e91eebe8a62c7c5cb0b0 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Fri, 13 Jun 2008 11:08:23 +0000
Subject: [PATCH] Fix for issue 3324 (Instance scripts broken after running dsjavaproperties when java.properties contains '\')

---
 opends/src/server/org/opends/server/tools/JavaPropertiesTool.java |   60 +++++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 49 insertions(+), 11 deletions(-)

diff --git a/opends/src/server/org/opends/server/tools/JavaPropertiesTool.java b/opends/src/server/org/opends/server/tools/JavaPropertiesTool.java
index c4c5203..5f3a5fd 100644
--- a/opends/src/server/org/opends/server/tools/JavaPropertiesTool.java
+++ b/opends/src/server/org/opends/server/tools/JavaPropertiesTool.java
@@ -260,28 +260,66 @@
     {
       String line;
       // Parse the file manually since '\' in windows paths can generate issues.
+      boolean slashInLastLine = false;
+      String key = null;
+      StringBuilder sbValue = null;
       while ((line = reader.readLine()) != null)
       {
         line = line.trim();
         if (!line.startsWith("#"))
         {
-          int index = line.indexOf('=');
-          if (index != -1)
+          if (!slashInLastLine)
           {
-            String key = line.substring(0, index);
-            if (key.indexOf(' ') == -1)
+            key = null;
+            sbValue = new StringBuilder();
+            int index = line.indexOf('=');
+            if (index > 0)
             {
-              if (index < line.length())
+              key = line.substring(0, index);
+              if (key.indexOf(' ') != -1)
               {
-                String value = line.substring(index+1);
-                properties.setProperty(key, value);
-              }
-              else
-              {
-                properties.setProperty(key, "");
+                key = null;
               }
             }
           }
+
+          // Consider the space: in windows the user might add a path ending
+          // with '\'. With this approach we minimize the possibilities of
+          // error.
+          boolean hasSlash = line.endsWith(" \\");
+
+          if (hasSlash)
+          {
+            line = line.substring(0, line.length() - 1);
+          }
+
+          String lineValue = null;
+
+          if (slashInLastLine)
+          {
+            lineValue = line;
+          }
+          else if (key != null)
+          {
+            int index = line.indexOf('=');
+            if ((index != -1) && ((index + 1) < line.length()))
+            {
+              lineValue = line.substring(index+1);
+            }
+          }
+          if ((lineValue != null) && (lineValue.length() > 0))
+          {
+            if (sbValue == null)
+            {
+              sbValue = new StringBuilder();
+            }
+            sbValue.append(lineValue);
+          }
+          if (!hasSlash && (key != null) && (sbValue != null))
+          {
+            properties.put(key, sbValue.toString());
+          }
+          slashInLastLine = hasSlash;
         }
       }
     }

--
Gitblit v1.10.0