mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

jvergara
18.01.2008 8e56a3541e4d0780a59cec88c6e8770565224180
Fix for issue 3612 (Control Panel: in the "Java Settings" panel, the value for "Java Home" variable is not correct (missing "\" characters)

Use the same parsing code used in JavaPropertiesTool to retrieve the values set in the java.properties file. This avoids problems with the '\' character.
2 files modified
153 ■■■■ changed files
opends/src/guitools/org/opends/guitools/controlpanel/ui/JavaPropertiesPanel.java 12 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/JavaPropertiesTool.java 141 ●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/controlpanel/ui/JavaPropertiesPanel.java
@@ -35,7 +35,6 @@
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
@@ -417,29 +416,30 @@
      public Void processBackgroundTask() throws Throwable
      {
        String propertiesFile = getPropertiesFile();
        FileInputStream fs = null;
        Properties properties = new Properties();
        BufferedReader reader = null;
        try
        {
          fs = new FileInputStream(propertiesFile);
          properties.load(fs);
          reader = new BufferedReader(new FileReader(propertiesFile));
          JavaPropertiesTool.updateProperties(reader, properties);
        }
        catch (Throwable t)
        {
        }
        finally
        {
          if (fs != null)
          if (reader != null)
          {
            try
            {
              fs.close();
              reader.close();
            }
            catch (Throwable t)
            {
            }
          }
        }
        String[] scripts =
        {
            "start-ds", "import-ldif.offline", "backup.online", "base64",
opends/src/server/org/opends/server/tools/JavaPropertiesTool.java
@@ -258,70 +258,7 @@
    }
    try
    {
      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("#"))
        {
          if (!slashInLastLine)
          {
            key = null;
            sbValue = new StringBuilder();
            int index = line.indexOf('=');
            if (index > 0)
            {
              key = line.substring(0, index);
              if (key.indexOf(' ') != -1)
              {
                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;
        }
      }
      updateProperties(reader, properties);
    }
    catch (IOException ioe)
    {
@@ -429,6 +366,82 @@
    return ErrorReturnCode.SUCCESSFUL.getReturnCode();
  }
  /**
   * Reads the contents of the provided reader and updates the provided
   * Properties object with it.  This is required because '\' characters in
   * windows paths generates problems.
   * @param reader the buffered reader.
   * @param properties the properties.
   * @throws IOException if there is an error reading the buffered reader.
   */
  public static void updateProperties(
      BufferedReader reader, Properties properties)
  throws IOException
  {
    String line;
    boolean slashInLastLine = false;
    String key = null;
    StringBuilder sbValue = null;
    while ((line = reader.readLine()) != null)
    {
      line = line.trim();
      if (!line.startsWith("#"))
      {
        if (!slashInLastLine)
        {
          key = null;
          sbValue = new StringBuilder();
          int index = line.indexOf('=');
          if (index > 0)
          {
            key = line.substring(0, index);
            if (key.indexOf(' ') != -1)
            {
              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;
      }
    }
  }
  /**
   * {@inheritDoc}