package com.intellij.ide.browsers;

import com.intellij.openapi.util.JDOMUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters;
import com.intellij.util.xmlb.XmlSerializer;
import com.intellij.util.xmlb.annotations.Attribute;
import com.intellij.util.xmlb.annotations.Tag;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@Tag("browser")
public class StartBrowserSettings {
  private boolean mySelected;
  private WebBrowser myBrowser;

  private String myUrl;
  private boolean myStartJavaScriptDebugger;

  @Attribute("start")
  public boolean isSelected() {
    return mySelected;
  }

  public void setSelected(boolean selected) {
    mySelected = selected;
  }

  @Nullable
  @Attribute(value = "name", converter = WebBrowserReferenceConverter.class)
  public WebBrowser getBrowser() {
    return myBrowser;
  }

  public void setBrowser(@Nullable WebBrowser value) {
    myBrowser = value;
  }

  @Nullable
  @Attribute
  public String getUrl() {
    return myUrl;
  }

  public void setUrl(@Nullable String value) {
    myUrl = StringUtil.nullize(value);
  }

  @Attribute("with-js-debugger")
  public boolean isStartJavaScriptDebugger() {
    return myStartJavaScriptDebugger;
  }

  public void setStartJavaScriptDebugger(boolean value) {
    myStartJavaScriptDebugger = value;
  }

  @NotNull
  public static StartBrowserSettings readExternal(@NotNull Element parent) {
    Element state = parent.getChild("browser");
    StartBrowserSettings settings = new StartBrowserSettings();
    if (state != null) {
      XmlSerializer.deserializeInto(settings, state);
    }
    return settings;
  }

  public void writeExternal(@NotNull Element parent) {
    Element state = XmlSerializer.serialize(this, new SkipDefaultValuesSerializationFilters());
    if (!JDOMUtil.isEmpty(state)) {
      parent.addContent(state);
    }
  }
}

@@ -29,16 +29,59 @@
 wsers;%0A%0A
+import com.google.common.base.CharMatcher;%0A
 import c
@@ -1195,21 +1195,33 @@
 ) %7B%0A    
-myUrl
+String normalized
  = Strin
@@ -1239,17 +1239,147 @@
 ze(value
-)
+, true);%0A    if (normalized != null) %7B%0A      normalized = CharMatcher.WHITESPACE.trimFrom(normalized);%0A    %7D%0A    myUrl = normalized
 ;%0A  %7D%0A%0A 

trim whitespace more aggressively