Java Code Examples for com.intellij.util.xmlb.XmlSerializer#serializeIfNotDefault()

The following examples show how to use com.intellij.util.xmlb.XmlSerializer#serializeIfNotDefault() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XDebuggerSettingManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public SettingsState getState() {
  SettingsState settingsState = new SettingsState();
  settingsState.setDataViewSettings(myDataViewSettings);
  settingsState.setGeneralSettings(myGeneralSettings);

  initSettings();
  if (!mySettingsById.isEmpty()) {
    SkipDefaultValuesSerializationFilters filter = new SkipDefaultValuesSerializationFilters();
    for (XDebuggerSettings<?> settings : mySettingsById.values()) {
      Object subState = settings.getState();
      if (subState != null) {
        Element serializedState = XmlSerializer.serializeIfNotDefault(subState, filter);
        if (!JDOMUtil.isEmpty(serializedState)) {
          SpecificSettingsState state = new SpecificSettingsState();
          state.id = settings.getId();
          state.configuration = serializedState;
          settingsState.specificStates.add(state);
        }
      }
    }
  }
  return settingsState;
}
 
Example 2
Source File: MultilanguageDuplocatorSettings.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public Element getState() {
  synchronized (mySettingsMap) {
    Element state = new Element("state");
    if (mySettingsMap.isEmpty()) {
      return state;
    }

    SkipDefaultValuesSerializationFilters filter = new SkipDefaultValuesSerializationFilters();
    for (String name : mySettingsMap.keySet()) {
      Element child = XmlSerializer.serializeIfNotDefault(mySettingsMap.get(name), filter);
      if (child != null) {
        child.setName("object");
        child.setAttribute("language", name);
        state.addContent(child);
      }
    }
    return state;
  }
}
 
Example 3
Source File: HttpConfigurable.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void afterLoadState() {
  final HttpConfigurable currentState = getState();
  if (currentState != null) {
    final Element serialized = XmlSerializer.serializeIfNotDefault(currentState, new SkipDefaultsSerializationFilter());
    if (serialized == null) {
      // all settings are defaults
      // trying user's proxy configuration entered while obtaining the license
      final SharedProxyConfig.ProxyParameters cfg = SharedProxyConfig.load();
      if (cfg != null) {
        SharedProxyConfig.clear();
        if (cfg.host != null) {
          USE_HTTP_PROXY = true;
          PROXY_HOST = cfg.host;
          PROXY_PORT = cfg.port;
          if (cfg.login != null) {
            setPlainProxyPassword(new String(cfg.password));
            storeSecure("proxy.login", cfg.login);
            PROXY_AUTHENTICATION = true;
            KEEP_PROXY_PASSWORD = true;
          }
        }
      }
    }
  }


  mySelector = new IdeaWideProxySelector(this);
  String name = getClass().getName();
  CommonProxy.getInstance().setCustom(name, mySelector);
  CommonProxy.getInstance().setCustomAuth(name, new IdeaWideAuthenticator(this));
}
 
Example 4
Source File: DefaultStateSerializer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static Element serializeState(@Nonnull Object state, @Nullable final Storage storage) throws WriteExternalException {
  if (state instanceof Element) {
    return (Element)state;
  }
  else if (state instanceof JDOMExternalizable) {
    Element element = new Element("temp_element");
    ((JDOMExternalizable)state).writeExternal(element);
    return element;
  }
  else {
    return XmlSerializer.serializeIfNotDefault(state, new SkipDefaultValuesSerializationFilters());
  }
}