Пример #1
0
  /**
   * Constructor.
   *
   * @param c the OpenOffice component context
   */
  public SettingsDialog(XComponentContext c) {
    super(c, Constants.SETTINGS_DIALOG);
    LoginData loginData = new LoginData();
    XWikiExtension xWikiExtension = XWikiExtension.getInstance();

    if (loginData.canAutoLogin()) {
      credentials = loginData.getCredentials();
      ConnectionSettings set = xWikiExtension.getSettings();

      set.setServerURL(credentials[0]);
      set.setPassword(credentials[1]);
      set.setPassword(credentials[2]);
      set.setWikiURL(credentials[3]);
      set.setXmlRpcURL(credentials[4]);

      try {
        getPropSet("txtServerURL").setPropertyValue("Text", credentials[0]);
        getPropSet("txtUsername").setPropertyValue("Text", credentials[1]);
        // TODO secure store for the password
        getPropSet("txtPassword").setPropertyValue("Text", credentials[2]);

      } catch (UnknownPropertyException e) {
        e.printStackTrace();
      } catch (PropertyVetoException e) {
        e.printStackTrace();
      } catch (IllegalArgumentException e) {
        e.printStackTrace();
      } catch (WrappedTargetException e) {
        e.printStackTrace();
      }
    }

    String urlOkButton = xWikiExtension.getImagesDirUrl() + "/" + Constants.IMG_OK_BUTTON;
    String urlCancelButton = xWikiExtension.getImagesDirUrl() + "/" + Constants.IMG_CANCEL_BUTTON;
    String urlCustomButton = xWikiExtension.getImagesDirUrl() + "/" + Constants.IMG_CONN_SETTINGS;

    try {

      getPropSet("btnOK").setPropertyValue("ImageURL", urlOkButton);
      getPropSet("btnCancel").setPropertyValue("ImageURL", urlCancelButton);
      getPropSet("cmdCustom").setPropertyValue("ImageURL", urlCustomButton);

    } catch (UnknownPropertyException e) {
      e.printStackTrace();
    } catch (PropertyVetoException e) {
      e.printStackTrace();
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
    } catch (WrappedTargetException e) {
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Пример #2
0
  /** The handler for the clicked event of the OK button. */
  private void btnOK_Clicked() {

    boolean bResult = false;

    try {
      String sServerURL = (String) getPropSet("txtServerURL").getPropertyValue("Text");
      String sUserName = (String) getPropSet("txtUsername").getPropertyValue("Text");
      String sPassword = (String) getPropSet("txtPassword").getPropertyValue("Text");
      Short nState = (Short) getPropSet("chkRemember").getPropertyValue("State");

      if (sServerURL.endsWith("/")) sServerURL = sServerURL.substring(0, sServerURL.length() - 1);

      XWikiExtension xWikiExtension = XWikiExtension.getInstance();
      ConnectionSettings set = xWikiExtension.getSettings();
      set.setServerURL(sServerURL);
      xWikiExtension.resetClient();
      set.setUsername(sUserName);
      set.setPassword(sPassword);

      if (nState == 0) {
        LoginData loginData = new LoginData();
        loginData.clearCredentials();
      } else if (nState == 1) {
        String new_credentials[] = {
          sServerURL,
          sUserName,
          sPassword,
          xWikiExtension.getSettings().getWikiURL(),
          xWikiExtension.getSettings().getXmlRpcURL()
        };
        LoginData loginData = new LoginData();
        loginData.writeCredentials(new_credentials);
      }

      XWikiXmlRpcClient client = xWikiExtension.getClient();
      if (client != null) {
        bResult = xWikiExtension.doLogin();
      }
      if (bResult) {
        m_xDialog.endExecute();
        xWikiExtension.getExtensionStatus().setLoginStatus(true);
        Utils.ShowMessage(
            m_xContext,
            m_xDialog,
            Constants.TITLE_XWIKI,
            Constants.MESS_LOGINSUCC,
            Constants.TYPE_INFO,
            false);
      } else {
        Utils.ShowMessage(
            m_xContext,
            m_xDialog,
            Constants.TITLE_ERROR,
            Constants.ERROR_LOGINFAILED,
            Constants.TYPE_ERROR,
            false);
      }
    } catch (UnknownPropertyException e) {
      e.printStackTrace();
    } catch (WrappedTargetException e) {
      e.printStackTrace();
    }
  }